1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 2 -*- */
3 /* GTK+: gtkfilechooserbutton.c
5 * Copyright (c) 2004 James M. Cape <jcape@ignore-your.tv>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
25 #include <sys/types.h>
34 #include "gtkbutton.h"
35 #include "gtkcelllayout.h"
36 #include "gtkcellrenderertext.h"
37 #include "gtkcellrendererpixbuf.h"
38 #include "gtkcombobox.h"
40 #include "gtkicontheme.h"
41 #include "gtkiconfactory.h"
44 #include "gtkliststore.h"
46 #include "gtktreemodelfilter.h"
47 #include "gtkvseparator.h"
48 #include "gtkfilechooserdialog.h"
49 #include "gtkfilechooserprivate.h"
50 #include "gtkfilechooserutils.h"
52 #include "gtkfilechooserbutton.h"
55 #include "gtkfilesystemwin32.h"
58 #include "gtkprivate.h"
65 #define GTK_FILE_CHOOSER_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_FILE_CHOOSER_BUTTON, GtkFileChooserButtonPrivate))
67 #define DEFAULT_TITLE N_("Select A File")
68 #define DESKTOP_DISPLAY_NAME N_("Desktop")
69 #define FALLBACK_DISPLAY_NAME N_("(None)")
70 #define FALLBACK_ICON_NAME "stock_unknown"
71 #define FALLBACK_ICON_SIZE 16
74 /* ********************** *
75 * Private Enumerations *
76 * ********************** */
89 /* TreeModel Columns */
101 /* TreeModel Row Types */
107 ROW_TYPE_BOOKMARK_SEPARATOR,
109 ROW_TYPE_CURRENT_FOLDER_SEPARATOR,
110 ROW_TYPE_CURRENT_FOLDER,
111 ROW_TYPE_OTHER_SEPARATOR,
114 ROW_TYPE_INVALID = -1
119 /* ******************** *
120 * Private Structures *
121 * ******************** */
123 struct _GtkFileChooserButtonPrivate
129 GtkWidget *combo_box;
130 GtkCellRenderer *icon_cell;
131 GtkCellRenderer *name_cell;
134 GtkTreeModel *filter_model;
138 GtkFilePath *old_path;
140 gulong combo_box_changed_id;
141 gulong dialog_file_activated_id;
142 gulong dialog_folder_changed_id;
143 gulong dialog_selection_changed_id;
144 gulong fs_volumes_changed_id;
145 gulong fs_bookmarks_changed_id;
147 GtkFileSystemHandle *dnd_select_folder_handle;
148 GtkFileSystemHandle *update_button_handle;
149 GSList *change_icon_theme_handles;
157 guint8 has_bookmark_separator : 1;
158 guint8 has_current_folder_separator : 1;
159 guint8 has_current_folder : 1;
160 guint8 has_other_separator : 1;
162 /* Used for hiding/showing the dialog when the button is hidden */
165 /* Used to remember whether a title has been set yet, so we can use the default if it has not been set. */
166 guint8 has_title : 1;
168 /* Used to track whether we need to set a default current folder on ::map() */
169 guint8 folder_has_been_set : 1;
171 guint8 focus_on_click : 1;
186 /* ********************* *
187 * Function Prototypes *
188 * ********************* */
190 /* GtkFileChooserIface Functions */
191 static void gtk_file_chooser_button_file_chooser_iface_init (GtkFileChooserIface *iface);
192 static gboolean gtk_file_chooser_button_add_shortcut_folder (GtkFileChooser *chooser,
193 const GtkFilePath *path,
195 static gboolean gtk_file_chooser_button_remove_shortcut_folder (GtkFileChooser *chooser,
196 const GtkFilePath *path,
199 /* GObject Functions */
200 static GObject *gtk_file_chooser_button_constructor (GType type,
202 GObjectConstructParam *params);
203 static void gtk_file_chooser_button_set_property (GObject *object,
207 static void gtk_file_chooser_button_get_property (GObject *object,
211 static void gtk_file_chooser_button_finalize (GObject *object);
213 /* GtkObject Functions */
214 static void gtk_file_chooser_button_destroy (GtkObject *object);
216 /* GtkWidget Functions */
217 static void gtk_file_chooser_button_drag_data_received (GtkWidget *widget,
218 GdkDragContext *context,
221 GtkSelectionData *data,
224 static void gtk_file_chooser_button_show_all (GtkWidget *widget);
225 static void gtk_file_chooser_button_hide_all (GtkWidget *widget);
226 static void gtk_file_chooser_button_show (GtkWidget *widget);
227 static void gtk_file_chooser_button_hide (GtkWidget *widget);
228 static void gtk_file_chooser_button_map (GtkWidget *widget);
229 static gboolean gtk_file_chooser_button_mnemonic_activate (GtkWidget *widget,
230 gboolean group_cycling);
231 static void gtk_file_chooser_button_style_set (GtkWidget *widget,
232 GtkStyle *old_style);
233 static void gtk_file_chooser_button_screen_changed (GtkWidget *widget,
234 GdkScreen *old_screen);
236 /* Utility Functions */
237 static GtkIconTheme *get_icon_theme (GtkWidget *widget);
238 static void set_info_for_path_at_iter (GtkFileChooserButton *fs,
239 const GtkFilePath *path,
242 static gint model_get_type_position (GtkFileChooserButton *button,
244 static void model_free_row_data (GtkFileChooserButton *button,
246 static inline void model_add_special (GtkFileChooserButton *button);
247 static inline void model_add_other (GtkFileChooserButton *button);
248 static void model_add_volumes (GtkFileChooserButton *button,
250 static void model_add_bookmarks (GtkFileChooserButton *button,
252 static void model_update_current_folder (GtkFileChooserButton *button,
253 const GtkFilePath *path);
254 static void model_remove_rows (GtkFileChooserButton *button,
258 static gboolean filter_model_visible_func (GtkTreeModel *model,
262 static gboolean combo_box_row_separator_func (GtkTreeModel *model,
265 static void name_cell_data_func (GtkCellLayout *layout,
266 GtkCellRenderer *cell,
270 static void open_dialog (GtkFileChooserButton *button);
271 static void update_combo_box (GtkFileChooserButton *button);
272 static void update_label_and_image (GtkFileChooserButton *button);
274 /* Child Object Callbacks */
275 static void fs_volumes_changed_cb (GtkFileSystem *fs,
277 static void fs_bookmarks_changed_cb (GtkFileSystem *fs,
280 static void combo_box_changed_cb (GtkComboBox *combo_box,
283 static void button_clicked_cb (GtkButton *real_button,
286 static void dialog_update_preview_cb (GtkFileChooser *dialog,
288 static void dialog_selection_changed_cb (GtkFileChooser *dialog,
290 static void dialog_file_activated_cb (GtkFileChooser *dialog,
292 static void dialog_current_folder_changed_cb (GtkFileChooser *dialog,
294 static void dialog_notify_cb (GObject *dialog,
297 static gboolean dialog_delete_event_cb (GtkWidget *dialog,
300 static void dialog_response_cb (GtkDialog *dialog,
305 /* ******************* *
306 * GType Declaration *
307 * ******************* */
309 G_DEFINE_TYPE_WITH_CODE (GtkFileChooserButton, gtk_file_chooser_button, GTK_TYPE_HBOX, { \
310 G_IMPLEMENT_INTERFACE (GTK_TYPE_FILE_CHOOSER, gtk_file_chooser_button_file_chooser_iface_init) \
314 /* ***************** *
316 * ***************** */
319 gtk_file_chooser_button_class_init (GtkFileChooserButtonClass * class)
321 GObjectClass *gobject_class;
322 GtkObjectClass *gtkobject_class;
323 GtkWidgetClass *widget_class;
325 gobject_class = G_OBJECT_CLASS (class);
326 gtkobject_class = GTK_OBJECT_CLASS (class);
327 widget_class = GTK_WIDGET_CLASS (class);
329 gobject_class->constructor = gtk_file_chooser_button_constructor;
330 gobject_class->set_property = gtk_file_chooser_button_set_property;
331 gobject_class->get_property = gtk_file_chooser_button_get_property;
332 gobject_class->finalize = gtk_file_chooser_button_finalize;
334 gtkobject_class->destroy = gtk_file_chooser_button_destroy;
336 widget_class->drag_data_received = gtk_file_chooser_button_drag_data_received;
337 widget_class->show_all = gtk_file_chooser_button_show_all;
338 widget_class->hide_all = gtk_file_chooser_button_hide_all;
339 widget_class->show = gtk_file_chooser_button_show;
340 widget_class->hide = gtk_file_chooser_button_hide;
341 widget_class->map = gtk_file_chooser_button_map;
342 widget_class->style_set = gtk_file_chooser_button_style_set;
343 widget_class->screen_changed = gtk_file_chooser_button_screen_changed;
344 widget_class->mnemonic_activate = gtk_file_chooser_button_mnemonic_activate;
347 * GtkFileChooserButton:dialog:
349 * Instance of the #GtkFileChooserDialog associated with the button.
353 g_object_class_install_property (gobject_class, PROP_DIALOG,
354 g_param_spec_object ("dialog",
356 P_("The file chooser dialog to use."),
357 GTK_TYPE_FILE_CHOOSER_DIALOG,
358 (GTK_PARAM_WRITABLE |
359 G_PARAM_CONSTRUCT_ONLY)));
362 * GtkFileChooserButton:focus-on-click:
364 * Whether the #GtkFileChooserButton button grabs focus when it is clicked
369 g_object_class_install_property (gobject_class,
371 g_param_spec_boolean ("focus-on-click",
372 P_("Focus on click"),
373 P_("Whether the button grabs focus when it is clicked with the mouse"),
375 GTK_PARAM_READWRITE));
378 * GtkFileChooserButton:title:
380 * Title to put on the #GtkFileChooserDialog associated with the button.
384 g_object_class_install_property (gobject_class, PROP_TITLE,
385 g_param_spec_string ("title",
387 P_("The title of the file chooser dialog."),
389 GTK_PARAM_READWRITE));
392 * GtkFileChooserButton:width-chars:
394 * The width of the entry and label inside the button, in characters.
398 g_object_class_install_property (gobject_class, PROP_WIDTH_CHARS,
399 g_param_spec_int ("width-chars",
400 P_("Width In Characters"),
401 P_("The desired width of the button widget, in characters."),
403 GTK_PARAM_READWRITE));
405 _gtk_file_chooser_install_properties (gobject_class);
407 g_type_class_add_private (class, sizeof (GtkFileChooserButtonPrivate));
411 gtk_file_chooser_button_init (GtkFileChooserButton *button)
413 GtkFileChooserButtonPrivate *priv;
414 GtkWidget *box, *image, *sep;
415 GtkTargetList *target_list;
417 priv = button->priv = GTK_FILE_CHOOSER_BUTTON_GET_PRIVATE (button);
419 priv->icon_size = FALLBACK_ICON_SIZE;
420 priv->focus_on_click = TRUE;
422 gtk_widget_push_composite_child ();
425 priv->button = gtk_button_new ();
426 g_signal_connect (priv->button, "clicked", G_CALLBACK (button_clicked_cb),
428 gtk_container_add (GTK_CONTAINER (button), priv->button);
429 gtk_widget_show (priv->button);
431 box = gtk_hbox_new (FALSE, 4);
432 gtk_container_add (GTK_CONTAINER (priv->button), box);
433 gtk_widget_show (box);
435 priv->image = gtk_image_new ();
436 gtk_box_pack_start (GTK_BOX (box), priv->image, FALSE, FALSE, 0);
437 gtk_widget_show (priv->image);
439 priv->label = gtk_label_new (_(FALLBACK_DISPLAY_NAME));
440 gtk_label_set_ellipsize (GTK_LABEL (priv->label), PANGO_ELLIPSIZE_END);
441 gtk_misc_set_alignment (GTK_MISC (priv->label), 0.0, 0.5);
442 gtk_container_add (GTK_CONTAINER (box), priv->label);
443 gtk_widget_show (priv->label);
445 sep = gtk_vseparator_new ();
446 gtk_box_pack_start (GTK_BOX (box), sep, FALSE, FALSE, 0);
447 gtk_widget_show (sep);
449 image = gtk_image_new_from_stock (GTK_STOCK_OPEN,
451 gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 0);
452 gtk_widget_show (image);
455 /* Keep in sync with columns enum, line 88 */
457 GTK_TREE_MODEL (gtk_list_store_new (NUM_COLUMNS,
458 GDK_TYPE_PIXBUF, /* Icon */
459 G_TYPE_STRING, /* Display Name */
460 G_TYPE_CHAR, /* Row Type */
461 G_TYPE_POINTER /* Volume || Path */,
462 G_TYPE_BOOLEAN /* Is Folder? */,
463 G_TYPE_POINTER /* handle */));
465 priv->combo_box = gtk_combo_box_new ();
466 priv->combo_box_changed_id =
467 g_signal_connect (priv->combo_box, "changed",
468 G_CALLBACK (combo_box_changed_cb), button);
469 gtk_container_add (GTK_CONTAINER (button), priv->combo_box);
471 priv->icon_cell = gtk_cell_renderer_pixbuf_new ();
472 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->combo_box),
473 priv->icon_cell, FALSE);
474 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (priv->combo_box),
475 priv->icon_cell, "pixbuf", ICON_COLUMN);
477 priv->name_cell = gtk_cell_renderer_text_new ();
478 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->combo_box),
479 priv->name_cell, TRUE);
480 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (priv->combo_box),
481 priv->name_cell, "text", DISPLAY_NAME_COLUMN);
482 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (priv->combo_box),
483 priv->name_cell, name_cell_data_func,
486 gtk_widget_pop_composite_child ();
489 gtk_drag_dest_set (GTK_WIDGET (button),
490 (GTK_DEST_DEFAULT_ALL),
493 target_list = gtk_target_list_new (NULL, 0);
494 gtk_target_list_add_uri_targets (target_list, TEXT_URI_LIST);
495 gtk_target_list_add_text_targets (target_list, TEXT_PLAIN);
496 gtk_drag_dest_set_target_list (GTK_WIDGET (button), target_list);
497 gtk_target_list_unref (target_list);
501 /* ******************************* *
502 * GtkFileChooserIface Functions *
503 * ******************************* */
505 gtk_file_chooser_button_file_chooser_iface_init (GtkFileChooserIface *iface)
507 _gtk_file_chooser_delegate_iface_init (iface);
509 iface->add_shortcut_folder = gtk_file_chooser_button_add_shortcut_folder;
510 iface->remove_shortcut_folder = gtk_file_chooser_button_remove_shortcut_folder;
514 gtk_file_chooser_button_add_shortcut_folder (GtkFileChooser *chooser,
515 const GtkFilePath *path,
518 GtkFileChooser *delegate;
521 delegate = g_object_get_qdata (G_OBJECT (chooser),
522 GTK_FILE_CHOOSER_DELEGATE_QUARK);
523 retval = _gtk_file_chooser_add_shortcut_folder (delegate, path, error);
527 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (chooser);
528 GtkFileChooserButtonPrivate *priv = button->priv;
532 pos = model_get_type_position (button, ROW_TYPE_SHORTCUT);
533 pos += priv->n_shortcuts;
535 gtk_list_store_insert (GTK_LIST_STORE (priv->model), &iter, pos);
536 gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter,
538 DISPLAY_NAME_COLUMN, _(FALLBACK_DISPLAY_NAME),
539 TYPE_COLUMN, ROW_TYPE_SHORTCUT,
540 DATA_COLUMN, gtk_file_path_copy (path),
541 IS_FOLDER_COLUMN, FALSE,
543 set_info_for_path_at_iter (button, path, &iter);
546 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter_model));
553 gtk_file_chooser_button_remove_shortcut_folder (GtkFileChooser *chooser,
554 const GtkFilePath *path,
557 GtkFileChooser *delegate;
560 delegate = g_object_get_qdata (G_OBJECT (chooser),
561 GTK_FILE_CHOOSER_DELEGATE_QUARK);
563 retval = _gtk_file_chooser_remove_shortcut_folder (delegate, path, error);
567 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (chooser);
568 GtkFileChooserButtonPrivate *priv = button->priv;
573 pos = model_get_type_position (button, ROW_TYPE_SHORTCUT);
574 gtk_tree_model_iter_nth_child (priv->model, &iter, NULL, pos);
580 gtk_tree_model_get (priv->model, &iter,
585 if (type == ROW_TYPE_SHORTCUT &&
587 gtk_file_path_compare (data, path) == 0)
589 model_free_row_data (GTK_FILE_CHOOSER_BUTTON (chooser), &iter);
590 gtk_list_store_remove (GTK_LIST_STORE (priv->model), &iter);
592 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter_model));
593 update_combo_box (GTK_FILE_CHOOSER_BUTTON (chooser));
597 while (type == ROW_TYPE_SHORTCUT &&
598 gtk_tree_model_iter_next (priv->model, &iter));
605 /* ******************* *
606 * GObject Functions *
607 * ******************* */
610 gtk_file_chooser_button_constructor (GType type,
612 GObjectConstructParam *params)
615 GtkFileChooserButton *button;
616 GtkFileChooserButtonPrivate *priv;
618 char *current_folder;
620 object = (*G_OBJECT_CLASS (gtk_file_chooser_button_parent_class)->constructor) (type,
623 button = GTK_FILE_CHOOSER_BUTTON (object);
629 priv->dialog = gtk_file_chooser_dialog_new_with_backend (NULL, NULL,
630 GTK_FILE_CHOOSER_ACTION_OPEN,
638 priv->dialog = gtk_file_chooser_dialog_new (NULL, NULL,
639 GTK_FILE_CHOOSER_ACTION_OPEN,
646 gtk_dialog_set_default_response (GTK_DIALOG (priv->dialog),
647 GTK_RESPONSE_ACCEPT);
648 gtk_dialog_set_alternative_button_order (GTK_DIALOG (priv->dialog),
654 /* Set the default title if necessary. We must wait until the dialog has been created to do this. */
655 if (!priv->has_title)
656 gtk_file_chooser_button_set_title (button, _(DEFAULT_TITLE));
658 current_folder = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (priv->dialog));
659 if (current_folder != NULL)
661 priv->folder_has_been_set = TRUE;
662 g_free (current_folder);
665 g_free (priv->backend);
666 priv->backend = NULL;
668 g_signal_connect (priv->dialog, "delete_event",
669 G_CALLBACK (dialog_delete_event_cb), object);
670 g_signal_connect (priv->dialog, "response",
671 G_CALLBACK (dialog_response_cb), object);
673 /* This is used, instead of the standard delegate, to ensure that signals are only
674 * delegated when the OK button is pressed. */
675 g_object_set_qdata (object, GTK_FILE_CHOOSER_DELEGATE_QUARK, priv->dialog);
676 priv->dialog_folder_changed_id =
677 g_signal_connect (priv->dialog, "current-folder-changed",
678 G_CALLBACK (dialog_current_folder_changed_cb), object);
679 priv->dialog_file_activated_id =
680 g_signal_connect (priv->dialog, "file-activated",
681 G_CALLBACK (dialog_file_activated_cb), object);
682 priv->dialog_selection_changed_id =
683 g_signal_connect (priv->dialog, "selection-changed",
684 G_CALLBACK (dialog_selection_changed_cb), object);
685 g_signal_connect (priv->dialog, "update-preview",
686 G_CALLBACK (dialog_update_preview_cb), object);
687 g_signal_connect (priv->dialog, "notify",
688 G_CALLBACK (dialog_notify_cb), object);
689 g_object_add_weak_pointer (G_OBJECT (priv->dialog),
690 (gpointer *) (&priv->dialog));
693 g_object_ref (_gtk_file_chooser_get_file_system (GTK_FILE_CHOOSER (priv->dialog)));
695 model_add_special (button);
697 list = gtk_file_system_list_volumes (priv->fs);
698 model_add_volumes (button, list);
701 list = gtk_file_system_list_bookmarks (priv->fs);
702 model_add_bookmarks (button, list);
703 gtk_file_paths_free (list);
705 model_add_other (button);
707 priv->filter_model = gtk_tree_model_filter_new (priv->model, NULL);
708 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (priv->filter_model),
709 filter_model_visible_func,
712 gtk_combo_box_set_model (GTK_COMBO_BOX (priv->combo_box), priv->filter_model);
713 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (priv->combo_box),
714 combo_box_row_separator_func,
717 /* set up the action for a user-provided dialog, this also updates
718 * the label, image and combobox
720 g_object_set (object,
721 "action", gtk_file_chooser_get_action (GTK_FILE_CHOOSER (priv->dialog)),
724 priv->fs_volumes_changed_id =
725 g_signal_connect (priv->fs, "volumes-changed",
726 G_CALLBACK (fs_volumes_changed_cb), object);
727 priv->fs_bookmarks_changed_id =
728 g_signal_connect (priv->fs, "bookmarks-changed",
729 G_CALLBACK (fs_bookmarks_changed_cb), object);
735 gtk_file_chooser_button_set_property (GObject *object,
740 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (object);
741 GtkFileChooserButtonPrivate *priv = button->priv;
747 priv->dialog = g_value_get_object (value);
749 case PROP_FOCUS_ON_CLICK:
750 gtk_file_chooser_button_set_focus_on_click (button, g_value_get_boolean (value));
752 case PROP_WIDTH_CHARS:
753 gtk_file_chooser_button_set_width_chars (GTK_FILE_CHOOSER_BUTTON (object),
754 g_value_get_int (value));
756 case GTK_FILE_CHOOSER_PROP_ACTION:
757 switch (g_value_get_enum (value))
759 case GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER:
760 case GTK_FILE_CHOOSER_ACTION_SAVE:
765 eclass = g_type_class_peek (GTK_TYPE_FILE_CHOOSER_ACTION);
766 eval = g_enum_get_value (eclass, g_value_get_enum (value));
767 g_warning ("%s: Choosers of type `%s' do not support `%s'.",
768 G_STRFUNC, G_OBJECT_TYPE_NAME (object), eval->value_name);
770 g_value_set_enum ((GValue *) value, GTK_FILE_CHOOSER_ACTION_OPEN);
775 g_object_set_property (G_OBJECT (priv->dialog), pspec->name, value);
776 update_label_and_image (GTK_FILE_CHOOSER_BUTTON (object));
777 update_combo_box (GTK_FILE_CHOOSER_BUTTON (object));
779 switch (g_value_get_enum (value))
781 case GTK_FILE_CHOOSER_ACTION_OPEN:
782 gtk_widget_hide (priv->combo_box);
783 gtk_widget_show (priv->button);
785 case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER:
786 gtk_widget_hide (priv->button);
787 gtk_widget_show (priv->combo_box);
790 g_assert_not_reached ();
796 /* Remember that a title has been set, so we do no try to set it to the default in _init(). */
797 priv->has_title = TRUE;
798 /* Intentionally fall through instead of breaking here, to actually set the property. */
799 case GTK_FILE_CHOOSER_PROP_FILTER:
800 case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
801 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
802 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE:
803 case GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL:
804 case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
805 case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN:
806 case GTK_FILE_CHOOSER_PROP_DO_OVERWRITE_CONFIRMATION:
807 g_object_set_property (G_OBJECT (priv->dialog), pspec->name, value);
810 case GTK_FILE_CHOOSER_PROP_FILE_SYSTEM_BACKEND:
812 priv->backend = g_value_dup_string (value);
815 case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
816 g_warning ("%s: Choosers of type `%s` do not support selecting multiple files.",
817 G_STRFUNC, G_OBJECT_TYPE_NAME (object));
820 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
826 gtk_file_chooser_button_get_property (GObject *object,
831 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (object);
832 GtkFileChooserButtonPrivate *priv = button->priv;
836 case PROP_WIDTH_CHARS:
837 g_value_set_int (value,
838 gtk_label_get_width_chars (GTK_LABEL (priv->label)));
840 case PROP_FOCUS_ON_CLICK:
841 g_value_set_boolean (value,
842 gtk_file_chooser_button_get_focus_on_click (button));
846 case GTK_FILE_CHOOSER_PROP_ACTION:
847 case GTK_FILE_CHOOSER_PROP_FILE_SYSTEM_BACKEND:
848 case GTK_FILE_CHOOSER_PROP_FILTER:
849 case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
850 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
851 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE:
852 case GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL:
853 case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
854 case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
855 case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN:
856 case GTK_FILE_CHOOSER_PROP_DO_OVERWRITE_CONFIRMATION:
857 g_object_get_property (G_OBJECT (priv->dialog), pspec->name, value);
861 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
867 gtk_file_chooser_button_finalize (GObject *object)
869 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (object);
870 GtkFileChooserButtonPrivate *priv = button->priv;
873 gtk_file_path_free (priv->old_path);
875 if (G_OBJECT_CLASS (gtk_file_chooser_button_parent_class)->finalize != NULL)
876 (*G_OBJECT_CLASS (gtk_file_chooser_button_parent_class)->finalize) (object);
879 /* ********************* *
880 * GtkObject Functions *
881 * ********************* */
884 gtk_file_chooser_button_destroy (GtkObject *object)
886 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (object);
887 GtkFileChooserButtonPrivate *priv = button->priv;
891 if (priv->dialog != NULL)
893 gtk_widget_destroy (priv->dialog);
897 if (priv->model && gtk_tree_model_get_iter_first (priv->model, &iter)) do
899 model_free_row_data (button, &iter);
901 while (gtk_tree_model_iter_next (priv->model, &iter));
903 if (priv->dnd_select_folder_handle)
905 gtk_file_system_cancel_operation (priv->dnd_select_folder_handle);
906 priv->dnd_select_folder_handle = NULL;
909 if (priv->update_button_handle)
911 gtk_file_system_cancel_operation (priv->update_button_handle);
912 priv->update_button_handle = NULL;
915 if (priv->change_icon_theme_handles)
917 for (l = priv->change_icon_theme_handles; l; l = l->next)
919 GtkFileSystemHandle *handle = GTK_FILE_SYSTEM_HANDLE (l->data);
920 gtk_file_system_cancel_operation (handle);
922 g_slist_free (priv->change_icon_theme_handles);
923 priv->change_icon_theme_handles = NULL;
928 g_object_unref (priv->model);
932 if (priv->filter_model)
934 g_object_unref (priv->filter_model);
935 priv->filter_model = NULL;
940 g_signal_handler_disconnect (priv->fs, priv->fs_volumes_changed_id);
941 g_signal_handler_disconnect (priv->fs, priv->fs_bookmarks_changed_id);
942 g_object_unref (priv->fs);
946 if (GTK_OBJECT_CLASS (gtk_file_chooser_button_parent_class)->destroy != NULL)
947 (*GTK_OBJECT_CLASS (gtk_file_chooser_button_parent_class)->destroy) (object);
951 /* ********************* *
952 * GtkWidget Functions *
953 * ********************* */
955 struct DndSelectFolderData
957 GtkFileChooserButton *button;
958 GtkFileChooserAction action;
966 dnd_select_folder_get_info_cb (GtkFileSystemHandle *handle,
967 const GtkFileInfo *info,
971 gboolean cancelled = handle->cancelled;
972 struct DndSelectFolderData *data = user_data;
974 if (handle != data->button->priv->dnd_select_folder_handle)
976 g_object_unref (data->button);
977 gtk_file_path_free (data->path);
978 g_strfreev (data->uris);
981 g_object_unref (handle);
985 data->button->priv->dnd_select_folder_handle = NULL;
987 if (!cancelled && !error && info != NULL)
990 (((data->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER &&
991 gtk_file_info_get_is_folder (info)) ||
992 (data->action == GTK_FILE_CHOOSER_ACTION_OPEN &&
993 !gtk_file_info_get_is_folder (info))) &&
994 _gtk_file_chooser_select_path (GTK_FILE_CHOOSER (data->button->priv->dialog),
998 data->selected = FALSE;
1000 if (data->selected || data->uris[++data->i] == NULL)
1002 g_object_unref (data->button);
1003 gtk_file_path_free (data->path);
1004 g_strfreev (data->uris);
1007 g_object_unref (handle);
1012 gtk_file_path_free (data->path);
1014 data->path = gtk_file_system_uri_to_path (handle->file_system,
1015 data->uris[data->i]);
1017 data->button->priv->dnd_select_folder_handle =
1018 gtk_file_system_get_info (handle->file_system, data->path,
1019 GTK_FILE_INFO_IS_FOLDER,
1020 dnd_select_folder_get_info_cb, user_data);
1022 g_object_unref (handle);
1026 gtk_file_chooser_button_drag_data_received (GtkWidget *widget,
1027 GdkDragContext *context,
1030 GtkSelectionData *data,
1034 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (widget);
1035 GtkFileChooserButtonPrivate *priv = button->priv;
1039 if (GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->drag_data_received != NULL)
1040 (*GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->drag_data_received) (widget,
1046 if (widget == NULL || context == NULL || data == NULL || data->length < 0)
1054 struct DndSelectFolderData *info;
1056 uris = gtk_selection_data_get_uris (data);
1061 info = g_new0 (struct DndSelectFolderData, 1);
1062 info->button = g_object_ref (button);
1065 info->selected = FALSE;
1066 g_object_get (priv->dialog, "action", &info->action, NULL);
1068 info->path = gtk_file_system_uri_to_path (priv->fs,
1069 info->uris[info->i]);
1071 if (priv->dnd_select_folder_handle)
1072 gtk_file_system_cancel_operation (priv->dnd_select_folder_handle);
1074 priv->dnd_select_folder_handle =
1075 gtk_file_system_get_info (priv->fs, info->path,
1076 GTK_FILE_INFO_IS_FOLDER,
1077 dnd_select_folder_get_info_cb, info);
1082 text = (char*) gtk_selection_data_get_text (data);
1083 path = gtk_file_path_new_steal (text);
1084 _gtk_file_chooser_select_path (GTK_FILE_CHOOSER (priv->dialog), path,
1086 gtk_file_path_free (path);
1093 gtk_drag_finish (context, TRUE, FALSE, drag_time);
1097 gtk_file_chooser_button_show_all (GtkWidget *widget)
1099 gtk_widget_show (widget);
1103 gtk_file_chooser_button_hide_all (GtkWidget *widget)
1105 gtk_widget_hide (widget);
1109 gtk_file_chooser_button_show (GtkWidget *widget)
1111 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (widget);
1112 GtkFileChooserButtonPrivate *priv = button->priv;
1114 if (GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->show)
1115 (*GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->show) (widget);
1118 open_dialog (GTK_FILE_CHOOSER_BUTTON (widget));
1122 gtk_file_chooser_button_hide (GtkWidget *widget)
1124 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (widget);
1125 GtkFileChooserButtonPrivate *priv = button->priv;
1127 gtk_widget_hide (priv->dialog);
1129 if (GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->hide)
1130 (*GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->hide) (widget);
1134 gtk_file_chooser_button_map (GtkWidget *widget)
1136 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (widget);
1137 GtkFileChooserButtonPrivate *priv = button->priv;
1139 if (!priv->folder_has_been_set)
1141 char *current_working_dir;
1143 current_working_dir = g_get_current_dir ();
1144 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (widget), current_working_dir);
1145 g_free (current_working_dir);
1147 priv->folder_has_been_set = TRUE;
1150 if (GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->map)
1151 (*GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->map) (widget);
1155 gtk_file_chooser_button_mnemonic_activate (GtkWidget *widget,
1156 gboolean group_cycling)
1158 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (widget);
1159 GtkFileChooserButtonPrivate *priv = button->priv;
1161 switch (gtk_file_chooser_get_action (GTK_FILE_CHOOSER (priv->dialog)))
1163 case GTK_FILE_CHOOSER_ACTION_OPEN:
1164 gtk_widget_grab_focus (priv->button);
1166 case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER:
1167 return gtk_widget_mnemonic_activate (priv->combo_box, group_cycling);
1170 g_assert_not_reached ();
1177 /* Changes the icons wherever it is needed */
1178 struct ChangeIconThemeData
1180 GtkFileChooserButton *button;
1181 GtkTreeRowReference *row_ref;
1185 change_icon_theme_get_info_cb (GtkFileSystemHandle *handle,
1186 const GtkFileInfo *info,
1187 const GError *error,
1190 gboolean cancelled = handle->cancelled;
1192 struct ChangeIconThemeData *data = user_data;
1194 if (!g_slist_find (data->button->priv->change_icon_theme_handles, handle))
1197 data->button->priv->change_icon_theme_handles =
1198 g_slist_remove (data->button->priv->change_icon_theme_handles, handle);
1200 if (cancelled || error)
1203 pixbuf = gtk_file_info_render_icon (info, GTK_WIDGET (data->button),
1204 data->button->priv->icon_size, NULL);
1212 width = MAX (width, gdk_pixbuf_get_width (pixbuf));
1214 path = gtk_tree_row_reference_get_path (data->row_ref);
1215 gtk_tree_model_get_iter (data->button->priv->model, &iter, path);
1216 gtk_tree_path_free (path);
1218 gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &iter,
1219 ICON_COLUMN, pixbuf,
1221 g_object_unref (pixbuf);
1223 g_object_set (data->button->priv->icon_cell,
1229 g_object_unref (data->button);
1230 gtk_tree_row_reference_free (data->row_ref);
1233 g_object_unref (handle);
1237 change_icon_theme (GtkFileChooserButton *button)
1239 GtkFileChooserButtonPrivate *priv = button->priv;
1240 GtkSettings *settings;
1241 GtkIconTheme *theme;
1244 gint width = 0, height = 0;
1246 for (l = button->priv->change_icon_theme_handles; l; l = l->next)
1248 GtkFileSystemHandle *handle = GTK_FILE_SYSTEM_HANDLE (l->data);
1249 gtk_file_system_cancel_operation (handle);
1251 g_slist_free (button->priv->change_icon_theme_handles);
1252 button->priv->change_icon_theme_handles = NULL;
1254 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (button)));
1256 if (gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
1258 priv->icon_size = MAX (width, height);
1260 priv->icon_size = FALLBACK_ICON_SIZE;
1262 update_label_and_image (button);
1264 gtk_tree_model_get_iter_first (priv->model, &iter);
1266 theme = get_icon_theme (GTK_WIDGET (button));
1274 type = ROW_TYPE_INVALID;
1275 gtk_tree_model_get (priv->model, &iter,
1282 case ROW_TYPE_SPECIAL:
1283 case ROW_TYPE_SHORTCUT:
1284 case ROW_TYPE_BOOKMARK:
1285 case ROW_TYPE_CURRENT_FOLDER:
1289 GtkFileSystemHandle *handle;
1290 struct ChangeIconThemeData *info;
1292 info = g_new0 (struct ChangeIconThemeData, 1);
1293 info->button = g_object_ref (button);
1294 path = gtk_tree_model_get_path (priv->model, &iter);
1295 info->row_ref = gtk_tree_row_reference_new (priv->model, path);
1296 gtk_tree_path_free (path);
1299 gtk_file_system_get_info (priv->fs, data, GTK_FILE_INFO_ICON,
1300 change_icon_theme_get_info_cb,
1302 button->priv->change_icon_theme_handles =
1303 g_slist_append (button->priv->change_icon_theme_handles, handle);
1307 pixbuf = gtk_icon_theme_load_icon (theme, FALLBACK_ICON_NAME,
1308 priv->icon_size, 0, NULL);
1310 case ROW_TYPE_VOLUME:
1312 pixbuf = gtk_file_system_volume_render_icon (priv->fs, data,
1313 GTK_WIDGET (button),
1317 pixbuf = gtk_icon_theme_load_icon (theme, FALLBACK_ICON_NAME,
1318 priv->icon_size, 0, NULL);
1326 width = MAX (width, gdk_pixbuf_get_width (pixbuf));
1328 gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter,
1329 ICON_COLUMN, pixbuf,
1333 g_object_unref (pixbuf);
1335 while (gtk_tree_model_iter_next (priv->model, &iter));
1337 g_object_set (button->priv->icon_cell,
1343 gtk_file_chooser_button_style_set (GtkWidget *widget,
1344 GtkStyle *old_style)
1346 if (GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->style_set)
1347 (*GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->style_set) (widget,
1350 if (gtk_widget_has_screen (widget))
1351 change_icon_theme (GTK_FILE_CHOOSER_BUTTON (widget));
1355 gtk_file_chooser_button_screen_changed (GtkWidget *widget,
1356 GdkScreen *old_screen)
1358 if (GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->screen_changed)
1359 (*GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->screen_changed) (widget,
1362 change_icon_theme (GTK_FILE_CHOOSER_BUTTON (widget));
1366 /* ******************* *
1367 * Utility Functions *
1368 * ******************* */
1371 static GtkIconTheme *
1372 get_icon_theme (GtkWidget *widget)
1374 if (gtk_widget_has_screen (widget))
1375 return gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget));
1377 return gtk_icon_theme_get_default ();
1381 struct SetDisplayNameData
1383 GtkFileChooserButton *button;
1384 GtkTreeRowReference *row_ref;
1388 set_info_get_info_cb (GtkFileSystemHandle *handle,
1389 const GtkFileInfo *info,
1390 const GError *error,
1391 gpointer callback_data)
1393 gboolean cancelled = handle->cancelled;
1397 GtkFileSystemHandle *model_handle;
1398 struct SetDisplayNameData *data = callback_data;
1400 if (!data->button->priv->model)
1401 /* button got destroyed */
1404 path = gtk_tree_row_reference_get_path (data->row_ref);
1406 /* Handle doesn't exist anymore in the model */
1409 gtk_tree_model_get_iter (data->button->priv->model, &iter, path);
1410 gtk_tree_path_free (path);
1412 /* Validate the handle */
1413 gtk_tree_model_get (data->button->priv->model, &iter,
1414 HANDLE_COLUMN, &model_handle,
1416 if (handle != model_handle)
1419 gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &iter,
1420 HANDLE_COLUMN, NULL,
1423 if (cancelled || error)
1424 /* There was an error, leave the fallback name in there */
1427 pixbuf = gtk_file_info_render_icon (info, GTK_WIDGET (data->button),
1428 data->button->priv->icon_size, NULL);
1430 gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &iter,
1431 ICON_COLUMN, pixbuf,
1432 DISPLAY_NAME_COLUMN, gtk_file_info_get_display_name (info),
1433 IS_FOLDER_COLUMN, gtk_file_info_get_is_folder (info),
1437 g_object_unref (pixbuf);
1440 g_object_unref (data->button);
1441 gtk_tree_row_reference_free (data->row_ref);
1444 g_object_unref (handle);
1448 set_info_for_path_at_iter (GtkFileChooserButton *button,
1449 const GtkFilePath *path,
1452 struct SetDisplayNameData *data;
1453 GtkTreePath *tree_path;
1454 GtkFileSystemHandle *handle;
1456 data = g_new0 (struct SetDisplayNameData, 1);
1457 data->button = g_object_ref (button);
1459 tree_path = gtk_tree_model_get_path (button->priv->model, iter);
1460 data->row_ref = gtk_tree_row_reference_new (button->priv->model, tree_path);
1461 gtk_tree_path_free (tree_path);
1463 handle = gtk_file_system_get_info (button->priv->fs, path,
1464 GTK_FILE_INFO_DISPLAY_NAME | GTK_FILE_INFO_IS_FOLDER | GTK_FILE_INFO_ICON,
1465 set_info_get_info_cb, data);
1467 gtk_list_store_set (GTK_LIST_STORE (button->priv->model), iter,
1468 HANDLE_COLUMN, handle,
1472 /* Shortcuts Model */
1474 model_get_type_position (GtkFileChooserButton *button,
1479 if (row_type == ROW_TYPE_SPECIAL)
1482 retval += button->priv->n_special;
1484 if (row_type == ROW_TYPE_VOLUME)
1487 retval += button->priv->n_volumes;
1489 if (row_type == ROW_TYPE_SHORTCUT)
1492 retval += button->priv->n_shortcuts;
1494 if (row_type == ROW_TYPE_BOOKMARK_SEPARATOR)
1497 retval += button->priv->has_bookmark_separator;
1499 if (row_type == ROW_TYPE_BOOKMARK)
1502 retval += button->priv->n_bookmarks;
1504 if (row_type == ROW_TYPE_CURRENT_FOLDER_SEPARATOR)
1507 retval += button->priv->has_current_folder_separator;
1509 if (row_type == ROW_TYPE_CURRENT_FOLDER)
1512 retval += button->priv->has_current_folder;
1514 if (row_type == ROW_TYPE_OTHER_SEPARATOR)
1517 retval += button->priv->has_other_separator;
1519 if (row_type == ROW_TYPE_OTHER)
1522 g_assert_not_reached ();
1527 model_free_row_data (GtkFileChooserButton *button,
1532 GtkFileSystemHandle *handle;
1534 gtk_tree_model_get (button->priv->model, iter,
1537 HANDLE_COLUMN, &handle,
1541 gtk_file_system_cancel_operation (handle);
1545 case ROW_TYPE_SPECIAL:
1546 case ROW_TYPE_SHORTCUT:
1547 case ROW_TYPE_BOOKMARK:
1548 case ROW_TYPE_CURRENT_FOLDER:
1549 gtk_file_path_free (data);
1551 case ROW_TYPE_VOLUME:
1552 gtk_file_system_volume_free (button->priv->fs, data);
1560 model_add_special_get_info_cb (GtkFileSystemHandle *handle,
1561 const GtkFileInfo *info,
1562 const GError *error,
1565 gboolean cancelled = handle->cancelled;
1569 GtkFileSystemHandle *model_handle;
1570 struct ChangeIconThemeData *data = user_data;
1572 if (!data->button->priv->model)
1573 /* button got destroyed */
1576 path = gtk_tree_row_reference_get_path (data->row_ref);
1578 /* Handle doesn't exist anymore in the model */
1581 gtk_tree_model_get_iter (data->button->priv->model, &iter, path);
1582 gtk_tree_path_free (path);
1584 gtk_tree_model_get (data->button->priv->model, &iter,
1585 HANDLE_COLUMN, &model_handle,
1587 if (handle != model_handle)
1590 gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &iter,
1591 HANDLE_COLUMN, NULL,
1594 if (cancelled || error)
1597 pixbuf = gtk_file_info_render_icon (info, GTK_WIDGET (data->button),
1598 data->button->priv->icon_size, NULL);
1602 gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &iter,
1603 ICON_COLUMN, pixbuf,
1605 g_object_unref (pixbuf);
1608 gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &iter,
1609 DISPLAY_NAME_COLUMN, gtk_file_info_get_display_name (info),
1613 g_object_unref (data->button);
1614 gtk_tree_row_reference_free (data->row_ref);
1617 g_object_unref (handle);
1621 model_add_special (GtkFileChooserButton *button)
1623 const gchar *homedir;
1624 gchar *desktopdir = NULL;
1625 GtkListStore *store;
1630 store = GTK_LIST_STORE (button->priv->model);
1631 pos = model_get_type_position (button, ROW_TYPE_SPECIAL);
1633 homedir = g_get_home_dir ();
1637 GtkTreePath *tree_path;
1638 GtkFileSystemHandle *handle;
1639 struct ChangeIconThemeData *info;
1641 path = gtk_file_system_filename_to_path (button->priv->fs, homedir);
1642 gtk_list_store_insert (store, &iter, pos);
1645 info = g_new0 (struct ChangeIconThemeData, 1);
1646 info->button = g_object_ref (button);
1647 tree_path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter);
1648 info->row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (store),
1650 gtk_tree_path_free (tree_path);
1652 handle = gtk_file_system_get_info (button->priv->fs, path,
1653 GTK_FILE_INFO_DISPLAY_NAME | GTK_FILE_INFO_ICON,
1654 model_add_special_get_info_cb, info);
1656 gtk_list_store_set (store, &iter,
1658 DISPLAY_NAME_COLUMN, NULL,
1659 TYPE_COLUMN, ROW_TYPE_SPECIAL,
1661 IS_FOLDER_COLUMN, TRUE,
1662 HANDLE_COLUMN, handle,
1665 button->priv->n_special++;
1668 desktopdir = g_build_filename (homedir, DESKTOP_DISPLAY_NAME, NULL);
1673 desktopdir = _gtk_file_system_win32_get_desktop ();
1678 GtkTreePath *tree_path;
1679 GtkFileSystemHandle *handle;
1680 struct ChangeIconThemeData *info;
1682 path = gtk_file_system_filename_to_path (button->priv->fs, desktopdir);
1683 g_free (desktopdir);
1684 gtk_list_store_insert (store, &iter, pos);
1687 info = g_new0 (struct ChangeIconThemeData, 1);
1688 info->button = g_object_ref (button);
1689 tree_path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter);
1690 info->row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (store),
1692 gtk_tree_path_free (tree_path);
1694 handle = gtk_file_system_get_info (button->priv->fs, path,
1696 model_add_special_get_info_cb, info);
1698 gtk_list_store_set (store, &iter,
1699 TYPE_COLUMN, ROW_TYPE_SPECIAL,
1701 DISPLAY_NAME_COLUMN, _(DESKTOP_DISPLAY_NAME),
1703 IS_FOLDER_COLUMN, TRUE,
1706 button->priv->n_special++;
1711 model_add_volumes (GtkFileChooserButton *button,
1714 GtkListStore *store;
1720 store = GTK_LIST_STORE (button->priv->model);
1721 pos = model_get_type_position (button, ROW_TYPE_VOLUME);
1727 gchar *display_name;
1729 pixbuf = gtk_file_system_volume_render_icon (button->priv->fs,
1731 GTK_WIDGET (button),
1732 button->priv->icon_size,
1734 display_name = gtk_file_system_volume_get_display_name (button->priv->fs,
1737 gtk_list_store_insert (store, &iter, pos);
1738 gtk_list_store_set (store, &iter,
1739 ICON_COLUMN, pixbuf,
1740 DISPLAY_NAME_COLUMN, display_name,
1741 TYPE_COLUMN, ROW_TYPE_VOLUME,
1742 DATA_COLUMN, volumes->data,
1743 IS_FOLDER_COLUMN, TRUE,
1747 g_object_unref (pixbuf);
1748 g_free (display_name);
1750 button->priv->n_volumes++;
1752 volumes = volumes->next;
1758 model_add_bookmarks (GtkFileChooserButton *button,
1761 GtkListStore *store;
1768 store = GTK_LIST_STORE (button->priv->model);
1769 pos = model_get_type_position (button, ROW_TYPE_BOOKMARK_SEPARATOR);
1771 if (!button->priv->has_bookmark_separator)
1773 gtk_list_store_insert (store, &iter, pos);
1774 gtk_list_store_set (store, &iter,
1776 DISPLAY_NAME_COLUMN, NULL,
1777 TYPE_COLUMN, ROW_TYPE_BOOKMARK_SEPARATOR,
1779 IS_FOLDER_COLUMN, FALSE,
1781 button->priv->has_bookmark_separator = TRUE;
1788 gtk_list_store_insert (store, &iter, pos);
1789 gtk_list_store_set (store, &iter,
1791 DISPLAY_NAME_COLUMN, _(FALLBACK_DISPLAY_NAME),
1792 TYPE_COLUMN, ROW_TYPE_BOOKMARK,
1793 DATA_COLUMN, gtk_file_path_copy (bookmarks->data),
1794 IS_FOLDER_COLUMN, FALSE,
1796 set_info_for_path_at_iter (button, bookmarks->data, &iter);
1798 button->priv->n_bookmarks++;
1799 bookmarks = bookmarks->next;
1805 model_update_current_folder (GtkFileChooserButton *button,
1806 const GtkFilePath *path)
1808 GtkListStore *store;
1815 store = GTK_LIST_STORE (button->priv->model);
1817 if (!button->priv->has_current_folder_separator)
1819 pos = model_get_type_position (button, ROW_TYPE_CURRENT_FOLDER_SEPARATOR);
1820 gtk_list_store_insert (store, &iter, pos);
1821 gtk_list_store_set (store, &iter,
1823 DISPLAY_NAME_COLUMN, NULL,
1824 TYPE_COLUMN, ROW_TYPE_CURRENT_FOLDER_SEPARATOR,
1826 IS_FOLDER_COLUMN, FALSE,
1828 button->priv->has_current_folder_separator = TRUE;
1831 pos = model_get_type_position (button, ROW_TYPE_CURRENT_FOLDER);
1832 if (!button->priv->has_current_folder)
1834 gtk_list_store_insert (store, &iter, pos);
1835 button->priv->has_current_folder = TRUE;
1839 gtk_tree_model_iter_nth_child (button->priv->model, &iter, NULL, pos);
1840 model_free_row_data (button, &iter);
1843 gtk_list_store_set (store, &iter,
1845 DISPLAY_NAME_COLUMN, _(FALLBACK_DISPLAY_NAME),
1846 TYPE_COLUMN, ROW_TYPE_CURRENT_FOLDER,
1847 DATA_COLUMN, gtk_file_path_copy (path),
1848 IS_FOLDER_COLUMN, FALSE,
1850 set_info_for_path_at_iter (button, path, &iter);
1854 model_add_other (GtkFileChooserButton *button)
1856 GtkListStore *store;
1860 store = GTK_LIST_STORE (button->priv->model);
1861 pos = model_get_type_position (button, ROW_TYPE_OTHER_SEPARATOR);
1863 gtk_list_store_insert (store, &iter, pos);
1864 gtk_list_store_set (store, &iter,
1866 DISPLAY_NAME_COLUMN, NULL,
1867 TYPE_COLUMN, ROW_TYPE_OTHER_SEPARATOR,
1869 IS_FOLDER_COLUMN, FALSE,
1871 button->priv->has_other_separator = TRUE;
1874 gtk_list_store_insert (store, &iter, pos);
1875 gtk_list_store_set (store, &iter,
1877 DISPLAY_NAME_COLUMN, _("Other..."),
1878 TYPE_COLUMN, ROW_TYPE_OTHER,
1880 IS_FOLDER_COLUMN, FALSE,
1885 model_remove_rows (GtkFileChooserButton *button,
1889 GtkListStore *store;
1894 store = GTK_LIST_STORE (button->priv->model);
1900 if (!gtk_tree_model_iter_nth_child (button->priv->model, &iter, NULL, pos))
1901 g_assert_not_reached ();
1903 model_free_row_data (button, &iter);
1904 gtk_list_store_remove (store, &iter);
1911 static inline gboolean
1912 test_if_path_is_visible (GtkFileSystem *fs,
1913 const GtkFilePath *path,
1914 gboolean local_only,
1920 if (local_only && !gtk_file_system_path_is_local (fs, path))
1930 filter_model_visible_func (GtkTreeModel *model,
1934 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (user_data);
1935 GtkFileChooserButtonPrivate *priv = button->priv;
1938 gboolean local_only, retval, is_folder;
1940 type = ROW_TYPE_INVALID;
1942 local_only = gtk_file_chooser_get_local_only (GTK_FILE_CHOOSER (priv->dialog));
1944 gtk_tree_model_get (model, iter,
1947 IS_FOLDER_COLUMN, &is_folder,
1952 case ROW_TYPE_CURRENT_FOLDER:
1955 case ROW_TYPE_SPECIAL:
1956 case ROW_TYPE_SHORTCUT:
1957 case ROW_TYPE_BOOKMARK:
1958 retval = test_if_path_is_visible (priv->fs, data, local_only, is_folder);
1960 case ROW_TYPE_VOLUME:
1962 GtkFilePath *base_path;
1964 base_path = gtk_file_system_volume_get_base_path (priv->fs, data);
1967 retval = (!local_only ||
1968 gtk_file_system_path_is_local (priv->fs, base_path));
1969 gtk_file_path_free (base_path);
1985 name_cell_data_func (GtkCellLayout *layout,
1986 GtkCellRenderer *cell,
1987 GtkTreeModel *model,
1994 gtk_tree_model_get (model, iter,
1998 if (type == ROW_TYPE_CURRENT_FOLDER)
1999 g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
2001 g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_NONE, NULL);
2005 combo_box_row_separator_func (GtkTreeModel *model,
2009 gchar type = ROW_TYPE_INVALID;
2011 gtk_tree_model_get (model, iter, TYPE_COLUMN, &type, -1);
2013 return (type == ROW_TYPE_BOOKMARK_SEPARATOR ||
2014 type == ROW_TYPE_CURRENT_FOLDER_SEPARATOR ||
2015 type == ROW_TYPE_OTHER_SEPARATOR);
2019 update_combo_box (GtkFileChooserButton *button)
2021 GtkFileChooserButtonPrivate *priv = button->priv;
2026 gtk_tree_model_get_iter_first (priv->filter_model, &iter);
2028 paths = _gtk_file_chooser_get_paths (GTK_FILE_CHOOSER (priv->dialog));
2037 type = ROW_TYPE_INVALID;
2040 gtk_tree_model_get (priv->filter_model, &iter,
2047 case ROW_TYPE_SPECIAL:
2048 case ROW_TYPE_SHORTCUT:
2049 case ROW_TYPE_BOOKMARK:
2050 case ROW_TYPE_CURRENT_FOLDER:
2051 row_found = (paths &&
2053 gtk_file_path_compare (data, paths->data) == 0);
2055 case ROW_TYPE_VOLUME:
2057 GtkFilePath *base_path;
2059 base_path = gtk_file_system_volume_get_base_path (priv->fs, data);
2060 row_found = (paths &&
2062 gtk_file_path_compare (base_path, paths->data) == 0);
2063 gtk_file_path_free (base_path);
2073 g_signal_handler_block (priv->combo_box, priv->combo_box_changed_id);
2074 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->combo_box),
2076 g_signal_handler_unblock (priv->combo_box,
2077 priv->combo_box_changed_id);
2080 while (!row_found && gtk_tree_model_iter_next (priv->filter_model, &iter));
2082 /* If it hasn't been found already, update & select the current-folder row. */
2083 if (!row_found && paths && paths->data)
2085 GtkTreeIter filter_iter;
2088 model_update_current_folder (button, paths->data);
2089 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter_model));
2091 pos = model_get_type_position (button, ROW_TYPE_CURRENT_FOLDER);
2092 gtk_tree_model_iter_nth_child (priv->model, &iter, NULL, pos);
2094 gtk_tree_model_filter_convert_child_iter_to_iter (GTK_TREE_MODEL_FILTER (priv->filter_model),
2095 &filter_iter, &iter);
2097 g_signal_handler_block (priv->combo_box, priv->combo_box_changed_id);
2098 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->combo_box), &filter_iter);
2099 g_signal_handler_unblock (priv->combo_box, priv->combo_box_changed_id);
2102 gtk_file_paths_free (paths);
2107 update_label_get_info_cb (GtkFileSystemHandle *handle,
2108 const GtkFileInfo *info,
2109 const GError *error,
2112 gboolean cancelled = handle->cancelled;
2114 GtkFileChooserButton *button = data;
2115 GtkFileChooserButtonPrivate *priv = button->priv;
2117 if (handle != priv->update_button_handle)
2120 priv->update_button_handle = NULL;
2122 if (cancelled || error)
2125 gtk_label_set_text (GTK_LABEL (priv->label), gtk_file_info_get_display_name (info));
2127 pixbuf = gtk_file_info_render_icon (info, GTK_WIDGET (priv->image),
2128 priv->icon_size, NULL);
2130 pixbuf = gtk_icon_theme_load_icon (get_icon_theme (GTK_WIDGET (priv->image)),
2132 priv->icon_size, 0, NULL);
2134 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), pixbuf);
2136 g_object_unref (pixbuf);
2139 g_object_unref (button);
2140 g_object_unref (handle);
2144 update_label_and_image (GtkFileChooserButton *button)
2146 GtkFileChooserButtonPrivate *priv = button->priv;
2151 paths = _gtk_file_chooser_get_paths (GTK_FILE_CHOOSER (priv->dialog));
2155 if (paths && paths->data)
2158 GtkFileSystemVolume *volume = NULL;
2162 volume = gtk_file_system_get_volume_for_path (priv->fs, path);
2165 GtkFilePath *base_path;
2167 base_path = gtk_file_system_volume_get_base_path (priv->fs, volume);
2168 if (base_path && gtk_file_path_compare (base_path, path) == 0)
2170 label_text = gtk_file_system_volume_get_display_name (priv->fs,
2172 pixbuf = gtk_file_system_volume_render_icon (priv->fs, volume,
2173 GTK_WIDGET (button),
2179 gtk_file_path_free (base_path);
2181 gtk_file_system_volume_free (priv->fs, volume);
2187 if (priv->update_button_handle)
2188 gtk_file_system_cancel_operation (priv->update_button_handle);
2190 priv->update_button_handle =
2191 gtk_file_system_get_info (priv->fs, path,
2192 GTK_FILE_INFO_DISPLAY_NAME | GTK_FILE_INFO_ICON,
2193 update_label_get_info_cb,
2194 g_object_ref (button));
2197 gtk_file_paths_free (paths);
2201 gtk_label_set_text (GTK_LABEL (priv->label), label_text);
2202 g_free (label_text);
2205 gtk_label_set_text (GTK_LABEL (priv->label), _(FALLBACK_DISPLAY_NAME));
2209 /* ************************ *
2210 * Child Object Callbacks *
2211 * ************************ */
2215 fs_volumes_changed_cb (GtkFileSystem *fs,
2218 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (user_data);
2219 GtkFileChooserButtonPrivate *priv = button->priv;
2222 model_remove_rows (user_data,
2223 model_get_type_position (user_data, ROW_TYPE_VOLUME),
2226 priv->n_volumes = 0;
2228 volumes = gtk_file_system_list_volumes (fs);
2229 model_add_volumes (user_data, volumes);
2230 g_slist_free (volumes);
2232 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter_model));
2234 update_label_and_image (user_data);
2235 update_combo_box (user_data);
2239 fs_bookmarks_changed_cb (GtkFileSystem *fs,
2242 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (user_data);
2243 GtkFileChooserButtonPrivate *priv = button->priv;
2246 bookmarks = gtk_file_system_list_bookmarks (fs);
2249 model_remove_rows (user_data,
2250 model_get_type_position (user_data,
2251 ROW_TYPE_BOOKMARK_SEPARATOR),
2252 (priv->n_bookmarks + priv->has_bookmark_separator));
2253 priv->has_bookmark_separator = FALSE;
2256 model_remove_rows (user_data,
2257 model_get_type_position (user_data, ROW_TYPE_BOOKMARK),
2260 priv->n_bookmarks = 0;
2261 model_add_bookmarks (user_data, bookmarks);
2262 gtk_file_paths_free (bookmarks);
2264 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter_model));
2266 update_label_and_image (user_data);
2267 update_combo_box (user_data);
2272 open_dialog (GtkFileChooserButton *button)
2274 GtkFileChooserButtonPrivate *priv = button->priv;
2276 /* Setup the dialog parent to be chooser button's toplevel, and be modal
2278 if (!GTK_WIDGET_VISIBLE (priv->dialog))
2280 GtkWidget *toplevel;
2282 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (button));
2284 if (GTK_WIDGET_TOPLEVEL (toplevel) && GTK_IS_WINDOW (toplevel))
2286 if (GTK_WINDOW (toplevel) != gtk_window_get_transient_for (GTK_WINDOW (priv->dialog)))
2287 gtk_window_set_transient_for (GTK_WINDOW (priv->dialog),
2288 GTK_WINDOW (toplevel));
2290 gtk_window_set_modal (GTK_WINDOW (priv->dialog),
2291 gtk_window_get_modal (GTK_WINDOW (toplevel)));
2299 g_signal_handler_block (priv->dialog,
2300 priv->dialog_folder_changed_id);
2301 g_signal_handler_block (priv->dialog,
2302 priv->dialog_file_activated_id);
2303 g_signal_handler_block (priv->dialog,
2304 priv->dialog_selection_changed_id);
2305 paths = _gtk_file_chooser_get_paths (GTK_FILE_CHOOSER (priv->dialog));
2309 priv->old_path = gtk_file_path_copy (paths->data);
2311 gtk_file_paths_free (paths);
2314 priv->active = TRUE;
2317 gtk_widget_set_sensitive (priv->combo_box, FALSE);
2318 gtk_window_present (GTK_WINDOW (priv->dialog));
2323 combo_box_changed_cb (GtkComboBox *combo_box,
2328 if (gtk_combo_box_get_active_iter (combo_box, &iter))
2330 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (user_data);
2331 GtkFileChooserButtonPrivate *priv = button->priv;
2335 type = ROW_TYPE_INVALID;
2338 gtk_tree_model_get (priv->filter_model, &iter,
2345 case ROW_TYPE_SPECIAL:
2346 case ROW_TYPE_SHORTCUT:
2347 case ROW_TYPE_BOOKMARK:
2348 case ROW_TYPE_CURRENT_FOLDER:
2349 gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (priv->dialog));
2351 _gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (priv->dialog),
2354 case ROW_TYPE_VOLUME:
2356 GtkFilePath *base_path;
2358 gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (priv->dialog));
2359 base_path = gtk_file_system_volume_get_base_path (priv->fs, data);
2362 _gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (priv->dialog),
2364 gtk_file_path_free (base_path);
2368 case ROW_TYPE_OTHER:
2369 open_dialog (user_data);
2379 button_clicked_cb (GtkButton *real_button,
2382 open_dialog (user_data);
2387 dialog_current_folder_changed_cb (GtkFileChooser *dialog,
2390 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (user_data);
2391 GtkFileChooserButtonPrivate *priv = button->priv;
2393 priv->folder_has_been_set = TRUE;
2395 g_signal_emit_by_name (button, "current-folder-changed");
2399 dialog_file_activated_cb (GtkFileChooser *dialog,
2402 g_signal_emit_by_name (user_data, "file-activated");
2406 dialog_selection_changed_cb (GtkFileChooser *dialog,
2409 update_label_and_image (user_data);
2410 update_combo_box (user_data);
2411 g_signal_emit_by_name (user_data, "selection-changed");
2415 dialog_update_preview_cb (GtkFileChooser *dialog,
2418 g_signal_emit_by_name (user_data, "update-preview");
2422 dialog_notify_cb (GObject *dialog,
2428 iface = g_type_interface_peek (g_type_class_peek (G_OBJECT_TYPE (dialog)),
2429 GTK_TYPE_FILE_CHOOSER);
2430 if (g_object_interface_find_property (iface, pspec->name))
2431 g_object_notify (user_data, pspec->name);
2433 if (g_ascii_strcasecmp (pspec->name, "local-only") == 0)
2435 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (user_data);
2436 GtkFileChooserButtonPrivate *priv = button->priv;
2438 if (priv->has_current_folder)
2444 pos = model_get_type_position (user_data,
2445 ROW_TYPE_CURRENT_FOLDER);
2446 gtk_tree_model_iter_nth_child (priv->model, &iter, NULL, pos);
2449 gtk_tree_model_get (priv->model, &iter, DATA_COLUMN, &data, -1);
2451 /* If the path isn't local but we're in local-only mode now, remove
2452 * the custom-folder row */
2454 (!gtk_file_system_path_is_local (priv->fs, data) &&
2455 gtk_file_chooser_get_local_only (GTK_FILE_CHOOSER (priv->dialog))))
2458 model_remove_rows (user_data, pos, 2);
2462 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter_model));
2463 update_combo_box (user_data);
2468 dialog_delete_event_cb (GtkWidget *dialog,
2472 g_signal_emit_by_name (dialog, "response", GTK_RESPONSE_DELETE_EVENT);
2478 dialog_response_cb (GtkDialog *dialog,
2482 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (user_data);
2483 GtkFileChooserButtonPrivate *priv = button->priv;
2485 if (response == GTK_RESPONSE_ACCEPT)
2487 g_signal_emit_by_name (user_data, "current-folder-changed");
2488 g_signal_emit_by_name (user_data, "selection-changed");
2490 else if (priv->old_path)
2492 switch (gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)))
2494 case GTK_FILE_CHOOSER_ACTION_OPEN:
2495 _gtk_file_chooser_select_path (GTK_FILE_CHOOSER (dialog), priv->old_path,
2498 case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER:
2499 _gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (dialog),
2500 priv->old_path, NULL);
2503 g_assert_not_reached ();
2508 gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (dialog));
2512 gtk_file_path_free (priv->old_path);
2513 priv->old_path = NULL;
2516 update_label_and_image (user_data);
2517 update_combo_box (user_data);
2521 g_signal_handler_unblock (priv->dialog,
2522 priv->dialog_folder_changed_id);
2523 g_signal_handler_unblock (priv->dialog,
2524 priv->dialog_file_activated_id);
2525 g_signal_handler_unblock (priv->dialog,
2526 priv->dialog_selection_changed_id);
2527 priv->active = FALSE;
2530 gtk_widget_set_sensitive (priv->combo_box, TRUE);
2531 gtk_widget_hide (priv->dialog);
2535 /* ************************************************************************** *
2537 * ************************************************************************** */
2540 * gtk_file_chooser_button_new:
2541 * @title: the title of the browse dialog.
2542 * @action: the open mode for the widget.
2544 * Creates a new file-selecting button widget.
2546 * Returns: a new button widget.
2551 gtk_file_chooser_button_new (const gchar *title,
2552 GtkFileChooserAction action)
2554 g_return_val_if_fail (action == GTK_FILE_CHOOSER_ACTION_OPEN ||
2555 action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, NULL);
2557 return g_object_new (GTK_TYPE_FILE_CHOOSER_BUTTON,
2559 "title", (title ? title : _(DEFAULT_TITLE)),
2564 * gtk_file_chooser_button_new_with_backend:
2565 * @title: the title of the browse dialog.
2566 * @action: the open mode for the widget.
2567 * @backend: the name of the #GtkFileSystem backend to use.
2569 * Creates a new file-selecting button widget using @backend.
2571 * Returns: a new button widget.
2576 gtk_file_chooser_button_new_with_backend (const gchar *title,
2577 GtkFileChooserAction action,
2578 const gchar *backend)
2580 g_return_val_if_fail (action == GTK_FILE_CHOOSER_ACTION_OPEN ||
2581 action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, NULL);
2583 return g_object_new (GTK_TYPE_FILE_CHOOSER_BUTTON,
2585 "title", (title ? title : _(DEFAULT_TITLE)),
2586 "file-system-backend", backend,
2591 * gtk_file_chooser_button_new_with_dialog:
2592 * @dialog: the #GtkFileChooserDialog widget to use.
2594 * Creates a #GtkFileChooserButton widget which uses @dialog as it's
2595 * file-picking window. Note that @dialog must be a #GtkFileChooserDialog (or
2596 * subclass) and must not have %GTK_DIALOG_DESTROY_WITH_PARENT set.
2598 * Returns: a new button widget.
2603 gtk_file_chooser_button_new_with_dialog (GtkWidget *dialog)
2605 g_return_val_if_fail (GTK_IS_FILE_CHOOSER_DIALOG (dialog), NULL);
2607 return g_object_new (GTK_TYPE_FILE_CHOOSER_BUTTON,
2613 * gtk_file_chooser_button_set_title:
2614 * @button: the button widget to modify.
2615 * @title: the new browse dialog title.
2617 * Modifies the @title of the browse dialog used by @button.
2622 gtk_file_chooser_button_set_title (GtkFileChooserButton *button,
2625 g_return_if_fail (GTK_IS_FILE_CHOOSER_BUTTON (button));
2627 gtk_window_set_title (GTK_WINDOW (button->priv->dialog), title);
2628 g_object_notify (G_OBJECT (button), "title");
2632 * gtk_file_chooser_button_get_title:
2633 * @button: the button widget to examine.
2635 * Retrieves the title of the browse dialog used by @button. The returned value
2636 * should not be modified or freed.
2638 * Returns: a pointer to the browse dialog's title.
2642 G_CONST_RETURN gchar *
2643 gtk_file_chooser_button_get_title (GtkFileChooserButton *button)
2645 g_return_val_if_fail (GTK_IS_FILE_CHOOSER_BUTTON (button), NULL);
2647 return gtk_window_get_title (GTK_WINDOW (button->priv->dialog));
2651 * gtk_file_chooser_button_get_width_chars:
2652 * @button: the button widget to examine.
2654 * Retrieves the width in characters of the @button widget's entry and/or label.
2656 * Returns: an integer width (in characters) that the button will use to size itself.
2661 gtk_file_chooser_button_get_width_chars (GtkFileChooserButton *button)
2663 g_return_val_if_fail (GTK_IS_FILE_CHOOSER_BUTTON (button), -1);
2665 return gtk_label_get_width_chars (GTK_LABEL (button->priv->label));
2669 * gtk_file_chooser_button_set_width_chars:
2670 * @button: the button widget to examine.
2671 * @n_chars: the new width, in characters.
2673 * Sets the width (in characters) that @button will use to @n_chars.
2678 gtk_file_chooser_button_set_width_chars (GtkFileChooserButton *button,
2681 g_return_if_fail (GTK_IS_FILE_CHOOSER_BUTTON (button));
2683 gtk_label_set_width_chars (GTK_LABEL (button->priv->label), n_chars);
2684 g_object_notify (G_OBJECT (button), "width-chars");
2688 * gtk_file_chooser_button_set_focus_on_click:
2689 * @button: a #GtkFileChooserButton
2690 * @focus_on_click: whether the button grabs focus when clicked with the mouse
2692 * Sets whether the button will grab focus when it is clicked with the mouse.
2693 * Making mouse clicks not grab focus is useful in places like toolbars where
2694 * you don't want the keyboard focus removed from the main area of the
2700 gtk_file_chooser_button_set_focus_on_click (GtkFileChooserButton *button,
2701 gboolean focus_on_click)
2703 GtkFileChooserButtonPrivate *priv;
2705 g_return_if_fail (GTK_IS_FILE_CHOOSER_BUTTON (button));
2707 priv = button->priv;
2709 focus_on_click = focus_on_click != FALSE;
2711 if (priv->focus_on_click != focus_on_click)
2713 priv->focus_on_click = focus_on_click;
2714 gtk_button_set_focus_on_click (GTK_BUTTON (priv->button), focus_on_click);
2715 gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (priv->combo_box), focus_on_click);
2717 g_object_notify (G_OBJECT (button), "focus-on-click");
2722 * gtk_file_chooser_button_get_focus_on_click:
2723 * @button: a #GtkFileChooserButton
2725 * Returns whether the button grabs focus when it is clicked with the mouse.
2726 * See gtk_file_chooser_button_set_focus_on_click().
2728 * Return value: %TRUE if the button grabs focus when it is clicked with
2734 gtk_file_chooser_button_get_focus_on_click (GtkFileChooserButton *button)
2736 g_return_val_if_fail (GTK_IS_FILE_CHOOSER_BUTTON (button), FALSE);
2738 return button->priv->focus_on_click;
2741 #define __GTK_FILE_CHOOSER_BUTTON_C__
2742 #include "gtkaliasdef.c"