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.FileChooserNative; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import gobject.ObjectG; 30 private import gtk.FileChooserIF; 31 private import gtk.FileChooserT; 32 private import gtk.NativeDialog; 33 private import gtk.Window; 34 private import gtkc.gtk; 35 public import gtkc.gtktypes; 36 37 38 /** 39 * #GtkFileChooserNative is an abstraction of a dialog box suitable 40 * for use with “File/Open” or “File/Save as” commands. By default, this 41 * just uses a #GtkFileChooserDialog to implement the actual dialog. 42 * However, on certain platforms, such as Windows, the native platform 43 * file chooser is uses instead. When the application is running in a 44 * sandboxed environment without direct filesystem access (such as Flatpak), 45 * #GtkFileChooserNative may call the proper APIs (portals) to let the user 46 * choose a file and make it available to the application. 47 * 48 * While the API of #GtkFileChooserNative closely mirrors #GtkFileChooserDialog, the main 49 * difference is that there is no access to any #GtkWindow or #GtkWidget for the dialog. 50 * This is required, as there may not be one in the case of a platform native dialog. 51 * Showing, hiding and running the dialog is handled by the #GtkNativeDialog functions. 52 * 53 * ## Typical usage ## {#gtkfilechoosernative-typical-usage} 54 * 55 * In the simplest of cases, you can the following code to use 56 * #GtkFileChooserDialog to select a file for opening: 57 * 58 * |[ 59 * GtkFileChooserNative *native; 60 * GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN; 61 * gint res; 62 * 63 * native = gtk_file_chooser_native_new ("Open File", 64 * parent_window, 65 * action, 66 * "_Open", 67 * "_Cancel"); 68 * 69 * res = gtk_native_dialog_run (GTK_NATIVE_DIALOG (native)); 70 * if (res == GTK_RESPONSE_ACCEPT) 71 * { 72 * char *filename; 73 * GtkFileChooser *chooser = GTK_FILE_CHOOSER (native); 74 * filename = gtk_file_chooser_get_filename (chooser); 75 * open_file (filename); 76 * g_free (filename); 77 * } 78 * 79 * g_object_unref (native); 80 * ]| 81 * 82 * To use a dialog for saving, you can use this: 83 * 84 * |[ 85 * GtkFileChooserNative *native; 86 * GtkFileChooser *chooser; 87 * GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE; 88 * gint res; 89 * 90 * native = gtk_file_chooser_native_new ("Save File", 91 * parent_window, 92 * action, 93 * "_Save", 94 * "_Cancel"); 95 * chooser = GTK_FILE_CHOOSER (native); 96 * 97 * gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE); 98 * 99 * if (user_edited_a_new_document) 100 * gtk_file_chooser_set_current_name (chooser, 101 * _("Untitled document")); 102 * else 103 * gtk_file_chooser_set_filename (chooser, 104 * existing_filename); 105 * 106 * res = gtk_native_dialog_run (GTK_NATIVE_DIALOG (native)); 107 * if (res == GTK_RESPONSE_ACCEPT) 108 * { 109 * char *filename; 110 * 111 * filename = gtk_file_chooser_get_filename (chooser); 112 * save_to_file (filename); 113 * g_free (filename); 114 * } 115 * 116 * g_object_unref (native); 117 * ]| 118 * 119 * For more information on how to best set up a file dialog, see #GtkFileChooserDialog. 120 * 121 * ## Response Codes ## {#gtkfilechooserdialognative-responses} 122 * 123 * #GtkFileChooserNative inherits from #GtkNativeDialog, which means it 124 * will return #GTK_RESPONSE_ACCEPT if the user accepted, and 125 * #GTK_RESPONSE_CANCEL if he pressed cancel. It can also return 126 * #GTK_RESPONSE_DELETE_EVENT if the window was unexpectedly closed. 127 * 128 * ## Differences from #GtkFileChooserDialog ## {#gtkfilechooserdialognative-differences} 129 * 130 * There are a few things in the GtkFileChooser API that are not 131 * possible to use with #GtkFileChooserNative, as such use would 132 * prohibit the use of a native dialog. 133 * 134 * There is no support for the signals that are emitted when the user 135 * navigates in the dialog, including: 136 * * #GtkFileChooser::current-folder-changed 137 * * #GtkFileChooser::selection-changed 138 * * #GtkFileChooser::file-activated 139 * * #GtkFileChooser::confirm-overwrite 140 * 141 * You can also not use the methods that directly control user navigation: 142 * * gtk_file_chooser_unselect_filename() 143 * * gtk_file_chooser_select_all() 144 * * gtk_file_chooser_unselect_all() 145 * 146 * If you need any of the above you will have to use #GtkFileChooserDialog directly. 147 * 148 * No operations that change the the dialog work while the dialog is 149 * visible. Set all the properties that are required before showing the dialog. 150 * 151 * ## Win32 details ## {#gtkfilechooserdialognative-win32} 152 * 153 * On windows the IFileDialog implementation (added in Windows Vista) is 154 * used. It supports many of the features that #GtkFileChooserDialog 155 * does, but there are some things it does not handle: 156 * 157 * * Extra widgets added with gtk_file_chooser_set_extra_widget(). 158 * 159 * * Use of custom previews by connecting to #GtkFileChooser::update-preview. 160 * 161 * * Any #GtkFileFilter added using a mimetype or custom filter. 162 * 163 * If any of these features are used the regular #GtkFileChooserDialog 164 * will be used in place of the native one. 165 * 166 * ## Portal details ## {#gtkfilechooserdialognative-portal} 167 * 168 * When the org.freedesktop.portal.FileChooser portal is available on the 169 * session bus, it is used to bring up an out-of-process file chooser. Depending 170 * on the kind of session the application is running in, this may or may not 171 * be a GTK+ file chooser. In this situation, the following things are not 172 * supported and will be silently ignored: 173 * 174 * * Extra widgets added with gtk_file_chooser_set_extra_widget(). 175 * 176 * * Use of custom previews by connecting to #GtkFileChooser::update-preview. 177 * 178 * * Any #GtkFileFilter added with a custom filter. 179 */ 180 public class FileChooserNative : NativeDialog, FileChooserIF 181 { 182 /** the main Gtk struct */ 183 protected GtkFileChooserNative* gtkFileChooserNative; 184 185 /** Get the main Gtk struct */ 186 public GtkFileChooserNative* getFileChooserNativeStruct(bool transferOwnership = false) 187 { 188 if (transferOwnership) 189 ownedRef = false; 190 return gtkFileChooserNative; 191 } 192 193 /** the main Gtk struct as a void* */ 194 protected override void* getStruct() 195 { 196 return cast(void*)gtkFileChooserNative; 197 } 198 199 protected override void setStruct(GObject* obj) 200 { 201 gtkFileChooserNative = cast(GtkFileChooserNative*)obj; 202 super.setStruct(obj); 203 } 204 205 /** 206 * Sets our main struct and passes it to the parent class. 207 */ 208 public this (GtkFileChooserNative* gtkFileChooserNative, bool ownedRef = false) 209 { 210 this.gtkFileChooserNative = gtkFileChooserNative; 211 super(cast(GtkNativeDialog*)gtkFileChooserNative, ownedRef); 212 } 213 214 // add the FileChooser capabilities 215 mixin FileChooserT!(GtkFileChooserNative); 216 217 218 /** */ 219 public static GType getType() 220 { 221 return gtk_file_chooser_native_get_type(); 222 } 223 224 /** 225 * Creates a new #GtkFileChooserNative. 226 * 227 * Params: 228 * title = Title of the native, or %NULL 229 * parent = Transient parent of the native, or %NULL 230 * action = Open or save mode for the dialog 231 * acceptLabel = text to go in the accept button, or %NULL for the default 232 * cancelLabel = text to go in the cancel button, or %NULL for the default 233 * 234 * Returns: a new #GtkFileChooserNative 235 * 236 * Since: 3.20 237 * 238 * Throws: ConstructionException GTK+ fails to create the object. 239 */ 240 public this(string title, Window parent, GtkFileChooserAction action, string acceptLabel, string cancelLabel) 241 { 242 auto p = gtk_file_chooser_native_new(Str.toStringz(title), (parent is null) ? null : parent.getWindowStruct(), action, Str.toStringz(acceptLabel), Str.toStringz(cancelLabel)); 243 244 if(p is null) 245 { 246 throw new ConstructionException("null returned by new"); 247 } 248 249 this(cast(GtkFileChooserNative*) p, true); 250 } 251 252 /** 253 * Retrieves the custom label text for the accept button. 254 * 255 * Returns: The custom label, or %NULL for the default. This string 256 * is owned by GTK+ and should not be modified or freed 257 * 258 * Since: 3.20 259 */ 260 public string getAcceptLabel() 261 { 262 return Str.toString(gtk_file_chooser_native_get_accept_label(gtkFileChooserNative)); 263 } 264 265 /** 266 * Retrieves the custom label text for the cancel button. 267 * 268 * Returns: The custom label, or %NULL for the default. This string 269 * is owned by GTK+ and should not be modified or freed 270 * 271 * Since: 3.20 272 */ 273 public string getCancelLabel() 274 { 275 return Str.toString(gtk_file_chooser_native_get_cancel_label(gtkFileChooserNative)); 276 } 277 278 /** 279 * Sets the custom label text for the accept button. 280 * 281 * If characters in @label are preceded by an underscore, they are underlined. 282 * If you need a literal underscore character in a label, use “__” (two 283 * underscores). The first underlined character represents a keyboard 284 * accelerator called a mnemonic. 285 * Pressing Alt and that key activates the button. 286 * 287 * Params: 288 * acceptLabel = custom label or %NULL for the default 289 * 290 * Since: 3.20 291 */ 292 public void setAcceptLabel(string acceptLabel) 293 { 294 gtk_file_chooser_native_set_accept_label(gtkFileChooserNative, Str.toStringz(acceptLabel)); 295 } 296 297 /** 298 * Sets the custom label text for the cancel button. 299 * 300 * If characters in @label are preceded by an underscore, they are underlined. 301 * If you need a literal underscore character in a label, use “__” (two 302 * underscores). The first underlined character represents a keyboard 303 * accelerator called a mnemonic. 304 * Pressing Alt and that key activates the button. 305 * 306 * Params: 307 * cancelLabel = custom label or %NULL for the default 308 * 309 * Since: 3.20 310 */ 311 public void setCancelLabel(string cancelLabel) 312 { 313 gtk_file_chooser_native_set_cancel_label(gtkFileChooserNative, Str.toStringz(cancelLabel)); 314 } 315 }