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.FileChooserT; 26 27 public import gio.File; 28 public import gio.FileIF; 29 public import glib.ErrorG; 30 public import glib.GException; 31 public import glib.ListSG; 32 public import glib.Str; 33 public import gobject.ObjectG; 34 public import gobject.Signals; 35 public import gtk.FileFilter; 36 public import gtk.Widget; 37 public import gtkc.gdktypes; 38 public import gtkc.gtk; 39 public import gtkc.gtktypes; 40 public import std.algorithm; 41 42 43 /** 44 * #GtkFileChooser is an interface that can be implemented by file 45 * selection widgets. In GTK+, the main objects that implement this 46 * interface are #GtkFileChooserWidget, #GtkFileChooserDialog, and 47 * #GtkFileChooserButton. You do not need to write an object that 48 * implements the #GtkFileChooser interface unless you are trying to 49 * adapt an existing file selector to expose a standard programming 50 * interface. 51 * 52 * #GtkFileChooser allows for shortcuts to various places in the filesystem. 53 * In the default implementation these are displayed in the left pane. It 54 * may be a bit confusing at first that these shortcuts come from various 55 * sources and in various flavours, so lets explain the terminology here: 56 * 57 * - Bookmarks: are created by the user, by dragging folders from the 58 * right pane to the left pane, or by using the “Add”. Bookmarks 59 * can be renamed and deleted by the user. 60 * 61 * - Shortcuts: can be provided by the application. For example, a Paint 62 * program may want to add a shortcut for a Clipart folder. Shortcuts 63 * cannot be modified by the user. 64 * 65 * - Volumes: are provided by the underlying filesystem abstraction. They are 66 * the “roots” of the filesystem. 67 * 68 * # File Names and Encodings 69 * 70 * When the user is finished selecting files in a 71 * #GtkFileChooser, your program can get the selected names 72 * either as filenames or as URIs. For URIs, the normal escaping 73 * rules are applied if the URI contains non-ASCII characters. 74 * However, filenames are always returned in 75 * the character set specified by the 76 * `G_FILENAME_ENCODING` environment variable. 77 * Please see the GLib documentation for more details about this 78 * variable. 79 * 80 * This means that while you can pass the result of 81 * gtk_file_chooser_get_filename() to open() or fopen(), 82 * you may not be able to directly set it as the text of a 83 * #GtkLabel widget unless you convert it first to UTF-8, 84 * which all GTK+ widgets expect. You should use g_filename_to_utf8() 85 * to convert filenames into strings that can be passed to GTK+ 86 * widgets. 87 * 88 * # Adding a Preview Widget 89 * 90 * You can add a custom preview widget to a file chooser and then 91 * get notification about when the preview needs to be updated. 92 * To install a preview widget, use 93 * gtk_file_chooser_set_preview_widget(). Then, connect to the 94 * #GtkFileChooser::update-preview signal to get notified when 95 * you need to update the contents of the preview. 96 * 97 * Your callback should use 98 * gtk_file_chooser_get_preview_filename() to see what needs 99 * previewing. Once you have generated the preview for the 100 * corresponding file, you must call 101 * gtk_file_chooser_set_preview_widget_active() with a boolean 102 * flag that indicates whether your callback could successfully 103 * generate a preview. 104 * 105 * ## Example: Using a Preview Widget ## {#gtkfilechooser-preview} 106 * |[<!-- language="C" --> 107 * { 108 * GtkImage *preview; 109 * 110 * ... 111 * 112 * preview = gtk_image_new (); 113 * 114 * gtk_file_chooser_set_preview_widget (my_file_chooser, preview); 115 * g_signal_connect (my_file_chooser, "update-preview", 116 * G_CALLBACK (update_preview_cb), preview); 117 * } 118 * 119 * static void 120 * update_preview_cb (GtkFileChooser *file_chooser, gpointer data) 121 * { 122 * GtkWidget *preview; 123 * char *filename; 124 * GdkPixbuf *pixbuf; 125 * gboolean have_preview; 126 * 127 * preview = GTK_WIDGET (data); 128 * filename = gtk_file_chooser_get_preview_filename (file_chooser); 129 * 130 * pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 128, 128, NULL); 131 * have_preview = (pixbuf != NULL); 132 * g_free (filename); 133 * 134 * gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf); 135 * if (pixbuf) 136 * g_object_unref (pixbuf); 137 * 138 * gtk_file_chooser_set_preview_widget_active (file_chooser, have_preview); 139 * } 140 * ]| 141 * 142 * # Adding Extra Widgets 143 * 144 * You can add extra widgets to a file chooser to provide options 145 * that are not present in the default design. For example, you 146 * can add a toggle button to give the user the option to open a 147 * file in read-only mode. You can use 148 * gtk_file_chooser_set_extra_widget() to insert additional 149 * widgets in a file chooser. 150 * 151 * An example for adding extra widgets: 152 * |[<!-- language="C" --> 153 * 154 * GtkWidget *toggle; 155 * 156 * ... 157 * 158 * toggle = gtk_check_button_new_with_label ("Open file read-only"); 159 * gtk_widget_show (toggle); 160 * gtk_file_chooser_set_extra_widget (my_file_chooser, toggle); 161 * } 162 * ]| 163 * 164 * If you want to set more than one extra widget in the file 165 * chooser, you can a container such as a #GtkBox or a #GtkGrid 166 * and include your widgets in it. Then, set the container as 167 * the whole extra widget. 168 */ 169 public template FileChooserT(TStruct) 170 { 171 /** Get the main Gtk struct */ 172 public GtkFileChooser* getFileChooserStruct() 173 { 174 return cast(GtkFileChooser*)getStruct(); 175 } 176 177 178 /** 179 * Adds a 'choice' to the file chooser. This is typically implemented 180 * as a combobox or, for boolean choices, as a checkbutton. You can select 181 * a value using gtk_file_chooser_set_choice() before the dialog is shown, 182 * and you can obtain the user-selected value in the ::response signal handler 183 * using gtk_file_chooser_get_choice(). 184 * 185 * Compare gtk_file_chooser_set_extra_widget(). 186 * 187 * Params: 188 * id = id for the added choice 189 * label = user-visible label for the added choice 190 * options = ids for the options of the choice, or %NULL for a boolean choice 191 * optionLabels = user-visible labels for the options, must be the same length as @options 192 * 193 * Since: 3.22 194 */ 195 public void addChoice(string id, string label, string[] options, string[] optionLabels) 196 { 197 gtk_file_chooser_add_choice(getFileChooserStruct(), Str.toStringz(id), Str.toStringz(label), Str.toStringzArray(options), Str.toStringzArray(optionLabels)); 198 } 199 200 /** 201 * Adds @filter to the list of filters that the user can select between. 202 * When a filter is selected, only files that are passed by that 203 * filter are displayed. 204 * 205 * Note that the @chooser takes ownership of the filter, so you have to 206 * ref and sink it if you want to keep a reference. 207 * 208 * Params: 209 * filter = a #GtkFileFilter 210 * 211 * Since: 2.4 212 */ 213 public void addFilter(FileFilter filter) 214 { 215 gtk_file_chooser_add_filter(getFileChooserStruct(), (filter is null) ? null : filter.getFileFilterStruct()); 216 } 217 218 /** 219 * Adds a folder to be displayed with the shortcut folders in a file chooser. 220 * Note that shortcut folders do not get saved, as they are provided by the 221 * application. For example, you can use this to add a 222 * “/usr/share/mydrawprogram/Clipart” folder to the volume list. 223 * 224 * Params: 225 * folder = filename of the folder to add 226 * 227 * Return: %TRUE if the folder could be added successfully, %FALSE 228 * otherwise. In the latter case, the @error will be set as appropriate. 229 * 230 * Since: 2.4 231 * 232 * Throws: GException on failure. 233 */ 234 public bool addShortcutFolder(string folder) 235 { 236 GError* err = null; 237 238 auto p = gtk_file_chooser_add_shortcut_folder(getFileChooserStruct(), Str.toStringz(folder), &err) != 0; 239 240 if (err !is null) 241 { 242 throw new GException( new ErrorG(err) ); 243 } 244 245 return p; 246 } 247 248 /** 249 * Adds a folder URI to be displayed with the shortcut folders in a file 250 * chooser. Note that shortcut folders do not get saved, as they are provided 251 * by the application. For example, you can use this to add a 252 * “file:///usr/share/mydrawprogram/Clipart” folder to the volume list. 253 * 254 * Params: 255 * uri = URI of the folder to add 256 * 257 * Return: %TRUE if the folder could be added successfully, %FALSE 258 * otherwise. In the latter case, the @error will be set as appropriate. 259 * 260 * Since: 2.4 261 * 262 * Throws: GException on failure. 263 */ 264 public bool addShortcutFolderUri(string uri) 265 { 266 GError* err = null; 267 268 auto p = gtk_file_chooser_add_shortcut_folder_uri(getFileChooserStruct(), Str.toStringz(uri), &err) != 0; 269 270 if (err !is null) 271 { 272 throw new GException( new ErrorG(err) ); 273 } 274 275 return p; 276 } 277 278 /** 279 * Gets the type of operation that the file chooser is performing; see 280 * gtk_file_chooser_set_action(). 281 * 282 * Return: the action that the file selector is performing 283 * 284 * Since: 2.4 285 */ 286 public GtkFileChooserAction getFileChooserAction() 287 { 288 return gtk_file_chooser_get_action(getFileChooserStruct()); 289 } 290 291 /** 292 * Gets the currently selected option in the 'choice' with the given ID. 293 * 294 * Params: 295 * id = the ID of the choice to get 296 * 297 * Return: the ID of the currenly selected option 298 * 299 * Since: 3.22 300 */ 301 public string getChoice(string id) 302 { 303 return Str.toString(gtk_file_chooser_get_choice(getFileChooserStruct(), Str.toStringz(id))); 304 } 305 306 /** 307 * Gets whether file choser will offer to create new folders. 308 * See gtk_file_chooser_set_create_folders(). 309 * 310 * Return: %TRUE if the Create Folder button should be displayed. 311 * 312 * Since: 2.18 313 */ 314 public bool getCreateFolders() 315 { 316 return gtk_file_chooser_get_create_folders(getFileChooserStruct()) != 0; 317 } 318 319 /** 320 * Gets the current folder of @chooser as a local filename. 321 * See gtk_file_chooser_set_current_folder(). 322 * 323 * Note that this is the folder that the file chooser is currently displaying 324 * (e.g. "/home/username/Documents"), which is not the same 325 * as the currently-selected folder if the chooser is in 326 * %GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER mode 327 * (e.g. "/home/username/Documents/selected-folder/". To get the 328 * currently-selected folder in that mode, use gtk_file_chooser_get_uri() as the 329 * usual way to get the selection. 330 * 331 * Return: the full path of the current 332 * folder, or %NULL if the current path cannot be represented as a local 333 * filename. Free with g_free(). This function will also return 334 * %NULL if the file chooser was unable to load the last folder that 335 * was requested from it; for example, as would be for calling 336 * gtk_file_chooser_set_current_folder() on a nonexistent folder. 337 * 338 * Since: 2.4 339 */ 340 public string getCurrentFolder() 341 { 342 auto retStr = gtk_file_chooser_get_current_folder(getFileChooserStruct()); 343 344 scope(exit) Str.freeString(retStr); 345 return Str.toString(retStr); 346 } 347 348 /** 349 * Gets the current folder of @chooser as #GFile. 350 * See gtk_file_chooser_get_current_folder_uri(). 351 * 352 * Return: the #GFile for the current folder. 353 * 354 * Since: 2.14 355 */ 356 public FileIF getCurrentFolderFile() 357 { 358 auto p = gtk_file_chooser_get_current_folder_file(getFileChooserStruct()); 359 360 if(p is null) 361 { 362 return null; 363 } 364 365 return ObjectG.getDObject!(File, FileIF)(cast(GFile*) p, true); 366 } 367 368 /** 369 * Gets the current folder of @chooser as an URI. 370 * See gtk_file_chooser_set_current_folder_uri(). 371 * 372 * Note that this is the folder that the file chooser is currently displaying 373 * (e.g. "file:///home/username/Documents"), which is not the same 374 * as the currently-selected folder if the chooser is in 375 * %GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER mode 376 * (e.g. "file:///home/username/Documents/selected-folder/". To get the 377 * currently-selected folder in that mode, use gtk_file_chooser_get_uri() as the 378 * usual way to get the selection. 379 * 380 * Return: the URI for the current folder. 381 * Free with g_free(). This function will also return %NULL if the file chooser 382 * was unable to load the last folder that was requested from it; for example, 383 * as would be for calling gtk_file_chooser_set_current_folder_uri() on a 384 * nonexistent folder. 385 * 386 * Since: 2.4 387 */ 388 public string getCurrentFolderUri() 389 { 390 auto retStr = gtk_file_chooser_get_current_folder_uri(getFileChooserStruct()); 391 392 scope(exit) Str.freeString(retStr); 393 return Str.toString(retStr); 394 } 395 396 /** 397 * Gets the current name in the file selector, as entered by the user in the 398 * text entry for “Name”. 399 * 400 * This is meant to be used in save dialogs, to get the currently typed filename 401 * when the file itself does not exist yet. For example, an application that 402 * adds a custom extra widget to the file chooser for “file format” may want to 403 * change the extension of the typed filename based on the chosen format, say, 404 * from “.jpg” to “.png”. 405 * 406 * Return: The raw text from the file chooser’s “Name” entry. Free this with 407 * g_free(). Note that this string is not a full pathname or URI; it is 408 * whatever the contents of the entry are. Note also that this string is in 409 * UTF-8 encoding, which is not necessarily the system’s encoding for filenames. 410 * 411 * Since: 3.10 412 */ 413 public string getCurrentName() 414 { 415 auto retStr = gtk_file_chooser_get_current_name(getFileChooserStruct()); 416 417 scope(exit) Str.freeString(retStr); 418 return Str.toString(retStr); 419 } 420 421 /** 422 * Queries whether a file chooser is set to confirm for overwriting when the user 423 * types a file name that already exists. 424 * 425 * Return: %TRUE if the file chooser will present a confirmation dialog; 426 * %FALSE otherwise. 427 * 428 * Since: 2.8 429 */ 430 public bool getDoOverwriteConfirmation() 431 { 432 return gtk_file_chooser_get_do_overwrite_confirmation(getFileChooserStruct()) != 0; 433 } 434 435 /** 436 * Gets the current preview widget; see 437 * gtk_file_chooser_set_extra_widget(). 438 * 439 * Return: the current extra widget, or %NULL 440 * 441 * Since: 2.4 442 */ 443 public Widget getExtraWidget() 444 { 445 auto p = gtk_file_chooser_get_extra_widget(getFileChooserStruct()); 446 447 if(p is null) 448 { 449 return null; 450 } 451 452 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 453 } 454 455 /** 456 * Gets the #GFile for the currently selected file in 457 * the file selector. If multiple files are selected, 458 * one of the files will be returned at random. 459 * 460 * If the file chooser is in folder mode, this function returns the selected 461 * folder. 462 * 463 * Return: a selected #GFile. You own the returned file; 464 * use g_object_unref() to release it. 465 * 466 * Since: 2.14 467 */ 468 public FileIF getFile() 469 { 470 auto p = gtk_file_chooser_get_file(getFileChooserStruct()); 471 472 if(p is null) 473 { 474 return null; 475 } 476 477 return ObjectG.getDObject!(File, FileIF)(cast(GFile*) p, true); 478 } 479 480 /** 481 * Gets the filename for the currently selected file in 482 * the file selector. The filename is returned as an absolute path. If 483 * multiple files are selected, one of the filenames will be returned at 484 * random. 485 * 486 * If the file chooser is in folder mode, this function returns the selected 487 * folder. 488 * 489 * Return: The currently selected filename, 490 * or %NULL if no file is selected, or the selected file can't 491 * be represented with a local filename. Free with g_free(). 492 * 493 * Since: 2.4 494 */ 495 public string getFilename() 496 { 497 auto retStr = gtk_file_chooser_get_filename(getFileChooserStruct()); 498 499 scope(exit) Str.freeString(retStr); 500 return Str.toString(retStr); 501 } 502 503 /** 504 * Lists all the selected files and subfolders in the current folder of 505 * @chooser. The returned names are full absolute paths. If files in the current 506 * folder cannot be represented as local filenames they will be ignored. (See 507 * gtk_file_chooser_get_uris()) 508 * 509 * Return: a #GSList 510 * containing the filenames of all selected files and subfolders in 511 * the current folder. Free the returned list with g_slist_free(), 512 * and the filenames with g_free(). 513 * 514 * Since: 2.4 515 */ 516 public ListSG getFilenames() 517 { 518 auto p = gtk_file_chooser_get_filenames(getFileChooserStruct()); 519 520 if(p is null) 521 { 522 return null; 523 } 524 525 return new ListSG(cast(GSList*) p, true); 526 } 527 528 /** 529 * Lists all the selected files and subfolders in the current folder of @chooser 530 * as #GFile. An internal function, see gtk_file_chooser_get_uris(). 531 * 532 * Return: a #GSList 533 * containing a #GFile for each selected file and subfolder in the 534 * current folder. Free the returned list with g_slist_free(), and 535 * the files with g_object_unref(). 536 * 537 * Since: 2.14 538 */ 539 public ListSG getFiles() 540 { 541 auto p = gtk_file_chooser_get_files(getFileChooserStruct()); 542 543 if(p is null) 544 { 545 return null; 546 } 547 548 return new ListSG(cast(GSList*) p, true); 549 } 550 551 /** 552 * Gets the current filter; see gtk_file_chooser_set_filter(). 553 * 554 * Return: the current filter, or %NULL 555 * 556 * Since: 2.4 557 */ 558 public FileFilter getFilter() 559 { 560 auto p = gtk_file_chooser_get_filter(getFileChooserStruct()); 561 562 if(p is null) 563 { 564 return null; 565 } 566 567 return ObjectG.getDObject!(FileFilter)(cast(GtkFileFilter*) p); 568 } 569 570 /** 571 * Gets whether only local files can be selected in the 572 * file selector. See gtk_file_chooser_set_local_only() 573 * 574 * Return: %TRUE if only local files can be selected. 575 * 576 * Since: 2.4 577 */ 578 public bool getLocalOnly() 579 { 580 return gtk_file_chooser_get_local_only(getFileChooserStruct()) != 0; 581 } 582 583 /** 584 * Gets the #GFile that should be previewed in a custom preview 585 * Internal function, see gtk_file_chooser_get_preview_uri(). 586 * 587 * Return: the #GFile for the file to preview, 588 * or %NULL if no file is selected. Free with g_object_unref(). 589 * 590 * Since: 2.14 591 */ 592 public FileIF getPreviewFile() 593 { 594 auto p = gtk_file_chooser_get_preview_file(getFileChooserStruct()); 595 596 if(p is null) 597 { 598 return null; 599 } 600 601 return ObjectG.getDObject!(File, FileIF)(cast(GFile*) p, true); 602 } 603 604 /** 605 * Gets the filename that should be previewed in a custom preview 606 * widget. See gtk_file_chooser_set_preview_widget(). 607 * 608 * Return: the filename to preview, or %NULL if 609 * no file is selected, or if the selected file cannot be represented 610 * as a local filename. Free with g_free() 611 * 612 * Since: 2.4 613 */ 614 public string getPreviewFilename() 615 { 616 auto retStr = gtk_file_chooser_get_preview_filename(getFileChooserStruct()); 617 618 scope(exit) Str.freeString(retStr); 619 return Str.toString(retStr); 620 } 621 622 /** 623 * Gets the URI that should be previewed in a custom preview 624 * widget. See gtk_file_chooser_set_preview_widget(). 625 * 626 * Return: the URI for the file to preview, 627 * or %NULL if no file is selected. Free with g_free(). 628 * 629 * Since: 2.4 630 */ 631 public string getPreviewUri() 632 { 633 auto retStr = gtk_file_chooser_get_preview_uri(getFileChooserStruct()); 634 635 scope(exit) Str.freeString(retStr); 636 return Str.toString(retStr); 637 } 638 639 /** 640 * Gets the current preview widget; see 641 * gtk_file_chooser_set_preview_widget(). 642 * 643 * Return: the current preview widget, or %NULL 644 * 645 * Since: 2.4 646 */ 647 public Widget getPreviewWidget() 648 { 649 auto p = gtk_file_chooser_get_preview_widget(getFileChooserStruct()); 650 651 if(p is null) 652 { 653 return null; 654 } 655 656 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 657 } 658 659 /** 660 * Gets whether the preview widget set by gtk_file_chooser_set_preview_widget() 661 * should be shown for the current filename. See 662 * gtk_file_chooser_set_preview_widget_active(). 663 * 664 * Return: %TRUE if the preview widget is active for the current filename. 665 * 666 * Since: 2.4 667 */ 668 public bool getPreviewWidgetActive() 669 { 670 return gtk_file_chooser_get_preview_widget_active(getFileChooserStruct()) != 0; 671 } 672 673 /** 674 * Gets whether multiple files can be selected in the file 675 * selector. See gtk_file_chooser_set_select_multiple(). 676 * 677 * Return: %TRUE if multiple files can be selected. 678 * 679 * Since: 2.4 680 */ 681 public bool getSelectMultiple() 682 { 683 return gtk_file_chooser_get_select_multiple(getFileChooserStruct()) != 0; 684 } 685 686 /** 687 * Gets whether hidden files and folders are displayed in the file selector. 688 * See gtk_file_chooser_set_show_hidden(). 689 * 690 * Return: %TRUE if hidden files and folders are displayed. 691 * 692 * Since: 2.6 693 */ 694 public bool getShowHidden() 695 { 696 return gtk_file_chooser_get_show_hidden(getFileChooserStruct()) != 0; 697 } 698 699 /** 700 * Gets the URI for the currently selected file in 701 * the file selector. If multiple files are selected, 702 * one of the filenames will be returned at random. 703 * 704 * If the file chooser is in folder mode, this function returns the selected 705 * folder. 706 * 707 * Return: The currently selected URI, or %NULL 708 * if no file is selected. If gtk_file_chooser_set_local_only() is set to 709 * %TRUE (the default) a local URI will be returned for any FUSE locations. 710 * Free with g_free() 711 * 712 * Since: 2.4 713 */ 714 public string getUri() 715 { 716 auto retStr = gtk_file_chooser_get_uri(getFileChooserStruct()); 717 718 scope(exit) Str.freeString(retStr); 719 return Str.toString(retStr); 720 } 721 722 /** 723 * Lists all the selected files and subfolders in the current folder of 724 * @chooser. The returned names are full absolute URIs. 725 * 726 * Return: a #GSList containing the URIs of all selected 727 * files and subfolders in the current folder. Free the returned list 728 * with g_slist_free(), and the filenames with g_free(). 729 * 730 * Since: 2.4 731 */ 732 public ListSG getUris() 733 { 734 auto p = gtk_file_chooser_get_uris(getFileChooserStruct()); 735 736 if(p is null) 737 { 738 return null; 739 } 740 741 return new ListSG(cast(GSList*) p, true); 742 } 743 744 /** 745 * Gets whether a stock label should be drawn with the name of the previewed 746 * file. See gtk_file_chooser_set_use_preview_label(). 747 * 748 * Return: %TRUE if the file chooser is set to display a label with the 749 * name of the previewed file, %FALSE otherwise. 750 */ 751 public bool getUsePreviewLabel() 752 { 753 return gtk_file_chooser_get_use_preview_label(getFileChooserStruct()) != 0; 754 } 755 756 /** 757 * Lists the current set of user-selectable filters; see 758 * gtk_file_chooser_add_filter(), gtk_file_chooser_remove_filter(). 759 * 760 * Return: a 761 * #GSList containing the current set of user selectable filters. The 762 * contents of the list are owned by GTK+, but you must free the list 763 * itself with g_slist_free() when you are done with it. 764 * 765 * Since: 2.4 766 */ 767 public ListSG listFilters() 768 { 769 auto p = gtk_file_chooser_list_filters(getFileChooserStruct()); 770 771 if(p is null) 772 { 773 return null; 774 } 775 776 return new ListSG(cast(GSList*) p); 777 } 778 779 /** 780 * Queries the list of shortcut folders in the file chooser, as set by 781 * gtk_file_chooser_add_shortcut_folder_uri(). 782 * 783 * Return: A list of 784 * folder URIs, or %NULL if there are no shortcut folders. Free the 785 * returned list with g_slist_free(), and the URIs with g_free(). 786 * 787 * Since: 2.4 788 */ 789 public ListSG listShortcutFolderUris() 790 { 791 auto p = gtk_file_chooser_list_shortcut_folder_uris(getFileChooserStruct()); 792 793 if(p is null) 794 { 795 return null; 796 } 797 798 return new ListSG(cast(GSList*) p, true); 799 } 800 801 /** 802 * Queries the list of shortcut folders in the file chooser, as set by 803 * gtk_file_chooser_add_shortcut_folder(). 804 * 805 * Return: A list 806 * of folder filenames, or %NULL if there are no shortcut folders. 807 * Free the returned list with g_slist_free(), and the filenames with 808 * g_free(). 809 * 810 * Since: 2.4 811 */ 812 public ListSG listShortcutFolders() 813 { 814 auto p = gtk_file_chooser_list_shortcut_folders(getFileChooserStruct()); 815 816 if(p is null) 817 { 818 return null; 819 } 820 821 return new ListSG(cast(GSList*) p, true); 822 } 823 824 /** 825 * Removes a 'choice' that has been added with gtk_file_chooser_add_choice(). 826 * 827 * Params: 828 * id = the ID of the choice to remove 829 * 830 * Since: 3.22 831 */ 832 public void removeChoice(string id) 833 { 834 gtk_file_chooser_remove_choice(getFileChooserStruct(), Str.toStringz(id)); 835 } 836 837 /** 838 * Removes @filter from the list of filters that the user can select between. 839 * 840 * Params: 841 * filter = a #GtkFileFilter 842 * 843 * Since: 2.4 844 */ 845 public void removeFilter(FileFilter filter) 846 { 847 gtk_file_chooser_remove_filter(getFileChooserStruct(), (filter is null) ? null : filter.getFileFilterStruct()); 848 } 849 850 /** 851 * Removes a folder from a file chooser’s list of shortcut folders. 852 * 853 * Params: 854 * folder = filename of the folder to remove 855 * 856 * Return: %TRUE if the operation succeeds, %FALSE otherwise. 857 * In the latter case, the @error will be set as appropriate. 858 * 859 * See also: gtk_file_chooser_add_shortcut_folder() 860 * 861 * Since: 2.4 862 * 863 * Throws: GException on failure. 864 */ 865 public bool removeShortcutFolder(string folder) 866 { 867 GError* err = null; 868 869 auto p = gtk_file_chooser_remove_shortcut_folder(getFileChooserStruct(), Str.toStringz(folder), &err) != 0; 870 871 if (err !is null) 872 { 873 throw new GException( new ErrorG(err) ); 874 } 875 876 return p; 877 } 878 879 /** 880 * Removes a folder URI from a file chooser’s list of shortcut folders. 881 * 882 * Params: 883 * uri = URI of the folder to remove 884 * 885 * Return: %TRUE if the operation succeeds, %FALSE otherwise. 886 * In the latter case, the @error will be set as appropriate. 887 * 888 * See also: gtk_file_chooser_add_shortcut_folder_uri() 889 * 890 * Since: 2.4 891 * 892 * Throws: GException on failure. 893 */ 894 public bool removeShortcutFolderUri(string uri) 895 { 896 GError* err = null; 897 898 auto p = gtk_file_chooser_remove_shortcut_folder_uri(getFileChooserStruct(), Str.toStringz(uri), &err) != 0; 899 900 if (err !is null) 901 { 902 throw new GException( new ErrorG(err) ); 903 } 904 905 return p; 906 } 907 908 /** 909 * Selects all the files in the current folder of a file chooser. 910 * 911 * Since: 2.4 912 */ 913 public void selectAll() 914 { 915 gtk_file_chooser_select_all(getFileChooserStruct()); 916 } 917 918 /** 919 * Selects the file referred to by @file. An internal function. See 920 * _gtk_file_chooser_select_uri(). 921 * 922 * Params: 923 * file = the file to select 924 * 925 * Return: Not useful. 926 * 927 * Since: 2.14 928 * 929 * Throws: GException on failure. 930 */ 931 public bool selectFile(FileIF file) 932 { 933 GError* err = null; 934 935 auto p = gtk_file_chooser_select_file(getFileChooserStruct(), (file is null) ? null : file.getFileStruct(), &err) != 0; 936 937 if (err !is null) 938 { 939 throw new GException( new ErrorG(err) ); 940 } 941 942 return p; 943 } 944 945 /** 946 * Selects a filename. If the file name isn’t in the current 947 * folder of @chooser, then the current folder of @chooser will 948 * be changed to the folder containing @filename. 949 * 950 * Params: 951 * filename = the filename to select 952 * 953 * Return: Not useful. 954 * 955 * See also: gtk_file_chooser_set_filename() 956 * 957 * Since: 2.4 958 */ 959 public bool selectFilename(string filename) 960 { 961 return gtk_file_chooser_select_filename(getFileChooserStruct(), Str.toStringz(filename)) != 0; 962 } 963 964 /** 965 * Selects the file to by @uri. If the URI doesn’t refer to a 966 * file in the current folder of @chooser, then the current folder of 967 * @chooser will be changed to the folder containing @filename. 968 * 969 * Params: 970 * uri = the URI to select 971 * 972 * Return: Not useful. 973 * 974 * Since: 2.4 975 */ 976 public bool selectUri(string uri) 977 { 978 return gtk_file_chooser_select_uri(getFileChooserStruct(), Str.toStringz(uri)) != 0; 979 } 980 981 /** 982 * Sets the type of operation that the chooser is performing; the 983 * user interface is adapted to suit the selected action. For example, 984 * an option to create a new folder might be shown if the action is 985 * %GTK_FILE_CHOOSER_ACTION_SAVE but not if the action is 986 * %GTK_FILE_CHOOSER_ACTION_OPEN. 987 * 988 * Params: 989 * action = the action that the file selector is performing 990 * 991 * Since: 2.4 992 */ 993 public void setFileChooserAction(GtkFileChooserAction action) 994 { 995 gtk_file_chooser_set_action(getFileChooserStruct(), action); 996 } 997 998 /** 999 * Selects an option in a 'choice' that has been added with 1000 * gtk_file_chooser_add_choice(). For a boolean choice, the 1001 * possible options are "true" and "false". 1002 * 1003 * Params: 1004 * id = the ID of the choice to set 1005 * option = the ID of the option to select 1006 * 1007 * Since: 3.22 1008 */ 1009 public void setChoice(string id, string option) 1010 { 1011 gtk_file_chooser_set_choice(getFileChooserStruct(), Str.toStringz(id), Str.toStringz(option)); 1012 } 1013 1014 /** 1015 * Sets whether file choser will offer to create new folders. 1016 * This is only relevant if the action is not set to be 1017 * %GTK_FILE_CHOOSER_ACTION_OPEN. 1018 * 1019 * Params: 1020 * createFolders = %TRUE if the Create Folder button should be displayed 1021 * 1022 * Since: 2.18 1023 */ 1024 public void setCreateFolders(bool createFolders) 1025 { 1026 gtk_file_chooser_set_create_folders(getFileChooserStruct(), createFolders); 1027 } 1028 1029 /** 1030 * Sets the current folder for @chooser from a local filename. 1031 * The user will be shown the full contents of the current folder, 1032 * plus user interface elements for navigating to other folders. 1033 * 1034 * In general, you should not use this function. See the 1035 * [section on setting up a file chooser dialog][gtkfilechooserdialog-setting-up] 1036 * for the rationale behind this. 1037 * 1038 * Params: 1039 * filename = the full path of the new current folder 1040 * 1041 * Return: Not useful. 1042 * 1043 * Since: 2.4 1044 */ 1045 public bool setCurrentFolder(string filename) 1046 { 1047 return gtk_file_chooser_set_current_folder(getFileChooserStruct(), Str.toStringz(filename)) != 0; 1048 } 1049 1050 /** 1051 * Sets the current folder for @chooser from a #GFile. 1052 * Internal function, see gtk_file_chooser_set_current_folder_uri(). 1053 * 1054 * Params: 1055 * file = the #GFile for the new folder 1056 * 1057 * Return: %TRUE if the folder could be changed successfully, %FALSE 1058 * otherwise. 1059 * 1060 * Since: 2.14 1061 * 1062 * Throws: GException on failure. 1063 */ 1064 public bool setCurrentFolderFile(FileIF file) 1065 { 1066 GError* err = null; 1067 1068 auto p = gtk_file_chooser_set_current_folder_file(getFileChooserStruct(), (file is null) ? null : file.getFileStruct(), &err) != 0; 1069 1070 if (err !is null) 1071 { 1072 throw new GException( new ErrorG(err) ); 1073 } 1074 1075 return p; 1076 } 1077 1078 /** 1079 * Sets the current folder for @chooser from an URI. 1080 * The user will be shown the full contents of the current folder, 1081 * plus user interface elements for navigating to other folders. 1082 * 1083 * In general, you should not use this function. See the 1084 * [section on setting up a file chooser dialog][gtkfilechooserdialog-setting-up] 1085 * for the rationale behind this. 1086 * 1087 * Params: 1088 * uri = the URI for the new current folder 1089 * 1090 * Return: %TRUE if the folder could be changed successfully, %FALSE 1091 * otherwise. 1092 * 1093 * Since: 2.4 1094 */ 1095 public bool setCurrentFolderUri(string uri) 1096 { 1097 return gtk_file_chooser_set_current_folder_uri(getFileChooserStruct(), Str.toStringz(uri)) != 0; 1098 } 1099 1100 /** 1101 * Sets the current name in the file selector, as if entered 1102 * by the user. Note that the name passed in here is a UTF-8 1103 * string rather than a filename. This function is meant for 1104 * such uses as a suggested name in a “Save As...” dialog. You can 1105 * pass “Untitled.doc” or a similarly suitable suggestion for the @name. 1106 * 1107 * If you want to preselect a particular existing file, you should use 1108 * gtk_file_chooser_set_filename() or gtk_file_chooser_set_uri() instead. 1109 * Please see the documentation for those functions for an example of using 1110 * gtk_file_chooser_set_current_name() as well. 1111 * 1112 * Params: 1113 * name = the filename to use, as a UTF-8 string 1114 * 1115 * Since: 2.4 1116 */ 1117 public void setCurrentName(string name) 1118 { 1119 gtk_file_chooser_set_current_name(getFileChooserStruct(), Str.toStringz(name)); 1120 } 1121 1122 /** 1123 * Sets whether a file chooser in %GTK_FILE_CHOOSER_ACTION_SAVE mode will present 1124 * a confirmation dialog if the user types a file name that already exists. This 1125 * is %FALSE by default. 1126 * 1127 * If set to %TRUE, the @chooser will emit the 1128 * #GtkFileChooser::confirm-overwrite signal when appropriate. 1129 * 1130 * If all you need is the stock confirmation dialog, set this property to %TRUE. 1131 * You can override the way confirmation is done by actually handling the 1132 * #GtkFileChooser::confirm-overwrite signal; please refer to its documentation 1133 * for the details. 1134 * 1135 * Params: 1136 * doOverwriteConfirmation = whether to confirm overwriting in save mode 1137 * 1138 * Since: 2.8 1139 */ 1140 public void setDoOverwriteConfirmation(bool doOverwriteConfirmation) 1141 { 1142 gtk_file_chooser_set_do_overwrite_confirmation(getFileChooserStruct(), doOverwriteConfirmation); 1143 } 1144 1145 /** 1146 * Sets an application-supplied widget to provide extra options to the user. 1147 * 1148 * Params: 1149 * extraWidget = widget for extra options 1150 * 1151 * Since: 2.4 1152 */ 1153 public void setExtraWidget(Widget extraWidget) 1154 { 1155 gtk_file_chooser_set_extra_widget(getFileChooserStruct(), (extraWidget is null) ? null : extraWidget.getWidgetStruct()); 1156 } 1157 1158 /** 1159 * Sets @file as the current filename for the file chooser, by changing 1160 * to the file’s parent folder and actually selecting the file in list. If 1161 * the @chooser is in %GTK_FILE_CHOOSER_ACTION_SAVE mode, the file’s base name 1162 * will also appear in the dialog’s file name entry. 1163 * 1164 * If the file name isn’t in the current folder of @chooser, then the current 1165 * folder of @chooser will be changed to the folder containing @filename. This 1166 * is equivalent to a sequence of gtk_file_chooser_unselect_all() followed by 1167 * gtk_file_chooser_select_filename(). 1168 * 1169 * Note that the file must exist, or nothing will be done except 1170 * for the directory change. 1171 * 1172 * If you are implementing a save dialog, 1173 * you should use this function if you already have a file name to which the 1174 * user may save; for example, when the user opens an existing file and then 1175 * does Save As... If you don’t have 1176 * a file name already — for example, if the user just created a new 1177 * file and is saving it for the first time, do not call this function. 1178 * Instead, use something similar to this: 1179 * |[<!-- language="C" --> 1180 * if (document_is_new) 1181 * { 1182 * // the user just created a new document 1183 * gtk_file_chooser_set_current_folder_file (chooser, default_file_for_saving); 1184 * gtk_file_chooser_set_current_name (chooser, "Untitled document"); 1185 * } 1186 * else 1187 * { 1188 * // the user edited an existing document 1189 * gtk_file_chooser_set_file (chooser, existing_file); 1190 * } 1191 * ]| 1192 * 1193 * Params: 1194 * file = the #GFile to set as current 1195 * 1196 * Return: Not useful. 1197 * 1198 * Since: 2.14 1199 * 1200 * Throws: GException on failure. 1201 */ 1202 public bool setFile(FileIF file) 1203 { 1204 GError* err = null; 1205 1206 auto p = gtk_file_chooser_set_file(getFileChooserStruct(), (file is null) ? null : file.getFileStruct(), &err) != 0; 1207 1208 if (err !is null) 1209 { 1210 throw new GException( new ErrorG(err) ); 1211 } 1212 1213 return p; 1214 } 1215 1216 /** 1217 * Sets @filename as the current filename for the file chooser, by changing to 1218 * the file’s parent folder and actually selecting the file in list; all other 1219 * files will be unselected. If the @chooser is in 1220 * %GTK_FILE_CHOOSER_ACTION_SAVE mode, the file’s base name will also appear in 1221 * the dialog’s file name entry. 1222 * 1223 * Note that the file must exist, or nothing will be done except 1224 * for the directory change. 1225 * 1226 * You should use this function only when implementing a save 1227 * dialog for which you already have a file name to which 1228 * the user may save. For example, when the user opens an existing file and 1229 * then does Save As... to save a copy or 1230 * a modified version. If you don’t have a file name already — for 1231 * example, if the user just created a new file and is saving it for the first 1232 * time, do not call this function. Instead, use something similar to this: 1233 * |[<!-- language="C" --> 1234 * if (document_is_new) 1235 * { 1236 * // the user just created a new document 1237 * gtk_file_chooser_set_current_name (chooser, "Untitled document"); 1238 * } 1239 * else 1240 * { 1241 * // the user edited an existing document 1242 * gtk_file_chooser_set_filename (chooser, existing_filename); 1243 * } 1244 * ]| 1245 * 1246 * In the first case, the file chooser will present the user with useful suggestions 1247 * as to where to save his new file. In the second case, the file’s existing location 1248 * is already known, so the file chooser will use it. 1249 * 1250 * Params: 1251 * filename = the filename to set as current 1252 * 1253 * Return: Not useful. 1254 * 1255 * Since: 2.4 1256 */ 1257 public bool setFilename(string filename) 1258 { 1259 return gtk_file_chooser_set_filename(getFileChooserStruct(), Str.toStringz(filename)) != 0; 1260 } 1261 1262 /** 1263 * Sets the current filter; only the files that pass the 1264 * filter will be displayed. If the user-selectable list of filters 1265 * is non-empty, then the filter should be one of the filters 1266 * in that list. Setting the current filter when the list of 1267 * filters is empty is useful if you want to restrict the displayed 1268 * set of files without letting the user change it. 1269 * 1270 * Params: 1271 * filter = a #GtkFileFilter 1272 * 1273 * Since: 2.4 1274 */ 1275 public void setFilter(FileFilter filter) 1276 { 1277 gtk_file_chooser_set_filter(getFileChooserStruct(), (filter is null) ? null : filter.getFileFilterStruct()); 1278 } 1279 1280 /** 1281 * Sets whether only local files can be selected in the 1282 * file selector. If @local_only is %TRUE (the default), 1283 * then the selected file or files are guaranteed to be 1284 * accessible through the operating systems native file 1285 * system and therefore the application only 1286 * needs to worry about the filename functions in 1287 * #GtkFileChooser, like gtk_file_chooser_get_filename(), 1288 * rather than the URI functions like 1289 * gtk_file_chooser_get_uri(), 1290 * 1291 * On some systems non-native files may still be 1292 * available using the native filesystem via a userspace 1293 * filesystem (FUSE). 1294 * 1295 * Params: 1296 * localOnly = %TRUE if only local files can be selected 1297 * 1298 * Since: 2.4 1299 */ 1300 public void setLocalOnly(bool localOnly) 1301 { 1302 gtk_file_chooser_set_local_only(getFileChooserStruct(), localOnly); 1303 } 1304 1305 /** 1306 * Sets an application-supplied widget to use to display a custom preview 1307 * of the currently selected file. To implement a preview, after setting the 1308 * preview widget, you connect to the #GtkFileChooser::update-preview 1309 * signal, and call gtk_file_chooser_get_preview_filename() or 1310 * gtk_file_chooser_get_preview_uri() on each change. If you can 1311 * display a preview of the new file, update your widget and 1312 * set the preview active using gtk_file_chooser_set_preview_widget_active(). 1313 * Otherwise, set the preview inactive. 1314 * 1315 * When there is no application-supplied preview widget, or the 1316 * application-supplied preview widget is not active, the file chooser 1317 * will display no preview at all. 1318 * 1319 * Params: 1320 * previewWidget = widget for displaying preview. 1321 * 1322 * Since: 2.4 1323 */ 1324 public void setPreviewWidget(Widget previewWidget) 1325 { 1326 gtk_file_chooser_set_preview_widget(getFileChooserStruct(), (previewWidget is null) ? null : previewWidget.getWidgetStruct()); 1327 } 1328 1329 /** 1330 * Sets whether the preview widget set by 1331 * gtk_file_chooser_set_preview_widget() should be shown for the 1332 * current filename. When @active is set to false, the file chooser 1333 * may display an internally generated preview of the current file 1334 * or it may display no preview at all. See 1335 * gtk_file_chooser_set_preview_widget() for more details. 1336 * 1337 * Params: 1338 * active = whether to display the user-specified preview widget 1339 * 1340 * Since: 2.4 1341 */ 1342 public void setPreviewWidgetActive(bool active) 1343 { 1344 gtk_file_chooser_set_preview_widget_active(getFileChooserStruct(), active); 1345 } 1346 1347 /** 1348 * Sets whether multiple files can be selected in the file selector. This is 1349 * only relevant if the action is set to be %GTK_FILE_CHOOSER_ACTION_OPEN or 1350 * %GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER. 1351 * 1352 * Params: 1353 * selectMultiple = %TRUE if multiple files can be selected. 1354 * 1355 * Since: 2.4 1356 */ 1357 public void setSelectMultiple(bool selectMultiple) 1358 { 1359 gtk_file_chooser_set_select_multiple(getFileChooserStruct(), selectMultiple); 1360 } 1361 1362 /** 1363 * Sets whether hidden files and folders are displayed in the file selector. 1364 * 1365 * Params: 1366 * showHidden = %TRUE if hidden files and folders should be displayed. 1367 * 1368 * Since: 2.6 1369 */ 1370 public void setShowHidden(bool showHidden) 1371 { 1372 gtk_file_chooser_set_show_hidden(getFileChooserStruct(), showHidden); 1373 } 1374 1375 /** 1376 * Sets the file referred to by @uri as the current file for the file chooser, 1377 * by changing to the URI’s parent folder and actually selecting the URI in the 1378 * list. If the @chooser is %GTK_FILE_CHOOSER_ACTION_SAVE mode, the URI’s base 1379 * name will also appear in the dialog’s file name entry. 1380 * 1381 * Note that the URI must exist, or nothing will be done except for the 1382 * directory change. 1383 * 1384 * You should use this function only when implementing a save 1385 * dialog for which you already have a file name to which 1386 * the user may save. For example, when the user opens an existing file and then 1387 * does Save As... to save a copy or a 1388 * modified version. If you don’t have a file name already — for example, 1389 * if the user just created a new file and is saving it for the first time, do 1390 * not call this function. Instead, use something similar to this: 1391 * |[<!-- language="C" --> 1392 * if (document_is_new) 1393 * { 1394 * // the user just created a new document 1395 * gtk_file_chooser_set_current_name (chooser, "Untitled document"); 1396 * } 1397 * else 1398 * { 1399 * // the user edited an existing document 1400 * gtk_file_chooser_set_uri (chooser, existing_uri); 1401 * } 1402 * ]| 1403 * 1404 * 1405 * In the first case, the file chooser will present the user with useful suggestions 1406 * as to where to save his new file. In the second case, the file’s existing location 1407 * is already known, so the file chooser will use it. 1408 * 1409 * Params: 1410 * uri = the URI to set as current 1411 * 1412 * Return: Not useful. 1413 * 1414 * Since: 2.4 1415 */ 1416 public bool setUri(string uri) 1417 { 1418 return gtk_file_chooser_set_uri(getFileChooserStruct(), Str.toStringz(uri)) != 0; 1419 } 1420 1421 /** 1422 * Sets whether the file chooser should display a stock label with the name of 1423 * the file that is being previewed; the default is %TRUE. Applications that 1424 * want to draw the whole preview area themselves should set this to %FALSE and 1425 * display the name themselves in their preview widget. 1426 * 1427 * See also: gtk_file_chooser_set_preview_widget() 1428 * 1429 * Params: 1430 * useLabel = whether to display a stock label with the name of the previewed file 1431 * 1432 * Since: 2.4 1433 */ 1434 public void setUsePreviewLabel(bool useLabel) 1435 { 1436 gtk_file_chooser_set_use_preview_label(getFileChooserStruct(), useLabel); 1437 } 1438 1439 /** 1440 * Unselects all the files in the current folder of a file chooser. 1441 * 1442 * Since: 2.4 1443 */ 1444 public void unselectAll() 1445 { 1446 gtk_file_chooser_unselect_all(getFileChooserStruct()); 1447 } 1448 1449 /** 1450 * Unselects the file referred to by @file. If the file is not in the current 1451 * directory, does not exist, or is otherwise not currently selected, does nothing. 1452 * 1453 * Params: 1454 * file = a #GFile 1455 * 1456 * Since: 2.14 1457 */ 1458 public void unselectFile(FileIF file) 1459 { 1460 gtk_file_chooser_unselect_file(getFileChooserStruct(), (file is null) ? null : file.getFileStruct()); 1461 } 1462 1463 /** 1464 * Unselects a currently selected filename. If the filename 1465 * is not in the current directory, does not exist, or 1466 * is otherwise not currently selected, does nothing. 1467 * 1468 * Params: 1469 * filename = the filename to unselect 1470 * 1471 * Since: 2.4 1472 */ 1473 public void unselectFilename(string filename) 1474 { 1475 gtk_file_chooser_unselect_filename(getFileChooserStruct(), Str.toStringz(filename)); 1476 } 1477 1478 /** 1479 * Unselects the file referred to by @uri. If the file 1480 * is not in the current directory, does not exist, or 1481 * is otherwise not currently selected, does nothing. 1482 * 1483 * Params: 1484 * uri = the URI to unselect 1485 * 1486 * Since: 2.4 1487 */ 1488 public void unselectUri(string uri) 1489 { 1490 gtk_file_chooser_unselect_uri(getFileChooserStruct(), Str.toStringz(uri)); 1491 } 1492 1493 protected class OnConfirmOverwriteDelegateWrapper 1494 { 1495 GtkFileChooserConfirmation delegate(FileChooserIF) dlg; 1496 gulong handlerId; 1497 ConnectFlags flags; 1498 this(GtkFileChooserConfirmation delegate(FileChooserIF) dlg, gulong handlerId, ConnectFlags flags) 1499 { 1500 this.dlg = dlg; 1501 this.handlerId = handlerId; 1502 this.flags = flags; 1503 } 1504 } 1505 protected OnConfirmOverwriteDelegateWrapper[] onConfirmOverwriteListeners; 1506 1507 /** 1508 * This signal gets emitted whenever it is appropriate to present a 1509 * confirmation dialog when the user has selected a file name that 1510 * already exists. The signal only gets emitted when the file 1511 * chooser is in %GTK_FILE_CHOOSER_ACTION_SAVE mode. 1512 * 1513 * Most applications just need to turn on the 1514 * #GtkFileChooser:do-overwrite-confirmation property (or call the 1515 * gtk_file_chooser_set_do_overwrite_confirmation() function), and 1516 * they will automatically get a stock confirmation dialog. 1517 * Applications which need to customize this behavior should do 1518 * that, and also connect to the #GtkFileChooser::confirm-overwrite 1519 * signal. 1520 * 1521 * A signal handler for this signal must return a 1522 * #GtkFileChooserConfirmation value, which indicates the action to 1523 * take. If the handler determines that the user wants to select a 1524 * different filename, it should return 1525 * %GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN. If it determines 1526 * that the user is satisfied with his choice of file name, it 1527 * should return %GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME. 1528 * On the other hand, if it determines that the stock confirmation 1529 * dialog should be used, it should return 1530 * %GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM. The following example 1531 * illustrates this. 1532 * 1533 * ## Custom confirmation ## {#gtkfilechooser-confirmation} 1534 * 1535 * |[<!-- language="C" --> 1536 * static GtkFileChooserConfirmation 1537 * confirm_overwrite_callback (GtkFileChooser *chooser, gpointer data) 1538 * { 1539 * char *uri; 1540 * 1541 * uri = gtk_file_chooser_get_uri (chooser); 1542 * 1543 * if (is_uri_read_only (uri)) 1544 * { 1545 * if (user_wants_to_replace_read_only_file (uri)) 1546 * return GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME; 1547 * else 1548 * return GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN; 1549 * } else 1550 * return GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM; // fall back to the default dialog 1551 * } 1552 * 1553 * ... 1554 * 1555 * chooser = gtk_file_chooser_dialog_new (...); 1556 * 1557 * gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE); 1558 * g_signal_connect (chooser, "confirm-overwrite", 1559 * G_CALLBACK (confirm_overwrite_callback), NULL); 1560 * 1561 * if (gtk_dialog_run (chooser) == GTK_RESPONSE_ACCEPT) 1562 * save_to_file (gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser)); 1563 * 1564 * gtk_widget_destroy (chooser); 1565 * ]| 1566 * 1567 * Return: a #GtkFileChooserConfirmation value that indicates which 1568 * action to take after emitting the signal. 1569 * 1570 * Since: 2.8 1571 */ 1572 gulong addOnConfirmOverwrite(GtkFileChooserConfirmation delegate(FileChooserIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1573 { 1574 onConfirmOverwriteListeners ~= new OnConfirmOverwriteDelegateWrapper(dlg, 0, connectFlags); 1575 onConfirmOverwriteListeners[onConfirmOverwriteListeners.length - 1].handlerId = Signals.connectData( 1576 this, 1577 "confirm-overwrite", 1578 cast(GCallback)&callBackConfirmOverwrite, 1579 cast(void*)onConfirmOverwriteListeners[onConfirmOverwriteListeners.length - 1], 1580 cast(GClosureNotify)&callBackConfirmOverwriteDestroy, 1581 connectFlags); 1582 return onConfirmOverwriteListeners[onConfirmOverwriteListeners.length - 1].handlerId; 1583 } 1584 1585 extern(C) static GtkFileChooserConfirmation callBackConfirmOverwrite(GtkFileChooser* filechooserStruct,OnConfirmOverwriteDelegateWrapper wrapper) 1586 { 1587 return wrapper.dlg(wrapper.outer); 1588 } 1589 1590 extern(C) static void callBackConfirmOverwriteDestroy(OnConfirmOverwriteDelegateWrapper wrapper, GClosure* closure) 1591 { 1592 wrapper.outer.internalRemoveOnConfirmOverwrite(wrapper); 1593 } 1594 1595 protected void internalRemoveOnConfirmOverwrite(OnConfirmOverwriteDelegateWrapper source) 1596 { 1597 foreach(index, wrapper; onConfirmOverwriteListeners) 1598 { 1599 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 1600 { 1601 onConfirmOverwriteListeners[index] = null; 1602 onConfirmOverwriteListeners = std.algorithm.remove(onConfirmOverwriteListeners, index); 1603 break; 1604 } 1605 } 1606 } 1607 1608 1609 protected class OnCurrentFolderChangedDelegateWrapper 1610 { 1611 void delegate(FileChooserIF) dlg; 1612 gulong handlerId; 1613 ConnectFlags flags; 1614 this(void delegate(FileChooserIF) dlg, gulong handlerId, ConnectFlags flags) 1615 { 1616 this.dlg = dlg; 1617 this.handlerId = handlerId; 1618 this.flags = flags; 1619 } 1620 } 1621 protected OnCurrentFolderChangedDelegateWrapper[] onCurrentFolderChangedListeners; 1622 1623 /** 1624 * This signal is emitted when the current folder in a #GtkFileChooser 1625 * changes. This can happen due to the user performing some action that 1626 * changes folders, such as selecting a bookmark or visiting a folder on the 1627 * file list. It can also happen as a result of calling a function to 1628 * explicitly change the current folder in a file chooser. 1629 * 1630 * Normally you do not need to connect to this signal, unless you need to keep 1631 * track of which folder a file chooser is showing. 1632 * 1633 * See also: gtk_file_chooser_set_current_folder(), 1634 * gtk_file_chooser_get_current_folder(), 1635 * gtk_file_chooser_set_current_folder_uri(), 1636 * gtk_file_chooser_get_current_folder_uri(). 1637 */ 1638 gulong addOnCurrentFolderChanged(void delegate(FileChooserIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1639 { 1640 onCurrentFolderChangedListeners ~= new OnCurrentFolderChangedDelegateWrapper(dlg, 0, connectFlags); 1641 onCurrentFolderChangedListeners[onCurrentFolderChangedListeners.length - 1].handlerId = Signals.connectData( 1642 this, 1643 "current-folder-changed", 1644 cast(GCallback)&callBackCurrentFolderChanged, 1645 cast(void*)onCurrentFolderChangedListeners[onCurrentFolderChangedListeners.length - 1], 1646 cast(GClosureNotify)&callBackCurrentFolderChangedDestroy, 1647 connectFlags); 1648 return onCurrentFolderChangedListeners[onCurrentFolderChangedListeners.length - 1].handlerId; 1649 } 1650 1651 extern(C) static void callBackCurrentFolderChanged(GtkFileChooser* filechooserStruct,OnCurrentFolderChangedDelegateWrapper wrapper) 1652 { 1653 wrapper.dlg(wrapper.outer); 1654 } 1655 1656 extern(C) static void callBackCurrentFolderChangedDestroy(OnCurrentFolderChangedDelegateWrapper wrapper, GClosure* closure) 1657 { 1658 wrapper.outer.internalRemoveOnCurrentFolderChanged(wrapper); 1659 } 1660 1661 protected void internalRemoveOnCurrentFolderChanged(OnCurrentFolderChangedDelegateWrapper source) 1662 { 1663 foreach(index, wrapper; onCurrentFolderChangedListeners) 1664 { 1665 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 1666 { 1667 onCurrentFolderChangedListeners[index] = null; 1668 onCurrentFolderChangedListeners = std.algorithm.remove(onCurrentFolderChangedListeners, index); 1669 break; 1670 } 1671 } 1672 } 1673 1674 1675 protected class OnFileActivatedDelegateWrapper 1676 { 1677 void delegate(FileChooserIF) dlg; 1678 gulong handlerId; 1679 ConnectFlags flags; 1680 this(void delegate(FileChooserIF) dlg, gulong handlerId, ConnectFlags flags) 1681 { 1682 this.dlg = dlg; 1683 this.handlerId = handlerId; 1684 this.flags = flags; 1685 } 1686 } 1687 protected OnFileActivatedDelegateWrapper[] onFileActivatedListeners; 1688 1689 /** 1690 * This signal is emitted when the user "activates" a file in the file 1691 * chooser. This can happen by double-clicking on a file in the file list, or 1692 * by pressing `Enter`. 1693 * 1694 * Normally you do not need to connect to this signal. It is used internally 1695 * by #GtkFileChooserDialog to know when to activate the default button in the 1696 * dialog. 1697 * 1698 * See also: gtk_file_chooser_get_filename(), 1699 * gtk_file_chooser_get_filenames(), gtk_file_chooser_get_uri(), 1700 * gtk_file_chooser_get_uris(). 1701 */ 1702 gulong addOnFileActivated(void delegate(FileChooserIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1703 { 1704 onFileActivatedListeners ~= new OnFileActivatedDelegateWrapper(dlg, 0, connectFlags); 1705 onFileActivatedListeners[onFileActivatedListeners.length - 1].handlerId = Signals.connectData( 1706 this, 1707 "file-activated", 1708 cast(GCallback)&callBackFileActivated, 1709 cast(void*)onFileActivatedListeners[onFileActivatedListeners.length - 1], 1710 cast(GClosureNotify)&callBackFileActivatedDestroy, 1711 connectFlags); 1712 return onFileActivatedListeners[onFileActivatedListeners.length - 1].handlerId; 1713 } 1714 1715 extern(C) static void callBackFileActivated(GtkFileChooser* filechooserStruct,OnFileActivatedDelegateWrapper wrapper) 1716 { 1717 wrapper.dlg(wrapper.outer); 1718 } 1719 1720 extern(C) static void callBackFileActivatedDestroy(OnFileActivatedDelegateWrapper wrapper, GClosure* closure) 1721 { 1722 wrapper.outer.internalRemoveOnFileActivated(wrapper); 1723 } 1724 1725 protected void internalRemoveOnFileActivated(OnFileActivatedDelegateWrapper source) 1726 { 1727 foreach(index, wrapper; onFileActivatedListeners) 1728 { 1729 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 1730 { 1731 onFileActivatedListeners[index] = null; 1732 onFileActivatedListeners = std.algorithm.remove(onFileActivatedListeners, index); 1733 break; 1734 } 1735 } 1736 } 1737 1738 1739 protected class OnSelectionChangedDelegateWrapper 1740 { 1741 void delegate(FileChooserIF) dlg; 1742 gulong handlerId; 1743 ConnectFlags flags; 1744 this(void delegate(FileChooserIF) dlg, gulong handlerId, ConnectFlags flags) 1745 { 1746 this.dlg = dlg; 1747 this.handlerId = handlerId; 1748 this.flags = flags; 1749 } 1750 } 1751 protected OnSelectionChangedDelegateWrapper[] onSelectionChangedListeners; 1752 1753 /** 1754 * This signal is emitted when there is a change in the set of selected files 1755 * in a #GtkFileChooser. This can happen when the user modifies the selection 1756 * with the mouse or the keyboard, or when explicitly calling functions to 1757 * change the selection. 1758 * 1759 * Normally you do not need to connect to this signal, as it is easier to wait 1760 * for the file chooser to finish running, and then to get the list of 1761 * selected files using the functions mentioned below. 1762 * 1763 * See also: gtk_file_chooser_select_filename(), 1764 * gtk_file_chooser_unselect_filename(), gtk_file_chooser_get_filename(), 1765 * gtk_file_chooser_get_filenames(), gtk_file_chooser_select_uri(), 1766 * gtk_file_chooser_unselect_uri(), gtk_file_chooser_get_uri(), 1767 * gtk_file_chooser_get_uris(). 1768 */ 1769 gulong addOnSelectionChanged(void delegate(FileChooserIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1770 { 1771 onSelectionChangedListeners ~= new OnSelectionChangedDelegateWrapper(dlg, 0, connectFlags); 1772 onSelectionChangedListeners[onSelectionChangedListeners.length - 1].handlerId = Signals.connectData( 1773 this, 1774 "selection-changed", 1775 cast(GCallback)&callBackSelectionChanged, 1776 cast(void*)onSelectionChangedListeners[onSelectionChangedListeners.length - 1], 1777 cast(GClosureNotify)&callBackSelectionChangedDestroy, 1778 connectFlags); 1779 return onSelectionChangedListeners[onSelectionChangedListeners.length - 1].handlerId; 1780 } 1781 1782 extern(C) static void callBackSelectionChanged(GtkFileChooser* filechooserStruct,OnSelectionChangedDelegateWrapper wrapper) 1783 { 1784 wrapper.dlg(wrapper.outer); 1785 } 1786 1787 extern(C) static void callBackSelectionChangedDestroy(OnSelectionChangedDelegateWrapper wrapper, GClosure* closure) 1788 { 1789 wrapper.outer.internalRemoveOnSelectionChanged(wrapper); 1790 } 1791 1792 protected void internalRemoveOnSelectionChanged(OnSelectionChangedDelegateWrapper source) 1793 { 1794 foreach(index, wrapper; onSelectionChangedListeners) 1795 { 1796 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 1797 { 1798 onSelectionChangedListeners[index] = null; 1799 onSelectionChangedListeners = std.algorithm.remove(onSelectionChangedListeners, index); 1800 break; 1801 } 1802 } 1803 } 1804 1805 1806 protected class OnUpdatePreviewDelegateWrapper 1807 { 1808 void delegate(FileChooserIF) dlg; 1809 gulong handlerId; 1810 ConnectFlags flags; 1811 this(void delegate(FileChooserIF) dlg, gulong handlerId, ConnectFlags flags) 1812 { 1813 this.dlg = dlg; 1814 this.handlerId = handlerId; 1815 this.flags = flags; 1816 } 1817 } 1818 protected OnUpdatePreviewDelegateWrapper[] onUpdatePreviewListeners; 1819 1820 /** 1821 * This signal is emitted when the preview in a file chooser should be 1822 * regenerated. For example, this can happen when the currently selected file 1823 * changes. You should use this signal if you want your file chooser to have 1824 * a preview widget. 1825 * 1826 * Once you have installed a preview widget with 1827 * gtk_file_chooser_set_preview_widget(), you should update it when this 1828 * signal is emitted. You can use the functions 1829 * gtk_file_chooser_get_preview_filename() or 1830 * gtk_file_chooser_get_preview_uri() to get the name of the file to preview. 1831 * Your widget may not be able to preview all kinds of files; your callback 1832 * must call gtk_file_chooser_set_preview_widget_active() to inform the file 1833 * chooser about whether the preview was generated successfully or not. 1834 * 1835 * Please see the example code in 1836 * [Using a Preview Widget][gtkfilechooser-preview]. 1837 * 1838 * See also: gtk_file_chooser_set_preview_widget(), 1839 * gtk_file_chooser_set_preview_widget_active(), 1840 * gtk_file_chooser_set_use_preview_label(), 1841 * gtk_file_chooser_get_preview_filename(), 1842 * gtk_file_chooser_get_preview_uri(). 1843 */ 1844 gulong addOnUpdatePreview(void delegate(FileChooserIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1845 { 1846 onUpdatePreviewListeners ~= new OnUpdatePreviewDelegateWrapper(dlg, 0, connectFlags); 1847 onUpdatePreviewListeners[onUpdatePreviewListeners.length - 1].handlerId = Signals.connectData( 1848 this, 1849 "update-preview", 1850 cast(GCallback)&callBackUpdatePreview, 1851 cast(void*)onUpdatePreviewListeners[onUpdatePreviewListeners.length - 1], 1852 cast(GClosureNotify)&callBackUpdatePreviewDestroy, 1853 connectFlags); 1854 return onUpdatePreviewListeners[onUpdatePreviewListeners.length - 1].handlerId; 1855 } 1856 1857 extern(C) static void callBackUpdatePreview(GtkFileChooser* filechooserStruct,OnUpdatePreviewDelegateWrapper wrapper) 1858 { 1859 wrapper.dlg(wrapper.outer); 1860 } 1861 1862 extern(C) static void callBackUpdatePreviewDestroy(OnUpdatePreviewDelegateWrapper wrapper, GClosure* closure) 1863 { 1864 wrapper.outer.internalRemoveOnUpdatePreview(wrapper); 1865 } 1866 1867 protected void internalRemoveOnUpdatePreview(OnUpdatePreviewDelegateWrapper source) 1868 { 1869 foreach(index, wrapper; onUpdatePreviewListeners) 1870 { 1871 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 1872 { 1873 onUpdatePreviewListeners[index] = null; 1874 onUpdatePreviewListeners = std.algorithm.remove(onUpdatePreviewListeners, index); 1875 break; 1876 } 1877 } 1878 } 1879 1880 }