1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.AppChooserButton; 26 27 private import gio.IconIF; 28 private import glib.ConstructionException; 29 private import glib.Str; 30 private import gobject.ObjectG; 31 private import gobject.Signals; 32 private import gtk.AppChooserIF; 33 private import gtk.AppChooserT; 34 private import gtk.ComboBox; 35 private import gtk.Widget; 36 private import gtkc.gtk; 37 public import gtkc.gtktypes; 38 private import std.algorithm; 39 40 41 /** 42 * The #GtkAppChooserButton is a widget that lets the user select 43 * an application. It implements the #GtkAppChooser interface. 44 * 45 * Initially, a #GtkAppChooserButton selects the first application 46 * in its list, which will either be the most-recently used application 47 * or, if #GtkAppChooserButton:show-default-item is %TRUE, the 48 * default application. 49 * 50 * The list of applications shown in a #GtkAppChooserButton includes 51 * the recommended applications for the given content type. When 52 * #GtkAppChooserButton:show-default-item is set, the default application 53 * is also included. To let the user chooser other applications, 54 * you can set the #GtkAppChooserButton:show-dialog-item property, 55 * which allows to open a full #GtkAppChooserDialog. 56 * 57 * It is possible to add custom items to the list, using 58 * gtk_app_chooser_button_append_custom_item(). These items cause 59 * the #GtkAppChooserButton::custom-item-activated signal to be 60 * emitted when they are selected. 61 * 62 * To track changes in the selected application, use the 63 * #GtkComboBox::changed signal. 64 */ 65 public class AppChooserButton : ComboBox, AppChooserIF 66 { 67 /** the main Gtk struct */ 68 protected GtkAppChooserButton* gtkAppChooserButton; 69 70 /** Get the main Gtk struct */ 71 public GtkAppChooserButton* getAppChooserButtonStruct(bool transferOwnership = false) 72 { 73 if (transferOwnership) 74 ownedRef = false; 75 return gtkAppChooserButton; 76 } 77 78 /** the main Gtk struct as a void* */ 79 protected override void* getStruct() 80 { 81 return cast(void*)gtkAppChooserButton; 82 } 83 84 protected override void setStruct(GObject* obj) 85 { 86 gtkAppChooserButton = cast(GtkAppChooserButton*)obj; 87 super.setStruct(obj); 88 } 89 90 /** 91 * Sets our main struct and passes it to the parent class. 92 */ 93 public this (GtkAppChooserButton* gtkAppChooserButton, bool ownedRef = false) 94 { 95 this.gtkAppChooserButton = gtkAppChooserButton; 96 super(cast(GtkComboBox*)gtkAppChooserButton, ownedRef); 97 } 98 99 // add the AppChooser capabilities 100 mixin AppChooserT!(GtkAppChooserButton); 101 102 103 /** */ 104 public static GType getType() 105 { 106 return gtk_app_chooser_button_get_type(); 107 } 108 109 /** 110 * Creates a new #GtkAppChooserButton for applications 111 * that can handle content of the given type. 112 * 113 * Params: 114 * contentType = the content type to show applications for 115 * 116 * Returns: a newly created #GtkAppChooserButton 117 * 118 * Since: 3.0 119 * 120 * Throws: ConstructionException GTK+ fails to create the object. 121 */ 122 public this(string contentType) 123 { 124 auto p = gtk_app_chooser_button_new(Str.toStringz(contentType)); 125 126 if(p is null) 127 { 128 throw new ConstructionException("null returned by new"); 129 } 130 131 this(cast(GtkAppChooserButton*) p); 132 } 133 134 /** 135 * Appends a custom item to the list of applications that is shown 136 * in the popup; the item name must be unique per-widget. 137 * Clients can use the provided name as a detail for the 138 * #GtkAppChooserButton::custom-item-activated signal, to add a 139 * callback for the activation of a particular custom item in the list. 140 * See also gtk_app_chooser_button_append_separator(). 141 * 142 * Params: 143 * name = the name of the custom item 144 * label = the label for the custom item 145 * icon = the icon for the custom item 146 * 147 * Since: 3.0 148 */ 149 public void appendCustomItem(string name, string label, IconIF icon) 150 { 151 gtk_app_chooser_button_append_custom_item(gtkAppChooserButton, Str.toStringz(name), Str.toStringz(label), (icon is null) ? null : icon.getIconStruct()); 152 } 153 154 /** 155 * Appends a separator to the list of applications that is shown 156 * in the popup. 157 * 158 * Since: 3.0 159 */ 160 public void appendSeparator() 161 { 162 gtk_app_chooser_button_append_separator(gtkAppChooserButton); 163 } 164 165 /** 166 * Returns the text to display at the top of the dialog. 167 * 168 * Returns: the text to display at the top of the dialog, 169 * or %NULL, in which case a default text is displayed 170 */ 171 public string getHeading() 172 { 173 return Str.toString(gtk_app_chooser_button_get_heading(gtkAppChooserButton)); 174 } 175 176 /** 177 * Returns the current value of the #GtkAppChooserButton:show-default-item 178 * property. 179 * 180 * Returns: the value of #GtkAppChooserButton:show-default-item 181 * 182 * Since: 3.2 183 */ 184 public bool getShowDefaultItem() 185 { 186 return gtk_app_chooser_button_get_show_default_item(gtkAppChooserButton) != 0; 187 } 188 189 /** 190 * Returns the current value of the #GtkAppChooserButton:show-dialog-item 191 * property. 192 * 193 * Returns: the value of #GtkAppChooserButton:show-dialog-item 194 * 195 * Since: 3.0 196 */ 197 public bool getShowDialogItem() 198 { 199 return gtk_app_chooser_button_get_show_dialog_item(gtkAppChooserButton) != 0; 200 } 201 202 /** 203 * Selects a custom item previously added with 204 * gtk_app_chooser_button_append_custom_item(). 205 * 206 * Use gtk_app_chooser_refresh() to bring the selection 207 * to its initial state. 208 * 209 * Params: 210 * name = the name of the custom item 211 * 212 * Since: 3.0 213 */ 214 public void setActiveCustomItem(string name) 215 { 216 gtk_app_chooser_button_set_active_custom_item(gtkAppChooserButton, Str.toStringz(name)); 217 } 218 219 /** 220 * Sets the text to display at the top of the dialog. 221 * If the heading is not set, the dialog displays a default text. 222 * 223 * Params: 224 * heading = a string containing Pango markup 225 */ 226 public void setHeading(string heading) 227 { 228 gtk_app_chooser_button_set_heading(gtkAppChooserButton, Str.toStringz(heading)); 229 } 230 231 /** 232 * Sets whether the dropdown menu of this button should show the 233 * default application for the given content type at top. 234 * 235 * Params: 236 * setting = the new value for #GtkAppChooserButton:show-default-item 237 * 238 * Since: 3.2 239 */ 240 public void setShowDefaultItem(bool setting) 241 { 242 gtk_app_chooser_button_set_show_default_item(gtkAppChooserButton, setting); 243 } 244 245 /** 246 * Sets whether the dropdown menu of this button should show an 247 * entry to trigger a #GtkAppChooserDialog. 248 * 249 * Params: 250 * setting = the new value for #GtkAppChooserButton:show-dialog-item 251 * 252 * Since: 3.0 253 */ 254 public void setShowDialogItem(bool setting) 255 { 256 gtk_app_chooser_button_set_show_dialog_item(gtkAppChooserButton, setting); 257 } 258 259 protected class OnCustomItemActivatedDelegateWrapper 260 { 261 static OnCustomItemActivatedDelegateWrapper[] listeners; 262 void delegate(string, AppChooserButton) dlg; 263 gulong handlerId; 264 265 this(void delegate(string, AppChooserButton) dlg) 266 { 267 this.dlg = dlg; 268 this.listeners ~= this; 269 } 270 271 void remove(OnCustomItemActivatedDelegateWrapper source) 272 { 273 foreach(index, wrapper; listeners) 274 { 275 if (wrapper.handlerId == source.handlerId) 276 { 277 listeners[index] = null; 278 listeners = std.algorithm.remove(listeners, index); 279 break; 280 } 281 } 282 } 283 } 284 285 /** 286 * Emitted when a custom item, previously added with 287 * gtk_app_chooser_button_append_custom_item(), is activated from the 288 * dropdown menu. 289 * 290 * Params: 291 * itemName = the name of the activated item 292 */ 293 gulong addOnCustomItemActivated(void delegate(string, AppChooserButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 294 { 295 auto wrapper = new OnCustomItemActivatedDelegateWrapper(dlg); 296 wrapper.handlerId = Signals.connectData( 297 this, 298 "custom-item-activated", 299 cast(GCallback)&callBackCustomItemActivated, 300 cast(void*)wrapper, 301 cast(GClosureNotify)&callBackCustomItemActivatedDestroy, 302 connectFlags); 303 return wrapper.handlerId; 304 } 305 306 extern(C) static void callBackCustomItemActivated(GtkAppChooserButton* appchooserbuttonStruct, char* itemName, OnCustomItemActivatedDelegateWrapper wrapper) 307 { 308 wrapper.dlg(Str.toString(itemName), wrapper.outer); 309 } 310 311 extern(C) static void callBackCustomItemActivatedDestroy(OnCustomItemActivatedDelegateWrapper wrapper, GClosure* closure) 312 { 313 wrapper.remove(wrapper); 314 } 315 }