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 public import gtkc.gdktypes; 37 private import gtkc.gtk; 38 public import gtkc.gtktypes; 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() 72 { 73 return gtkAppChooserButton; 74 } 75 76 /** the main Gtk struct as a void* */ 77 protected override void* getStruct() 78 { 79 return cast(void*)gtkAppChooserButton; 80 } 81 82 protected override void setStruct(GObject* obj) 83 { 84 gtkAppChooserButton = cast(GtkAppChooserButton*)obj; 85 super.setStruct(obj); 86 } 87 88 /** 89 * Sets our main struct and passes it to the parent class. 90 */ 91 public this (GtkAppChooserButton* gtkAppChooserButton, bool ownedRef = false) 92 { 93 this.gtkAppChooserButton = gtkAppChooserButton; 94 super(cast(GtkComboBox*)gtkAppChooserButton, ownedRef); 95 } 96 97 // add the AppChooser capabilities 98 mixin AppChooserT!(GtkAppChooserButton); 99 100 101 /** */ 102 public static GType getType() 103 { 104 return gtk_app_chooser_button_get_type(); 105 } 106 107 /** 108 * Creates a new #GtkAppChooserButton for applications 109 * that can handle content of the given type. 110 * 111 * Params: 112 * contentType = the content type to show applications for 113 * 114 * Return: a newly created #GtkAppChooserButton 115 * 116 * Since: 3.0 117 * 118 * Throws: ConstructionException GTK+ fails to create the object. 119 */ 120 public this(string contentType) 121 { 122 auto p = gtk_app_chooser_button_new(Str.toStringz(contentType)); 123 124 if(p is null) 125 { 126 throw new ConstructionException("null returned by new"); 127 } 128 129 this(cast(GtkAppChooserButton*) p); 130 } 131 132 /** 133 * Appends a custom item to the list of applications that is shown 134 * in the popup; the item name must be unique per-widget. 135 * Clients can use the provided name as a detail for the 136 * #GtkAppChooserButton::custom-item-activated signal, to add a 137 * callback for the activation of a particular custom item in the list. 138 * See also gtk_app_chooser_button_append_separator(). 139 * 140 * Params: 141 * name = the name of the custom item 142 * label = the label for the custom item 143 * icon = the icon for the custom item 144 * 145 * Since: 3.0 146 */ 147 public void appendCustomItem(string name, string label, IconIF icon) 148 { 149 gtk_app_chooser_button_append_custom_item(gtkAppChooserButton, Str.toStringz(name), Str.toStringz(label), (icon is null) ? null : icon.getIconStruct()); 150 } 151 152 /** 153 * Appends a separator to the list of applications that is shown 154 * in the popup. 155 * 156 * Since: 3.0 157 */ 158 public void appendSeparator() 159 { 160 gtk_app_chooser_button_append_separator(gtkAppChooserButton); 161 } 162 163 /** 164 * Returns the text to display at the top of the dialog. 165 * 166 * Return: the text to display at the top of the dialog, 167 * or %NULL, in which case a default text is displayed 168 */ 169 public string getHeading() 170 { 171 return Str.toString(gtk_app_chooser_button_get_heading(gtkAppChooserButton)); 172 } 173 174 /** 175 * Returns the current value of the #GtkAppChooserButton:show-default-item 176 * property. 177 * 178 * Return: the value of #GtkAppChooserButton:show-default-item 179 * 180 * Since: 3.2 181 */ 182 public bool getShowDefaultItem() 183 { 184 return gtk_app_chooser_button_get_show_default_item(gtkAppChooserButton) != 0; 185 } 186 187 /** 188 * Returns the current value of the #GtkAppChooserButton:show-dialog-item 189 * property. 190 * 191 * Return: the value of #GtkAppChooserButton:show-dialog-item 192 * 193 * Since: 3.0 194 */ 195 public bool getShowDialogItem() 196 { 197 return gtk_app_chooser_button_get_show_dialog_item(gtkAppChooserButton) != 0; 198 } 199 200 /** 201 * Selects a custom item previously added with 202 * gtk_app_chooser_button_append_custom_item(). 203 * 204 * Use gtk_app_chooser_refresh() to bring the selection 205 * to its initial state. 206 * 207 * Params: 208 * name = the name of the custom item 209 * 210 * Since: 3.0 211 */ 212 public void setActiveCustomItem(string name) 213 { 214 gtk_app_chooser_button_set_active_custom_item(gtkAppChooserButton, Str.toStringz(name)); 215 } 216 217 /** 218 * Sets the text to display at the top of the dialog. 219 * If the heading is not set, the dialog displays a default text. 220 * 221 * Params: 222 * heading = a string containing Pango markup 223 */ 224 public void setHeading(string heading) 225 { 226 gtk_app_chooser_button_set_heading(gtkAppChooserButton, Str.toStringz(heading)); 227 } 228 229 /** 230 * Sets whether the dropdown menu of this button should show the 231 * default application for the given content type at top. 232 * 233 * Params: 234 * setting = the new value for #GtkAppChooserButton:show-default-item 235 * 236 * Since: 3.2 237 */ 238 public void setShowDefaultItem(bool setting) 239 { 240 gtk_app_chooser_button_set_show_default_item(gtkAppChooserButton, setting); 241 } 242 243 /** 244 * Sets whether the dropdown menu of this button should show an 245 * entry to trigger a #GtkAppChooserDialog. 246 * 247 * Params: 248 * setting = the new value for #GtkAppChooserButton:show-dialog-item 249 * 250 * Since: 3.0 251 */ 252 public void setShowDialogItem(bool setting) 253 { 254 gtk_app_chooser_button_set_show_dialog_item(gtkAppChooserButton, setting); 255 } 256 257 int[string] connectedSignals; 258 259 void delegate(string, AppChooserButton)[] onCustomItemActivatedListeners; 260 /** 261 * Emitted when a custom item, previously added with 262 * gtk_app_chooser_button_append_custom_item(), is activated from the 263 * dropdown menu. 264 * 265 * Params: 266 * itemName = the name of the activated item 267 */ 268 void addOnCustomItemActivated(void delegate(string, AppChooserButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 269 { 270 if ( "custom-item-activated" !in connectedSignals ) 271 { 272 Signals.connectData( 273 this, 274 "custom-item-activated", 275 cast(GCallback)&callBackCustomItemActivated, 276 cast(void*)this, 277 null, 278 connectFlags); 279 connectedSignals["custom-item-activated"] = 1; 280 } 281 onCustomItemActivatedListeners ~= dlg; 282 } 283 extern(C) static void callBackCustomItemActivated(GtkAppChooserButton* appchooserbuttonStruct, char* itemName, AppChooserButton _appchooserbutton) 284 { 285 foreach ( void delegate(string, AppChooserButton) dlg; _appchooserbutton.onCustomItemActivatedListeners ) 286 { 287 dlg(Str.toString(itemName), _appchooserbutton); 288 } 289 } 290 }