1 /* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
2 /* GTK - The GIMP Toolkit
3 * gtkfilechooserdefault.c: Default implementation of GtkFileChooser
4 * Copyright (C) 2003, Red Hat, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 #include "gdk/gdkkeysyms.h"
24 #include "gtkalignment.h"
25 #include "gtkbindings.h"
26 #include "gtkbutton.h"
27 #include "gtkcelllayout.h"
28 #include "gtkcellrendererpixbuf.h"
29 #include "gtkcellrenderertext.h"
30 #include "gtkcheckmenuitem.h"
31 #include "gtkclipboard.h"
32 #include "gtkcombobox.h"
34 #include "gtkeventbox.h"
35 #include "gtkexpander.h"
36 #include "gtkfilechooserprivate.h"
37 #include "gtkfilechooserdefault.h"
38 #include "gtkfilechooserembed.h"
39 #include "gtkfilechooserentry.h"
40 #include "gtkfilechoosersettings.h"
41 #include "gtkfilechooserutils.h"
42 #include "gtkfilechooser.h"
43 #include "gtkfilesystemmodel.h"
46 #include "gtkhpaned.h"
47 #include "gtkiconfactory.h"
48 #include "gtkicontheme.h"
50 #include "gtkimagemenuitem.h"
53 #include "gtkmarshalers.h"
54 #include "gtkmenuitem.h"
55 #include "gtkmessagedialog.h"
56 #include "gtkpathbar.h"
57 #include "gtkprivate.h"
58 #include "gtkradiobutton.h"
59 #include "gtkrecentfilter.h"
60 #include "gtkrecentmanager.h"
61 #include "gtkscrolledwindow.h"
62 #include "gtkseparatormenuitem.h"
63 #include "gtksizegroup.h"
66 #include "gtktreednd.h"
67 #include "gtktreeprivate.h"
68 #include "gtktreeselection.h"
69 #include "gtktypebuiltins.h"
72 #if defined (G_OS_UNIX)
73 #include "gtkfilesystemunix.h"
74 #elif defined (G_OS_WIN32)
75 #include "gtkfilesystemwin32.h"
84 #include <sys/types.h>
95 #undef PROFILE_FILE_CHOOSER
96 #ifdef PROFILE_FILE_CHOOSER
103 #define PROFILE_INDENT 4
104 static int profile_indent;
107 profile_add_indent (int indent)
109 profile_indent += indent;
110 if (profile_indent < 0)
111 g_error ("You screwed up your indentation");
115 _gtk_file_chooser_profile_log (const char *func, int indent, const char *msg1, const char *msg2)
120 profile_add_indent (indent);
122 if (profile_indent == 0)
123 str = g_strdup_printf ("MARK: %s %s %s", func ? func : "", msg1 ? msg1 : "", msg2 ? msg2 : "");
125 str = g_strdup_printf ("MARK: %*c %s %s %s", profile_indent - 1, ' ', func ? func : "", msg1 ? msg1 : "", msg2 ? msg2 : "");
131 profile_add_indent (indent);
134 #define profile_start(x, y) _gtk_file_chooser_profile_log (G_STRFUNC, PROFILE_INDENT, x, y)
135 #define profile_end(x, y) _gtk_file_chooser_profile_log (G_STRFUNC, -PROFILE_INDENT, x, y)
136 #define profile_msg(x, y) _gtk_file_chooser_profile_log (NULL, 0, x, y)
138 #define profile_start(x, y)
139 #define profile_end(x, y)
140 #define profile_msg(x, y)
145 typedef struct _GtkFileChooserDefaultClass GtkFileChooserDefaultClass;
147 #define GTK_FILE_CHOOSER_DEFAULT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FILE_CHOOSER_DEFAULT, GtkFileChooserDefaultClass))
148 #define GTK_IS_FILE_CHOOSER_DEFAULT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FILE_CHOOSER_DEFAULT))
149 #define GTK_FILE_CHOOSER_DEFAULT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FILE_CHOOSER_DEFAULT, GtkFileChooserDefaultClass))
151 #define MAX_LOADING_TIME 500
153 struct _GtkFileChooserDefaultClass
155 GtkVBoxClass parent_class;
161 LOCATION_POPUP_ON_PASTE,
167 LOCATION_TOGGLE_POPUP,
175 static guint signals[LAST_SIGNAL] = { 0 };
177 /* Column numbers for the shortcuts tree. Keep these in sync with shortcuts_model_create() */
179 SHORTCUTS_COL_PIXBUF,
183 SHORTCUTS_COL_REMOVABLE,
184 SHORTCUTS_COL_PIXBUF_VISIBLE,
185 SHORTCUTS_COL_HANDLE,
186 SHORTCUTS_COL_NUM_COLUMNS
191 SHORTCUT_TYPE_VOLUME,
192 SHORTCUT_TYPE_SEPARATOR,
193 SHORTCUT_TYPE_SEARCH,
197 /* Column numbers for the file list */
202 FILE_LIST_COL_NUM_COLUMNS
205 /* Column numbers for the search model.
206 * Keep this in sync with search_setup_model()
209 SEARCH_MODEL_COL_PATH,
210 SEARCH_MODEL_COL_DISPLAY_NAME,
211 SEARCH_MODEL_COL_COLLATION_KEY,
212 SEARCH_MODEL_COL_STAT,
213 SEARCH_MODEL_COL_HANDLE,
214 SEARCH_MODEL_COL_PIXBUF,
215 SEARCH_MODEL_COL_MIME_TYPE,
216 SEARCH_MODEL_COL_IS_FOLDER,
217 SEARCH_MODEL_COL_NUM_COLUMNS
221 RECENT_MODEL_COL_PATH,
222 RECENT_MODEL_COL_DISPLAY_NAME,
223 RECENT_MODEL_COL_INFO,
224 RECENT_MODEL_COL_IS_FOLDER,
225 RECENT_MODEL_COL_HANDLE,
226 RECENT_MODEL_COL_NUM_COLUMNS
229 /* Identifiers for target types */
235 /* Target types for dragging from the shortcuts list */
236 static const GtkTargetEntry shortcuts_source_targets[] = {
237 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, GTK_TREE_MODEL_ROW }
240 static const int num_shortcuts_source_targets = G_N_ELEMENTS (shortcuts_source_targets);
242 /* Target types for dropping into the shortcuts list */
243 static const GtkTargetEntry shortcuts_dest_targets[] = {
244 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, GTK_TREE_MODEL_ROW },
245 { "text/uri-list", 0, TEXT_URI_LIST }
248 static const int num_shortcuts_dest_targets = G_N_ELEMENTS (shortcuts_dest_targets);
250 /* Target types for DnD from the file list */
251 static const GtkTargetEntry file_list_source_targets[] = {
252 { "text/uri-list", 0, TEXT_URI_LIST }
255 static const int num_file_list_source_targets = G_N_ELEMENTS (file_list_source_targets);
257 /* Target types for dropping into the file list */
258 static const GtkTargetEntry file_list_dest_targets[] = {
259 { "text/uri-list", 0, TEXT_URI_LIST }
262 static const int num_file_list_dest_targets = G_N_ELEMENTS (file_list_dest_targets);
264 /* Target types for dragging from the recent files list */
265 static const GtkTargetEntry recent_list_source_targets[] = {
266 { "text/uri-list", 0, TEXT_URI_LIST }
269 static const int num_recent_list_source_targets = G_N_ELEMENTS (recent_list_source_targets);
272 search_is_possible (GtkFileChooserDefault *impl)
274 if (impl->search_engine == NULL)
275 impl->search_engine = _gtk_search_engine_new ();
277 return impl->search_engine != NULL;
280 /* Interesting places in the shortcuts bar */
284 SHORTCUTS_RECENT_SEPARATOR,
289 SHORTCUTS_BOOKMARKS_SEPARATOR,
291 SHORTCUTS_CURRENT_FOLDER_SEPARATOR,
292 SHORTCUTS_CURRENT_FOLDER
295 /* Icon size for if we can't get it from the theme */
296 #define FALLBACK_ICON_SIZE 16
298 #define PREVIEW_HBOX_SPACING 12
302 static void gtk_file_chooser_default_iface_init (GtkFileChooserIface *iface);
303 static void gtk_file_chooser_embed_default_iface_init (GtkFileChooserEmbedIface *iface);
305 static GObject* gtk_file_chooser_default_constructor (GType type,
306 guint n_construct_properties,
307 GObjectConstructParam *construct_params);
308 static void gtk_file_chooser_default_finalize (GObject *object);
309 static void gtk_file_chooser_default_set_property (GObject *object,
313 static void gtk_file_chooser_default_get_property (GObject *object,
317 static void gtk_file_chooser_default_dispose (GObject *object);
318 static void gtk_file_chooser_default_show_all (GtkWidget *widget);
319 static void gtk_file_chooser_default_map (GtkWidget *widget);
320 static void gtk_file_chooser_default_unmap (GtkWidget *widget);
321 static void gtk_file_chooser_default_hierarchy_changed (GtkWidget *widget,
322 GtkWidget *previous_toplevel);
323 static void gtk_file_chooser_default_style_set (GtkWidget *widget,
324 GtkStyle *previous_style);
325 static void gtk_file_chooser_default_screen_changed (GtkWidget *widget,
326 GdkScreen *previous_screen);
327 static void gtk_file_chooser_default_size_allocate (GtkWidget *widget,
328 GtkAllocation *allocation);
330 static gboolean gtk_file_chooser_default_set_current_folder (GtkFileChooser *chooser,
331 const GtkFilePath *path,
333 static gboolean gtk_file_chooser_default_update_current_folder (GtkFileChooser *chooser,
334 const GtkFilePath *path,
336 gboolean clear_entry,
338 static GtkFilePath * gtk_file_chooser_default_get_current_folder (GtkFileChooser *chooser);
339 static void gtk_file_chooser_default_set_current_name (GtkFileChooser *chooser,
341 static gboolean gtk_file_chooser_default_select_path (GtkFileChooser *chooser,
342 const GtkFilePath *path,
344 static void gtk_file_chooser_default_unselect_path (GtkFileChooser *chooser,
345 const GtkFilePath *path);
346 static void gtk_file_chooser_default_select_all (GtkFileChooser *chooser);
347 static void gtk_file_chooser_default_unselect_all (GtkFileChooser *chooser);
348 static GSList * gtk_file_chooser_default_get_paths (GtkFileChooser *chooser);
349 static GtkFilePath * gtk_file_chooser_default_get_preview_path (GtkFileChooser *chooser);
350 static GtkFileSystem *gtk_file_chooser_default_get_file_system (GtkFileChooser *chooser);
351 static void gtk_file_chooser_default_add_filter (GtkFileChooser *chooser,
352 GtkFileFilter *filter);
353 static void gtk_file_chooser_default_remove_filter (GtkFileChooser *chooser,
354 GtkFileFilter *filter);
355 static GSList * gtk_file_chooser_default_list_filters (GtkFileChooser *chooser);
356 static gboolean gtk_file_chooser_default_add_shortcut_folder (GtkFileChooser *chooser,
357 const GtkFilePath *path,
359 static gboolean gtk_file_chooser_default_remove_shortcut_folder (GtkFileChooser *chooser,
360 const GtkFilePath *path,
362 static GSList * gtk_file_chooser_default_list_shortcut_folders (GtkFileChooser *chooser);
364 static void gtk_file_chooser_default_get_default_size (GtkFileChooserEmbed *chooser_embed,
366 gint *default_height);
367 static gboolean gtk_file_chooser_default_get_resizable (GtkFileChooserEmbed *chooser_embed);
368 static gboolean gtk_file_chooser_default_should_respond (GtkFileChooserEmbed *chooser_embed);
369 static void gtk_file_chooser_default_initial_focus (GtkFileChooserEmbed *chooser_embed);
371 static void location_popup_handler (GtkFileChooserDefault *impl,
373 static void location_popup_on_paste_handler (GtkFileChooserDefault *impl);
374 static void location_toggle_popup_handler (GtkFileChooserDefault *impl);
375 static void up_folder_handler (GtkFileChooserDefault *impl);
376 static void down_folder_handler (GtkFileChooserDefault *impl);
377 static void home_folder_handler (GtkFileChooserDefault *impl);
378 static void desktop_folder_handler (GtkFileChooserDefault *impl);
379 static void quick_bookmark_handler (GtkFileChooserDefault *impl,
380 gint bookmark_index);
381 static void show_hidden_handler (GtkFileChooserDefault *impl);
382 static void search_shortcut_handler (GtkFileChooserDefault *impl);
383 static void recent_shortcut_handler (GtkFileChooserDefault *impl);
384 static void update_appearance (GtkFileChooserDefault *impl);
386 static void set_current_filter (GtkFileChooserDefault *impl,
387 GtkFileFilter *filter);
388 static void check_preview_change (GtkFileChooserDefault *impl);
390 static void filter_combo_changed (GtkComboBox *combo_box,
391 GtkFileChooserDefault *impl);
392 static void shortcuts_row_activated_cb (GtkTreeView *tree_view,
394 GtkTreeViewColumn *column,
395 GtkFileChooserDefault *impl);
397 static gboolean shortcuts_key_press_event_cb (GtkWidget *widget,
399 GtkFileChooserDefault *impl);
401 static gboolean shortcuts_select_func (GtkTreeSelection *selection,
404 gboolean path_currently_selected,
406 static gboolean shortcuts_get_selected (GtkFileChooserDefault *impl,
408 static void shortcuts_activate_iter (GtkFileChooserDefault *impl,
410 static int shortcuts_get_index (GtkFileChooserDefault *impl,
411 ShortcutsIndex where);
412 static int shortcut_find_position (GtkFileChooserDefault *impl,
413 const GtkFilePath *path);
415 static void bookmarks_check_add_sensitivity (GtkFileChooserDefault *impl);
417 static gboolean list_select_func (GtkTreeSelection *selection,
420 gboolean path_currently_selected,
423 static void list_selection_changed (GtkTreeSelection *tree_selection,
424 GtkFileChooserDefault *impl);
425 static void list_row_activated (GtkTreeView *tree_view,
427 GtkTreeViewColumn *column,
428 GtkFileChooserDefault *impl);
430 static void select_func (GtkFileSystemModel *model,
435 static void path_bar_clicked (GtkPathBar *path_bar,
436 GtkFilePath *file_path,
437 GtkFilePath *child_path,
438 gboolean child_is_hidden,
439 GtkFileChooserDefault *impl);
441 static void add_bookmark_button_clicked_cb (GtkButton *button,
442 GtkFileChooserDefault *impl);
443 static void remove_bookmark_button_clicked_cb (GtkButton *button,
444 GtkFileChooserDefault *impl);
445 static void save_folder_combo_changed_cb (GtkComboBox *combo,
446 GtkFileChooserDefault *impl);
448 static void list_icon_data_func (GtkTreeViewColumn *tree_column,
449 GtkCellRenderer *cell,
450 GtkTreeModel *tree_model,
453 static void list_name_data_func (GtkTreeViewColumn *tree_column,
454 GtkCellRenderer *cell,
455 GtkTreeModel *tree_model,
459 static void list_size_data_func (GtkTreeViewColumn *tree_column,
460 GtkCellRenderer *cell,
461 GtkTreeModel *tree_model,
465 static void list_mtime_data_func (GtkTreeViewColumn *tree_column,
466 GtkCellRenderer *cell,
467 GtkTreeModel *tree_model,
471 static const GtkFileInfo *get_list_file_info (GtkFileChooserDefault *impl,
474 static void load_remove_timer (GtkFileChooserDefault *impl);
475 static void browse_files_center_selected_row (GtkFileChooserDefault *impl);
477 static void location_button_toggled_cb (GtkToggleButton *toggle,
478 GtkFileChooserDefault *impl);
479 static void location_switch_to_path_bar (GtkFileChooserDefault *impl);
481 static void search_stop_searching (GtkFileChooserDefault *impl,
482 gboolean remove_query);
483 static void search_clear_model (GtkFileChooserDefault *impl,
484 gboolean remove_from_treeview);
485 static gboolean search_should_respond (GtkFileChooserDefault *impl);
486 static void search_switch_to_browse_mode (GtkFileChooserDefault *impl);
487 static GSList *search_get_selected_paths (GtkFileChooserDefault *impl);
488 static void search_entry_activate_cb (GtkEntry *entry,
490 static void settings_load (GtkFileChooserDefault *impl);
491 static void search_get_valid_child_iter (GtkFileChooserDefault *impl,
492 GtkTreeIter *child_iter,
495 static void recent_manager_update (GtkFileChooserDefault *impl);
496 static void recent_stop_loading (GtkFileChooserDefault *impl);
497 static void recent_clear_model (GtkFileChooserDefault *impl,
498 gboolean remove_from_treeview);
499 static gboolean recent_should_respond (GtkFileChooserDefault *impl);
500 static void recent_switch_to_browse_mode (GtkFileChooserDefault *impl);
501 static GSList * recent_get_selected_paths (GtkFileChooserDefault *impl);
502 static void recent_get_valid_child_iter (GtkFileChooserDefault *impl,
503 GtkTreeIter *child_iter,
509 /* Drag and drop interface declarations */
512 GtkTreeModelFilter parent;
514 GtkFileChooserDefault *impl;
515 } ShortcutsPaneModelFilter;
518 GtkTreeModelFilterClass parent_class;
519 } ShortcutsPaneModelFilterClass;
521 #define SHORTCUTS_PANE_MODEL_FILTER_TYPE (_shortcuts_pane_model_filter_get_type ())
522 #define SHORTCUTS_PANE_MODEL_FILTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SHORTCUTS_PANE_MODEL_FILTER_TYPE, ShortcutsPaneModelFilter))
524 static void shortcuts_pane_model_filter_drag_source_iface_init (GtkTreeDragSourceIface *iface);
526 G_DEFINE_TYPE_WITH_CODE (ShortcutsPaneModelFilter,
527 _shortcuts_pane_model_filter,
528 GTK_TYPE_TREE_MODEL_FILTER,
529 G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_DRAG_SOURCE,
530 shortcuts_pane_model_filter_drag_source_iface_init))
532 static GtkTreeModel *shortcuts_pane_model_filter_new (GtkFileChooserDefault *impl,
533 GtkTreeModel *child_model,
538 GtkTreeModelSort parent;
540 GtkFileChooserDefault *impl;
544 GtkTreeModelSortClass parent_class;
545 } RecentModelSortClass;
547 #define RECENT_MODEL_SORT_TYPE (_recent_model_sort_get_type ())
548 #define RECENT_MODEL_SORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RECENT_MODEL_SORT_TYPE, RecentModelSort))
550 static void recent_model_sort_drag_source_iface_init (GtkTreeDragSourceIface *iface);
552 G_DEFINE_TYPE_WITH_CODE (RecentModelSort,
554 GTK_TYPE_TREE_MODEL_SORT,
555 G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_DRAG_SOURCE,
556 recent_model_sort_drag_source_iface_init));
558 static GtkTreeModel *recent_model_sort_new (GtkFileChooserDefault *impl,
559 GtkTreeModel *child_model);
563 GtkTreeModelSort parent;
565 GtkFileChooserDefault *impl;
569 GtkTreeModelSortClass parent_class;
570 } SearchModelSortClass;
572 #define SEARCH_MODEL_SORT_TYPE (_search_model_sort_get_type ())
573 #define SEARCH_MODEL_SORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SEARCH_MODEL_SORT_TYPE, SearchModelSort))
575 static void search_model_sort_drag_source_iface_init (GtkTreeDragSourceIface *iface);
577 G_DEFINE_TYPE_WITH_CODE (SearchModelSort,
579 GTK_TYPE_TREE_MODEL_SORT,
580 G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_DRAG_SOURCE,
581 search_model_sort_drag_source_iface_init));
583 static GtkTreeModel *search_model_sort_new (GtkFileChooserDefault *impl,
584 GtkTreeModel *child_model);
588 G_DEFINE_TYPE_WITH_CODE (GtkFileChooserDefault, _gtk_file_chooser_default, GTK_TYPE_VBOX,
589 G_IMPLEMENT_INTERFACE (GTK_TYPE_FILE_CHOOSER,
590 gtk_file_chooser_default_iface_init)
591 G_IMPLEMENT_INTERFACE (GTK_TYPE_FILE_CHOOSER_EMBED,
592 gtk_file_chooser_embed_default_iface_init));
595 _gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class)
597 static const guint quick_bookmark_keyvals[10] = {
598 GDK_1, GDK_2, GDK_3, GDK_4, GDK_5, GDK_6, GDK_7, GDK_8, GDK_9, GDK_0
600 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
601 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
602 GtkBindingSet *binding_set;
605 gobject_class->finalize = gtk_file_chooser_default_finalize;
606 gobject_class->constructor = gtk_file_chooser_default_constructor;
607 gobject_class->set_property = gtk_file_chooser_default_set_property;
608 gobject_class->get_property = gtk_file_chooser_default_get_property;
609 gobject_class->dispose = gtk_file_chooser_default_dispose;
611 widget_class->show_all = gtk_file_chooser_default_show_all;
612 widget_class->map = gtk_file_chooser_default_map;
613 widget_class->unmap = gtk_file_chooser_default_unmap;
614 widget_class->hierarchy_changed = gtk_file_chooser_default_hierarchy_changed;
615 widget_class->style_set = gtk_file_chooser_default_style_set;
616 widget_class->screen_changed = gtk_file_chooser_default_screen_changed;
617 widget_class->size_allocate = gtk_file_chooser_default_size_allocate;
619 signals[LOCATION_POPUP] =
620 _gtk_binding_signal_new (I_("location-popup"),
621 G_OBJECT_CLASS_TYPE (class),
622 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
623 G_CALLBACK (location_popup_handler),
625 _gtk_marshal_VOID__STRING,
626 G_TYPE_NONE, 1, G_TYPE_STRING);
627 signals[LOCATION_POPUP_ON_PASTE] =
628 _gtk_binding_signal_new ("location-popup-on-paste",
629 G_OBJECT_CLASS_TYPE (class),
630 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
631 G_CALLBACK (location_popup_on_paste_handler),
633 _gtk_marshal_VOID__VOID,
635 signals[LOCATION_TOGGLE_POPUP] =
636 _gtk_binding_signal_new (I_("location-toggle-popup"),
637 G_OBJECT_CLASS_TYPE (class),
638 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
639 G_CALLBACK (location_toggle_popup_handler),
641 _gtk_marshal_VOID__VOID,
644 _gtk_binding_signal_new (I_("up-folder"),
645 G_OBJECT_CLASS_TYPE (class),
646 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
647 G_CALLBACK (up_folder_handler),
649 _gtk_marshal_VOID__VOID,
651 signals[DOWN_FOLDER] =
652 _gtk_binding_signal_new (I_("down-folder"),
653 G_OBJECT_CLASS_TYPE (class),
654 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
655 G_CALLBACK (down_folder_handler),
657 _gtk_marshal_VOID__VOID,
659 signals[HOME_FOLDER] =
660 _gtk_binding_signal_new (I_("home-folder"),
661 G_OBJECT_CLASS_TYPE (class),
662 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
663 G_CALLBACK (home_folder_handler),
665 _gtk_marshal_VOID__VOID,
667 signals[DESKTOP_FOLDER] =
668 _gtk_binding_signal_new (I_("desktop-folder"),
669 G_OBJECT_CLASS_TYPE (class),
670 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
671 G_CALLBACK (desktop_folder_handler),
673 _gtk_marshal_VOID__VOID,
675 signals[QUICK_BOOKMARK] =
676 _gtk_binding_signal_new (I_("quick-bookmark"),
677 G_OBJECT_CLASS_TYPE (class),
678 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
679 G_CALLBACK (quick_bookmark_handler),
681 _gtk_marshal_VOID__INT,
682 G_TYPE_NONE, 1, G_TYPE_INT);
683 signals[SHOW_HIDDEN] =
684 _gtk_binding_signal_new ("show-hidden",
685 G_OBJECT_CLASS_TYPE (class),
686 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
687 G_CALLBACK (show_hidden_handler),
689 _gtk_marshal_VOID__VOID,
691 signals[SEARCH_SHORTCUT] =
692 _gtk_binding_signal_new ("search-shortcut",
693 G_OBJECT_CLASS_TYPE (class),
694 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
695 G_CALLBACK (search_shortcut_handler),
697 _gtk_marshal_VOID__VOID,
699 signals[RECENT_SHORTCUT] =
700 _gtk_binding_signal_new ("recent-shortcut",
701 G_OBJECT_CLASS_TYPE (class),
702 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
703 G_CALLBACK (recent_shortcut_handler),
705 _gtk_marshal_VOID__VOID,
708 binding_set = gtk_binding_set_by_class (class);
710 gtk_binding_entry_add_signal (binding_set,
711 GDK_l, GDK_CONTROL_MASK,
712 "location-toggle-popup",
715 gtk_binding_entry_add_signal (binding_set,
718 1, G_TYPE_STRING, "/");
719 gtk_binding_entry_add_signal (binding_set,
722 1, G_TYPE_STRING, "/");
725 gtk_binding_entry_add_signal (binding_set,
728 1, G_TYPE_STRING, "~");
731 gtk_binding_entry_add_signal (binding_set,
732 GDK_v, GDK_CONTROL_MASK,
733 "location-popup-on-paste",
735 gtk_binding_entry_add_signal (binding_set,
736 GDK_Up, GDK_MOD1_MASK,
739 gtk_binding_entry_add_signal (binding_set,
743 gtk_binding_entry_add_signal (binding_set,
744 GDK_KP_Up, GDK_MOD1_MASK,
748 gtk_binding_entry_add_signal (binding_set,
749 GDK_Down, GDK_MOD1_MASK,
752 gtk_binding_entry_add_signal (binding_set,
753 GDK_KP_Down, GDK_MOD1_MASK,
757 gtk_binding_entry_add_signal (binding_set,
758 GDK_Home, GDK_MOD1_MASK,
761 gtk_binding_entry_add_signal (binding_set,
762 GDK_KP_Home, GDK_MOD1_MASK,
765 gtk_binding_entry_add_signal (binding_set,
766 GDK_d, GDK_MOD1_MASK,
769 gtk_binding_entry_add_signal (binding_set,
770 GDK_h, GDK_CONTROL_MASK,
773 gtk_binding_entry_add_signal (binding_set,
774 GDK_s, GDK_MOD1_MASK,
777 gtk_binding_entry_add_signal (binding_set,
778 GDK_r, GDK_MOD1_MASK,
782 for (i = 0; i < 10; i++)
783 gtk_binding_entry_add_signal (binding_set,
784 quick_bookmark_keyvals[i], GDK_MOD1_MASK,
788 _gtk_file_chooser_install_properties (gobject_class);
792 gtk_file_chooser_default_iface_init (GtkFileChooserIface *iface)
794 iface->select_path = gtk_file_chooser_default_select_path;
795 iface->unselect_path = gtk_file_chooser_default_unselect_path;
796 iface->select_all = gtk_file_chooser_default_select_all;
797 iface->unselect_all = gtk_file_chooser_default_unselect_all;
798 iface->get_paths = gtk_file_chooser_default_get_paths;
799 iface->get_preview_path = gtk_file_chooser_default_get_preview_path;
800 iface->get_file_system = gtk_file_chooser_default_get_file_system;
801 iface->set_current_folder = gtk_file_chooser_default_set_current_folder;
802 iface->get_current_folder = gtk_file_chooser_default_get_current_folder;
803 iface->set_current_name = gtk_file_chooser_default_set_current_name;
804 iface->add_filter = gtk_file_chooser_default_add_filter;
805 iface->remove_filter = gtk_file_chooser_default_remove_filter;
806 iface->list_filters = gtk_file_chooser_default_list_filters;
807 iface->add_shortcut_folder = gtk_file_chooser_default_add_shortcut_folder;
808 iface->remove_shortcut_folder = gtk_file_chooser_default_remove_shortcut_folder;
809 iface->list_shortcut_folders = gtk_file_chooser_default_list_shortcut_folders;
813 gtk_file_chooser_embed_default_iface_init (GtkFileChooserEmbedIface *iface)
815 iface->get_default_size = gtk_file_chooser_default_get_default_size;
816 iface->get_resizable = gtk_file_chooser_default_get_resizable;
817 iface->should_respond = gtk_file_chooser_default_should_respond;
818 iface->initial_focus = gtk_file_chooser_default_initial_focus;
822 _gtk_file_chooser_default_init (GtkFileChooserDefault *impl)
824 profile_start ("start", NULL);
825 #ifdef PROFILE_FILE_CHOOSER
826 access ("MARK: *** CREATE FILE CHOOSER", F_OK);
828 impl->local_only = TRUE;
829 impl->preview_widget_active = TRUE;
830 impl->use_preview_label = TRUE;
831 impl->select_multiple = FALSE;
832 impl->show_hidden = FALSE;
833 impl->icon_size = FALLBACK_ICON_SIZE;
834 impl->load_state = LOAD_EMPTY;
835 impl->reload_state = RELOAD_EMPTY;
836 impl->pending_select_paths = NULL;
837 impl->location_mode = LOCATION_MODE_PATH_BAR;
838 impl->operation_mode = OPERATION_MODE_BROWSE;
840 gtk_box_set_spacing (GTK_BOX (impl), 12);
842 impl->tooltips = gtk_tooltips_new ();
843 g_object_ref_sink (impl->tooltips);
845 profile_end ("end", NULL);
848 /* Frees the data columns for the specified iter in the shortcuts model*/
850 shortcuts_free_row_data (GtkFileChooserDefault *impl,
854 ShortcutType shortcut_type;
855 GtkFileSystemHandle *handle;
857 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), iter,
858 SHORTCUTS_COL_DATA, &col_data,
859 SHORTCUTS_COL_TYPE, &shortcut_type,
860 SHORTCUTS_COL_HANDLE, &handle,
864 gtk_file_system_cancel_operation (handle);
866 if (!(shortcut_type == SHORTCUT_TYPE_PATH ||
867 shortcut_type == SHORTCUT_TYPE_VOLUME) ||
871 if (shortcut_type == SHORTCUT_TYPE_VOLUME)
873 GtkFileSystemVolume *volume;
876 gtk_file_system_volume_free (impl->file_system, volume);
882 g_assert (shortcut_type == SHORTCUT_TYPE_PATH);
885 gtk_file_path_free (path);
889 /* Frees all the data columns in the shortcuts model */
891 shortcuts_free (GtkFileChooserDefault *impl)
895 if (!impl->shortcuts_model)
898 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
901 shortcuts_free_row_data (impl, &iter);
903 while (gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter));
905 g_object_unref (impl->shortcuts_model);
906 impl->shortcuts_model = NULL;
910 pending_select_paths_free (GtkFileChooserDefault *impl)
914 for (l = impl->pending_select_paths; l; l = l->next)
919 gtk_file_path_free (path);
922 g_slist_free (impl->pending_select_paths);
923 impl->pending_select_paths = NULL;
927 pending_select_paths_add (GtkFileChooserDefault *impl,
928 const GtkFilePath *path)
930 impl->pending_select_paths =
931 g_slist_prepend (impl->pending_select_paths, gtk_file_path_copy (path));
934 /* Used from gtk_tree_selection_selected_foreach() */
936 store_selection_foreach (GtkTreeModel *model,
941 GtkFileChooserDefault *impl;
942 GtkTreeIter child_iter;
943 const GtkFilePath *file_path;
945 impl = GTK_FILE_CHOOSER_DEFAULT (data);
947 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model, &child_iter, iter);
949 file_path = _gtk_file_system_model_get_path (impl->browse_files_model, &child_iter);
950 pending_select_paths_add (impl, file_path);
953 /* Stores the current selection in the list of paths to select; this is used to
954 * preserve the selection when reloading the current folder.
957 pending_select_paths_store_selection (GtkFileChooserDefault *impl)
959 GtkTreeSelection *selection;
961 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
962 gtk_tree_selection_selected_foreach (selection, store_selection_foreach, impl);
966 gtk_file_chooser_default_finalize (GObject *object)
968 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (object);
971 if (impl->shortcuts_pane_filter_model)
972 g_object_unref (impl->shortcuts_pane_filter_model);
974 if (impl->shortcuts_combo_filter_model)
975 g_object_unref (impl->shortcuts_combo_filter_model);
977 shortcuts_free (impl);
979 g_object_unref (impl->file_system);
981 g_free (impl->browse_files_last_selected_name);
983 for (l = impl->filters; l; l = l->next)
985 GtkFileFilter *filter;
987 filter = GTK_FILE_FILTER (l->data);
988 g_object_unref (filter);
990 g_slist_free (impl->filters);
992 if (impl->current_filter)
993 g_object_unref (impl->current_filter);
995 if (impl->current_volume_path)
996 gtk_file_path_free (impl->current_volume_path);
998 if (impl->current_folder)
999 gtk_file_path_free (impl->current_folder);
1001 if (impl->preview_path)
1002 gtk_file_path_free (impl->preview_path);
1004 load_remove_timer (impl);
1006 /* Free all the Models we have */
1007 if (impl->browse_files_model)
1008 g_object_unref (impl->browse_files_model);
1010 if (impl->sort_model)
1011 g_object_unref (impl->sort_model);
1013 search_clear_model (impl, FALSE);
1014 recent_clear_model (impl, FALSE);
1016 g_free (impl->preview_display_name);
1018 g_free (impl->edited_new_text);
1020 g_object_unref (impl->tooltips);
1022 G_OBJECT_CLASS (_gtk_file_chooser_default_parent_class)->finalize (object);
1025 /* Shows an error dialog set as transient for the specified window */
1027 error_message_with_parent (GtkWindow *parent,
1033 dialog = gtk_message_dialog_new (parent,
1034 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
1039 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
1043 gtk_window_group_add_window (parent->group, GTK_WINDOW (dialog));
1045 gtk_dialog_run (GTK_DIALOG (dialog));
1046 gtk_widget_destroy (dialog);
1049 /* Returns a toplevel GtkWindow, or NULL if none */
1051 get_toplevel (GtkWidget *widget)
1053 GtkWidget *toplevel;
1055 toplevel = gtk_widget_get_toplevel (widget);
1056 if (!GTK_WIDGET_TOPLEVEL (toplevel))
1059 return GTK_WINDOW (toplevel);
1062 /* Shows an error dialog for the file chooser */
1064 error_message (GtkFileChooserDefault *impl,
1068 error_message_with_parent (get_toplevel (GTK_WIDGET (impl)), msg, detail);
1071 /* Shows a simple error dialog relative to a path. Frees the GError as well. */
1073 error_dialog (GtkFileChooserDefault *impl,
1075 const GtkFilePath *path,
1084 uri = gtk_file_system_path_to_uri (impl->file_system, path);
1085 text = g_strdup_printf (msg, uri);
1086 error_message (impl, text, error->message);
1089 g_error_free (error);
1093 /* Displays an error message about not being able to get information for a file.
1094 * Frees the GError as well.
1097 error_getting_info_dialog (GtkFileChooserDefault *impl,
1098 const GtkFilePath *path,
1102 _("Could not retrieve information about the file"),
1106 /* Shows an error dialog about not being able to add a bookmark */
1108 error_adding_bookmark_dialog (GtkFileChooserDefault *impl,
1109 const GtkFilePath *path,
1113 _("Could not add a bookmark"),
1117 /* Shows an error dialog about not being able to remove a bookmark */
1119 error_removing_bookmark_dialog (GtkFileChooserDefault *impl,
1120 const GtkFilePath *path,
1124 _("Could not remove bookmark"),
1128 /* Shows an error dialog about not being able to create a folder */
1130 error_creating_folder_dialog (GtkFileChooserDefault *impl,
1131 const GtkFilePath *path,
1135 _("The folder could not be created"),
1139 /* Shows an error about not being able to create a folder because a file with
1140 * the same name is already there.
1143 error_creating_folder_over_existing_file_dialog (GtkFileChooserDefault *impl,
1144 const GtkFilePath *path,
1148 _("The folder could not be created, as a file with the same "
1149 "name already exists. Try using a different name for the "
1150 "folder, or rename the file first."),
1154 /* Shows an error dialog about not being able to create a filename */
1156 error_building_filename_dialog (GtkFileChooserDefault *impl,
1157 const GtkFilePath *folder_part,
1158 const char *file_part,
1161 error_dialog (impl, _("Invalid file name"),
1165 /* Shows an error dialog when we cannot switch to a folder */
1167 error_changing_folder_dialog (GtkFileChooserDefault *impl,
1168 const GtkFilePath *path,
1171 error_dialog (impl, _("The folder contents could not be displayed"),
1175 /* Changes folders, displaying an error dialog if this fails */
1177 change_folder_and_display_error (GtkFileChooserDefault *impl,
1178 const GtkFilePath *path,
1179 gboolean clear_entry)
1183 GtkFilePath *path_copy;
1185 g_return_val_if_fail (path != NULL, FALSE);
1187 profile_start ("start", (char *) path);
1189 /* We copy the path because of this case:
1191 * list_row_activated()
1192 * fetches path from model; path belongs to the model (*)
1193 * calls change_folder_and_display_error()
1194 * calls _gtk_file_chooser_set_current_folder_path()
1195 * changing folders fails, sets model to NULL, thus freeing the path in (*)
1198 path_copy = gtk_file_path_copy (path);
1201 result = gtk_file_chooser_default_update_current_folder (GTK_FILE_CHOOSER (impl), path_copy, TRUE, clear_entry, &error);
1204 error_changing_folder_dialog (impl, path_copy, error);
1206 gtk_file_path_free (path_copy);
1208 profile_end ("end", (char *) path);
1214 update_preview_widget_visibility (GtkFileChooserDefault *impl)
1216 if (impl->use_preview_label)
1218 if (!impl->preview_label)
1220 impl->preview_label = gtk_label_new (impl->preview_display_name);
1221 gtk_box_pack_start (GTK_BOX (impl->preview_box), impl->preview_label, FALSE, FALSE, 0);
1222 gtk_box_reorder_child (GTK_BOX (impl->preview_box), impl->preview_label, 0);
1223 gtk_label_set_ellipsize (GTK_LABEL (impl->preview_label), PANGO_ELLIPSIZE_MIDDLE);
1224 gtk_widget_show (impl->preview_label);
1229 if (impl->preview_label)
1231 gtk_widget_destroy (impl->preview_label);
1232 impl->preview_label = NULL;
1236 if (impl->preview_widget_active && impl->preview_widget)
1237 gtk_widget_show (impl->preview_box);
1239 gtk_widget_hide (impl->preview_box);
1241 g_signal_emit_by_name (impl, "default-size-changed");
1245 set_preview_widget (GtkFileChooserDefault *impl,
1246 GtkWidget *preview_widget)
1248 if (preview_widget == impl->preview_widget)
1251 if (impl->preview_widget)
1252 gtk_container_remove (GTK_CONTAINER (impl->preview_box),
1253 impl->preview_widget);
1255 impl->preview_widget = preview_widget;
1256 if (impl->preview_widget)
1258 gtk_widget_show (impl->preview_widget);
1259 gtk_box_pack_start (GTK_BOX (impl->preview_box), impl->preview_widget, TRUE, TRUE, 0);
1260 gtk_box_reorder_child (GTK_BOX (impl->preview_box),
1261 impl->preview_widget,
1262 (impl->use_preview_label && impl->preview_label) ? 1 : 0);
1265 update_preview_widget_visibility (impl);
1268 /* Renders a "Search" icon at an appropriate size for a tree view */
1270 render_search_icon (GtkFileChooserDefault *impl)
1272 return gtk_widget_render_icon (GTK_WIDGET (impl), GTK_STOCK_FIND, GTK_ICON_SIZE_MENU, NULL);
1276 render_recent_icon (GtkFileChooserDefault *impl)
1278 return gtk_widget_render_icon (GTK_WIDGET (impl), GTK_STOCK_FILE, GTK_ICON_SIZE_MENU, NULL);
1282 /* Re-reads all the icons for the shortcuts, used when the theme changes */
1283 struct ReloadIconsData
1285 GtkFileChooserDefault *impl;
1286 GtkTreeRowReference *row_ref;
1290 shortcuts_reload_icons_get_info_cb (GtkFileSystemHandle *handle,
1291 const GtkFileInfo *info,
1292 const GError *error,
1298 gboolean cancelled = handle->cancelled;
1299 struct ReloadIconsData *data = user_data;
1301 if (!g_slist_find (data->impl->reload_icon_handles, handle))
1304 data->impl->reload_icon_handles = g_slist_remove (data->impl->reload_icon_handles, handle);
1306 if (cancelled || error)
1309 pixbuf = gtk_file_info_render_icon (info, GTK_WIDGET (data->impl),
1310 data->impl->icon_size, NULL);
1312 path = gtk_tree_row_reference_get_path (data->row_ref);
1313 gtk_tree_model_get_iter (GTK_TREE_MODEL (data->impl->shortcuts_model), &iter, path);
1314 gtk_list_store_set (data->impl->shortcuts_model, &iter,
1315 SHORTCUTS_COL_PIXBUF, pixbuf,
1317 gtk_tree_path_free (path);
1320 g_object_unref (pixbuf);
1323 gtk_tree_row_reference_free (data->row_ref);
1324 g_object_unref (data->impl);
1327 g_object_unref (handle);
1331 shortcuts_reload_icons (GtkFileChooserDefault *impl)
1336 profile_start ("start", NULL);
1338 if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
1341 for (l = impl->reload_icon_handles; l; l = l->next)
1343 GtkFileSystemHandle *handle = GTK_FILE_SYSTEM_HANDLE (l->data);
1344 gtk_file_system_cancel_operation (handle);
1346 g_slist_free (impl->reload_icon_handles);
1347 impl->reload_icon_handles = NULL;
1352 ShortcutType shortcut_type;
1353 gboolean pixbuf_visible;
1356 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
1357 SHORTCUTS_COL_DATA, &data,
1358 SHORTCUTS_COL_TYPE, &shortcut_type,
1359 SHORTCUTS_COL_PIXBUF_VISIBLE, &pixbuf_visible,
1365 if (shortcut_type == SHORTCUT_TYPE_VOLUME)
1367 GtkFileSystemVolume *volume;
1370 pixbuf = gtk_file_system_volume_render_icon (impl->file_system, volume, GTK_WIDGET (impl),
1371 impl->icon_size, NULL);
1373 gtk_list_store_set (impl->shortcuts_model, &iter,
1374 SHORTCUTS_COL_PIXBUF, pixbuf,
1378 g_object_unref (pixbuf);
1380 else if (shortcut_type == SHORTCUT_TYPE_PATH)
1382 if (gtk_file_system_path_is_local (impl->file_system, (GtkFilePath *)data))
1384 const GtkFilePath *path;
1385 struct ReloadIconsData *info;
1386 GtkTreePath *tree_path;
1387 GtkFileSystemHandle *handle;
1391 info = g_new0 (struct ReloadIconsData, 1);
1392 info->impl = g_object_ref (impl);
1393 tree_path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
1394 info->row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (impl->shortcuts_model), tree_path);
1395 gtk_tree_path_free (tree_path);
1397 handle = gtk_file_system_get_info (impl->file_system, path,
1399 shortcuts_reload_icons_get_info_cb,
1401 impl->reload_icon_handles = g_slist_append (impl->reload_icon_handles, handle);
1405 GtkIconTheme *icon_theme;
1407 /* Don't call get_info for remote paths to avoid latency and
1409 * If we switch to a better bookmarks file format (XBEL), we
1410 * should use mime info to get a better icon.
1412 icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl)));
1413 pixbuf = gtk_icon_theme_load_icon (icon_theme, "gnome-fs-directory",
1414 impl->icon_size, 0, NULL);
1416 gtk_list_store_set (impl->shortcuts_model, &iter,
1417 SHORTCUTS_COL_PIXBUF, pixbuf,
1421 g_object_unref (pixbuf);
1424 else if (shortcut_type == SHORTCUT_TYPE_SEARCH)
1426 pixbuf = render_search_icon (impl);
1428 else if (shortcut_type == SHORTCUT_TYPE_RECENT)
1430 pixbuf = render_recent_icon (impl);
1434 while (gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model),&iter));
1438 profile_end ("end", NULL);
1442 shortcuts_find_folder (GtkFileChooserDefault *impl,
1443 GtkFilePath *folder)
1445 GtkTreeSelection *selection;
1449 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view));
1451 g_assert (folder != NULL);
1452 pos = shortcut_find_position (impl, folder);
1455 gtk_tree_selection_unselect_all (selection);
1459 path = gtk_tree_path_new_from_indices (pos, -1);
1460 gtk_tree_selection_select_path (selection, path);
1461 gtk_tree_path_free (path);
1464 /* If a shortcut corresponds to the current folder, selects it */
1466 shortcuts_find_current_folder (GtkFileChooserDefault *impl)
1468 shortcuts_find_folder (impl, impl->current_folder);
1471 /* Removes the specified number of rows from the shortcuts list */
1473 shortcuts_remove_rows (GtkFileChooserDefault *impl,
1479 path = gtk_tree_path_new_from_indices (start_row, -1);
1481 for (; n_rows; n_rows--)
1485 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->shortcuts_model), &iter, path))
1486 g_assert_not_reached ();
1488 shortcuts_free_row_data (impl, &iter);
1489 gtk_list_store_remove (impl->shortcuts_model, &iter);
1492 gtk_tree_path_free (path);
1496 shortcuts_update_count (GtkFileChooserDefault *impl,
1497 ShortcutsIndex type,
1502 case SHORTCUTS_HOME:
1504 impl->has_home = FALSE;
1506 impl->has_home = TRUE;
1509 case SHORTCUTS_DESKTOP:
1511 impl->has_desktop = FALSE;
1513 impl->has_desktop = TRUE;
1516 case SHORTCUTS_VOLUMES:
1517 impl->num_volumes += value;
1520 case SHORTCUTS_SHORTCUTS:
1521 impl->num_shortcuts += value;
1524 case SHORTCUTS_BOOKMARKS:
1525 impl->num_bookmarks += value;
1528 case SHORTCUTS_CURRENT_FOLDER:
1530 impl->shortcuts_current_folder_active = FALSE;
1532 impl->shortcuts_current_folder_active = TRUE;
1541 struct ShortcutsInsertRequest
1543 GtkFileChooserDefault *impl;
1544 GtkFilePath *parent_path;
1548 GtkTreeRowReference *row_ref;
1549 ShortcutsIndex type;
1555 get_file_info_finished (GtkFileSystemHandle *handle,
1556 const GtkFileInfo *info,
1557 const GError *error,
1561 gboolean cancelled = handle->cancelled;
1565 GtkFileSystemHandle *model_handle;
1566 struct ShortcutsInsertRequest *request = data;
1568 path = gtk_tree_row_reference_get_path (request->row_ref);
1570 /* Handle doesn't exist anymore in the model */
1573 pos = gtk_tree_path_get_indices (path)[0];
1574 gtk_tree_model_get_iter (GTK_TREE_MODEL (request->impl->shortcuts_model),
1576 gtk_tree_path_free (path);
1578 /* validate handle, else goto out */
1579 gtk_tree_model_get (GTK_TREE_MODEL (request->impl->shortcuts_model), &iter,
1580 SHORTCUTS_COL_HANDLE, &model_handle,
1582 if (handle != model_handle)
1585 /* set the handle to NULL in the model (we unref later on) */
1586 gtk_list_store_set (request->impl->shortcuts_model, &iter,
1587 SHORTCUTS_COL_HANDLE, NULL,
1595 gtk_list_store_remove (request->impl->shortcuts_model, &iter);
1596 shortcuts_update_count (request->impl, request->type, -1);
1598 if (request->type == SHORTCUTS_HOME)
1600 const char *home = g_get_home_dir ();
1601 GtkFilePath *home_path;
1603 home_path = gtk_file_system_filename_to_path (request->impl->file_system, home);
1604 error_getting_info_dialog (request->impl, home_path, g_error_copy (error));
1605 gtk_file_path_free (home_path);
1607 else if (request->type == SHORTCUTS_CURRENT_FOLDER)
1609 /* Remove the current folder separator */
1610 gint separator_pos = shortcuts_get_index (request->impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR);
1611 shortcuts_remove_rows (request->impl, separator_pos, 1);
1617 if (!request->label_copy)
1618 request->label_copy = g_strdup (gtk_file_info_get_display_name (info));
1619 pixbuf = gtk_file_info_render_icon (info, GTK_WIDGET (request->impl),
1620 request->impl->icon_size, NULL);
1622 gtk_list_store_set (request->impl->shortcuts_model, &iter,
1623 SHORTCUTS_COL_PIXBUF, pixbuf,
1624 SHORTCUTS_COL_PIXBUF_VISIBLE, TRUE,
1625 SHORTCUTS_COL_NAME, request->label_copy,
1626 SHORTCUTS_COL_TYPE, SHORTCUT_TYPE_PATH,
1627 SHORTCUTS_COL_REMOVABLE, request->removable,
1630 if (request->impl->shortcuts_pane_filter_model)
1631 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (request->impl->shortcuts_pane_filter_model));
1633 if (request->impl->shortcuts_combo_filter_model)
1634 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (request->impl->shortcuts_combo_filter_model));
1636 if (request->type == SHORTCUTS_CURRENT_FOLDER
1637 && request->impl->save_folder_combo != NULL)
1639 /* The current folder is updated via _activate_iter(), don't
1640 * have save_folder_combo_changed_cb() call _activate_iter()
1643 g_signal_handlers_block_by_func (request->impl->save_folder_combo,
1644 G_CALLBACK (save_folder_combo_changed_cb),
1646 gtk_combo_box_set_active (GTK_COMBO_BOX (request->impl->save_folder_combo), request->impl->has_search ? pos - 2 : pos);
1647 g_signal_handlers_unblock_by_func (request->impl->save_folder_combo,
1648 G_CALLBACK (save_folder_combo_changed_cb),
1653 g_object_unref (pixbuf);
1656 g_object_unref (request->impl);
1657 gtk_file_path_free (request->parent_path);
1658 gtk_file_path_free (request->path);
1659 gtk_tree_row_reference_free (request->row_ref);
1660 g_free (request->label_copy);
1663 g_object_unref (handle);
1666 /* FIXME: GtkFileSystem needs a function to split a remote path
1667 * into hostname and path components, or maybe just have a
1668 * gtk_file_system_path_get_display_name().
1670 * This function is also used in gtkfilechooserbutton.c
1673 _gtk_file_chooser_label_for_uri (const gchar *uri)
1675 const gchar *path, *start, *end, *p;
1676 gchar *host, *label;
1678 start = strstr (uri, "://");
1680 path = strchr (start, '/');
1686 end = uri + strlen (uri);
1690 /* strip username */
1691 p = strchr (start, '@');
1697 p = strchr (start, ':');
1701 host = g_strndup (start, end - start);
1703 /* Translators: the first string is a path and the second string
1704 * is a hostname. Nautilus and the panel contain the same string
1707 label = g_strdup_printf (_("%1$s on %2$s"), path, host);
1714 /* Inserts a path in the shortcuts tree, making a copy of it; alternatively,
1715 * inserts a volume. A position of -1 indicates the end of the tree.
1718 shortcuts_insert_path (GtkFileChooserDefault *impl,
1720 ShortcutType shortcut_type,
1721 GtkFileSystemVolume *volume,
1722 const GtkFilePath *path,
1725 ShortcutsIndex type)
1728 GdkPixbuf *pixbuf = NULL;
1729 gpointer data = NULL;
1731 GtkIconTheme *icon_theme;
1733 profile_start ("start", (shortcut_type == SHORTCUT_TYPE_VOLUME) ? "volume"
1734 : ((shortcut_type == SHORTCUT_TYPE_PATH) ? (char *) path : NULL));
1736 if (shortcut_type == SHORTCUT_TYPE_VOLUME)
1739 label_copy = gtk_file_system_volume_get_display_name (impl->file_system, volume);
1740 pixbuf = gtk_file_system_volume_render_icon (impl->file_system, volume, GTK_WIDGET (impl),
1741 impl->icon_size, NULL);
1743 else if (shortcut_type == SHORTCUT_TYPE_PATH)
1745 if (gtk_file_system_path_is_local (impl->file_system, path))
1747 struct ShortcutsInsertRequest *request;
1748 GtkFileSystemHandle *handle;
1751 request = g_new0 (struct ShortcutsInsertRequest, 1);
1752 request->impl = g_object_ref (impl);
1753 request->path = gtk_file_path_copy (path);
1754 request->name_only = TRUE;
1755 request->removable = removable;
1757 request->type = type;
1759 request->label_copy = g_strdup (label);
1762 gtk_list_store_append (impl->shortcuts_model, &iter);
1764 gtk_list_store_insert (impl->shortcuts_model, &iter, pos);
1766 p = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
1767 request->row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (impl->shortcuts_model), p);
1768 gtk_tree_path_free (p);
1770 handle = gtk_file_system_get_info (request->impl->file_system, request->path,
1771 GTK_FILE_INFO_DISPLAY_NAME | GTK_FILE_INFO_IS_HIDDEN | GTK_FILE_INFO_ICON,
1772 get_file_info_finished, request);
1774 gtk_list_store_set (impl->shortcuts_model, &iter,
1775 SHORTCUTS_COL_DATA, gtk_file_path_copy (path),
1776 SHORTCUTS_COL_TYPE, SHORTCUT_TYPE_PATH,
1777 SHORTCUTS_COL_HANDLE, handle,
1780 shortcuts_update_count (impl, type, 1);
1786 /* Don't call get_info for remote paths to avoid latency and
1789 data = gtk_file_path_copy (path);
1791 label_copy = g_strdup (label);
1796 uri = gtk_file_system_path_to_uri (impl->file_system, path);
1798 label_copy = _gtk_file_chooser_label_for_uri (uri);
1803 /* If we switch to a better bookmarks file format (XBEL), we
1804 * should use mime info to get a better icon.
1806 icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl)));
1807 pixbuf = gtk_icon_theme_load_icon (icon_theme, "gnome-fs-directory",
1808 impl->icon_size, 0, NULL);
1813 g_assert_not_reached ();
1819 gtk_list_store_append (impl->shortcuts_model, &iter);
1821 gtk_list_store_insert (impl->shortcuts_model, &iter, pos);
1823 shortcuts_update_count (impl, type, 1);
1825 gtk_list_store_set (impl->shortcuts_model, &iter,
1826 SHORTCUTS_COL_PIXBUF, pixbuf,
1827 SHORTCUTS_COL_PIXBUF_VISIBLE, TRUE,
1828 SHORTCUTS_COL_NAME, label_copy,
1829 SHORTCUTS_COL_DATA, data,
1830 SHORTCUTS_COL_TYPE, shortcut_type,
1831 SHORTCUTS_COL_REMOVABLE, removable,
1832 SHORTCUTS_COL_HANDLE, NULL,
1835 if (impl->shortcuts_pane_filter_model)
1836 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_pane_filter_model));
1838 if (impl->shortcuts_combo_filter_model)
1839 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_combo_filter_model));
1841 if (type == SHORTCUTS_CURRENT_FOLDER && impl->save_folder_combo != NULL)
1843 /* The current folder is updated via _activate_iter(), don't
1844 * have save_folder_combo_changed_cb() call _activate_iter()
1847 gint combo_pos = shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER);
1848 g_signal_handlers_block_by_func (impl->save_folder_combo,
1849 G_CALLBACK (save_folder_combo_changed_cb),
1851 gtk_combo_box_set_active (GTK_COMBO_BOX (impl->save_folder_combo),
1852 impl->has_search ? combo_pos - 2 : combo_pos);
1853 g_signal_handlers_unblock_by_func (impl->save_folder_combo,
1854 G_CALLBACK (save_folder_combo_changed_cb),
1858 g_free (label_copy);
1861 g_object_unref (pixbuf);
1863 profile_end ("end", NULL);
1867 shortcuts_append_search (GtkFileChooserDefault *impl)
1872 pixbuf = render_search_icon (impl);
1874 gtk_list_store_append (impl->shortcuts_model, &iter);
1875 gtk_list_store_set (impl->shortcuts_model, &iter,
1876 SHORTCUTS_COL_PIXBUF, pixbuf,
1877 SHORTCUTS_COL_PIXBUF_VISIBLE, TRUE,
1878 SHORTCUTS_COL_NAME, _("Search"),
1879 SHORTCUTS_COL_DATA, NULL,
1880 SHORTCUTS_COL_TYPE, SHORTCUT_TYPE_SEARCH,
1881 SHORTCUTS_COL_REMOVABLE, FALSE,
1885 g_object_unref (pixbuf);
1887 impl->has_search = TRUE;
1891 shortcuts_append_recent (GtkFileChooserDefault *impl)
1896 pixbuf = render_recent_icon (impl);
1898 gtk_list_store_append (impl->shortcuts_model, &iter);
1899 gtk_list_store_set (impl->shortcuts_model, &iter,
1900 SHORTCUTS_COL_PIXBUF, pixbuf,
1901 SHORTCUTS_COL_PIXBUF_VISIBLE, TRUE,
1902 SHORTCUTS_COL_NAME, _("Recently Used"),
1903 SHORTCUTS_COL_DATA, NULL,
1904 SHORTCUTS_COL_TYPE, SHORTCUT_TYPE_RECENT,
1905 SHORTCUTS_COL_REMOVABLE, FALSE,
1909 g_object_unref (pixbuf);
1911 impl->has_recent = TRUE;
1914 /* Appends an item for the user's home directory to the shortcuts model */
1916 shortcuts_append_home (GtkFileChooserDefault *impl)
1919 GtkFilePath *home_path;
1921 profile_start ("start", NULL);
1923 home = g_get_home_dir ();
1926 profile_end ("end - no home directory!?", NULL);
1930 home_path = gtk_file_system_filename_to_path (impl->file_system, home);
1932 shortcuts_insert_path (impl, -1, SHORTCUT_TYPE_PATH, NULL, home_path, NULL, FALSE, SHORTCUTS_HOME);
1933 impl->has_home = TRUE;
1935 gtk_file_path_free (home_path);
1937 profile_end ("end", NULL);
1940 /* Appends the ~/Desktop directory to the shortcuts model */
1942 shortcuts_append_desktop (GtkFileChooserDefault *impl)
1948 profile_start ("start", NULL);
1951 name = _gtk_file_system_win32_get_desktop ();
1953 home = g_get_home_dir ();
1956 profile_end ("end - no home directory!?", NULL);
1960 name = g_build_filename (home, "Desktop", NULL);
1963 path = gtk_file_system_filename_to_path (impl->file_system, name);
1966 shortcuts_insert_path (impl, -1, SHORTCUT_TYPE_PATH, NULL, path, _("Desktop"), FALSE, SHORTCUTS_DESKTOP);
1967 impl->has_desktop = TRUE;
1969 /* We do not actually pop up an error dialog if there is no desktop directory
1970 * because some people may really not want to have one.
1973 gtk_file_path_free (path);
1975 profile_end ("end", NULL);
1978 /* Appends a list of GtkFilePath to the shortcuts model; returns how many were inserted */
1980 shortcuts_append_paths (GtkFileChooserDefault *impl,
1987 profile_start ("start", NULL);
1989 /* As there is no separator now, we want to start there.
1991 start_row = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR);
1994 for (; paths; paths = paths->next)
2000 if (impl->local_only &&
2001 !gtk_file_system_path_is_local (impl->file_system, path))
2004 label = gtk_file_system_get_bookmark_label (impl->file_system, path);
2006 /* NULL GError, but we don't really want to show error boxes here */
2007 shortcuts_insert_path (impl, start_row + num_inserted, SHORTCUT_TYPE_PATH, NULL, path, label, TRUE, SHORTCUTS_BOOKMARKS);
2013 profile_end ("end", NULL);
2015 return num_inserted;
2018 /* Returns the index for the corresponding item in the shortcuts bar */
2020 shortcuts_get_index (GtkFileChooserDefault *impl,
2021 ShortcutsIndex where)
2027 if (where == SHORTCUTS_SEARCH)
2030 n += impl->has_search ? 1 : 0;
2032 if (where == SHORTCUTS_RECENT)
2035 n += impl->has_recent ? 1 : 0;
2037 if (where == SHORTCUTS_RECENT_SEPARATOR)
2040 n += impl->has_recent ? 1 : 0;
2042 if (where == SHORTCUTS_HOME)
2045 n += impl->has_home ? 1 : 0;
2047 if (where == SHORTCUTS_DESKTOP)
2050 n += impl->has_desktop ? 1 : 0;
2052 if (where == SHORTCUTS_VOLUMES)
2055 n += impl->num_volumes;
2057 if (where == SHORTCUTS_SHORTCUTS)
2060 n += impl->num_shortcuts;
2062 if (where == SHORTCUTS_BOOKMARKS_SEPARATOR)
2065 /* If there are no bookmarks there won't be a separator */
2066 n += (impl->num_bookmarks > 0) ? 1 : 0;
2068 if (where == SHORTCUTS_BOOKMARKS)
2071 n += impl->num_bookmarks;
2073 if (where == SHORTCUTS_CURRENT_FOLDER_SEPARATOR)
2078 if (where == SHORTCUTS_CURRENT_FOLDER)
2081 g_assert_not_reached ();
2088 /* Adds all the file system volumes to the shortcuts model */
2090 shortcuts_add_volumes (GtkFileChooserDefault *impl)
2095 gboolean old_changing_folders;
2097 profile_start ("start", NULL);
2100 old_changing_folders = impl->changing_folder;
2101 impl->changing_folder = TRUE;
2103 start_row = shortcuts_get_index (impl, SHORTCUTS_VOLUMES);
2104 shortcuts_remove_rows (impl, start_row, impl->num_volumes);
2105 impl->num_volumes = 0;
2107 list = gtk_file_system_list_volumes (impl->file_system);
2111 for (l = list; l; l = l->next)
2113 GtkFileSystemVolume *volume;
2117 if (impl->local_only)
2119 if (gtk_file_system_volume_get_is_mounted (impl->file_system, volume))
2121 GtkFilePath *base_path;
2123 base_path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
2124 if (base_path != NULL)
2126 gboolean is_local = gtk_file_system_path_is_local (impl->file_system, base_path);
2127 gtk_file_path_free (base_path);
2131 gtk_file_system_volume_free (impl->file_system, volume);
2138 shortcuts_insert_path (impl, start_row + n, SHORTCUT_TYPE_VOLUME, volume, NULL, NULL, FALSE, SHORTCUTS_VOLUMES);
2142 impl->num_volumes = n;
2143 g_slist_free (list);
2145 if (impl->shortcuts_pane_filter_model)
2146 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_pane_filter_model));
2148 if (impl->shortcuts_combo_filter_model)
2149 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_combo_filter_model));
2151 impl->changing_folder = old_changing_folders;
2153 profile_end ("end", NULL);
2156 /* Inserts a separator node in the shortcuts list */
2158 shortcuts_insert_separator (GtkFileChooserDefault *impl,
2159 ShortcutsIndex where)
2163 g_assert (where == SHORTCUTS_RECENT_SEPARATOR ||
2164 where == SHORTCUTS_BOOKMARKS_SEPARATOR ||
2165 where == SHORTCUTS_CURRENT_FOLDER_SEPARATOR);
2167 gtk_list_store_insert (impl->shortcuts_model, &iter,
2168 shortcuts_get_index (impl, where));
2169 gtk_list_store_set (impl->shortcuts_model, &iter,
2170 SHORTCUTS_COL_PIXBUF, NULL,
2171 SHORTCUTS_COL_PIXBUF_VISIBLE, FALSE,
2172 SHORTCUTS_COL_NAME, NULL,
2173 SHORTCUTS_COL_DATA, NULL,
2174 SHORTCUTS_COL_TYPE, SHORTCUT_TYPE_SEPARATOR,
2178 /* Updates the list of bookmarks */
2180 shortcuts_add_bookmarks (GtkFileChooserDefault *impl)
2183 gboolean old_changing_folders;
2185 GtkFilePath *list_selected = NULL;
2186 GtkFilePath *combo_selected = NULL;
2187 ShortcutType shortcut_type;
2190 profile_start ("start", NULL);
2192 old_changing_folders = impl->changing_folder;
2193 impl->changing_folder = TRUE;
2195 if (shortcuts_get_selected (impl, &iter))
2197 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model),
2199 SHORTCUTS_COL_DATA, &col_data,
2200 SHORTCUTS_COL_TYPE, &shortcut_type,
2203 if (col_data && shortcut_type == SHORTCUT_TYPE_PATH)
2204 list_selected = gtk_file_path_copy (col_data);
2207 if (impl->save_folder_combo &&
2208 gtk_combo_box_get_active_iter (GTK_COMBO_BOX (impl->save_folder_combo),
2211 GtkTreeIter child_iter;
2213 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (impl->shortcuts_combo_filter_model),
2216 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model),
2218 SHORTCUTS_COL_DATA, &col_data,
2219 SHORTCUTS_COL_TYPE, &shortcut_type,
2222 if (col_data && shortcut_type == SHORTCUT_TYPE_PATH)
2223 combo_selected = gtk_file_path_copy (col_data);
2226 if (impl->num_bookmarks > 0)
2227 shortcuts_remove_rows (impl,
2228 shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR),
2229 impl->num_bookmarks + 1);
2231 impl->num_bookmarks = 0;
2233 bookmarks = gtk_file_system_list_bookmarks (impl->file_system);
2234 shortcuts_append_paths (impl, bookmarks);
2235 gtk_file_paths_free (bookmarks);
2237 if (impl->num_bookmarks > 0)
2238 shortcuts_insert_separator (impl, SHORTCUTS_BOOKMARKS_SEPARATOR);
2240 if (impl->shortcuts_pane_filter_model)
2241 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_pane_filter_model));
2243 if (impl->shortcuts_combo_filter_model)
2244 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_combo_filter_model));
2248 shortcuts_find_folder (impl, list_selected);
2249 gtk_file_path_free (list_selected);
2256 pos = shortcut_find_position (impl, combo_selected);
2258 gtk_combo_box_set_active (GTK_COMBO_BOX (impl->save_folder_combo),
2259 impl->has_search ? pos - 2 : pos);
2260 gtk_file_path_free (combo_selected);
2263 impl->changing_folder = old_changing_folders;
2265 profile_end ("end", NULL);
2268 /* Appends a separator and a row to the shortcuts list for the current folder */
2270 shortcuts_add_current_folder (GtkFileChooserDefault *impl)
2275 g_assert (!impl->shortcuts_current_folder_active);
2279 g_assert (impl->current_folder != NULL);
2281 pos = shortcut_find_position (impl, impl->current_folder);
2284 GtkFileSystemVolume *volume;
2285 GtkFilePath *base_path;
2289 shortcuts_insert_separator (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR);
2293 pos = shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER);
2295 volume = gtk_file_system_get_volume_for_path (impl->file_system, impl->current_folder);
2297 base_path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
2302 strcmp (gtk_file_path_get_string (base_path), gtk_file_path_get_string (impl->current_folder)) == 0)
2304 shortcuts_insert_path (impl, pos, SHORTCUT_TYPE_VOLUME, volume, NULL, NULL, FALSE, SHORTCUTS_CURRENT_FOLDER);
2308 shortcuts_insert_path (impl, pos, SHORTCUT_TYPE_PATH, NULL, impl->current_folder, NULL, FALSE, SHORTCUTS_CURRENT_FOLDER);
2310 gtk_file_system_volume_free (impl->file_system, volume);
2314 gtk_file_path_free (base_path);
2316 else if (impl->save_folder_combo != NULL)
2317 gtk_combo_box_set_active (GTK_COMBO_BOX (impl->save_folder_combo),
2318 impl->has_search ? pos - 2 : pos);
2321 /* Updates the current folder row in the shortcuts model */
2323 shortcuts_update_current_folder (GtkFileChooserDefault *impl)
2327 pos = shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR);
2329 if (impl->shortcuts_current_folder_active)
2331 shortcuts_remove_rows (impl, pos, 2);
2332 impl->shortcuts_current_folder_active = FALSE;
2335 shortcuts_add_current_folder (impl);
2338 /* Filter function used for the shortcuts filter model */
2340 shortcuts_pane_filter_cb (GtkTreeModel *model,
2344 GtkFileChooserDefault *impl;
2348 impl = GTK_FILE_CHOOSER_DEFAULT (data);
2350 path = gtk_tree_model_get_path (model, iter);
2354 pos = *gtk_tree_path_get_indices (path);
2355 gtk_tree_path_free (path);
2357 return (pos < shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR));
2360 /* Creates the list model for shortcuts */
2362 shortcuts_model_create (GtkFileChooserDefault *impl)
2364 /* Keep this order in sync with the SHORCUTS_COL_* enum values */
2365 impl->shortcuts_model = gtk_list_store_new (SHORTCUTS_COL_NUM_COLUMNS,
2366 GDK_TYPE_PIXBUF, /* pixbuf */
2367 G_TYPE_STRING, /* name */
2368 G_TYPE_POINTER, /* path or volume */
2369 G_TYPE_INT, /* ShortcutType */
2370 G_TYPE_BOOLEAN, /* removable */
2371 G_TYPE_BOOLEAN, /* pixbuf cell visibility */
2372 G_TYPE_POINTER); /* GtkFileSystemHandle */
2374 if (search_is_possible (impl))
2376 shortcuts_append_search (impl);
2379 if (impl->recent_manager)
2381 shortcuts_append_recent (impl);
2382 shortcuts_insert_separator (impl, SHORTCUTS_RECENT_SEPARATOR);
2385 if (impl->file_system)
2387 shortcuts_append_home (impl);
2388 shortcuts_append_desktop (impl);
2389 shortcuts_add_volumes (impl);
2392 impl->shortcuts_pane_filter_model = shortcuts_pane_model_filter_new (impl,
2393 GTK_TREE_MODEL (impl->shortcuts_model),
2396 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (impl->shortcuts_pane_filter_model),
2397 shortcuts_pane_filter_cb,
2402 /* Callback used when the "New Folder" button is clicked */
2404 new_folder_button_clicked (GtkButton *button,
2405 GtkFileChooserDefault *impl)
2410 if (!impl->browse_files_model)
2411 return; /* FIXME: this sucks. Disable the New Folder button or something. */
2413 /* Prevent button from being clicked twice */
2414 gtk_widget_set_sensitive (impl->browse_new_folder_button, FALSE);
2416 _gtk_file_system_model_add_editable (impl->browse_files_model, &iter);
2418 path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->browse_files_model), &iter);
2419 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (impl->browse_files_tree_view),
2420 path, impl->list_name_column,
2423 g_object_set (impl->list_name_renderer, "editable", TRUE, NULL);
2424 gtk_tree_view_set_cursor (GTK_TREE_VIEW (impl->browse_files_tree_view),
2426 impl->list_name_column,
2429 gtk_tree_path_free (path);
2433 edited_idle_create_folder_cb (GtkFileSystemHandle *handle,
2434 const GtkFilePath *path,
2435 const GError *error,
2438 gboolean cancelled = handle->cancelled;
2439 GtkFileChooserDefault *impl = data;
2441 if (!g_slist_find (impl->pending_handles, handle))
2444 impl->pending_handles = g_slist_remove (impl->pending_handles, handle);
2450 change_folder_and_display_error (impl, path, FALSE);
2452 error_creating_folder_dialog (impl, path, g_error_copy (error));
2455 g_object_unref (impl);
2456 g_object_unref (handle);
2459 /* Idle handler for creating a new folder after editing its name cell, or for
2460 * canceling the editing.
2463 edited_idle_cb (GtkFileChooserDefault *impl)
2465 GDK_THREADS_ENTER ();
2467 g_source_destroy (impl->edited_idle);
2468 impl->edited_idle = NULL;
2470 _gtk_file_system_model_remove_editable (impl->browse_files_model);
2471 g_object_set (impl->list_name_renderer, "editable", FALSE, NULL);
2473 gtk_widget_set_sensitive (impl->browse_new_folder_button, TRUE);
2475 if (impl->edited_new_text) /* not cancelled? */
2478 GtkFilePath *file_path;
2481 file_path = gtk_file_system_make_path (impl->file_system,
2482 impl->current_folder,
2483 impl->edited_new_text,
2487 GtkFileSystemHandle *handle;
2489 handle = gtk_file_system_create_folder (impl->file_system, file_path,
2490 edited_idle_create_folder_cb,
2491 g_object_ref (impl));
2492 impl->pending_handles = g_slist_append (impl->pending_handles, handle);
2494 gtk_file_path_free (file_path);
2497 error_creating_folder_dialog (impl, file_path, error);
2499 g_free (impl->edited_new_text);
2500 impl->edited_new_text = NULL;
2503 GDK_THREADS_LEAVE ();
2509 queue_edited_idle (GtkFileChooserDefault *impl,
2510 const gchar *new_text)
2512 /* We create the folder in an idle handler so that we don't modify the tree
2516 if (!impl->edited_idle)
2518 impl->edited_idle = g_idle_source_new ();
2519 g_source_set_closure (impl->edited_idle,
2520 g_cclosure_new_object (G_CALLBACK (edited_idle_cb),
2522 g_source_attach (impl->edited_idle, NULL);
2525 g_free (impl->edited_new_text);
2526 impl->edited_new_text = g_strdup (new_text);
2529 /* Callback used from the text cell renderer when the new folder is named */
2531 renderer_edited_cb (GtkCellRendererText *cell_renderer_text,
2533 const gchar *new_text,
2534 GtkFileChooserDefault *impl)
2536 /* work around bug #154921 */
2537 g_object_set (cell_renderer_text,
2538 "mode", GTK_CELL_RENDERER_MODE_INERT, NULL);
2539 queue_edited_idle (impl, new_text);
2542 /* Callback used from the text cell renderer when the new folder edition gets
2546 renderer_editing_canceled_cb (GtkCellRendererText *cell_renderer_text,
2547 GtkFileChooserDefault *impl)
2549 /* work around bug #154921 */
2550 g_object_set (cell_renderer_text,
2551 "mode", GTK_CELL_RENDERER_MODE_INERT, NULL);
2552 queue_edited_idle (impl, NULL);
2555 /* Creates the widgets for the filter combo box */
2557 filter_create (GtkFileChooserDefault *impl)
2559 impl->filter_combo = gtk_combo_box_new_text ();
2560 gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (impl->filter_combo), FALSE);
2562 g_signal_connect (impl->filter_combo, "changed",
2563 G_CALLBACK (filter_combo_changed), impl);
2565 return impl->filter_combo;
2569 button_new (GtkFileChooserDefault *impl,
2571 const char *stock_id,
2579 button = gtk_button_new_with_mnemonic (text);
2580 image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
2581 gtk_button_set_image (GTK_BUTTON (button), image);
2583 gtk_widget_set_sensitive (button, sensitive);
2584 g_signal_connect (button, "clicked", callback, impl);
2587 gtk_widget_show (button);
2592 /* Looks for a path among the shortcuts; returns its index or -1 if it doesn't exist */
2594 shortcut_find_position (GtkFileChooserDefault *impl,
2595 const GtkFilePath *path)
2599 int current_folder_separator_idx;
2601 if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
2604 current_folder_separator_idx = shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR);
2607 /* FIXME: is this still needed? */
2608 if (current_folder_separator_idx >= impl->shortcuts_model->length)
2612 for (i = 0; i < current_folder_separator_idx; i++)
2615 ShortcutType shortcut_type;
2617 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
2618 SHORTCUTS_COL_DATA, &col_data,
2619 SHORTCUTS_COL_TYPE, &shortcut_type,
2624 if (shortcut_type == SHORTCUT_TYPE_VOLUME)
2626 GtkFileSystemVolume *volume;
2627 GtkFilePath *base_path;
2631 base_path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
2633 exists = base_path && strcmp (gtk_file_path_get_string (path),
2634 gtk_file_path_get_string (base_path)) == 0;
2640 else if (shortcut_type == SHORTCUT_TYPE_PATH)
2642 GtkFilePath *model_path;
2644 model_path = col_data;
2646 if (model_path && gtk_file_path_compare (model_path, path) == 0)
2651 if (i < current_folder_separator_idx - 1)
2653 if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
2654 g_assert_not_reached ();
2661 /* Tries to add a bookmark from a path name */
2663 shortcuts_add_bookmark_from_path (GtkFileChooserDefault *impl,
2664 const GtkFilePath *path,
2669 g_return_val_if_fail (path != NULL, FALSE);
2671 if (shortcut_find_position (impl, path) != -1)
2675 if (!gtk_file_system_insert_bookmark (impl->file_system, path, pos, &error))
2677 error_adding_bookmark_dialog (impl, path, error);
2685 add_bookmark_foreach_cb (GtkTreeModel *model,
2690 GtkFileChooserDefault *impl;
2691 GtkFileSystemModel *fs_model;
2692 GtkTreeIter child_iter;
2693 const GtkFilePath *file_path;
2695 impl = (GtkFileChooserDefault *) data;
2697 switch (impl->operation_mode)
2699 case OPERATION_MODE_BROWSE:
2700 fs_model = impl->browse_files_model;
2701 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model, &child_iter, iter);
2702 file_path = _gtk_file_system_model_get_path (fs_model, &child_iter);
2705 case OPERATION_MODE_SEARCH:
2706 search_get_valid_child_iter (impl, &child_iter, iter);
2707 gtk_tree_model_get (GTK_TREE_MODEL (impl->search_model), &child_iter,
2708 SEARCH_MODEL_COL_PATH, &file_path,
2712 case OPERATION_MODE_RECENT:
2713 recent_get_valid_child_iter (impl, &child_iter, iter);
2714 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &child_iter,
2715 RECENT_MODEL_COL_PATH, &file_path,
2720 shortcuts_add_bookmark_from_path (impl, file_path, -1);
2723 /* Adds a bookmark from the currently selected item in the file list */
2725 bookmarks_add_selected_folder (GtkFileChooserDefault *impl)
2727 GtkTreeSelection *selection;
2729 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
2731 if (gtk_tree_selection_count_selected_rows (selection) == 0)
2732 shortcuts_add_bookmark_from_path (impl, impl->current_folder, -1);
2734 gtk_tree_selection_selected_foreach (selection,
2735 add_bookmark_foreach_cb,
2739 /* Callback used when the "Add bookmark" button is clicked */
2741 add_bookmark_button_clicked_cb (GtkButton *button,
2742 GtkFileChooserDefault *impl)
2744 bookmarks_add_selected_folder (impl);
2747 /* Returns TRUE plus an iter in the shortcuts_model if a row is selected;
2748 * returns FALSE if no shortcut is selected.
2751 shortcuts_get_selected (GtkFileChooserDefault *impl,
2754 GtkTreeSelection *selection;
2755 GtkTreeIter parent_iter;
2757 if (!impl->browse_shortcuts_tree_view)
2760 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view));
2762 if (!gtk_tree_selection_get_selected (selection, NULL, &parent_iter))
2765 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (impl->shortcuts_pane_filter_model),
2771 /* Removes the selected bookmarks */
2773 remove_selected_bookmarks (GtkFileChooserDefault *impl)
2781 if (!shortcuts_get_selected (impl, &iter))
2784 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
2785 SHORTCUTS_COL_DATA, &col_data,
2786 SHORTCUTS_COL_REMOVABLE, &removable,
2792 g_assert (col_data != NULL);
2797 if (!gtk_file_system_remove_bookmark (impl->file_system, path, &error))
2798 error_removing_bookmark_dialog (impl, path, error);
2801 /* Callback used when the "Remove bookmark" button is clicked */
2803 remove_bookmark_button_clicked_cb (GtkButton *button,
2804 GtkFileChooserDefault *impl)
2806 remove_selected_bookmarks (impl);
2809 struct selection_check_closure {
2810 GtkFileChooserDefault *impl;
2813 gboolean all_folders;
2816 /* Used from gtk_tree_selection_selected_foreach() */
2818 selection_check_foreach_cb (GtkTreeModel *model,
2823 struct selection_check_closure *closure;
2824 GtkTreeIter child_iter;
2825 const GtkFileInfo *info;
2829 closure->num_selected++;
2831 switch (closure->impl->operation_mode)
2833 case OPERATION_MODE_BROWSE:
2834 gtk_tree_model_sort_convert_iter_to_child_iter (closure->impl->sort_model, &child_iter, iter);
2835 info = _gtk_file_system_model_get_info (closure->impl->browse_files_model, &child_iter);
2836 is_folder = info ? gtk_file_info_get_is_folder (info) : FALSE;
2839 case OPERATION_MODE_SEARCH:
2840 search_get_valid_child_iter (closure->impl, &child_iter, iter);
2841 gtk_tree_model_get (GTK_TREE_MODEL (closure->impl->search_model), &child_iter,
2842 SEARCH_MODEL_COL_IS_FOLDER, &is_folder,
2846 case OPERATION_MODE_RECENT:
2847 recent_get_valid_child_iter (closure->impl, &child_iter, iter);
2848 gtk_tree_model_get (GTK_TREE_MODEL (closure->impl->recent_model), &child_iter,
2849 RECENT_MODEL_COL_IS_FOLDER, &is_folder,
2854 closure->all_folders = closure->all_folders && is_folder;
2855 closure->all_files = closure->all_files && !is_folder;
2858 /* Checks whether the selected items in the file list are all files or all folders */
2860 selection_check (GtkFileChooserDefault *impl,
2862 gboolean *all_files,
2863 gboolean *all_folders)
2865 struct selection_check_closure closure;
2866 GtkTreeSelection *selection;
2868 closure.impl = impl;
2869 closure.num_selected = 0;
2870 closure.all_files = TRUE;
2871 closure.all_folders = TRUE;
2873 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
2874 gtk_tree_selection_selected_foreach (selection,
2875 selection_check_foreach_cb,
2878 g_assert (closure.num_selected == 0 || !(closure.all_files && closure.all_folders));
2881 *num_selected = closure.num_selected;
2884 *all_files = closure.all_files;
2887 *all_folders = closure.all_folders;
2890 struct get_selected_path_closure {
2891 GtkFileChooserDefault *impl;
2892 const GtkFilePath *path;
2896 get_selected_path_foreach_cb (GtkTreeModel *model,
2901 struct get_selected_path_closure *closure;
2902 GtkTreeIter child_iter;
2906 switch (closure->impl->operation_mode)
2908 case OPERATION_MODE_BROWSE:
2909 gtk_tree_model_sort_convert_iter_to_child_iter (closure->impl->sort_model, &child_iter, iter);
2910 closure->path = _gtk_file_system_model_get_path (closure->impl->browse_files_model, &child_iter);
2913 case OPERATION_MODE_SEARCH:
2914 search_get_valid_child_iter (closure->impl, &child_iter, iter);
2915 gtk_tree_model_get (GTK_TREE_MODEL (closure->impl->search_model), &child_iter,
2916 SEARCH_MODEL_COL_PATH, &closure->path,
2920 case OPERATION_MODE_RECENT:
2921 recent_get_valid_child_iter (closure->impl, &child_iter, iter);
2922 gtk_tree_model_get (GTK_TREE_MODEL (closure->impl->recent_model), &child_iter,
2923 RECENT_MODEL_COL_PATH, &closure->path,
2929 /* Returns a selected path from the file list */
2930 static const GtkFilePath *
2931 get_selected_path (GtkFileChooserDefault *impl)
2933 struct get_selected_path_closure closure;
2934 GtkTreeSelection *selection;
2936 closure.impl = impl;
2937 closure.path = NULL;
2939 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
2940 gtk_tree_selection_selected_foreach (selection,
2941 get_selected_path_foreach_cb,
2944 return closure.path;
2948 GtkFileChooserDefault *impl;
2950 } UpdateTooltipData;
2953 update_tooltip (GtkTreeModel *model,
2958 UpdateTooltipData *udata = data;
2959 GtkTreeIter child_iter;
2960 const GtkFileInfo *info;
2962 if (udata->tip == NULL)
2964 const gchar *display_name;
2966 switch (udata->impl->operation_mode)
2968 case OPERATION_MODE_BROWSE:
2969 gtk_tree_model_sort_convert_iter_to_child_iter (udata->impl->sort_model,
2972 info = _gtk_file_system_model_get_info (udata->impl->browse_files_model, &child_iter);
2973 display_name = gtk_file_info_get_display_name (info);
2976 case OPERATION_MODE_SEARCH:
2977 search_get_valid_child_iter (udata->impl, &child_iter, iter);
2978 gtk_tree_model_get (GTK_TREE_MODEL (udata->impl->search_model), &child_iter,
2979 SEARCH_MODEL_COL_DISPLAY_NAME, &display_name,
2983 case OPERATION_MODE_RECENT:
2984 recent_get_valid_child_iter (udata->impl, &child_iter, iter);
2985 gtk_tree_model_get (GTK_TREE_MODEL (udata->impl->recent_model), &child_iter,
2986 RECENT_MODEL_COL_DISPLAY_NAME, &display_name,
2991 udata->tip = g_strdup_printf (_("Add the folder '%s' to the bookmarks"),
2997 /* Sensitize the "add bookmark" button if all the selected items are folders, or
2998 * if there are no selected items *and* the current folder is not in the
2999 * bookmarks list. De-sensitize the button otherwise.
3002 bookmarks_check_add_sensitivity (GtkFileChooserDefault *impl)
3005 gboolean all_folders;
3009 selection_check (impl, &num_selected, NULL, &all_folders);
3011 if (num_selected == 0)
3012 active = (impl->current_folder != NULL) && (shortcut_find_position (impl, impl->current_folder) == -1);
3013 else if (num_selected == 1)
3015 const GtkFilePath *path;
3017 path = get_selected_path (impl);
3018 active = all_folders && (shortcut_find_position (impl, path) == -1);
3021 active = all_folders;
3023 gtk_widget_set_sensitive (impl->browse_shortcuts_add_button, active);
3025 if (impl->browse_files_popup_menu_add_shortcut_item)
3026 gtk_widget_set_sensitive (impl->browse_files_popup_menu_add_shortcut_item,
3027 (num_selected == 0) ? FALSE : active);
3031 if (num_selected == 0)
3032 tip = g_strdup_printf (_("Add the current folder to the bookmarks"));
3033 else if (num_selected > 1)
3034 tip = g_strdup_printf (_("Add the selected folders to the bookmarks"));
3037 GtkTreeSelection *selection;
3038 UpdateTooltipData data;
3040 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
3043 gtk_tree_selection_selected_foreach (selection, update_tooltip, &data);
3047 gtk_tooltips_set_tip (impl->tooltips, impl->browse_shortcuts_add_button, tip, NULL);
3052 /* Sets the sensitivity of the "remove bookmark" button depending on whether a
3053 * bookmark row is selected in the shortcuts tree.
3056 bookmarks_check_remove_sensitivity (GtkFileChooserDefault *impl)
3059 gboolean removable = FALSE;
3062 if (shortcuts_get_selected (impl, &iter))
3063 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
3064 SHORTCUTS_COL_REMOVABLE, &removable,
3065 SHORTCUTS_COL_NAME, &name,
3068 gtk_widget_set_sensitive (impl->browse_shortcuts_remove_button, removable);
3074 tip = g_strdup_printf (_("Remove the bookmark '%s'"), name);
3075 gtk_tooltips_set_tip (impl->tooltips, impl->browse_shortcuts_remove_button,
3084 shortcuts_check_popup_sensitivity (GtkFileChooserDefault *impl)
3087 gboolean removable = FALSE;
3089 if (impl->browse_shortcuts_popup_menu == NULL)
3092 if (shortcuts_get_selected (impl, &iter))
3093 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
3094 SHORTCUTS_COL_REMOVABLE, &removable,
3097 gtk_widget_set_sensitive (impl->browse_shortcuts_popup_menu_remove_item, removable);
3098 gtk_widget_set_sensitive (impl->browse_shortcuts_popup_menu_rename_item, removable);
3101 /* GtkWidget::drag-begin handler for the shortcuts list. */
3103 shortcuts_drag_begin_cb (GtkWidget *widget,
3104 GdkDragContext *context,
3105 GtkFileChooserDefault *impl)
3108 impl->shortcuts_drag_context = g_object_ref (context);
3113 /* Removes the idle handler for outside drags */
3115 shortcuts_cancel_drag_outside_idle (GtkFileChooserDefault *impl)
3117 if (!impl->shortcuts_drag_outside_idle)
3120 g_source_destroy (impl->shortcuts_drag_outside_idle);
3121 impl->shortcuts_drag_outside_idle = NULL;
3125 /* GtkWidget::drag-end handler for the shortcuts list. */
3127 shortcuts_drag_end_cb (GtkWidget *widget,
3128 GdkDragContext *context,
3129 GtkFileChooserDefault *impl)
3132 g_object_unref (impl->shortcuts_drag_context);
3134 shortcuts_cancel_drag_outside_idle (impl);
3136 if (!impl->shortcuts_drag_outside)
3139 gtk_button_clicked (GTK_BUTTON (impl->browse_shortcuts_remove_button));
3141 impl->shortcuts_drag_outside = FALSE;
3145 /* GtkWidget::drag-data-delete handler for the shortcuts list. */
3147 shortcuts_drag_data_delete_cb (GtkWidget *widget,
3148 GdkDragContext *context,
3149 GtkFileChooserDefault *impl)
3151 g_signal_stop_emission_by_name (widget, "drag_data_delete");
3155 /* Creates a suitable drag cursor to indicate that the selected bookmark will be
3159 shortcuts_drag_set_delete_cursor (GtkFileChooserDefault *impl,
3162 GtkTreeView *tree_view;
3165 GdkPixmap *row_pixmap;
3170 tree_view = GTK_TREE_VIEW (impl->browse_shortcuts_tree_view);
3172 /* Find the selected path and get its drag pixmap */
3174 if (!shortcuts_get_selected (impl, &iter))
3175 g_assert_not_reached ();
3177 path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
3179 row_pixmap = gtk_tree_view_create_row_drag_icon (tree_view, path);
3180 gtk_tree_path_free (path);
3189 pixbuf = gtk_widget_render_icon (impl->browse_shortcuts_tree_view,
3195 GdkPixmap *composite;
3196 int row_pixmap_width, row_pixmap_height;
3197 int pixbuf_width, pixbuf_height;
3198 int composite_width, composite_height;
3199 int pixbuf_x, pixbuf_y;
3200 GdkGC *gc, *mask_gc;
3202 GdkBitmap *pixbuf_mask;
3204 /* Create pixmap and mask for composite image */
3206 gdk_drawable_get_size (row_pixmap, &row_pixmap_width, &row_pixmap_height);
3207 pixbuf_width = gdk_pixbuf_get_width (pixbuf);
3208 pixbuf_height = gdk_pixbuf_get_height (pixbuf);
3210 composite_width = MAX (row_pixmap_width, pixbuf_width);
3211 composite_height = MAX (row_pixmap_height, pixbuf_height);
3213 row_pixmap_y = (composite_height - row_pixmap_height) / 2;
3215 if (gtk_widget_get_direction (impl->browse_shortcuts_tree_view) == GTK_TEXT_DIR_RTL)
3218 pixbuf_x = composite_width - pixbuf_width;
3220 pixbuf_y = (composite_height - pixbuf_height) / 2;
3222 composite = gdk_pixmap_new (row_pixmap, composite_width, composite_height, -1);
3223 gc = gdk_gc_new (composite);
3225 mask = gdk_pixmap_new (row_pixmap, composite_width, composite_height, 1);
3226 mask_gc = gdk_gc_new (mask);
3228 gdk_gc_set_foreground (mask_gc, &color);
3229 gdk_draw_rectangle (mask, mask_gc, TRUE, 0, 0, composite_width, composite_height);
3232 color.green = 0xffff;
3233 color.blue = 0xffff;
3234 gdk_gc_set_rgb_fg_color (gc, &color);
3235 gdk_draw_rectangle (composite, gc, TRUE, 0, 0, composite_width, composite_height);
3237 /* Composite the row pixmap and the pixbuf */
3239 gdk_pixbuf_render_pixmap_and_mask_for_colormap
3241 gtk_widget_get_colormap (impl->browse_shortcuts_tree_view),
3242 NULL, &pixbuf_mask, 128);
3243 gdk_draw_drawable (mask, mask_gc, pixbuf_mask,
3246 pixbuf_width, pixbuf_height);
3247 g_object_unref (pixbuf_mask);
3249 gdk_draw_drawable (composite, gc, row_pixmap,
3252 row_pixmap_width, row_pixmap_height);
3254 gdk_gc_set_foreground (mask_gc, &color);
3255 gdk_draw_rectangle (mask, mask_gc, TRUE, 0, row_pixmap_y, row_pixmap_width, row_pixmap_height);
3257 gdk_draw_pixbuf (composite, gc, pixbuf,
3260 pixbuf_width, pixbuf_height,
3264 g_object_unref (pixbuf);
3265 g_object_unref (row_pixmap);
3267 row_pixmap = composite;
3271 /* The hotspot offsets here are copied from gtk_tree_view_drag_begin(), ugh */
3273 gtk_tree_view_get_path_at_pos (tree_view,
3274 tree_view->priv->press_start_x,
3275 tree_view->priv->press_start_y,
3281 gtk_drag_set_icon_pixmap (impl->shortcuts_drag_context,
3282 gdk_drawable_get_colormap (row_pixmap),
3285 tree_view->priv->press_start_x + 1,
3286 row_pixmap_y + cell_y + 1);
3288 g_object_unref (row_pixmap);
3290 g_object_unref (mask);
3293 /* We set the delete cursor and the shortcuts_drag_outside flag in an idle
3294 * handler so that we can tell apart the drag_leave event that comes right
3295 * before a drag_drop, from a normal drag_leave. We don't want to set the
3296 * cursor nor the flag in the latter case.
3299 shortcuts_drag_outside_idle_cb (GtkFileChooserDefault *impl)
3301 GDK_THREADS_ENTER ();
3303 shortcuts_drag_set_delete_cursor (impl, TRUE);
3304 impl->shortcuts_drag_outside = TRUE;
3306 shortcuts_cancel_drag_outside_idle (impl);
3308 GDK_THREADS_LEAVE ();
3314 /* GtkWidget::drag-leave handler for the shortcuts list. We unhighlight the
3318 shortcuts_drag_leave_cb (GtkWidget *widget,
3319 GdkDragContext *context,
3321 GtkFileChooserDefault *impl)
3324 if (gtk_drag_get_source_widget (context) == widget && !impl->shortcuts_drag_outside_idle)
3326 impl->shortcuts_drag_outside_idle = g_idle_source_new ();
3327 g_source_set_closure (impl->shortcuts_drag_outside_idle,
3328 g_cclosure_new_object (G_CALLBACK (shortcuts_drag_outside_idle_cb),
3330 g_source_attach (impl->shortcuts_drag_outside_idle, NULL);
3334 gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view),
3336 GTK_TREE_VIEW_DROP_BEFORE);
3338 g_signal_stop_emission_by_name (widget, "drag_leave");
3341 /* Computes the appropriate row and position for dropping */
3343 shortcuts_compute_drop_position (GtkFileChooserDefault *impl,
3347 GtkTreeViewDropPosition *pos)
3349 GtkTreeView *tree_view;
3350 GtkTreeViewColumn *column;
3354 int bookmarks_index;
3356 tree_view = GTK_TREE_VIEW (impl->browse_shortcuts_tree_view);
3358 bookmarks_index = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS);
3360 if (!gtk_tree_view_get_path_at_pos (tree_view,
3362 y - TREE_VIEW_HEADER_HEIGHT (tree_view),
3368 row = bookmarks_index + impl->num_bookmarks - 1;
3369 *path = gtk_tree_path_new_from_indices (row, -1);
3370 *pos = GTK_TREE_VIEW_DROP_AFTER;
3374 row = *gtk_tree_path_get_indices (*path);
3375 gtk_tree_view_get_background_area (tree_view, *path, column, &cell);
3376 gtk_tree_path_free (*path);
3378 if (row < bookmarks_index)
3380 row = bookmarks_index;
3381 *pos = GTK_TREE_VIEW_DROP_BEFORE;
3383 else if (row > bookmarks_index + impl->num_bookmarks - 1)
3385 row = bookmarks_index + impl->num_bookmarks - 1;
3386 *pos = GTK_TREE_VIEW_DROP_AFTER;
3390 if (cell_y < cell.height / 2)
3391 *pos = GTK_TREE_VIEW_DROP_BEFORE;
3393 *pos = GTK_TREE_VIEW_DROP_AFTER;
3396 *path = gtk_tree_path_new_from_indices (row, -1);
3399 /* GtkWidget::drag-motion handler for the shortcuts list. We basically
3400 * implement the destination side of DnD by hand, due to limitations in
3401 * GtkTreeView's DnD API.
3404 shortcuts_drag_motion_cb (GtkWidget *widget,
3405 GdkDragContext *context,
3409 GtkFileChooserDefault *impl)
3412 GtkTreeViewDropPosition pos;
3413 GdkDragAction action;
3416 if (gtk_drag_get_source_widget (context) == widget)
3418 shortcuts_cancel_drag_outside_idle (impl);
3420 if (impl->shortcuts_drag_outside)
3422 shortcuts_drag_set_delete_cursor (impl, FALSE);
3423 impl->shortcuts_drag_outside = FALSE;
3428 if (context->suggested_action == GDK_ACTION_COPY ||
3429 (context->actions & GDK_ACTION_COPY) != 0)
3430 action = GDK_ACTION_COPY;
3431 else if (context->suggested_action == GDK_ACTION_MOVE ||
3432 (context->actions & GDK_ACTION_MOVE) != 0)
3433 action = GDK_ACTION_MOVE;
3440 shortcuts_compute_drop_position (impl, x, y, &path, &pos);
3441 gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), path, pos);
3442 gtk_tree_path_free (path);
3446 g_signal_stop_emission_by_name (widget, "drag_motion");
3450 gdk_drag_status (context, action, time_);
3457 /* GtkWidget::drag-drop handler for the shortcuts list. */
3459 shortcuts_drag_drop_cb (GtkWidget *widget,
3460 GdkDragContext *context,
3464 GtkFileChooserDefault *impl)
3467 shortcuts_cancel_drag_outside_idle (impl);
3470 g_signal_stop_emission_by_name (widget, "drag_drop");
3474 /* Parses a "text/uri-list" string and inserts its URIs as bookmarks */
3476 shortcuts_drop_uris (GtkFileChooserDefault *impl,
3483 uris = g_uri_list_extract_uris (data);
3485 for (i = 0; uris[i]; i++)
3491 path = gtk_file_system_uri_to_path (impl->file_system, uri);
3495 if (shortcuts_add_bookmark_from_path (impl, path, position))
3498 gtk_file_path_free (path);
3504 g_set_error (&error,
3505 GTK_FILE_CHOOSER_ERROR,
3506 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
3507 _("Could not add a bookmark for '%s' "
3508 "because it is an invalid path name."),
3510 error_adding_bookmark_dialog (impl, path, error);
3517 /* Reorders the selected bookmark to the specified position */
3519 shortcuts_reorder (GtkFileChooserDefault *impl,
3524 ShortcutType shortcut_type;
3527 int bookmarks_index;
3528 const GtkFilePath *file_path;
3529 GtkFilePath *file_path_copy;
3533 /* Get the selected path */
3535 if (!shortcuts_get_selected (impl, &iter))
3536 g_assert_not_reached ();
3538 path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
3539 old_position = *gtk_tree_path_get_indices (path);
3540 gtk_tree_path_free (path);
3542 bookmarks_index = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS);
3543 old_position -= bookmarks_index;
3544 g_assert (old_position >= 0 && old_position < impl->num_bookmarks);
3546 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
3547 SHORTCUTS_COL_NAME, &name,
3548 SHORTCUTS_COL_DATA, &col_data,
3549 SHORTCUTS_COL_TYPE, &shortcut_type,
3551 g_assert (col_data != NULL);
3552 g_assert (shortcut_type == SHORTCUT_TYPE_PATH);
3554 file_path = col_data;
3555 file_path_copy = gtk_file_path_copy (file_path); /* removal below will free file_path, so we need a copy */
3557 /* Remove the path from the old position and insert it in the new one */
3559 if (new_position > old_position)
3562 if (old_position == new_position)
3566 if (gtk_file_system_remove_bookmark (impl->file_system, file_path_copy, &error))
3568 shortcuts_add_bookmark_from_path (impl, file_path_copy, new_position);
3569 gtk_file_system_set_bookmark_label (impl->file_system, file_path_copy, name);
3572 error_adding_bookmark_dialog (impl, file_path_copy, error);
3576 gtk_file_path_free (file_path_copy);
3579 /* Callback used when we get the drag data for the bookmarks list. We add the
3580 * received URIs as bookmarks if they are folders.
3583 shortcuts_drag_data_received_cb (GtkWidget *widget,
3584 GdkDragContext *context,
3587 GtkSelectionData *selection_data,
3592 GtkFileChooserDefault *impl;
3593 GtkTreePath *tree_path;
3594 GtkTreeViewDropPosition tree_pos;
3596 int bookmarks_index;
3598 impl = GTK_FILE_CHOOSER_DEFAULT (data);
3600 /* Compute position */
3602 bookmarks_index = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS);
3604 shortcuts_compute_drop_position (impl, x, y, &tree_path, &tree_pos);
3605 position = *gtk_tree_path_get_indices (tree_path);
3606 gtk_tree_path_free (tree_path);
3608 if (tree_pos == GTK_TREE_VIEW_DROP_AFTER)
3611 g_assert (position >= bookmarks_index);
3612 position -= bookmarks_index;
3614 if (selection_data->target == gdk_atom_intern_static_string ("text/uri-list"))
3615 shortcuts_drop_uris (impl, (const char *) selection_data->data, position);
3616 else if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
3617 shortcuts_reorder (impl, position);
3619 g_signal_stop_emission_by_name (widget, "drag_data_received");
3622 /* Callback used when the selection in the shortcuts tree changes */
3624 shortcuts_selection_changed_cb (GtkTreeSelection *selection,
3625 GtkFileChooserDefault *impl)
3627 bookmarks_check_remove_sensitivity (impl);
3628 shortcuts_check_popup_sensitivity (impl);
3632 shortcuts_row_separator_func (GtkTreeModel *model,
3636 ShortcutType shortcut_type;
3638 gtk_tree_model_get (model, iter, SHORTCUTS_COL_TYPE, &shortcut_type, -1);
3640 return shortcut_type == SHORTCUT_TYPE_SEPARATOR;
3643 /* Since GtkTreeView has a keybinding attached to '/', we need to catch
3644 * keypresses before the TreeView gets them.
3647 tree_view_keybinding_cb (GtkWidget *tree_view,
3649 GtkFileChooserDefault *impl)
3651 if ((event->keyval == GDK_slash
3652 || event->keyval == GDK_KP_Divide
3654 || event->keyval == GDK_asciitilde
3656 ) && ! (event->state & (~GDK_SHIFT_MASK & gtk_accelerator_get_default_mod_mask ())))
3658 location_popup_handler (impl, event->string);
3665 /* Callback used when the file list's popup menu is detached */
3667 shortcuts_popup_menu_detach_cb (GtkWidget *attach_widget,
3670 GtkFileChooserDefault *impl;
3672 impl = g_object_get_data (G_OBJECT (attach_widget), "GtkFileChooserDefault");
3673 g_assert (GTK_IS_FILE_CHOOSER_DEFAULT (impl));
3675 impl->browse_shortcuts_popup_menu = NULL;
3676 impl->browse_shortcuts_popup_menu_remove_item = NULL;
3677 impl->browse_shortcuts_popup_menu_rename_item = NULL;
3681 remove_shortcut_cb (GtkMenuItem *item,
3682 GtkFileChooserDefault *impl)
3684 remove_selected_bookmarks (impl);
3687 /* Rename the selected bookmark */
3689 rename_selected_bookmark (GtkFileChooserDefault *impl)
3693 GtkTreeViewColumn *column;
3694 GtkCellRenderer *cell;
3697 if (shortcuts_get_selected (impl, &iter))
3699 path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
3700 column = gtk_tree_view_get_column (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), 0);
3701 renderers = gtk_tree_view_column_get_cell_renderers (column);
3702 cell = g_list_nth_data (renderers, 1);
3703 g_list_free (renderers);
3704 g_object_set (cell, "editable", TRUE, NULL);
3705 gtk_tree_view_set_cursor_on_cell (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view),
3706 path, column, cell, TRUE);
3707 gtk_tree_path_free (path);
3712 rename_shortcut_cb (GtkMenuItem *item,
3713 GtkFileChooserDefault *impl)
3715 rename_selected_bookmark (impl);
3718 /* Constructs the popup menu for the file list if needed */
3720 shortcuts_build_popup_menu (GtkFileChooserDefault *impl)
3724 if (impl->browse_shortcuts_popup_menu)
3727 impl->browse_shortcuts_popup_menu = gtk_menu_new ();
3728 gtk_menu_attach_to_widget (GTK_MENU (impl->browse_shortcuts_popup_menu),
3729 impl->browse_shortcuts_tree_view,
3730 shortcuts_popup_menu_detach_cb);
3732 item = gtk_image_menu_item_new_with_label (_("Remove"));
3733 impl->browse_shortcuts_popup_menu_remove_item = item;
3734 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
3735 gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU));
3736 g_signal_connect (item, "activate",
3737 G_CALLBACK (remove_shortcut_cb), impl);
3738 gtk_widget_show (item);
3739 gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_shortcuts_popup_menu), item);
3741 item = gtk_menu_item_new_with_label (_("Rename..."));
3742 impl->browse_shortcuts_popup_menu_rename_item = item;
3743 g_signal_connect (item, "activate",
3744 G_CALLBACK (rename_shortcut_cb), impl);
3745 gtk_widget_show (item);
3746 gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_shortcuts_popup_menu), item);
3748 shortcuts_check_popup_sensitivity (impl);
3752 shortcuts_update_popup_menu (GtkFileChooserDefault *impl)
3754 shortcuts_build_popup_menu (impl);
3758 popup_position_func (GtkMenu *menu,
3762 gpointer user_data);
3765 shortcuts_popup_menu (GtkFileChooserDefault *impl,
3766 GdkEventButton *event)
3768 shortcuts_update_popup_menu (impl);
3770 gtk_menu_popup (GTK_MENU (impl->browse_shortcuts_popup_menu),
3771 NULL, NULL, NULL, NULL,
3772 event->button, event->time);
3775 gtk_menu_popup (GTK_MENU (impl->browse_shortcuts_popup_menu),
3777 popup_position_func, impl->browse_shortcuts_tree_view,
3778 0, GDK_CURRENT_TIME);
3779 gtk_menu_shell_select_first (GTK_MENU_SHELL (impl->browse_shortcuts_popup_menu),
3784 /* Callback used for the GtkWidget::popup-menu signal of the shortcuts list */
3786 shortcuts_popup_menu_cb (GtkWidget *widget,
3787 GtkFileChooserDefault *impl)
3789 shortcuts_popup_menu (impl, NULL);
3793 /* Callback used when a button is pressed on the shortcuts list.
3794 * We trap button 3 to bring up a popup menu.
3797 shortcuts_button_press_event_cb (GtkWidget *widget,
3798 GdkEventButton *event,
3799 GtkFileChooserDefault *impl)
3801 static gboolean in_press = FALSE;
3807 if (event->button != 3)
3811 handled = gtk_widget_event (impl->browse_shortcuts_tree_view, (GdkEvent *) event);
3817 shortcuts_popup_menu (impl, event);
3822 shortcuts_edited (GtkCellRenderer *cell,
3825 GtkFileChooserDefault *impl)
3829 GtkFilePath *shortcut;
3831 g_object_set (cell, "editable", FALSE, NULL);
3833 path = gtk_tree_path_new_from_string (path_string);
3834 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->shortcuts_model), &iter, path))
3835 g_assert_not_reached ();
3837 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
3838 SHORTCUTS_COL_DATA, &shortcut,
3840 gtk_tree_path_free (path);
3842 gtk_file_system_set_bookmark_label (impl->file_system, shortcut, new_text);
3846 shortcuts_editing_canceled (GtkCellRenderer *cell,
3847 GtkFileChooserDefault *impl)
3849 g_object_set (cell, "editable", FALSE, NULL);
3852 /* Creates the widgets for the shortcuts and bookmarks tree */
3854 shortcuts_list_create (GtkFileChooserDefault *impl)
3857 GtkTreeSelection *selection;
3858 GtkTreeViewColumn *column;
3859 GtkCellRenderer *renderer;
3861 /* Scrolled window */
3863 swin = gtk_scrolled_window_new (NULL, NULL);
3864 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin),
3865 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
3866 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swin),
3868 gtk_widget_show (swin);
3872 impl->browse_shortcuts_tree_view = gtk_tree_view_new ();
3873 #ifdef PROFILE_FILE_CHOOSER
3874 g_object_set_data (G_OBJECT (impl->browse_shortcuts_tree_view), "fmq-name", "shortcuts");
3876 g_signal_connect (impl->browse_shortcuts_tree_view, "key_press_event",
3877 G_CALLBACK (tree_view_keybinding_cb), impl);
3878 g_signal_connect (impl->browse_shortcuts_tree_view, "popup_menu",
3879 G_CALLBACK (shortcuts_popup_menu_cb), impl);
3880 g_signal_connect (impl->browse_shortcuts_tree_view, "button_press_event",
3881 G_CALLBACK (shortcuts_button_press_event_cb), impl);
3882 /* Accessible object name for the file chooser's shortcuts pane */
3883 atk_object_set_name (gtk_widget_get_accessible (impl->browse_shortcuts_tree_view), _("Places"));
3885 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), impl->shortcuts_pane_filter_model);
3887 gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view),
3889 shortcuts_source_targets,
3890 num_shortcuts_source_targets,
3893 gtk_drag_dest_set (impl->browse_shortcuts_tree_view,
3894 GTK_DEST_DEFAULT_ALL,
3895 shortcuts_dest_targets,
3896 num_shortcuts_dest_targets,
3897 GDK_ACTION_COPY | GDK_ACTION_MOVE);
3899 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view));
3900 gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
3901 gtk_tree_selection_set_select_function (selection,
3902 shortcuts_select_func,
3905 g_signal_connect (selection, "changed",
3906 G_CALLBACK (shortcuts_selection_changed_cb), impl);
3908 g_signal_connect (impl->browse_shortcuts_tree_view, "row_activated",
3909 G_CALLBACK (shortcuts_row_activated_cb), impl);
3911 g_signal_connect (impl->browse_shortcuts_tree_view, "key_press_event",
3912 G_CALLBACK (shortcuts_key_press_event_cb), impl);
3914 g_signal_connect (impl->browse_shortcuts_tree_view, "drag_begin",
3915 G_CALLBACK (shortcuts_drag_begin_cb), impl);
3916 g_signal_connect (impl->browse_shortcuts_tree_view, "drag_end",
3917 G_CALLBACK (shortcuts_drag_end_cb), impl);
3918 g_signal_connect (impl->browse_shortcuts_tree_view, "drag_data_delete",
3919 G_CALLBACK (shortcuts_drag_data_delete_cb), impl);
3921 g_signal_connect (impl->browse_shortcuts_tree_view, "drag_leave",
3922 G_CALLBACK (shortcuts_drag_leave_cb), impl);
3923 g_signal_connect (impl->browse_shortcuts_tree_view, "drag_motion",
3924 G_CALLBACK (shortcuts_drag_motion_cb), impl);
3925 g_signal_connect (impl->browse_shortcuts_tree_view, "drag_drop",
3926 G_CALLBACK (shortcuts_drag_drop_cb), impl);
3927 g_signal_connect (impl->browse_shortcuts_tree_view, "drag_data_received",
3928 G_CALLBACK (shortcuts_drag_data_received_cb), impl);
3930 gtk_container_add (GTK_CONTAINER (swin), impl->browse_shortcuts_tree_view);
3931 gtk_widget_show (impl->browse_shortcuts_tree_view);
3935 column = gtk_tree_view_column_new ();
3936 /* Column header for the file chooser's shortcuts pane */
3937 gtk_tree_view_column_set_title (column, _("_Places"));
3939 renderer = gtk_cell_renderer_pixbuf_new ();
3940 gtk_tree_view_column_pack_start (column, renderer, FALSE);
3941 gtk_tree_view_column_set_attributes (column, renderer,
3942 "pixbuf", SHORTCUTS_COL_PIXBUF,
3943 "visible", SHORTCUTS_COL_PIXBUF_VISIBLE,
3946 renderer = gtk_cell_renderer_text_new ();
3947 g_signal_connect (renderer, "edited",
3948 G_CALLBACK (shortcuts_edited), impl);
3949 g_signal_connect (renderer, "editing-canceled",
3950 G_CALLBACK (shortcuts_editing_canceled), impl);
3951 gtk_tree_view_column_pack_start (column, renderer, TRUE);
3952 gtk_tree_view_column_set_attributes (column, renderer,
3953 "text", SHORTCUTS_COL_NAME,
3956 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view),
3957 shortcuts_row_separator_func,
3960 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), column);
3965 /* Creates the widgets for the shortcuts/bookmarks pane */
3967 shortcuts_pane_create (GtkFileChooserDefault *impl,
3968 GtkSizeGroup *size_group)
3974 vbox = gtk_vbox_new (FALSE, 6);
3975 gtk_widget_show (vbox);
3977 /* Shortcuts tree */
3979 widget = shortcuts_list_create (impl);
3980 gtk_box_pack_start (GTK_BOX (vbox), widget, TRUE, TRUE, 0);
3982 /* Box for buttons */
3984 hbox = gtk_hbox_new (TRUE, 6);
3985 gtk_size_group_add_widget (size_group, hbox);
3986 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
3987 gtk_widget_show (hbox);
3989 /* Add bookmark button */
3991 impl->browse_shortcuts_add_button = button_new (impl,
3996 G_CALLBACK (add_bookmark_button_clicked_cb));
3997 gtk_box_pack_start (GTK_BOX (hbox), impl->browse_shortcuts_add_button, TRUE, TRUE, 0);
3998 gtk_tooltips_set_tip (impl->tooltips, impl->browse_shortcuts_add_button,
3999 _("Add the selected folder to the Bookmarks"), NULL);
4001 /* Remove bookmark button */
4003 impl->browse_shortcuts_remove_button = button_new (impl,
4008 G_CALLBACK (remove_bookmark_button_clicked_cb));
4009 gtk_box_pack_start (GTK_BOX (hbox), impl->browse_shortcuts_remove_button, TRUE, TRUE, 0);
4010 gtk_tooltips_set_tip (impl->tooltips, impl->browse_shortcuts_remove_button,
4011 _("Remove the selected bookmark"), NULL);
4016 /* Handles key press events on the file list, so that we can trap Enter to
4017 * activate the default button on our own. Also, checks to see if '/' has been
4018 * pressed. See comment by tree_view_keybinding_cb() for more details.
4021 trap_activate_cb (GtkWidget *widget,
4025 GtkFileChooserDefault *impl;
4028 impl = (GtkFileChooserDefault *) data;
4030 modifiers = gtk_accelerator_get_default_mod_mask ();
4032 if ((event->keyval == GDK_slash
4033 || event->keyval == GDK_KP_Divide
4035 || event->keyval == GDK_asciitilde
4037 ) && ! (event->state & (~GDK_SHIFT_MASK & modifiers)))
4039 location_popup_handler (impl, event->string);
4043 if ((event->keyval == GDK_Return
4044 || event->keyval == GDK_ISO_Enter
4045 || event->keyval == GDK_KP_Enter
4046 || event->keyval == GDK_space)
4047 && ((event->state & modifiers) == 0)
4048 && !(impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
4049 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER))
4053 window = get_toplevel (widget);
4055 && widget != window->default_widget
4056 && !(widget == window->focus_widget &&
4057 (!window->default_widget || !GTK_WIDGET_SENSITIVE (window->default_widget))))
4059 gtk_window_activate_default (window);
4067 /* Callback used when the file list's popup menu is detached */
4069 popup_menu_detach_cb (GtkWidget *attach_widget,
4072 GtkFileChooserDefault *impl;
4074 impl = g_object_get_data (G_OBJECT (attach_widget), "GtkFileChooserDefault");
4075 g_assert (GTK_IS_FILE_CHOOSER_DEFAULT (impl));
4077 impl->browse_files_popup_menu = NULL;
4078 impl->browse_files_popup_menu_add_shortcut_item = NULL;
4079 impl->browse_files_popup_menu_hidden_files_item = NULL;
4082 /* Callback used when the "Add to Bookmarks" menu item is activated */
4084 add_to_shortcuts_cb (GtkMenuItem *item,
4085 GtkFileChooserDefault *impl)
4087 bookmarks_add_selected_folder (impl);
4090 /* Callback used when the "Show Hidden Files" menu item is toggled */
4092 show_hidden_toggled_cb (GtkCheckMenuItem *item,
4093 GtkFileChooserDefault *impl)
4096 "show-hidden", gtk_check_menu_item_get_active (item),
4100 /* Shows an error dialog about not being able to select a dragged file */
4102 error_selecting_dragged_file_dialog (GtkFileChooserDefault *impl,
4103 const GtkFilePath *path,
4107 _("Could not select file"),
4112 file_list_drag_data_select_uris (GtkFileChooserDefault *impl,
4117 GtkFileChooser *chooser = GTK_FILE_CHOOSER (impl);
4119 for (i = 1; uris[i]; i++)
4124 path = gtk_file_system_uri_to_path (impl->file_system, uri);
4128 GError *error = NULL;
4130 gtk_file_chooser_default_select_path (chooser, path, &error);
4132 error_selecting_dragged_file_dialog (impl, path, error);
4134 gtk_file_path_free (path);
4139 struct FileListDragData
4141 GtkFileChooserDefault *impl;
4147 file_list_drag_data_received_get_info_cb (GtkFileSystemHandle *handle,
4148 const GtkFileInfo *info,
4149 const GError *error,
4152 gboolean cancelled = handle->cancelled;
4153 struct FileListDragData *data = user_data;
4154 GtkFileChooser *chooser = GTK_FILE_CHOOSER (data->impl);
4156 if (handle != data->impl->file_list_drag_data_received_handle)
4159 data->impl->file_list_drag_data_received_handle = NULL;
4161 if (cancelled || error)
4164 if ((data->impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
4165 data->impl->action == GTK_FILE_CHOOSER_ACTION_SAVE) &&
4166 data->uris[1] == 0 && !error &&
4167 gtk_file_info_get_is_folder (info))
4168 change_folder_and_display_error (data->impl, data->path, FALSE);
4171 GError *error = NULL;
4173 gtk_file_chooser_default_unselect_all (chooser);
4174 gtk_file_chooser_default_select_path (chooser, data->path, &error);
4176 error_selecting_dragged_file_dialog (data->impl, data->path, error);
4178 browse_files_center_selected_row (data->impl);
4181 if (data->impl->select_multiple)
4182 file_list_drag_data_select_uris (data->impl, data->uris);
4185 g_object_unref (data->impl);
4186 g_strfreev (data->uris);
4187 gtk_file_path_free (data->path);
4190 g_object_unref (handle);
4194 file_list_drag_data_received_cb (GtkWidget *widget,
4195 GdkDragContext *context,
4198 GtkSelectionData *selection_data,
4203 GtkFileChooserDefault *impl;
4204 GtkFileChooser *chooser;
4208 GError *error = NULL;
4210 impl = GTK_FILE_CHOOSER_DEFAULT (data);
4211 chooser = GTK_FILE_CHOOSER (data);
4213 /* Parse the text/uri-list string, navigate to the first one */
4214 uris = g_uri_list_extract_uris ((const char *) selection_data->data);
4218 path = gtk_file_system_uri_to_path (impl->file_system, uri);
4222 struct FileListDragData *data;
4224 data = g_new0 (struct FileListDragData, 1);
4225 data->impl = g_object_ref (impl);
4229 if (impl->file_list_drag_data_received_handle)
4230 gtk_file_system_cancel_operation (impl->file_list_drag_data_received_handle);
4232 impl->file_list_drag_data_received_handle =
4233 gtk_file_system_get_info (impl->file_system, path,
4234 GTK_FILE_INFO_IS_FOLDER,
4235 file_list_drag_data_received_get_info_cb,
4241 g_set_error (&error,
4242 GTK_FILE_CHOOSER_ERROR,
4243 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
4244 _("Could not select file '%s' "
4245 "because it is an invalid path name."),
4247 error_selecting_dragged_file_dialog (impl, NULL, error);
4250 if (impl->select_multiple)
4251 file_list_drag_data_select_uris (impl, uris);
4257 g_signal_stop_emission_by_name (widget, "drag_data_received");
4260 /* Don't do anything with the drag_drop signal */
4262 file_list_drag_drop_cb (GtkWidget *widget,
4263 GdkDragContext *context,
4267 GtkFileChooserDefault *impl)
4269 g_signal_stop_emission_by_name (widget, "drag_drop");
4273 /* Disable the normal tree drag motion handler, it makes it look like you're
4274 dropping the dragged item onto a tree item */
4276 file_list_drag_motion_cb (GtkWidget *widget,
4277 GdkDragContext *context,
4281 GtkFileChooserDefault *impl)
4283 g_signal_stop_emission_by_name (widget, "drag_motion");
4287 /* Constructs the popup menu for the file list if needed */
4289 file_list_build_popup_menu (GtkFileChooserDefault *impl)
4293 if (impl->browse_files_popup_menu)
4296 impl->browse_files_popup_menu = gtk_menu_new ();
4297 gtk_menu_attach_to_widget (GTK_MENU (impl->browse_files_popup_menu),
4298 impl->browse_files_tree_view,
4299 popup_menu_detach_cb);
4301 item = gtk_image_menu_item_new_with_mnemonic (_("_Add to Bookmarks"));
4302 impl->browse_files_popup_menu_add_shortcut_item = item;
4303 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
4304 gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
4305 gtk_widget_set_sensitive (item, FALSE);
4306 g_signal_connect (item, "activate",
4307 G_CALLBACK (add_to_shortcuts_cb), impl);
4308 gtk_widget_show (item);
4309 gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
4311 item = gtk_separator_menu_item_new ();
4312 gtk_widget_show (item);
4313 gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
4315 item = gtk_check_menu_item_new_with_mnemonic (_("Show _Hidden Files"));
4316 impl->browse_files_popup_menu_hidden_files_item = item;
4317 g_signal_connect (item, "toggled",
4318 G_CALLBACK (show_hidden_toggled_cb), impl);
4319 gtk_widget_show (item);
4320 gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
4323 /* Updates the popup menu for the file list, creating it if necessary */
4325 file_list_update_popup_menu (GtkFileChooserDefault *impl)
4327 file_list_build_popup_menu (impl);
4329 /* FIXME - handle OPERATION_MODE_SEARCH and OPERATION_MODE_RECENT */
4331 /* The sensitivity of the Add to Bookmarks item is set in
4332 * bookmarks_check_add_sensitivity()
4335 g_signal_handlers_block_by_func (impl->browse_files_popup_menu_hidden_files_item,
4336 G_CALLBACK (show_hidden_toggled_cb), impl);
4337 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (impl->browse_files_popup_menu_hidden_files_item),
4339 g_signal_handlers_unblock_by_func (impl->browse_files_popup_menu_hidden_files_item,
4340 G_CALLBACK (show_hidden_toggled_cb), impl);
4344 popup_position_func (GtkMenu *menu,
4350 GtkWidget *widget = GTK_WIDGET (user_data);
4351 GdkScreen *screen = gtk_widget_get_screen (widget);
4354 GdkRectangle monitor;
4356 g_return_if_fail (GTK_WIDGET_REALIZED (widget));
4358 gdk_window_get_origin (widget->window, x, y);
4360 gtk_widget_size_request (GTK_WIDGET (menu), &req);
4362 *x += (widget->allocation.width - req.width) / 2;
4363 *y += (widget->allocation.height - req.height) / 2;
4365 monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
4366 gtk_menu_set_monitor (menu, monitor_num);
4367 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
4369 *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
4370 *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
4376 file_list_popup_menu (GtkFileChooserDefault *impl,
4377 GdkEventButton *event)
4379 file_list_update_popup_menu (impl);
4381 gtk_menu_popup (GTK_MENU (impl->browse_files_popup_menu),
4382 NULL, NULL, NULL, NULL,
4383 event->button, event->time);
4386 gtk_menu_popup (GTK_MENU (impl->browse_files_popup_menu),
4388 popup_position_func, impl->browse_files_tree_view,
4389 0, GDK_CURRENT_TIME);
4390 gtk_menu_shell_select_first (GTK_MENU_SHELL (impl->browse_files_popup_menu),
4396 /* Callback used for the GtkWidget::popup-menu signal of the file list */
4398 list_popup_menu_cb (GtkWidget *widget,
4399 GtkFileChooserDefault *impl)
4401 file_list_popup_menu (impl, NULL);
4405 /* Callback used when a button is pressed on the file list. We trap button 3 to
4406 * bring up a popup menu.
4409 list_button_press_event_cb (GtkWidget *widget,
4410 GdkEventButton *event,
4411 GtkFileChooserDefault *impl)
4413 static gboolean in_press = FALSE;
4419 if (event->button != 3)
4423 handled = gtk_widget_event (impl->browse_files_tree_view, (GdkEvent *) event);
4426 file_list_popup_menu (impl, event);
4430 /* Sets the sort column IDs for the file list based on the operation mode */
4432 file_list_set_sort_column_ids (GtkFileChooserDefault *impl)
4434 int name_id, mtime_id;
4436 name_id = mtime_id = 0;
4438 switch (impl->operation_mode)
4440 case OPERATION_MODE_BROWSE:
4441 name_id = FILE_LIST_COL_NAME;
4442 mtime_id = FILE_LIST_COL_MTIME;
4444 case OPERATION_MODE_SEARCH:
4445 name_id = SEARCH_MODEL_COL_PATH;
4446 mtime_id = SEARCH_MODEL_COL_STAT;
4448 case OPERATION_MODE_RECENT:
4449 name_id = RECENT_MODEL_COL_PATH;
4450 mtime_id = RECENT_MODEL_COL_INFO;
4454 gtk_tree_view_column_set_sort_column_id (impl->list_name_column, name_id);
4455 gtk_tree_view_column_set_sort_column_id (impl->list_mtime_column, mtime_id);
4459 /* Creates the widgets for the file list */
4461 create_file_list (GtkFileChooserDefault *impl)
4464 GtkTreeSelection *selection;
4465 GtkTreeViewColumn *column;
4466 GtkCellRenderer *renderer;
4468 /* Scrolled window */
4470 swin = gtk_scrolled_window_new (NULL, NULL);
4471 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin),
4472 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
4473 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swin),
4476 /* Tree/list view */
4478 impl->browse_files_tree_view = gtk_tree_view_new ();
4479 #ifdef PROFILE_FILE_CHOOSER
4480 g_object_set_data (G_OBJECT (impl->browse_files_tree_view), "fmq-name", "file_list");
4482 g_object_set_data (G_OBJECT (impl->browse_files_tree_view), I_("GtkFileChooserDefault"), impl);
4483 atk_object_set_name (gtk_widget_get_accessible (impl->browse_files_tree_view), _("Files"));
4485 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (impl->browse_files_tree_view), TRUE);
4486 gtk_container_add (GTK_CONTAINER (swin), impl->browse_files_tree_view);
4488 gtk_drag_dest_set (impl->browse_files_tree_view,
4489 GTK_DEST_DEFAULT_ALL,
4490 file_list_dest_targets,
4491 num_file_list_dest_targets,
4492 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4494 g_signal_connect (impl->browse_files_tree_view, "row_activated",
4495 G_CALLBACK (list_row_activated), impl);
4496 g_signal_connect (impl->browse_files_tree_view, "key_press_event",
4497 G_CALLBACK (trap_activate_cb), impl);
4498 g_signal_connect (impl->browse_files_tree_view, "popup_menu",
4499 G_CALLBACK (list_popup_menu_cb), impl);
4500 g_signal_connect (impl->browse_files_tree_view, "button_press_event",
4501 G_CALLBACK (list_button_press_event_cb), impl);
4503 g_signal_connect (impl->browse_files_tree_view, "drag_data_received",
4504 G_CALLBACK (file_list_drag_data_received_cb), impl);
4505 g_signal_connect (impl->browse_files_tree_view, "drag_drop",
4506 G_CALLBACK (file_list_drag_drop_cb), impl);
4507 g_signal_connect (impl->browse_files_tree_view, "drag_motion",
4508 G_CALLBACK (file_list_drag_motion_cb), impl);
4510 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
4511 gtk_tree_selection_set_select_function (selection,
4514 gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (impl->browse_files_tree_view),
4516 file_list_source_targets,
4517 num_file_list_source_targets,
4520 g_signal_connect (selection, "changed",
4521 G_CALLBACK (list_selection_changed), impl);
4523 /* Filename column */
4525 impl->list_name_column = gtk_tree_view_column_new ();
4526 gtk_tree_view_column_set_expand (impl->list_name_column, TRUE);
4527 gtk_tree_view_column_set_resizable (impl->list_name_column, TRUE);
4528 gtk_tree_view_column_set_title (impl->list_name_column, _("Name"));
4529 gtk_tree_view_column_set_sort_column_id (impl->list_name_column, FILE_LIST_COL_NAME);
4531 renderer = gtk_cell_renderer_pixbuf_new ();
4532 gtk_tree_view_column_pack_start (impl->list_name_column, renderer, FALSE);
4533 gtk_tree_view_column_set_cell_data_func (impl->list_name_column, renderer,
4534 list_icon_data_func, impl, NULL);
4536 impl->list_name_renderer = gtk_cell_renderer_text_new ();
4537 g_object_set (impl->list_name_renderer,
4538 "ellipsize", PANGO_ELLIPSIZE_END,
4540 g_signal_connect (impl->list_name_renderer, "edited",
4541 G_CALLBACK (renderer_edited_cb), impl);
4542 g_signal_connect (impl->list_name_renderer, "editing_canceled",
4543 G_CALLBACK (renderer_editing_canceled_cb), impl);
4544 gtk_tree_view_column_pack_start (impl->list_name_column, impl->list_name_renderer, TRUE);
4545 gtk_tree_view_column_set_cell_data_func (impl->list_name_column, impl->list_name_renderer,
4546 list_name_data_func, impl, NULL);
4548 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->browse_files_tree_view), impl->list_name_column);
4552 column = gtk_tree_view_column_new ();
4553 gtk_tree_view_column_set_title (column, _("Size"));
4555 renderer = gtk_cell_renderer_text_new ();
4556 gtk_tree_view_column_pack_start (column, renderer, TRUE); /* bug: it doesn't expand */
4557 gtk_tree_view_column_set_cell_data_func (column, renderer,
4558 list_size_data_func, impl, NULL);
4559 gtk_tree_view_column_set_sort_column_id (column, FILE_LIST_COL_SIZE);
4560 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->browse_files_tree_view), column);
4563 /* Modification time column */
4565 column = gtk_tree_view_column_new ();
4566 gtk_tree_view_column_set_resizable (column, TRUE);
4567 gtk_tree_view_column_set_title (column, _("Modified"));
4569 renderer = gtk_cell_renderer_text_new ();
4570 gtk_tree_view_column_pack_start (column, renderer, TRUE);
4571 gtk_tree_view_column_set_cell_data_func (column, renderer,
4572 list_mtime_data_func, impl, NULL);
4573 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->browse_files_tree_view), column);
4574 impl->list_mtime_column = column;
4576 file_list_set_sort_column_ids (impl);
4578 gtk_widget_show_all (swin);
4584 create_path_bar (GtkFileChooserDefault *impl)
4586 GtkWidget *path_bar;
4588 path_bar = g_object_new (GTK_TYPE_PATH_BAR, NULL);
4589 _gtk_path_bar_set_file_system (GTK_PATH_BAR (path_bar), impl->file_system);
4595 set_filter_tooltip (GtkWidget *widget,
4598 GtkTooltips *tooltips = (GtkTooltips *)data;
4600 if (GTK_IS_BUTTON (widget))
4601 gtk_tooltips_set_tip (tooltips, widget,
4602 _("Select which types of files are shown"),
4607 realize_filter_combo (GtkWidget *combo,
4610 GtkFileChooserDefault *impl = (GtkFileChooserDefault *)data;
4612 gtk_container_forall (GTK_CONTAINER (combo),
4617 /* Creates the widgets for the files/folders pane */
4619 file_pane_create (GtkFileChooserDefault *impl,
4620 GtkSizeGroup *size_group)
4626 vbox = gtk_vbox_new (FALSE, 6);
4627 gtk_widget_show (vbox);
4629 /* Box for lists and preview */
4631 hbox = gtk_hbox_new (FALSE, PREVIEW_HBOX_SPACING);
4632 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
4633 gtk_widget_show (hbox);
4637 widget = create_file_list (impl);
4638 gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
4642 impl->preview_box = gtk_vbox_new (FALSE, 12);
4643 gtk_box_pack_start (GTK_BOX (hbox), impl->preview_box, FALSE, FALSE, 0);
4644 /* Don't show preview box initially */
4648 impl->filter_combo_hbox = gtk_hbox_new (FALSE, 12);
4650 widget = filter_create (impl);
4652 g_signal_connect (widget, "realize",
4653 G_CALLBACK (realize_filter_combo), impl);
4655 gtk_widget_show (widget);
4656 gtk_box_pack_end (GTK_BOX (impl->filter_combo_hbox), widget, FALSE, FALSE, 0);
4658 gtk_size_group_add_widget (size_group, impl->filter_combo_hbox);
4659 gtk_box_pack_end (GTK_BOX (vbox), impl->filter_combo_hbox, FALSE, FALSE, 0);
4664 /* Callback used when the "Browse for more folders" expander is toggled */
4666 expander_changed_cb (GtkExpander *expander,
4668 GtkFileChooserDefault *impl)
4670 impl->expand_folders = gtk_expander_get_expanded(GTK_EXPANDER (impl->save_expander));
4671 update_appearance (impl);
4674 /* Callback used when the selection changes in the save folder combo box */
4676 save_folder_combo_changed_cb (GtkComboBox *combo,
4677 GtkFileChooserDefault *impl)
4681 if (impl->changing_folder)
4684 if (gtk_combo_box_get_active_iter (combo, &iter))
4686 GtkTreeIter child_iter;
4688 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (impl->shortcuts_combo_filter_model),
4691 shortcuts_activate_iter (impl, &child_iter);
4695 /* Filter function used to filter out the Search item and its separator.
4696 * Used for the "Save in folder" combo box, so that these items do not appear in it.
4699 shortcuts_combo_filter_func (GtkTreeModel *model,
4703 GtkFileChooserDefault *impl;
4704 GtkTreePath *tree_path;
4709 impl = GTK_FILE_CHOOSER_DEFAULT (data);
4711 g_assert (model == GTK_TREE_MODEL (impl->shortcuts_model));
4713 tree_path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), iter);
4714 g_assert (tree_path != NULL);
4716 indices = gtk_tree_path_get_indices (tree_path);
4720 if (impl->has_search)
4722 idx = shortcuts_get_index (impl, SHORTCUTS_SEARCH);
4723 if (idx == indices[0])
4727 if (impl->has_recent)
4729 idx = shortcuts_get_index (impl, SHORTCUTS_RECENT);
4730 if (idx == indices[0])
4734 idx = shortcuts_get_index (impl, SHORTCUTS_RECENT_SEPARATOR);
4735 if (idx == indices[0])
4740 gtk_tree_path_free (tree_path);
4745 /* Creates the combo box with the save folders */
4747 save_folder_combo_create (GtkFileChooserDefault *impl)
4750 GtkCellRenderer *cell;
4752 impl->shortcuts_combo_filter_model = gtk_tree_model_filter_new (GTK_TREE_MODEL (impl->shortcuts_model), NULL);
4753 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (impl->shortcuts_combo_filter_model),
4754 shortcuts_combo_filter_func,
4758 combo = g_object_new (GTK_TYPE_COMBO_BOX,
4759 "model", impl->shortcuts_combo_filter_model,
4760 "focus-on-click", FALSE,
4762 gtk_widget_show (combo);
4764 cell = gtk_cell_renderer_pixbuf_new ();
4765 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, FALSE);
4766 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), cell,
4767 "pixbuf", SHORTCUTS_COL_PIXBUF,
4768 "visible", SHORTCUTS_COL_PIXBUF_VISIBLE,
4769 "sensitive", SHORTCUTS_COL_PIXBUF_VISIBLE,
4772 cell = gtk_cell_renderer_text_new ();
4773 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE);
4774 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), cell,
4775 "text", SHORTCUTS_COL_NAME,
4776 "sensitive", SHORTCUTS_COL_PIXBUF_VISIBLE,
4779 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo),
4780 shortcuts_row_separator_func,
4783 g_signal_connect (combo, "changed",
4784 G_CALLBACK (save_folder_combo_changed_cb), impl);
4789 /* Creates the widgets specific to Save mode */
4791 save_widgets_create (GtkFileChooserDefault *impl)
4796 GtkWidget *alignment;
4798 if (impl->save_widgets != NULL)
4801 location_switch_to_path_bar (impl);
4803 vbox = gtk_vbox_new (FALSE, 12);
4805 table = gtk_table_new (2, 2, FALSE);
4806 gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
4807 gtk_widget_show (table);
4808 gtk_table_set_row_spacings (GTK_TABLE (table), 12);
4809 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
4813 widget = gtk_label_new_with_mnemonic (_("_Name:"));
4814 gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
4815 gtk_table_attach (GTK_TABLE (table), widget,
4819 gtk_widget_show (widget);
4821 /* Location entry */
4823 impl->location_entry = _gtk_file_chooser_entry_new (TRUE);
4824 _gtk_file_chooser_entry_set_file_system (GTK_FILE_CHOOSER_ENTRY (impl->location_entry),
4826 gtk_entry_set_width_chars (GTK_ENTRY (impl->location_entry), 45);
4827 gtk_entry_set_activates_default (GTK_ENTRY (impl->location_entry), TRUE);
4828 gtk_table_attach (GTK_TABLE (table), impl->location_entry,
4830 GTK_EXPAND | GTK_FILL, 0,
4832 gtk_widget_show (impl->location_entry);
4833 gtk_label_set_mnemonic_widget (GTK_LABEL (widget), impl->location_entry);
4836 impl->save_folder_label = gtk_label_new (NULL);
4837 gtk_misc_set_alignment (GTK_MISC (impl->save_folder_label), 0.0, 0.5);
4838 gtk_table_attach (GTK_TABLE (table), impl->save_folder_label,
4842 gtk_widget_show (impl->save_folder_label);
4844 impl->save_folder_combo = save_folder_combo_create (impl);
4845 gtk_table_attach (GTK_TABLE (table), impl->save_folder_combo,
4847 GTK_EXPAND | GTK_FILL, GTK_FILL,
4849 gtk_label_set_mnemonic_widget (GTK_LABEL (impl->save_folder_label), impl->save_folder_combo);
4852 alignment = gtk_alignment_new (0.0, 0.5, 1.0, 1.0);
4853 gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0);
4855 impl->save_expander = gtk_expander_new_with_mnemonic (_("_Browse for other folders"));
4856 gtk_container_add (GTK_CONTAINER (alignment), impl->save_expander);
4857 g_signal_connect (impl->save_expander, "notify::expanded",
4858 G_CALLBACK (expander_changed_cb),
4860 gtk_widget_show_all (alignment);
4862 impl->save_widgets = vbox;
4863 gtk_box_pack_start (GTK_BOX (impl), impl->save_widgets, FALSE, FALSE, 0);
4864 gtk_box_reorder_child (GTK_BOX (impl), impl->save_widgets, 0);
4865 gtk_widget_show (impl->save_widgets);
4868 /* Destroys the widgets specific to Save mode */
4870 save_widgets_destroy (GtkFileChooserDefault *impl)
4872 if (impl->save_widgets == NULL)
4875 gtk_widget_destroy (impl->save_widgets);
4876 impl->save_widgets = NULL;
4877 impl->location_entry = NULL;
4878 impl->save_folder_label = NULL;
4879 impl->save_folder_combo = NULL;
4880 impl->save_expander = NULL;
4883 /* Turns on the path bar widget. Can be called even if we are already in that
4887 location_switch_to_path_bar (GtkFileChooserDefault *impl)
4889 if (impl->location_entry)
4891 gtk_widget_destroy (impl->location_entry);
4892 impl->location_entry = NULL;
4895 gtk_widget_hide (impl->location_entry_box);
4898 /* Sets the full path of the current folder as the text in the location entry. */
4900 location_entry_set_initial_text (GtkFileChooserDefault *impl)
4904 if (!impl->current_folder)
4907 if (gtk_file_system_path_is_local (impl->file_system, impl->current_folder))
4911 filename = gtk_file_system_path_to_filename (impl->file_system, impl->current_folder);
4914 text = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
4921 text = gtk_file_system_path_to_uri (impl->file_system, impl->current_folder);
4925 gboolean need_slash;
4928 len = strlen (text);
4929 need_slash = (text[len - 1] != G_DIR_SEPARATOR);
4935 slash_text = g_new (char, len + 2);
4936 strcpy (slash_text, text);
4937 slash_text[len] = G_DIR_SEPARATOR;
4938 slash_text[len + 1] = 0;
4944 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), text);
4949 /* Turns on the location entry. Can be called even if we are already in that
4953 location_switch_to_filename_entry (GtkFileChooserDefault *impl)
4955 /* when in search or recent files mode, we are not showing the
4956 * location_entry_box container, so there's no point in switching
4959 if (impl->operation_mode == OPERATION_MODE_SEARCH ||
4960 impl->operation_mode == OPERATION_MODE_RECENT)
4963 if (impl->location_entry)
4964 gtk_widget_destroy (impl->location_entry);
4968 gtk_widget_show (impl->location_entry_box);
4972 impl->location_entry = _gtk_file_chooser_entry_new (TRUE);
4973 _gtk_file_chooser_entry_set_file_system (GTK_FILE_CHOOSER_ENTRY (impl->location_entry),
4975 gtk_entry_set_activates_default (GTK_ENTRY (impl->location_entry), TRUE);
4976 _gtk_file_chooser_entry_set_action (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->action);
4978 gtk_box_pack_start (GTK_BOX (impl->location_entry_box), impl->location_entry, TRUE, TRUE, 0);
4979 gtk_label_set_mnemonic_widget (GTK_LABEL (impl->location_label), impl->location_entry);
4981 /* Configure the entry */
4983 _gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->current_folder);
4987 gtk_widget_show (impl->location_entry);
4988 gtk_widget_grab_focus (impl->location_entry);
4991 /* Sets a new location mode. set_buttons determines whether the toggle button
4992 * for the mode will also be changed.
4995 location_mode_set (GtkFileChooserDefault *impl,
4996 LocationMode new_mode,
4997 gboolean set_button)
4999 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
5000 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
5002 GtkWindow *toplevel;
5003 GtkWidget *current_focus;
5004 gboolean button_active;
5005 gboolean switch_to_file_list;
5009 case LOCATION_MODE_PATH_BAR:
5010 button_active = FALSE;
5012 /* The location_entry will disappear when we switch to path bar mode. So,
5013 * we'll focus the file list in that case, to avoid having a window with
5014 * no focused widget.
5016 toplevel = get_toplevel (GTK_WIDGET (impl));
5017 switch_to_file_list = FALSE;
5020 current_focus = gtk_window_get_focus (toplevel);
5021 if (!current_focus || current_focus == impl->location_entry)
5022 switch_to_file_list = TRUE;
5025 location_switch_to_path_bar (impl);
5027 if (switch_to_file_list)
5028 gtk_widget_grab_focus (impl->browse_files_tree_view);
5032 case LOCATION_MODE_FILENAME_ENTRY:
5033 button_active = TRUE;
5034 location_switch_to_filename_entry (impl);
5038 g_assert_not_reached ();
5044 g_signal_handlers_block_by_func (impl->location_button,
5045 G_CALLBACK (location_button_toggled_cb), impl);
5047 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->location_button), button_active);
5049 g_signal_handlers_unblock_by_func (impl->location_button,
5050 G_CALLBACK (location_button_toggled_cb), impl);
5054 impl->location_mode = new_mode;
5058 toggle_location_mode (GtkFileChooserDefault *impl,
5059 gboolean set_button)
5061 LocationMode new_mode;
5064 new_mode = (impl->location_mode == LOCATION_MODE_PATH_BAR) ?
5065 LOCATION_MODE_FILENAME_ENTRY : LOCATION_MODE_PATH_BAR;
5067 location_mode_set (impl, new_mode, set_button);
5071 location_toggle_popup_handler (GtkFileChooserDefault *impl)
5073 toggle_location_mode (impl, TRUE);
5076 /* Callback used when one of the location mode buttons is toggled */
5078 location_button_toggled_cb (GtkToggleButton *toggle,
5079 GtkFileChooserDefault *impl)
5083 is_active = gtk_toggle_button_get_active (toggle);
5086 g_assert (impl->location_mode == LOCATION_MODE_PATH_BAR);
5088 g_assert (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY);
5090 toggle_location_mode (impl, FALSE);
5093 /* Creates a toggle button for the location entry. */
5095 location_button_create (GtkFileChooserDefault *impl)
5100 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_BUTTON);
5101 gtk_widget_show (image);
5103 impl->location_button = g_object_new (GTK_TYPE_TOGGLE_BUTTON,
5107 g_signal_connect (impl->location_button, "toggled",
5108 G_CALLBACK (location_button_toggled_cb), impl);
5110 str = _("Type a file name");
5112 gtk_tooltips_set_tip (impl->tooltips, impl->location_button, str, NULL);
5113 atk_object_set_name (gtk_widget_get_accessible (impl->location_button), str);
5116 /* Creates the main hpaned with the widgets shared by Open and Save mode */
5118 browse_widgets_create (GtkFileChooserDefault *impl)
5124 GtkSizeGroup *size_group;
5126 /* size group is used by the [+][-] buttons and the filter combo */
5127 size_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
5128 vbox = gtk_vbox_new (FALSE, 12);
5130 /* Location widgets */
5131 hbox = gtk_hbox_new (FALSE, 12);
5132 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
5133 gtk_widget_show (hbox);
5134 impl->browse_path_bar_hbox = hbox;
5136 location_button_create (impl);
5137 gtk_box_pack_start (GTK_BOX (hbox), impl->location_button, FALSE, FALSE, 0);
5141 impl->browse_path_bar = create_path_bar (impl);
5142 g_signal_connect (impl->browse_path_bar, "path-clicked", G_CALLBACK (path_bar_clicked), impl);
5143 gtk_widget_show_all (impl->browse_path_bar);
5144 gtk_box_pack_start (GTK_BOX (hbox), impl->browse_path_bar, TRUE, TRUE, 0);
5147 impl->browse_new_folder_button = gtk_button_new_with_mnemonic (_("Create Fo_lder"));
5148 g_signal_connect (impl->browse_new_folder_button, "clicked",
5149 G_CALLBACK (new_folder_button_clicked), impl);
5150 gtk_box_pack_end (GTK_BOX (hbox), impl->browse_new_folder_button, FALSE, FALSE, 0);
5152 /* Box for the location label and entry */
5154 impl->location_entry_box = gtk_hbox_new (FALSE, 12);
5155 gtk_box_pack_start (GTK_BOX (vbox), impl->location_entry_box, FALSE, FALSE, 0);
5157 impl->location_label = gtk_label_new_with_mnemonic (_("_Location:"));
5158 gtk_widget_show (impl->location_label);
5159 gtk_box_pack_start (GTK_BOX (impl->location_entry_box), impl->location_label, FALSE, FALSE, 0);
5162 hpaned = gtk_hpaned_new ();
5163 gtk_widget_show (hpaned);
5164 gtk_box_pack_start (GTK_BOX (vbox), hpaned, TRUE, TRUE, 0);
5166 widget = shortcuts_pane_create (impl, size_group);
5167 gtk_paned_pack1 (GTK_PANED (hpaned), widget, FALSE, FALSE);
5168 widget = file_pane_create (impl, size_group);
5169 gtk_paned_pack2 (GTK_PANED (hpaned), widget, TRUE, FALSE);
5171 g_object_unref (size_group);
5177 gtk_file_chooser_default_constructor (GType type,
5178 guint n_construct_properties,
5179 GObjectConstructParam *construct_params)
5181 GtkFileChooserDefault *impl;
5184 profile_start ("start", NULL);
5186 object = G_OBJECT_CLASS (_gtk_file_chooser_default_parent_class)->constructor (type,
5187 n_construct_properties,
5189 impl = GTK_FILE_CHOOSER_DEFAULT (object);
5191 g_assert (impl->file_system);
5193 gtk_widget_push_composite_child ();
5195 /* Recent files manager */
5196 recent_manager_update (impl);
5198 /* Shortcuts model */
5199 shortcuts_model_create (impl);
5201 /* The browse widgets */
5202 impl->browse_widgets = browse_widgets_create (impl);
5203 gtk_box_pack_start (GTK_BOX (impl), impl->browse_widgets, TRUE, TRUE, 0);
5205 /* Alignment to hold extra widget */
5206 impl->extra_align = gtk_alignment_new (0.0, 0.5, 1.0, 1.0);
5207 gtk_box_pack_start (GTK_BOX (impl), impl->extra_align, FALSE, FALSE, 0);
5209 gtk_widget_pop_composite_child ();
5210 update_appearance (impl);
5212 profile_end ("end", NULL);
5217 /* Sets the extra_widget by packing it in the appropriate place */
5219 set_extra_widget (GtkFileChooserDefault *impl,
5220 GtkWidget *extra_widget)
5224 g_object_ref (extra_widget);
5225 /* FIXME: is this right ? */
5226 gtk_widget_show (extra_widget);
5229 if (impl->extra_widget)
5231 gtk_container_remove (GTK_CONTAINER (impl->extra_align), impl->extra_widget);
5232 g_object_unref (impl->extra_widget);
5235 impl->extra_widget = extra_widget;
5236 if (impl->extra_widget)
5238 gtk_container_add (GTK_CONTAINER (impl->extra_align), impl->extra_widget);
5239 gtk_widget_show (impl->extra_align);
5242 gtk_widget_hide (impl->extra_align);
5246 set_local_only (GtkFileChooserDefault *impl,
5247 gboolean local_only)
5249 if (local_only != impl->local_only)
5251 impl->local_only = local_only;
5253 if (impl->shortcuts_model && impl->file_system)
5255 shortcuts_add_volumes (impl);
5256 shortcuts_add_bookmarks (impl);
5260 !gtk_file_system_path_is_local (impl->file_system, impl->current_folder))
5262 /* If we are pointing to a non-local folder, make an effort to change
5263 * back to a local folder, but it's really up to the app to not cause
5264 * such a situation, so we ignore errors.
5266 const gchar *home = g_get_home_dir ();
5267 GtkFilePath *home_path;
5272 home_path = gtk_file_system_filename_to_path (impl->file_system, home);
5274 _gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (impl), home_path, NULL);
5276 gtk_file_path_free (home_path);
5282 volumes_changed_cb (GtkFileSystem *file_system,
5283 GtkFileChooserDefault *impl)
5285 shortcuts_add_volumes (impl);
5288 /* Callback used when the set of bookmarks changes in the file system */
5290 bookmarks_changed_cb (GtkFileSystem *file_system,
5291 GtkFileChooserDefault *impl)
5293 shortcuts_add_bookmarks (impl);
5295 bookmarks_check_add_sensitivity (impl);
5296 bookmarks_check_remove_sensitivity (impl);
5297 shortcuts_check_popup_sensitivity (impl);
5300 /* Sets the file chooser to multiple selection mode */
5302 set_select_multiple (GtkFileChooserDefault *impl,
5303 gboolean select_multiple,
5304 gboolean property_notify)
5306 GtkTreeSelection *selection;
5307 GtkSelectionMode mode;
5309 if (select_multiple == impl->select_multiple)
5312 mode = select_multiple ? GTK_SELECTION_MULTIPLE : GTK_SELECTION_BROWSE;
5314 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
5315 gtk_tree_selection_set_mode (selection, mode);
5317 impl->select_multiple = select_multiple;
5318 g_object_notify (G_OBJECT (impl), "select-multiple");
5320 check_preview_change (impl);
5324 set_file_system_backend (GtkFileChooserDefault *impl,
5325 const char *backend)
5327 profile_start ("start for backend", backend ? backend : "default");
5329 if (impl->file_system)
5331 g_signal_handler_disconnect (impl->file_system, impl->volumes_changed_id);
5332 impl->volumes_changed_id = 0;
5333 g_signal_handler_disconnect (impl->file_system, impl->bookmarks_changed_id);
5334 impl->bookmarks_changed_id = 0;
5335 g_object_unref (impl->file_system);
5338 impl->file_system = NULL;
5340 impl->file_system = _gtk_file_system_create (backend);
5343 GtkSettings *settings = gtk_settings_get_default ();
5344 gchar *default_backend = NULL;
5346 g_object_get (settings, "gtk-file-chooser-backend", &default_backend, NULL);
5347 if (default_backend)
5349 impl->file_system = _gtk_file_system_create (default_backend);
5350 g_free (default_backend);
5354 if (!impl->file_system)
5356 #if defined (G_OS_UNIX)
5357 impl->file_system = gtk_file_system_unix_new ();
5358 #elif defined (G_OS_WIN32)
5359 impl->file_system = gtk_file_system_win32_new ();
5361 #error "No default filesystem implementation on the platform"
5365 if (impl->file_system)
5367 impl->volumes_changed_id = g_signal_connect (impl->file_system, "volumes-changed",
5368 G_CALLBACK (volumes_changed_cb),
5370 impl->bookmarks_changed_id = g_signal_connect (impl->file_system, "bookmarks-changed",
5371 G_CALLBACK (bookmarks_changed_cb),
5375 profile_end ("end", NULL);
5378 /* This function is basically a do_all function.
5380 * It sets the visibility on all the widgets based on the current state, and
5381 * moves the custom_widget if needed.
5384 update_appearance (GtkFileChooserDefault *impl)
5386 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
5387 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
5391 gtk_widget_hide (impl->location_button);
5392 save_widgets_create (impl);
5394 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
5395 text = _("Save in _folder:");
5397 text = _("Create in _folder:");
5399 gtk_label_set_text_with_mnemonic (GTK_LABEL (impl->save_folder_label), text);
5401 if (gtk_expander_get_expanded (GTK_EXPANDER (impl->save_expander)))
5403 gtk_widget_set_sensitive (impl->save_folder_label, FALSE);
5404 gtk_widget_set_sensitive (impl->save_folder_combo, FALSE);
5405 gtk_widget_show (impl->browse_widgets);
5409 gtk_widget_set_sensitive (impl->save_folder_label, TRUE);
5410 gtk_widget_set_sensitive (impl->save_folder_combo, TRUE);
5411 gtk_widget_hide (impl->browse_widgets);
5414 gtk_widget_show (impl->browse_new_folder_button);
5416 if (impl->select_multiple)
5418 g_warning ("Save mode cannot be set in conjunction with multiple selection mode. "
5419 "Re-setting to single selection mode.");
5420 set_select_multiple (impl, FALSE, TRUE);
5423 else if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
5424 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
5426 gtk_widget_show (impl->location_button);
5427 save_widgets_destroy (impl);
5428 gtk_widget_show (impl->browse_widgets);
5429 location_mode_set (impl, impl->location_mode, TRUE);
5432 if (impl->location_entry)
5433 _gtk_file_chooser_entry_set_action (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->action);
5435 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
5436 gtk_widget_hide (impl->browse_new_folder_button);
5438 gtk_widget_show (impl->browse_new_folder_button);
5440 /* This *is* needed; we need to redraw the file list because the "sensitivity"
5441 * of files may change depending whether we are in a file or folder-only mode.
5443 gtk_widget_queue_draw (impl->browse_files_tree_view);
5445 g_signal_emit_by_name (impl, "default-size-changed");
5449 gtk_file_chooser_default_set_property (GObject *object,
5451 const GValue *value,
5455 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (object);
5459 case GTK_FILE_CHOOSER_PROP_ACTION:
5461 GtkFileChooserAction action = g_value_get_enum (value);
5463 if (action != impl->action)
5465 gtk_file_chooser_default_unselect_all (GTK_FILE_CHOOSER (impl));
5467 if ((action == GTK_FILE_CHOOSER_ACTION_SAVE ||
5468 action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
5469 && impl->select_multiple)
5471 g_warning ("Tried to change the file chooser action to SAVE or CREATE_FOLDER, but "
5472 "this is not allowed in multiple selection mode. Resetting the file chooser "
5473 "to single selection mode.");
5474 set_select_multiple (impl, FALSE, TRUE);
5476 impl->action = action;
5477 update_appearance (impl);
5478 settings_load (impl);
5483 case GTK_FILE_CHOOSER_PROP_FILE_SYSTEM_BACKEND:
5484 set_file_system_backend (impl, g_value_get_string (value));
5487 case GTK_FILE_CHOOSER_PROP_FILTER:
5488 set_current_filter (impl, g_value_get_object (value));
5491 case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
5492 set_local_only (impl, g_value_get_boolean (value));
5495 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
5496 set_preview_widget (impl, g_value_get_object (value));
5499 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE:
5500 impl->preview_widget_active = g_value_get_boolean (value);
5501 update_preview_widget_visibility (impl);
5504 case GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL:
5505 impl->use_preview_label = g_value_get_boolean (value);
5506 update_preview_widget_visibility (impl);
5509 case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
5510 set_extra_widget (impl, g_value_get_object (value));
5513 case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
5515 gboolean select_multiple = g_value_get_boolean (value);
5516 if ((impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
5517 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
5520 g_warning ("Tried to set the file chooser to multiple selection mode, but this is "
5521 "not allowed in SAVE or CREATE_FOLDER modes. Ignoring the change and "
5522 "leaving the file chooser in single selection mode.");
5526 set_select_multiple (impl, select_multiple, FALSE);
5530 case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN:
5532 gboolean show_hidden = g_value_get_boolean (value);
5533 if (show_hidden != impl->show_hidden)
5535 impl->show_hidden = show_hidden;
5537 if (impl->browse_files_model)
5538 _gtk_file_system_model_set_show_hidden (impl->browse_files_model, show_hidden);
5543 case GTK_FILE_CHOOSER_PROP_DO_OVERWRITE_CONFIRMATION:
5545 gboolean do_overwrite_confirmation = g_value_get_boolean (value);
5546 impl->do_overwrite_confirmation = do_overwrite_confirmation;
5551 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
5557 gtk_file_chooser_default_get_property (GObject *object,
5562 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (object);
5566 case GTK_FILE_CHOOSER_PROP_ACTION:
5567 g_value_set_enum (value, impl->action);
5570 case GTK_FILE_CHOOSER_PROP_FILTER:
5571 g_value_set_object (value, impl->current_filter);
5574 case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
5575 g_value_set_boolean (value, impl->local_only);
5578 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
5579 g_value_set_object (value, impl->preview_widget);
5582 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE:
5583 g_value_set_boolean (value, impl->preview_widget_active);
5586 case GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL:
5587 g_value_set_boolean (value, impl->use_preview_label);
5590 case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
5591 g_value_set_object (value, impl->extra_widget);
5594 case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
5595 g_value_set_boolean (value, impl->select_multiple);
5598 case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN:
5599 g_value_set_boolean (value, impl->show_hidden);
5602 case GTK_FILE_CHOOSER_PROP_DO_OVERWRITE_CONFIRMATION:
5603 g_value_set_boolean (value, impl->do_overwrite_confirmation);
5607 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
5612 /* Removes the settings signal handler. It's safe to call multiple times */
5614 remove_settings_signal (GtkFileChooserDefault *impl,
5617 if (impl->settings_signal_id)
5619 GtkSettings *settings;
5621 settings = gtk_settings_get_for_screen (screen);
5622 g_signal_handler_disconnect (settings,
5623 impl->settings_signal_id);
5624 impl->settings_signal_id = 0;
5629 gtk_file_chooser_default_dispose (GObject *object)
5632 GtkFileChooserDefault *impl = (GtkFileChooserDefault *) object;
5634 if (impl->extra_widget)
5636 g_object_unref (impl->extra_widget);
5637 impl->extra_widget = NULL;
5640 if (impl->volumes_changed_id > 0)
5642 g_signal_handler_disconnect (impl->file_system, impl->volumes_changed_id);
5643 impl->volumes_changed_id = 0;
5646 if (impl->bookmarks_changed_id > 0)
5648 g_signal_handler_disconnect (impl->file_system, impl->bookmarks_changed_id);
5649 impl->bookmarks_changed_id = 0;
5652 pending_select_paths_free (impl);
5654 /* cancel all pending operations */
5655 if (impl->pending_handles)
5657 for (l = impl->pending_handles; l; l = l->next)
5659 GtkFileSystemHandle *handle =l->data;
5660 gtk_file_system_cancel_operation (handle);
5662 g_slist_free (impl->pending_handles);
5663 impl->pending_handles = NULL;
5666 if (impl->reload_icon_handles)
5668 for (l = impl->reload_icon_handles; l; l = l->next)
5670 GtkFileSystemHandle *handle =l->data;
5671 gtk_file_system_cancel_operation (handle);
5673 g_slist_free (impl->reload_icon_handles);
5674 impl->reload_icon_handles = NULL;
5677 if (impl->loading_shortcuts)
5679 for (l = impl->loading_shortcuts; l; l = l->next)
5681 GtkFileSystemHandle *handle =l->data;
5682 gtk_file_system_cancel_operation (handle);
5684 g_slist_free (impl->loading_shortcuts);
5685 impl->loading_shortcuts = NULL;
5688 if (impl->file_list_drag_data_received_handle)
5690 gtk_file_system_cancel_operation (impl->file_list_drag_data_received_handle);
5691 impl->file_list_drag_data_received_handle = NULL;
5694 if (impl->update_current_folder_handle)
5696 gtk_file_system_cancel_operation (impl->update_current_folder_handle);
5697 impl->update_current_folder_handle = NULL;
5700 if (impl->show_and_select_paths_handle)
5702 gtk_file_system_cancel_operation (impl->show_and_select_paths_handle);
5703 impl->show_and_select_paths_handle = NULL;
5706 if (impl->should_respond_get_info_handle)
5708 gtk_file_system_cancel_operation (impl->should_respond_get_info_handle);
5709 impl->should_respond_get_info_handle = NULL;
5712 if (impl->update_from_entry_handle)
5714 gtk_file_system_cancel_operation (impl->update_from_entry_handle);
5715 impl->update_from_entry_handle = NULL;
5718 if (impl->shortcuts_activate_iter_handle)
5720 gtk_file_system_cancel_operation (impl->shortcuts_activate_iter_handle);
5721 impl->shortcuts_activate_iter_handle = NULL;
5724 search_stop_searching (impl, TRUE);
5725 recent_stop_loading (impl);
5727 remove_settings_signal (impl, gtk_widget_get_screen (GTK_WIDGET (impl)));
5729 G_OBJECT_CLASS (_gtk_file_chooser_default_parent_class)->dispose (object);
5732 /* We override show-all since we have internal widgets that
5733 * shouldn't be shown when you call show_all(), like the filter
5737 gtk_file_chooser_default_show_all (GtkWidget *widget)
5739 GtkFileChooserDefault *impl = (GtkFileChooserDefault *) widget;
5741 gtk_widget_show (widget);
5743 if (impl->extra_widget)
5744 gtk_widget_show_all (impl->extra_widget);
5747 /* Handler for GtkWindow::set-focus; this is where we save the last-focused
5748 * widget on our toplevel. See gtk_file_chooser_default_hierarchy_changed()
5751 toplevel_set_focus_cb (GtkWindow *window,
5753 GtkFileChooserDefault *impl)
5755 impl->toplevel_last_focus_widget = gtk_window_get_focus (window);
5758 /* We monitor the focus widget on our toplevel to be able to know which widget
5759 * was last focused at the time our "should_respond" method gets called.
5762 gtk_file_chooser_default_hierarchy_changed (GtkWidget *widget,
5763 GtkWidget *previous_toplevel)
5765 GtkFileChooserDefault *impl;
5766 GtkWidget *toplevel;
5768 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
5770 if (previous_toplevel)
5772 g_assert (impl->toplevel_set_focus_id != 0);
5773 g_signal_handler_disconnect (previous_toplevel, impl->toplevel_set_focus_id);
5774 impl->toplevel_set_focus_id = 0;
5775 impl->toplevel_last_focus_widget = NULL;
5778 g_assert (impl->toplevel_set_focus_id == 0);
5780 toplevel = gtk_widget_get_toplevel (widget);
5781 if (GTK_IS_WINDOW (toplevel))
5783 impl->toplevel_set_focus_id = g_signal_connect (toplevel, "set_focus",
5784 G_CALLBACK (toplevel_set_focus_cb), impl);
5785 impl->toplevel_last_focus_widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
5789 /* Changes the icons wherever it is needed */
5791 change_icon_theme (GtkFileChooserDefault *impl)
5793 GtkSettings *settings;
5796 profile_start ("start", NULL);
5798 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl)));
5800 if (gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &width, &height))
5801 impl->icon_size = MAX (width, height);
5803 impl->icon_size = FALLBACK_ICON_SIZE;
5805 shortcuts_reload_icons (impl);
5806 gtk_widget_queue_resize (impl->browse_files_tree_view);
5808 profile_end ("end", NULL);
5811 /* Callback used when a GtkSettings value changes */
5813 settings_notify_cb (GObject *object,
5815 GtkFileChooserDefault *impl)
5819 profile_start ("start", NULL);
5821 name = g_param_spec_get_name (pspec);
5823 if (strcmp (name, "gtk-icon-theme-name") == 0 ||
5824 strcmp (name, "gtk-icon-sizes") == 0)
5825 change_icon_theme (impl);
5827 profile_end ("end", NULL);
5830 /* Installs a signal handler for GtkSettings so that we can monitor changes in
5834 check_icon_theme (GtkFileChooserDefault *impl)
5836 GtkSettings *settings;
5838 profile_start ("start", NULL);
5840 if (impl->settings_signal_id)
5842 profile_end ("end", NULL);
5846 if (gtk_widget_has_screen (GTK_WIDGET (impl)))
5848 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl)));
5849 impl->settings_signal_id = g_signal_connect (settings, "notify",
5850 G_CALLBACK (settings_notify_cb), impl);
5852 change_icon_theme (impl);
5855 profile_end ("end", NULL);
5859 recent_manager_update (GtkFileChooserDefault *impl)
5861 GtkRecentManager *manager;
5863 profile_start ("start", NULL);
5865 if (gtk_widget_has_screen (GTK_WIDGET (impl)))
5866 manager = gtk_recent_manager_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl)));
5868 manager = gtk_recent_manager_get_default ();
5870 if (impl->recent_manager != manager)
5871 impl->recent_manager = manager;
5873 profile_end ("end", NULL);
5877 gtk_file_chooser_default_style_set (GtkWidget *widget,
5878 GtkStyle *previous_style)
5880 GtkFileChooserDefault *impl;
5882 profile_start ("start", NULL);
5884 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
5886 profile_msg (" parent class style_set start", NULL);
5887 if (GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->style_set)
5888 GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->style_set (widget, previous_style);
5889 profile_msg (" parent class style_set end", NULL);
5891 if (gtk_widget_has_screen (GTK_WIDGET (impl)))
5892 change_icon_theme (impl);
5894 profile_msg (" emit default-size-changed start", NULL);
5895 g_signal_emit_by_name (widget, "default-size-changed");
5896 profile_msg (" emit default-size-changed end", NULL);
5898 profile_end ("end", NULL);
5902 gtk_file_chooser_default_screen_changed (GtkWidget *widget,
5903 GdkScreen *previous_screen)
5905 GtkFileChooserDefault *impl;
5907 profile_start ("start", NULL);
5909 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
5911 if (GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->screen_changed)
5912 GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->screen_changed (widget, previous_screen);
5914 remove_settings_signal (impl, previous_screen);
5915 check_icon_theme (impl);
5916 recent_manager_update (impl);
5918 g_signal_emit_by_name (widget, "default-size-changed");
5920 profile_end ("end", NULL);
5924 gtk_file_chooser_default_size_allocate (GtkWidget *widget,
5925 GtkAllocation *allocation)
5927 GtkFileChooserDefault *impl;
5929 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
5931 GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->size_allocate (widget, allocation);
5933 if (!gtk_file_chooser_default_get_resizable (GTK_FILE_CHOOSER_EMBED (impl)))
5935 /* The dialog is not resizable, we shouldn't
5936 * trust in the size it has in this stage
5941 impl->default_width = allocation->width;
5942 impl->default_height = allocation->height;
5944 if (impl->preview_widget_active &&
5945 impl->preview_widget &&
5946 GTK_WIDGET_DRAWABLE (impl->preview_widget))
5947 impl->default_width -= impl->preview_widget->allocation.width + PREVIEW_HBOX_SPACING;
5949 if (impl->extra_widget &&
5950 GTK_WIDGET_DRAWABLE (impl->extra_widget))
5951 impl->default_height -= GTK_BOX (widget)->spacing + impl->extra_widget->allocation.height;
5955 get_is_file_filtered (GtkFileChooserDefault *impl,
5956 const GtkFilePath *path,
5957 GtkFileInfo *file_info)
5959 GtkFileFilterInfo filter_info;
5960 GtkFileFilterFlags needed;
5963 if (!impl->current_filter)
5966 filter_info.contains = GTK_FILE_FILTER_DISPLAY_NAME | GTK_FILE_FILTER_MIME_TYPE;
5968 needed = gtk_file_filter_get_needed (impl->current_filter);
5970 filter_info.display_name = gtk_file_info_get_display_name (file_info);
5971 filter_info.mime_type = gtk_file_info_get_mime_type (file_info);
5973 if (needed & GTK_FILE_FILTER_FILENAME)
5975 filter_info.filename = gtk_file_system_path_to_filename (impl->file_system, path);
5976 if (filter_info.filename)
5977 filter_info.contains |= GTK_FILE_FILTER_FILENAME;
5980 filter_info.filename = NULL;
5982 if (needed & GTK_FILE_FILTER_URI)
5984 filter_info.uri = gtk_file_system_path_to_uri (impl->file_system, path);
5985 if (filter_info.uri)
5986 filter_info.contains |= GTK_FILE_FILTER_URI;
5989 filter_info.uri = NULL;
5991 result = gtk_file_filter_filter (impl->current_filter, &filter_info);
5993 if (filter_info.filename)
5994 g_free ((gchar *)filter_info.filename);
5995 if (filter_info.uri)
5996 g_free ((gchar *)filter_info.uri);
6002 settings_load (GtkFileChooserDefault *impl)
6004 GtkFileChooserSettings *settings;
6005 LocationMode location_mode;
6006 gboolean show_hidden;
6007 gboolean expand_folders;
6009 settings = _gtk_file_chooser_settings_new ();
6011 location_mode = _gtk_file_chooser_settings_get_location_mode (settings);
6012 show_hidden = _gtk_file_chooser_settings_get_show_hidden (settings);
6013 expand_folders = _gtk_file_chooser_settings_get_expand_folders (settings);
6015 g_object_unref (settings);
6017 location_mode_set (impl, location_mode, TRUE);
6018 gtk_file_chooser_set_show_hidden (GTK_FILE_CHOOSER (impl), show_hidden);
6019 impl->expand_folders = expand_folders;
6020 if (impl->save_expander)
6021 gtk_expander_set_expanded (GTK_EXPANDER (impl->save_expander), expand_folders);
6025 settings_save (GtkFileChooserDefault *impl)
6027 GtkFileChooserSettings *settings;
6029 settings = _gtk_file_chooser_settings_new ();
6031 _gtk_file_chooser_settings_set_location_mode (settings, impl->location_mode);
6032 _gtk_file_chooser_settings_set_show_hidden (settings, gtk_file_chooser_get_show_hidden (GTK_FILE_CHOOSER (impl)));
6033 _gtk_file_chooser_settings_set_expand_folders (settings, impl->expand_folders);
6036 _gtk_file_chooser_settings_save (settings, NULL);
6038 g_object_unref (settings);
6041 /* GtkWidget::map method */
6043 gtk_file_chooser_default_map (GtkWidget *widget)
6045 GtkFileChooserDefault *impl;
6046 char *current_working_dir;
6048 profile_start ("start", NULL);
6050 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
6052 GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->map (widget);
6054 if (impl->operation_mode == OPERATION_MODE_BROWSE)
6056 switch (impl->reload_state)
6059 /* The user didn't explicitly give us a folder to
6060 * display, so we'll use the cwd
6062 current_working_dir = g_get_current_dir ();
6063 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl),
6064 current_working_dir);
6065 g_free (current_working_dir);
6068 case RELOAD_HAS_FOLDER:
6069 /* Nothing; we are already loading or loaded, so we
6070 * don't need to reload
6074 case RELOAD_WAS_UNMAPPED:
6075 /* Just reload the current folder; else continue
6078 if (impl->current_folder)
6080 pending_select_paths_store_selection (impl);
6081 change_folder_and_display_error (impl, impl->current_folder, FALSE);
6086 g_assert_not_reached ();
6090 bookmarks_changed_cb (impl->file_system, impl);
6092 settings_load (impl);
6094 profile_end ("end", NULL);
6097 /* GtkWidget::unmap method */
6099 gtk_file_chooser_default_unmap (GtkWidget *widget)
6101 GtkFileChooserDefault *impl;
6103 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
6105 settings_save (impl);
6107 GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->unmap (widget);
6109 impl->reload_state = RELOAD_WAS_UNMAPPED;
6113 list_model_filter_func (GtkFileSystemModel *model,
6115 const GtkFileInfo *file_info,
6118 GtkFileChooserDefault *impl = user_data;
6120 if (!impl->current_filter)
6123 if (gtk_file_info_get_is_folder (file_info))
6126 return !get_is_file_filtered (impl, path, (GtkFileInfo *) file_info);
6130 install_list_model_filter (GtkFileChooserDefault *impl)
6132 GtkFileSystemModelFilter filter;
6135 g_assert (impl->browse_files_model != NULL);
6137 if (impl->current_filter)
6139 filter = list_model_filter_func;
6148 _gtk_file_system_model_set_filter (impl->browse_files_model,
6153 #define COMPARE_DIRECTORIES \
6154 GtkFileChooserDefault *impl = user_data; \
6155 const GtkFileInfo *info_a = _gtk_file_system_model_get_info (impl->browse_files_model, a); \
6156 const GtkFileInfo *info_b = _gtk_file_system_model_get_info (impl->browse_files_model, b); \
6157 gboolean dir_a, dir_b; \
6160 dir_a = gtk_file_info_get_is_folder (info_a); \
6162 return impl->list_sort_ascending ? -1 : 1; \
6165 dir_b = gtk_file_info_get_is_folder (info_b); \
6167 return impl->list_sort_ascending ? 1 : -1; \
6169 if (dir_a != dir_b) \
6170 return impl->list_sort_ascending ? (dir_a ? -1 : 1) : (dir_a ? 1 : -1) /* Directories *always* go first */
6172 /* Sort callback for the filename column */
6174 name_sort_func (GtkTreeModel *model,
6179 COMPARE_DIRECTORIES;
6181 return strcmp (gtk_file_info_get_display_key (info_a), gtk_file_info_get_display_key (info_b));
6184 /* Sort callback for the size column */
6186 size_sort_func (GtkTreeModel *model,
6191 COMPARE_DIRECTORIES;
6194 gint64 size_a = gtk_file_info_get_size (info_a);
6195 gint64 size_b = gtk_file_info_get_size (info_b);
6197 return size_a > size_b ? -1 : (size_a == size_b ? 0 : 1);
6201 /* Sort callback for the mtime column */
6203 mtime_sort_func (GtkTreeModel *model,
6208 COMPARE_DIRECTORIES;
6211 GtkFileTime ta = gtk_file_info_get_modification_time (info_a);
6212 GtkFileTime tb = gtk_file_info_get_modification_time (info_b);
6214 return ta > tb ? -1 : (ta == tb ? 0 : 1);
6218 /* Callback used when the sort column changes. We cache the sort order for use
6219 * in name_sort_func().
6222 list_sort_column_changed_cb (GtkTreeSortable *sortable,
6223 GtkFileChooserDefault *impl)
6225 GtkSortType sort_type;
6227 if (gtk_tree_sortable_get_sort_column_id (sortable, NULL, &sort_type))
6228 impl->list_sort_ascending = (sort_type == GTK_SORT_ASCENDING);
6232 set_busy_cursor (GtkFileChooserDefault *impl,
6235 GtkWindow *toplevel;
6236 GdkDisplay *display;
6239 toplevel = get_toplevel (GTK_WIDGET (impl));
6240 if (!toplevel || !GTK_WIDGET_REALIZED (toplevel))
6243 display = gtk_widget_get_display (GTK_WIDGET (toplevel));
6246 cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
6250 gdk_window_set_cursor (GTK_WIDGET (toplevel)->window, cursor);
6251 gdk_display_flush (display);
6254 gdk_cursor_unref (cursor);
6257 /* Creates a sort model to wrap the file system model and sets it on the tree view */
6259 load_set_model (GtkFileChooserDefault *impl)
6261 profile_start ("start", NULL);
6263 g_assert (impl->browse_files_model != NULL);
6264 g_assert (impl->sort_model == NULL);
6266 profile_msg (" gtk_tree_model_sort_new_with_model start", NULL);
6267 impl->sort_model = (GtkTreeModelSort *)gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (impl->browse_files_model));
6268 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_NAME, name_sort_func, impl, NULL);
6269 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_SIZE, size_sort_func, impl, NULL);
6270 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_MTIME, mtime_sort_func, impl, NULL);
6271 gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (impl->sort_model), NULL, NULL, NULL);
6272 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_NAME, GTK_SORT_ASCENDING);
6273 impl->list_sort_ascending = TRUE;
6274 profile_msg (" gtk_tree_model_sort_new_with_model end", NULL);
6276 g_signal_connect (impl->sort_model, "sort_column_changed",
6277 G_CALLBACK (list_sort_column_changed_cb), impl);
6279 profile_msg (" gtk_tree_view_set_model start", NULL);
6280 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view),
6281 GTK_TREE_MODEL (impl->sort_model));
6282 gtk_tree_view_columns_autosize (GTK_TREE_VIEW (impl->browse_files_tree_view));
6283 gtk_tree_view_set_search_column (GTK_TREE_VIEW (impl->browse_files_tree_view),
6284 GTK_FILE_SYSTEM_MODEL_DISPLAY_NAME);
6285 profile_msg (" gtk_tree_view_set_model end", NULL);
6287 profile_end ("end", NULL);
6290 /* Timeout callback used when the loading timer expires */
6292 load_timeout_cb (gpointer data)
6294 GtkFileChooserDefault *impl;
6296 profile_start ("start", NULL);
6298 impl = GTK_FILE_CHOOSER_DEFAULT (data);
6299 g_assert (impl->load_state == LOAD_PRELOAD);
6300 g_assert (impl->load_timeout_id != 0);
6301 g_assert (impl->browse_files_model != NULL);
6303 impl->load_timeout_id = 0;
6304 impl->load_state = LOAD_LOADING;
6306 load_set_model (impl);
6308 profile_end ("end", NULL);
6313 /* Sets up a new load timer for the model and switches to the LOAD_PRELOAD state */
6315 load_setup_timer (GtkFileChooserDefault *impl)
6317 g_assert (impl->load_timeout_id == 0);
6318 g_assert (impl->load_state != LOAD_PRELOAD);
6320 impl->load_timeout_id = gdk_threads_add_timeout (MAX_LOADING_TIME, load_timeout_cb, impl);
6321 impl->load_state = LOAD_PRELOAD;
6324 /* Removes the load timeout and switches to the LOAD_FINISHED state */
6326 load_remove_timer (GtkFileChooserDefault *impl)
6328 if (impl->load_timeout_id != 0)
6330 g_assert (impl->load_state == LOAD_PRELOAD);
6332 g_source_remove (impl->load_timeout_id);
6333 impl->load_timeout_id = 0;
6334 impl->load_state = LOAD_EMPTY;
6337 g_assert (impl->load_state == LOAD_EMPTY ||
6338 impl->load_state == LOAD_LOADING ||
6339 impl->load_state == LOAD_FINISHED);
6342 /* Selects the first row in the file list */
6344 browse_files_select_first_row (GtkFileChooserDefault *impl)
6348 if (!impl->sort_model)
6351 path = gtk_tree_path_new_from_indices (0, -1);
6352 gtk_tree_view_set_cursor (GTK_TREE_VIEW (impl->browse_files_tree_view), path, NULL, FALSE);
6353 gtk_tree_path_free (path);
6356 struct center_selected_row_closure {
6357 GtkFileChooserDefault *impl;
6358 gboolean already_centered;
6361 /* Callback used from gtk_tree_selection_selected_foreach(); centers the
6362 * selected row in the tree view.
6365 center_selected_row_foreach_cb (GtkTreeModel *model,
6370 struct center_selected_row_closure *closure;
6373 if (closure->already_centered)
6376 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (closure->impl->browse_files_tree_view), path, NULL, TRUE, 0.5, 0.0);
6377 closure->already_centered = TRUE;
6380 /* Centers the selected row in the tree view */
6382 browse_files_center_selected_row (GtkFileChooserDefault *impl)
6384 struct center_selected_row_closure closure;
6385 GtkTreeSelection *selection;
6387 closure.impl = impl;
6388 closure.already_centered = FALSE;
6390 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
6391 gtk_tree_selection_selected_foreach (selection, center_selected_row_foreach_cb, &closure);
6394 struct ShowAndSelectPathsData
6396 GtkFileChooserDefault *impl;
6401 show_and_select_paths_finished_loading (GtkFileFolder *folder,
6404 gboolean have_hidden;
6405 gboolean have_filtered;
6407 struct ShowAndSelectPathsData *data = user_data;
6409 have_hidden = FALSE;
6410 have_filtered = FALSE;
6412 for (l = data->paths; l; l = l->next)
6414 const GtkFilePath *path;
6420 info = gtk_file_folder_get_info (folder, path, NULL);
6424 have_hidden = gtk_file_info_get_is_hidden (info);
6427 have_filtered = !gtk_file_info_get_is_folder (info) && get_is_file_filtered (data->impl, path, info);
6429 gtk_file_info_free (info);
6431 if (have_hidden && have_filtered)
6432 break; /* we now have all the information we need */
6436 g_signal_handlers_disconnect_by_func (folder,
6437 show_and_select_paths_finished_loading,
6440 g_object_unref (folder);
6443 g_object_set (data->impl, "show-hidden", TRUE, NULL);
6446 set_current_filter (data->impl, NULL);
6448 for (l = data->paths; l; l = l->next)
6450 const GtkFilePath *path;
6453 _gtk_file_system_model_path_do (data->impl->browse_files_model, path,
6454 select_func, data->impl);
6457 browse_files_center_selected_row (data->impl);
6459 g_object_unref (data->impl);
6460 gtk_file_paths_free (data->paths);
6465 show_and_select_paths_get_folder_cb (GtkFileSystemHandle *handle,
6466 GtkFileFolder *folder,
6467 const GError *error,
6470 gboolean cancelled = handle->cancelled;
6471 struct ShowAndSelectPathsData *data = user_data;
6473 if (data->impl->show_and_select_paths_handle != handle)
6476 data->impl->show_and_select_paths_handle = NULL;
6478 if (cancelled || error)
6481 g_object_unref (handle);
6483 if (gtk_file_folder_is_finished_loading (folder))
6484 show_and_select_paths_finished_loading (folder, user_data);
6486 g_signal_connect (folder, "finished-loading",
6487 G_CALLBACK (show_and_select_paths_finished_loading),
6493 g_object_unref (data->impl);
6494 gtk_file_paths_free (data->paths);
6497 g_object_unref (handle);
6501 show_and_select_paths (GtkFileChooserDefault *impl,
6502 const GtkFilePath *parent_path,
6506 struct ShowAndSelectPathsData *info;
6508 profile_start ("start", NULL);
6512 profile_end ("end", NULL);
6516 info = g_new (struct ShowAndSelectPathsData, 1);
6517 info->impl = g_object_ref (impl);
6518 info->paths = gtk_file_paths_copy (paths);
6520 if (impl->show_and_select_paths_handle)
6521 gtk_file_system_cancel_operation (impl->show_and_select_paths_handle);
6523 impl->show_and_select_paths_handle =
6524 gtk_file_system_get_folder (impl->file_system, parent_path,
6525 GTK_FILE_INFO_IS_FOLDER | GTK_FILE_INFO_IS_HIDDEN,
6526 show_and_select_paths_get_folder_cb, info);
6528 profile_end ("end", NULL);
6532 /* Processes the pending operation when a folder is finished loading */
6534 pending_select_paths_process (GtkFileChooserDefault *impl)
6536 g_assert (impl->load_state == LOAD_FINISHED);
6537 g_assert (impl->browse_files_model != NULL);
6538 g_assert (impl->sort_model != NULL);
6540 if (impl->pending_select_paths)
6543 show_and_select_paths (impl, impl->current_folder, impl->pending_select_paths, NULL);
6544 pending_select_paths_free (impl);
6545 browse_files_center_selected_row (impl);
6549 /* We only select the first row if the chooser is actually mapped ---
6550 * selecting the first row is to help the user when he is interacting with
6551 * the chooser, but sometimes a chooser works not on behalf of the user,
6552 * but rather on behalf of something else like GtkFileChooserButton. In
6553 * that case, the chooser's selection should be what the caller expects,
6554 * as the user can't see that something else got selected. See bug #165264.
6556 if (GTK_WIDGET_MAPPED (impl) && impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
6557 browse_files_select_first_row (impl);
6560 g_assert (impl->pending_select_paths == NULL);
6563 /* Callback used when the file system model finishes loading */
6565 browse_files_model_finished_loading_cb (GtkFileSystemModel *model,
6566 GtkFileChooserDefault *impl)
6568 profile_start ("start", NULL);
6570 if (impl->load_state == LOAD_PRELOAD)
6572 load_remove_timer (impl);
6573 load_set_model (impl);
6575 else if (impl->load_state == LOAD_LOADING)
6581 /* We can't g_assert_not_reached(), as something other than us may have
6582 * initiated a folder reload. See #165556.
6584 profile_end ("end", NULL);
6588 g_assert (impl->load_timeout_id == 0);
6590 impl->load_state = LOAD_FINISHED;
6592 pending_select_paths_process (impl);
6593 set_busy_cursor (impl, FALSE);
6594 #ifdef PROFILE_FILE_CHOOSER
6595 access ("MARK: *** FINISHED LOADING", F_OK);
6598 profile_end ("end", NULL);
6602 stop_loading_and_clear_list_model (GtkFileChooserDefault *impl)
6604 load_remove_timer (impl); /* This changes the state to LOAD_EMPTY */
6606 if (impl->browse_files_model)
6608 g_object_unref (impl->browse_files_model);
6609 impl->browse_files_model = NULL;
6612 if (impl->sort_model)
6614 g_object_unref (impl->sort_model);
6615 impl->sort_model = NULL;
6618 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), NULL);
6621 /* Gets rid of the old list model and creates a new one for the current folder */
6623 set_list_model (GtkFileChooserDefault *impl,
6626 g_assert (impl->current_folder != NULL);
6628 profile_start ("start", NULL);
6630 stop_loading_and_clear_list_model (impl);
6632 set_busy_cursor (impl, TRUE);
6633 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), NULL);
6635 impl->browse_files_model = _gtk_file_system_model_new (impl->file_system,
6636 impl->current_folder, 0,
6639 if (!impl->browse_files_model)
6641 set_busy_cursor (impl, FALSE);
6642 profile_end ("end", NULL);
6646 load_setup_timer (impl); /* This changes the state to LOAD_PRELOAD */
6648 g_signal_connect (impl->browse_files_model, "finished-loading",
6649 G_CALLBACK (browse_files_model_finished_loading_cb), impl);
6651 _gtk_file_system_model_set_show_hidden (impl->browse_files_model, impl->show_hidden);
6653 install_list_model_filter (impl);
6655 profile_end ("end", NULL);
6660 struct update_chooser_entry_selected_foreach_closure {
6662 GtkTreeIter first_selected_iter;
6666 compare_utf8_filenames (const gchar *a,
6669 gchar *a_folded, *b_folded;
6672 a_folded = g_utf8_strdown (a, -1);
6673 b_folded = g_utf8_strdown (b, -1);
6675 retval = strcmp (a_folded, b_folded);
6684 update_chooser_entry_selected_foreach (GtkTreeModel *model,
6689 struct update_chooser_entry_selected_foreach_closure *closure;
6692 closure->num_selected++;
6694 if (closure->num_selected == 1)
6695 closure->first_selected_iter = *iter;
6699 update_chooser_entry (GtkFileChooserDefault *impl)
6701 GtkTreeSelection *selection;
6702 struct update_chooser_entry_selected_foreach_closure closure;
6703 const char *file_part;
6705 if (impl->operation_mode == OPERATION_MODE_SEARCH ||
6706 impl->operation_mode == OPERATION_MODE_RECENT ||
6707 !impl->location_entry)
6710 if (!(impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
6711 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER
6712 || ((impl->action == GTK_FILE_CHOOSER_ACTION_OPEN
6713 || impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
6714 && impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)))
6717 g_assert (impl->location_entry != NULL);
6719 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
6720 closure.num_selected = 0;
6721 gtk_tree_selection_selected_foreach (selection, update_chooser_entry_selected_foreach, &closure);
6725 if (closure.num_selected == 0)
6727 goto maybe_clear_entry;
6729 else if (closure.num_selected == 1)
6731 GtkTreeIter child_iter;
6733 if (impl->operation_mode == OPERATION_MODE_BROWSE)
6735 const GtkFileInfo *info;
6736 gboolean change_entry;
6738 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
6740 &closure.first_selected_iter);
6742 info = _gtk_file_system_model_get_info (impl->browse_files_model, &child_iter);
6744 /* If the cursor moved to the row of the newly created folder,
6745 * retrieving info will return NULL.
6750 g_free (impl->browse_files_last_selected_name);
6751 impl->browse_files_last_selected_name =
6752 g_strdup (gtk_file_info_get_display_name (info));
6754 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
6755 impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
6756 change_entry = !gtk_file_info_get_is_folder (info); /* We don't want the name to change when clicking on a folder... */
6758 change_entry = TRUE; /* ... unless we are in one of the folder modes */
6761 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry),
6762 impl->browse_files_last_selected_name);
6765 else if (impl->operation_mode == OPERATION_MODE_SEARCH)
6767 search_get_valid_child_iter (impl, &child_iter, &closure.first_selected_iter);
6768 gtk_tree_model_get (GTK_TREE_MODEL (impl->search_model), &child_iter,
6769 SEARCH_MODEL_COL_DISPLAY_NAME, &file_part,
6772 else if (impl->operation_mode == OPERATION_MODE_RECENT)
6774 recent_get_valid_child_iter (impl, &child_iter, &closure.first_selected_iter);
6775 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &child_iter,
6776 RECENT_MODEL_COL_DISPLAY_NAME, &file_part,
6782 g_assert (!(impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
6783 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER));
6785 /* Multiple selection, so just clear the entry. */
6787 g_free (impl->browse_files_last_selected_name);
6788 impl->browse_files_last_selected_name = NULL;
6790 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), "");
6796 if (impl->browse_files_last_selected_name)
6798 const char *entry_text;
6800 gboolean clear_entry;
6802 entry_text = gtk_entry_get_text (GTK_ENTRY (impl->location_entry));
6803 len = strlen (entry_text);
6806 /* The file chooser entry may have appended a "/" to its text. So
6807 * take it out, and compare the result to the old selection.
6809 if (entry_text[len - 1] == G_DIR_SEPARATOR)
6813 tmp = g_strndup (entry_text, len - 1);
6814 clear_entry = (compare_utf8_filenames (impl->browse_files_last_selected_name, tmp) == 0);
6818 clear_entry = (compare_utf8_filenames (impl->browse_files_last_selected_name, entry_text) == 0);
6821 clear_entry = FALSE;
6824 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), "");
6829 gtk_file_chooser_default_set_current_folder (GtkFileChooser *chooser,
6830 const GtkFilePath *path,
6833 return gtk_file_chooser_default_update_current_folder (chooser, path, FALSE, FALSE, error);
6837 struct UpdateCurrentFolderData
6839 GtkFileChooserDefault *impl;
6841 gboolean keep_trail;
6842 gboolean clear_entry;
6843 GtkFilePath *original_path;
6844 GError *original_error;
6848 update_current_folder_get_info_cb (GtkFileSystemHandle *handle,
6849 const GtkFileInfo *info,
6850 const GError *error,
6853 gboolean cancelled = handle->cancelled;
6854 struct UpdateCurrentFolderData *data = user_data;
6855 GtkFileChooserDefault *impl = data->impl;
6857 if (handle != impl->update_current_folder_handle)
6860 impl->update_current_folder_handle = NULL;
6861 impl->reload_state = RELOAD_EMPTY;
6863 set_busy_cursor (impl, FALSE);
6870 GtkFilePath *parent_path;
6872 if (!data->original_path)
6874 data->original_path = gtk_file_path_copy (data->path);
6875 data->original_error = g_error_copy (error);
6878 /* get parent path and try to change the folder to that */
6879 if (gtk_file_system_get_parent (impl->file_system, data->path, &parent_path, NULL) &&
6880 parent_path != NULL)
6882 gtk_file_path_free (data->path);
6883 data->path = parent_path;
6885 g_object_unref (handle);
6887 /* restart the update current folder operation */
6888 impl->reload_state = RELOAD_HAS_FOLDER;
6890 impl->update_current_folder_handle =
6891 gtk_file_system_get_info (impl->file_system, data->path,
6892 GTK_FILE_INFO_IS_FOLDER,
6893 update_current_folder_get_info_cb,
6896 set_busy_cursor (impl, TRUE);
6902 /* error and bail out */
6903 error_changing_folder_dialog (impl, data->original_path, data->original_error);
6905 gtk_file_path_free (data->original_path);
6911 if (data->original_path)
6913 error_changing_folder_dialog (impl, data->original_path, data->original_error);
6915 gtk_file_path_free (data->original_path);
6918 if (!gtk_file_info_get_is_folder (info))
6921 if (!_gtk_path_bar_set_path (GTK_PATH_BAR (impl->browse_path_bar), data->path, data->keep_trail, NULL))
6924 if (impl->current_folder != data->path)
6926 if (impl->current_folder)
6927 gtk_file_path_free (impl->current_folder);
6929 impl->current_folder = gtk_file_path_copy (data->path);
6931 impl->reload_state = RELOAD_HAS_FOLDER;
6934 /* Update the widgets that may trigger a folder change themselves. */
6936 if (!impl->changing_folder)
6938 impl->changing_folder = TRUE;
6940 shortcuts_update_current_folder (impl);
6942 impl->changing_folder = FALSE;
6945 /* Set the folder on the save entry */
6947 if (impl->location_entry)
6949 _gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->location_entry),
6950 impl->current_folder);
6952 if (data->clear_entry)
6953 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), "");
6956 /* Create a new list model. This is slightly evil; we store the result value
6957 * but perform more actions rather than returning immediately even if it
6958 * generates an error.
6960 set_list_model (impl, NULL);
6962 /* Refresh controls */
6964 shortcuts_find_current_folder (impl);
6966 g_signal_emit_by_name (impl, "current-folder-changed", 0);
6968 check_preview_change (impl);
6969 bookmarks_check_add_sensitivity (impl);
6971 g_signal_emit_by_name (impl, "selection-changed", 0);
6974 gtk_file_path_free (data->path);
6977 g_object_unref (handle);
6981 gtk_file_chooser_default_update_current_folder (GtkFileChooser *chooser,
6982 const GtkFilePath *path,
6983 gboolean keep_trail,
6984 gboolean clear_entry,
6987 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
6988 struct UpdateCurrentFolderData *data;
6990 profile_start ("start", (char *) path);
6992 switch (impl->operation_mode)
6994 case OPERATION_MODE_SEARCH:
6995 search_switch_to_browse_mode (impl);
6997 case OPERATION_MODE_RECENT:
6998 recent_switch_to_browse_mode (impl);
7000 case OPERATION_MODE_BROWSE:
7004 g_assert (path != NULL);
7006 if (impl->local_only &&
7007 !gtk_file_system_path_is_local (impl->file_system, path))
7010 GTK_FILE_CHOOSER_ERROR,
7011 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
7012 _("Cannot change to folder because it is not local"));
7014 profile_end ("end - not local", (char *) path);
7018 if (impl->update_current_folder_handle)
7019 gtk_file_system_cancel_operation (impl->update_current_folder_handle);
7021 /* Test validity of path here. */
7022 data = g_new0 (struct UpdateCurrentFolderData, 1);
7024 data->path = gtk_file_path_copy (path);
7025 data->keep_trail = keep_trail;
7026 data->clear_entry = clear_entry;
7028 impl->reload_state = RELOAD_HAS_FOLDER;
7030 impl->update_current_folder_handle =
7031 gtk_file_system_get_info (impl->file_system, path, GTK_FILE_INFO_IS_FOLDER,
7032 update_current_folder_get_info_cb,
7035 set_busy_cursor (impl, TRUE);
7037 profile_end ("end", NULL);
7041 static GtkFilePath *
7042 gtk_file_chooser_default_get_current_folder (GtkFileChooser *chooser)
7044 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7046 if (impl->operation_mode == OPERATION_MODE_SEARCH ||
7047 impl->operation_mode == OPERATION_MODE_RECENT)
7050 if (impl->reload_state == RELOAD_EMPTY)
7052 char *current_working_dir;
7055 /* We are unmapped, or we had an error while loading the last folder. We'll return
7056 * the $cwd since once we get (re)mapped, we'll load $cwd anyway unless the caller
7057 * explicitly calls set_current_folder() on us.
7059 current_working_dir = g_get_current_dir ();
7060 path = gtk_file_system_filename_to_path (impl->file_system, current_working_dir);
7061 g_free (current_working_dir);
7065 return gtk_file_path_copy (impl->current_folder);
7069 gtk_file_chooser_default_set_current_name (GtkFileChooser *chooser,
7072 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7074 g_return_if_fail (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
7075 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER);
7077 pending_select_paths_free (impl);
7078 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), name);
7082 select_func (GtkFileSystemModel *model,
7087 GtkFileChooserDefault *impl = user_data;
7088 GtkTreeSelection *selection;
7089 GtkTreeIter sorted_iter;
7091 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
7093 gtk_tree_model_sort_convert_child_iter_to_iter (impl->sort_model, &sorted_iter, iter);
7094 gtk_tree_selection_select_iter (selection, &sorted_iter);
7098 gtk_file_chooser_default_select_path (GtkFileChooser *chooser,
7099 const GtkFilePath *path,
7102 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7103 GtkFilePath *parent_path;
7106 if (!gtk_file_system_get_parent (impl->file_system, path, &parent_path, error))
7110 return _gtk_file_chooser_set_current_folder_path (chooser, path, error);
7112 if (impl->operation_mode == OPERATION_MODE_SEARCH ||
7113 impl->operation_mode == OPERATION_MODE_RECENT ||
7114 impl->load_state == LOAD_EMPTY)
7120 g_assert (impl->current_folder != NULL);
7122 same_path = gtk_file_path_compare (parent_path, impl->current_folder) == 0;
7125 if (same_path && impl->load_state == LOAD_FINISHED)
7130 paths.data = (gpointer) path;
7133 result = show_and_select_paths (impl, parent_path, &paths, error);
7134 gtk_file_path_free (parent_path);
7138 pending_select_paths_add (impl, path);
7144 result = _gtk_file_chooser_set_current_folder_path (chooser, parent_path, error);
7145 gtk_file_path_free (parent_path);
7149 gtk_file_path_free (parent_path);
7154 unselect_func (GtkFileSystemModel *model,
7159 GtkFileChooserDefault *impl = user_data;
7160 GtkTreeView *tree_view = GTK_TREE_VIEW (impl->browse_files_tree_view);
7161 GtkTreePath *sorted_path;
7163 sorted_path = gtk_tree_model_sort_convert_child_path_to_path (impl->sort_model,
7165 gtk_tree_selection_unselect_path (gtk_tree_view_get_selection (tree_view),
7167 gtk_tree_path_free (sorted_path);
7171 gtk_file_chooser_default_unselect_path (GtkFileChooser *chooser,
7172 const GtkFilePath *path)
7174 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7176 if (!impl->browse_files_model)
7179 _gtk_file_system_model_path_do (impl->browse_files_model, path,
7180 unselect_func, impl);
7184 maybe_select (GtkTreeModel *model,
7189 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (data);
7190 GtkTreeSelection *selection;
7191 const GtkFileInfo *info;
7194 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
7196 info = get_list_file_info (impl, iter);
7197 is_folder = gtk_file_info_get_is_folder (info);
7199 if ((is_folder && impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) ||
7200 (!is_folder && impl->action == GTK_FILE_CHOOSER_ACTION_OPEN))
7201 gtk_tree_selection_select_iter (selection, iter);
7203 gtk_tree_selection_unselect_iter (selection, iter);
7209 gtk_file_chooser_default_select_all (GtkFileChooser *chooser)
7211 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7213 if (impl->operation_mode == OPERATION_MODE_SEARCH ||
7214 impl->operation_mode == OPERATION_MODE_RECENT)
7216 GtkTreeSelection *selection;
7218 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
7219 gtk_tree_selection_select_all (selection);
7223 if (impl->select_multiple)
7224 gtk_tree_model_foreach (GTK_TREE_MODEL (impl->sort_model),
7225 maybe_select, impl);
7229 gtk_file_chooser_default_unselect_all (GtkFileChooser *chooser)
7231 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7232 GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
7234 gtk_tree_selection_unselect_all (selection);
7235 pending_select_paths_free (impl);
7238 /* Checks whether the filename entry for the Save modes contains a well-formed filename.
7240 * is_well_formed_ret - whether what the user typed passes gkt_file_system_make_path()
7242 * is_empty_ret - whether the file entry is totally empty
7244 * is_file_part_empty_ret - whether the file part is empty (will be if user types "foobar/", and
7245 * the path will be "$cwd/foobar")
7248 check_save_entry (GtkFileChooserDefault *impl,
7249 GtkFilePath **path_ret,
7250 gboolean *is_well_formed_ret,
7251 gboolean *is_empty_ret,
7252 gboolean *is_file_part_empty_ret,
7253 gboolean *is_folder)
7255 GtkFileChooserEntry *chooser_entry;
7256 const GtkFilePath *current_folder;
7257 const char *file_part;
7261 g_assert (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
7262 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER
7263 || ((impl->action == GTK_FILE_CHOOSER_ACTION_OPEN
7264 || impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
7265 && impl->location_mode == LOCATION_MODE_FILENAME_ENTRY));
7267 chooser_entry = GTK_FILE_CHOOSER_ENTRY (impl->location_entry);
7269 if (strlen (gtk_entry_get_text (GTK_ENTRY (chooser_entry))) == 0)
7272 *is_well_formed_ret = TRUE;
7273 *is_empty_ret = TRUE;
7274 *is_file_part_empty_ret = TRUE;
7280 *is_empty_ret = FALSE;
7282 current_folder = _gtk_file_chooser_entry_get_current_folder (chooser_entry);
7283 if (!current_folder)
7286 *is_well_formed_ret = FALSE;
7287 *is_file_part_empty_ret = FALSE;
7293 file_part = _gtk_file_chooser_entry_get_file_part (chooser_entry);
7295 if (!file_part || file_part[0] == '\0')
7297 *path_ret = gtk_file_path_copy (current_folder);
7298 *is_well_formed_ret = TRUE;
7299 *is_file_part_empty_ret = TRUE;
7305 *is_file_part_empty_ret = FALSE;
7308 path = gtk_file_system_make_path (impl->file_system, current_folder, file_part, &error);
7312 error_building_filename_dialog (impl, current_folder, file_part, error);
7314 *is_well_formed_ret = FALSE;
7321 *is_well_formed_ret = TRUE;
7322 *is_folder = _gtk_file_chooser_entry_get_is_folder (chooser_entry, path);
7325 struct get_paths_closure {
7326 GtkFileChooserDefault *impl;
7328 GtkFilePath *path_from_entry;
7332 get_paths_foreach (GtkTreeModel *model,
7337 struct get_paths_closure *info;
7338 const GtkFilePath *file_path;
7339 GtkFileSystemModel *fs_model;
7340 GtkTreeIter sel_iter;
7343 fs_model = info->impl->browse_files_model;
7344 gtk_tree_model_sort_convert_iter_to_child_iter (info->impl->sort_model, &sel_iter, iter);
7346 file_path = _gtk_file_system_model_get_path (fs_model, &sel_iter);
7348 return; /* We are on the editable row */
7350 if (!info->path_from_entry
7351 || gtk_file_path_compare (info->path_from_entry, file_path) != 0)
7352 info->result = g_slist_prepend (info->result, gtk_file_path_copy (file_path));
7356 gtk_file_chooser_default_get_paths (GtkFileChooser *chooser)
7358 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7359 struct get_paths_closure info;
7360 GtkWindow *toplevel;
7361 GtkWidget *current_focus;
7362 gboolean file_list_seen;
7364 if (impl->operation_mode == OPERATION_MODE_SEARCH)
7365 return search_get_selected_paths (impl);
7367 if (impl->operation_mode == OPERATION_MODE_RECENT)
7368 return recent_get_selected_paths (impl);
7372 info.path_from_entry = NULL;
7374 toplevel = get_toplevel (GTK_WIDGET (impl));
7376 current_focus = gtk_window_get_focus (toplevel);
7378 current_focus = NULL;
7380 file_list_seen = FALSE;
7381 if (current_focus == impl->browse_files_tree_view)
7383 GtkTreeSelection *selection;
7387 file_list_seen = TRUE;
7388 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
7389 gtk_tree_selection_selected_foreach (selection, get_paths_foreach, &info);
7391 /* If there is no selection in the file list, we probably have this situation:
7393 * 1. The user typed a filename in the SAVE filename entry ("foo.txt").
7394 * 2. He then double-clicked on a folder ("bar") in the file list
7396 * So we want the selection to be "bar/foo.txt". Jump to the case for the
7397 * filename entry to see if that is the case.
7399 if (info.result == NULL && impl->location_entry)
7402 else if (impl->location_entry && current_focus == impl->location_entry)
7404 gboolean is_well_formed, is_empty, is_file_part_empty, is_folder;
7408 check_save_entry (impl, &info.path_from_entry, &is_well_formed, &is_empty, &is_file_part_empty, &is_folder);
7413 if (!is_well_formed)
7416 if (is_file_part_empty && impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
7418 gtk_file_path_free (info.path_from_entry);
7422 if (info.path_from_entry)
7423 info.result = g_slist_prepend (info.result, info.path_from_entry);
7424 else if (!file_list_seen)
7429 else if (impl->toplevel_last_focus_widget == impl->browse_files_tree_view)
7431 else if (impl->location_entry && impl->toplevel_last_focus_widget == impl->location_entry)
7435 /* The focus is on a dialog's action area button or something else */
7436 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
7437 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
7445 /* If there's no folder selected, and we're in SELECT_FOLDER mode, then we
7446 * fall back to the current directory */
7447 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER &&
7448 info.result == NULL)
7450 info.result = g_slist_prepend (info.result, _gtk_file_chooser_get_current_folder_path (chooser));
7453 return g_slist_reverse (info.result);
7456 static GtkFilePath *
7457 gtk_file_chooser_default_get_preview_path (GtkFileChooser *chooser)
7459 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7461 if (impl->preview_path)
7462 return gtk_file_path_copy (impl->preview_path);
7467 static GtkFileSystem *
7468 gtk_file_chooser_default_get_file_system (GtkFileChooser *chooser)
7470 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7472 return impl->file_system;
7475 /* Shows or hides the filter widgets */
7477 show_filters (GtkFileChooserDefault *impl,
7481 gtk_widget_show (impl->filter_combo_hbox);
7483 gtk_widget_hide (impl->filter_combo_hbox);
7487 gtk_file_chooser_default_add_filter (GtkFileChooser *chooser,
7488 GtkFileFilter *filter)
7490 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7493 if (g_slist_find (impl->filters, filter))
7495 g_warning ("gtk_file_chooser_add_filter() called on filter already in list\n");
7499 g_object_ref_sink (filter);
7500 impl->filters = g_slist_append (impl->filters, filter);
7502 name = gtk_file_filter_get_name (filter);
7504 name = "Untitled filter"; /* Place-holder, doesn't need to be marked for translation */
7506 gtk_combo_box_append_text (GTK_COMBO_BOX (impl->filter_combo), name);
7508 if (!g_slist_find (impl->filters, impl->current_filter))
7509 set_current_filter (impl, filter);
7511 show_filters (impl, TRUE);
7515 gtk_file_chooser_default_remove_filter (GtkFileChooser *chooser,
7516 GtkFileFilter *filter)
7518 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7519 GtkTreeModel *model;
7523 filter_index = g_slist_index (impl->filters, filter);
7525 if (filter_index < 0)
7527 g_warning ("gtk_file_chooser_remove_filter() called on filter not in list\n");
7531 impl->filters = g_slist_remove (impl->filters, filter);
7533 if (filter == impl->current_filter)
7536 set_current_filter (impl, impl->filters->data);
7538 set_current_filter (impl, NULL);
7541 /* Remove row from the combo box */
7542 model = gtk_combo_box_get_model (GTK_COMBO_BOX (impl->filter_combo));
7543 if (!gtk_tree_model_iter_nth_child (model, &iter, NULL, filter_index))
7544 g_assert_not_reached ();
7546 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
7548 g_object_unref (filter);
7551 show_filters (impl, FALSE);
7555 gtk_file_chooser_default_list_filters (GtkFileChooser *chooser)
7557 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7559 return g_slist_copy (impl->filters);
7562 /* Returns the position in the shortcuts tree where the nth specified shortcut would appear */
7564 shortcuts_get_pos_for_shortcut_folder (GtkFileChooserDefault *impl,
7567 return pos + shortcuts_get_index (impl, SHORTCUTS_SHORTCUTS);
7570 struct AddShortcutData
7572 GtkFileChooserDefault *impl;
7577 add_shortcut_get_info_cb (GtkFileSystemHandle *handle,
7578 const GtkFileInfo *info,
7579 const GError *error,
7583 gboolean cancelled = handle->cancelled;
7584 struct AddShortcutData *data = user_data;
7586 if (!g_slist_find (data->impl->loading_shortcuts, handle))
7589 data->impl->loading_shortcuts = g_slist_remove (data->impl->loading_shortcuts, handle);
7591 if (cancelled || error || !gtk_file_info_get_is_folder (info))
7594 pos = shortcuts_get_pos_for_shortcut_folder (data->impl, data->impl->num_shortcuts);
7596 shortcuts_insert_path (data->impl, pos, SHORTCUT_TYPE_PATH, NULL, data->path, NULL, FALSE, SHORTCUTS_SHORTCUTS);
7599 g_object_unref (data->impl);
7600 gtk_file_path_free (data->path);
7603 g_object_unref (handle);
7607 gtk_file_chooser_default_add_shortcut_folder (GtkFileChooser *chooser,
7608 const GtkFilePath *path,
7611 GtkFileSystemHandle *handle;
7612 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7613 struct AddShortcutData *data;
7617 /* Avoid adding duplicates */
7618 pos = shortcut_find_position (impl, path);
7619 if (pos >= 0 && pos < shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR))
7623 uri = gtk_file_system_path_to_uri (impl->file_system, path);
7624 /* translators, "Shortcut" means "Bookmark" here */
7626 GTK_FILE_CHOOSER_ERROR,
7627 GTK_FILE_CHOOSER_ERROR_ALREADY_EXISTS,
7628 _("Shortcut %s already exists"),
7635 for (l = impl->loading_shortcuts; l; l = l->next)
7637 GtkFileSystemHandle *h = l->data;
7640 p = g_object_get_data (G_OBJECT (h), "add-shortcut-path-key");
7641 if (p && !gtk_file_path_compare (path, p))
7645 uri = gtk_file_system_path_to_uri (impl->file_system, path);
7647 GTK_FILE_CHOOSER_ERROR,
7648 GTK_FILE_CHOOSER_ERROR_ALREADY_EXISTS,
7649 _("Shortcut %s already exists"),
7657 data = g_new0 (struct AddShortcutData, 1);
7658 data->impl = g_object_ref (impl);
7659 data->path = gtk_file_path_copy (path);
7661 handle = gtk_file_system_get_info (impl->file_system, path,
7662 GTK_FILE_INFO_IS_FOLDER,
7663 add_shortcut_get_info_cb, data);
7668 impl->loading_shortcuts = g_slist_append (impl->loading_shortcuts, handle);
7669 g_object_set_data (G_OBJECT (handle), "add-shortcut-path-key", data->path);
7675 gtk_file_chooser_default_remove_shortcut_folder (GtkFileChooser *chooser,
7676 const GtkFilePath *path,
7679 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7686 for (l = impl->loading_shortcuts; l; l = l->next)
7688 GtkFileSystemHandle *h = l->data;
7691 p = g_object_get_data (G_OBJECT (h), "add-shortcut-path-key");
7692 if (p && !gtk_file_path_compare (path, p))
7694 impl->loading_shortcuts = g_slist_remove (impl->loading_shortcuts, h);
7695 gtk_file_system_cancel_operation (h);
7700 if (impl->num_shortcuts == 0)
7703 pos = shortcuts_get_pos_for_shortcut_folder (impl, 0);
7704 if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos))
7705 g_assert_not_reached ();
7707 for (i = 0; i < impl->num_shortcuts; i++)
7710 ShortcutType shortcut_type;
7711 GtkFilePath *shortcut;
7713 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
7714 SHORTCUTS_COL_DATA, &col_data,
7715 SHORTCUTS_COL_TYPE, &shortcut_type,
7717 g_assert (col_data != NULL);
7718 g_assert (shortcut_type == SHORTCUT_TYPE_PATH);
7720 shortcut = col_data;
7721 if (gtk_file_path_compare (shortcut, path) == 0)
7723 shortcuts_remove_rows (impl, pos + i, 1);
7724 impl->num_shortcuts--;
7728 if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
7729 g_assert_not_reached ();
7734 uri = gtk_file_system_path_to_uri (impl->file_system, path);
7735 /* translators, "Shortcut" means "Bookmark" here */
7737 GTK_FILE_CHOOSER_ERROR,
7738 GTK_FILE_CHOOSER_ERROR_NONEXISTENT,
7739 _("Shortcut %s does not exist"),
7747 gtk_file_chooser_default_list_shortcut_folders (GtkFileChooser *chooser)
7749 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7755 if (impl->num_shortcuts == 0)
7758 pos = shortcuts_get_pos_for_shortcut_folder (impl, 0);
7759 if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos))
7760 g_assert_not_reached ();
7764 for (i = 0; i < impl->num_shortcuts; i++)
7767 ShortcutType shortcut_type;
7768 GtkFilePath *shortcut;
7770 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
7771 SHORTCUTS_COL_DATA, &col_data,
7772 SHORTCUTS_COL_TYPE, &shortcut_type,
7774 g_assert (col_data != NULL);
7775 g_assert (shortcut_type == SHORTCUT_TYPE_PATH);
7777 shortcut = col_data;
7778 list = g_slist_prepend (list, gtk_file_path_copy (shortcut));
7780 if (i != impl->num_shortcuts - 1)
7782 if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
7783 g_assert_not_reached ();
7787 return g_slist_reverse (list);
7790 /* Guesses a size based upon font sizes */
7792 find_good_size_from_style (GtkWidget *widget,
7796 GtkFileChooserDefault *impl;
7801 g_assert (widget->style != NULL);
7802 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
7804 if (impl->default_width == 0 &&
7805 impl->default_height == 0)
7807 screen = gtk_widget_get_screen (widget);
7810 resolution = gdk_screen_get_resolution (screen);
7811 if (resolution < 0.0) /* will be -1 if the resolution is not defined in the GdkScreen */
7815 resolution = 96.0; /* wheeee */
7817 font_size = pango_font_description_get_size (widget->style->font_desc);
7818 font_size = PANGO_PIXELS (font_size) * resolution / 72.0;
7820 impl->default_width = font_size * NUM_CHARS;
7821 impl->default_height = font_size * NUM_LINES;
7824 *width = impl->default_width;
7825 *height = impl->default_height;
7829 gtk_file_chooser_default_get_default_size (GtkFileChooserEmbed *chooser_embed,
7830 gint *default_width,
7831 gint *default_height)
7833 GtkFileChooserDefault *impl;
7836 impl = GTK_FILE_CHOOSER_DEFAULT (chooser_embed);
7837 find_good_size_from_style (GTK_WIDGET (chooser_embed), default_width, default_height);
7839 if (impl->preview_widget_active &&
7840 impl->preview_widget &&
7841 GTK_WIDGET_VISIBLE (impl->preview_widget))
7843 gtk_widget_size_request (impl->preview_box, &req);
7844 *default_width += PREVIEW_HBOX_SPACING + req.width;
7847 if (impl->extra_widget &&
7848 GTK_WIDGET_VISIBLE (impl->extra_widget))
7850 gtk_widget_size_request (impl->extra_align, &req);
7851 *default_height += GTK_BOX (chooser_embed)->spacing + req.height;
7856 gtk_file_chooser_default_get_resizable (GtkFileChooserEmbed *chooser_embed)
7858 GtkFileChooserDefault *impl;
7860 impl = GTK_FILE_CHOOSER_DEFAULT (chooser_embed);
7862 return (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
7863 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
7864 gtk_expander_get_expanded (GTK_EXPANDER (impl->save_expander)));
7867 struct switch_folder_closure {
7868 GtkFileChooserDefault *impl;
7869 const GtkFilePath *path;
7873 /* Used from gtk_tree_selection_selected_foreach() in switch_to_selected_folder() */
7875 switch_folder_foreach_cb (GtkTreeModel *model,
7880 struct switch_folder_closure *closure;
7881 GtkTreeIter child_iter;
7885 gtk_tree_model_sort_convert_iter_to_child_iter (closure->impl->sort_model, &child_iter, iter);
7887 closure->path = _gtk_file_system_model_get_path (closure->impl->browse_files_model, &child_iter);
7888 closure->num_selected++;
7891 /* Changes to the selected folder in the list view */
7893 switch_to_selected_folder (GtkFileChooserDefault *impl)
7895 GtkTreeSelection *selection;
7896 struct switch_folder_closure closure;
7898 /* We do this with foreach() rather than get_selected() as we may be in
7899 * multiple selection mode
7902 closure.impl = impl;
7903 closure.path = NULL;
7904 closure.num_selected = 0;
7906 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
7907 gtk_tree_selection_selected_foreach (selection, switch_folder_foreach_cb, &closure);
7909 g_assert (closure.path && closure.num_selected == 1);
7911 change_folder_and_display_error (impl, closure.path, FALSE);
7914 /* Gets the GtkFileInfo for the selected row in the file list; assumes single
7917 static const GtkFileInfo *
7918 get_selected_file_info_from_file_list (GtkFileChooserDefault *impl,
7919 gboolean *had_selection)
7921 GtkTreeSelection *selection;
7922 GtkTreeIter iter, child_iter;
7923 const GtkFileInfo *info;
7925 g_assert (!impl->select_multiple);
7926 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
7927 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
7929 *had_selection = FALSE;
7933 *had_selection = TRUE;
7935 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
7939 info = _gtk_file_system_model_get_info (impl->browse_files_model, &child_iter);
7943 /* Gets the display name of the selected file in the file list; assumes single
7944 * selection mode and that something is selected.
7946 static const gchar *
7947 get_display_name_from_file_list (GtkFileChooserDefault *impl)
7949 const GtkFileInfo *info;
7950 gboolean had_selection;
7952 info = get_selected_file_info_from_file_list (impl, &had_selection);
7953 g_assert (had_selection);
7954 g_assert (info != NULL);
7956 return gtk_file_info_get_display_name (info);
7960 add_custom_button_to_dialog (GtkDialog *dialog,
7961 const gchar *mnemonic_label,
7962 const gchar *stock_id,
7967 button = gtk_button_new_with_mnemonic (mnemonic_label);
7968 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
7969 gtk_button_set_image (GTK_BUTTON (button),
7970 gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON));
7971 gtk_widget_show (button);
7973 gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, response_id);
7976 /* Presents an overwrite confirmation dialog; returns whether we should accept
7980 confirm_dialog_should_accept_filename (GtkFileChooserDefault *impl,
7981 const gchar *file_part,
7982 const gchar *folder_display_name)
7984 GtkWindow *toplevel;
7988 toplevel = get_toplevel (GTK_WIDGET (impl));
7990 dialog = gtk_message_dialog_new (toplevel,
7991 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
7992 GTK_MESSAGE_QUESTION,
7994 _("A file named \"%s\" already exists. Do you want to replace it?"),
7996 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
7997 _("The file already exists in \"%s\". Replacing it will "
7998 "overwrite its contents."),
7999 folder_display_name);
8001 gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
8002 add_custom_button_to_dialog (GTK_DIALOG (dialog), _("_Replace"), GTK_STOCK_SAVE_AS, GTK_RESPONSE_ACCEPT);
8003 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
8005 if (toplevel->group)
8006 gtk_window_group_add_window (toplevel->group, GTK_WINDOW (dialog));
8008 response = gtk_dialog_run (GTK_DIALOG (dialog));
8010 gtk_widget_destroy (dialog);
8012 return (response == GTK_RESPONSE_ACCEPT);
8015 struct GetDisplayNameData
8017 GtkFileChooserDefault *impl;
8022 confirmation_confirm_get_info_cb (GtkFileSystemHandle *handle,
8023 const GtkFileInfo *info,
8024 const GError *error,
8027 gboolean cancelled = handle->cancelled;
8028 gboolean should_respond = FALSE;
8029 struct GetDisplayNameData *data = user_data;
8031 if (handle != data->impl->should_respond_get_info_handle)
8034 data->impl->should_respond_get_info_handle = NULL;
8040 /* Huh? Did the folder disappear? Let the caller deal with it */
8041 should_respond = TRUE;
8043 should_respond = confirm_dialog_should_accept_filename (data->impl, data->file_part, gtk_file_info_get_display_name (info));
8045 set_busy_cursor (data->impl, FALSE);
8047 g_signal_emit_by_name (data->impl, "response-requested");
8050 g_object_unref (data->impl);
8051 g_free (data->file_part);
8054 g_object_unref (handle);
8057 /* Does overwrite confirmation if appropriate, and returns whether the dialog
8058 * should respond. Can get the file part from the file list or the save entry.
8061 should_respond_after_confirm_overwrite (GtkFileChooserDefault *impl,
8062 const gchar *file_part,
8063 const GtkFilePath *parent_path)
8065 GtkFileChooserConfirmation conf;
8067 if (!impl->do_overwrite_confirmation)
8070 conf = GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM;
8072 g_signal_emit_by_name (impl, "confirm-overwrite", &conf);
8076 case GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM:
8078 struct GetDisplayNameData *data;
8080 g_assert (file_part != NULL);
8082 data = g_new0 (struct GetDisplayNameData, 1);
8083 data->impl = g_object_ref (impl);
8084 data->file_part = g_strdup (file_part);
8086 if (impl->should_respond_get_info_handle)
8087 gtk_file_system_cancel_operation (impl->should_respond_get_info_handle);
8089 impl->should_respond_get_info_handle =
8090 gtk_file_system_get_info (impl->file_system, parent_path,
8091 GTK_FILE_INFO_DISPLAY_NAME,
8092 confirmation_confirm_get_info_cb,
8094 set_busy_cursor (data->impl, TRUE);
8098 case GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME:
8101 case GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN:
8105 g_assert_not_reached ();
8110 /* Gives the focus to the browse tree view only if it is visible */
8112 focus_browse_tree_view_if_possible (GtkFileChooserDefault *impl)
8116 if ((impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
8117 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
8118 && !gtk_expander_get_expanded (GTK_EXPANDER (impl->save_expander)))
8124 gtk_widget_grab_focus (impl->browse_files_tree_view);
8128 action_create_folder_cb (GtkFileSystemHandle *handle,
8129 const GtkFilePath *path,
8130 const GError *error,
8133 gboolean cancelled = handle->cancelled;
8134 GtkFileChooserDefault *impl = user_data;
8136 if (!g_slist_find (impl->pending_handles, handle))
8139 impl->pending_handles = g_slist_remove (impl->pending_handles, handle);
8141 set_busy_cursor (impl, FALSE);
8147 error_creating_folder_dialog (impl, path, g_error_copy (error));
8149 g_signal_emit_by_name (impl, "response-requested");
8152 g_object_unref (impl);
8153 g_object_unref (handle);
8156 struct FileExistsData
8158 GtkFileChooserDefault *impl;
8159 gboolean file_exists_and_is_not_folder;
8160 GtkFilePath *parent_path;
8165 save_entry_get_info_cb (GtkFileSystemHandle *handle,
8166 const GtkFileInfo *info,
8167 const GError *error,
8170 gboolean parent_is_folder;
8171 gboolean cancelled = handle->cancelled;
8172 struct FileExistsData *data = user_data;
8174 if (handle != data->impl->should_respond_get_info_handle)
8177 data->impl->should_respond_get_info_handle = NULL;
8179 set_busy_cursor (data->impl, FALSE);
8185 parent_is_folder = FALSE;
8187 parent_is_folder = gtk_file_info_get_is_folder (info);
8189 if (parent_is_folder)
8191 if (data->impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
8193 if (data->file_exists_and_is_not_folder)
8196 const char *file_part;
8198 file_part = _gtk_file_chooser_entry_get_file_part (GTK_FILE_CHOOSER_ENTRY (data->impl->location_entry));
8199 retval = should_respond_after_confirm_overwrite (data->impl, file_part, data->parent_path);
8202 g_signal_emit_by_name (data->impl, "response-requested");
8205 g_signal_emit_by_name (data->impl, "response-requested");
8207 else /* GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER */
8209 GtkFileSystemHandle *handle;
8211 g_object_ref (data->impl);
8212 handle = gtk_file_system_create_folder (data->impl->file_system,
8214 action_create_folder_cb,
8216 data->impl->pending_handles = g_slist_append (data->impl->pending_handles, handle);
8217 set_busy_cursor (data->impl, TRUE);
8222 /* This will display an error, which is what we want */
8223 change_folder_and_display_error (data->impl, data->parent_path, FALSE);
8227 g_object_unref (data->impl);
8228 gtk_file_path_free (data->path);
8229 gtk_file_path_free (data->parent_path);
8232 g_object_unref (handle);
8236 file_exists_get_info_cb (GtkFileSystemHandle *handle,
8237 const GtkFileInfo *info,
8238 const GError *error,
8241 gboolean data_ownership_taken = FALSE;
8242 gboolean cancelled = handle->cancelled;
8243 gboolean file_exists_and_is_not_folder;
8244 struct FileExistsData *data = user_data;
8246 if (handle != data->impl->file_exists_get_info_handle)
8249 data->impl->file_exists_get_info_handle = NULL;
8251 set_busy_cursor (data->impl, FALSE);
8256 file_exists_and_is_not_folder = info && !gtk_file_info_get_is_folder (info);
8258 if (data->impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
8259 /* user typed a filename; we are done */
8260 g_signal_emit_by_name (data->impl, "response-requested");
8261 else if (data->impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER
8262 && file_exists_and_is_not_folder)
8264 /* Oops, the user typed the name of an existing path which is not
8267 error_creating_folder_over_existing_file_dialog (data->impl, data->path,
8268 g_error_copy (error));
8272 /* check that everything up to the last component exists */
8274 data->file_exists_and_is_not_folder = file_exists_and_is_not_folder;
8275 data_ownership_taken = TRUE;
8277 if (data->impl->should_respond_get_info_handle)
8278 gtk_file_system_cancel_operation (data->impl->should_respond_get_info_handle);
8280 data->impl->should_respond_get_info_handle =
8281 gtk_file_system_get_info (data->impl->file_system,
8283 GTK_FILE_INFO_IS_FOLDER,
8284 save_entry_get_info_cb,
8286 set_busy_cursor (data->impl, TRUE);
8290 if (!data_ownership_taken)
8292 g_object_unref (data->impl);
8293 gtk_file_path_free (data->path);
8294 gtk_file_path_free (data->parent_path);
8298 g_object_unref (handle);
8302 paste_text_received (GtkClipboard *clipboard,
8304 GtkFileChooserDefault *impl)
8311 path = gtk_file_system_uri_to_path (impl->file_system, text);
8314 if (!g_path_is_absolute (text))
8316 location_popup_handler (impl, text);
8320 path = gtk_file_system_filename_to_path (impl->file_system, text);
8323 location_popup_handler (impl, text);
8328 if (!gtk_file_chooser_default_select_path (GTK_FILE_CHOOSER (impl), path, NULL))
8329 location_popup_handler (impl, text);
8331 gtk_file_path_free (path);
8334 /* Handler for the "location-popup-on-paste" keybinding signal */
8336 location_popup_on_paste_handler (GtkFileChooserDefault *impl)
8338 GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (impl),
8339 GDK_SELECTION_CLIPBOARD);
8340 gtk_clipboard_request_text (clipboard,
8341 (GtkClipboardTextReceivedFunc) paste_text_received,
8346 /* Implementation for GtkFileChooserEmbed::should_respond() */
8348 gtk_file_chooser_default_should_respond (GtkFileChooserEmbed *chooser_embed)
8350 GtkFileChooserDefault *impl;
8351 GtkWidget *toplevel;
8352 GtkWidget *current_focus;
8354 impl = GTK_FILE_CHOOSER_DEFAULT (chooser_embed);
8356 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (impl));
8357 g_assert (GTK_IS_WINDOW (toplevel));
8359 current_focus = gtk_window_get_focus (GTK_WINDOW (toplevel));
8361 if (current_focus == impl->browse_files_tree_view)
8363 /* The following array encodes what we do based on the impl->action and the
8364 * number of files selected.
8367 NOOP, /* Do nothing (don't respond) */
8368 RESPOND, /* Respond immediately */
8369 RESPOND_OR_SWITCH, /* Respond immediately if the selected item is a file; switch to it if it is a folder */
8370 ALL_FILES, /* Respond only if everything selected is a file */
8371 ALL_FOLDERS, /* Respond only if everything selected is a folder */
8372 SAVE_ENTRY, /* Go to the code for handling the save entry */
8373 NOT_REACHED /* Sanity check */
8375 static const ActionToTake what_to_do[4][3] = {
8376 /* 0 selected 1 selected many selected */
8377 /* ACTION_OPEN */ { NOOP, RESPOND_OR_SWITCH, ALL_FILES },
8378 /* ACTION_SAVE */ { SAVE_ENTRY, RESPOND_OR_SWITCH, NOT_REACHED },
8379 /* ACTION_SELECT_FOLDER */ { RESPOND, ALL_FOLDERS, ALL_FOLDERS },
8380 /* ACTION_CREATE_FOLDER */ { SAVE_ENTRY, ALL_FOLDERS, NOT_REACHED }
8384 gboolean all_files, all_folders;
8386 ActionToTake action;
8390 g_assert (impl->action >= GTK_FILE_CHOOSER_ACTION_OPEN && impl->action <= GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER);
8392 if (impl->operation_mode == OPERATION_MODE_SEARCH)
8393 return search_should_respond (impl);
8395 if (impl->operation_mode == OPERATION_MODE_RECENT)
8396 return recent_should_respond (impl);
8398 selection_check (impl, &num_selected, &all_files, &all_folders);
8400 if (num_selected > 2)
8405 action = what_to_do [impl->action] [k];
8415 case RESPOND_OR_SWITCH:
8416 g_assert (num_selected == 1);
8420 switch_to_selected_folder (impl);
8423 else if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
8424 return should_respond_after_confirm_overwrite (impl,
8425 get_display_name_from_file_list (impl),
8426 impl->current_folder);
8440 g_assert_not_reached ();
8443 else if ((impl->location_entry != NULL) && (current_focus == impl->location_entry))
8446 gboolean is_well_formed, is_empty, is_file_part_empty;
8449 GtkFileChooserEntry *entry;
8454 g_assert (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
8455 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER
8456 || ((impl->action == GTK_FILE_CHOOSER_ACTION_OPEN
8457 || impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
8458 && impl->location_mode == LOCATION_MODE_FILENAME_ENTRY));
8460 entry = GTK_FILE_CHOOSER_ENTRY (impl->location_entry);
8461 check_save_entry (impl, &path, &is_well_formed, &is_empty, &is_file_part_empty, &is_folder);
8463 if (is_empty || !is_well_formed)
8466 g_assert (path != NULL);
8471 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
8472 impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
8474 change_folder_and_display_error (impl, path, TRUE);
8477 else if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
8478 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
8480 /* The folder already exists, so we do not need to create it.
8481 * Just respond to terminate the dialog.
8487 g_assert_not_reached ();
8493 struct FileExistsData *data;
8495 /* We need to check whether path exists and is not a folder */
8497 data = g_new0 (struct FileExistsData, 1);
8498 data->impl = g_object_ref (impl);
8499 data->path = gtk_file_path_copy (path);
8500 data->parent_path = gtk_file_path_copy (_gtk_file_chooser_entry_get_current_folder (entry));
8502 if (impl->file_exists_get_info_handle)
8503 gtk_file_system_cancel_operation (impl->file_exists_get_info_handle);
8505 impl->file_exists_get_info_handle =
8506 gtk_file_system_get_info (impl->file_system, path,
8507 GTK_FILE_INFO_IS_FOLDER,
8508 file_exists_get_info_cb,
8511 set_busy_cursor (impl, TRUE);
8515 g_error_free (error);
8518 gtk_file_path_free (path);
8521 else if (impl->toplevel_last_focus_widget == impl->browse_shortcuts_tree_view)
8523 /* The focus is on a dialog's action area button, *and* the widget that
8524 * was focused immediately before it is the shortcuts list. Switch to the
8525 * selected shortcut and tell the caller not to respond.
8529 if (shortcuts_get_selected (impl, &iter))
8531 shortcuts_activate_iter (impl, &iter);
8533 focus_browse_tree_view_if_possible (impl);
8540 else if (impl->toplevel_last_focus_widget == impl->browse_files_tree_view)
8542 /* The focus is on a dialog's action area button, *and* the widget that
8543 * was focused immediately before it is the file list.
8547 else if (impl->operation_mode == OPERATION_MODE_SEARCH && impl->toplevel_last_focus_widget == impl->search_entry)
8549 search_entry_activate_cb (GTK_ENTRY (impl->search_entry), impl);
8552 else if (impl->location_entry && impl->toplevel_last_focus_widget == impl->location_entry)
8554 /* The focus is on a dialog's action area button, *and* the widget that
8555 * was focused immediately before it is the location entry.
8560 /* The focus is on a dialog's action area button or something else */
8561 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
8562 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
8567 g_assert_not_reached ();
8571 /* Implementation for GtkFileChooserEmbed::initial_focus() */
8573 gtk_file_chooser_default_initial_focus (GtkFileChooserEmbed *chooser_embed)
8575 GtkFileChooserDefault *impl;
8578 impl = GTK_FILE_CHOOSER_DEFAULT (chooser_embed);
8580 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
8581 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
8583 if (impl->location_mode == LOCATION_MODE_PATH_BAR)
8584 widget = impl->browse_files_tree_view;
8586 widget = impl->location_entry;
8588 else if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
8589 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
8590 widget = impl->location_entry;
8593 g_assert_not_reached ();
8597 g_assert (widget != NULL);
8598 gtk_widget_grab_focus (widget);
8601 /* Callback used from gtk_tree_selection_selected_foreach(); gets the selected GtkFilePaths */
8603 search_selected_foreach_get_path_cb (GtkTreeModel *model,
8609 const GtkFilePath *file_path;
8610 GtkFilePath *file_path_copy;
8614 gtk_tree_model_get (model, iter, SEARCH_MODEL_COL_PATH, &file_path, -1);
8615 file_path_copy = gtk_file_path_copy (file_path);
8616 *list = g_slist_prepend (*list, file_path_copy);
8619 /* Constructs a list of the selected paths in search mode */
8621 search_get_selected_paths (GtkFileChooserDefault *impl)
8624 GtkTreeSelection *selection;
8628 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
8629 gtk_tree_selection_selected_foreach (selection, search_selected_foreach_get_path_cb, &result);
8630 result = g_slist_reverse (result);
8635 /* Called from ::should_respond(). We return whether there are selected files
8636 * in the search list.
8639 search_should_respond (GtkFileChooserDefault *impl)
8641 GtkTreeSelection *selection;
8643 g_assert (impl->operation_mode == OPERATION_MODE_SEARCH);
8645 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
8646 return (gtk_tree_selection_count_selected_rows (selection) != 0);
8649 struct SearchHitInsertRequest
8651 GtkFileChooserDefault *impl;
8653 GtkTreeRowReference *row_ref;
8657 search_hit_get_info_cb (GtkFileSystemHandle *handle,
8658 const GtkFileInfo *info,
8659 const GError *error,
8662 gboolean cancelled = handle->cancelled;
8663 GdkPixbuf *pixbuf = NULL;
8666 GtkFileSystemHandle *model_handle;
8667 gboolean is_folder = FALSE;
8670 struct SearchHitInsertRequest *request = data;
8672 path = gtk_tree_row_reference_get_path (request->row_ref);
8676 gtk_tree_model_get_iter (GTK_TREE_MODEL (request->impl->search_model),
8678 gtk_tree_path_free (path);
8680 gtk_tree_model_get (GTK_TREE_MODEL (request->impl->search_model), &iter,
8681 SEARCH_MODEL_COL_HANDLE, &model_handle,
8683 if (handle != model_handle)
8686 /* set the handle to NULL in the model */
8687 gtk_list_store_set (request->impl->search_model, &iter,
8688 SEARCH_MODEL_COL_HANDLE, NULL,
8696 gtk_list_store_remove (request->impl->search_model, &iter);
8700 display_name = g_strdup (gtk_file_info_get_display_name (info));
8701 mime_type = g_strdup (gtk_file_info_get_mime_type (info));
8702 is_folder = gtk_file_info_get_is_folder (info);
8703 pixbuf = gtk_file_info_render_icon (info, GTK_WIDGET (request->impl),
8704 request->impl->icon_size, NULL);
8706 gtk_list_store_set (request->impl->search_model, &iter,
8707 SEARCH_MODEL_COL_PIXBUF, pixbuf,
8708 SEARCH_MODEL_COL_DISPLAY_NAME, display_name,
8709 SEARCH_MODEL_COL_MIME_TYPE, mime_type,
8710 SEARCH_MODEL_COL_IS_FOLDER, is_folder,
8714 g_object_unref (pixbuf);
8717 g_object_unref (request->impl);
8718 gtk_file_path_free (request->path);
8719 gtk_tree_row_reference_free (request->row_ref);
8722 g_object_unref (handle);
8725 /* Adds one hit from the search engine to the search_model */
8727 search_add_hit (GtkFileChooserDefault *impl,
8733 char *collation_key;
8734 struct stat statbuf;
8735 struct stat *statbuf_copy;
8738 GtkFileSystemHandle *handle;
8739 struct SearchHitInsertRequest *request;
8741 path = gtk_file_system_uri_to_path (impl->file_system, uri);
8745 filename = gtk_file_system_path_to_filename (impl->file_system, path);
8748 gtk_file_path_free (path);
8752 if (stat (filename, &statbuf) != 0)
8754 gtk_file_path_free (path);
8759 statbuf_copy = g_new (struct stat, 1);
8760 *statbuf_copy = statbuf;
8762 tmp = g_filename_display_name (filename);
8763 collation_key = g_utf8_collate_key_for_filename (tmp, -1);
8766 request = g_new0 (struct SearchHitInsertRequest, 1);
8767 request->impl = g_object_ref (impl);
8768 request->path = gtk_file_path_copy (path);
8770 gtk_list_store_append (impl->search_model, &iter);
8771 p = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->search_model), &iter);
8773 request->row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (impl->search_model), p);
8774 gtk_tree_path_free (p);
8776 handle = gtk_file_system_get_info (impl->file_system, path,
8777 GTK_FILE_INFO_IS_FOLDER | GTK_FILE_INFO_ICON | GTK_FILE_INFO_MIME_TYPE | GTK_FILE_INFO_DISPLAY_NAME,
8778 search_hit_get_info_cb,
8781 gtk_list_store_set (impl->search_model, &iter,
8782 SEARCH_MODEL_COL_PATH, path,
8783 SEARCH_MODEL_COL_COLLATION_KEY, collation_key,
8784 SEARCH_MODEL_COL_STAT, statbuf_copy,
8785 SEARCH_MODEL_COL_HANDLE, handle,
8789 /* Callback used from GtkSearchEngine when we get new hits */
8791 search_engine_hits_added_cb (GtkSearchEngine *engine,
8795 GtkFileChooserDefault *impl;
8798 impl = GTK_FILE_CHOOSER_DEFAULT (data);
8800 for (l = hits; l; l = l->next)
8801 search_add_hit (impl, (gchar*)l->data);
8804 /* Callback used from GtkSearchEngine when the query is done running */
8806 search_engine_finished_cb (GtkSearchEngine *engine,
8809 GtkFileChooserDefault *impl;
8811 impl = GTK_FILE_CHOOSER_DEFAULT (data);
8814 /* EB: setting the model here will avoid loads of row events,
8815 * but it'll make the search look like blocked.
8817 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view),
8818 GTK_TREE_MODEL (impl->search_model_filter));
8821 /* FMQ: if search was empty, say that we got no hits */
8822 set_busy_cursor (impl, FALSE);
8825 /* Displays a generic error when we cannot create a GtkSearchEngine.
8826 * It would be better if _gtk_search_engine_new() gave us a GError
8827 * with a better message, but it doesn't do that right now.
8830 search_error_could_not_create_client (GtkFileChooserDefault *impl)
8832 error_message (impl,
8833 _("Could not start the search process"),
8834 _("The program was not able to create a connection to the indexer "
8835 "daemon. Please make sure it is running."));
8839 search_engine_error_cb (GtkSearchEngine *engine,
8840 const gchar *message,
8843 GtkFileChooserDefault *impl;
8845 impl = GTK_FILE_CHOOSER_DEFAULT (data);
8847 search_stop_searching (impl, TRUE);
8848 error_message (impl, _("Could not send the search request"), message);
8850 set_busy_cursor (impl, FALSE);
8853 /* Frees the data in the search_model */
8855 search_clear_model (GtkFileChooserDefault *impl,
8856 gboolean remove_from_treeview)
8858 GtkTreeModel *model;
8861 if (!impl->search_model)
8864 model = GTK_TREE_MODEL (impl->search_model);
8866 if (gtk_tree_model_get_iter_first (model, &iter))
8870 gchar *display_name;
8871 gchar *collation_key;
8872 struct stat *statbuf;
8873 GtkFileSystemHandle *handle;
8875 gtk_tree_model_get (model, &iter,
8876 SEARCH_MODEL_COL_PATH, &path,
8877 SEARCH_MODEL_COL_DISPLAY_NAME, &display_name,
8878 SEARCH_MODEL_COL_COLLATION_KEY, &collation_key,
8879 SEARCH_MODEL_COL_STAT, &statbuf,
8880 SEARCH_MODEL_COL_HANDLE, &handle,
8884 gtk_file_system_cancel_operation (handle);
8886 gtk_file_path_free (path);
8887 g_free (display_name);
8888 g_free (collation_key);
8891 while (gtk_tree_model_iter_next (model, &iter));
8893 g_object_unref (impl->search_model);
8894 impl->search_model = NULL;
8896 g_object_unref (impl->search_model_filter);
8897 impl->search_model_filter = NULL;
8899 g_object_unref (impl->search_model_sort);
8900 impl->search_model_sort = NULL;
8902 if (remove_from_treeview)
8903 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), NULL);
8906 /* Stops any ongoing searches; does not touch the search_model */
8908 search_stop_searching (GtkFileChooserDefault *impl,
8909 gboolean remove_query)
8911 if (remove_query && impl->search_query)
8913 g_object_unref (impl->search_query);
8914 impl->search_query = NULL;
8917 if (impl->search_engine)
8919 g_object_unref (impl->search_engine);
8920 impl->search_engine = NULL;
8924 /* Stops any pending searches, clears the file list, and switches back to OPERATION_MODE_BROWSE */
8926 search_switch_to_browse_mode (GtkFileChooserDefault *impl)
8928 g_assert (impl->operation_mode != OPERATION_MODE_BROWSE);
8930 search_stop_searching (impl, FALSE);
8931 search_clear_model (impl, TRUE);
8933 gtk_widget_destroy (impl->search_hbox);
8934 impl->search_hbox = NULL;
8935 impl->search_entry = NULL;
8937 gtk_widget_show (impl->browse_path_bar);
8938 gtk_widget_show (impl->browse_new_folder_button);
8940 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
8941 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
8943 gtk_widget_show (impl->location_button);
8945 if (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)
8946 gtk_widget_show (impl->location_entry_box);
8949 impl->operation_mode = OPERATION_MODE_BROWSE;
8951 file_list_set_sort_column_ids (impl);
8954 /* Sort callback from the path column */
8956 search_column_path_sort_func (GtkTreeModel *model,
8961 GtkFileChooserDefault *impl = user_data;
8962 GtkTreeIter child_a, child_b;
8963 const char *collation_key_a, *collation_key_b;
8964 gboolean is_folder_a, is_folder_b;
8966 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_a, a);
8967 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_b, b);
8969 gtk_tree_model_get (GTK_TREE_MODEL (impl->search_model), &child_a,
8970 SEARCH_MODEL_COL_IS_FOLDER, &is_folder_a,
8971 SEARCH_MODEL_COL_COLLATION_KEY, &collation_key_a,
8973 gtk_tree_model_get (GTK_TREE_MODEL (impl->search_model), &child_b,
8974 SEARCH_MODEL_COL_IS_FOLDER, &is_folder_b,
8975 SEARCH_MODEL_COL_COLLATION_KEY, &collation_key_b,
8978 if (!collation_key_a)
8981 if (!collation_key_b)
8984 /* always show folders first */
8985 if (is_folder_a != is_folder_b)
8986 return is_folder_a ? 1 : -1;
8988 return strcmp (collation_key_a, collation_key_b);
8991 /* Sort callback from the modification time column */
8993 search_column_mtime_sort_func (GtkTreeModel *model,
8998 GtkFileChooserDefault *impl = user_data;
8999 GtkTreeIter child_a, child_b;
9000 const struct stat *statbuf_a, *statbuf_b;
9001 gboolean is_folder_a, is_folder_b;
9003 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_a, a);
9004 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_b, b);
9006 /* Note that although we store a whole struct stat in the model, we only
9007 * compare the mtime here. If we add another column relative to a struct stat
9008 * (e.g. a file size column), we'll want another sort callback similar to this
9011 gtk_tree_model_get (GTK_TREE_MODEL (impl->search_model), &child_a,
9012 SEARCH_MODEL_COL_IS_FOLDER, &is_folder_a,
9013 SEARCH_MODEL_COL_STAT, &statbuf_a,
9015 gtk_tree_model_get (GTK_TREE_MODEL (impl->search_model), &child_b,
9016 SEARCH_MODEL_COL_IS_FOLDER, &is_folder_b,
9017 SEARCH_MODEL_COL_STAT, &statbuf_b,
9026 if (is_folder_a != is_folder_b)
9027 return is_folder_a ? 1 : -1;
9029 if (statbuf_a->st_mtime < statbuf_b->st_mtime)
9031 else if (statbuf_a->st_mtime > statbuf_b->st_mtime)
9038 search_get_is_filtered (GtkFileChooserDefault *impl,
9039 const GtkFilePath *path,
9040 const gchar *display_name,
9041 const gchar *mime_type)
9043 GtkFileFilterInfo filter_info;
9044 GtkFileFilterFlags needed;
9047 if (!impl->current_filter)
9050 filter_info.contains = GTK_FILE_FILTER_DISPLAY_NAME | GTK_FILE_FILTER_MIME_TYPE;
9051 needed = gtk_file_filter_get_needed (impl->current_filter);
9053 filter_info.display_name = display_name;
9054 filter_info.mime_type = mime_type;
9056 if (needed & GTK_FILE_FILTER_FILENAME)
9058 filter_info.filename = gtk_file_system_path_to_filename (impl->file_system, path);
9059 if (filter_info.filename)
9060 filter_info.contains |= GTK_FILE_FILTER_FILENAME;
9063 filter_info.filename = NULL;
9065 if (needed & GTK_FILE_FILTER_URI)
9067 filter_info.uri = gtk_file_system_path_to_uri (impl->file_system, path);
9068 if (filter_info.uri)
9069 filter_info.contains |= GTK_FILE_FILTER_URI;
9072 filter_info.uri = NULL;
9074 result = gtk_file_filter_filter (impl->current_filter, &filter_info);
9076 if (filter_info.filename)
9077 g_free ((gchar *) filter_info.filename);
9078 if (filter_info.uri)
9079 g_free ((gchar *) filter_info.uri);
9085 /* Visibility function for the recent filter model */
9087 search_model_visible_func (GtkTreeModel *model,
9091 GtkFileChooserDefault *impl = user_data;
9092 GtkFilePath *file_path;
9093 gchar *display_name, *mime_type;
9096 if (!impl->current_filter)
9099 gtk_tree_model_get (model, iter,
9100 SEARCH_MODEL_COL_PATH, &file_path,
9101 SEARCH_MODEL_COL_IS_FOLDER, &is_folder,
9102 SEARCH_MODEL_COL_DISPLAY_NAME, &display_name,
9103 SEARCH_MODEL_COL_MIME_TYPE, &mime_type,
9112 return !search_get_is_filtered (impl, file_path, display_name, mime_type);
9115 /* Creates the search_model and puts it in the tree view */
9117 search_setup_model (GtkFileChooserDefault *impl)
9119 g_assert (impl->search_model == NULL);
9120 g_assert (impl->search_model_filter == NULL);
9121 g_assert (impl->search_model_sort == NULL);
9123 /* We store these columns in the search model:
9125 * SEARCH_MODEL_COL_PATH - a GtkFilePath for the hit's URI, stored as a
9126 * pointer not as a GTK_TYPE_FILE_PATH
9127 * SEARCH_MODEL_COL_DISPLAY_NAME - a string with the display name, stored
9128 * as a pointer not as a G_TYPE_STRING
9129 * SEARCH_MODEL_COL_COLLATION_KEY - collation key for the filename, stored
9130 * as a pointer not as a G_TYPE_STRING
9131 * SEARCH_MODEL_COL_STAT - pointer to a struct stat
9132 * SEARCH_MODEL_COL_HANDLE - handle used when getting the hit's info
9133 * SEARCH_MODEL_COL_PIXBUF - GdkPixbuf for the hit's icon
9134 * SEARCH_MODEL_COL_MIME_TYPE - a string with the hit's MIME type
9135 * SEARCH_MODEL_COL_IS_FOLDER - a boolean flag for folders
9137 * Keep this in sync with the enumeration defined near the beginning
9140 impl->search_model = gtk_list_store_new (SEARCH_MODEL_COL_NUM_COLUMNS,
9150 impl->search_model_filter =
9151 GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (GTK_TREE_MODEL (impl->search_model), NULL));
9152 gtk_tree_model_filter_set_visible_func (impl->search_model_filter,
9153 search_model_visible_func,
9156 impl->search_model_sort =
9157 GTK_TREE_MODEL_SORT (search_model_sort_new (impl, GTK_TREE_MODEL (impl->search_model_filter)));
9158 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->search_model_sort),
9159 SEARCH_MODEL_COL_PATH,
9160 search_column_path_sort_func,
9162 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->search_model_sort),
9163 SEARCH_MODEL_COL_STAT,
9164 search_column_mtime_sort_func,
9166 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (impl->search_model_sort),
9167 SEARCH_MODEL_COL_STAT,
9168 GTK_SORT_DESCENDING);
9170 /* EB: setting the model here will make the hits list update feel
9171 * more "alive" than setting the model at the end of the search
9174 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view),
9175 GTK_TREE_MODEL (impl->search_model_sort));
9179 search_get_valid_child_iter (GtkFileChooserDefault *impl,
9180 GtkTreeIter *child_iter,
9185 if (!impl->search_model)
9188 if (!impl->search_model_filter || !impl->search_model_sort)
9191 /* pass 1: get the iterator in the filter model */
9192 gtk_tree_model_sort_convert_iter_to_child_iter (impl->search_model_sort,
9195 /* pass 2: get the iterator in the real model */
9196 gtk_tree_model_filter_convert_iter_to_child_iter (impl->search_model_filter,
9197 child_iter, &middle);
9200 /* Creates a new query with the specified text and launches it */
9202 search_start_query (GtkFileChooserDefault *impl,
9203 const gchar *query_text)
9205 search_stop_searching (impl, FALSE);
9206 search_clear_model (impl, TRUE);
9207 search_setup_model (impl);
9208 set_busy_cursor (impl, TRUE);
9210 if (impl->search_engine == NULL)
9211 impl->search_engine = _gtk_search_engine_new ();
9213 if (!impl->search_engine)
9215 set_busy_cursor (impl, FALSE);
9216 search_error_could_not_create_client (impl); /* lame; we don't get an error code or anything */
9220 if (!impl->search_query)
9222 impl->search_query = _gtk_query_new ();
9223 _gtk_query_set_text (impl->search_query, query_text);
9226 _gtk_search_engine_set_query (impl->search_engine, impl->search_query);
9228 g_signal_connect (impl->search_engine, "hits-added",
9229 G_CALLBACK (search_engine_hits_added_cb), impl);
9230 g_signal_connect (impl->search_engine, "finished",
9231 G_CALLBACK (search_engine_finished_cb), impl);
9232 g_signal_connect (impl->search_engine, "error",
9233 G_CALLBACK (search_engine_error_cb), impl);
9235 _gtk_search_engine_start (impl->search_engine);
9238 /* Callback used when the user presses Enter while typing on the search
9239 * entry; starts the query
9242 search_entry_activate_cb (GtkEntry *entry,
9245 GtkFileChooserDefault *impl;
9248 impl = GTK_FILE_CHOOSER_DEFAULT (data);
9250 text = gtk_entry_get_text (GTK_ENTRY (impl->search_entry));
9251 if (strlen (text) == 0)
9254 /* reset any existing query object */
9255 if (impl->search_query)
9257 g_object_unref (impl->search_query);
9258 impl->search_query = NULL;
9261 search_start_query (impl, text);
9264 /* Hides the path bar and creates the search entry */
9266 search_setup_widgets (GtkFileChooserDefault *impl)
9270 impl->search_hbox = gtk_hbox_new (FALSE, 12);
9274 label = gtk_label_new_with_mnemonic (_("_Search:"));
9275 gtk_box_pack_start (GTK_BOX (impl->search_hbox), label, FALSE, FALSE, 0);
9279 impl->search_entry = gtk_entry_new ();
9280 gtk_label_set_mnemonic_widget (GTK_LABEL (label), impl->search_entry);
9281 g_signal_connect (impl->search_entry, "activate",
9282 G_CALLBACK (search_entry_activate_cb),
9284 gtk_box_pack_start (GTK_BOX (impl->search_hbox), impl->search_entry, TRUE, TRUE, 0);
9286 /* if there already is a query, restart it */
9287 if (impl->search_query)
9289 gchar *query = _gtk_query_get_text (impl->search_query);
9293 gtk_entry_set_text (GTK_ENTRY (impl->search_entry), query);
9294 search_start_query (impl, query);
9300 g_object_unref (impl->search_query);
9301 impl->search_query = NULL;
9305 gtk_widget_hide (impl->browse_path_bar);
9306 gtk_widget_hide (impl->browse_new_folder_button);
9308 /* Box for search widgets */
9309 gtk_box_pack_start (GTK_BOX (impl->browse_path_bar_hbox), impl->search_hbox, TRUE, TRUE, 0);
9310 gtk_widget_show_all (impl->search_hbox);
9312 /* Hide the location widgets temporarily */
9314 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
9315 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
9317 gtk_widget_hide (impl->location_button);
9318 gtk_widget_hide (impl->location_entry_box);
9321 gtk_widget_grab_focus (impl->search_entry);
9323 /* FMQ: hide the filter combo? */
9326 /* Main entry point to the searching functions; this gets called when the user
9327 * activates the Search shortcut.
9330 search_activate (GtkFileChooserDefault *impl)
9332 OperationMode previous_mode;
9334 if (impl->operation_mode == OPERATION_MODE_SEARCH)
9336 gtk_widget_grab_focus (impl->search_entry);
9340 previous_mode = impl->operation_mode;
9341 impl->operation_mode = OPERATION_MODE_SEARCH;
9343 switch (previous_mode)
9345 case OPERATION_MODE_RECENT:
9346 recent_stop_loading (impl);
9347 recent_clear_model (impl, TRUE);
9350 case OPERATION_MODE_BROWSE:
9351 stop_loading_and_clear_list_model (impl);
9354 case OPERATION_MODE_SEARCH:
9355 g_assert_not_reached ();
9359 g_assert (impl->search_hbox == NULL);
9360 g_assert (impl->search_entry == NULL);
9361 g_assert (impl->search_model == NULL);
9362 g_assert (impl->search_model_filter == NULL);
9364 search_setup_widgets (impl);
9365 file_list_set_sort_column_ids (impl);
9369 * Recent files support
9372 /* Frees the data in the recent_model */
9374 recent_clear_model (GtkFileChooserDefault *impl,
9375 gboolean remove_from_treeview)
9377 GtkTreeModel *model;
9380 if (!impl->recent_model)
9383 model = GTK_TREE_MODEL (impl->recent_model);
9385 if (gtk_tree_model_get_iter_first (model, &iter))
9389 GtkFilePath *file_path;
9390 GtkFileSystemHandle *handle;
9391 GtkRecentInfo *recent_info;
9392 gchar *display_name;
9394 gtk_tree_model_get (model, &iter,
9395 RECENT_MODEL_COL_DISPLAY_NAME, &display_name,
9396 RECENT_MODEL_COL_PATH, &file_path,
9397 RECENT_MODEL_COL_HANDLE, &handle,
9398 RECENT_MODEL_COL_INFO, &recent_info,
9402 gtk_file_system_cancel_operation (handle);
9404 gtk_file_path_free (file_path);
9405 gtk_recent_info_unref (recent_info);
9406 g_free (display_name);
9408 while (gtk_tree_model_iter_next (model, &iter));
9411 g_object_unref (impl->recent_model);
9412 impl->recent_model = NULL;
9414 g_object_unref (impl->recent_model_filter);
9415 impl->recent_model_filter = NULL;
9417 g_object_unref (impl->recent_model_sort);
9418 impl->recent_model_sort = NULL;
9420 if (remove_from_treeview)
9421 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), NULL);
9424 /* Stops any ongoing loading of the recent files list; does
9425 * not touch the recent_model
9428 recent_stop_loading (GtkFileChooserDefault *impl)
9430 if (impl->load_recent_id)
9432 g_source_remove (impl->load_recent_id);
9433 impl->load_recent_id = 0;
9437 /* Stops any pending load, clears the file list, and switches
9438 * back to OPERATION_MODE_BROWSE
9441 recent_switch_to_browse_mode (GtkFileChooserDefault *impl)
9443 g_assert (impl->operation_mode != OPERATION_MODE_BROWSE);
9445 recent_stop_loading (impl);
9446 recent_clear_model (impl, TRUE);
9448 gtk_widget_show (impl->browse_path_bar);
9449 gtk_widget_show (impl->browse_new_folder_button);
9451 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
9452 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
9454 gtk_widget_show (impl->location_button);
9456 if (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)
9457 gtk_widget_show (impl->location_entry_box);
9460 impl->operation_mode = OPERATION_MODE_BROWSE;
9462 file_list_set_sort_column_ids (impl);
9465 /* Sort callback from the modification time column */
9467 recent_column_mtime_sort_func (GtkTreeModel *model,
9472 GtkFileChooserDefault *impl = user_data;
9473 GtkTreeIter child_a, child_b;
9474 GtkRecentInfo *info_a, *info_b;
9475 gboolean is_folder_a, is_folder_b;
9477 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_a, a);
9478 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_b, b);
9480 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &child_a,
9481 RECENT_MODEL_COL_IS_FOLDER, &is_folder_a,
9482 RECENT_MODEL_COL_INFO, &info_a,
9484 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &child_b,
9485 RECENT_MODEL_COL_IS_FOLDER, &is_folder_b,
9486 RECENT_MODEL_COL_INFO, &info_b,
9495 /* folders always go first */
9496 if (is_folder_a != is_folder_b)
9497 return is_folder_a ? 1 : -1;
9499 if (gtk_recent_info_get_modified (info_a) < gtk_recent_info_get_modified (info_b))
9501 else if (gtk_recent_info_get_modified (info_a) > gtk_recent_info_get_modified (info_b))
9508 recent_column_path_sort_func (GtkTreeModel *model,
9513 GtkFileChooserDefault *impl = user_data;
9514 GtkTreeIter child_a, child_b;
9515 gboolean is_folder_a, is_folder_b;
9516 gchar *name_a, *name_b;
9518 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_a, a);
9519 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_b, b);
9521 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &child_a,
9522 RECENT_MODEL_COL_IS_FOLDER, &is_folder_a,
9523 RECENT_MODEL_COL_DISPLAY_NAME, &name_a,
9525 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &child_b,
9526 RECENT_MODEL_COL_IS_FOLDER, &is_folder_b,
9527 RECENT_MODEL_COL_DISPLAY_NAME, &name_b,
9536 if (is_folder_a != is_folder_b)
9537 return is_folder_a ? 1 : -1;
9539 return strcmp (name_a, name_b);
9543 recent_get_is_filtered (GtkFileChooserDefault *impl,
9544 const GtkFilePath *path,
9545 GtkRecentInfo *recent_info)
9547 GtkFileFilterInfo filter_info;
9548 GtkFileFilterFlags needed;
9551 if (!impl->current_filter)
9554 filter_info.contains = GTK_FILE_FILTER_DISPLAY_NAME | GTK_FILE_FILTER_MIME_TYPE;
9555 needed = gtk_file_filter_get_needed (impl->current_filter);
9557 filter_info.display_name = gtk_recent_info_get_display_name (recent_info);
9558 filter_info.mime_type = gtk_recent_info_get_mime_type (recent_info);
9560 if (needed & GTK_FILE_FILTER_FILENAME)
9562 filter_info.filename = gtk_file_system_path_to_filename (impl->file_system, path);
9563 if (filter_info.filename)
9564 filter_info.contains |= GTK_FILE_FILTER_FILENAME;
9567 filter_info.filename = NULL;
9569 if (needed & GTK_FILE_FILTER_URI)
9571 filter_info.uri = gtk_file_system_path_to_uri (impl->file_system, path);
9572 if (filter_info.uri)
9573 filter_info.contains |= GTK_FILE_FILTER_URI;
9576 filter_info.uri = NULL;
9578 result = gtk_file_filter_filter (impl->current_filter, &filter_info);
9580 if (filter_info.filename)
9581 g_free ((gchar *) filter_info.filename);
9582 if (filter_info.uri)
9583 g_free ((gchar *) filter_info.uri);
9588 /* Visibility function for the recent filter model */
9590 recent_model_visible_func (GtkTreeModel *model,
9594 GtkFileChooserDefault *impl = user_data;
9595 GtkFilePath *file_path;
9596 GtkRecentInfo *recent_info;
9599 if (!impl->current_filter)
9602 gtk_tree_model_get (model, iter,
9603 RECENT_MODEL_COL_INFO, &recent_info,
9604 RECENT_MODEL_COL_PATH, &file_path,
9605 RECENT_MODEL_COL_IS_FOLDER, &is_folder,
9614 return !recent_get_is_filtered (impl, file_path, recent_info);
9618 recent_setup_model (GtkFileChooserDefault *impl)
9620 g_assert (impl->recent_model == NULL);
9621 g_assert (impl->recent_model_filter == NULL);
9622 g_assert (impl->recent_model_sort == NULL);
9624 /* We store these columns in the search model:
9626 * RECENT_MODEL_COL_PATH - a pointer to GtkFilePath for the hit's URI,
9627 * stored as a pointer and not as a GTK_TYPE_FILE_PATH;
9628 * RECENT_MODEL_COL_DISPLAY_NAME - a string with the display name,
9629 * stored as a pointer and not as a G_TYPE_STRING;
9630 * RECENT_MODEL_COL_INFO - GtkRecentInfo, stored as a pointer and not
9631 * as a GTK_TYPE_RECENT_INFO;
9632 * RECENT_MODEL_COL_IS_FOLDER - boolean flag;
9633 * RECENT_MODEL_COL_HANDLE - GtkFileSystemHandle, stored as a pointer
9634 * and not as a GTK_TYPE_FILE_SYSTEM_HANDLE;
9636 * Keep this in sync with the enumeration defined near the beginning of
9639 impl->recent_model = gtk_list_store_new (RECENT_MODEL_COL_NUM_COLUMNS,
9646 impl->recent_model_filter =
9647 GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (GTK_TREE_MODEL (impl->recent_model), NULL));
9648 gtk_tree_model_filter_set_visible_func (impl->recent_model_filter,
9649 recent_model_visible_func,
9653 /* this is the model that will actually be added to
9654 * the browse_files_tree_view widget; remember: we are
9655 * stuffing the real model into a filter model and then
9656 * into a sort model; this means we'll have to translate
9657 * the child iterator *twice* to get from a path or an
9658 * iterator coming from the tree view widget to the
9659 * real data inside the model.
9661 impl->recent_model_sort =
9662 GTK_TREE_MODEL_SORT (recent_model_sort_new (impl, GTK_TREE_MODEL (impl->recent_model_filter)));
9663 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->recent_model_sort),
9664 RECENT_MODEL_COL_PATH,
9665 recent_column_path_sort_func,
9667 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->recent_model_sort),
9668 RECENT_MODEL_COL_INFO,
9669 recent_column_mtime_sort_func,
9671 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (impl->recent_model_sort),
9672 RECENT_MODEL_COL_INFO,
9673 GTK_SORT_DESCENDING);
9675 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view),
9676 GTK_TREE_MODEL (impl->recent_model_sort));
9681 GtkFileChooserDefault *impl;
9684 gint n_loaded_items;
9688 recent_idle_cleanup (gpointer data)
9690 RecentLoadData *load_data = data;
9691 GtkFileChooserDefault *impl = load_data->impl;
9693 set_busy_cursor (impl, FALSE);
9695 impl->load_recent_id = 0;
9697 if (load_data->items)
9699 g_list_foreach (load_data->items, (GFunc) gtk_recent_info_unref, NULL);
9700 g_list_free (load_data->items);
9706 struct RecentItemInsertRequest
9708 GtkFileChooserDefault *impl;
9710 GtkTreeRowReference *row_ref;
9714 recent_item_get_info_cb (GtkFileSystemHandle *handle,
9715 const GtkFileInfo *info,
9716 const GError *error,
9719 gboolean cancelled = handle->cancelled;
9722 GtkFileSystemHandle *model_handle;
9723 gboolean is_folder = FALSE;
9724 struct RecentItemInsertRequest *request = data;
9726 path = gtk_tree_row_reference_get_path (request->row_ref);
9730 gtk_tree_model_get_iter (GTK_TREE_MODEL (request->impl->recent_model),
9732 gtk_tree_path_free (path);
9734 gtk_tree_model_get (GTK_TREE_MODEL (request->impl->recent_model), &iter,
9735 RECENT_MODEL_COL_HANDLE, &model_handle,
9737 if (handle != model_handle)
9740 gtk_list_store_set (request->impl->recent_model, &iter,
9741 RECENT_MODEL_COL_HANDLE, NULL,
9749 gtk_list_store_remove (request->impl->recent_model, &iter);
9753 is_folder = gtk_file_info_get_is_folder (info);
9755 gtk_list_store_set (request->impl->recent_model, &iter,
9756 RECENT_MODEL_COL_IS_FOLDER, is_folder,
9760 g_object_unref (request->impl);
9761 gtk_file_path_free (request->path);
9762 gtk_tree_row_reference_free (request->row_ref);
9765 g_object_unref (handle);
9769 recent_idle_load (gpointer data)
9771 RecentLoadData *load_data = data;
9772 GtkFileChooserDefault *impl = load_data->impl;
9775 GtkRecentInfo *info;
9776 const gchar *uri, *display_name;
9778 GtkFileSystemHandle *handle;
9779 struct RecentItemInsertRequest *request;
9781 if (!impl->recent_manager)
9784 if (!load_data->items)
9786 load_data->items = gtk_recent_manager_get_items (impl->recent_manager);
9787 load_data->n_items = g_list_length (load_data->items);
9788 load_data->n_loaded_items = 0;
9793 info = g_list_nth_data (load_data->items, load_data->n_loaded_items);
9794 g_assert (info != NULL);
9796 uri = gtk_recent_info_get_uri (info);
9797 display_name = gtk_recent_info_get_display_name (info);
9798 path = gtk_file_system_uri_to_path (impl->file_system, uri);
9802 gtk_list_store_append (impl->recent_model, &iter);
9803 p = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->recent_model), &iter);
9805 request = g_new0 (struct RecentItemInsertRequest, 1);
9806 request->impl = g_object_ref (impl);
9807 request->path = gtk_file_path_copy (path);
9808 request->row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (impl->recent_model), p);
9809 gtk_tree_path_free (p);
9811 handle = gtk_file_system_get_info (impl->file_system, path,
9812 GTK_FILE_INFO_IS_FOLDER,
9813 recent_item_get_info_cb,
9816 gtk_list_store_set (impl->recent_model, &iter,
9817 RECENT_MODEL_COL_PATH, path,
9818 RECENT_MODEL_COL_DISPLAY_NAME, g_strdup (display_name),
9819 RECENT_MODEL_COL_INFO, gtk_recent_info_ref (info),
9820 RECENT_MODEL_COL_HANDLE, handle,
9825 load_data->n_loaded_items += 1;
9827 /* finished loading items */
9828 if (load_data->n_loaded_items == load_data->n_items)
9830 g_list_foreach (load_data->items, (GFunc) gtk_recent_info_unref, NULL);
9831 g_list_free (load_data->items);
9832 load_data->items = NULL;
9841 recent_start_loading (GtkFileChooserDefault *impl)
9843 RecentLoadData *load_data;
9845 recent_stop_loading (impl);
9846 recent_clear_model (impl, TRUE);
9847 recent_setup_model (impl);
9848 set_busy_cursor (impl, TRUE);
9850 if (!impl->recent_manager)
9851 recent_manager_update (impl);
9853 g_assert (impl->load_recent_id == 0);
9855 load_data = g_new (RecentLoadData, 1);
9856 load_data->impl = impl;
9857 load_data->items = NULL;
9858 load_data->n_items = 0;
9859 load_data->n_loaded_items = 0;
9861 /* begin lazy loading the recent files into the model */
9862 impl->load_recent_id = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 30,
9865 recent_idle_cleanup);
9869 recent_selected_foreach_get_path_cb (GtkTreeModel *model,
9875 const GtkFilePath *file_path;
9876 GtkFilePath *file_path_copy;
9880 gtk_tree_model_get (model, iter, RECENT_MODEL_COL_PATH, &file_path, -1);
9881 file_path_copy = gtk_file_path_copy (file_path);
9882 *list = g_slist_prepend (*list, file_path_copy);
9885 /* Constructs a list of the selected paths in recent files mode */
9887 recent_get_selected_paths (GtkFileChooserDefault *impl)
9890 GtkTreeSelection *selection;
9894 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
9895 gtk_tree_selection_selected_foreach (selection, recent_selected_foreach_get_path_cb, &result);
9896 result = g_slist_reverse (result);
9901 /* Called from ::should_respond(). We return whether there are selected
9902 * files in the recent files list.
9905 recent_should_respond (GtkFileChooserDefault *impl)
9907 GtkTreeSelection *selection;
9909 g_assert (impl->operation_mode == OPERATION_MODE_RECENT);
9911 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
9912 return (gtk_tree_selection_count_selected_rows (selection) != 0);
9915 /* Hide the location widgets temporarily */
9917 recent_hide_entry (GtkFileChooserDefault *impl)
9919 gtk_widget_hide (impl->browse_path_bar);
9920 gtk_widget_hide (impl->browse_new_folder_button);
9922 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
9923 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
9925 gtk_widget_hide (impl->location_button);
9926 gtk_widget_hide (impl->location_entry_box);
9930 /* Main entry point to the recent files functions; this gets called when
9931 * the user activates the Recently Used shortcut.
9934 recent_activate (GtkFileChooserDefault *impl)
9936 OperationMode previous_mode;
9938 if (impl->operation_mode == OPERATION_MODE_RECENT)
9941 previous_mode = impl->operation_mode;
9942 impl->operation_mode = OPERATION_MODE_RECENT;
9944 switch (previous_mode)
9946 case OPERATION_MODE_SEARCH:
9947 search_stop_searching (impl, FALSE);
9948 search_clear_model (impl, TRUE);
9950 gtk_widget_destroy (impl->search_hbox);
9951 impl->search_hbox = NULL;
9952 impl->search_entry = NULL;
9955 case OPERATION_MODE_BROWSE:
9956 stop_loading_and_clear_list_model (impl);
9959 case OPERATION_MODE_RECENT:
9960 g_assert_not_reached ();
9964 recent_hide_entry (impl);
9965 file_list_set_sort_column_ids (impl);
9966 recent_start_loading (impl);
9969 /* convert an iterator coming from the model bound to
9970 * browse_files_tree_view to an interator inside the
9974 recent_get_valid_child_iter (GtkFileChooserDefault *impl,
9975 GtkTreeIter *child_iter,
9980 if (!impl->recent_model)
9983 if (!impl->recent_model_filter || !impl->recent_model_sort)
9986 /* pass 1: get the iterator in the filter model */
9987 gtk_tree_model_sort_convert_iter_to_child_iter (impl->recent_model_sort,
9990 /* pass 2: get the iterator in the real model */
9991 gtk_tree_model_filter_convert_iter_to_child_iter (impl->recent_model_filter,
9998 set_current_filter (GtkFileChooserDefault *impl,
9999 GtkFileFilter *filter)
10001 if (impl->current_filter != filter)
10005 /* NULL filters are allowed to reset to non-filtered status
10007 filter_index = g_slist_index (impl->filters, filter);
10008 if (impl->filters && filter && filter_index < 0)
10011 if (impl->current_filter)
10012 g_object_unref (impl->current_filter);
10013 impl->current_filter = filter;
10014 if (impl->current_filter)
10016 g_object_ref_sink (impl->current_filter);
10020 gtk_combo_box_set_active (GTK_COMBO_BOX (impl->filter_combo),
10023 if (impl->browse_files_model)
10024 install_list_model_filter (impl);
10026 if (impl->search_model_filter)
10027 gtk_tree_model_filter_refilter (impl->search_model_filter);
10029 if (impl->recent_model_filter)
10030 gtk_tree_model_filter_refilter (impl->recent_model_filter);
10032 g_object_notify (G_OBJECT (impl), "filter");
10037 filter_combo_changed (GtkComboBox *combo_box,
10038 GtkFileChooserDefault *impl)
10040 gint new_index = gtk_combo_box_get_active (combo_box);
10041 GtkFileFilter *new_filter = g_slist_nth_data (impl->filters, new_index);
10043 set_current_filter (impl, new_filter);
10047 check_preview_change (GtkFileChooserDefault *impl)
10049 GtkTreePath *cursor_path;
10050 const GtkFilePath *new_path;
10051 const char *new_display_name;
10053 gtk_tree_view_get_cursor (GTK_TREE_VIEW (impl->browse_files_tree_view), &cursor_path, NULL);
10055 new_display_name = NULL;
10058 GtkTreeIter child_iter;
10060 if (impl->operation_mode == OPERATION_MODE_BROWSE)
10062 if (impl->sort_model)
10065 const GtkFileInfo *new_info;
10067 gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->sort_model), &iter, cursor_path);
10068 gtk_tree_path_free (cursor_path);
10070 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model, &child_iter, &iter);
10072 new_path = _gtk_file_system_model_get_path (impl->browse_files_model, &child_iter);
10073 new_info = _gtk_file_system_model_get_info (impl->browse_files_model, &child_iter);
10075 new_display_name = gtk_file_info_get_display_name (new_info);
10078 else if (impl->operation_mode == OPERATION_MODE_SEARCH)
10082 gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->search_model_sort),
10083 &iter, cursor_path);
10084 gtk_tree_path_free (cursor_path);
10086 search_get_valid_child_iter (impl, &child_iter, &iter);
10087 gtk_tree_model_get (GTK_TREE_MODEL (impl->search_model), &child_iter,
10088 SEARCH_MODEL_COL_PATH, &new_path,
10089 SEARCH_MODEL_COL_DISPLAY_NAME, &new_display_name,
10092 else if (impl->operation_mode == OPERATION_MODE_RECENT)
10096 gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->recent_model_sort),
10097 &iter, cursor_path);
10098 gtk_tree_path_free (cursor_path);
10100 recent_get_valid_child_iter (impl, &child_iter, &iter);
10101 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &child_iter,
10102 RECENT_MODEL_COL_PATH, &new_path,
10103 RECENT_MODEL_COL_DISPLAY_NAME, &new_display_name,
10108 if (new_path != impl->preview_path &&
10109 !(new_path && impl->preview_path &&
10110 gtk_file_path_compare (new_path, impl->preview_path) == 0))
10112 if (impl->preview_path)
10114 gtk_file_path_free (impl->preview_path);
10115 g_free (impl->preview_display_name);
10120 impl->preview_path = gtk_file_path_copy (new_path);
10121 impl->preview_display_name = g_strdup (new_display_name);
10125 impl->preview_path = NULL;
10126 impl->preview_display_name = NULL;
10129 if (impl->use_preview_label && impl->preview_label)
10130 gtk_label_set_text (GTK_LABEL (impl->preview_label), impl->preview_display_name);
10132 g_signal_emit_by_name (impl, "update-preview");
10137 shortcuts_activate_volume_mount_cb (GtkFileSystemHandle *handle,
10138 GtkFileSystemVolume *volume,
10139 const GError *error,
10143 gboolean cancelled = handle->cancelled;
10144 GtkFileChooserDefault *impl = data;
10146 if (handle != impl->shortcuts_activate_iter_handle)
10149 impl->shortcuts_activate_iter_handle = NULL;
10151 set_busy_cursor (impl, FALSE);
10160 msg = g_strdup_printf (_("Could not mount %s"),
10161 gtk_file_system_volume_get_display_name (impl->file_system, volume));
10162 error_message (impl, msg, error->message);
10168 path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
10171 change_folder_and_display_error (impl, path, FALSE);
10172 focus_browse_tree_view_if_possible (impl);
10174 gtk_file_path_free (path);
10178 g_object_unref (impl);
10179 g_object_unref (handle);
10183 /* Activates a volume by mounting it if necessary and then switching to its
10187 shortcuts_activate_volume (GtkFileChooserDefault *impl,
10188 GtkFileSystemVolume *volume)
10192 switch (impl->operation_mode)
10194 case OPERATION_MODE_BROWSE:
10196 case OPERATION_MODE_SEARCH:
10197 search_switch_to_browse_mode (impl);
10199 case OPERATION_MODE_RECENT:
10200 recent_switch_to_browse_mode (impl);
10204 /* We ref the file chooser since volume_mount() may run a main loop, and the
10205 * user could close the file chooser window in the meantime.
10207 g_object_ref (impl);
10209 if (!gtk_file_system_volume_get_is_mounted (impl->file_system, volume))
10211 set_busy_cursor (impl, TRUE);
10213 impl->shortcuts_activate_iter_handle =
10214 gtk_file_system_volume_mount (impl->file_system, volume,
10215 shortcuts_activate_volume_mount_cb,
10216 g_object_ref (impl));
10220 path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
10223 change_folder_and_display_error (impl, path, FALSE);
10224 gtk_file_path_free (path);
10228 g_object_unref (impl);
10231 /* Opens the folder or volume at the specified iter in the shortcuts model */
10232 struct ShortcutsActivateData
10234 GtkFileChooserDefault *impl;
10239 shortcuts_activate_get_info_cb (GtkFileSystemHandle *handle,
10240 const GtkFileInfo *info,
10241 const GError *error,
10242 gpointer user_data)
10244 gboolean cancelled = handle->cancelled;
10245 struct ShortcutsActivateData *data = user_data;
10247 if (handle != data->impl->shortcuts_activate_iter_handle)
10250 data->impl->shortcuts_activate_iter_handle = NULL;
10255 if (!error && gtk_file_info_get_is_folder (info))
10257 change_folder_and_display_error (data->impl, data->path, FALSE);
10258 focus_browse_tree_view_if_possible (data->impl);
10261 gtk_file_chooser_default_select_path (GTK_FILE_CHOOSER (data->impl),
10266 g_object_unref (data->impl);
10267 gtk_file_path_free (data->path);
10270 g_object_unref (handle);
10274 shortcuts_activate_iter (GtkFileChooserDefault *impl,
10278 ShortcutType shortcut_type;
10280 if (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY && impl->action != GTK_FILE_CHOOSER_ACTION_SAVE)
10281 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), "");
10283 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), iter,
10284 SHORTCUTS_COL_DATA, &col_data,
10285 SHORTCUTS_COL_TYPE, &shortcut_type,
10288 if (impl->shortcuts_activate_iter_handle)
10290 gtk_file_system_cancel_operation (impl->shortcuts_activate_iter_handle);
10291 impl->shortcuts_activate_iter_handle = NULL;
10294 if (shortcut_type == SHORTCUT_TYPE_SEPARATOR)
10296 else if (shortcut_type == SHORTCUT_TYPE_VOLUME)
10298 GtkFileSystemVolume *volume;
10302 shortcuts_activate_volume (impl, volume);
10304 else if (shortcut_type == SHORTCUT_TYPE_PATH)
10306 struct ShortcutsActivateData *data;
10308 data = g_new0 (struct ShortcutsActivateData, 1);
10309 data->impl = g_object_ref (impl);
10310 data->path = gtk_file_path_copy (col_data);
10312 impl->shortcuts_activate_iter_handle =
10313 gtk_file_system_get_info (impl->file_system, data->path,
10314 GTK_FILE_INFO_IS_FOLDER,
10315 shortcuts_activate_get_info_cb, data);
10317 else if (shortcut_type == SHORTCUT_TYPE_SEARCH)
10319 search_activate (impl);
10321 else if (shortcut_type == SHORTCUT_TYPE_RECENT)
10323 recent_activate (impl);
10327 /* Callback used when a row in the shortcuts list is activated */
10329 shortcuts_row_activated_cb (GtkTreeView *tree_view,
10331 GtkTreeViewColumn *column,
10332 GtkFileChooserDefault *impl)
10335 GtkTreeIter child_iter;
10337 if (!gtk_tree_model_get_iter (impl->shortcuts_pane_filter_model, &iter, path))
10340 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (impl->shortcuts_pane_filter_model),
10343 shortcuts_activate_iter (impl, &child_iter);
10346 /* Handler for GtkWidget::key-press-event on the shortcuts list */
10348 shortcuts_key_press_event_cb (GtkWidget *widget,
10349 GdkEventKey *event,
10350 GtkFileChooserDefault *impl)
10354 modifiers = gtk_accelerator_get_default_mod_mask ();
10356 if ((event->keyval == GDK_BackSpace
10357 || event->keyval == GDK_Delete
10358 || event->keyval == GDK_KP_Delete)
10359 && (event->state & modifiers) == 0)
10361 remove_selected_bookmarks (impl);
10365 if ((event->keyval == GDK_F2)
10366 && (event->state & modifiers) == 0)
10368 rename_selected_bookmark (impl);
10376 shortcuts_select_func (GtkTreeSelection *selection,
10377 GtkTreeModel *model,
10379 gboolean path_currently_selected,
10382 GtkFileChooserDefault *impl = data;
10383 GtkTreeIter filter_iter;
10384 ShortcutType shortcut_type;
10386 if (!gtk_tree_model_get_iter (impl->shortcuts_pane_filter_model, &filter_iter, path))
10387 g_assert_not_reached ();
10389 gtk_tree_model_get (impl->shortcuts_pane_filter_model, &filter_iter, SHORTCUTS_COL_TYPE, &shortcut_type, -1);
10391 return shortcut_type != SHORTCUT_TYPE_SEPARATOR;
10395 list_select_func (GtkTreeSelection *selection,
10396 GtkTreeModel *model,
10398 gboolean path_currently_selected,
10401 GtkFileChooserDefault *impl = data;
10403 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
10404 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
10406 GtkTreeIter iter, child_iter;
10408 switch (impl->operation_mode)
10410 case OPERATION_MODE_SEARCH:
10412 gboolean is_folder;
10414 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->search_model_sort), &iter, path))
10417 search_get_valid_child_iter (impl, &child_iter, &iter);
10418 gtk_tree_model_get (GTK_TREE_MODEL (impl->search_model), &child_iter,
10419 SEARCH_MODEL_COL_IS_FOLDER, &is_folder,
10426 case OPERATION_MODE_RECENT:
10428 gboolean is_folder;
10430 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->recent_model_sort), &iter, path))
10433 recent_get_valid_child_iter (impl, &child_iter, &iter);
10434 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &child_iter,
10435 RECENT_MODEL_COL_IS_FOLDER, &is_folder,
10442 case OPERATION_MODE_BROWSE:
10444 const GtkFileInfo *info;
10446 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->sort_model), &iter, path))
10449 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model, &child_iter, &iter);
10450 info = _gtk_file_system_model_get_info (impl->browse_files_model, &child_iter);
10451 if (info && !gtk_file_info_get_is_folder (info))
10462 list_selection_changed (GtkTreeSelection *selection,
10463 GtkFileChooserDefault *impl)
10465 /* See if we are in the new folder editable row for Save mode */
10466 if (impl->operation_mode == OPERATION_MODE_BROWSE &&
10467 impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
10469 const GtkFileInfo *info;
10470 gboolean had_selection;
10472 info = get_selected_file_info_from_file_list (impl, &had_selection);
10473 if (!had_selection)
10474 goto out; /* normal processing */
10477 return; /* We are on the editable row for New Folder */
10482 /* TODO - Change the following functions to make them accept MODE_SEARCH */
10483 if (impl->location_entry)
10484 update_chooser_entry (impl);
10486 check_preview_change (impl);
10487 bookmarks_check_add_sensitivity (impl);
10489 g_signal_emit_by_name (impl, "selection-changed", 0);
10492 /* Callback used when a row in the file list is activated */
10494 list_row_activated (GtkTreeView *tree_view,
10496 GtkTreeViewColumn *column,
10497 GtkFileChooserDefault *impl)
10500 GtkTreeIter child_iter;
10502 switch (impl->operation_mode)
10504 case OPERATION_MODE_SEARCH:
10506 GtkFilePath *file_path;
10507 gboolean is_folder;
10509 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->search_model_sort), &iter, path))
10512 search_get_valid_child_iter (impl, &child_iter, &iter);
10513 gtk_tree_model_get (GTK_TREE_MODEL (impl->search_model), &child_iter,
10514 SEARCH_MODEL_COL_PATH, &file_path,
10515 SEARCH_MODEL_COL_IS_FOLDER, &is_folder,
10520 change_folder_and_display_error (impl, file_path, FALSE);
10524 g_signal_emit_by_name (impl, "file-activated");
10528 case OPERATION_MODE_RECENT:
10530 GtkFilePath *file_path;
10531 gboolean is_folder;
10533 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->recent_model_sort), &iter, path))
10536 recent_get_valid_child_iter (impl, &child_iter, &iter);
10537 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &child_iter,
10538 RECENT_MODEL_COL_PATH, &file_path,
10539 RECENT_MODEL_COL_IS_FOLDER, &is_folder,
10544 change_folder_and_display_error (impl, file_path, FALSE);
10548 g_signal_emit_by_name (impl, "file-activated");
10552 case OPERATION_MODE_BROWSE:
10554 const GtkFileInfo *info;
10556 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->sort_model), &iter, path))
10559 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
10560 &child_iter, &iter);
10561 info = _gtk_file_system_model_get_info (impl->browse_files_model,
10564 if (gtk_file_info_get_is_folder (info))
10566 const GtkFilePath *file_path;
10568 file_path = _gtk_file_system_model_get_path (impl->browse_files_model, &child_iter);
10569 change_folder_and_display_error (impl, file_path, FALSE);
10573 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
10574 impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
10575 g_signal_emit_by_name (impl, "file-activated");
10582 path_bar_clicked (GtkPathBar *path_bar,
10583 GtkFilePath *file_path,
10584 GtkFilePath *child_path,
10585 gboolean child_is_hidden,
10586 GtkFileChooserDefault *impl)
10589 pending_select_paths_add (impl, child_path);
10591 if (!change_folder_and_display_error (impl, file_path, FALSE))
10594 /* Say we have "/foo/bar/[.baz]" and the user clicks on "bar". We should then
10595 * show hidden files so that ".baz" appears in the file list, as it will still
10596 * be shown in the path bar: "/foo/[bar]/.baz"
10598 if (child_is_hidden)
10599 g_object_set (impl, "show-hidden", TRUE, NULL);
10602 static const GtkFileInfo *
10603 get_list_file_info (GtkFileChooserDefault *impl,
10606 GtkTreeIter child_iter;
10608 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
10612 return _gtk_file_system_model_get_info (impl->browse_files_model, &child_iter);
10616 list_icon_data_func (GtkTreeViewColumn *tree_column,
10617 GtkCellRenderer *cell,
10618 GtkTreeModel *tree_model,
10622 GtkFileChooserDefault *impl = data;
10623 GtkTreeIter child_iter;
10624 GdkPixbuf *pixbuf = NULL;
10625 gboolean sensitive = TRUE;
10627 profile_start ("start", NULL);
10629 switch (impl->operation_mode)
10631 case OPERATION_MODE_SEARCH:
10633 GtkTreeIter child_iter;
10634 gboolean is_folder;
10636 search_get_valid_child_iter (impl, &child_iter, iter);
10637 gtk_tree_model_get (GTK_TREE_MODEL (impl->search_model), &child_iter,
10638 SEARCH_MODEL_COL_PIXBUF, &pixbuf,
10639 SEARCH_MODEL_COL_IS_FOLDER, &is_folder,
10642 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
10643 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
10644 sensitive = is_folder;
10648 case OPERATION_MODE_RECENT:
10650 GtkTreeIter child_iter;
10651 GtkRecentInfo *info;
10652 gboolean is_folder;
10654 recent_get_valid_child_iter (impl, &child_iter, iter);
10655 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &child_iter,
10656 RECENT_MODEL_COL_INFO, &info,
10657 RECENT_MODEL_COL_IS_FOLDER, &is_folder,
10660 pixbuf = gtk_recent_info_get_icon (info, impl->icon_size);
10662 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
10663 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
10664 sensitive = is_folder;
10668 case OPERATION_MODE_BROWSE:
10670 const GtkFileInfo *info;
10671 const GtkFilePath *path;
10673 info = get_list_file_info (impl, iter);
10675 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
10678 path = _gtk_file_system_model_get_path (impl->browse_files_model, &child_iter);
10683 /* FIXME: NULL GError */
10684 pixbuf = gtk_file_info_render_icon (info, GTK_WIDGET (impl),
10685 impl->icon_size, NULL);
10690 /* We are on the editable row */
10695 (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
10696 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER))
10697 sensitive = gtk_file_info_get_is_folder (info);
10702 g_object_set (cell,
10704 "sensitive", sensitive,
10708 g_object_unref (pixbuf);
10710 profile_end ("end", NULL);
10714 list_name_data_func (GtkTreeViewColumn *tree_column,
10715 GtkCellRenderer *cell,
10716 GtkTreeModel *tree_model,
10720 GtkFileChooserDefault *impl = data;
10721 const GtkFileInfo *info;
10722 gboolean sensitive = TRUE;
10724 if (impl->operation_mode == OPERATION_MODE_SEARCH)
10726 GtkTreeIter child_iter;
10727 GtkFilePath *file_path;
10728 gchar *display_name, *tmp;
10730 gboolean is_folder;
10732 search_get_valid_child_iter (impl, &child_iter, iter);
10733 gtk_tree_model_get (GTK_TREE_MODEL (impl->search_model), &child_iter,
10734 SEARCH_MODEL_COL_PATH, &file_path,
10735 SEARCH_MODEL_COL_DISPLAY_NAME, &display_name,
10736 SEARCH_MODEL_COL_IS_FOLDER, &is_folder,
10739 tmp = gtk_file_system_path_to_filename (impl->file_system, file_path);
10740 text = g_strdup_printf ("<b>%s</b>\n%s", display_name, tmp);
10743 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
10744 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
10746 sensitive = is_folder;
10749 g_object_set (cell,
10751 "sensitive", sensitive,
10752 "ellipsize", PANGO_ELLIPSIZE_END,
10760 if (impl->operation_mode == OPERATION_MODE_RECENT)
10762 GtkTreeIter child_iter;
10763 GtkRecentInfo *recent_info;
10765 gboolean is_folder;
10767 recent_get_valid_child_iter (impl, &child_iter, iter);
10768 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &child_iter,
10769 RECENT_MODEL_COL_INFO, &recent_info,
10770 RECENT_MODEL_COL_IS_FOLDER, &is_folder,
10773 tmp = gtk_recent_info_get_short_name (recent_info);
10774 text = g_strdup_printf ("<b>%s</b>\n%s",
10776 gtk_recent_info_get_uri_display (recent_info));
10779 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
10780 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
10782 sensitive = is_folder;
10785 g_object_set (cell,
10787 "sensitive", sensitive,
10788 "ellipsize", PANGO_ELLIPSIZE_END,
10795 info = get_list_file_info (impl, iter);
10800 g_object_set (cell,
10801 "text", _("Type name of new folder"),
10803 "ellipsize", PANGO_ELLIPSIZE_NONE,
10810 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
10811 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
10813 sensitive = gtk_file_info_get_is_folder (info);
10816 g_object_set (cell,
10817 "text", gtk_file_info_get_display_name (info),
10818 "sensitive", sensitive,
10819 "ellipsize", PANGO_ELLIPSIZE_END,
10825 list_size_data_func (GtkTreeViewColumn *tree_column,
10826 GtkCellRenderer *cell,
10827 GtkTreeModel *tree_model,
10831 GtkFileChooserDefault *impl = data;
10832 const GtkFileInfo *info = get_list_file_info (impl, iter);
10835 gboolean sensitive = TRUE;
10837 if (!info || gtk_file_info_get_is_folder (info))
10839 g_object_set (cell,
10841 "sensitive", sensitive,
10846 size = gtk_file_info_get_size (info);
10848 if (size < (gint64)1024)
10849 str = g_strdup_printf (ngettext ("%d byte", "%d bytes", (gint)size), (gint)size);
10850 else if (size < (gint64)1024*1024)
10851 str = g_strdup_printf (_("%.1f KB"), size / (1024.));
10852 else if (size < (gint64)1024*1024*1024)
10853 str = g_strdup_printf (_("%.1f MB"), size / (1024.*1024.));
10855 str = g_strdup_printf (_("%.1f GB"), size / (1024.*1024.*1024.));
10857 str = g_strdup_printf ("%" G_GINT64_FORMAT, size);
10858 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
10859 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
10862 g_object_set (cell,
10864 "sensitive", sensitive,
10865 "alignment", PANGO_ALIGN_RIGHT,
10872 /* Tree column data callback for the file list; fetches the mtime of a file */
10874 list_mtime_data_func (GtkTreeViewColumn *tree_column,
10875 GtkCellRenderer *cell,
10876 GtkTreeModel *tree_model,
10880 GtkFileChooserDefault *impl;
10881 GtkFileTime time_mtime;
10885 gboolean sensitive = TRUE;
10889 if (impl->operation_mode == OPERATION_MODE_SEARCH)
10891 GtkTreeIter child_iter;
10892 struct stat *statbuf;
10893 gboolean is_folder;
10895 search_get_valid_child_iter (impl, &child_iter, iter);
10896 gtk_tree_model_get (GTK_TREE_MODEL (impl->search_model), &child_iter,
10897 SEARCH_MODEL_COL_STAT, &statbuf,
10898 SEARCH_MODEL_COL_IS_FOLDER, &is_folder,
10901 time_mtime = statbuf->st_mtime;
10906 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
10907 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
10908 sensitive = is_folder;
10910 else if (impl->operation_mode == OPERATION_MODE_RECENT)
10912 GtkTreeIter child_iter;
10913 GtkRecentInfo *info;
10914 gboolean is_folder;
10916 recent_get_valid_child_iter (impl, &child_iter, iter);
10917 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &child_iter,
10918 RECENT_MODEL_COL_INFO, &info,
10919 RECENT_MODEL_COL_IS_FOLDER, &is_folder,
10923 time_mtime = (GtkFileTime) gtk_recent_info_get_modified (info);
10927 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
10928 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
10929 sensitive = is_folder;
10933 const GtkFileInfo *info;
10935 info = get_list_file_info (impl, iter);
10938 g_object_set (cell,
10945 time_mtime = gtk_file_info_get_modification_time (info);
10947 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
10948 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
10949 sensitive = gtk_file_info_get_is_folder (info);
10952 if (time_mtime == 0)
10953 strcpy (buf, _("Unknown"));
10957 g_date_set_time_t (&mtime, time_mtime);
10958 time_now = time (NULL);
10959 g_date_set_time_t (&now, time_now);
10961 days_diff = g_date_get_julian (&now) - g_date_get_julian (&mtime);
10963 if (days_diff == 0)
10964 strcpy (buf, _("Today"));
10965 else if (days_diff == 1)
10966 strcpy (buf, _("Yesterday"));
10971 if (days_diff > 1 && days_diff < 7)
10972 format = "%A"; /* Days from last week */
10974 format = "%x"; /* Any other date */
10976 if (g_date_strftime (buf, sizeof (buf), format, &mtime) == 0)
10977 strcpy (buf, _("Unknown"));
10981 g_object_set (cell,
10983 "sensitive", sensitive,
10988 _gtk_file_chooser_default_new (const char *file_system)
10990 return g_object_new (GTK_TYPE_FILE_CHOOSER_DEFAULT,
10991 "file-system-backend", file_system,
10996 location_set_user_text (GtkFileChooserDefault *impl,
10999 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), path);
11000 gtk_editable_set_position (GTK_EDITABLE (impl->location_entry), -1);
11004 location_popup_handler (GtkFileChooserDefault *impl,
11007 if (impl->operation_mode != OPERATION_MODE_BROWSE)
11009 GtkWidget *widget_to_focus;
11011 /* This will give us the location widgets back */
11012 switch (impl->operation_mode)
11014 case OPERATION_MODE_SEARCH:
11015 search_switch_to_browse_mode (impl);
11017 case OPERATION_MODE_RECENT:
11018 recent_switch_to_browse_mode (impl);
11020 case OPERATION_MODE_BROWSE:
11021 g_assert_not_reached ();
11025 if (impl->current_folder)
11026 change_folder_and_display_error (impl, impl->current_folder, FALSE);
11028 if (impl->location_mode == LOCATION_MODE_PATH_BAR)
11029 widget_to_focus = impl->browse_files_tree_view;
11031 widget_to_focus = impl->location_entry;
11033 gtk_widget_grab_focus (widget_to_focus);
11037 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
11038 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
11040 LocationMode new_mode;
11044 /* since the user typed something, we unconditionally want to turn on the entry */
11045 new_mode = LOCATION_MODE_FILENAME_ENTRY;
11047 else if (impl->location_mode == LOCATION_MODE_PATH_BAR)
11048 new_mode = LOCATION_MODE_FILENAME_ENTRY;
11049 else if (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)
11050 new_mode = LOCATION_MODE_PATH_BAR;
11053 g_assert_not_reached ();
11057 location_mode_set (impl, new_mode, TRUE);
11058 if (new_mode == LOCATION_MODE_FILENAME_ENTRY)
11061 location_set_user_text (impl, path);
11064 location_entry_set_initial_text (impl);
11065 gtk_editable_select_region (GTK_EDITABLE (impl->location_entry), 0, -1);
11069 else if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
11070 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
11072 gtk_widget_grab_focus (impl->location_entry);
11074 location_set_user_text (impl, path);
11077 g_assert_not_reached ();
11080 /* Handler for the "up-folder" keybinding signal */
11082 up_folder_handler (GtkFileChooserDefault *impl)
11084 _gtk_path_bar_up (GTK_PATH_BAR (impl->browse_path_bar));
11087 /* Handler for the "down-folder" keybinding signal */
11089 down_folder_handler (GtkFileChooserDefault *impl)
11091 _gtk_path_bar_down (GTK_PATH_BAR (impl->browse_path_bar));
11094 /* Switches to the shortcut in the specified index */
11096 switch_to_shortcut (GtkFileChooserDefault *impl,
11101 if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos))
11102 g_assert_not_reached ();
11104 shortcuts_activate_iter (impl, &iter);
11105 focus_browse_tree_view_if_possible (impl);
11108 /* Handler for the "home-folder" keybinding signal */
11110 home_folder_handler (GtkFileChooserDefault *impl)
11112 if (impl->has_home)
11113 switch_to_shortcut (impl, shortcuts_get_index (impl, SHORTCUTS_HOME));
11116 /* Handler for the "desktop-folder" keybinding signal */
11118 desktop_folder_handler (GtkFileChooserDefault *impl)
11120 if (impl->has_desktop)
11121 switch_to_shortcut (impl, shortcuts_get_index (impl, SHORTCUTS_DESKTOP));
11124 /* Handler for the "search-shortcut" keybinding signal */
11126 search_shortcut_handler (GtkFileChooserDefault *impl)
11128 if (impl->has_search)
11130 switch_to_shortcut (impl, shortcuts_get_index (impl, SHORTCUTS_SEARCH));
11132 /* we want the entry widget to grab the focus the first
11133 * time, not the browse_files_tree_view widget.
11135 if (impl->search_entry)
11136 gtk_widget_grab_focus (impl->search_entry);
11140 /* Handler for the "recent-shortcut" keybinding signal */
11142 recent_shortcut_handler (GtkFileChooserDefault *impl)
11144 if (impl->has_recent)
11145 switch_to_shortcut (impl, shortcuts_get_index (impl, SHORTCUTS_RECENT));
11149 quick_bookmark_handler (GtkFileChooserDefault *impl,
11150 gint bookmark_index)
11155 if (bookmark_index < 0 || bookmark_index >= impl->num_bookmarks)
11158 bookmark_pos = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS) + bookmark_index;
11160 path = gtk_tree_path_new_from_indices (bookmark_pos, -1);
11161 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view),
11164 gtk_tree_path_free (path);
11166 switch_to_shortcut (impl, bookmark_pos);
11170 show_hidden_handler (GtkFileChooserDefault *impl)
11172 g_object_set (impl,
11173 "show-hidden", !impl->show_hidden,
11178 /* Drag and drop interfaces */
11181 _shortcuts_pane_model_filter_class_init (ShortcutsPaneModelFilterClass *class)
11186 _shortcuts_pane_model_filter_init (ShortcutsPaneModelFilter *model)
11188 model->impl = NULL;
11191 /* GtkTreeDragSource::row_draggable implementation for the shortcuts filter model */
11193 shortcuts_pane_model_filter_row_draggable (GtkTreeDragSource *drag_source,
11196 ShortcutsPaneModelFilter *model;
11200 model = SHORTCUTS_PANE_MODEL_FILTER (drag_source);
11202 pos = *gtk_tree_path_get_indices (path);
11203 bookmarks_pos = shortcuts_get_index (model->impl, SHORTCUTS_BOOKMARKS);
11205 return (pos >= bookmarks_pos && pos < bookmarks_pos + model->impl->num_bookmarks);
11208 /* GtkTreeDragSource::drag_data_get implementation for the shortcuts filter model */
11210 shortcuts_pane_model_filter_drag_data_get (GtkTreeDragSource *drag_source,
11212 GtkSelectionData *selection_data)
11214 ShortcutsPaneModelFilter *model;
11216 model = SHORTCUTS_PANE_MODEL_FILTER (drag_source);
11223 /* Fill the GtkTreeDragSourceIface vtable */
11225 shortcuts_pane_model_filter_drag_source_iface_init (GtkTreeDragSourceIface *iface)
11227 iface->row_draggable = shortcuts_pane_model_filter_row_draggable;
11228 iface->drag_data_get = shortcuts_pane_model_filter_drag_data_get;
11232 /* Fill the GtkTreeDragDestIface vtable */
11234 shortcuts_pane_model_filter_drag_dest_iface_init (GtkTreeDragDestIface *iface)
11236 iface->drag_data_received = shortcuts_pane_model_filter_drag_data_received;
11237 iface->row_drop_possible = shortcuts_pane_model_filter_row_drop_possible;
11241 static GtkTreeModel *
11242 shortcuts_pane_model_filter_new (GtkFileChooserDefault *impl,
11243 GtkTreeModel *child_model,
11246 ShortcutsPaneModelFilter *model;
11248 model = g_object_new (SHORTCUTS_PANE_MODEL_FILTER_TYPE,
11249 "child-model", child_model,
11250 "virtual-root", root,
11253 model->impl = impl;
11255 return GTK_TREE_MODEL (model);
11261 recent_model_sort_row_draggable (GtkTreeDragSource *drag_source,
11264 RecentModelSort *model;
11265 GtkTreeIter iter, child_iter;
11266 gboolean is_folder;
11268 model = RECENT_MODEL_SORT (drag_source);
11269 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path))
11272 recent_get_valid_child_iter (model->impl, &child_iter, &iter);
11273 gtk_tree_model_get (GTK_TREE_MODEL (model->impl->recent_model), &child_iter,
11274 RECENT_MODEL_COL_IS_FOLDER, &is_folder,
11281 recent_model_sort_drag_data_get (GtkTreeDragSource *drag_source,
11283 GtkSelectionData *selection_data)
11285 RecentModelSort *model;
11286 GtkTreeIter iter, child_iter;
11287 GtkFilePath *file_path;
11290 model = RECENT_MODEL_SORT (drag_source);
11291 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path))
11294 recent_get_valid_child_iter (model->impl, &child_iter, &iter);
11295 gtk_tree_model_get (GTK_TREE_MODEL (model->impl->recent_model), &child_iter,
11296 RECENT_MODEL_COL_PATH, &file_path,
11298 g_assert (file_path != NULL);
11300 uris = g_new (gchar *, 2);
11301 uris[0] = gtk_file_system_path_to_uri (model->impl->file_system, file_path);
11304 gtk_selection_data_set_uris (selection_data, uris);
11312 recent_model_sort_drag_source_iface_init (GtkTreeDragSourceIface *iface)
11314 iface->row_draggable = recent_model_sort_row_draggable;
11315 iface->drag_data_get = recent_model_sort_drag_data_get;
11319 _recent_model_sort_class_init (RecentModelSortClass *klass)
11325 _recent_model_sort_init (RecentModelSort *model)
11327 model->impl = NULL;
11330 static GtkTreeModel *
11331 recent_model_sort_new (GtkFileChooserDefault *impl,
11332 GtkTreeModel *child_model)
11334 RecentModelSort *model;
11336 model = g_object_new (RECENT_MODEL_SORT_TYPE,
11337 "model", child_model,
11339 model->impl = impl;
11341 return GTK_TREE_MODEL (model);
11347 search_model_sort_row_draggable (GtkTreeDragSource *drag_source,
11350 SearchModelSort *model;
11351 GtkTreeIter iter, child_iter;
11352 gboolean is_folder;
11354 model = SEARCH_MODEL_SORT (drag_source);
11355 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path))
11358 search_get_valid_child_iter (model->impl, &child_iter, &iter);
11359 gtk_tree_model_get (GTK_TREE_MODEL (model->impl->search_model), &child_iter,
11360 SEARCH_MODEL_COL_IS_FOLDER, &is_folder,
11367 search_model_sort_drag_data_get (GtkTreeDragSource *drag_source,
11369 GtkSelectionData *selection_data)
11371 SearchModelSort *model;
11372 GtkTreeIter iter, child_iter;
11373 GtkFilePath *file_path;
11376 model = SEARCH_MODEL_SORT (drag_source);
11377 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path))
11380 search_get_valid_child_iter (model->impl, &child_iter, &iter);
11381 gtk_tree_model_get (GTK_TREE_MODEL (model->impl->search_model), &child_iter,
11382 RECENT_MODEL_COL_PATH, &file_path,
11384 g_assert (file_path != NULL);
11386 uris = g_new (gchar *, 2);
11387 uris[0] = gtk_file_system_path_to_uri (model->impl->file_system, file_path);
11390 gtk_selection_data_set_uris (selection_data, uris);
11398 search_model_sort_drag_source_iface_init (GtkTreeDragSourceIface *iface)
11400 iface->row_draggable = search_model_sort_row_draggable;
11401 iface->drag_data_get = search_model_sort_drag_data_get;
11405 _search_model_sort_class_init (SearchModelSortClass *klass)
11411 _search_model_sort_init (SearchModelSort *model)
11413 model->impl = NULL;
11416 static GtkTreeModel *
11417 search_model_sort_new (GtkFileChooserDefault *impl,
11418 GtkTreeModel *child_model)
11420 SearchModelSort *model;
11422 model = g_object_new (SEARCH_MODEL_SORT_TYPE,
11423 "model", child_model,
11425 model->impl = impl;
11427 return GTK_TREE_MODEL (model);