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