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 "gtktooltip.h"
67 #include "gtktreednd.h"
68 #include "gtktreeprivate.h"
69 #include "gtktreeselection.h"
70 #include "gtktypebuiltins.h"
73 #if defined (G_OS_UNIX)
74 #include "gtkfilesystemunix.h"
75 #elif defined (G_OS_WIN32)
77 #include "gtkfilesystemwin32.h"
86 #include <sys/types.h>
97 #undef PROFILE_FILE_CHOOSER
98 #ifdef PROFILE_FILE_CHOOSER
105 #define PROFILE_INDENT 4
106 static int profile_indent;
109 profile_add_indent (int indent)
111 profile_indent += indent;
112 if (profile_indent < 0)
113 g_error ("You screwed up your indentation");
117 _gtk_file_chooser_profile_log (const char *func, int indent, const char *msg1, const char *msg2)
122 profile_add_indent (indent);
124 if (profile_indent == 0)
125 str = g_strdup_printf ("MARK: %s %s %s", func ? func : "", msg1 ? msg1 : "", msg2 ? msg2 : "");
127 str = g_strdup_printf ("MARK: %*c %s %s %s", profile_indent - 1, ' ', func ? func : "", msg1 ? msg1 : "", msg2 ? msg2 : "");
133 profile_add_indent (indent);
136 #define profile_start(x, y) _gtk_file_chooser_profile_log (G_STRFUNC, PROFILE_INDENT, x, y)
137 #define profile_end(x, y) _gtk_file_chooser_profile_log (G_STRFUNC, -PROFILE_INDENT, x, y)
138 #define profile_msg(x, y) _gtk_file_chooser_profile_log (NULL, 0, x, y)
140 #define profile_start(x, y)
141 #define profile_end(x, y)
142 #define profile_msg(x, y)
147 typedef struct _GtkFileChooserDefaultClass GtkFileChooserDefaultClass;
149 #define GTK_FILE_CHOOSER_DEFAULT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FILE_CHOOSER_DEFAULT, GtkFileChooserDefaultClass))
150 #define GTK_IS_FILE_CHOOSER_DEFAULT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FILE_CHOOSER_DEFAULT))
151 #define GTK_FILE_CHOOSER_DEFAULT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FILE_CHOOSER_DEFAULT, GtkFileChooserDefaultClass))
153 #define MAX_LOADING_TIME 500
155 struct _GtkFileChooserDefaultClass
157 GtkVBoxClass parent_class;
163 LOCATION_POPUP_ON_PASTE,
169 LOCATION_TOGGLE_POPUP,
177 static guint signals[LAST_SIGNAL] = { 0 };
179 /* Column numbers for the shortcuts tree. Keep these in sync with shortcuts_model_create() */
181 SHORTCUTS_COL_PIXBUF,
185 SHORTCUTS_COL_REMOVABLE,
186 SHORTCUTS_COL_PIXBUF_VISIBLE,
187 SHORTCUTS_COL_HANDLE,
188 SHORTCUTS_COL_NUM_COLUMNS
193 SHORTCUT_TYPE_VOLUME,
194 SHORTCUT_TYPE_SEPARATOR,
195 SHORTCUT_TYPE_SEARCH,
199 /* Column numbers for the file list */
204 FILE_LIST_COL_NUM_COLUMNS
207 /* Column numbers for the search model.
208 * Keep this in sync with search_setup_model()
211 SEARCH_MODEL_COL_PATH,
212 SEARCH_MODEL_COL_DISPLAY_NAME,
213 SEARCH_MODEL_COL_COLLATION_KEY,
214 SEARCH_MODEL_COL_STAT,
215 SEARCH_MODEL_COL_HANDLE,
216 SEARCH_MODEL_COL_PIXBUF,
217 SEARCH_MODEL_COL_MIME_TYPE,
218 SEARCH_MODEL_COL_IS_FOLDER,
219 SEARCH_MODEL_COL_NUM_COLUMNS
223 RECENT_MODEL_COL_PATH,
224 RECENT_MODEL_COL_DISPLAY_NAME,
225 RECENT_MODEL_COL_INFO,
226 RECENT_MODEL_COL_IS_FOLDER,
227 RECENT_MODEL_COL_HANDLE,
228 RECENT_MODEL_COL_NUM_COLUMNS
231 /* Identifiers for target types */
237 /* Target types for dragging from the shortcuts list */
238 static const GtkTargetEntry shortcuts_source_targets[] = {
239 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, GTK_TREE_MODEL_ROW }
242 static const int num_shortcuts_source_targets = G_N_ELEMENTS (shortcuts_source_targets);
244 /* Target types for dropping into the shortcuts list */
245 static const GtkTargetEntry shortcuts_dest_targets[] = {
246 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, GTK_TREE_MODEL_ROW },
247 { "text/uri-list", 0, TEXT_URI_LIST }
250 static const int num_shortcuts_dest_targets = G_N_ELEMENTS (shortcuts_dest_targets);
252 /* Target types for DnD from the file list */
253 static const GtkTargetEntry file_list_source_targets[] = {
254 { "text/uri-list", 0, TEXT_URI_LIST }
257 static const int num_file_list_source_targets = G_N_ELEMENTS (file_list_source_targets);
259 /* Target types for dropping into the file list */
260 static const GtkTargetEntry file_list_dest_targets[] = {
261 { "text/uri-list", 0, TEXT_URI_LIST }
264 static const int num_file_list_dest_targets = G_N_ELEMENTS (file_list_dest_targets);
266 /* Target types for dragging from the recent files list */
267 static const GtkTargetEntry recent_list_source_targets[] = {
268 { "text/uri-list", 0, TEXT_URI_LIST }
271 static const int num_recent_list_source_targets = G_N_ELEMENTS (recent_list_source_targets);
274 search_is_possible (GtkFileChooserDefault *impl)
276 if (impl->search_engine == NULL)
277 impl->search_engine = _gtk_search_engine_new ();
279 return impl->search_engine != NULL;
282 /* Interesting places in the shortcuts bar */
286 SHORTCUTS_RECENT_SEPARATOR,
291 SHORTCUTS_BOOKMARKS_SEPARATOR,
293 SHORTCUTS_CURRENT_FOLDER_SEPARATOR,
294 SHORTCUTS_CURRENT_FOLDER
297 /* Icon size for if we can't get it from the theme */
298 #define FALLBACK_ICON_SIZE 16
300 #define PREVIEW_HBOX_SPACING 12
304 static void gtk_file_chooser_default_iface_init (GtkFileChooserIface *iface);
305 static void gtk_file_chooser_embed_default_iface_init (GtkFileChooserEmbedIface *iface);
307 static GObject* gtk_file_chooser_default_constructor (GType type,
308 guint n_construct_properties,
309 GObjectConstructParam *construct_params);
310 static void gtk_file_chooser_default_finalize (GObject *object);
311 static void gtk_file_chooser_default_set_property (GObject *object,
315 static void gtk_file_chooser_default_get_property (GObject *object,
319 static void gtk_file_chooser_default_dispose (GObject *object);
320 static void gtk_file_chooser_default_show_all (GtkWidget *widget);
321 static void gtk_file_chooser_default_map (GtkWidget *widget);
322 static void gtk_file_chooser_default_unmap (GtkWidget *widget);
323 static void gtk_file_chooser_default_hierarchy_changed (GtkWidget *widget,
324 GtkWidget *previous_toplevel);
325 static void gtk_file_chooser_default_style_set (GtkWidget *widget,
326 GtkStyle *previous_style);
327 static void gtk_file_chooser_default_screen_changed (GtkWidget *widget,
328 GdkScreen *previous_screen);
329 static void gtk_file_chooser_default_size_allocate (GtkWidget *widget,
330 GtkAllocation *allocation);
332 static gboolean gtk_file_chooser_default_set_current_folder (GtkFileChooser *chooser,
333 const GtkFilePath *path,
335 static gboolean gtk_file_chooser_default_update_current_folder (GtkFileChooser *chooser,
336 const GtkFilePath *path,
338 gboolean clear_entry,
340 static GtkFilePath * gtk_file_chooser_default_get_current_folder (GtkFileChooser *chooser);
341 static void gtk_file_chooser_default_set_current_name (GtkFileChooser *chooser,
343 static gboolean gtk_file_chooser_default_select_path (GtkFileChooser *chooser,
344 const GtkFilePath *path,
346 static void gtk_file_chooser_default_unselect_path (GtkFileChooser *chooser,
347 const GtkFilePath *path);
348 static void gtk_file_chooser_default_select_all (GtkFileChooser *chooser);
349 static void gtk_file_chooser_default_unselect_all (GtkFileChooser *chooser);
350 static GSList * gtk_file_chooser_default_get_paths (GtkFileChooser *chooser);
351 static GtkFilePath * gtk_file_chooser_default_get_preview_path (GtkFileChooser *chooser);
352 static GtkFileSystem *gtk_file_chooser_default_get_file_system (GtkFileChooser *chooser);
353 static void gtk_file_chooser_default_add_filter (GtkFileChooser *chooser,
354 GtkFileFilter *filter);
355 static void gtk_file_chooser_default_remove_filter (GtkFileChooser *chooser,
356 GtkFileFilter *filter);
357 static GSList * gtk_file_chooser_default_list_filters (GtkFileChooser *chooser);
358 static gboolean gtk_file_chooser_default_add_shortcut_folder (GtkFileChooser *chooser,
359 const GtkFilePath *path,
361 static gboolean gtk_file_chooser_default_remove_shortcut_folder (GtkFileChooser *chooser,
362 const GtkFilePath *path,
364 static GSList * gtk_file_chooser_default_list_shortcut_folders (GtkFileChooser *chooser);
366 static void gtk_file_chooser_default_get_default_size (GtkFileChooserEmbed *chooser_embed,
368 gint *default_height);
369 static gboolean gtk_file_chooser_default_get_resizable (GtkFileChooserEmbed *chooser_embed);
370 static gboolean gtk_file_chooser_default_should_respond (GtkFileChooserEmbed *chooser_embed);
371 static void gtk_file_chooser_default_initial_focus (GtkFileChooserEmbed *chooser_embed);
373 static void location_popup_handler (GtkFileChooserDefault *impl,
375 static void location_popup_on_paste_handler (GtkFileChooserDefault *impl);
376 static void location_toggle_popup_handler (GtkFileChooserDefault *impl);
377 static void up_folder_handler (GtkFileChooserDefault *impl);
378 static void down_folder_handler (GtkFileChooserDefault *impl);
379 static void home_folder_handler (GtkFileChooserDefault *impl);
380 static void desktop_folder_handler (GtkFileChooserDefault *impl);
381 static void quick_bookmark_handler (GtkFileChooserDefault *impl,
382 gint bookmark_index);
383 static void show_hidden_handler (GtkFileChooserDefault *impl);
384 static void search_shortcut_handler (GtkFileChooserDefault *impl);
385 static void recent_shortcut_handler (GtkFileChooserDefault *impl);
386 static void update_appearance (GtkFileChooserDefault *impl);
388 static void set_current_filter (GtkFileChooserDefault *impl,
389 GtkFileFilter *filter);
390 static void check_preview_change (GtkFileChooserDefault *impl);
392 static void filter_combo_changed (GtkComboBox *combo_box,
393 GtkFileChooserDefault *impl);
395 static gboolean shortcuts_key_press_event_cb (GtkWidget *widget,
397 GtkFileChooserDefault *impl);
399 static gboolean shortcuts_select_func (GtkTreeSelection *selection,
402 gboolean path_currently_selected,
404 static gboolean shortcuts_get_selected (GtkFileChooserDefault *impl,
406 static void shortcuts_activate_iter (GtkFileChooserDefault *impl,
408 static int shortcuts_get_index (GtkFileChooserDefault *impl,
409 ShortcutsIndex where);
410 static int shortcut_find_position (GtkFileChooserDefault *impl,
411 const GtkFilePath *path);
413 static void bookmarks_check_add_sensitivity (GtkFileChooserDefault *impl);
415 static gboolean list_select_func (GtkTreeSelection *selection,
418 gboolean path_currently_selected,
421 static void list_selection_changed (GtkTreeSelection *tree_selection,
422 GtkFileChooserDefault *impl);
423 static void list_row_activated (GtkTreeView *tree_view,
425 GtkTreeViewColumn *column,
426 GtkFileChooserDefault *impl);
428 static void select_func (GtkFileSystemModel *model,
433 static void path_bar_clicked (GtkPathBar *path_bar,
434 GtkFilePath *file_path,
435 GtkFilePath *child_path,
436 gboolean child_is_hidden,
437 GtkFileChooserDefault *impl);
439 static void add_bookmark_button_clicked_cb (GtkButton *button,
440 GtkFileChooserDefault *impl);
441 static void remove_bookmark_button_clicked_cb (GtkButton *button,
442 GtkFileChooserDefault *impl);
443 static void save_folder_combo_changed_cb (GtkComboBox *combo,
444 GtkFileChooserDefault *impl);
446 static void list_icon_data_func (GtkTreeViewColumn *tree_column,
447 GtkCellRenderer *cell,
448 GtkTreeModel *tree_model,
451 static void list_name_data_func (GtkTreeViewColumn *tree_column,
452 GtkCellRenderer *cell,
453 GtkTreeModel *tree_model,
457 static void list_size_data_func (GtkTreeViewColumn *tree_column,
458 GtkCellRenderer *cell,
459 GtkTreeModel *tree_model,
463 static void list_mtime_data_func (GtkTreeViewColumn *tree_column,
464 GtkCellRenderer *cell,
465 GtkTreeModel *tree_model,
469 static const GtkFileInfo *get_list_file_info (GtkFileChooserDefault *impl,
472 static void load_remove_timer (GtkFileChooserDefault *impl);
473 static void browse_files_center_selected_row (GtkFileChooserDefault *impl);
475 static void location_button_toggled_cb (GtkToggleButton *toggle,
476 GtkFileChooserDefault *impl);
477 static void location_switch_to_path_bar (GtkFileChooserDefault *impl);
479 static void search_stop_searching (GtkFileChooserDefault *impl,
480 gboolean remove_query);
481 static void search_clear_model (GtkFileChooserDefault *impl,
482 gboolean remove_from_treeview);
483 static gboolean search_should_respond (GtkFileChooserDefault *impl);
484 static void search_switch_to_browse_mode (GtkFileChooserDefault *impl);
485 static GSList *search_get_selected_paths (GtkFileChooserDefault *impl);
486 static void search_entry_activate_cb (GtkEntry *entry,
488 static void settings_load (GtkFileChooserDefault *impl);
489 static void search_get_valid_child_iter (GtkFileChooserDefault *impl,
490 GtkTreeIter *child_iter,
493 static void recent_manager_update (GtkFileChooserDefault *impl);
494 static void recent_stop_loading (GtkFileChooserDefault *impl);
495 static void recent_clear_model (GtkFileChooserDefault *impl,
496 gboolean remove_from_treeview);
497 static gboolean recent_should_respond (GtkFileChooserDefault *impl);
498 static void recent_switch_to_browse_mode (GtkFileChooserDefault *impl);
499 static GSList * recent_get_selected_paths (GtkFileChooserDefault *impl);
500 static void recent_get_valid_child_iter (GtkFileChooserDefault *impl,
501 GtkTreeIter *child_iter,
507 /* Drag and drop interface declarations */
510 GtkTreeModelFilter parent;
512 GtkFileChooserDefault *impl;
513 } ShortcutsPaneModelFilter;
516 GtkTreeModelFilterClass parent_class;
517 } ShortcutsPaneModelFilterClass;
519 #define SHORTCUTS_PANE_MODEL_FILTER_TYPE (_shortcuts_pane_model_filter_get_type ())
520 #define SHORTCUTS_PANE_MODEL_FILTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SHORTCUTS_PANE_MODEL_FILTER_TYPE, ShortcutsPaneModelFilter))
522 static void shortcuts_pane_model_filter_drag_source_iface_init (GtkTreeDragSourceIface *iface);
524 G_DEFINE_TYPE_WITH_CODE (ShortcutsPaneModelFilter,
525 _shortcuts_pane_model_filter,
526 GTK_TYPE_TREE_MODEL_FILTER,
527 G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_DRAG_SOURCE,
528 shortcuts_pane_model_filter_drag_source_iface_init))
530 static GtkTreeModel *shortcuts_pane_model_filter_new (GtkFileChooserDefault *impl,
531 GtkTreeModel *child_model,
536 GtkTreeModelSort parent;
538 GtkFileChooserDefault *impl;
542 GtkTreeModelSortClass parent_class;
543 } RecentModelSortClass;
545 #define RECENT_MODEL_SORT_TYPE (_recent_model_sort_get_type ())
546 #define RECENT_MODEL_SORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RECENT_MODEL_SORT_TYPE, RecentModelSort))
548 static void recent_model_sort_drag_source_iface_init (GtkTreeDragSourceIface *iface);
550 G_DEFINE_TYPE_WITH_CODE (RecentModelSort,
552 GTK_TYPE_TREE_MODEL_SORT,
553 G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_DRAG_SOURCE,
554 recent_model_sort_drag_source_iface_init));
556 static GtkTreeModel *recent_model_sort_new (GtkFileChooserDefault *impl,
557 GtkTreeModel *child_model);
561 GtkTreeModelSort parent;
563 GtkFileChooserDefault *impl;
567 GtkTreeModelSortClass parent_class;
568 } SearchModelSortClass;
570 #define SEARCH_MODEL_SORT_TYPE (_search_model_sort_get_type ())
571 #define SEARCH_MODEL_SORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SEARCH_MODEL_SORT_TYPE, SearchModelSort))
573 static void search_model_sort_drag_source_iface_init (GtkTreeDragSourceIface *iface);
575 G_DEFINE_TYPE_WITH_CODE (SearchModelSort,
577 GTK_TYPE_TREE_MODEL_SORT,
578 G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_DRAG_SOURCE,
579 search_model_sort_drag_source_iface_init));
581 static GtkTreeModel *search_model_sort_new (GtkFileChooserDefault *impl,
582 GtkTreeModel *child_model);
586 G_DEFINE_TYPE_WITH_CODE (GtkFileChooserDefault, _gtk_file_chooser_default, GTK_TYPE_VBOX,
587 G_IMPLEMENT_INTERFACE (GTK_TYPE_FILE_CHOOSER,
588 gtk_file_chooser_default_iface_init)
589 G_IMPLEMENT_INTERFACE (GTK_TYPE_FILE_CHOOSER_EMBED,
590 gtk_file_chooser_embed_default_iface_init));
593 _gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class)
595 static const guint quick_bookmark_keyvals[10] = {
596 GDK_1, GDK_2, GDK_3, GDK_4, GDK_5, GDK_6, GDK_7, GDK_8, GDK_9, GDK_0
598 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
599 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
600 GtkBindingSet *binding_set;
603 gobject_class->finalize = gtk_file_chooser_default_finalize;
604 gobject_class->constructor = gtk_file_chooser_default_constructor;
605 gobject_class->set_property = gtk_file_chooser_default_set_property;
606 gobject_class->get_property = gtk_file_chooser_default_get_property;
607 gobject_class->dispose = gtk_file_chooser_default_dispose;
609 widget_class->show_all = gtk_file_chooser_default_show_all;
610 widget_class->map = gtk_file_chooser_default_map;
611 widget_class->unmap = gtk_file_chooser_default_unmap;
612 widget_class->hierarchy_changed = gtk_file_chooser_default_hierarchy_changed;
613 widget_class->style_set = gtk_file_chooser_default_style_set;
614 widget_class->screen_changed = gtk_file_chooser_default_screen_changed;
615 widget_class->size_allocate = gtk_file_chooser_default_size_allocate;
617 signals[LOCATION_POPUP] =
618 _gtk_binding_signal_new (I_("location-popup"),
619 G_OBJECT_CLASS_TYPE (class),
620 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
621 G_CALLBACK (location_popup_handler),
623 _gtk_marshal_VOID__STRING,
624 G_TYPE_NONE, 1, G_TYPE_STRING);
625 signals[LOCATION_POPUP_ON_PASTE] =
626 _gtk_binding_signal_new ("location-popup-on-paste",
627 G_OBJECT_CLASS_TYPE (class),
628 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
629 G_CALLBACK (location_popup_on_paste_handler),
631 _gtk_marshal_VOID__VOID,
633 signals[LOCATION_TOGGLE_POPUP] =
634 _gtk_binding_signal_new (I_("location-toggle-popup"),
635 G_OBJECT_CLASS_TYPE (class),
636 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
637 G_CALLBACK (location_toggle_popup_handler),
639 _gtk_marshal_VOID__VOID,
642 _gtk_binding_signal_new (I_("up-folder"),
643 G_OBJECT_CLASS_TYPE (class),
644 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
645 G_CALLBACK (up_folder_handler),
647 _gtk_marshal_VOID__VOID,
649 signals[DOWN_FOLDER] =
650 _gtk_binding_signal_new (I_("down-folder"),
651 G_OBJECT_CLASS_TYPE (class),
652 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
653 G_CALLBACK (down_folder_handler),
655 _gtk_marshal_VOID__VOID,
657 signals[HOME_FOLDER] =
658 _gtk_binding_signal_new (I_("home-folder"),
659 G_OBJECT_CLASS_TYPE (class),
660 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
661 G_CALLBACK (home_folder_handler),
663 _gtk_marshal_VOID__VOID,
665 signals[DESKTOP_FOLDER] =
666 _gtk_binding_signal_new (I_("desktop-folder"),
667 G_OBJECT_CLASS_TYPE (class),
668 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
669 G_CALLBACK (desktop_folder_handler),
671 _gtk_marshal_VOID__VOID,
673 signals[QUICK_BOOKMARK] =
674 _gtk_binding_signal_new (I_("quick-bookmark"),
675 G_OBJECT_CLASS_TYPE (class),
676 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
677 G_CALLBACK (quick_bookmark_handler),
679 _gtk_marshal_VOID__INT,
680 G_TYPE_NONE, 1, G_TYPE_INT);
681 signals[SHOW_HIDDEN] =
682 _gtk_binding_signal_new ("show-hidden",
683 G_OBJECT_CLASS_TYPE (class),
684 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
685 G_CALLBACK (show_hidden_handler),
687 _gtk_marshal_VOID__VOID,
689 signals[SEARCH_SHORTCUT] =
690 _gtk_binding_signal_new ("search-shortcut",
691 G_OBJECT_CLASS_TYPE (class),
692 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
693 G_CALLBACK (search_shortcut_handler),
695 _gtk_marshal_VOID__VOID,
697 signals[RECENT_SHORTCUT] =
698 _gtk_binding_signal_new ("recent-shortcut",
699 G_OBJECT_CLASS_TYPE (class),
700 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
701 G_CALLBACK (recent_shortcut_handler),
703 _gtk_marshal_VOID__VOID,
706 binding_set = gtk_binding_set_by_class (class);
708 gtk_binding_entry_add_signal (binding_set,
709 GDK_l, GDK_CONTROL_MASK,
710 "location-toggle-popup",
713 gtk_binding_entry_add_signal (binding_set,
716 1, G_TYPE_STRING, "/");
717 gtk_binding_entry_add_signal (binding_set,
720 1, G_TYPE_STRING, "/");
723 gtk_binding_entry_add_signal (binding_set,
726 1, G_TYPE_STRING, "~");
729 gtk_binding_entry_add_signal (binding_set,
730 GDK_v, GDK_CONTROL_MASK,
731 "location-popup-on-paste",
733 gtk_binding_entry_add_signal (binding_set,
734 GDK_Up, GDK_MOD1_MASK,
737 gtk_binding_entry_add_signal (binding_set,
741 gtk_binding_entry_add_signal (binding_set,
742 GDK_KP_Up, GDK_MOD1_MASK,
746 gtk_binding_entry_add_signal (binding_set,
747 GDK_Down, GDK_MOD1_MASK,
750 gtk_binding_entry_add_signal (binding_set,
751 GDK_KP_Down, GDK_MOD1_MASK,
755 gtk_binding_entry_add_signal (binding_set,
756 GDK_Home, GDK_MOD1_MASK,
759 gtk_binding_entry_add_signal (binding_set,
760 GDK_KP_Home, GDK_MOD1_MASK,
763 gtk_binding_entry_add_signal (binding_set,
764 GDK_d, GDK_MOD1_MASK,
767 gtk_binding_entry_add_signal (binding_set,
768 GDK_h, GDK_CONTROL_MASK,
771 gtk_binding_entry_add_signal (binding_set,
772 GDK_s, GDK_MOD1_MASK,
775 gtk_binding_entry_add_signal (binding_set,
776 GDK_r, GDK_MOD1_MASK,
780 for (i = 0; i < 10; i++)
781 gtk_binding_entry_add_signal (binding_set,
782 quick_bookmark_keyvals[i], GDK_MOD1_MASK,
786 _gtk_file_chooser_install_properties (gobject_class);
790 gtk_file_chooser_default_iface_init (GtkFileChooserIface *iface)
792 iface->select_path = gtk_file_chooser_default_select_path;
793 iface->unselect_path = gtk_file_chooser_default_unselect_path;
794 iface->select_all = gtk_file_chooser_default_select_all;
795 iface->unselect_all = gtk_file_chooser_default_unselect_all;
796 iface->get_paths = gtk_file_chooser_default_get_paths;
797 iface->get_preview_path = gtk_file_chooser_default_get_preview_path;
798 iface->get_file_system = gtk_file_chooser_default_get_file_system;
799 iface->set_current_folder = gtk_file_chooser_default_set_current_folder;
800 iface->get_current_folder = gtk_file_chooser_default_get_current_folder;
801 iface->set_current_name = gtk_file_chooser_default_set_current_name;
802 iface->add_filter = gtk_file_chooser_default_add_filter;
803 iface->remove_filter = gtk_file_chooser_default_remove_filter;
804 iface->list_filters = gtk_file_chooser_default_list_filters;
805 iface->add_shortcut_folder = gtk_file_chooser_default_add_shortcut_folder;
806 iface->remove_shortcut_folder = gtk_file_chooser_default_remove_shortcut_folder;
807 iface->list_shortcut_folders = gtk_file_chooser_default_list_shortcut_folders;
811 gtk_file_chooser_embed_default_iface_init (GtkFileChooserEmbedIface *iface)
813 iface->get_default_size = gtk_file_chooser_default_get_default_size;
814 iface->get_resizable = gtk_file_chooser_default_get_resizable;
815 iface->should_respond = gtk_file_chooser_default_should_respond;
816 iface->initial_focus = gtk_file_chooser_default_initial_focus;
820 _gtk_file_chooser_default_init (GtkFileChooserDefault *impl)
822 profile_start ("start", NULL);
823 #ifdef PROFILE_FILE_CHOOSER
824 access ("MARK: *** CREATE FILE CHOOSER", F_OK);
826 impl->local_only = TRUE;
827 impl->preview_widget_active = TRUE;
828 impl->use_preview_label = TRUE;
829 impl->select_multiple = FALSE;
830 impl->show_hidden = FALSE;
831 impl->icon_size = FALLBACK_ICON_SIZE;
832 impl->load_state = LOAD_EMPTY;
833 impl->reload_state = RELOAD_EMPTY;
834 impl->pending_select_paths = NULL;
835 impl->location_mode = LOCATION_MODE_PATH_BAR;
836 impl->operation_mode = OPERATION_MODE_BROWSE;
838 gtk_box_set_spacing (GTK_BOX (impl), 12);
840 impl->tooltips = gtk_tooltips_new ();
841 g_object_ref_sink (impl->tooltips);
843 profile_end ("end", NULL);
846 /* Frees the data columns for the specified iter in the shortcuts model*/
848 shortcuts_free_row_data (GtkFileChooserDefault *impl,
852 ShortcutType shortcut_type;
853 GtkFileSystemHandle *handle;
855 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), iter,
856 SHORTCUTS_COL_DATA, &col_data,
857 SHORTCUTS_COL_TYPE, &shortcut_type,
858 SHORTCUTS_COL_HANDLE, &handle,
862 gtk_file_system_cancel_operation (handle);
864 if (!(shortcut_type == SHORTCUT_TYPE_PATH ||
865 shortcut_type == SHORTCUT_TYPE_VOLUME) ||
869 if (shortcut_type == SHORTCUT_TYPE_VOLUME)
871 GtkFileSystemVolume *volume;
874 gtk_file_system_volume_free (impl->file_system, volume);
880 g_assert (shortcut_type == SHORTCUT_TYPE_PATH);
883 gtk_file_path_free (path);
887 /* Frees all the data columns in the shortcuts model */
889 shortcuts_free (GtkFileChooserDefault *impl)
893 if (!impl->shortcuts_model)
896 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
899 shortcuts_free_row_data (impl, &iter);
901 while (gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter));
903 g_object_unref (impl->shortcuts_model);
904 impl->shortcuts_model = NULL;
908 pending_select_paths_free (GtkFileChooserDefault *impl)
912 for (l = impl->pending_select_paths; l; l = l->next)
917 gtk_file_path_free (path);
920 g_slist_free (impl->pending_select_paths);
921 impl->pending_select_paths = NULL;
925 pending_select_paths_add (GtkFileChooserDefault *impl,
926 const GtkFilePath *path)
928 impl->pending_select_paths =
929 g_slist_prepend (impl->pending_select_paths, gtk_file_path_copy (path));
932 /* Used from gtk_tree_selection_selected_foreach() */
934 store_selection_foreach (GtkTreeModel *model,
939 GtkFileChooserDefault *impl;
940 GtkTreeIter child_iter;
941 const GtkFilePath *file_path;
943 impl = GTK_FILE_CHOOSER_DEFAULT (data);
945 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model, &child_iter, iter);
947 file_path = _gtk_file_system_model_get_path (impl->browse_files_model, &child_iter);
948 pending_select_paths_add (impl, file_path);
951 /* Stores the current selection in the list of paths to select; this is used to
952 * preserve the selection when reloading the current folder.
955 pending_select_paths_store_selection (GtkFileChooserDefault *impl)
957 GtkTreeSelection *selection;
959 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
960 gtk_tree_selection_selected_foreach (selection, store_selection_foreach, impl);
964 gtk_file_chooser_default_finalize (GObject *object)
966 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (object);
969 if (impl->shortcuts_pane_filter_model)
970 g_object_unref (impl->shortcuts_pane_filter_model);
972 if (impl->shortcuts_combo_filter_model)
973 g_object_unref (impl->shortcuts_combo_filter_model);
975 shortcuts_free (impl);
977 g_object_unref (impl->file_system);
979 g_free (impl->browse_files_last_selected_name);
981 for (l = impl->filters; l; l = l->next)
983 GtkFileFilter *filter;
985 filter = GTK_FILE_FILTER (l->data);
986 g_object_unref (filter);
988 g_slist_free (impl->filters);
990 if (impl->current_filter)
991 g_object_unref (impl->current_filter);
993 if (impl->current_volume_path)
994 gtk_file_path_free (impl->current_volume_path);
996 if (impl->current_folder)
997 gtk_file_path_free (impl->current_folder);
999 if (impl->preview_path)
1000 gtk_file_path_free (impl->preview_path);
1002 load_remove_timer (impl);
1004 /* Free all the Models we have */
1005 if (impl->browse_files_model)
1006 g_object_unref (impl->browse_files_model);
1008 if (impl->sort_model)
1009 g_object_unref (impl->sort_model);
1011 search_clear_model (impl, FALSE);
1012 recent_clear_model (impl, FALSE);
1014 g_free (impl->preview_display_name);
1016 g_free (impl->edited_new_text);
1018 g_object_unref (impl->tooltips);
1020 G_OBJECT_CLASS (_gtk_file_chooser_default_parent_class)->finalize (object);
1023 /* Shows an error dialog set as transient for the specified window */
1025 error_message_with_parent (GtkWindow *parent,
1031 dialog = gtk_message_dialog_new (parent,
1032 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
1037 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
1041 gtk_window_group_add_window (parent->group, GTK_WINDOW (dialog));
1043 gtk_dialog_run (GTK_DIALOG (dialog));
1044 gtk_widget_destroy (dialog);
1047 /* Returns a toplevel GtkWindow, or NULL if none */
1049 get_toplevel (GtkWidget *widget)
1051 GtkWidget *toplevel;
1053 toplevel = gtk_widget_get_toplevel (widget);
1054 if (!GTK_WIDGET_TOPLEVEL (toplevel))
1057 return GTK_WINDOW (toplevel);
1060 /* Shows an error dialog for the file chooser */
1062 error_message (GtkFileChooserDefault *impl,
1066 error_message_with_parent (get_toplevel (GTK_WIDGET (impl)), msg, detail);
1069 /* Shows a simple error dialog relative to a path. Frees the GError as well. */
1071 error_dialog (GtkFileChooserDefault *impl,
1073 const GtkFilePath *path,
1082 uri = gtk_file_system_path_to_uri (impl->file_system, path);
1083 text = g_strdup_printf (msg, uri);
1084 error_message (impl, text, error->message);
1087 g_error_free (error);
1091 /* Displays an error message about not being able to get information for a file.
1092 * Frees the GError as well.
1095 error_getting_info_dialog (GtkFileChooserDefault *impl,
1096 const GtkFilePath *path,
1100 _("Could not retrieve information about the file"),
1104 /* Shows an error dialog about not being able to add a bookmark */
1106 error_adding_bookmark_dialog (GtkFileChooserDefault *impl,
1107 const GtkFilePath *path,
1111 _("Could not add a bookmark"),
1115 /* Shows an error dialog about not being able to remove a bookmark */
1117 error_removing_bookmark_dialog (GtkFileChooserDefault *impl,
1118 const GtkFilePath *path,
1122 _("Could not remove bookmark"),
1126 /* Shows an error dialog about not being able to create a folder */
1128 error_creating_folder_dialog (GtkFileChooserDefault *impl,
1129 const GtkFilePath *path,
1133 _("The folder could not be created"),
1137 /* Shows an error about not being able to create a folder because a file with
1138 * the same name is already there.
1141 error_creating_folder_over_existing_file_dialog (GtkFileChooserDefault *impl,
1142 const GtkFilePath *path,
1146 _("The folder could not be created, as a file with the same "
1147 "name already exists. Try using a different name for the "
1148 "folder, or rename the file first."),
1152 /* Shows an error dialog about not being able to create a filename */
1154 error_building_filename_dialog (GtkFileChooserDefault *impl,
1155 const GtkFilePath *folder_part,
1156 const char *file_part,
1159 error_dialog (impl, _("Invalid file name"),
1163 /* Shows an error dialog when we cannot switch to a folder */
1165 error_changing_folder_dialog (GtkFileChooserDefault *impl,
1166 const GtkFilePath *path,
1169 error_dialog (impl, _("The folder contents could not be displayed"),
1173 /* Changes folders, displaying an error dialog if this fails */
1175 change_folder_and_display_error (GtkFileChooserDefault *impl,
1176 const GtkFilePath *path,
1177 gboolean clear_entry)
1181 GtkFilePath *path_copy;
1183 g_return_val_if_fail (path != NULL, FALSE);
1185 profile_start ("start", (char *) path);
1187 /* We copy the path because of this case:
1189 * list_row_activated()
1190 * fetches path from model; path belongs to the model (*)
1191 * calls change_folder_and_display_error()
1192 * calls _gtk_file_chooser_set_current_folder_path()
1193 * changing folders fails, sets model to NULL, thus freeing the path in (*)
1196 path_copy = gtk_file_path_copy (path);
1199 result = gtk_file_chooser_default_update_current_folder (GTK_FILE_CHOOSER (impl), path_copy, TRUE, clear_entry, &error);
1202 error_changing_folder_dialog (impl, path_copy, error);
1204 gtk_file_path_free (path_copy);
1206 profile_end ("end", (char *) path);
1212 update_preview_widget_visibility (GtkFileChooserDefault *impl)
1214 if (impl->use_preview_label)
1216 if (!impl->preview_label)
1218 impl->preview_label = gtk_label_new (impl->preview_display_name);
1219 gtk_box_pack_start (GTK_BOX (impl->preview_box), impl->preview_label, FALSE, FALSE, 0);
1220 gtk_box_reorder_child (GTK_BOX (impl->preview_box), impl->preview_label, 0);
1221 gtk_label_set_ellipsize (GTK_LABEL (impl->preview_label), PANGO_ELLIPSIZE_MIDDLE);
1222 gtk_widget_show (impl->preview_label);
1227 if (impl->preview_label)
1229 gtk_widget_destroy (impl->preview_label);
1230 impl->preview_label = NULL;
1234 if (impl->preview_widget_active && impl->preview_widget)
1235 gtk_widget_show (impl->preview_box);
1237 gtk_widget_hide (impl->preview_box);
1239 g_signal_emit_by_name (impl, "default-size-changed");
1243 set_preview_widget (GtkFileChooserDefault *impl,
1244 GtkWidget *preview_widget)
1246 if (preview_widget == impl->preview_widget)
1249 if (impl->preview_widget)
1250 gtk_container_remove (GTK_CONTAINER (impl->preview_box),
1251 impl->preview_widget);
1253 impl->preview_widget = preview_widget;
1254 if (impl->preview_widget)
1256 gtk_widget_show (impl->preview_widget);
1257 gtk_box_pack_start (GTK_BOX (impl->preview_box), impl->preview_widget, TRUE, TRUE, 0);
1258 gtk_box_reorder_child (GTK_BOX (impl->preview_box),
1259 impl->preview_widget,
1260 (impl->use_preview_label && impl->preview_label) ? 1 : 0);
1263 update_preview_widget_visibility (impl);
1266 /* Renders a "Search" icon at an appropriate size for a tree view */
1268 render_search_icon (GtkFileChooserDefault *impl)
1270 return gtk_widget_render_icon (GTK_WIDGET (impl), GTK_STOCK_FIND, GTK_ICON_SIZE_MENU, NULL);
1274 render_recent_icon (GtkFileChooserDefault *impl)
1276 GtkIconTheme *theme;
1279 if (gtk_widget_has_screen (GTK_WIDGET (impl)))
1280 theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl)));
1282 theme = gtk_icon_theme_get_default ();
1284 retval = gtk_icon_theme_load_icon (theme, "document-open-recent",
1290 retval = gtk_widget_render_icon (GTK_WIDGET (impl), GTK_STOCK_FILE, GTK_ICON_SIZE_MENU, NULL);
1296 /* Re-reads all the icons for the shortcuts, used when the theme changes */
1297 struct ReloadIconsData
1299 GtkFileChooserDefault *impl;
1300 GtkTreeRowReference *row_ref;
1304 shortcuts_reload_icons_get_info_cb (GtkFileSystemHandle *handle,
1305 const GtkFileInfo *info,
1306 const GError *error,
1312 gboolean cancelled = handle->cancelled;
1313 struct ReloadIconsData *data = user_data;
1315 if (!g_slist_find (data->impl->reload_icon_handles, handle))
1318 data->impl->reload_icon_handles = g_slist_remove (data->impl->reload_icon_handles, handle);
1320 if (cancelled || error)
1323 pixbuf = gtk_file_info_render_icon (info, GTK_WIDGET (data->impl),
1324 data->impl->icon_size, NULL);
1326 path = gtk_tree_row_reference_get_path (data->row_ref);
1327 gtk_tree_model_get_iter (GTK_TREE_MODEL (data->impl->shortcuts_model), &iter, path);
1328 gtk_list_store_set (data->impl->shortcuts_model, &iter,
1329 SHORTCUTS_COL_PIXBUF, pixbuf,
1331 gtk_tree_path_free (path);
1334 g_object_unref (pixbuf);
1337 gtk_tree_row_reference_free (data->row_ref);
1338 g_object_unref (data->impl);
1341 g_object_unref (handle);
1345 shortcuts_reload_icons (GtkFileChooserDefault *impl)
1350 profile_start ("start", NULL);
1352 if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
1355 for (l = impl->reload_icon_handles; l; l = l->next)
1357 GtkFileSystemHandle *handle = GTK_FILE_SYSTEM_HANDLE (l->data);
1358 gtk_file_system_cancel_operation (handle);
1360 g_slist_free (impl->reload_icon_handles);
1361 impl->reload_icon_handles = NULL;
1366 ShortcutType shortcut_type;
1367 gboolean pixbuf_visible;
1370 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
1371 SHORTCUTS_COL_DATA, &data,
1372 SHORTCUTS_COL_TYPE, &shortcut_type,
1373 SHORTCUTS_COL_PIXBUF_VISIBLE, &pixbuf_visible,
1379 if (shortcut_type == SHORTCUT_TYPE_VOLUME)
1381 GtkFileSystemVolume *volume;
1384 pixbuf = gtk_file_system_volume_render_icon (impl->file_system, volume, GTK_WIDGET (impl),
1385 impl->icon_size, NULL);
1387 else if (shortcut_type == SHORTCUT_TYPE_PATH)
1389 if (gtk_file_system_path_is_local (impl->file_system, (GtkFilePath *)data))
1391 const GtkFilePath *path;
1392 struct ReloadIconsData *info;
1393 GtkTreePath *tree_path;
1394 GtkFileSystemHandle *handle;
1398 info = g_new0 (struct ReloadIconsData, 1);
1399 info->impl = g_object_ref (impl);
1400 tree_path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
1401 info->row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (impl->shortcuts_model), tree_path);
1402 gtk_tree_path_free (tree_path);
1404 handle = gtk_file_system_get_info (impl->file_system, path,
1406 shortcuts_reload_icons_get_info_cb,
1408 impl->reload_icon_handles = g_slist_append (impl->reload_icon_handles, handle);
1412 GtkIconTheme *icon_theme;
1414 /* Don't call get_info for remote paths to avoid latency and
1416 * If we switch to a better bookmarks file format (XBEL), we
1417 * should use mime info to get a better icon.
1419 icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl)));
1420 pixbuf = gtk_icon_theme_load_icon (icon_theme, "gnome-fs-share",
1421 impl->icon_size, 0, NULL);
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);
1433 gtk_list_store_set (impl->shortcuts_model, &iter,
1434 SHORTCUTS_COL_PIXBUF, pixbuf,
1438 g_object_unref (pixbuf);
1442 while (gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model),&iter));
1446 profile_end ("end", NULL);
1450 shortcuts_find_folder (GtkFileChooserDefault *impl,
1451 GtkFilePath *folder)
1453 GtkTreeSelection *selection;
1457 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view));
1459 g_assert (folder != NULL);
1460 pos = shortcut_find_position (impl, folder);
1463 gtk_tree_selection_unselect_all (selection);
1467 path = gtk_tree_path_new_from_indices (pos, -1);
1468 gtk_tree_selection_select_path (selection, path);
1469 gtk_tree_path_free (path);
1472 /* If a shortcut corresponds to the current folder, selects it */
1474 shortcuts_find_current_folder (GtkFileChooserDefault *impl)
1476 shortcuts_find_folder (impl, impl->current_folder);
1479 /* Removes the specified number of rows from the shortcuts list */
1481 shortcuts_remove_rows (GtkFileChooserDefault *impl,
1487 path = gtk_tree_path_new_from_indices (start_row, -1);
1489 for (; n_rows; n_rows--)
1493 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->shortcuts_model), &iter, path))
1494 g_assert_not_reached ();
1496 shortcuts_free_row_data (impl, &iter);
1497 gtk_list_store_remove (impl->shortcuts_model, &iter);
1500 gtk_tree_path_free (path);
1504 shortcuts_update_count (GtkFileChooserDefault *impl,
1505 ShortcutsIndex type,
1510 case SHORTCUTS_HOME:
1512 impl->has_home = FALSE;
1514 impl->has_home = TRUE;
1517 case SHORTCUTS_DESKTOP:
1519 impl->has_desktop = FALSE;
1521 impl->has_desktop = TRUE;
1524 case SHORTCUTS_VOLUMES:
1525 impl->num_volumes += value;
1528 case SHORTCUTS_SHORTCUTS:
1529 impl->num_shortcuts += value;
1532 case SHORTCUTS_BOOKMARKS:
1533 impl->num_bookmarks += value;
1536 case SHORTCUTS_CURRENT_FOLDER:
1538 impl->shortcuts_current_folder_active = FALSE;
1540 impl->shortcuts_current_folder_active = TRUE;
1549 struct ShortcutsInsertRequest
1551 GtkFileChooserDefault *impl;
1552 GtkFilePath *parent_path;
1556 GtkTreeRowReference *row_ref;
1557 ShortcutsIndex type;
1563 get_file_info_finished (GtkFileSystemHandle *handle,
1564 const GtkFileInfo *info,
1565 const GError *error,
1569 gboolean cancelled = handle->cancelled;
1573 GtkFileSystemHandle *model_handle;
1574 struct ShortcutsInsertRequest *request = data;
1576 path = gtk_tree_row_reference_get_path (request->row_ref);
1578 /* Handle doesn't exist anymore in the model */
1581 pos = gtk_tree_path_get_indices (path)[0];
1582 gtk_tree_model_get_iter (GTK_TREE_MODEL (request->impl->shortcuts_model),
1584 gtk_tree_path_free (path);
1586 /* validate handle, else goto out */
1587 gtk_tree_model_get (GTK_TREE_MODEL (request->impl->shortcuts_model), &iter,
1588 SHORTCUTS_COL_HANDLE, &model_handle,
1590 if (handle != model_handle)
1593 /* set the handle to NULL in the model (we unref later on) */
1594 gtk_list_store_set (request->impl->shortcuts_model, &iter,
1595 SHORTCUTS_COL_HANDLE, NULL,
1603 gtk_list_store_remove (request->impl->shortcuts_model, &iter);
1604 shortcuts_update_count (request->impl, request->type, -1);
1606 if (request->type == SHORTCUTS_HOME)
1608 const char *home = g_get_home_dir ();
1609 GtkFilePath *home_path;
1611 home_path = gtk_file_system_filename_to_path (request->impl->file_system, home);
1612 error_getting_info_dialog (request->impl, home_path, g_error_copy (error));
1613 gtk_file_path_free (home_path);
1615 else if (request->type == SHORTCUTS_CURRENT_FOLDER)
1617 /* Remove the current folder separator */
1618 gint separator_pos = shortcuts_get_index (request->impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR);
1619 shortcuts_remove_rows (request->impl, separator_pos, 1);
1625 if (!request->label_copy)
1626 request->label_copy = g_strdup (gtk_file_info_get_display_name (info));
1627 pixbuf = gtk_file_info_render_icon (info, GTK_WIDGET (request->impl),
1628 request->impl->icon_size, NULL);
1630 gtk_list_store_set (request->impl->shortcuts_model, &iter,
1631 SHORTCUTS_COL_PIXBUF, pixbuf,
1632 SHORTCUTS_COL_PIXBUF_VISIBLE, TRUE,
1633 SHORTCUTS_COL_NAME, request->label_copy,
1634 SHORTCUTS_COL_TYPE, SHORTCUT_TYPE_PATH,
1635 SHORTCUTS_COL_REMOVABLE, request->removable,
1638 if (request->impl->shortcuts_pane_filter_model)
1639 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (request->impl->shortcuts_pane_filter_model));
1641 if (request->impl->shortcuts_combo_filter_model)
1642 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (request->impl->shortcuts_combo_filter_model));
1644 if (request->type == SHORTCUTS_CURRENT_FOLDER &&
1645 request->impl->save_folder_combo != NULL)
1647 /* The current folder is updated via _activate_iter(), don't
1648 * have save_folder_combo_changed_cb() call _activate_iter()
1651 g_signal_handlers_block_by_func (request->impl->save_folder_combo,
1652 G_CALLBACK (save_folder_combo_changed_cb),
1655 if (request->impl->has_search)
1658 if (request->impl->has_recent)
1661 gtk_combo_box_set_active (GTK_COMBO_BOX (request->impl->save_folder_combo), pos);
1662 g_signal_handlers_unblock_by_func (request->impl->save_folder_combo,
1663 G_CALLBACK (save_folder_combo_changed_cb),
1668 g_object_unref (pixbuf);
1671 g_object_unref (request->impl);
1672 gtk_file_path_free (request->parent_path);
1673 gtk_file_path_free (request->path);
1674 gtk_tree_row_reference_free (request->row_ref);
1675 g_free (request->label_copy);
1678 g_object_unref (handle);
1681 /* FIXME: GtkFileSystem needs a function to split a remote path
1682 * into hostname and path components, or maybe just have a
1683 * gtk_file_system_path_get_display_name().
1685 * This function is also used in gtkfilechooserbutton.c
1688 _gtk_file_chooser_label_for_uri (const gchar *uri)
1690 const gchar *path, *start, *end, *p;
1691 gchar *host, *label;
1693 start = strstr (uri, "://");
1695 path = strchr (start, '/');
1701 end = uri + strlen (uri);
1705 /* strip username */
1706 p = strchr (start, '@');
1712 p = strchr (start, ':');
1716 host = g_strndup (start, end - start);
1718 /* Translators: the first string is a path and the second string
1719 * is a hostname. Nautilus and the panel contain the same string
1722 label = g_strdup_printf (_("%1$s on %2$s"), path, host);
1729 /* Inserts a path in the shortcuts tree, making a copy of it; alternatively,
1730 * inserts a volume. A position of -1 indicates the end of the tree.
1733 shortcuts_insert_path (GtkFileChooserDefault *impl,
1735 ShortcutType shortcut_type,
1736 GtkFileSystemVolume *volume,
1737 const GtkFilePath *path,
1740 ShortcutsIndex type)
1743 GdkPixbuf *pixbuf = NULL;
1744 gpointer data = NULL;
1746 GtkIconTheme *icon_theme;
1748 profile_start ("start", (shortcut_type == SHORTCUT_TYPE_VOLUME) ? "volume"
1749 : ((shortcut_type == SHORTCUT_TYPE_PATH) ? (char *) path : NULL));
1751 if (shortcut_type == SHORTCUT_TYPE_VOLUME)
1754 label_copy = gtk_file_system_volume_get_display_name (impl->file_system, volume);
1755 pixbuf = gtk_file_system_volume_render_icon (impl->file_system, volume, GTK_WIDGET (impl),
1756 impl->icon_size, NULL);
1758 else if (shortcut_type == SHORTCUT_TYPE_PATH)
1760 if (gtk_file_system_path_is_local (impl->file_system, path))
1762 struct ShortcutsInsertRequest *request;
1763 GtkFileSystemHandle *handle;
1766 request = g_new0 (struct ShortcutsInsertRequest, 1);
1767 request->impl = g_object_ref (impl);
1768 request->path = gtk_file_path_copy (path);
1769 request->name_only = TRUE;
1770 request->removable = removable;
1772 request->type = type;
1774 request->label_copy = g_strdup (label);
1777 gtk_list_store_append (impl->shortcuts_model, &iter);
1779 gtk_list_store_insert (impl->shortcuts_model, &iter, pos);
1781 p = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
1782 request->row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (impl->shortcuts_model), p);
1783 gtk_tree_path_free (p);
1785 handle = gtk_file_system_get_info (request->impl->file_system, request->path,
1786 GTK_FILE_INFO_DISPLAY_NAME | GTK_FILE_INFO_IS_HIDDEN | GTK_FILE_INFO_ICON,
1787 get_file_info_finished, request);
1789 gtk_list_store_set (impl->shortcuts_model, &iter,
1790 SHORTCUTS_COL_DATA, gtk_file_path_copy (path),
1791 SHORTCUTS_COL_TYPE, SHORTCUT_TYPE_PATH,
1792 SHORTCUTS_COL_HANDLE, handle,
1795 shortcuts_update_count (impl, type, 1);
1801 /* Don't call get_info for remote paths to avoid latency and
1804 data = gtk_file_path_copy (path);
1806 label_copy = g_strdup (label);
1811 uri = gtk_file_system_path_to_uri (impl->file_system, path);
1813 label_copy = _gtk_file_chooser_label_for_uri (uri);
1818 /* If we switch to a better bookmarks file format (XBEL), we
1819 * should use mime info to get a better icon.
1821 icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl)));
1822 pixbuf = gtk_icon_theme_load_icon (icon_theme, "gnome-fs-share",
1823 impl->icon_size, 0, NULL);
1828 g_assert_not_reached ();
1834 gtk_list_store_append (impl->shortcuts_model, &iter);
1836 gtk_list_store_insert (impl->shortcuts_model, &iter, pos);
1838 shortcuts_update_count (impl, type, 1);
1840 gtk_list_store_set (impl->shortcuts_model, &iter,
1841 SHORTCUTS_COL_PIXBUF, pixbuf,
1842 SHORTCUTS_COL_PIXBUF_VISIBLE, TRUE,
1843 SHORTCUTS_COL_NAME, label_copy,
1844 SHORTCUTS_COL_DATA, data,
1845 SHORTCUTS_COL_TYPE, shortcut_type,
1846 SHORTCUTS_COL_REMOVABLE, removable,
1847 SHORTCUTS_COL_HANDLE, NULL,
1850 if (impl->shortcuts_pane_filter_model)
1851 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_pane_filter_model));
1853 if (impl->shortcuts_combo_filter_model)
1854 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_combo_filter_model));
1856 if (type == SHORTCUTS_CURRENT_FOLDER && impl->save_folder_combo != NULL)
1858 /* The current folder is updated via _activate_iter(), don't
1859 * have save_folder_combo_changed_cb() call _activate_iter()
1862 gint combo_pos = shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER);
1864 if (impl->has_search)
1867 if (impl->has_recent)
1870 g_signal_handlers_block_by_func (impl->save_folder_combo,
1871 G_CALLBACK (save_folder_combo_changed_cb),
1874 gtk_combo_box_set_active (GTK_COMBO_BOX (impl->save_folder_combo), combo_pos);
1875 g_signal_handlers_unblock_by_func (impl->save_folder_combo,
1876 G_CALLBACK (save_folder_combo_changed_cb),
1880 g_free (label_copy);
1883 g_object_unref (pixbuf);
1885 profile_end ("end", NULL);
1889 shortcuts_append_search (GtkFileChooserDefault *impl)
1894 pixbuf = render_search_icon (impl);
1896 gtk_list_store_append (impl->shortcuts_model, &iter);
1897 gtk_list_store_set (impl->shortcuts_model, &iter,
1898 SHORTCUTS_COL_PIXBUF, pixbuf,
1899 SHORTCUTS_COL_PIXBUF_VISIBLE, TRUE,
1900 SHORTCUTS_COL_NAME, _("Search"),
1901 SHORTCUTS_COL_DATA, NULL,
1902 SHORTCUTS_COL_TYPE, SHORTCUT_TYPE_SEARCH,
1903 SHORTCUTS_COL_REMOVABLE, FALSE,
1907 g_object_unref (pixbuf);
1909 impl->has_search = TRUE;
1913 shortcuts_append_recent (GtkFileChooserDefault *impl)
1918 pixbuf = render_recent_icon (impl);
1920 gtk_list_store_append (impl->shortcuts_model, &iter);
1921 gtk_list_store_set (impl->shortcuts_model, &iter,
1922 SHORTCUTS_COL_PIXBUF, pixbuf,
1923 SHORTCUTS_COL_PIXBUF_VISIBLE, TRUE,
1924 SHORTCUTS_COL_NAME, _("Recently Used"),
1925 SHORTCUTS_COL_DATA, NULL,
1926 SHORTCUTS_COL_TYPE, SHORTCUT_TYPE_RECENT,
1927 SHORTCUTS_COL_REMOVABLE, FALSE,
1931 g_object_unref (pixbuf);
1933 impl->has_recent = TRUE;
1936 /* Appends an item for the user's home directory to the shortcuts model */
1938 shortcuts_append_home (GtkFileChooserDefault *impl)
1941 GtkFilePath *home_path;
1943 profile_start ("start", NULL);
1945 home = g_get_home_dir ();
1948 profile_end ("end - no home directory!?", NULL);
1952 home_path = gtk_file_system_filename_to_path (impl->file_system, home);
1954 shortcuts_insert_path (impl, -1, SHORTCUT_TYPE_PATH, NULL, home_path, NULL, FALSE, SHORTCUTS_HOME);
1955 impl->has_home = TRUE;
1957 gtk_file_path_free (home_path);
1959 profile_end ("end", NULL);
1962 /* Appends the ~/Desktop directory to the shortcuts model */
1964 shortcuts_append_desktop (GtkFileChooserDefault *impl)
1969 profile_start ("start", NULL);
1971 name = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
1972 path = gtk_file_system_filename_to_path (impl->file_system, name);
1973 shortcuts_insert_path (impl, -1, SHORTCUT_TYPE_PATH, NULL, path, _("Desktop"), FALSE, SHORTCUTS_DESKTOP);
1974 impl->has_desktop = TRUE;
1976 /* We do not actually pop up an error dialog if there is no desktop directory
1977 * because some people may really not want to have one.
1980 gtk_file_path_free (path);
1982 profile_end ("end", NULL);
1985 /* Appends a list of GtkFilePath to the shortcuts model; returns how many were inserted */
1987 shortcuts_append_paths (GtkFileChooserDefault *impl,
1994 profile_start ("start", NULL);
1996 start_row = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR) + 1;
1999 for (; paths; paths = paths->next)
2005 if (impl->local_only &&
2006 !gtk_file_system_path_is_local (impl->file_system, path))
2008 if (shortcut_find_position (impl, path) != -1)
2011 label = gtk_file_system_get_bookmark_label (impl->file_system, path);
2013 /* NULL GError, but we don't really want to show error boxes here */
2014 shortcuts_insert_path (impl, start_row + num_inserted, SHORTCUT_TYPE_PATH, NULL, path, label, TRUE, SHORTCUTS_BOOKMARKS);
2020 profile_end ("end", NULL);
2022 return num_inserted;
2025 /* Returns the index for the corresponding item in the shortcuts bar */
2027 shortcuts_get_index (GtkFileChooserDefault *impl,
2028 ShortcutsIndex where)
2034 if (where == SHORTCUTS_SEARCH)
2037 n += impl->has_search ? 1 : 0;
2039 if (where == SHORTCUTS_RECENT)
2042 n += impl->has_recent ? 1 : 0;
2044 if (where == SHORTCUTS_RECENT_SEPARATOR)
2047 n += impl->has_recent ? 1 : 0;
2049 if (where == SHORTCUTS_HOME)
2052 n += impl->has_home ? 1 : 0;
2054 if (where == SHORTCUTS_DESKTOP)
2057 n += impl->has_desktop ? 1 : 0;
2059 if (where == SHORTCUTS_VOLUMES)
2062 n += impl->num_volumes;
2064 if (where == SHORTCUTS_SHORTCUTS)
2067 n += impl->num_shortcuts;
2069 if (where == SHORTCUTS_BOOKMARKS_SEPARATOR)
2072 /* If there are no bookmarks there won't be a separator */
2073 n += (impl->num_bookmarks > 0) ? 1 : 0;
2075 if (where == SHORTCUTS_BOOKMARKS)
2078 n += impl->num_bookmarks;
2080 if (where == SHORTCUTS_CURRENT_FOLDER_SEPARATOR)
2085 if (where == SHORTCUTS_CURRENT_FOLDER)
2088 g_assert_not_reached ();
2095 /* Adds all the file system volumes to the shortcuts model */
2097 shortcuts_add_volumes (GtkFileChooserDefault *impl)
2102 gboolean old_changing_folders;
2104 profile_start ("start", NULL);
2107 old_changing_folders = impl->changing_folder;
2108 impl->changing_folder = TRUE;
2110 start_row = shortcuts_get_index (impl, SHORTCUTS_VOLUMES);
2111 shortcuts_remove_rows (impl, start_row, impl->num_volumes);
2112 impl->num_volumes = 0;
2114 list = gtk_file_system_list_volumes (impl->file_system);
2118 for (l = list; l; l = l->next)
2120 GtkFileSystemVolume *volume;
2124 if (impl->local_only)
2126 if (gtk_file_system_volume_get_is_mounted (impl->file_system, volume))
2128 GtkFilePath *base_path;
2130 base_path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
2131 if (base_path != NULL)
2133 gboolean is_local = gtk_file_system_path_is_local (impl->file_system, base_path);
2134 gtk_file_path_free (base_path);
2138 gtk_file_system_volume_free (impl->file_system, volume);
2145 shortcuts_insert_path (impl, start_row + n, SHORTCUT_TYPE_VOLUME, volume, NULL, NULL, FALSE, SHORTCUTS_VOLUMES);
2149 impl->num_volumes = n;
2150 g_slist_free (list);
2152 if (impl->shortcuts_pane_filter_model)
2153 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_pane_filter_model));
2155 if (impl->shortcuts_combo_filter_model)
2156 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_combo_filter_model));
2158 impl->changing_folder = old_changing_folders;
2160 profile_end ("end", NULL);
2163 /* Inserts a separator node in the shortcuts list */
2165 shortcuts_insert_separator (GtkFileChooserDefault *impl,
2166 ShortcutsIndex where)
2170 g_assert (where == SHORTCUTS_RECENT_SEPARATOR ||
2171 where == SHORTCUTS_BOOKMARKS_SEPARATOR ||
2172 where == SHORTCUTS_CURRENT_FOLDER_SEPARATOR);
2174 gtk_list_store_insert (impl->shortcuts_model, &iter,
2175 shortcuts_get_index (impl, where));
2176 gtk_list_store_set (impl->shortcuts_model, &iter,
2177 SHORTCUTS_COL_PIXBUF, NULL,
2178 SHORTCUTS_COL_PIXBUF_VISIBLE, FALSE,
2179 SHORTCUTS_COL_NAME, NULL,
2180 SHORTCUTS_COL_DATA, NULL,
2181 SHORTCUTS_COL_TYPE, SHORTCUT_TYPE_SEPARATOR,
2185 /* Updates the list of bookmarks */
2187 shortcuts_add_bookmarks (GtkFileChooserDefault *impl)
2190 gboolean old_changing_folders;
2192 GtkFilePath *list_selected = NULL;
2193 GtkFilePath *combo_selected = NULL;
2194 ShortcutType shortcut_type;
2197 profile_start ("start", NULL);
2199 old_changing_folders = impl->changing_folder;
2200 impl->changing_folder = TRUE;
2202 if (shortcuts_get_selected (impl, &iter))
2204 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model),
2206 SHORTCUTS_COL_DATA, &col_data,
2207 SHORTCUTS_COL_TYPE, &shortcut_type,
2210 if (col_data && shortcut_type == SHORTCUT_TYPE_PATH)
2211 list_selected = gtk_file_path_copy (col_data);
2214 if (impl->save_folder_combo &&
2215 gtk_combo_box_get_active_iter (GTK_COMBO_BOX (impl->save_folder_combo),
2218 GtkTreeIter child_iter;
2220 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (impl->shortcuts_combo_filter_model),
2223 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model),
2225 SHORTCUTS_COL_DATA, &col_data,
2226 SHORTCUTS_COL_TYPE, &shortcut_type,
2229 if (col_data && shortcut_type == SHORTCUT_TYPE_PATH)
2230 combo_selected = gtk_file_path_copy (col_data);
2233 if (impl->num_bookmarks > 0)
2234 shortcuts_remove_rows (impl,
2235 shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR),
2236 impl->num_bookmarks + 1);
2238 impl->num_bookmarks = 0;
2239 shortcuts_insert_separator (impl, SHORTCUTS_BOOKMARKS_SEPARATOR);
2241 bookmarks = gtk_file_system_list_bookmarks (impl->file_system);
2242 shortcuts_append_paths (impl, bookmarks);
2243 gtk_file_paths_free (bookmarks);
2245 if (impl->num_bookmarks == 0)
2246 shortcuts_remove_rows (impl, shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR), 1);
2248 if (impl->shortcuts_pane_filter_model)
2249 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_pane_filter_model));
2251 if (impl->shortcuts_combo_filter_model)
2252 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_combo_filter_model));
2256 shortcuts_find_folder (impl, list_selected);
2257 gtk_file_path_free (list_selected);
2264 pos = shortcut_find_position (impl, combo_selected);
2267 if (impl->has_search)
2270 if (impl->has_recent)
2273 gtk_combo_box_set_active (GTK_COMBO_BOX (impl->save_folder_combo), pos);
2276 gtk_file_path_free (combo_selected);
2279 impl->changing_folder = old_changing_folders;
2281 profile_end ("end", NULL);
2284 /* Appends a separator and a row to the shortcuts list for the current folder */
2286 shortcuts_add_current_folder (GtkFileChooserDefault *impl)
2291 g_assert (!impl->shortcuts_current_folder_active);
2295 g_assert (impl->current_folder != NULL);
2297 pos = shortcut_find_position (impl, impl->current_folder);
2300 GtkFileSystemVolume *volume;
2301 GtkFilePath *base_path;
2305 shortcuts_insert_separator (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR);
2309 pos = shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER);
2311 volume = gtk_file_system_get_volume_for_path (impl->file_system, impl->current_folder);
2313 base_path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
2318 strcmp (gtk_file_path_get_string (base_path), gtk_file_path_get_string (impl->current_folder)) == 0)
2320 shortcuts_insert_path (impl, pos, SHORTCUT_TYPE_VOLUME, volume, NULL, NULL, FALSE, SHORTCUTS_CURRENT_FOLDER);
2324 shortcuts_insert_path (impl, pos, SHORTCUT_TYPE_PATH, NULL, impl->current_folder, NULL, FALSE, SHORTCUTS_CURRENT_FOLDER);
2326 gtk_file_system_volume_free (impl->file_system, volume);
2330 gtk_file_path_free (base_path);
2332 else if (impl->save_folder_combo != NULL)
2334 if (impl->has_search)
2337 if (impl->has_recent)
2338 pos -= 2; /* + separator */
2340 gtk_combo_box_set_active (GTK_COMBO_BOX (impl->save_folder_combo), pos);
2344 /* Updates the current folder row in the shortcuts model */
2346 shortcuts_update_current_folder (GtkFileChooserDefault *impl)
2350 pos = shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR);
2352 if (impl->shortcuts_current_folder_active)
2354 shortcuts_remove_rows (impl, pos, 2);
2355 impl->shortcuts_current_folder_active = FALSE;
2358 shortcuts_add_current_folder (impl);
2361 /* Filter function used for the shortcuts filter model */
2363 shortcuts_pane_filter_cb (GtkTreeModel *model,
2367 GtkFileChooserDefault *impl;
2371 impl = GTK_FILE_CHOOSER_DEFAULT (data);
2373 path = gtk_tree_model_get_path (model, iter);
2377 pos = *gtk_tree_path_get_indices (path);
2378 gtk_tree_path_free (path);
2380 return (pos < shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR));
2383 /* Creates the list model for shortcuts */
2385 shortcuts_model_create (GtkFileChooserDefault *impl)
2387 /* Keep this order in sync with the SHORCUTS_COL_* enum values */
2388 impl->shortcuts_model = gtk_list_store_new (SHORTCUTS_COL_NUM_COLUMNS,
2389 GDK_TYPE_PIXBUF, /* pixbuf */
2390 G_TYPE_STRING, /* name */
2391 G_TYPE_POINTER, /* path or volume */
2392 G_TYPE_INT, /* ShortcutType */
2393 G_TYPE_BOOLEAN, /* removable */
2394 G_TYPE_BOOLEAN, /* pixbuf cell visibility */
2395 G_TYPE_POINTER); /* GtkFileSystemHandle */
2397 if (search_is_possible (impl))
2399 shortcuts_append_search (impl);
2402 if (impl->recent_manager)
2404 shortcuts_append_recent (impl);
2405 shortcuts_insert_separator (impl, SHORTCUTS_RECENT_SEPARATOR);
2408 if (impl->file_system)
2410 shortcuts_append_home (impl);
2411 shortcuts_append_desktop (impl);
2412 shortcuts_add_volumes (impl);
2415 impl->shortcuts_pane_filter_model = shortcuts_pane_model_filter_new (impl,
2416 GTK_TREE_MODEL (impl->shortcuts_model),
2419 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (impl->shortcuts_pane_filter_model),
2420 shortcuts_pane_filter_cb,
2425 /* Callback used when the "New Folder" button is clicked */
2427 new_folder_button_clicked (GtkButton *button,
2428 GtkFileChooserDefault *impl)
2433 if (!impl->browse_files_model)
2434 return; /* FIXME: this sucks. Disable the New Folder button or something. */
2436 /* Prevent button from being clicked twice */
2437 gtk_widget_set_sensitive (impl->browse_new_folder_button, FALSE);
2439 _gtk_file_system_model_add_editable (impl->browse_files_model, &iter);
2441 path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->browse_files_model), &iter);
2442 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (impl->browse_files_tree_view),
2443 path, impl->list_name_column,
2446 g_object_set (impl->list_name_renderer, "editable", TRUE, NULL);
2447 gtk_tree_view_set_cursor (GTK_TREE_VIEW (impl->browse_files_tree_view),
2449 impl->list_name_column,
2452 gtk_tree_path_free (path);
2456 edited_idle_create_folder_cb (GtkFileSystemHandle *handle,
2457 const GtkFilePath *path,
2458 const GError *error,
2461 gboolean cancelled = handle->cancelled;
2462 GtkFileChooserDefault *impl = data;
2464 if (!g_slist_find (impl->pending_handles, handle))
2467 impl->pending_handles = g_slist_remove (impl->pending_handles, handle);
2473 change_folder_and_display_error (impl, path, FALSE);
2475 error_creating_folder_dialog (impl, path, g_error_copy (error));
2478 g_object_unref (impl);
2479 g_object_unref (handle);
2482 /* Idle handler for creating a new folder after editing its name cell, or for
2483 * canceling the editing.
2486 edited_idle_cb (GtkFileChooserDefault *impl)
2488 GDK_THREADS_ENTER ();
2490 g_source_destroy (impl->edited_idle);
2491 impl->edited_idle = NULL;
2493 _gtk_file_system_model_remove_editable (impl->browse_files_model);
2494 g_object_set (impl->list_name_renderer, "editable", FALSE, NULL);
2496 gtk_widget_set_sensitive (impl->browse_new_folder_button, TRUE);
2498 if (impl->edited_new_text) /* not cancelled? */
2501 GtkFilePath *file_path;
2504 file_path = gtk_file_system_make_path (impl->file_system,
2505 impl->current_folder,
2506 impl->edited_new_text,
2510 GtkFileSystemHandle *handle;
2512 handle = gtk_file_system_create_folder (impl->file_system, file_path,
2513 edited_idle_create_folder_cb,
2514 g_object_ref (impl));
2515 impl->pending_handles = g_slist_append (impl->pending_handles, handle);
2517 gtk_file_path_free (file_path);
2520 error_creating_folder_dialog (impl, file_path, error);
2522 g_free (impl->edited_new_text);
2523 impl->edited_new_text = NULL;
2526 GDK_THREADS_LEAVE ();
2532 queue_edited_idle (GtkFileChooserDefault *impl,
2533 const gchar *new_text)
2535 /* We create the folder in an idle handler so that we don't modify the tree
2539 if (!impl->edited_idle)
2541 impl->edited_idle = g_idle_source_new ();
2542 g_source_set_closure (impl->edited_idle,
2543 g_cclosure_new_object (G_CALLBACK (edited_idle_cb),
2545 g_source_attach (impl->edited_idle, NULL);
2548 g_free (impl->edited_new_text);
2549 impl->edited_new_text = g_strdup (new_text);
2552 /* Callback used from the text cell renderer when the new folder is named */
2554 renderer_edited_cb (GtkCellRendererText *cell_renderer_text,
2556 const gchar *new_text,
2557 GtkFileChooserDefault *impl)
2559 /* work around bug #154921 */
2560 g_object_set (cell_renderer_text,
2561 "mode", GTK_CELL_RENDERER_MODE_INERT, NULL);
2562 queue_edited_idle (impl, new_text);
2565 /* Callback used from the text cell renderer when the new folder edition gets
2569 renderer_editing_canceled_cb (GtkCellRendererText *cell_renderer_text,
2570 GtkFileChooserDefault *impl)
2572 /* work around bug #154921 */
2573 g_object_set (cell_renderer_text,
2574 "mode", GTK_CELL_RENDERER_MODE_INERT, NULL);
2575 queue_edited_idle (impl, NULL);
2578 /* Creates the widgets for the filter combo box */
2580 filter_create (GtkFileChooserDefault *impl)
2582 impl->filter_combo = gtk_combo_box_new_text ();
2583 gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (impl->filter_combo), FALSE);
2585 g_signal_connect (impl->filter_combo, "changed",
2586 G_CALLBACK (filter_combo_changed), impl);
2588 gtk_widget_set_tooltip_text (impl->filter_combo,
2589 _("Select which types of files are shown"));
2591 return impl->filter_combo;
2595 button_new (GtkFileChooserDefault *impl,
2597 const char *stock_id,
2605 button = gtk_button_new_with_mnemonic (text);
2606 image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
2607 gtk_button_set_image (GTK_BUTTON (button), image);
2609 gtk_widget_set_sensitive (button, sensitive);
2610 g_signal_connect (button, "clicked", callback, impl);
2613 gtk_widget_show (button);
2618 /* Looks for a path among the shortcuts; returns its index or -1 if it doesn't exist */
2620 shortcut_find_position (GtkFileChooserDefault *impl,
2621 const GtkFilePath *path)
2625 int current_folder_separator_idx;
2627 if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
2630 current_folder_separator_idx = shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR);
2633 /* FIXME: is this still needed? */
2634 if (current_folder_separator_idx >= impl->shortcuts_model->length)
2638 for (i = 0; i < current_folder_separator_idx; i++)
2641 ShortcutType shortcut_type;
2643 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
2644 SHORTCUTS_COL_DATA, &col_data,
2645 SHORTCUTS_COL_TYPE, &shortcut_type,
2650 if (shortcut_type == SHORTCUT_TYPE_VOLUME)
2652 GtkFileSystemVolume *volume;
2653 GtkFilePath *base_path;
2657 base_path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
2659 exists = base_path && strcmp (gtk_file_path_get_string (path),
2660 gtk_file_path_get_string (base_path)) == 0;
2666 else if (shortcut_type == SHORTCUT_TYPE_PATH)
2668 GtkFilePath *model_path;
2670 model_path = col_data;
2672 if (model_path && gtk_file_path_compare (model_path, path) == 0)
2677 if (i < current_folder_separator_idx - 1)
2679 if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
2680 g_assert_not_reached ();
2687 /* Tries to add a bookmark from a path name */
2689 shortcuts_add_bookmark_from_path (GtkFileChooserDefault *impl,
2690 const GtkFilePath *path,
2695 g_return_val_if_fail (path != NULL, FALSE);
2697 if (shortcut_find_position (impl, path) != -1)
2701 if (!gtk_file_system_insert_bookmark (impl->file_system, path, pos, &error))
2703 error_adding_bookmark_dialog (impl, path, error);
2711 add_bookmark_foreach_cb (GtkTreeModel *model,
2716 GtkFileChooserDefault *impl;
2717 GtkFileSystemModel *fs_model;
2718 GtkTreeIter child_iter;
2719 const GtkFilePath *file_path;
2721 impl = (GtkFileChooserDefault *) data;
2723 switch (impl->operation_mode)
2725 case OPERATION_MODE_BROWSE:
2726 fs_model = impl->browse_files_model;
2727 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model, &child_iter, iter);
2728 file_path = _gtk_file_system_model_get_path (fs_model, &child_iter);
2731 case OPERATION_MODE_SEARCH:
2732 search_get_valid_child_iter (impl, &child_iter, iter);
2733 gtk_tree_model_get (GTK_TREE_MODEL (impl->search_model), &child_iter,
2734 SEARCH_MODEL_COL_PATH, &file_path,
2738 case OPERATION_MODE_RECENT:
2739 recent_get_valid_child_iter (impl, &child_iter, iter);
2740 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &child_iter,
2741 RECENT_MODEL_COL_PATH, &file_path,
2746 shortcuts_add_bookmark_from_path (impl, file_path, -1);
2749 /* Adds a bookmark from the currently selected item in the file list */
2751 bookmarks_add_selected_folder (GtkFileChooserDefault *impl)
2753 GtkTreeSelection *selection;
2755 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
2757 if (gtk_tree_selection_count_selected_rows (selection) == 0)
2758 shortcuts_add_bookmark_from_path (impl, impl->current_folder, -1);
2760 gtk_tree_selection_selected_foreach (selection,
2761 add_bookmark_foreach_cb,
2765 /* Callback used when the "Add bookmark" button is clicked */
2767 add_bookmark_button_clicked_cb (GtkButton *button,
2768 GtkFileChooserDefault *impl)
2770 bookmarks_add_selected_folder (impl);
2773 /* Returns TRUE plus an iter in the shortcuts_model if a row is selected;
2774 * returns FALSE if no shortcut is selected.
2777 shortcuts_get_selected (GtkFileChooserDefault *impl,
2780 GtkTreeSelection *selection;
2781 GtkTreeIter parent_iter;
2783 if (!impl->browse_shortcuts_tree_view)
2786 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view));
2788 if (!gtk_tree_selection_get_selected (selection, NULL, &parent_iter))
2791 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (impl->shortcuts_pane_filter_model),
2797 /* Removes the selected bookmarks */
2799 remove_selected_bookmarks (GtkFileChooserDefault *impl)
2807 if (!shortcuts_get_selected (impl, &iter))
2810 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
2811 SHORTCUTS_COL_DATA, &col_data,
2812 SHORTCUTS_COL_REMOVABLE, &removable,
2818 g_assert (col_data != NULL);
2823 if (!gtk_file_system_remove_bookmark (impl->file_system, path, &error))
2824 error_removing_bookmark_dialog (impl, path, error);
2827 /* Callback used when the "Remove bookmark" button is clicked */
2829 remove_bookmark_button_clicked_cb (GtkButton *button,
2830 GtkFileChooserDefault *impl)
2832 remove_selected_bookmarks (impl);
2835 struct selection_check_closure {
2836 GtkFileChooserDefault *impl;
2839 gboolean all_folders;
2842 /* Used from gtk_tree_selection_selected_foreach() */
2844 selection_check_foreach_cb (GtkTreeModel *model,
2849 struct selection_check_closure *closure;
2850 GtkTreeIter child_iter;
2851 const GtkFileInfo *info;
2855 closure->num_selected++;
2857 switch (closure->impl->operation_mode)
2859 case OPERATION_MODE_BROWSE:
2860 gtk_tree_model_sort_convert_iter_to_child_iter (closure->impl->sort_model, &child_iter, iter);
2861 info = _gtk_file_system_model_get_info (closure->impl->browse_files_model, &child_iter);
2862 is_folder = info ? gtk_file_info_get_is_folder (info) : FALSE;
2865 case OPERATION_MODE_SEARCH:
2866 search_get_valid_child_iter (closure->impl, &child_iter, iter);
2867 gtk_tree_model_get (GTK_TREE_MODEL (closure->impl->search_model), &child_iter,
2868 SEARCH_MODEL_COL_IS_FOLDER, &is_folder,
2872 case OPERATION_MODE_RECENT:
2873 recent_get_valid_child_iter (closure->impl, &child_iter, iter);
2874 gtk_tree_model_get (GTK_TREE_MODEL (closure->impl->recent_model), &child_iter,
2875 RECENT_MODEL_COL_IS_FOLDER, &is_folder,
2880 closure->all_folders = closure->all_folders && is_folder;
2881 closure->all_files = closure->all_files && !is_folder;
2884 /* Checks whether the selected items in the file list are all files or all folders */
2886 selection_check (GtkFileChooserDefault *impl,
2888 gboolean *all_files,
2889 gboolean *all_folders)
2891 struct selection_check_closure closure;
2892 GtkTreeSelection *selection;
2894 closure.impl = impl;
2895 closure.num_selected = 0;
2896 closure.all_files = TRUE;
2897 closure.all_folders = TRUE;
2899 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
2900 gtk_tree_selection_selected_foreach (selection,
2901 selection_check_foreach_cb,
2904 g_assert (closure.num_selected == 0 || !(closure.all_files && closure.all_folders));
2907 *num_selected = closure.num_selected;
2910 *all_files = closure.all_files;
2913 *all_folders = closure.all_folders;
2916 struct get_selected_path_closure {
2917 GtkFileChooserDefault *impl;
2918 const GtkFilePath *path;
2922 get_selected_path_foreach_cb (GtkTreeModel *model,
2927 struct get_selected_path_closure *closure;
2928 GtkTreeIter child_iter;
2932 switch (closure->impl->operation_mode)
2934 case OPERATION_MODE_BROWSE:
2935 gtk_tree_model_sort_convert_iter_to_child_iter (closure->impl->sort_model, &child_iter, iter);
2936 closure->path = _gtk_file_system_model_get_path (closure->impl->browse_files_model, &child_iter);
2939 case OPERATION_MODE_SEARCH:
2940 search_get_valid_child_iter (closure->impl, &child_iter, iter);
2941 gtk_tree_model_get (GTK_TREE_MODEL (closure->impl->search_model), &child_iter,
2942 SEARCH_MODEL_COL_PATH, &closure->path,
2946 case OPERATION_MODE_RECENT:
2947 recent_get_valid_child_iter (closure->impl, &child_iter, iter);
2948 gtk_tree_model_get (GTK_TREE_MODEL (closure->impl->recent_model), &child_iter,
2949 RECENT_MODEL_COL_PATH, &closure->path,
2955 /* Returns a selected path from the file list */
2956 static const GtkFilePath *
2957 get_selected_path (GtkFileChooserDefault *impl)
2959 struct get_selected_path_closure closure;
2960 GtkTreeSelection *selection;
2962 closure.impl = impl;
2963 closure.path = NULL;
2965 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
2966 gtk_tree_selection_selected_foreach (selection,
2967 get_selected_path_foreach_cb,
2970 return closure.path;
2974 GtkFileChooserDefault *impl;
2976 } UpdateTooltipData;
2979 update_tooltip (GtkTreeModel *model,
2984 UpdateTooltipData *udata = data;
2985 GtkTreeIter child_iter;
2986 const GtkFileInfo *info;
2988 if (udata->tip == NULL)
2990 const gchar *display_name;
2992 switch (udata->impl->operation_mode)
2994 case OPERATION_MODE_BROWSE:
2995 gtk_tree_model_sort_convert_iter_to_child_iter (udata->impl->sort_model,
2998 info = _gtk_file_system_model_get_info (udata->impl->browse_files_model, &child_iter);
2999 display_name = gtk_file_info_get_display_name (info);
3002 case OPERATION_MODE_SEARCH:
3003 search_get_valid_child_iter (udata->impl, &child_iter, iter);
3004 gtk_tree_model_get (GTK_TREE_MODEL (udata->impl->search_model), &child_iter,
3005 SEARCH_MODEL_COL_DISPLAY_NAME, &display_name,
3009 case OPERATION_MODE_RECENT:
3010 recent_get_valid_child_iter (udata->impl, &child_iter, iter);
3011 gtk_tree_model_get (GTK_TREE_MODEL (udata->impl->recent_model), &child_iter,
3012 RECENT_MODEL_COL_DISPLAY_NAME, &display_name,
3017 udata->tip = g_strdup_printf (_("Add the folder '%s' to the bookmarks"),
3023 /* Sensitize the "add bookmark" button if all the selected items are folders, or
3024 * if there are no selected items *and* the current folder is not in the
3025 * bookmarks list. De-sensitize the button otherwise.
3028 bookmarks_check_add_sensitivity (GtkFileChooserDefault *impl)
3031 gboolean all_folders;
3035 selection_check (impl, &num_selected, NULL, &all_folders);
3037 if (num_selected == 0)
3038 active = (impl->current_folder != NULL) && (shortcut_find_position (impl, impl->current_folder) == -1);
3039 else if (num_selected == 1)
3041 const GtkFilePath *path;
3043 path = get_selected_path (impl);
3044 active = all_folders && (shortcut_find_position (impl, path) == -1);
3047 active = all_folders;
3049 gtk_widget_set_sensitive (impl->browse_shortcuts_add_button, active);
3051 if (impl->browse_files_popup_menu_add_shortcut_item)
3052 gtk_widget_set_sensitive (impl->browse_files_popup_menu_add_shortcut_item,
3053 (num_selected == 0) ? FALSE : active);
3057 if (num_selected == 0)
3058 tip = g_strdup_printf (_("Add the current folder to the bookmarks"));
3059 else if (num_selected > 1)
3060 tip = g_strdup_printf (_("Add the selected folders to the bookmarks"));
3063 GtkTreeSelection *selection;
3064 UpdateTooltipData data;
3066 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
3069 gtk_tree_selection_selected_foreach (selection, update_tooltip, &data);
3073 gtk_widget_set_tooltip_text (impl->browse_shortcuts_add_button, tip);
3078 /* Sets the sensitivity of the "remove bookmark" button depending on whether a
3079 * bookmark row is selected in the shortcuts tree.
3082 bookmarks_check_remove_sensitivity (GtkFileChooserDefault *impl)
3085 gboolean removable = FALSE;
3088 if (shortcuts_get_selected (impl, &iter))
3089 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
3090 SHORTCUTS_COL_REMOVABLE, &removable,
3091 SHORTCUTS_COL_NAME, &name,
3094 gtk_widget_set_sensitive (impl->browse_shortcuts_remove_button, removable);
3100 tip = g_strdup_printf (_("Remove the bookmark '%s'"), name);
3101 gtk_widget_set_tooltip_text (impl->browse_shortcuts_remove_button, tip);
3109 shortcuts_check_popup_sensitivity (GtkFileChooserDefault *impl)
3112 gboolean removable = FALSE;
3114 if (impl->browse_shortcuts_popup_menu == NULL)
3117 if (shortcuts_get_selected (impl, &iter))
3118 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
3119 SHORTCUTS_COL_REMOVABLE, &removable,
3122 gtk_widget_set_sensitive (impl->browse_shortcuts_popup_menu_remove_item, removable);
3123 gtk_widget_set_sensitive (impl->browse_shortcuts_popup_menu_rename_item, removable);
3126 /* GtkWidget::drag-begin handler for the shortcuts list. */
3128 shortcuts_drag_begin_cb (GtkWidget *widget,
3129 GdkDragContext *context,
3130 GtkFileChooserDefault *impl)
3133 impl->shortcuts_drag_context = g_object_ref (context);
3138 /* Removes the idle handler for outside drags */
3140 shortcuts_cancel_drag_outside_idle (GtkFileChooserDefault *impl)
3142 if (!impl->shortcuts_drag_outside_idle)
3145 g_source_destroy (impl->shortcuts_drag_outside_idle);
3146 impl->shortcuts_drag_outside_idle = NULL;
3150 /* GtkWidget::drag-end handler for the shortcuts list. */
3152 shortcuts_drag_end_cb (GtkWidget *widget,
3153 GdkDragContext *context,
3154 GtkFileChooserDefault *impl)
3157 g_object_unref (impl->shortcuts_drag_context);
3159 shortcuts_cancel_drag_outside_idle (impl);
3161 if (!impl->shortcuts_drag_outside)
3164 gtk_button_clicked (GTK_BUTTON (impl->browse_shortcuts_remove_button));
3166 impl->shortcuts_drag_outside = FALSE;
3170 /* GtkWidget::drag-data-delete handler for the shortcuts list. */
3172 shortcuts_drag_data_delete_cb (GtkWidget *widget,
3173 GdkDragContext *context,
3174 GtkFileChooserDefault *impl)
3176 g_signal_stop_emission_by_name (widget, "drag_data_delete");
3180 /* Creates a suitable drag cursor to indicate that the selected bookmark will be
3184 shortcuts_drag_set_delete_cursor (GtkFileChooserDefault *impl,
3187 GtkTreeView *tree_view;
3190 GdkPixmap *row_pixmap;
3195 tree_view = GTK_TREE_VIEW (impl->browse_shortcuts_tree_view);
3197 /* Find the selected path and get its drag pixmap */
3199 if (!shortcuts_get_selected (impl, &iter))
3200 g_assert_not_reached ();
3202 path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
3204 row_pixmap = gtk_tree_view_create_row_drag_icon (tree_view, path);
3205 gtk_tree_path_free (path);
3214 pixbuf = gtk_widget_render_icon (impl->browse_shortcuts_tree_view,
3220 GdkPixmap *composite;
3221 int row_pixmap_width, row_pixmap_height;
3222 int pixbuf_width, pixbuf_height;
3223 int composite_width, composite_height;
3224 int pixbuf_x, pixbuf_y;
3225 GdkGC *gc, *mask_gc;
3227 GdkBitmap *pixbuf_mask;
3229 /* Create pixmap and mask for composite image */
3231 gdk_drawable_get_size (row_pixmap, &row_pixmap_width, &row_pixmap_height);
3232 pixbuf_width = gdk_pixbuf_get_width (pixbuf);
3233 pixbuf_height = gdk_pixbuf_get_height (pixbuf);
3235 composite_width = MAX (row_pixmap_width, pixbuf_width);
3236 composite_height = MAX (row_pixmap_height, pixbuf_height);
3238 row_pixmap_y = (composite_height - row_pixmap_height) / 2;
3240 if (gtk_widget_get_direction (impl->browse_shortcuts_tree_view) == GTK_TEXT_DIR_RTL)
3243 pixbuf_x = composite_width - pixbuf_width;
3245 pixbuf_y = (composite_height - pixbuf_height) / 2;
3247 composite = gdk_pixmap_new (row_pixmap, composite_width, composite_height, -1);
3248 gc = gdk_gc_new (composite);
3250 mask = gdk_pixmap_new (row_pixmap, composite_width, composite_height, 1);
3251 mask_gc = gdk_gc_new (mask);
3253 gdk_gc_set_foreground (mask_gc, &color);
3254 gdk_draw_rectangle (mask, mask_gc, TRUE, 0, 0, composite_width, composite_height);
3257 color.green = 0xffff;
3258 color.blue = 0xffff;
3259 gdk_gc_set_rgb_fg_color (gc, &color);
3260 gdk_draw_rectangle (composite, gc, TRUE, 0, 0, composite_width, composite_height);
3262 /* Composite the row pixmap and the pixbuf */
3264 gdk_pixbuf_render_pixmap_and_mask_for_colormap
3266 gtk_widget_get_colormap (impl->browse_shortcuts_tree_view),
3267 NULL, &pixbuf_mask, 128);
3268 gdk_draw_drawable (mask, mask_gc, pixbuf_mask,
3271 pixbuf_width, pixbuf_height);
3272 g_object_unref (pixbuf_mask);
3274 gdk_draw_drawable (composite, gc, row_pixmap,
3277 row_pixmap_width, row_pixmap_height);
3279 gdk_gc_set_foreground (mask_gc, &color);
3280 gdk_draw_rectangle (mask, mask_gc, TRUE, 0, row_pixmap_y, row_pixmap_width, row_pixmap_height);
3282 gdk_draw_pixbuf (composite, gc, pixbuf,
3285 pixbuf_width, pixbuf_height,
3289 g_object_unref (pixbuf);
3290 g_object_unref (row_pixmap);
3292 row_pixmap = composite;
3296 /* The hotspot offsets here are copied from gtk_tree_view_drag_begin(), ugh */
3298 gtk_tree_view_get_path_at_pos (tree_view,
3299 tree_view->priv->press_start_x,
3300 tree_view->priv->press_start_y,
3306 gtk_drag_set_icon_pixmap (impl->shortcuts_drag_context,
3307 gdk_drawable_get_colormap (row_pixmap),
3310 tree_view->priv->press_start_x + 1,
3311 row_pixmap_y + cell_y + 1);
3313 g_object_unref (row_pixmap);
3315 g_object_unref (mask);
3318 /* We set the delete cursor and the shortcuts_drag_outside flag in an idle
3319 * handler so that we can tell apart the drag_leave event that comes right
3320 * before a drag_drop, from a normal drag_leave. We don't want to set the
3321 * cursor nor the flag in the latter case.
3324 shortcuts_drag_outside_idle_cb (GtkFileChooserDefault *impl)
3326 GDK_THREADS_ENTER ();
3328 shortcuts_drag_set_delete_cursor (impl, TRUE);
3329 impl->shortcuts_drag_outside = TRUE;
3331 shortcuts_cancel_drag_outside_idle (impl);
3333 GDK_THREADS_LEAVE ();
3339 /* GtkWidget::drag-leave handler for the shortcuts list. We unhighlight the
3343 shortcuts_drag_leave_cb (GtkWidget *widget,
3344 GdkDragContext *context,
3346 GtkFileChooserDefault *impl)
3349 if (gtk_drag_get_source_widget (context) == widget && !impl->shortcuts_drag_outside_idle)
3351 impl->shortcuts_drag_outside_idle = g_idle_source_new ();
3352 g_source_set_closure (impl->shortcuts_drag_outside_idle,
3353 g_cclosure_new_object (G_CALLBACK (shortcuts_drag_outside_idle_cb),
3355 g_source_attach (impl->shortcuts_drag_outside_idle, NULL);
3359 gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view),
3361 GTK_TREE_VIEW_DROP_BEFORE);
3363 g_signal_stop_emission_by_name (widget, "drag_leave");
3366 /* Computes the appropriate row and position for dropping */
3368 shortcuts_compute_drop_position (GtkFileChooserDefault *impl,
3372 GtkTreeViewDropPosition *pos)
3374 GtkTreeView *tree_view;
3375 GtkTreeViewColumn *column;
3379 int bookmarks_index;
3381 tree_view = GTK_TREE_VIEW (impl->browse_shortcuts_tree_view);
3383 bookmarks_index = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS);
3385 if (!gtk_tree_view_get_path_at_pos (tree_view,
3387 y - TREE_VIEW_HEADER_HEIGHT (tree_view),
3393 row = bookmarks_index + impl->num_bookmarks - 1;
3394 *path = gtk_tree_path_new_from_indices (row, -1);
3395 *pos = GTK_TREE_VIEW_DROP_AFTER;
3399 row = *gtk_tree_path_get_indices (*path);
3400 gtk_tree_view_get_background_area (tree_view, *path, column, &cell);
3401 gtk_tree_path_free (*path);
3403 if (row < bookmarks_index)
3405 row = bookmarks_index;
3406 *pos = GTK_TREE_VIEW_DROP_BEFORE;
3408 else if (row > bookmarks_index + impl->num_bookmarks - 1)
3410 row = bookmarks_index + impl->num_bookmarks - 1;
3411 *pos = GTK_TREE_VIEW_DROP_AFTER;
3415 if (cell_y < cell.height / 2)
3416 *pos = GTK_TREE_VIEW_DROP_BEFORE;
3418 *pos = GTK_TREE_VIEW_DROP_AFTER;
3421 *path = gtk_tree_path_new_from_indices (row, -1);
3424 /* GtkWidget::drag-motion handler for the shortcuts list. We basically
3425 * implement the destination side of DnD by hand, due to limitations in
3426 * GtkTreeView's DnD API.
3429 shortcuts_drag_motion_cb (GtkWidget *widget,
3430 GdkDragContext *context,
3434 GtkFileChooserDefault *impl)
3437 GtkTreeViewDropPosition pos;
3438 GdkDragAction action;
3441 if (gtk_drag_get_source_widget (context) == widget)
3443 shortcuts_cancel_drag_outside_idle (impl);
3445 if (impl->shortcuts_drag_outside)
3447 shortcuts_drag_set_delete_cursor (impl, FALSE);
3448 impl->shortcuts_drag_outside = FALSE;
3453 if (context->suggested_action == GDK_ACTION_COPY ||
3454 (context->actions & GDK_ACTION_COPY) != 0)
3455 action = GDK_ACTION_COPY;
3456 else if (context->suggested_action == GDK_ACTION_MOVE ||
3457 (context->actions & GDK_ACTION_MOVE) != 0)
3458 action = GDK_ACTION_MOVE;
3465 shortcuts_compute_drop_position (impl, x, y, &path, &pos);
3466 gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), path, pos);
3467 gtk_tree_path_free (path);
3471 g_signal_stop_emission_by_name (widget, "drag_motion");
3475 gdk_drag_status (context, action, time_);
3482 /* GtkWidget::drag-drop handler for the shortcuts list. */
3484 shortcuts_drag_drop_cb (GtkWidget *widget,
3485 GdkDragContext *context,
3489 GtkFileChooserDefault *impl)
3492 shortcuts_cancel_drag_outside_idle (impl);
3495 g_signal_stop_emission_by_name (widget, "drag_drop");
3499 /* Parses a "text/uri-list" string and inserts its URIs as bookmarks */
3501 shortcuts_drop_uris (GtkFileChooserDefault *impl,
3508 uris = g_uri_list_extract_uris (data);
3510 for (i = 0; uris[i]; i++)
3516 path = gtk_file_system_uri_to_path (impl->file_system, uri);
3520 if (shortcuts_add_bookmark_from_path (impl, path, position))
3523 gtk_file_path_free (path);
3527 GError *error = NULL;
3529 g_set_error (&error,
3530 GTK_FILE_CHOOSER_ERROR,
3531 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
3532 _("Could not add a bookmark for '%s' "
3533 "because it is an invalid path name."),
3535 error_adding_bookmark_dialog (impl, path, error);
3542 /* Reorders the selected bookmark to the specified position */
3544 shortcuts_reorder (GtkFileChooserDefault *impl,
3549 ShortcutType shortcut_type;
3552 int bookmarks_index;
3553 const GtkFilePath *file_path;
3554 GtkFilePath *file_path_copy;
3558 /* Get the selected path */
3560 if (!shortcuts_get_selected (impl, &iter))
3561 g_assert_not_reached ();
3563 path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
3564 old_position = *gtk_tree_path_get_indices (path);
3565 gtk_tree_path_free (path);
3567 bookmarks_index = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS);
3568 old_position -= bookmarks_index;
3569 g_assert (old_position >= 0 && old_position < impl->num_bookmarks);
3571 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
3572 SHORTCUTS_COL_NAME, &name,
3573 SHORTCUTS_COL_DATA, &col_data,
3574 SHORTCUTS_COL_TYPE, &shortcut_type,
3576 g_assert (col_data != NULL);
3577 g_assert (shortcut_type == SHORTCUT_TYPE_PATH);
3579 file_path = col_data;
3580 file_path_copy = gtk_file_path_copy (file_path); /* removal below will free file_path, so we need a copy */
3582 /* Remove the path from the old position and insert it in the new one */
3584 if (new_position > old_position)
3587 if (old_position == new_position)
3591 if (gtk_file_system_remove_bookmark (impl->file_system, file_path_copy, &error))
3593 shortcuts_add_bookmark_from_path (impl, file_path_copy, new_position);
3594 gtk_file_system_set_bookmark_label (impl->file_system, file_path_copy, name);
3597 error_adding_bookmark_dialog (impl, file_path_copy, error);
3601 gtk_file_path_free (file_path_copy);
3604 /* Callback used when we get the drag data for the bookmarks list. We add the
3605 * received URIs as bookmarks if they are folders.
3608 shortcuts_drag_data_received_cb (GtkWidget *widget,
3609 GdkDragContext *context,
3612 GtkSelectionData *selection_data,
3617 GtkFileChooserDefault *impl;
3618 GtkTreePath *tree_path;
3619 GtkTreeViewDropPosition tree_pos;
3621 int bookmarks_index;
3623 impl = GTK_FILE_CHOOSER_DEFAULT (data);
3625 /* Compute position */
3627 bookmarks_index = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS);
3629 shortcuts_compute_drop_position (impl, x, y, &tree_path, &tree_pos);
3630 position = *gtk_tree_path_get_indices (tree_path);
3631 gtk_tree_path_free (tree_path);
3633 if (tree_pos == GTK_TREE_VIEW_DROP_AFTER)
3636 g_assert (position >= bookmarks_index);
3637 position -= bookmarks_index;
3639 if (selection_data->target == gdk_atom_intern_static_string ("text/uri-list"))
3640 shortcuts_drop_uris (impl, (const char *) selection_data->data, position);
3641 else if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
3642 shortcuts_reorder (impl, position);
3644 g_signal_stop_emission_by_name (widget, "drag_data_received");
3647 /* Callback used when the selection in the shortcuts tree changes */
3649 shortcuts_selection_changed_cb (GtkTreeSelection *selection,
3650 GtkFileChooserDefault *impl)
3653 GtkTreeIter child_iter;
3655 bookmarks_check_remove_sensitivity (impl);
3656 shortcuts_check_popup_sensitivity (impl);
3658 if (impl->changing_folder)
3661 if (gtk_tree_selection_get_selected(selection, NULL, &iter))
3663 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (impl->shortcuts_pane_filter_model),
3666 shortcuts_activate_iter (impl, &child_iter);
3671 shortcuts_row_separator_func (GtkTreeModel *model,
3675 ShortcutType shortcut_type;
3677 gtk_tree_model_get (model, iter, SHORTCUTS_COL_TYPE, &shortcut_type, -1);
3679 return shortcut_type == SHORTCUT_TYPE_SEPARATOR;
3682 /* Since GtkTreeView has a keybinding attached to '/', we need to catch
3683 * keypresses before the TreeView gets them.
3686 tree_view_keybinding_cb (GtkWidget *tree_view,
3688 GtkFileChooserDefault *impl)
3690 if ((event->keyval == GDK_slash
3691 || event->keyval == GDK_KP_Divide
3693 || event->keyval == GDK_asciitilde
3695 ) && ! (event->state & (~GDK_SHIFT_MASK & gtk_accelerator_get_default_mod_mask ())))
3697 location_popup_handler (impl, event->string);
3704 /* Callback used when the file list's popup menu is detached */
3706 shortcuts_popup_menu_detach_cb (GtkWidget *attach_widget,
3709 GtkFileChooserDefault *impl;
3711 impl = g_object_get_data (G_OBJECT (attach_widget), "GtkFileChooserDefault");
3712 g_assert (GTK_IS_FILE_CHOOSER_DEFAULT (impl));
3714 impl->browse_shortcuts_popup_menu = NULL;
3715 impl->browse_shortcuts_popup_menu_remove_item = NULL;
3716 impl->browse_shortcuts_popup_menu_rename_item = NULL;
3720 remove_shortcut_cb (GtkMenuItem *item,
3721 GtkFileChooserDefault *impl)
3723 remove_selected_bookmarks (impl);
3726 /* Rename the selected bookmark */
3728 rename_selected_bookmark (GtkFileChooserDefault *impl)
3732 GtkTreeViewColumn *column;
3733 GtkCellRenderer *cell;
3736 if (shortcuts_get_selected (impl, &iter))
3738 path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
3739 column = gtk_tree_view_get_column (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), 0);
3740 renderers = gtk_tree_view_column_get_cell_renderers (column);
3741 cell = g_list_nth_data (renderers, 1);
3742 g_list_free (renderers);
3743 g_object_set (cell, "editable", TRUE, NULL);
3744 gtk_tree_view_set_cursor_on_cell (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view),
3745 path, column, cell, TRUE);
3746 gtk_tree_path_free (path);
3751 rename_shortcut_cb (GtkMenuItem *item,
3752 GtkFileChooserDefault *impl)
3754 rename_selected_bookmark (impl);
3757 /* Constructs the popup menu for the file list if needed */
3759 shortcuts_build_popup_menu (GtkFileChooserDefault *impl)
3763 if (impl->browse_shortcuts_popup_menu)
3766 impl->browse_shortcuts_popup_menu = gtk_menu_new ();
3767 gtk_menu_attach_to_widget (GTK_MENU (impl->browse_shortcuts_popup_menu),
3768 impl->browse_shortcuts_tree_view,
3769 shortcuts_popup_menu_detach_cb);
3771 item = gtk_image_menu_item_new_with_label (_("Remove"));
3772 impl->browse_shortcuts_popup_menu_remove_item = item;
3773 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
3774 gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU));
3775 g_signal_connect (item, "activate",
3776 G_CALLBACK (remove_shortcut_cb), impl);
3777 gtk_widget_show (item);
3778 gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_shortcuts_popup_menu), item);
3780 item = gtk_menu_item_new_with_label (_("Rename..."));
3781 impl->browse_shortcuts_popup_menu_rename_item = item;
3782 g_signal_connect (item, "activate",
3783 G_CALLBACK (rename_shortcut_cb), impl);
3784 gtk_widget_show (item);
3785 gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_shortcuts_popup_menu), item);
3787 shortcuts_check_popup_sensitivity (impl);
3791 shortcuts_update_popup_menu (GtkFileChooserDefault *impl)
3793 shortcuts_build_popup_menu (impl);
3797 popup_position_func (GtkMenu *menu,
3801 gpointer user_data);
3804 shortcuts_popup_menu (GtkFileChooserDefault *impl,
3805 GdkEventButton *event)
3807 shortcuts_update_popup_menu (impl);
3809 gtk_menu_popup (GTK_MENU (impl->browse_shortcuts_popup_menu),
3810 NULL, NULL, NULL, NULL,
3811 event->button, event->time);
3814 gtk_menu_popup (GTK_MENU (impl->browse_shortcuts_popup_menu),
3816 popup_position_func, impl->browse_shortcuts_tree_view,
3817 0, GDK_CURRENT_TIME);
3818 gtk_menu_shell_select_first (GTK_MENU_SHELL (impl->browse_shortcuts_popup_menu),
3823 /* Callback used for the GtkWidget::popup-menu signal of the shortcuts list */
3825 shortcuts_popup_menu_cb (GtkWidget *widget,
3826 GtkFileChooserDefault *impl)
3828 shortcuts_popup_menu (impl, NULL);
3832 /* Callback used when a button is pressed on the shortcuts list.
3833 * We trap button 3 to bring up a popup menu.
3836 shortcuts_button_press_event_cb (GtkWidget *widget,
3837 GdkEventButton *event,
3838 GtkFileChooserDefault *impl)
3840 static gboolean in_press = FALSE;
3846 if (event->button != 3)
3850 handled = gtk_widget_event (impl->browse_shortcuts_tree_view, (GdkEvent *) event);
3856 shortcuts_popup_menu (impl, event);
3861 shortcuts_edited (GtkCellRenderer *cell,
3864 GtkFileChooserDefault *impl)
3868 GtkFilePath *shortcut;
3870 g_object_set (cell, "editable", FALSE, NULL);
3872 path = gtk_tree_path_new_from_string (path_string);
3873 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->shortcuts_model), &iter, path))
3874 g_assert_not_reached ();
3876 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
3877 SHORTCUTS_COL_DATA, &shortcut,
3879 gtk_tree_path_free (path);
3881 gtk_file_system_set_bookmark_label (impl->file_system, shortcut, new_text);
3885 shortcuts_editing_canceled (GtkCellRenderer *cell,
3886 GtkFileChooserDefault *impl)
3888 g_object_set (cell, "editable", FALSE, NULL);
3891 /* Creates the widgets for the shortcuts and bookmarks tree */
3893 shortcuts_list_create (GtkFileChooserDefault *impl)
3896 GtkTreeSelection *selection;
3897 GtkTreeViewColumn *column;
3898 GtkCellRenderer *renderer;
3900 /* Scrolled window */
3902 swin = gtk_scrolled_window_new (NULL, NULL);
3903 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin),
3904 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
3905 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swin),
3907 gtk_widget_show (swin);
3911 impl->browse_shortcuts_tree_view = gtk_tree_view_new ();
3912 #ifdef PROFILE_FILE_CHOOSER
3913 g_object_set_data (G_OBJECT (impl->browse_shortcuts_tree_view), "fmq-name", "shortcuts");
3915 g_signal_connect (impl->browse_shortcuts_tree_view, "key_press_event",
3916 G_CALLBACK (tree_view_keybinding_cb), impl);
3917 g_signal_connect (impl->browse_shortcuts_tree_view, "popup_menu",
3918 G_CALLBACK (shortcuts_popup_menu_cb), impl);
3919 g_signal_connect (impl->browse_shortcuts_tree_view, "button_press_event",
3920 G_CALLBACK (shortcuts_button_press_event_cb), impl);
3921 /* Accessible object name for the file chooser's shortcuts pane */
3922 atk_object_set_name (gtk_widget_get_accessible (impl->browse_shortcuts_tree_view), _("Places"));
3924 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), impl->shortcuts_pane_filter_model);
3926 gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view),
3928 shortcuts_source_targets,
3929 num_shortcuts_source_targets,
3932 gtk_drag_dest_set (impl->browse_shortcuts_tree_view,
3933 GTK_DEST_DEFAULT_ALL,
3934 shortcuts_dest_targets,
3935 num_shortcuts_dest_targets,
3936 GDK_ACTION_COPY | GDK_ACTION_MOVE);
3938 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view));
3939 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
3940 gtk_tree_selection_set_select_function (selection,
3941 shortcuts_select_func,
3944 g_signal_connect (selection, "changed",
3945 G_CALLBACK (shortcuts_selection_changed_cb), impl);
3947 g_signal_connect (impl->browse_shortcuts_tree_view, "key_press_event",
3948 G_CALLBACK (shortcuts_key_press_event_cb), impl);
3950 g_signal_connect (impl->browse_shortcuts_tree_view, "drag_begin",
3951 G_CALLBACK (shortcuts_drag_begin_cb), impl);
3952 g_signal_connect (impl->browse_shortcuts_tree_view, "drag_end",
3953 G_CALLBACK (shortcuts_drag_end_cb), impl);
3954 g_signal_connect (impl->browse_shortcuts_tree_view, "drag_data_delete",
3955 G_CALLBACK (shortcuts_drag_data_delete_cb), impl);
3957 g_signal_connect (impl->browse_shortcuts_tree_view, "drag_leave",
3958 G_CALLBACK (shortcuts_drag_leave_cb), impl);
3959 g_signal_connect (impl->browse_shortcuts_tree_view, "drag_motion",
3960 G_CALLBACK (shortcuts_drag_motion_cb), impl);
3961 g_signal_connect (impl->browse_shortcuts_tree_view, "drag_drop",
3962 G_CALLBACK (shortcuts_drag_drop_cb), impl);
3963 g_signal_connect (impl->browse_shortcuts_tree_view, "drag_data_received",
3964 G_CALLBACK (shortcuts_drag_data_received_cb), impl);
3966 gtk_container_add (GTK_CONTAINER (swin), impl->browse_shortcuts_tree_view);
3967 gtk_widget_show (impl->browse_shortcuts_tree_view);
3971 column = gtk_tree_view_column_new ();
3972 /* Column header for the file chooser's shortcuts pane */
3973 gtk_tree_view_column_set_title (column, _("_Places"));
3975 renderer = gtk_cell_renderer_pixbuf_new ();
3976 gtk_tree_view_column_pack_start (column, renderer, FALSE);
3977 gtk_tree_view_column_set_attributes (column, renderer,
3978 "pixbuf", SHORTCUTS_COL_PIXBUF,
3979 "visible", SHORTCUTS_COL_PIXBUF_VISIBLE,
3982 renderer = gtk_cell_renderer_text_new ();
3983 g_signal_connect (renderer, "edited",
3984 G_CALLBACK (shortcuts_edited), impl);
3985 g_signal_connect (renderer, "editing-canceled",
3986 G_CALLBACK (shortcuts_editing_canceled), impl);
3987 gtk_tree_view_column_pack_start (column, renderer, TRUE);
3988 gtk_tree_view_column_set_attributes (column, renderer,
3989 "text", SHORTCUTS_COL_NAME,
3992 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view),
3993 shortcuts_row_separator_func,
3996 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), column);
4001 /* Creates the widgets for the shortcuts/bookmarks pane */
4003 shortcuts_pane_create (GtkFileChooserDefault *impl,
4004 GtkSizeGroup *size_group)
4010 vbox = gtk_vbox_new (FALSE, 6);
4011 gtk_widget_show (vbox);
4013 /* Shortcuts tree */
4015 widget = shortcuts_list_create (impl);
4016 gtk_box_pack_start (GTK_BOX (vbox), widget, TRUE, TRUE, 0);
4018 /* Box for buttons */
4020 hbox = gtk_hbox_new (TRUE, 6);
4021 gtk_size_group_add_widget (size_group, hbox);
4022 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
4023 gtk_widget_show (hbox);
4025 /* Add bookmark button */
4027 impl->browse_shortcuts_add_button = button_new (impl,
4032 G_CALLBACK (add_bookmark_button_clicked_cb));
4033 gtk_box_pack_start (GTK_BOX (hbox), impl->browse_shortcuts_add_button, TRUE, TRUE, 0);
4034 gtk_widget_set_tooltip_text (impl->browse_shortcuts_add_button,
4035 _("Add the selected folder to the Bookmarks"));
4037 /* Remove bookmark button */
4039 impl->browse_shortcuts_remove_button = button_new (impl,
4044 G_CALLBACK (remove_bookmark_button_clicked_cb));
4045 gtk_box_pack_start (GTK_BOX (hbox), impl->browse_shortcuts_remove_button, TRUE, TRUE, 0);
4046 gtk_widget_set_tooltip_text (impl->browse_shortcuts_remove_button,
4047 _("Remove the selected bookmark"));
4052 /* Handles key press events on the file list, so that we can trap Enter to
4053 * activate the default button on our own. Also, checks to see if '/' has been
4054 * pressed. See comment by tree_view_keybinding_cb() for more details.
4057 trap_activate_cb (GtkWidget *widget,
4061 GtkFileChooserDefault *impl;
4064 impl = (GtkFileChooserDefault *) data;
4066 modifiers = gtk_accelerator_get_default_mod_mask ();
4068 if ((event->keyval == GDK_slash
4069 || event->keyval == GDK_KP_Divide
4071 || event->keyval == GDK_asciitilde
4073 ) && ! (event->state & (~GDK_SHIFT_MASK & modifiers)))
4075 location_popup_handler (impl, event->string);
4079 if ((event->keyval == GDK_Return
4080 || event->keyval == GDK_ISO_Enter
4081 || event->keyval == GDK_KP_Enter
4082 || event->keyval == GDK_space
4083 || event->keyval == GDK_KP_Space)
4084 && ((event->state & modifiers) == 0)
4085 && !(impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
4086 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER))
4090 window = get_toplevel (widget);
4092 && widget != window->default_widget
4093 && !(widget == window->focus_widget &&
4094 (!window->default_widget || !GTK_WIDGET_SENSITIVE (window->default_widget))))
4096 gtk_window_activate_default (window);
4104 /* Callback used when the file list's popup menu is detached */
4106 popup_menu_detach_cb (GtkWidget *attach_widget,
4109 GtkFileChooserDefault *impl;
4111 impl = g_object_get_data (G_OBJECT (attach_widget), "GtkFileChooserDefault");
4112 g_assert (GTK_IS_FILE_CHOOSER_DEFAULT (impl));
4114 impl->browse_files_popup_menu = NULL;
4115 impl->browse_files_popup_menu_add_shortcut_item = NULL;
4116 impl->browse_files_popup_menu_hidden_files_item = NULL;
4119 /* Callback used when the "Add to Bookmarks" menu item is activated */
4121 add_to_shortcuts_cb (GtkMenuItem *item,
4122 GtkFileChooserDefault *impl)
4124 bookmarks_add_selected_folder (impl);
4127 /* Callback used when the "Show Hidden Files" menu item is toggled */
4129 show_hidden_toggled_cb (GtkCheckMenuItem *item,
4130 GtkFileChooserDefault *impl)
4133 "show-hidden", gtk_check_menu_item_get_active (item),
4137 /* Shows an error dialog about not being able to select a dragged file */
4139 error_selecting_dragged_file_dialog (GtkFileChooserDefault *impl,
4140 const GtkFilePath *path,
4144 _("Could not select file"),
4149 file_list_drag_data_select_uris (GtkFileChooserDefault *impl,
4154 GtkFileChooser *chooser = GTK_FILE_CHOOSER (impl);
4156 for (i = 1; uris[i]; i++)
4161 path = gtk_file_system_uri_to_path (impl->file_system, uri);
4165 GError *error = NULL;
4167 gtk_file_chooser_default_select_path (chooser, path, &error);
4169 error_selecting_dragged_file_dialog (impl, path, error);
4171 gtk_file_path_free (path);
4176 struct FileListDragData
4178 GtkFileChooserDefault *impl;
4184 file_list_drag_data_received_get_info_cb (GtkFileSystemHandle *handle,
4185 const GtkFileInfo *info,
4186 const GError *error,
4189 gboolean cancelled = handle->cancelled;
4190 struct FileListDragData *data = user_data;
4191 GtkFileChooser *chooser = GTK_FILE_CHOOSER (data->impl);
4193 if (handle != data->impl->file_list_drag_data_received_handle)
4196 data->impl->file_list_drag_data_received_handle = NULL;
4198 if (cancelled || error)
4201 if ((data->impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
4202 data->impl->action == GTK_FILE_CHOOSER_ACTION_SAVE) &&
4203 data->uris[1] == 0 && !error &&
4204 gtk_file_info_get_is_folder (info))
4205 change_folder_and_display_error (data->impl, data->path, FALSE);
4208 GError *error = NULL;
4210 gtk_file_chooser_default_unselect_all (chooser);
4211 gtk_file_chooser_default_select_path (chooser, data->path, &error);
4213 error_selecting_dragged_file_dialog (data->impl, data->path, error);
4215 browse_files_center_selected_row (data->impl);
4218 if (data->impl->select_multiple)
4219 file_list_drag_data_select_uris (data->impl, data->uris);
4222 g_object_unref (data->impl);
4223 g_strfreev (data->uris);
4224 gtk_file_path_free (data->path);
4227 g_object_unref (handle);
4231 file_list_drag_data_received_cb (GtkWidget *widget,
4232 GdkDragContext *context,
4235 GtkSelectionData *selection_data,
4240 GtkFileChooserDefault *impl;
4241 GtkFileChooser *chooser;
4245 GError *error = NULL;
4247 impl = GTK_FILE_CHOOSER_DEFAULT (data);
4248 chooser = GTK_FILE_CHOOSER (data);
4250 /* Parse the text/uri-list string, navigate to the first one */
4251 uris = g_uri_list_extract_uris ((const char *) selection_data->data);
4255 path = gtk_file_system_uri_to_path (impl->file_system, uri);
4259 struct FileListDragData *data;
4261 data = g_new0 (struct FileListDragData, 1);
4262 data->impl = g_object_ref (impl);
4266 if (impl->file_list_drag_data_received_handle)
4267 gtk_file_system_cancel_operation (impl->file_list_drag_data_received_handle);
4269 impl->file_list_drag_data_received_handle =
4270 gtk_file_system_get_info (impl->file_system, path,
4271 GTK_FILE_INFO_IS_FOLDER,
4272 file_list_drag_data_received_get_info_cb,
4278 g_set_error (&error,
4279 GTK_FILE_CHOOSER_ERROR,
4280 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
4281 _("Could not select file '%s' "
4282 "because it is an invalid path name."),
4284 error_selecting_dragged_file_dialog (impl, NULL, error);
4287 if (impl->select_multiple)
4288 file_list_drag_data_select_uris (impl, uris);
4294 g_signal_stop_emission_by_name (widget, "drag_data_received");
4297 /* Don't do anything with the drag_drop signal */
4299 file_list_drag_drop_cb (GtkWidget *widget,
4300 GdkDragContext *context,
4304 GtkFileChooserDefault *impl)
4306 g_signal_stop_emission_by_name (widget, "drag_drop");
4310 /* Disable the normal tree drag motion handler, it makes it look like you're
4311 dropping the dragged item onto a tree item */
4313 file_list_drag_motion_cb (GtkWidget *widget,
4314 GdkDragContext *context,
4318 GtkFileChooserDefault *impl)
4320 g_signal_stop_emission_by_name (widget, "drag_motion");
4324 /* Constructs the popup menu for the file list if needed */
4326 file_list_build_popup_menu (GtkFileChooserDefault *impl)
4330 if (impl->browse_files_popup_menu)
4333 impl->browse_files_popup_menu = gtk_menu_new ();
4334 gtk_menu_attach_to_widget (GTK_MENU (impl->browse_files_popup_menu),
4335 impl->browse_files_tree_view,
4336 popup_menu_detach_cb);
4338 item = gtk_image_menu_item_new_with_mnemonic (_("_Add to Bookmarks"));
4339 impl->browse_files_popup_menu_add_shortcut_item = item;
4340 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
4341 gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
4342 gtk_widget_set_sensitive (item, FALSE);
4343 g_signal_connect (item, "activate",
4344 G_CALLBACK (add_to_shortcuts_cb), impl);
4345 gtk_widget_show (item);
4346 gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
4348 item = gtk_separator_menu_item_new ();
4349 gtk_widget_show (item);
4350 gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
4352 item = gtk_check_menu_item_new_with_mnemonic (_("Show _Hidden Files"));
4353 impl->browse_files_popup_menu_hidden_files_item = item;
4354 g_signal_connect (item, "toggled",
4355 G_CALLBACK (show_hidden_toggled_cb), impl);
4356 gtk_widget_show (item);
4357 gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
4360 /* Updates the popup menu for the file list, creating it if necessary */
4362 file_list_update_popup_menu (GtkFileChooserDefault *impl)
4364 file_list_build_popup_menu (impl);
4366 /* FIXME - handle OPERATION_MODE_SEARCH and OPERATION_MODE_RECENT */
4368 /* The sensitivity of the Add to Bookmarks item is set in
4369 * bookmarks_check_add_sensitivity()
4372 g_signal_handlers_block_by_func (impl->browse_files_popup_menu_hidden_files_item,
4373 G_CALLBACK (show_hidden_toggled_cb), impl);
4374 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (impl->browse_files_popup_menu_hidden_files_item),
4376 g_signal_handlers_unblock_by_func (impl->browse_files_popup_menu_hidden_files_item,
4377 G_CALLBACK (show_hidden_toggled_cb), impl);
4381 popup_position_func (GtkMenu *menu,
4387 GtkWidget *widget = GTK_WIDGET (user_data);
4388 GdkScreen *screen = gtk_widget_get_screen (widget);
4391 GdkRectangle monitor;
4393 g_return_if_fail (GTK_WIDGET_REALIZED (widget));
4395 gdk_window_get_origin (widget->window, x, y);
4397 gtk_widget_size_request (GTK_WIDGET (menu), &req);
4399 *x += (widget->allocation.width - req.width) / 2;
4400 *y += (widget->allocation.height - req.height) / 2;
4402 monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
4403 gtk_menu_set_monitor (menu, monitor_num);
4404 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
4406 *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
4407 *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
4413 file_list_popup_menu (GtkFileChooserDefault *impl,
4414 GdkEventButton *event)
4416 file_list_update_popup_menu (impl);
4418 gtk_menu_popup (GTK_MENU (impl->browse_files_popup_menu),
4419 NULL, NULL, NULL, NULL,
4420 event->button, event->time);
4423 gtk_menu_popup (GTK_MENU (impl->browse_files_popup_menu),
4425 popup_position_func, impl->browse_files_tree_view,
4426 0, GDK_CURRENT_TIME);
4427 gtk_menu_shell_select_first (GTK_MENU_SHELL (impl->browse_files_popup_menu),
4433 /* Callback used for the GtkWidget::popup-menu signal of the file list */
4435 list_popup_menu_cb (GtkWidget *widget,
4436 GtkFileChooserDefault *impl)
4438 file_list_popup_menu (impl, NULL);
4442 /* Callback used when a button is pressed on the file list. We trap button 3 to
4443 * bring up a popup menu.
4446 list_button_press_event_cb (GtkWidget *widget,
4447 GdkEventButton *event,
4448 GtkFileChooserDefault *impl)
4450 static gboolean in_press = FALSE;
4456 if (event->button != 3)
4460 handled = gtk_widget_event (impl->browse_files_tree_view, (GdkEvent *) event);
4463 file_list_popup_menu (impl, event);
4467 /* Sets the sort column IDs for the file list based on the operation mode */
4469 file_list_set_sort_column_ids (GtkFileChooserDefault *impl)
4471 int name_id, mtime_id;
4473 name_id = mtime_id = 0;
4475 switch (impl->operation_mode)
4477 case OPERATION_MODE_BROWSE:
4478 name_id = FILE_LIST_COL_NAME;
4479 mtime_id = FILE_LIST_COL_MTIME;
4481 case OPERATION_MODE_SEARCH:
4482 name_id = SEARCH_MODEL_COL_PATH;
4483 mtime_id = SEARCH_MODEL_COL_STAT;
4485 case OPERATION_MODE_RECENT:
4486 name_id = RECENT_MODEL_COL_PATH;
4487 mtime_id = RECENT_MODEL_COL_INFO;
4491 gtk_tree_view_column_set_sort_column_id (impl->list_name_column, name_id);
4492 gtk_tree_view_column_set_sort_column_id (impl->list_mtime_column, mtime_id);
4496 file_list_query_tooltip_cb (GtkWidget *widget,
4499 gboolean keyboard_tip,
4500 GtkTooltip *tooltip,
4503 GtkFileChooserDefault *impl = user_data;
4504 GtkTreeIter iter, child_iter;
4505 GtkTreePath *path = NULL;
4506 GtkFilePath *file_path = NULL;
4509 if (impl->operation_mode == OPERATION_MODE_BROWSE)
4513 gtk_tree_view_get_tooltip_context (GTK_TREE_VIEW (impl->browse_files_tree_view),
4521 switch (impl->operation_mode)
4523 case OPERATION_MODE_SEARCH:
4524 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->search_model_sort), &iter, path))
4526 gtk_tree_path_free (path);
4530 search_get_valid_child_iter (impl, &child_iter, &iter);
4531 gtk_tree_model_get (GTK_TREE_MODEL (impl->search_model), &child_iter,
4532 SEARCH_MODEL_COL_PATH, &file_path,
4536 case OPERATION_MODE_RECENT:
4537 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->recent_model_sort), &iter, path))
4539 gtk_tree_path_free (path);
4543 recent_get_valid_child_iter (impl, &child_iter, &iter);
4544 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &child_iter,
4545 RECENT_MODEL_COL_PATH, &file_path,
4549 case OPERATION_MODE_BROWSE:
4550 g_assert_not_reached ();
4556 gtk_tree_path_free (path);
4560 filename = gtk_file_system_path_to_filename (impl->file_system, file_path);
4561 gtk_tooltip_set_text (tooltip, filename);
4562 gtk_tree_view_set_tooltip_row (GTK_TREE_VIEW (impl->browse_files_tree_view),
4567 gtk_tree_path_free (path);
4572 /* Creates the widgets for the file list */
4574 create_file_list (GtkFileChooserDefault *impl)
4577 GtkTreeSelection *selection;
4578 GtkTreeViewColumn *column;
4579 GtkCellRenderer *renderer;
4581 /* Scrolled window */
4583 swin = gtk_scrolled_window_new (NULL, NULL);
4584 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin),
4585 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
4586 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swin),
4589 /* Tree/list view */
4591 impl->browse_files_tree_view = gtk_tree_view_new ();
4592 #ifdef PROFILE_FILE_CHOOSER
4593 g_object_set_data (G_OBJECT (impl->browse_files_tree_view), "fmq-name", "file_list");
4595 g_object_set_data (G_OBJECT (impl->browse_files_tree_view), I_("GtkFileChooserDefault"), impl);
4596 atk_object_set_name (gtk_widget_get_accessible (impl->browse_files_tree_view), _("Files"));
4598 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (impl->browse_files_tree_view), TRUE);
4599 gtk_container_add (GTK_CONTAINER (swin), impl->browse_files_tree_view);
4601 gtk_drag_dest_set (impl->browse_files_tree_view,
4602 GTK_DEST_DEFAULT_ALL,
4603 file_list_dest_targets,
4604 num_file_list_dest_targets,
4605 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4607 g_signal_connect (impl->browse_files_tree_view, "row_activated",
4608 G_CALLBACK (list_row_activated), impl);
4609 g_signal_connect (impl->browse_files_tree_view, "key_press_event",
4610 G_CALLBACK (trap_activate_cb), impl);
4611 g_signal_connect (impl->browse_files_tree_view, "popup_menu",
4612 G_CALLBACK (list_popup_menu_cb), impl);
4613 g_signal_connect (impl->browse_files_tree_view, "button_press_event",
4614 G_CALLBACK (list_button_press_event_cb), impl);
4616 g_signal_connect (impl->browse_files_tree_view, "drag_data_received",
4617 G_CALLBACK (file_list_drag_data_received_cb), impl);
4618 g_signal_connect (impl->browse_files_tree_view, "drag_drop",
4619 G_CALLBACK (file_list_drag_drop_cb), impl);
4620 g_signal_connect (impl->browse_files_tree_view, "drag_motion",
4621 G_CALLBACK (file_list_drag_motion_cb), impl);
4623 g_object_set (impl->browse_files_tree_view, "has-tooltip", TRUE, NULL);
4624 g_signal_connect (impl->browse_files_tree_view, "query-tooltip",
4625 G_CALLBACK (file_list_query_tooltip_cb), impl);
4627 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
4628 gtk_tree_selection_set_select_function (selection,
4631 gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (impl->browse_files_tree_view),
4633 file_list_source_targets,
4634 num_file_list_source_targets,
4637 g_signal_connect (selection, "changed",
4638 G_CALLBACK (list_selection_changed), impl);
4640 /* Filename column */
4642 impl->list_name_column = gtk_tree_view_column_new ();
4643 gtk_tree_view_column_set_expand (impl->list_name_column, TRUE);
4644 gtk_tree_view_column_set_resizable (impl->list_name_column, TRUE);
4645 gtk_tree_view_column_set_title (impl->list_name_column, _("Name"));
4646 gtk_tree_view_column_set_sort_column_id (impl->list_name_column, FILE_LIST_COL_NAME);
4648 renderer = gtk_cell_renderer_pixbuf_new ();
4649 gtk_tree_view_column_pack_start (impl->list_name_column, renderer, FALSE);
4650 gtk_tree_view_column_set_cell_data_func (impl->list_name_column, renderer,
4651 list_icon_data_func, impl, NULL);
4653 impl->list_name_renderer = gtk_cell_renderer_text_new ();
4654 g_object_set (impl->list_name_renderer,
4655 "ellipsize", PANGO_ELLIPSIZE_END,
4657 g_signal_connect (impl->list_name_renderer, "edited",
4658 G_CALLBACK (renderer_edited_cb), impl);
4659 g_signal_connect (impl->list_name_renderer, "editing_canceled",
4660 G_CALLBACK (renderer_editing_canceled_cb), impl);
4661 gtk_tree_view_column_pack_start (impl->list_name_column, impl->list_name_renderer, TRUE);
4662 gtk_tree_view_column_set_cell_data_func (impl->list_name_column, impl->list_name_renderer,
4663 list_name_data_func, impl, NULL);
4665 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->browse_files_tree_view), impl->list_name_column);
4669 column = gtk_tree_view_column_new ();
4670 gtk_tree_view_column_set_title (column, _("Size"));
4672 renderer = gtk_cell_renderer_text_new ();
4673 gtk_tree_view_column_pack_start (column, renderer, TRUE); /* bug: it doesn't expand */
4674 gtk_tree_view_column_set_cell_data_func (column, renderer,
4675 list_size_data_func, impl, NULL);
4676 gtk_tree_view_column_set_sort_column_id (column, FILE_LIST_COL_SIZE);
4677 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->browse_files_tree_view), column);
4680 /* Modification time column */
4682 column = gtk_tree_view_column_new ();
4683 gtk_tree_view_column_set_resizable (column, TRUE);
4684 gtk_tree_view_column_set_title (column, _("Modified"));
4686 renderer = gtk_cell_renderer_text_new ();
4687 gtk_tree_view_column_pack_start (column, renderer, TRUE);
4688 gtk_tree_view_column_set_cell_data_func (column, renderer,
4689 list_mtime_data_func, impl, NULL);
4690 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->browse_files_tree_view), column);
4691 impl->list_mtime_column = column;
4693 file_list_set_sort_column_ids (impl);
4695 gtk_widget_show_all (swin);
4701 create_path_bar (GtkFileChooserDefault *impl)
4703 GtkWidget *path_bar;
4705 path_bar = g_object_new (GTK_TYPE_PATH_BAR, NULL);
4706 _gtk_path_bar_set_file_system (GTK_PATH_BAR (path_bar), impl->file_system);
4711 /* Creates the widgets for the files/folders pane */
4713 file_pane_create (GtkFileChooserDefault *impl,
4714 GtkSizeGroup *size_group)
4720 vbox = gtk_vbox_new (FALSE, 6);
4721 gtk_widget_show (vbox);
4723 /* Box for lists and preview */
4725 hbox = gtk_hbox_new (FALSE, PREVIEW_HBOX_SPACING);
4726 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
4727 gtk_widget_show (hbox);
4731 widget = create_file_list (impl);
4732 gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
4736 impl->preview_box = gtk_vbox_new (FALSE, 12);
4737 gtk_box_pack_start (GTK_BOX (hbox), impl->preview_box, FALSE, FALSE, 0);
4738 /* Don't show preview box initially */
4742 impl->filter_combo_hbox = gtk_hbox_new (FALSE, 12);
4744 widget = filter_create (impl);
4746 gtk_widget_show (widget);
4747 gtk_box_pack_end (GTK_BOX (impl->filter_combo_hbox), widget, FALSE, FALSE, 0);
4749 gtk_size_group_add_widget (size_group, impl->filter_combo_hbox);
4750 gtk_box_pack_end (GTK_BOX (vbox), impl->filter_combo_hbox, FALSE, FALSE, 0);
4755 /* Callback used when the "Browse for more folders" expander is toggled */
4757 expander_changed_cb (GtkExpander *expander,
4759 GtkFileChooserDefault *impl)
4761 impl->expand_folders = gtk_expander_get_expanded(GTK_EXPANDER (impl->save_expander));
4762 update_appearance (impl);
4765 /* Callback used when the selection changes in the save folder combo box */
4767 save_folder_combo_changed_cb (GtkComboBox *combo,
4768 GtkFileChooserDefault *impl)
4772 if (impl->changing_folder)
4775 if (gtk_combo_box_get_active_iter (combo, &iter))
4777 GtkTreeIter child_iter;
4779 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (impl->shortcuts_combo_filter_model),
4782 shortcuts_activate_iter (impl, &child_iter);
4786 /* Filter function used to filter out the Search item and its separator.
4787 * Used for the "Save in folder" combo box, so that these items do not appear in it.
4790 shortcuts_combo_filter_func (GtkTreeModel *model,
4794 GtkFileChooserDefault *impl;
4795 GtkTreePath *tree_path;
4800 impl = GTK_FILE_CHOOSER_DEFAULT (data);
4802 g_assert (model == GTK_TREE_MODEL (impl->shortcuts_model));
4804 tree_path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), iter);
4805 g_assert (tree_path != NULL);
4807 indices = gtk_tree_path_get_indices (tree_path);
4811 if (impl->has_search)
4813 idx = shortcuts_get_index (impl, SHORTCUTS_SEARCH);
4814 if (idx == indices[0])
4818 if (impl->has_recent)
4820 idx = shortcuts_get_index (impl, SHORTCUTS_RECENT);
4821 if (idx == indices[0])
4825 idx = shortcuts_get_index (impl, SHORTCUTS_RECENT_SEPARATOR);
4826 if (idx == indices[0])
4831 gtk_tree_path_free (tree_path);
4836 /* Creates the combo box with the save folders */
4838 save_folder_combo_create (GtkFileChooserDefault *impl)
4841 GtkCellRenderer *cell;
4843 impl->shortcuts_combo_filter_model = gtk_tree_model_filter_new (GTK_TREE_MODEL (impl->shortcuts_model), NULL);
4844 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (impl->shortcuts_combo_filter_model),
4845 shortcuts_combo_filter_func,
4849 combo = g_object_new (GTK_TYPE_COMBO_BOX,
4850 "model", impl->shortcuts_combo_filter_model,
4851 "focus-on-click", FALSE,
4853 gtk_widget_show (combo);
4855 cell = gtk_cell_renderer_pixbuf_new ();
4856 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, FALSE);
4857 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), cell,
4858 "pixbuf", SHORTCUTS_COL_PIXBUF,
4859 "visible", SHORTCUTS_COL_PIXBUF_VISIBLE,
4860 "sensitive", SHORTCUTS_COL_PIXBUF_VISIBLE,
4863 cell = gtk_cell_renderer_text_new ();
4864 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE);
4865 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), cell,
4866 "text", SHORTCUTS_COL_NAME,
4867 "sensitive", SHORTCUTS_COL_PIXBUF_VISIBLE,
4870 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo),
4871 shortcuts_row_separator_func,
4874 g_signal_connect (combo, "changed",
4875 G_CALLBACK (save_folder_combo_changed_cb), impl);
4880 /* Creates the widgets specific to Save mode */
4882 save_widgets_create (GtkFileChooserDefault *impl)
4887 GtkWidget *alignment;
4889 if (impl->save_widgets != NULL)
4892 location_switch_to_path_bar (impl);
4894 vbox = gtk_vbox_new (FALSE, 12);
4896 table = gtk_table_new (2, 2, FALSE);
4897 gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
4898 gtk_widget_show (table);
4899 gtk_table_set_row_spacings (GTK_TABLE (table), 12);
4900 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
4904 widget = gtk_label_new_with_mnemonic (_("_Name:"));
4905 gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
4906 gtk_table_attach (GTK_TABLE (table), widget,
4910 gtk_widget_show (widget);
4912 /* Location entry */
4914 impl->location_entry = _gtk_file_chooser_entry_new (TRUE);
4915 _gtk_file_chooser_entry_set_file_system (GTK_FILE_CHOOSER_ENTRY (impl->location_entry),
4917 gtk_entry_set_width_chars (GTK_ENTRY (impl->location_entry), 45);
4918 gtk_entry_set_activates_default (GTK_ENTRY (impl->location_entry), TRUE);
4919 gtk_table_attach (GTK_TABLE (table), impl->location_entry,
4921 GTK_EXPAND | GTK_FILL, 0,
4923 gtk_widget_show (impl->location_entry);
4924 gtk_label_set_mnemonic_widget (GTK_LABEL (widget), impl->location_entry);
4927 impl->save_folder_label = gtk_label_new (NULL);
4928 gtk_misc_set_alignment (GTK_MISC (impl->save_folder_label), 0.0, 0.5);
4929 gtk_table_attach (GTK_TABLE (table), impl->save_folder_label,
4933 gtk_widget_show (impl->save_folder_label);
4935 impl->save_folder_combo = save_folder_combo_create (impl);
4936 gtk_table_attach (GTK_TABLE (table), impl->save_folder_combo,
4938 GTK_EXPAND | GTK_FILL, GTK_FILL,
4940 gtk_label_set_mnemonic_widget (GTK_LABEL (impl->save_folder_label), impl->save_folder_combo);
4943 alignment = gtk_alignment_new (0.0, 0.5, 1.0, 1.0);
4944 gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0);
4946 impl->save_expander = gtk_expander_new_with_mnemonic (_("_Browse for other folders"));
4947 gtk_container_add (GTK_CONTAINER (alignment), impl->save_expander);
4948 g_signal_connect (impl->save_expander, "notify::expanded",
4949 G_CALLBACK (expander_changed_cb),
4951 gtk_widget_show_all (alignment);
4953 impl->save_widgets = vbox;
4954 gtk_box_pack_start (GTK_BOX (impl), impl->save_widgets, FALSE, FALSE, 0);
4955 gtk_box_reorder_child (GTK_BOX (impl), impl->save_widgets, 0);
4956 gtk_widget_show (impl->save_widgets);
4959 /* Destroys the widgets specific to Save mode */
4961 save_widgets_destroy (GtkFileChooserDefault *impl)
4963 if (impl->save_widgets == NULL)
4966 gtk_widget_destroy (impl->save_widgets);
4967 impl->save_widgets = NULL;
4968 impl->location_entry = NULL;
4969 impl->save_folder_label = NULL;
4970 impl->save_folder_combo = NULL;
4971 impl->save_expander = NULL;
4974 /* Turns on the path bar widget. Can be called even if we are already in that
4978 location_switch_to_path_bar (GtkFileChooserDefault *impl)
4980 if (impl->location_entry)
4982 gtk_widget_destroy (impl->location_entry);
4983 impl->location_entry = NULL;
4986 gtk_widget_hide (impl->location_entry_box);
4989 /* Sets the full path of the current folder as the text in the location entry. */
4991 location_entry_set_initial_text (GtkFileChooserDefault *impl)
4995 if (!impl->current_folder)
4998 if (gtk_file_system_path_is_local (impl->file_system, impl->current_folder))
5002 filename = gtk_file_system_path_to_filename (impl->file_system, impl->current_folder);
5005 text = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
5012 text = gtk_file_system_path_to_uri (impl->file_system, impl->current_folder);
5016 gboolean need_slash;
5019 len = strlen (text);
5020 need_slash = (text[len - 1] != G_DIR_SEPARATOR);
5026 slash_text = g_new (char, len + 2);
5027 strcpy (slash_text, text);
5028 slash_text[len] = G_DIR_SEPARATOR;
5029 slash_text[len + 1] = 0;
5035 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), text);
5040 /* Turns on the location entry. Can be called even if we are already in that
5044 location_switch_to_filename_entry (GtkFileChooserDefault *impl)
5046 /* when in search or recent files mode, we are not showing the
5047 * location_entry_box container, so there's no point in switching
5050 if (impl->operation_mode == OPERATION_MODE_SEARCH ||
5051 impl->operation_mode == OPERATION_MODE_RECENT)
5054 if (impl->location_entry)
5055 gtk_widget_destroy (impl->location_entry);
5059 gtk_widget_show (impl->location_entry_box);
5063 impl->location_entry = _gtk_file_chooser_entry_new (TRUE);
5064 _gtk_file_chooser_entry_set_file_system (GTK_FILE_CHOOSER_ENTRY (impl->location_entry),
5066 gtk_entry_set_activates_default (GTK_ENTRY (impl->location_entry), TRUE);
5067 _gtk_file_chooser_entry_set_action (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->action);
5069 gtk_box_pack_start (GTK_BOX (impl->location_entry_box), impl->location_entry, TRUE, TRUE, 0);
5070 gtk_label_set_mnemonic_widget (GTK_LABEL (impl->location_label), impl->location_entry);
5072 /* Configure the entry */
5074 _gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->current_folder);
5078 gtk_widget_show (impl->location_entry);
5079 gtk_widget_grab_focus (impl->location_entry);
5082 /* Sets a new location mode. set_buttons determines whether the toggle button
5083 * for the mode will also be changed.
5086 location_mode_set (GtkFileChooserDefault *impl,
5087 LocationMode new_mode,
5088 gboolean set_button)
5090 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
5091 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
5093 GtkWindow *toplevel;
5094 GtkWidget *current_focus;
5095 gboolean button_active;
5096 gboolean switch_to_file_list;
5100 case LOCATION_MODE_PATH_BAR:
5101 button_active = FALSE;
5103 /* The location_entry will disappear when we switch to path bar mode. So,
5104 * we'll focus the file list in that case, to avoid having a window with
5105 * no focused widget.
5107 toplevel = get_toplevel (GTK_WIDGET (impl));
5108 switch_to_file_list = FALSE;
5111 current_focus = gtk_window_get_focus (toplevel);
5112 if (!current_focus || current_focus == impl->location_entry)
5113 switch_to_file_list = TRUE;
5116 location_switch_to_path_bar (impl);
5118 if (switch_to_file_list)
5119 gtk_widget_grab_focus (impl->browse_files_tree_view);
5123 case LOCATION_MODE_FILENAME_ENTRY:
5124 button_active = TRUE;
5125 location_switch_to_filename_entry (impl);
5129 g_assert_not_reached ();
5135 g_signal_handlers_block_by_func (impl->location_button,
5136 G_CALLBACK (location_button_toggled_cb), impl);
5138 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->location_button), button_active);
5140 g_signal_handlers_unblock_by_func (impl->location_button,
5141 G_CALLBACK (location_button_toggled_cb), impl);
5145 impl->location_mode = new_mode;
5149 location_toggle_popup_handler (GtkFileChooserDefault *impl)
5151 /* If the file entry is not visible, show it.
5152 * If it is visible, turn it off only if it is focused. Otherwise, switch to the entry.
5154 if (impl->location_mode == LOCATION_MODE_PATH_BAR)
5156 location_mode_set (impl, LOCATION_MODE_FILENAME_ENTRY, TRUE);
5158 else if (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)
5160 if (GTK_WIDGET_HAS_FOCUS (impl->location_entry))
5162 location_mode_set (impl, LOCATION_MODE_PATH_BAR, TRUE);
5166 gtk_widget_grab_focus (impl->location_entry);
5171 /* Callback used when one of the location mode buttons is toggled */
5173 location_button_toggled_cb (GtkToggleButton *toggle,
5174 GtkFileChooserDefault *impl)
5177 LocationMode new_mode;
5179 is_active = gtk_toggle_button_get_active (toggle);
5183 g_assert (impl->location_mode == LOCATION_MODE_PATH_BAR);
5184 new_mode = LOCATION_MODE_FILENAME_ENTRY;
5188 g_assert (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY);
5189 new_mode = LOCATION_MODE_PATH_BAR;
5192 location_mode_set (impl, new_mode, FALSE);
5195 /* Creates a toggle button for the location entry. */
5197 location_button_create (GtkFileChooserDefault *impl)
5202 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_BUTTON);
5203 gtk_widget_show (image);
5205 impl->location_button = g_object_new (GTK_TYPE_TOGGLE_BUTTON,
5209 g_signal_connect (impl->location_button, "toggled",
5210 G_CALLBACK (location_button_toggled_cb), impl);
5212 str = _("Type a file name");
5214 gtk_widget_set_tooltip_text (impl->location_button, str);
5215 atk_object_set_name (gtk_widget_get_accessible (impl->location_button), str);
5218 /* Creates the main hpaned with the widgets shared by Open and Save mode */
5220 browse_widgets_create (GtkFileChooserDefault *impl)
5226 GtkSizeGroup *size_group;
5228 /* size group is used by the [+][-] buttons and the filter combo */
5229 size_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
5230 vbox = gtk_vbox_new (FALSE, 12);
5232 /* Location widgets */
5233 hbox = gtk_hbox_new (FALSE, 12);
5234 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
5235 gtk_widget_show (hbox);
5236 impl->browse_path_bar_hbox = hbox;
5238 location_button_create (impl);
5239 gtk_box_pack_start (GTK_BOX (hbox), impl->location_button, FALSE, FALSE, 0);
5243 impl->browse_path_bar = create_path_bar (impl);
5244 g_signal_connect (impl->browse_path_bar, "path-clicked", G_CALLBACK (path_bar_clicked), impl);
5245 gtk_widget_show_all (impl->browse_path_bar);
5246 gtk_box_pack_start (GTK_BOX (hbox), impl->browse_path_bar, TRUE, TRUE, 0);
5249 impl->browse_new_folder_button = gtk_button_new_with_mnemonic (_("Create Fo_lder"));
5250 g_signal_connect (impl->browse_new_folder_button, "clicked",
5251 G_CALLBACK (new_folder_button_clicked), impl);
5252 gtk_box_pack_end (GTK_BOX (hbox), impl->browse_new_folder_button, FALSE, FALSE, 0);
5254 /* Box for the location label and entry */
5256 impl->location_entry_box = gtk_hbox_new (FALSE, 12);
5257 gtk_box_pack_start (GTK_BOX (vbox), impl->location_entry_box, FALSE, FALSE, 0);
5259 impl->location_label = gtk_label_new_with_mnemonic (_("_Location:"));
5260 gtk_widget_show (impl->location_label);
5261 gtk_box_pack_start (GTK_BOX (impl->location_entry_box), impl->location_label, FALSE, FALSE, 0);
5264 hpaned = gtk_hpaned_new ();
5265 gtk_widget_show (hpaned);
5266 gtk_box_pack_start (GTK_BOX (vbox), hpaned, TRUE, TRUE, 0);
5268 widget = shortcuts_pane_create (impl, size_group);
5269 gtk_paned_pack1 (GTK_PANED (hpaned), widget, FALSE, FALSE);
5270 widget = file_pane_create (impl, size_group);
5271 gtk_paned_pack2 (GTK_PANED (hpaned), widget, TRUE, FALSE);
5273 g_object_unref (size_group);
5279 gtk_file_chooser_default_constructor (GType type,
5280 guint n_construct_properties,
5281 GObjectConstructParam *construct_params)
5283 GtkFileChooserDefault *impl;
5286 profile_start ("start", NULL);
5288 object = G_OBJECT_CLASS (_gtk_file_chooser_default_parent_class)->constructor (type,
5289 n_construct_properties,
5291 impl = GTK_FILE_CHOOSER_DEFAULT (object);
5293 g_assert (impl->file_system);
5295 gtk_widget_push_composite_child ();
5297 /* Recent files manager */
5298 recent_manager_update (impl);
5300 /* Shortcuts model */
5301 shortcuts_model_create (impl);
5303 /* The browse widgets */
5304 impl->browse_widgets = browse_widgets_create (impl);
5305 gtk_box_pack_start (GTK_BOX (impl), impl->browse_widgets, TRUE, TRUE, 0);
5307 /* Alignment to hold extra widget */
5308 impl->extra_align = gtk_alignment_new (0.0, 0.5, 1.0, 1.0);
5309 gtk_box_pack_start (GTK_BOX (impl), impl->extra_align, FALSE, FALSE, 0);
5311 gtk_widget_pop_composite_child ();
5312 update_appearance (impl);
5314 profile_end ("end", NULL);
5319 /* Sets the extra_widget by packing it in the appropriate place */
5321 set_extra_widget (GtkFileChooserDefault *impl,
5322 GtkWidget *extra_widget)
5326 g_object_ref (extra_widget);
5327 /* FIXME: is this right ? */
5328 gtk_widget_show (extra_widget);
5331 if (impl->extra_widget)
5333 gtk_container_remove (GTK_CONTAINER (impl->extra_align), impl->extra_widget);
5334 g_object_unref (impl->extra_widget);
5337 impl->extra_widget = extra_widget;
5338 if (impl->extra_widget)
5340 gtk_container_add (GTK_CONTAINER (impl->extra_align), impl->extra_widget);
5341 gtk_widget_show (impl->extra_align);
5344 gtk_widget_hide (impl->extra_align);
5348 set_local_only (GtkFileChooserDefault *impl,
5349 gboolean local_only)
5351 if (local_only != impl->local_only)
5353 impl->local_only = local_only;
5355 if (impl->shortcuts_model && impl->file_system)
5357 shortcuts_add_volumes (impl);
5358 shortcuts_add_bookmarks (impl);
5362 !gtk_file_system_path_is_local (impl->file_system, impl->current_folder))
5364 /* If we are pointing to a non-local folder, make an effort to change
5365 * back to a local folder, but it's really up to the app to not cause
5366 * such a situation, so we ignore errors.
5368 const gchar *home = g_get_home_dir ();
5369 GtkFilePath *home_path;
5374 home_path = gtk_file_system_filename_to_path (impl->file_system, home);
5376 _gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (impl), home_path, NULL);
5378 gtk_file_path_free (home_path);
5384 volumes_changed_cb (GtkFileSystem *file_system,
5385 GtkFileChooserDefault *impl)
5387 shortcuts_add_volumes (impl);
5390 /* Callback used when the set of bookmarks changes in the file system */
5392 bookmarks_changed_cb (GtkFileSystem *file_system,
5393 GtkFileChooserDefault *impl)
5395 shortcuts_add_bookmarks (impl);
5397 bookmarks_check_add_sensitivity (impl);
5398 bookmarks_check_remove_sensitivity (impl);
5399 shortcuts_check_popup_sensitivity (impl);
5402 /* Sets the file chooser to multiple selection mode */
5404 set_select_multiple (GtkFileChooserDefault *impl,
5405 gboolean select_multiple,
5406 gboolean property_notify)
5408 GtkTreeSelection *selection;
5409 GtkSelectionMode mode;
5411 if (select_multiple == impl->select_multiple)
5414 mode = select_multiple ? GTK_SELECTION_MULTIPLE : GTK_SELECTION_BROWSE;
5416 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
5417 gtk_tree_selection_set_mode (selection, mode);
5419 impl->select_multiple = select_multiple;
5420 g_object_notify (G_OBJECT (impl), "select-multiple");
5422 check_preview_change (impl);
5426 set_file_system_backend (GtkFileChooserDefault *impl,
5427 const char *backend)
5429 profile_start ("start for backend", backend ? backend : "default");
5431 if (impl->file_system)
5433 g_signal_handler_disconnect (impl->file_system, impl->volumes_changed_id);
5434 impl->volumes_changed_id = 0;
5435 g_signal_handler_disconnect (impl->file_system, impl->bookmarks_changed_id);
5436 impl->bookmarks_changed_id = 0;
5437 g_object_unref (impl->file_system);
5440 impl->file_system = NULL;
5442 impl->file_system = gtk_file_system_create (backend);
5445 GtkSettings *settings = gtk_settings_get_default ();
5446 gchar *default_backend = NULL;
5448 g_object_get (settings, "gtk-file-chooser-backend", &default_backend, NULL);
5449 if (default_backend)
5451 impl->file_system = gtk_file_system_create (default_backend);
5452 g_free (default_backend);
5456 if (!impl->file_system)
5458 #if defined (G_OS_UNIX)
5459 impl->file_system = gtk_file_system_unix_new ();
5460 #elif defined (G_OS_WIN32)
5461 impl->file_system = gtk_file_system_win32_new ();
5463 #error "No default filesystem implementation on the platform"
5467 if (impl->file_system)
5469 impl->volumes_changed_id = g_signal_connect (impl->file_system, "volumes-changed",
5470 G_CALLBACK (volumes_changed_cb),
5472 impl->bookmarks_changed_id = g_signal_connect (impl->file_system, "bookmarks-changed",
5473 G_CALLBACK (bookmarks_changed_cb),
5477 profile_end ("end", NULL);
5480 /* This function is basically a do_all function.
5482 * It sets the visibility on all the widgets based on the current state, and
5483 * moves the custom_widget if needed.
5486 update_appearance (GtkFileChooserDefault *impl)
5488 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
5489 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
5493 gtk_widget_hide (impl->location_button);
5494 save_widgets_create (impl);
5496 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
5497 text = _("Save in _folder:");
5499 text = _("Create in _folder:");
5501 gtk_label_set_text_with_mnemonic (GTK_LABEL (impl->save_folder_label), text);
5503 if (gtk_expander_get_expanded (GTK_EXPANDER (impl->save_expander)))
5505 gtk_widget_set_sensitive (impl->save_folder_label, FALSE);
5506 gtk_widget_set_sensitive (impl->save_folder_combo, FALSE);
5507 gtk_widget_show (impl->browse_widgets);
5511 gtk_widget_set_sensitive (impl->save_folder_label, TRUE);
5512 gtk_widget_set_sensitive (impl->save_folder_combo, TRUE);
5513 gtk_widget_hide (impl->browse_widgets);
5516 gtk_widget_show (impl->browse_new_folder_button);
5518 if (impl->select_multiple)
5520 g_warning ("Save mode cannot be set in conjunction with multiple selection mode. "
5521 "Re-setting to single selection mode.");
5522 set_select_multiple (impl, FALSE, TRUE);
5525 else if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
5526 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
5528 gtk_widget_show (impl->location_button);
5529 save_widgets_destroy (impl);
5530 gtk_widget_show (impl->browse_widgets);
5531 location_mode_set (impl, impl->location_mode, TRUE);
5534 if (impl->location_entry)
5535 _gtk_file_chooser_entry_set_action (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->action);
5537 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
5538 gtk_widget_hide (impl->browse_new_folder_button);
5540 gtk_widget_show (impl->browse_new_folder_button);
5542 /* This *is* needed; we need to redraw the file list because the "sensitivity"
5543 * of files may change depending whether we are in a file or folder-only mode.
5545 gtk_widget_queue_draw (impl->browse_files_tree_view);
5547 g_signal_emit_by_name (impl, "default-size-changed");
5551 gtk_file_chooser_default_set_property (GObject *object,
5553 const GValue *value,
5557 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (object);
5561 case GTK_FILE_CHOOSER_PROP_ACTION:
5563 GtkFileChooserAction action = g_value_get_enum (value);
5565 if (action != impl->action)
5567 gtk_file_chooser_default_unselect_all (GTK_FILE_CHOOSER (impl));
5569 if ((action == GTK_FILE_CHOOSER_ACTION_SAVE ||
5570 action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
5571 && impl->select_multiple)
5573 g_warning ("Tried to change the file chooser action to SAVE or CREATE_FOLDER, but "
5574 "this is not allowed in multiple selection mode. Resetting the file chooser "
5575 "to single selection mode.");
5576 set_select_multiple (impl, FALSE, TRUE);
5578 impl->action = action;
5579 update_appearance (impl);
5580 settings_load (impl);
5585 case GTK_FILE_CHOOSER_PROP_FILE_SYSTEM_BACKEND:
5586 set_file_system_backend (impl, g_value_get_string (value));
5589 case GTK_FILE_CHOOSER_PROP_FILTER:
5590 set_current_filter (impl, g_value_get_object (value));
5593 case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
5594 set_local_only (impl, g_value_get_boolean (value));
5597 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
5598 set_preview_widget (impl, g_value_get_object (value));
5601 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE:
5602 impl->preview_widget_active = g_value_get_boolean (value);
5603 update_preview_widget_visibility (impl);
5606 case GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL:
5607 impl->use_preview_label = g_value_get_boolean (value);
5608 update_preview_widget_visibility (impl);
5611 case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
5612 set_extra_widget (impl, g_value_get_object (value));
5615 case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
5617 gboolean select_multiple = g_value_get_boolean (value);
5618 if ((impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
5619 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
5622 g_warning ("Tried to set the file chooser to multiple selection mode, but this is "
5623 "not allowed in SAVE or CREATE_FOLDER modes. Ignoring the change and "
5624 "leaving the file chooser in single selection mode.");
5628 set_select_multiple (impl, select_multiple, FALSE);
5632 case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN:
5634 gboolean show_hidden = g_value_get_boolean (value);
5635 if (show_hidden != impl->show_hidden)
5637 impl->show_hidden = show_hidden;
5639 if (impl->browse_files_model)
5640 _gtk_file_system_model_set_show_hidden (impl->browse_files_model, show_hidden);
5645 case GTK_FILE_CHOOSER_PROP_DO_OVERWRITE_CONFIRMATION:
5647 gboolean do_overwrite_confirmation = g_value_get_boolean (value);
5648 impl->do_overwrite_confirmation = do_overwrite_confirmation;
5653 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
5659 gtk_file_chooser_default_get_property (GObject *object,
5664 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (object);
5668 case GTK_FILE_CHOOSER_PROP_ACTION:
5669 g_value_set_enum (value, impl->action);
5672 case GTK_FILE_CHOOSER_PROP_FILTER:
5673 g_value_set_object (value, impl->current_filter);
5676 case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
5677 g_value_set_boolean (value, impl->local_only);
5680 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
5681 g_value_set_object (value, impl->preview_widget);
5684 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE:
5685 g_value_set_boolean (value, impl->preview_widget_active);
5688 case GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL:
5689 g_value_set_boolean (value, impl->use_preview_label);
5692 case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
5693 g_value_set_object (value, impl->extra_widget);
5696 case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
5697 g_value_set_boolean (value, impl->select_multiple);
5700 case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN:
5701 g_value_set_boolean (value, impl->show_hidden);
5704 case GTK_FILE_CHOOSER_PROP_DO_OVERWRITE_CONFIRMATION:
5705 g_value_set_boolean (value, impl->do_overwrite_confirmation);
5709 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
5714 /* Removes the settings signal handler. It's safe to call multiple times */
5716 remove_settings_signal (GtkFileChooserDefault *impl,
5719 if (impl->settings_signal_id)
5721 GtkSettings *settings;
5723 settings = gtk_settings_get_for_screen (screen);
5724 g_signal_handler_disconnect (settings,
5725 impl->settings_signal_id);
5726 impl->settings_signal_id = 0;
5731 gtk_file_chooser_default_dispose (GObject *object)
5734 GtkFileChooserDefault *impl = (GtkFileChooserDefault *) object;
5736 if (impl->extra_widget)
5738 g_object_unref (impl->extra_widget);
5739 impl->extra_widget = NULL;
5742 if (impl->volumes_changed_id > 0)
5744 g_signal_handler_disconnect (impl->file_system, impl->volumes_changed_id);
5745 impl->volumes_changed_id = 0;
5748 if (impl->bookmarks_changed_id > 0)
5750 g_signal_handler_disconnect (impl->file_system, impl->bookmarks_changed_id);
5751 impl->bookmarks_changed_id = 0;
5754 pending_select_paths_free (impl);
5756 /* cancel all pending operations */
5757 if (impl->pending_handles)
5759 for (l = impl->pending_handles; l; l = l->next)
5761 GtkFileSystemHandle *handle =l->data;
5762 gtk_file_system_cancel_operation (handle);
5764 g_slist_free (impl->pending_handles);
5765 impl->pending_handles = NULL;
5768 if (impl->reload_icon_handles)
5770 for (l = impl->reload_icon_handles; l; l = l->next)
5772 GtkFileSystemHandle *handle =l->data;
5773 gtk_file_system_cancel_operation (handle);
5775 g_slist_free (impl->reload_icon_handles);
5776 impl->reload_icon_handles = NULL;
5779 if (impl->loading_shortcuts)
5781 for (l = impl->loading_shortcuts; l; l = l->next)
5783 GtkFileSystemHandle *handle =l->data;
5784 gtk_file_system_cancel_operation (handle);
5786 g_slist_free (impl->loading_shortcuts);
5787 impl->loading_shortcuts = NULL;
5790 if (impl->file_list_drag_data_received_handle)
5792 gtk_file_system_cancel_operation (impl->file_list_drag_data_received_handle);
5793 impl->file_list_drag_data_received_handle = NULL;
5796 if (impl->update_current_folder_handle)
5798 gtk_file_system_cancel_operation (impl->update_current_folder_handle);
5799 impl->update_current_folder_handle = NULL;
5802 if (impl->show_and_select_paths_handle)
5804 gtk_file_system_cancel_operation (impl->show_and_select_paths_handle);
5805 impl->show_and_select_paths_handle = NULL;
5808 if (impl->should_respond_get_info_handle)
5810 gtk_file_system_cancel_operation (impl->should_respond_get_info_handle);
5811 impl->should_respond_get_info_handle = NULL;
5814 if (impl->update_from_entry_handle)
5816 gtk_file_system_cancel_operation (impl->update_from_entry_handle);
5817 impl->update_from_entry_handle = NULL;
5820 if (impl->shortcuts_activate_iter_handle)
5822 gtk_file_system_cancel_operation (impl->shortcuts_activate_iter_handle);
5823 impl->shortcuts_activate_iter_handle = NULL;
5826 search_stop_searching (impl, TRUE);
5827 recent_stop_loading (impl);
5829 remove_settings_signal (impl, gtk_widget_get_screen (GTK_WIDGET (impl)));
5831 G_OBJECT_CLASS (_gtk_file_chooser_default_parent_class)->dispose (object);
5834 /* We override show-all since we have internal widgets that
5835 * shouldn't be shown when you call show_all(), like the filter
5839 gtk_file_chooser_default_show_all (GtkWidget *widget)
5841 GtkFileChooserDefault *impl = (GtkFileChooserDefault *) widget;
5843 gtk_widget_show (widget);
5845 if (impl->extra_widget)
5846 gtk_widget_show_all (impl->extra_widget);
5849 /* Handler for GtkWindow::set-focus; this is where we save the last-focused
5850 * widget on our toplevel. See gtk_file_chooser_default_hierarchy_changed()
5853 toplevel_set_focus_cb (GtkWindow *window,
5855 GtkFileChooserDefault *impl)
5857 impl->toplevel_last_focus_widget = gtk_window_get_focus (window);
5860 /* We monitor the focus widget on our toplevel to be able to know which widget
5861 * was last focused at the time our "should_respond" method gets called.
5864 gtk_file_chooser_default_hierarchy_changed (GtkWidget *widget,
5865 GtkWidget *previous_toplevel)
5867 GtkFileChooserDefault *impl;
5868 GtkWidget *toplevel;
5870 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
5872 if (previous_toplevel)
5874 g_assert (impl->toplevel_set_focus_id != 0);
5875 g_signal_handler_disconnect (previous_toplevel, impl->toplevel_set_focus_id);
5876 impl->toplevel_set_focus_id = 0;
5877 impl->toplevel_last_focus_widget = NULL;
5880 g_assert (impl->toplevel_set_focus_id == 0);
5882 toplevel = gtk_widget_get_toplevel (widget);
5883 if (GTK_IS_WINDOW (toplevel))
5885 impl->toplevel_set_focus_id = g_signal_connect (toplevel, "set_focus",
5886 G_CALLBACK (toplevel_set_focus_cb), impl);
5887 impl->toplevel_last_focus_widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
5891 /* Changes the icons wherever it is needed */
5893 change_icon_theme (GtkFileChooserDefault *impl)
5895 GtkSettings *settings;
5898 profile_start ("start", NULL);
5900 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl)));
5902 if (gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &width, &height))
5903 impl->icon_size = MAX (width, height);
5905 impl->icon_size = FALLBACK_ICON_SIZE;
5907 shortcuts_reload_icons (impl);
5908 gtk_widget_queue_resize (impl->browse_files_tree_view);
5910 profile_end ("end", NULL);
5913 /* Callback used when a GtkSettings value changes */
5915 settings_notify_cb (GObject *object,
5917 GtkFileChooserDefault *impl)
5921 profile_start ("start", NULL);
5923 name = g_param_spec_get_name (pspec);
5925 if (strcmp (name, "gtk-icon-theme-name") == 0 ||
5926 strcmp (name, "gtk-icon-sizes") == 0)
5927 change_icon_theme (impl);
5929 profile_end ("end", NULL);
5932 /* Installs a signal handler for GtkSettings so that we can monitor changes in
5936 check_icon_theme (GtkFileChooserDefault *impl)
5938 GtkSettings *settings;
5940 profile_start ("start", NULL);
5942 if (impl->settings_signal_id)
5944 profile_end ("end", NULL);
5948 if (gtk_widget_has_screen (GTK_WIDGET (impl)))
5950 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl)));
5951 impl->settings_signal_id = g_signal_connect (settings, "notify",
5952 G_CALLBACK (settings_notify_cb), impl);
5954 change_icon_theme (impl);
5957 profile_end ("end", NULL);
5961 recent_manager_update (GtkFileChooserDefault *impl)
5963 GtkRecentManager *manager;
5965 profile_start ("start", NULL);
5967 if (gtk_widget_has_screen (GTK_WIDGET (impl)))
5968 manager = gtk_recent_manager_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl)));
5970 manager = gtk_recent_manager_get_default ();
5972 if (impl->recent_manager != manager)
5973 impl->recent_manager = manager;
5975 profile_end ("end", NULL);
5979 gtk_file_chooser_default_style_set (GtkWidget *widget,
5980 GtkStyle *previous_style)
5982 GtkFileChooserDefault *impl;
5984 profile_start ("start", NULL);
5986 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
5988 profile_msg (" parent class style_set start", NULL);
5989 if (GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->style_set)
5990 GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->style_set (widget, previous_style);
5991 profile_msg (" parent class style_set end", NULL);
5993 if (gtk_widget_has_screen (GTK_WIDGET (impl)))
5994 change_icon_theme (impl);
5996 profile_msg (" emit default-size-changed start", NULL);
5997 g_signal_emit_by_name (widget, "default-size-changed");
5998 profile_msg (" emit default-size-changed end", NULL);
6000 profile_end ("end", NULL);
6004 gtk_file_chooser_default_screen_changed (GtkWidget *widget,
6005 GdkScreen *previous_screen)
6007 GtkFileChooserDefault *impl;
6009 profile_start ("start", NULL);
6011 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
6013 if (GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->screen_changed)
6014 GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->screen_changed (widget, previous_screen);
6016 remove_settings_signal (impl, previous_screen);
6017 check_icon_theme (impl);
6018 recent_manager_update (impl);
6020 g_signal_emit_by_name (widget, "default-size-changed");
6022 profile_end ("end", NULL);
6026 gtk_file_chooser_default_size_allocate (GtkWidget *widget,
6027 GtkAllocation *allocation)
6029 GtkFileChooserDefault *impl;
6031 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
6033 GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->size_allocate (widget, allocation);
6035 if (!gtk_file_chooser_default_get_resizable (GTK_FILE_CHOOSER_EMBED (impl)))
6037 /* The dialog is not resizable, we shouldn't
6038 * trust in the size it has in this stage
6043 impl->default_width = allocation->width;
6044 impl->default_height = allocation->height;
6046 if (impl->preview_widget_active &&
6047 impl->preview_widget &&
6048 GTK_WIDGET_DRAWABLE (impl->preview_widget))
6049 impl->default_width -= impl->preview_widget->allocation.width + PREVIEW_HBOX_SPACING;
6051 if (impl->extra_widget &&
6052 GTK_WIDGET_DRAWABLE (impl->extra_widget))
6053 impl->default_height -= GTK_BOX (widget)->spacing + impl->extra_widget->allocation.height;
6057 get_is_file_filtered (GtkFileChooserDefault *impl,
6058 const GtkFilePath *path,
6059 GtkFileInfo *file_info)
6061 GtkFileFilterInfo filter_info;
6062 GtkFileFilterFlags needed;
6065 if (!impl->current_filter)
6068 filter_info.contains = GTK_FILE_FILTER_DISPLAY_NAME | GTK_FILE_FILTER_MIME_TYPE;
6070 needed = gtk_file_filter_get_needed (impl->current_filter);
6072 filter_info.display_name = gtk_file_info_get_display_name (file_info);
6073 filter_info.mime_type = gtk_file_info_get_mime_type (file_info);
6075 if (needed & GTK_FILE_FILTER_FILENAME)
6077 filter_info.filename = gtk_file_system_path_to_filename (impl->file_system, path);
6078 if (filter_info.filename)
6079 filter_info.contains |= GTK_FILE_FILTER_FILENAME;
6082 filter_info.filename = NULL;
6084 if (needed & GTK_FILE_FILTER_URI)
6086 filter_info.uri = gtk_file_system_path_to_uri (impl->file_system, path);
6087 if (filter_info.uri)
6088 filter_info.contains |= GTK_FILE_FILTER_URI;
6091 filter_info.uri = NULL;
6093 result = gtk_file_filter_filter (impl->current_filter, &filter_info);
6095 if (filter_info.filename)
6096 g_free ((gchar *)filter_info.filename);
6097 if (filter_info.uri)
6098 g_free ((gchar *)filter_info.uri);
6104 settings_load (GtkFileChooserDefault *impl)
6106 GtkFileChooserSettings *settings;
6107 LocationMode location_mode;
6108 gboolean show_hidden;
6109 gboolean expand_folders;
6111 settings = _gtk_file_chooser_settings_new ();
6113 location_mode = _gtk_file_chooser_settings_get_location_mode (settings);
6114 show_hidden = _gtk_file_chooser_settings_get_show_hidden (settings);
6115 expand_folders = _gtk_file_chooser_settings_get_expand_folders (settings);
6117 g_object_unref (settings);
6119 location_mode_set (impl, location_mode, TRUE);
6120 gtk_file_chooser_set_show_hidden (GTK_FILE_CHOOSER (impl), show_hidden);
6121 impl->expand_folders = expand_folders;
6122 if (impl->save_expander)
6123 gtk_expander_set_expanded (GTK_EXPANDER (impl->save_expander), expand_folders);
6127 settings_save (GtkFileChooserDefault *impl)
6129 GtkFileChooserSettings *settings;
6131 settings = _gtk_file_chooser_settings_new ();
6133 _gtk_file_chooser_settings_set_location_mode (settings, impl->location_mode);
6134 _gtk_file_chooser_settings_set_show_hidden (settings, gtk_file_chooser_get_show_hidden (GTK_FILE_CHOOSER (impl)));
6135 _gtk_file_chooser_settings_set_expand_folders (settings, impl->expand_folders);
6138 _gtk_file_chooser_settings_save (settings, NULL);
6140 g_object_unref (settings);
6143 /* GtkWidget::map method */
6145 gtk_file_chooser_default_map (GtkWidget *widget)
6147 GtkFileChooserDefault *impl;
6148 char *current_working_dir;
6150 profile_start ("start", NULL);
6152 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
6154 GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->map (widget);
6156 if (impl->operation_mode == OPERATION_MODE_BROWSE)
6158 switch (impl->reload_state)
6161 /* The user didn't explicitly give us a folder to
6162 * display, so we'll use the cwd
6164 current_working_dir = g_get_current_dir ();
6165 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl),
6166 current_working_dir);
6167 g_free (current_working_dir);
6170 case RELOAD_HAS_FOLDER:
6171 /* Nothing; we are already loading or loaded, so we
6172 * don't need to reload
6176 case RELOAD_WAS_UNMAPPED:
6177 /* Just reload the current folder; else continue
6180 if (impl->current_folder)
6182 pending_select_paths_store_selection (impl);
6183 change_folder_and_display_error (impl, impl->current_folder, FALSE);
6188 g_assert_not_reached ();
6192 bookmarks_changed_cb (impl->file_system, impl);
6194 settings_load (impl);
6196 profile_end ("end", NULL);
6199 /* GtkWidget::unmap method */
6201 gtk_file_chooser_default_unmap (GtkWidget *widget)
6203 GtkFileChooserDefault *impl;
6205 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
6207 settings_save (impl);
6209 GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->unmap (widget);
6211 impl->reload_state = RELOAD_WAS_UNMAPPED;
6215 list_model_filter_func (GtkFileSystemModel *model,
6217 const GtkFileInfo *file_info,
6220 GtkFileChooserDefault *impl = user_data;
6222 if (!impl->current_filter)
6225 if (gtk_file_info_get_is_folder (file_info))
6228 return !get_is_file_filtered (impl, path, (GtkFileInfo *) file_info);
6232 install_list_model_filter (GtkFileChooserDefault *impl)
6234 GtkFileSystemModelFilter filter;
6237 g_assert (impl->browse_files_model != NULL);
6239 if (impl->current_filter)
6241 filter = list_model_filter_func;
6250 _gtk_file_system_model_set_filter (impl->browse_files_model,
6255 #define COMPARE_DIRECTORIES \
6256 GtkFileChooserDefault *impl = user_data; \
6257 const GtkFileInfo *info_a = _gtk_file_system_model_get_info (impl->browse_files_model, a); \
6258 const GtkFileInfo *info_b = _gtk_file_system_model_get_info (impl->browse_files_model, b); \
6259 gboolean dir_a, dir_b; \
6262 dir_a = gtk_file_info_get_is_folder (info_a); \
6264 return impl->list_sort_ascending ? -1 : 1; \
6267 dir_b = gtk_file_info_get_is_folder (info_b); \
6269 return impl->list_sort_ascending ? 1 : -1; \
6271 if (dir_a != dir_b) \
6272 return impl->list_sort_ascending ? (dir_a ? -1 : 1) : (dir_a ? 1 : -1) /* Directories *always* go first */
6274 /* Sort callback for the filename column */
6276 name_sort_func (GtkTreeModel *model,
6281 COMPARE_DIRECTORIES;
6283 return strcmp (gtk_file_info_get_display_key (info_a), gtk_file_info_get_display_key (info_b));
6286 /* Sort callback for the size column */
6288 size_sort_func (GtkTreeModel *model,
6293 COMPARE_DIRECTORIES;
6296 gint64 size_a = gtk_file_info_get_size (info_a);
6297 gint64 size_b = gtk_file_info_get_size (info_b);
6299 return size_a > size_b ? -1 : (size_a == size_b ? 0 : 1);
6303 /* Sort callback for the mtime column */
6305 mtime_sort_func (GtkTreeModel *model,
6310 COMPARE_DIRECTORIES;
6313 GtkFileTime ta = gtk_file_info_get_modification_time (info_a);
6314 GtkFileTime tb = gtk_file_info_get_modification_time (info_b);
6316 return ta > tb ? -1 : (ta == tb ? 0 : 1);
6320 /* Callback used when the sort column changes. We cache the sort order for use
6321 * in name_sort_func().
6324 list_sort_column_changed_cb (GtkTreeSortable *sortable,
6325 GtkFileChooserDefault *impl)
6327 GtkSortType sort_type;
6329 if (gtk_tree_sortable_get_sort_column_id (sortable, NULL, &sort_type))
6330 impl->list_sort_ascending = (sort_type == GTK_SORT_ASCENDING);
6334 set_busy_cursor (GtkFileChooserDefault *impl,
6337 GtkWindow *toplevel;
6338 GdkDisplay *display;
6341 toplevel = get_toplevel (GTK_WIDGET (impl));
6342 if (!toplevel || !GTK_WIDGET_REALIZED (toplevel))
6345 display = gtk_widget_get_display (GTK_WIDGET (toplevel));
6348 cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
6352 gdk_window_set_cursor (GTK_WIDGET (toplevel)->window, cursor);
6353 gdk_display_flush (display);
6356 gdk_cursor_unref (cursor);
6359 /* Creates a sort model to wrap the file system model and sets it on the tree view */
6361 load_set_model (GtkFileChooserDefault *impl)
6363 profile_start ("start", NULL);
6365 g_assert (impl->browse_files_model != NULL);
6366 g_assert (impl->sort_model == NULL);
6368 profile_msg (" gtk_tree_model_sort_new_with_model start", NULL);
6369 impl->sort_model = (GtkTreeModelSort *)gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (impl->browse_files_model));
6370 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_NAME, name_sort_func, impl, NULL);
6371 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_SIZE, size_sort_func, impl, NULL);
6372 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_MTIME, mtime_sort_func, impl, NULL);
6373 gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (impl->sort_model), NULL, NULL, NULL);
6374 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_NAME, GTK_SORT_ASCENDING);
6375 impl->list_sort_ascending = TRUE;
6376 profile_msg (" gtk_tree_model_sort_new_with_model end", NULL);
6378 g_signal_connect (impl->sort_model, "sort_column_changed",
6379 G_CALLBACK (list_sort_column_changed_cb), impl);
6381 profile_msg (" gtk_tree_view_set_model start", NULL);
6382 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view),
6383 GTK_TREE_MODEL (impl->sort_model));
6384 gtk_tree_view_columns_autosize (GTK_TREE_VIEW (impl->browse_files_tree_view));
6385 gtk_tree_view_set_search_column (GTK_TREE_VIEW (impl->browse_files_tree_view),
6386 GTK_FILE_SYSTEM_MODEL_DISPLAY_NAME);
6387 profile_msg (" gtk_tree_view_set_model end", NULL);
6389 profile_end ("end", NULL);
6392 /* Timeout callback used when the loading timer expires */
6394 load_timeout_cb (gpointer data)
6396 GtkFileChooserDefault *impl;
6398 profile_start ("start", NULL);
6400 impl = GTK_FILE_CHOOSER_DEFAULT (data);
6401 g_assert (impl->load_state == LOAD_PRELOAD);
6402 g_assert (impl->load_timeout_id != 0);
6403 g_assert (impl->browse_files_model != NULL);
6405 impl->load_timeout_id = 0;
6406 impl->load_state = LOAD_LOADING;
6408 load_set_model (impl);
6410 profile_end ("end", NULL);
6415 /* Sets up a new load timer for the model and switches to the LOAD_PRELOAD state */
6417 load_setup_timer (GtkFileChooserDefault *impl)
6419 g_assert (impl->load_timeout_id == 0);
6420 g_assert (impl->load_state != LOAD_PRELOAD);
6422 impl->load_timeout_id = gdk_threads_add_timeout (MAX_LOADING_TIME, load_timeout_cb, impl);
6423 impl->load_state = LOAD_PRELOAD;
6426 /* Removes the load timeout and switches to the LOAD_FINISHED state */
6428 load_remove_timer (GtkFileChooserDefault *impl)
6430 if (impl->load_timeout_id != 0)
6432 g_assert (impl->load_state == LOAD_PRELOAD);
6434 g_source_remove (impl->load_timeout_id);
6435 impl->load_timeout_id = 0;
6436 impl->load_state = LOAD_EMPTY;
6439 g_assert (impl->load_state == LOAD_EMPTY ||
6440 impl->load_state == LOAD_LOADING ||
6441 impl->load_state == LOAD_FINISHED);
6444 /* Selects the first row in the file list */
6446 browse_files_select_first_row (GtkFileChooserDefault *impl)
6450 if (!impl->sort_model)
6453 path = gtk_tree_path_new_from_indices (0, -1);
6454 gtk_tree_view_set_cursor (GTK_TREE_VIEW (impl->browse_files_tree_view), path, NULL, FALSE);
6455 gtk_tree_path_free (path);
6458 struct center_selected_row_closure {
6459 GtkFileChooserDefault *impl;
6460 gboolean already_centered;
6463 /* Callback used from gtk_tree_selection_selected_foreach(); centers the
6464 * selected row in the tree view.
6467 center_selected_row_foreach_cb (GtkTreeModel *model,
6472 struct center_selected_row_closure *closure;
6475 if (closure->already_centered)
6478 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (closure->impl->browse_files_tree_view), path, NULL, TRUE, 0.5, 0.0);
6479 closure->already_centered = TRUE;
6482 /* Centers the selected row in the tree view */
6484 browse_files_center_selected_row (GtkFileChooserDefault *impl)
6486 struct center_selected_row_closure closure;
6487 GtkTreeSelection *selection;
6489 closure.impl = impl;
6490 closure.already_centered = FALSE;
6492 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
6493 gtk_tree_selection_selected_foreach (selection, center_selected_row_foreach_cb, &closure);
6496 struct ShowAndSelectPathsData
6498 GtkFileChooserDefault *impl;
6503 show_and_select_paths_finished_loading (GtkFileFolder *folder,
6506 gboolean have_hidden;
6507 gboolean have_filtered;
6509 struct ShowAndSelectPathsData *data = user_data;
6511 have_hidden = FALSE;
6512 have_filtered = FALSE;
6514 for (l = data->paths; l; l = l->next)
6516 const GtkFilePath *path;
6522 info = gtk_file_folder_get_info (folder, path, NULL);
6526 have_hidden = gtk_file_info_get_is_hidden (info);
6529 have_filtered = !gtk_file_info_get_is_folder (info) && get_is_file_filtered (data->impl, path, info);
6531 gtk_file_info_free (info);
6533 if (have_hidden && have_filtered)
6534 break; /* we now have all the information we need */
6538 g_signal_handlers_disconnect_by_func (folder,
6539 show_and_select_paths_finished_loading,
6542 g_object_unref (folder);
6545 g_object_set (data->impl, "show-hidden", TRUE, NULL);
6548 set_current_filter (data->impl, NULL);
6550 for (l = data->paths; l; l = l->next)
6552 const GtkFilePath *path;
6555 _gtk_file_system_model_path_do (data->impl->browse_files_model, path,
6556 select_func, data->impl);
6559 browse_files_center_selected_row (data->impl);
6561 g_object_unref (data->impl);
6562 gtk_file_paths_free (data->paths);
6567 show_and_select_paths_get_folder_cb (GtkFileSystemHandle *handle,
6568 GtkFileFolder *folder,
6569 const GError *error,
6572 gboolean cancelled = handle->cancelled;
6573 struct ShowAndSelectPathsData *data = user_data;
6575 if (data->impl->show_and_select_paths_handle != handle)
6578 data->impl->show_and_select_paths_handle = NULL;
6580 if (cancelled || error)
6583 g_object_unref (handle);
6585 if (gtk_file_folder_is_finished_loading (folder))
6586 show_and_select_paths_finished_loading (folder, user_data);
6588 g_signal_connect (folder, "finished-loading",
6589 G_CALLBACK (show_and_select_paths_finished_loading),
6595 g_object_unref (data->impl);
6596 gtk_file_paths_free (data->paths);
6599 g_object_unref (handle);
6603 show_and_select_paths (GtkFileChooserDefault *impl,
6604 const GtkFilePath *parent_path,
6608 struct ShowAndSelectPathsData *info;
6610 profile_start ("start", NULL);
6614 profile_end ("end", NULL);
6618 info = g_new (struct ShowAndSelectPathsData, 1);
6619 info->impl = g_object_ref (impl);
6620 info->paths = gtk_file_paths_copy (paths);
6622 if (impl->show_and_select_paths_handle)
6623 gtk_file_system_cancel_operation (impl->show_and_select_paths_handle);
6625 impl->show_and_select_paths_handle =
6626 gtk_file_system_get_folder (impl->file_system, parent_path,
6627 GTK_FILE_INFO_IS_FOLDER | GTK_FILE_INFO_IS_HIDDEN,
6628 show_and_select_paths_get_folder_cb, info);
6630 profile_end ("end", NULL);
6634 /* Processes the pending operation when a folder is finished loading */
6636 pending_select_paths_process (GtkFileChooserDefault *impl)
6638 g_assert (impl->load_state == LOAD_FINISHED);
6639 g_assert (impl->browse_files_model != NULL);
6640 g_assert (impl->sort_model != NULL);
6642 if (impl->pending_select_paths)
6645 show_and_select_paths (impl, impl->current_folder, impl->pending_select_paths, NULL);
6646 pending_select_paths_free (impl);
6647 browse_files_center_selected_row (impl);
6651 /* We only select the first row if the chooser is actually mapped ---
6652 * selecting the first row is to help the user when he is interacting with
6653 * the chooser, but sometimes a chooser works not on behalf of the user,
6654 * but rather on behalf of something else like GtkFileChooserButton. In
6655 * that case, the chooser's selection should be what the caller expects,
6656 * as the user can't see that something else got selected. See bug #165264.
6658 if (GTK_WIDGET_MAPPED (impl) && impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
6659 browse_files_select_first_row (impl);
6662 g_assert (impl->pending_select_paths == NULL);
6665 /* Callback used when the file system model finishes loading */
6667 browse_files_model_finished_loading_cb (GtkFileSystemModel *model,
6668 GtkFileChooserDefault *impl)
6670 profile_start ("start", NULL);
6672 if (impl->load_state == LOAD_PRELOAD)
6674 load_remove_timer (impl);
6675 load_set_model (impl);
6677 else if (impl->load_state == LOAD_LOADING)
6683 /* We can't g_assert_not_reached(), as something other than us may have
6684 * initiated a folder reload. See #165556.
6686 profile_end ("end", NULL);
6690 g_assert (impl->load_timeout_id == 0);
6692 impl->load_state = LOAD_FINISHED;
6694 pending_select_paths_process (impl);
6695 set_busy_cursor (impl, FALSE);
6696 #ifdef PROFILE_FILE_CHOOSER
6697 access ("MARK: *** FINISHED LOADING", F_OK);
6700 profile_end ("end", NULL);
6704 stop_loading_and_clear_list_model (GtkFileChooserDefault *impl)
6706 load_remove_timer (impl); /* This changes the state to LOAD_EMPTY */
6708 if (impl->browse_files_model)
6710 g_object_unref (impl->browse_files_model);
6711 impl->browse_files_model = NULL;
6714 if (impl->sort_model)
6716 g_object_unref (impl->sort_model);
6717 impl->sort_model = NULL;
6720 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), NULL);
6723 /* Gets rid of the old list model and creates a new one for the current folder */
6725 set_list_model (GtkFileChooserDefault *impl,
6728 g_assert (impl->current_folder != NULL);
6730 profile_start ("start", NULL);
6732 stop_loading_and_clear_list_model (impl);
6734 set_busy_cursor (impl, TRUE);
6735 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), NULL);
6737 impl->browse_files_model = _gtk_file_system_model_new (impl->file_system,
6738 impl->current_folder, 0,
6741 if (!impl->browse_files_model)
6743 set_busy_cursor (impl, FALSE);
6744 profile_end ("end", NULL);
6748 load_setup_timer (impl); /* This changes the state to LOAD_PRELOAD */
6750 g_signal_connect (impl->browse_files_model, "finished-loading",
6751 G_CALLBACK (browse_files_model_finished_loading_cb), impl);
6753 _gtk_file_system_model_set_show_hidden (impl->browse_files_model, impl->show_hidden);
6755 install_list_model_filter (impl);
6757 profile_end ("end", NULL);
6762 struct update_chooser_entry_selected_foreach_closure {
6764 GtkTreeIter first_selected_iter;
6768 compare_utf8_filenames (const gchar *a,
6771 gchar *a_folded, *b_folded;
6774 a_folded = g_utf8_strdown (a, -1);
6775 b_folded = g_utf8_strdown (b, -1);
6777 retval = strcmp (a_folded, b_folded);
6786 update_chooser_entry_selected_foreach (GtkTreeModel *model,
6791 struct update_chooser_entry_selected_foreach_closure *closure;
6794 closure->num_selected++;
6796 if (closure->num_selected == 1)
6797 closure->first_selected_iter = *iter;
6801 update_chooser_entry (GtkFileChooserDefault *impl)
6803 GtkTreeSelection *selection;
6804 struct update_chooser_entry_selected_foreach_closure closure;
6805 const char *file_part;
6807 /* no need to update the file chooser's entry if there's no entry */
6808 if (impl->operation_mode == OPERATION_MODE_SEARCH ||
6809 impl->operation_mode == OPERATION_MODE_RECENT ||
6810 !impl->location_entry)
6813 if (!(impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
6814 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER
6815 || ((impl->action == GTK_FILE_CHOOSER_ACTION_OPEN
6816 || impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
6817 && impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)))
6820 g_assert (impl->location_entry != NULL);
6822 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
6823 closure.num_selected = 0;
6824 gtk_tree_selection_selected_foreach (selection, update_chooser_entry_selected_foreach, &closure);
6828 if (closure.num_selected == 0)
6830 goto maybe_clear_entry;
6832 else if (closure.num_selected == 1)
6834 GtkTreeIter child_iter;
6836 if (impl->operation_mode == OPERATION_MODE_BROWSE)
6838 const GtkFileInfo *info;
6839 gboolean change_entry;
6841 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
6843 &closure.first_selected_iter);
6845 info = _gtk_file_system_model_get_info (impl->browse_files_model, &child_iter);
6847 /* If the cursor moved to the row of the newly created folder,
6848 * retrieving info will return NULL.
6853 g_free (impl->browse_files_last_selected_name);
6854 impl->browse_files_last_selected_name =
6855 g_strdup (gtk_file_info_get_display_name (info));
6857 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
6858 impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
6859 change_entry = !gtk_file_info_get_is_folder (info); /* We don't want the name to change when clicking on a folder... */
6861 change_entry = TRUE; /* ... unless we are in one of the folder modes */
6865 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->browse_files_last_selected_name);
6867 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
6868 _gtk_file_chooser_entry_select_filename (GTK_FILE_CHOOSER_ENTRY (impl->location_entry));
6876 g_assert (!(impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
6877 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER));
6879 /* Multiple selection, so just clear the entry. */
6881 g_free (impl->browse_files_last_selected_name);
6882 impl->browse_files_last_selected_name = NULL;
6884 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), "");
6890 if (impl->browse_files_last_selected_name)
6892 const char *entry_text;
6894 gboolean clear_entry;
6896 entry_text = gtk_entry_get_text (GTK_ENTRY (impl->location_entry));
6897 len = strlen (entry_text);
6900 /* The file chooser entry may have appended a "/" to its text. So
6901 * take it out, and compare the result to the old selection.
6903 if (entry_text[len - 1] == G_DIR_SEPARATOR)
6907 tmp = g_strndup (entry_text, len - 1);
6908 clear_entry = (compare_utf8_filenames (impl->browse_files_last_selected_name, tmp) == 0);
6912 clear_entry = (compare_utf8_filenames (impl->browse_files_last_selected_name, entry_text) == 0);
6915 clear_entry = FALSE;
6918 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), "");
6923 gtk_file_chooser_default_set_current_folder (GtkFileChooser *chooser,
6924 const GtkFilePath *path,
6927 return gtk_file_chooser_default_update_current_folder (chooser, path, FALSE, FALSE, error);
6931 struct UpdateCurrentFolderData
6933 GtkFileChooserDefault *impl;
6935 gboolean keep_trail;
6936 gboolean clear_entry;
6937 GtkFilePath *original_path;
6938 GError *original_error;
6942 update_current_folder_get_info_cb (GtkFileSystemHandle *handle,
6943 const GtkFileInfo *info,
6944 const GError *error,
6947 gboolean cancelled = handle->cancelled;
6948 struct UpdateCurrentFolderData *data = user_data;
6949 GtkFileChooserDefault *impl = data->impl;
6951 if (handle != impl->update_current_folder_handle)
6954 impl->update_current_folder_handle = NULL;
6955 impl->reload_state = RELOAD_EMPTY;
6957 set_busy_cursor (impl, FALSE);
6964 GtkFilePath *parent_path;
6966 if (!data->original_path)
6968 data->original_path = gtk_file_path_copy (data->path);
6969 data->original_error = g_error_copy (error);
6972 /* get parent path and try to change the folder to that */
6973 if (gtk_file_system_get_parent (impl->file_system, data->path, &parent_path, NULL) &&
6974 parent_path != NULL)
6976 gtk_file_path_free (data->path);
6977 data->path = parent_path;
6979 g_object_unref (handle);
6981 /* restart the update current folder operation */
6982 impl->reload_state = RELOAD_HAS_FOLDER;
6984 impl->update_current_folder_handle =
6985 gtk_file_system_get_info (impl->file_system, data->path,
6986 GTK_FILE_INFO_IS_FOLDER,
6987 update_current_folder_get_info_cb,
6990 set_busy_cursor (impl, TRUE);
6996 /* error and bail out */
6997 error_changing_folder_dialog (impl, data->original_path, data->original_error);
6999 gtk_file_path_free (data->original_path);
7005 if (data->original_path)
7007 error_changing_folder_dialog (impl, data->original_path, data->original_error);
7009 gtk_file_path_free (data->original_path);
7012 if (!gtk_file_info_get_is_folder (info))
7015 if (!_gtk_path_bar_set_path (GTK_PATH_BAR (impl->browse_path_bar), data->path, data->keep_trail, NULL))
7018 if (impl->current_folder != data->path)
7020 if (impl->current_folder)
7021 gtk_file_path_free (impl->current_folder);
7023 impl->current_folder = gtk_file_path_copy (data->path);
7025 impl->reload_state = RELOAD_HAS_FOLDER;
7028 /* Update the widgets that may trigger a folder change themselves. */
7030 if (!impl->changing_folder)
7032 impl->changing_folder = TRUE;
7034 shortcuts_update_current_folder (impl);
7036 impl->changing_folder = FALSE;
7039 /* Set the folder on the save entry */
7041 if (impl->location_entry)
7043 _gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->location_entry),
7044 impl->current_folder);
7046 if (data->clear_entry)
7047 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), "");
7050 /* Create a new list model. This is slightly evil; we store the result value
7051 * but perform more actions rather than returning immediately even if it
7052 * generates an error.
7054 set_list_model (impl, NULL);
7056 /* Refresh controls */
7058 shortcuts_find_current_folder (impl);
7060 g_signal_emit_by_name (impl, "current-folder-changed", 0);
7062 check_preview_change (impl);
7063 bookmarks_check_add_sensitivity (impl);
7065 g_signal_emit_by_name (impl, "selection-changed", 0);
7068 gtk_file_path_free (data->path);
7071 g_object_unref (handle);
7075 gtk_file_chooser_default_update_current_folder (GtkFileChooser *chooser,
7076 const GtkFilePath *path,
7077 gboolean keep_trail,
7078 gboolean clear_entry,
7081 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7082 struct UpdateCurrentFolderData *data;
7084 profile_start ("start", (char *) path);
7086 switch (impl->operation_mode)
7088 case OPERATION_MODE_SEARCH:
7089 search_switch_to_browse_mode (impl);
7091 case OPERATION_MODE_RECENT:
7092 recent_switch_to_browse_mode (impl);
7094 case OPERATION_MODE_BROWSE:
7098 g_assert (path != NULL);
7100 if (impl->local_only &&
7101 !gtk_file_system_path_is_local (impl->file_system, path))
7104 GTK_FILE_CHOOSER_ERROR,
7105 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
7106 _("Cannot change to folder because it is not local"));
7108 profile_end ("end - not local", (char *) path);
7112 if (impl->update_current_folder_handle)
7113 gtk_file_system_cancel_operation (impl->update_current_folder_handle);
7115 /* Test validity of path here. */
7116 data = g_new0 (struct UpdateCurrentFolderData, 1);
7118 data->path = gtk_file_path_copy (path);
7119 data->keep_trail = keep_trail;
7120 data->clear_entry = clear_entry;
7122 impl->reload_state = RELOAD_HAS_FOLDER;
7124 impl->update_current_folder_handle =
7125 gtk_file_system_get_info (impl->file_system, path, GTK_FILE_INFO_IS_FOLDER,
7126 update_current_folder_get_info_cb,
7129 set_busy_cursor (impl, TRUE);
7131 profile_end ("end", NULL);
7135 static GtkFilePath *
7136 gtk_file_chooser_default_get_current_folder (GtkFileChooser *chooser)
7138 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7140 if (impl->operation_mode == OPERATION_MODE_SEARCH ||
7141 impl->operation_mode == OPERATION_MODE_RECENT)
7144 if (impl->reload_state == RELOAD_EMPTY)
7146 char *current_working_dir;
7149 /* We are unmapped, or we had an error while loading the last folder. We'll return
7150 * the $cwd since once we get (re)mapped, we'll load $cwd anyway unless the caller
7151 * explicitly calls set_current_folder() on us.
7153 current_working_dir = g_get_current_dir ();
7154 path = gtk_file_system_filename_to_path (impl->file_system, current_working_dir);
7155 g_free (current_working_dir);
7159 return gtk_file_path_copy (impl->current_folder);
7163 gtk_file_chooser_default_set_current_name (GtkFileChooser *chooser,
7166 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7168 g_return_if_fail (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
7169 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER);
7171 pending_select_paths_free (impl);
7172 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), name);
7176 select_func (GtkFileSystemModel *model,
7181 GtkFileChooserDefault *impl = user_data;
7182 GtkTreeSelection *selection;
7183 GtkTreeIter sorted_iter;
7185 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
7187 gtk_tree_model_sort_convert_child_iter_to_iter (impl->sort_model, &sorted_iter, iter);
7188 gtk_tree_selection_select_iter (selection, &sorted_iter);
7192 gtk_file_chooser_default_select_path (GtkFileChooser *chooser,
7193 const GtkFilePath *path,
7196 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7197 GtkFilePath *parent_path;
7200 if (!gtk_file_system_get_parent (impl->file_system, path, &parent_path, error))
7204 return _gtk_file_chooser_set_current_folder_path (chooser, path, error);
7206 if (impl->operation_mode == OPERATION_MODE_SEARCH ||
7207 impl->operation_mode == OPERATION_MODE_RECENT ||
7208 impl->load_state == LOAD_EMPTY)
7214 g_assert (impl->current_folder != NULL);
7216 same_path = gtk_file_path_compare (parent_path, impl->current_folder) == 0;
7219 if (same_path && impl->load_state == LOAD_FINISHED)
7224 paths.data = (gpointer) path;
7227 result = show_and_select_paths (impl, parent_path, &paths, error);
7228 gtk_file_path_free (parent_path);
7232 pending_select_paths_add (impl, path);
7238 result = _gtk_file_chooser_set_current_folder_path (chooser, parent_path, error);
7239 gtk_file_path_free (parent_path);
7243 gtk_file_path_free (parent_path);
7248 unselect_func (GtkFileSystemModel *model,
7253 GtkFileChooserDefault *impl = user_data;
7254 GtkTreeView *tree_view = GTK_TREE_VIEW (impl->browse_files_tree_view);
7255 GtkTreePath *sorted_path;
7257 sorted_path = gtk_tree_model_sort_convert_child_path_to_path (impl->sort_model,
7259 gtk_tree_selection_unselect_path (gtk_tree_view_get_selection (tree_view),
7261 gtk_tree_path_free (sorted_path);
7265 gtk_file_chooser_default_unselect_path (GtkFileChooser *chooser,
7266 const GtkFilePath *path)
7268 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7270 if (!impl->browse_files_model)
7273 _gtk_file_system_model_path_do (impl->browse_files_model, path,
7274 unselect_func, impl);
7278 maybe_select (GtkTreeModel *model,
7283 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (data);
7284 GtkTreeSelection *selection;
7285 const GtkFileInfo *info;
7288 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
7290 info = get_list_file_info (impl, iter);
7291 is_folder = gtk_file_info_get_is_folder (info);
7293 if ((is_folder && impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) ||
7294 (!is_folder && impl->action == GTK_FILE_CHOOSER_ACTION_OPEN))
7295 gtk_tree_selection_select_iter (selection, iter);
7297 gtk_tree_selection_unselect_iter (selection, iter);
7303 gtk_file_chooser_default_select_all (GtkFileChooser *chooser)
7305 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7307 if (impl->operation_mode == OPERATION_MODE_SEARCH ||
7308 impl->operation_mode == OPERATION_MODE_RECENT)
7310 GtkTreeSelection *selection;
7312 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
7313 gtk_tree_selection_select_all (selection);
7317 if (impl->select_multiple)
7318 gtk_tree_model_foreach (GTK_TREE_MODEL (impl->sort_model),
7319 maybe_select, impl);
7323 gtk_file_chooser_default_unselect_all (GtkFileChooser *chooser)
7325 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7326 GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
7328 gtk_tree_selection_unselect_all (selection);
7329 pending_select_paths_free (impl);
7332 /* Checks whether the filename entry for the Save modes contains a well-formed filename.
7334 * is_well_formed_ret - whether what the user typed passes gkt_file_system_make_path()
7336 * is_empty_ret - whether the file entry is totally empty
7338 * is_file_part_empty_ret - whether the file part is empty (will be if user types "foobar/", and
7339 * the path will be "$cwd/foobar")
7342 check_save_entry (GtkFileChooserDefault *impl,
7343 GtkFilePath **path_ret,
7344 gboolean *is_well_formed_ret,
7345 gboolean *is_empty_ret,
7346 gboolean *is_file_part_empty_ret,
7347 gboolean *is_folder)
7349 GtkFileChooserEntry *chooser_entry;
7350 const GtkFilePath *current_folder;
7351 const char *file_part;
7355 g_assert (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
7356 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER
7357 || ((impl->action == GTK_FILE_CHOOSER_ACTION_OPEN
7358 || impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
7359 && impl->location_mode == LOCATION_MODE_FILENAME_ENTRY));
7361 chooser_entry = GTK_FILE_CHOOSER_ENTRY (impl->location_entry);
7363 if (strlen (gtk_entry_get_text (GTK_ENTRY (chooser_entry))) == 0)
7366 *is_well_formed_ret = TRUE;
7367 *is_empty_ret = TRUE;
7368 *is_file_part_empty_ret = TRUE;
7374 *is_empty_ret = FALSE;
7376 current_folder = _gtk_file_chooser_entry_get_current_folder (chooser_entry);
7377 if (!current_folder)
7380 *is_well_formed_ret = FALSE;
7381 *is_file_part_empty_ret = FALSE;
7387 file_part = _gtk_file_chooser_entry_get_file_part (chooser_entry);
7389 if (!file_part || file_part[0] == '\0')
7391 *path_ret = gtk_file_path_copy (current_folder);
7392 *is_well_formed_ret = TRUE;
7393 *is_file_part_empty_ret = TRUE;
7399 *is_file_part_empty_ret = FALSE;
7402 path = gtk_file_system_make_path (impl->file_system, current_folder, file_part, &error);
7406 error_building_filename_dialog (impl, current_folder, file_part, error);
7408 *is_well_formed_ret = FALSE;
7415 *is_well_formed_ret = TRUE;
7416 *is_folder = _gtk_file_chooser_entry_get_is_folder (chooser_entry, path);
7419 struct get_paths_closure {
7420 GtkFileChooserDefault *impl;
7422 GtkFilePath *path_from_entry;
7426 get_paths_foreach (GtkTreeModel *model,
7431 struct get_paths_closure *info;
7432 const GtkFilePath *file_path;
7433 GtkFileSystemModel *fs_model;
7434 GtkTreeIter sel_iter;
7437 fs_model = info->impl->browse_files_model;
7438 gtk_tree_model_sort_convert_iter_to_child_iter (info->impl->sort_model, &sel_iter, iter);
7440 file_path = _gtk_file_system_model_get_path (fs_model, &sel_iter);
7442 return; /* We are on the editable row */
7444 if (!info->path_from_entry
7445 || gtk_file_path_compare (info->path_from_entry, file_path) != 0)
7446 info->result = g_slist_prepend (info->result, gtk_file_path_copy (file_path));
7450 gtk_file_chooser_default_get_paths (GtkFileChooser *chooser)
7452 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7453 struct get_paths_closure info;
7454 GtkWindow *toplevel;
7455 GtkWidget *current_focus;
7456 gboolean file_list_seen;
7458 if (impl->operation_mode == OPERATION_MODE_SEARCH)
7459 return search_get_selected_paths (impl);
7461 if (impl->operation_mode == OPERATION_MODE_RECENT)
7462 return recent_get_selected_paths (impl);
7466 info.path_from_entry = NULL;
7468 toplevel = get_toplevel (GTK_WIDGET (impl));
7470 current_focus = gtk_window_get_focus (toplevel);
7472 current_focus = NULL;
7474 file_list_seen = FALSE;
7475 if (current_focus == impl->browse_files_tree_view)
7477 GtkTreeSelection *selection;
7481 file_list_seen = TRUE;
7482 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
7483 gtk_tree_selection_selected_foreach (selection, get_paths_foreach, &info);
7485 /* If there is no selection in the file list, we probably have this situation:
7487 * 1. The user typed a filename in the SAVE filename entry ("foo.txt").
7488 * 2. He then double-clicked on a folder ("bar") in the file list
7490 * So we want the selection to be "bar/foo.txt". Jump to the case for the
7491 * filename entry to see if that is the case.
7493 if (info.result == NULL && impl->location_entry)
7496 else if (impl->location_entry && current_focus == impl->location_entry)
7498 gboolean is_well_formed, is_empty, is_file_part_empty, is_folder;
7502 check_save_entry (impl, &info.path_from_entry, &is_well_formed, &is_empty, &is_file_part_empty, &is_folder);
7507 if (!is_well_formed)
7510 if (is_file_part_empty && impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
7512 gtk_file_path_free (info.path_from_entry);
7516 if (info.path_from_entry)
7517 info.result = g_slist_prepend (info.result, info.path_from_entry);
7518 else if (!file_list_seen)
7523 else if (impl->toplevel_last_focus_widget == impl->browse_files_tree_view)
7525 else if (impl->location_entry && impl->toplevel_last_focus_widget == impl->location_entry)
7529 /* The focus is on a dialog's action area button or something else */
7530 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
7531 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
7539 /* If there's no folder selected, and we're in SELECT_FOLDER mode, then we
7540 * fall back to the current directory */
7541 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER &&
7542 info.result == NULL)
7544 info.result = g_slist_prepend (info.result, _gtk_file_chooser_get_current_folder_path (chooser));
7547 return g_slist_reverse (info.result);
7550 static GtkFilePath *
7551 gtk_file_chooser_default_get_preview_path (GtkFileChooser *chooser)
7553 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7555 if (impl->preview_path)
7556 return gtk_file_path_copy (impl->preview_path);
7561 static GtkFileSystem *
7562 gtk_file_chooser_default_get_file_system (GtkFileChooser *chooser)
7564 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7566 return impl->file_system;
7569 /* Shows or hides the filter widgets */
7571 show_filters (GtkFileChooserDefault *impl,
7575 gtk_widget_show (impl->filter_combo_hbox);
7577 gtk_widget_hide (impl->filter_combo_hbox);
7581 gtk_file_chooser_default_add_filter (GtkFileChooser *chooser,
7582 GtkFileFilter *filter)
7584 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7587 if (g_slist_find (impl->filters, filter))
7589 g_warning ("gtk_file_chooser_add_filter() called on filter already in list\n");
7593 g_object_ref_sink (filter);
7594 impl->filters = g_slist_append (impl->filters, filter);
7596 name = gtk_file_filter_get_name (filter);
7598 name = "Untitled filter"; /* Place-holder, doesn't need to be marked for translation */
7600 gtk_combo_box_append_text (GTK_COMBO_BOX (impl->filter_combo), name);
7602 if (!g_slist_find (impl->filters, impl->current_filter))
7603 set_current_filter (impl, filter);
7605 show_filters (impl, TRUE);
7609 gtk_file_chooser_default_remove_filter (GtkFileChooser *chooser,
7610 GtkFileFilter *filter)
7612 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7613 GtkTreeModel *model;
7617 filter_index = g_slist_index (impl->filters, filter);
7619 if (filter_index < 0)
7621 g_warning ("gtk_file_chooser_remove_filter() called on filter not in list\n");
7625 impl->filters = g_slist_remove (impl->filters, filter);
7627 if (filter == impl->current_filter)
7630 set_current_filter (impl, impl->filters->data);
7632 set_current_filter (impl, NULL);
7635 /* Remove row from the combo box */
7636 model = gtk_combo_box_get_model (GTK_COMBO_BOX (impl->filter_combo));
7637 if (!gtk_tree_model_iter_nth_child (model, &iter, NULL, filter_index))
7638 g_assert_not_reached ();
7640 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
7642 g_object_unref (filter);
7645 show_filters (impl, FALSE);
7649 gtk_file_chooser_default_list_filters (GtkFileChooser *chooser)
7651 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7653 return g_slist_copy (impl->filters);
7656 /* Returns the position in the shortcuts tree where the nth specified shortcut would appear */
7658 shortcuts_get_pos_for_shortcut_folder (GtkFileChooserDefault *impl,
7661 return pos + shortcuts_get_index (impl, SHORTCUTS_SHORTCUTS);
7664 struct AddShortcutData
7666 GtkFileChooserDefault *impl;
7671 add_shortcut_get_info_cb (GtkFileSystemHandle *handle,
7672 const GtkFileInfo *info,
7673 const GError *error,
7677 gboolean cancelled = handle->cancelled;
7678 struct AddShortcutData *data = user_data;
7680 if (!g_slist_find (data->impl->loading_shortcuts, handle))
7683 data->impl->loading_shortcuts = g_slist_remove (data->impl->loading_shortcuts, handle);
7685 if (cancelled || error || !gtk_file_info_get_is_folder (info))
7688 pos = shortcuts_get_pos_for_shortcut_folder (data->impl, data->impl->num_shortcuts);
7690 shortcuts_insert_path (data->impl, pos, SHORTCUT_TYPE_PATH, NULL, data->path, NULL, FALSE, SHORTCUTS_SHORTCUTS);
7693 g_object_unref (data->impl);
7694 gtk_file_path_free (data->path);
7697 g_object_unref (handle);
7701 gtk_file_chooser_default_add_shortcut_folder (GtkFileChooser *chooser,
7702 const GtkFilePath *path,
7705 GtkFileSystemHandle *handle;
7706 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7707 struct AddShortcutData *data;
7711 /* Avoid adding duplicates */
7712 pos = shortcut_find_position (impl, path);
7713 if (pos >= 0 && pos < shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR))
7717 uri = gtk_file_system_path_to_uri (impl->file_system, path);
7718 /* translators, "Shortcut" means "Bookmark" here */
7720 GTK_FILE_CHOOSER_ERROR,
7721 GTK_FILE_CHOOSER_ERROR_ALREADY_EXISTS,
7722 _("Shortcut %s already exists"),
7729 for (l = impl->loading_shortcuts; l; l = l->next)
7731 GtkFileSystemHandle *h = l->data;
7734 p = g_object_get_data (G_OBJECT (h), "add-shortcut-path-key");
7735 if (p && !gtk_file_path_compare (path, p))
7739 uri = gtk_file_system_path_to_uri (impl->file_system, path);
7741 GTK_FILE_CHOOSER_ERROR,
7742 GTK_FILE_CHOOSER_ERROR_ALREADY_EXISTS,
7743 _("Shortcut %s already exists"),
7751 data = g_new0 (struct AddShortcutData, 1);
7752 data->impl = g_object_ref (impl);
7753 data->path = gtk_file_path_copy (path);
7755 handle = gtk_file_system_get_info (impl->file_system, path,
7756 GTK_FILE_INFO_IS_FOLDER,
7757 add_shortcut_get_info_cb, data);
7762 impl->loading_shortcuts = g_slist_append (impl->loading_shortcuts, handle);
7763 g_object_set_data (G_OBJECT (handle), "add-shortcut-path-key", data->path);
7769 gtk_file_chooser_default_remove_shortcut_folder (GtkFileChooser *chooser,
7770 const GtkFilePath *path,
7773 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7780 for (l = impl->loading_shortcuts; l; l = l->next)
7782 GtkFileSystemHandle *h = l->data;
7785 p = g_object_get_data (G_OBJECT (h), "add-shortcut-path-key");
7786 if (p && !gtk_file_path_compare (path, p))
7788 impl->loading_shortcuts = g_slist_remove (impl->loading_shortcuts, h);
7789 gtk_file_system_cancel_operation (h);
7794 if (impl->num_shortcuts == 0)
7797 pos = shortcuts_get_pos_for_shortcut_folder (impl, 0);
7798 if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos))
7799 g_assert_not_reached ();
7801 for (i = 0; i < impl->num_shortcuts; i++)
7804 ShortcutType shortcut_type;
7805 GtkFilePath *shortcut;
7807 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
7808 SHORTCUTS_COL_DATA, &col_data,
7809 SHORTCUTS_COL_TYPE, &shortcut_type,
7811 g_assert (col_data != NULL);
7812 g_assert (shortcut_type == SHORTCUT_TYPE_PATH);
7814 shortcut = col_data;
7815 if (gtk_file_path_compare (shortcut, path) == 0)
7817 shortcuts_remove_rows (impl, pos + i, 1);
7818 impl->num_shortcuts--;
7822 if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
7823 g_assert_not_reached ();
7828 uri = gtk_file_system_path_to_uri (impl->file_system, path);
7829 /* translators, "Shortcut" means "Bookmark" here */
7831 GTK_FILE_CHOOSER_ERROR,
7832 GTK_FILE_CHOOSER_ERROR_NONEXISTENT,
7833 _("Shortcut %s does not exist"),
7841 gtk_file_chooser_default_list_shortcut_folders (GtkFileChooser *chooser)
7843 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7849 if (impl->num_shortcuts == 0)
7852 pos = shortcuts_get_pos_for_shortcut_folder (impl, 0);
7853 if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos))
7854 g_assert_not_reached ();
7858 for (i = 0; i < impl->num_shortcuts; i++)
7861 ShortcutType shortcut_type;
7862 GtkFilePath *shortcut;
7864 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
7865 SHORTCUTS_COL_DATA, &col_data,
7866 SHORTCUTS_COL_TYPE, &shortcut_type,
7868 g_assert (col_data != NULL);
7869 g_assert (shortcut_type == SHORTCUT_TYPE_PATH);
7871 shortcut = col_data;
7872 list = g_slist_prepend (list, gtk_file_path_copy (shortcut));
7874 if (i != impl->num_shortcuts - 1)
7876 if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
7877 g_assert_not_reached ();
7881 return g_slist_reverse (list);
7884 /* Guesses a size based upon font sizes */
7886 find_good_size_from_style (GtkWidget *widget,
7890 GtkFileChooserDefault *impl;
7895 g_assert (widget->style != NULL);
7896 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
7898 if (impl->default_width == 0 &&
7899 impl->default_height == 0)
7901 screen = gtk_widget_get_screen (widget);
7904 resolution = gdk_screen_get_resolution (screen);
7905 if (resolution < 0.0) /* will be -1 if the resolution is not defined in the GdkScreen */
7909 resolution = 96.0; /* wheeee */
7911 font_size = pango_font_description_get_size (widget->style->font_desc);
7912 font_size = PANGO_PIXELS (font_size) * resolution / 72.0;
7914 impl->default_width = font_size * NUM_CHARS;
7915 impl->default_height = font_size * NUM_LINES;
7918 *width = impl->default_width;
7919 *height = impl->default_height;
7923 gtk_file_chooser_default_get_default_size (GtkFileChooserEmbed *chooser_embed,
7924 gint *default_width,
7925 gint *default_height)
7927 GtkFileChooserDefault *impl;
7930 impl = GTK_FILE_CHOOSER_DEFAULT (chooser_embed);
7931 find_good_size_from_style (GTK_WIDGET (chooser_embed), default_width, default_height);
7933 if (impl->preview_widget_active &&
7934 impl->preview_widget &&
7935 GTK_WIDGET_VISIBLE (impl->preview_widget))
7937 gtk_widget_size_request (impl->preview_box, &req);
7938 *default_width += PREVIEW_HBOX_SPACING + req.width;
7941 if (impl->extra_widget &&
7942 GTK_WIDGET_VISIBLE (impl->extra_widget))
7944 gtk_widget_size_request (impl->extra_align, &req);
7945 *default_height += GTK_BOX (chooser_embed)->spacing + req.height;
7950 gtk_file_chooser_default_get_resizable (GtkFileChooserEmbed *chooser_embed)
7952 GtkFileChooserDefault *impl;
7954 impl = GTK_FILE_CHOOSER_DEFAULT (chooser_embed);
7956 return (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
7957 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
7958 gtk_expander_get_expanded (GTK_EXPANDER (impl->save_expander)));
7961 struct switch_folder_closure {
7962 GtkFileChooserDefault *impl;
7963 const GtkFilePath *path;
7967 /* Used from gtk_tree_selection_selected_foreach() in switch_to_selected_folder() */
7969 switch_folder_foreach_cb (GtkTreeModel *model,
7974 struct switch_folder_closure *closure;
7975 GtkTreeIter child_iter;
7979 gtk_tree_model_sort_convert_iter_to_child_iter (closure->impl->sort_model, &child_iter, iter);
7981 closure->path = _gtk_file_system_model_get_path (closure->impl->browse_files_model, &child_iter);
7982 closure->num_selected++;
7985 /* Changes to the selected folder in the list view */
7987 switch_to_selected_folder (GtkFileChooserDefault *impl)
7989 GtkTreeSelection *selection;
7990 struct switch_folder_closure closure;
7992 /* We do this with foreach() rather than get_selected() as we may be in
7993 * multiple selection mode
7996 closure.impl = impl;
7997 closure.path = NULL;
7998 closure.num_selected = 0;
8000 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
8001 gtk_tree_selection_selected_foreach (selection, switch_folder_foreach_cb, &closure);
8003 g_assert (closure.path && closure.num_selected == 1);
8005 change_folder_and_display_error (impl, closure.path, FALSE);
8008 /* Gets the GtkFileInfo for the selected row in the file list; assumes single
8011 static const GtkFileInfo *
8012 get_selected_file_info_from_file_list (GtkFileChooserDefault *impl,
8013 gboolean *had_selection)
8015 GtkTreeSelection *selection;
8016 GtkTreeIter iter, child_iter;
8017 const GtkFileInfo *info;
8019 g_assert (!impl->select_multiple);
8020 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
8021 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
8023 *had_selection = FALSE;
8027 *had_selection = TRUE;
8029 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
8033 info = _gtk_file_system_model_get_info (impl->browse_files_model, &child_iter);
8037 /* Gets the display name of the selected file in the file list; assumes single
8038 * selection mode and that something is selected.
8040 static const gchar *
8041 get_display_name_from_file_list (GtkFileChooserDefault *impl)
8043 const GtkFileInfo *info;
8044 gboolean had_selection;
8046 info = get_selected_file_info_from_file_list (impl, &had_selection);
8047 g_assert (had_selection);
8048 g_assert (info != NULL);
8050 return gtk_file_info_get_display_name (info);
8054 add_custom_button_to_dialog (GtkDialog *dialog,
8055 const gchar *mnemonic_label,
8056 const gchar *stock_id,
8061 button = gtk_button_new_with_mnemonic (mnemonic_label);
8062 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
8063 gtk_button_set_image (GTK_BUTTON (button),
8064 gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON));
8065 gtk_widget_show (button);
8067 gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, response_id);
8070 /* Presents an overwrite confirmation dialog; returns whether we should accept
8074 confirm_dialog_should_accept_filename (GtkFileChooserDefault *impl,
8075 const gchar *file_part,
8076 const gchar *folder_display_name)
8078 GtkWindow *toplevel;
8082 toplevel = get_toplevel (GTK_WIDGET (impl));
8084 dialog = gtk_message_dialog_new (toplevel,
8085 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
8086 GTK_MESSAGE_QUESTION,
8088 _("A file named \"%s\" already exists. Do you want to replace it?"),
8090 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
8091 _("The file already exists in \"%s\". Replacing it will "
8092 "overwrite its contents."),
8093 folder_display_name);
8095 gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
8096 add_custom_button_to_dialog (GTK_DIALOG (dialog), _("_Replace"), GTK_STOCK_SAVE_AS, GTK_RESPONSE_ACCEPT);
8097 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
8099 if (toplevel->group)
8100 gtk_window_group_add_window (toplevel->group, GTK_WINDOW (dialog));
8102 response = gtk_dialog_run (GTK_DIALOG (dialog));
8104 gtk_widget_destroy (dialog);
8106 return (response == GTK_RESPONSE_ACCEPT);
8109 struct GetDisplayNameData
8111 GtkFileChooserDefault *impl;
8116 confirmation_confirm_get_info_cb (GtkFileSystemHandle *handle,
8117 const GtkFileInfo *info,
8118 const GError *error,
8121 gboolean cancelled = handle->cancelled;
8122 gboolean should_respond = FALSE;
8123 struct GetDisplayNameData *data = user_data;
8125 if (handle != data->impl->should_respond_get_info_handle)
8128 data->impl->should_respond_get_info_handle = NULL;
8134 /* Huh? Did the folder disappear? Let the caller deal with it */
8135 should_respond = TRUE;
8137 should_respond = confirm_dialog_should_accept_filename (data->impl, data->file_part, gtk_file_info_get_display_name (info));
8139 set_busy_cursor (data->impl, FALSE);
8141 g_signal_emit_by_name (data->impl, "response-requested");
8144 g_object_unref (data->impl);
8145 g_free (data->file_part);
8148 g_object_unref (handle);
8151 /* Does overwrite confirmation if appropriate, and returns whether the dialog
8152 * should respond. Can get the file part from the file list or the save entry.
8155 should_respond_after_confirm_overwrite (GtkFileChooserDefault *impl,
8156 const gchar *file_part,
8157 const GtkFilePath *parent_path)
8159 GtkFileChooserConfirmation conf;
8161 if (!impl->do_overwrite_confirmation)
8164 conf = GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM;
8166 g_signal_emit_by_name (impl, "confirm-overwrite", &conf);
8170 case GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM:
8172 struct GetDisplayNameData *data;
8174 g_assert (file_part != NULL);
8176 data = g_new0 (struct GetDisplayNameData, 1);
8177 data->impl = g_object_ref (impl);
8178 data->file_part = g_strdup (file_part);
8180 if (impl->should_respond_get_info_handle)
8181 gtk_file_system_cancel_operation (impl->should_respond_get_info_handle);
8183 impl->should_respond_get_info_handle =
8184 gtk_file_system_get_info (impl->file_system, parent_path,
8185 GTK_FILE_INFO_DISPLAY_NAME,
8186 confirmation_confirm_get_info_cb,
8188 set_busy_cursor (data->impl, TRUE);
8192 case GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME:
8195 case GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN:
8199 g_assert_not_reached ();
8205 action_create_folder_cb (GtkFileSystemHandle *handle,
8206 const GtkFilePath *path,
8207 const GError *error,
8210 gboolean cancelled = handle->cancelled;
8211 GtkFileChooserDefault *impl = user_data;
8213 if (!g_slist_find (impl->pending_handles, handle))
8216 impl->pending_handles = g_slist_remove (impl->pending_handles, handle);
8218 set_busy_cursor (impl, FALSE);
8224 error_creating_folder_dialog (impl, path, g_error_copy (error));
8226 g_signal_emit_by_name (impl, "response-requested");
8229 g_object_unref (impl);
8230 g_object_unref (handle);
8233 struct FileExistsData
8235 GtkFileChooserDefault *impl;
8236 gboolean file_exists_and_is_not_folder;
8237 GtkFilePath *parent_path;
8242 save_entry_get_info_cb (GtkFileSystemHandle *handle,
8243 const GtkFileInfo *info,
8244 const GError *error,
8247 gboolean parent_is_folder;
8248 gboolean cancelled = handle->cancelled;
8249 struct FileExistsData *data = user_data;
8251 if (handle != data->impl->should_respond_get_info_handle)
8254 data->impl->should_respond_get_info_handle = NULL;
8256 set_busy_cursor (data->impl, FALSE);
8262 parent_is_folder = FALSE;
8264 parent_is_folder = gtk_file_info_get_is_folder (info);
8266 if (parent_is_folder)
8268 if (data->impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
8270 if (data->file_exists_and_is_not_folder)
8273 const char *file_part;
8275 file_part = _gtk_file_chooser_entry_get_file_part (GTK_FILE_CHOOSER_ENTRY (data->impl->location_entry));
8276 retval = should_respond_after_confirm_overwrite (data->impl, file_part, data->parent_path);
8279 g_signal_emit_by_name (data->impl, "response-requested");
8282 g_signal_emit_by_name (data->impl, "response-requested");
8284 else /* GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER */
8286 GtkFileSystemHandle *handle;
8288 g_object_ref (data->impl);
8289 handle = gtk_file_system_create_folder (data->impl->file_system,
8291 action_create_folder_cb,
8293 data->impl->pending_handles = g_slist_append (data->impl->pending_handles, handle);
8294 set_busy_cursor (data->impl, TRUE);
8299 /* This will display an error, which is what we want */
8300 change_folder_and_display_error (data->impl, data->parent_path, FALSE);
8304 g_object_unref (data->impl);
8305 gtk_file_path_free (data->path);
8306 gtk_file_path_free (data->parent_path);
8309 g_object_unref (handle);
8313 file_exists_get_info_cb (GtkFileSystemHandle *handle,
8314 const GtkFileInfo *info,
8315 const GError *error,
8318 gboolean data_ownership_taken = FALSE;
8319 gboolean cancelled = handle->cancelled;
8320 gboolean file_exists_and_is_not_folder;
8321 struct FileExistsData *data = user_data;
8323 if (handle != data->impl->file_exists_get_info_handle)
8326 data->impl->file_exists_get_info_handle = NULL;
8328 set_busy_cursor (data->impl, FALSE);
8333 file_exists_and_is_not_folder = info && !gtk_file_info_get_is_folder (info);
8335 if (data->impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
8336 /* user typed a filename; we are done */
8337 g_signal_emit_by_name (data->impl, "response-requested");
8338 else if (data->impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER
8339 && file_exists_and_is_not_folder)
8341 /* Oops, the user typed the name of an existing path which is not
8344 error_creating_folder_over_existing_file_dialog (data->impl, data->path,
8345 g_error_copy (error));
8349 /* check that everything up to the last component exists */
8351 data->file_exists_and_is_not_folder = file_exists_and_is_not_folder;
8352 data_ownership_taken = TRUE;
8354 if (data->impl->should_respond_get_info_handle)
8355 gtk_file_system_cancel_operation (data->impl->should_respond_get_info_handle);
8357 data->impl->should_respond_get_info_handle =
8358 gtk_file_system_get_info (data->impl->file_system,
8360 GTK_FILE_INFO_IS_FOLDER,
8361 save_entry_get_info_cb,
8363 set_busy_cursor (data->impl, TRUE);
8367 if (!data_ownership_taken)
8369 g_object_unref (data->impl);
8370 gtk_file_path_free (data->path);
8371 gtk_file_path_free (data->parent_path);
8375 g_object_unref (handle);
8379 paste_text_received (GtkClipboard *clipboard,
8381 GtkFileChooserDefault *impl)
8388 path = gtk_file_system_uri_to_path (impl->file_system, text);
8391 if (!g_path_is_absolute (text))
8393 location_popup_handler (impl, text);
8397 path = gtk_file_system_filename_to_path (impl->file_system, text);
8400 location_popup_handler (impl, text);
8405 if (!gtk_file_chooser_default_select_path (GTK_FILE_CHOOSER (impl), path, NULL))
8406 location_popup_handler (impl, text);
8408 gtk_file_path_free (path);
8411 /* Handler for the "location-popup-on-paste" keybinding signal */
8413 location_popup_on_paste_handler (GtkFileChooserDefault *impl)
8415 GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (impl),
8416 GDK_SELECTION_CLIPBOARD);
8417 gtk_clipboard_request_text (clipboard,
8418 (GtkClipboardTextReceivedFunc) paste_text_received,
8423 /* Implementation for GtkFileChooserEmbed::should_respond() */
8425 gtk_file_chooser_default_should_respond (GtkFileChooserEmbed *chooser_embed)
8427 GtkFileChooserDefault *impl;
8428 GtkWidget *toplevel;
8429 GtkWidget *current_focus;
8431 impl = GTK_FILE_CHOOSER_DEFAULT (chooser_embed);
8433 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (impl));
8434 g_assert (GTK_IS_WINDOW (toplevel));
8436 current_focus = gtk_window_get_focus (GTK_WINDOW (toplevel));
8438 if (current_focus == impl->browse_files_tree_view)
8440 /* The following array encodes what we do based on the impl->action and the
8441 * number of files selected.
8444 NOOP, /* Do nothing (don't respond) */
8445 RESPOND, /* Respond immediately */
8446 RESPOND_OR_SWITCH, /* Respond immediately if the selected item is a file; switch to it if it is a folder */
8447 ALL_FILES, /* Respond only if everything selected is a file */
8448 ALL_FOLDERS, /* Respond only if everything selected is a folder */
8449 SAVE_ENTRY, /* Go to the code for handling the save entry */
8450 NOT_REACHED /* Sanity check */
8452 static const ActionToTake what_to_do[4][3] = {
8453 /* 0 selected 1 selected many selected */
8454 /* ACTION_OPEN */ { NOOP, RESPOND_OR_SWITCH, ALL_FILES },
8455 /* ACTION_SAVE */ { SAVE_ENTRY, RESPOND_OR_SWITCH, NOT_REACHED },
8456 /* ACTION_SELECT_FOLDER */ { RESPOND, ALL_FOLDERS, ALL_FOLDERS },
8457 /* ACTION_CREATE_FOLDER */ { SAVE_ENTRY, ALL_FOLDERS, NOT_REACHED }
8461 gboolean all_files, all_folders;
8463 ActionToTake action;
8467 g_assert (impl->action >= GTK_FILE_CHOOSER_ACTION_OPEN && impl->action <= GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER);
8469 if (impl->operation_mode == OPERATION_MODE_SEARCH)
8470 return search_should_respond (impl);
8472 if (impl->operation_mode == OPERATION_MODE_RECENT)
8473 return recent_should_respond (impl);
8475 selection_check (impl, &num_selected, &all_files, &all_folders);
8477 if (num_selected > 2)
8482 action = what_to_do [impl->action] [k];
8492 case RESPOND_OR_SWITCH:
8493 g_assert (num_selected == 1);
8497 switch_to_selected_folder (impl);
8500 else if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
8501 return should_respond_after_confirm_overwrite (impl,
8502 get_display_name_from_file_list (impl),
8503 impl->current_folder);
8517 g_assert_not_reached ();
8520 else if ((impl->location_entry != NULL) && (current_focus == impl->location_entry))
8523 gboolean is_well_formed, is_empty, is_file_part_empty;
8526 GtkFileChooserEntry *entry;
8531 g_assert (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
8532 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER
8533 || ((impl->action == GTK_FILE_CHOOSER_ACTION_OPEN
8534 || impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
8535 && impl->location_mode == LOCATION_MODE_FILENAME_ENTRY));
8537 entry = GTK_FILE_CHOOSER_ENTRY (impl->location_entry);
8538 check_save_entry (impl, &path, &is_well_formed, &is_empty, &is_file_part_empty, &is_folder);
8540 if (is_empty || !is_well_formed)
8543 g_assert (path != NULL);
8548 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
8549 impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
8551 change_folder_and_display_error (impl, path, TRUE);
8554 else if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
8555 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
8557 /* The folder already exists, so we do not need to create it.
8558 * Just respond to terminate the dialog.
8564 g_assert_not_reached ();
8570 struct FileExistsData *data;
8572 /* We need to check whether path exists and is not a folder */
8574 data = g_new0 (struct FileExistsData, 1);
8575 data->impl = g_object_ref (impl);
8576 data->path = gtk_file_path_copy (path);
8577 data->parent_path = gtk_file_path_copy (_gtk_file_chooser_entry_get_current_folder (entry));
8579 if (impl->file_exists_get_info_handle)
8580 gtk_file_system_cancel_operation (impl->file_exists_get_info_handle);
8582 impl->file_exists_get_info_handle =
8583 gtk_file_system_get_info (impl->file_system, path,
8584 GTK_FILE_INFO_IS_FOLDER,
8585 file_exists_get_info_cb,
8588 set_busy_cursor (impl, TRUE);
8592 g_error_free (error);
8595 gtk_file_path_free (path);
8598 else if (impl->toplevel_last_focus_widget == impl->browse_files_tree_view)
8600 /* The focus is on a dialog's action area button, *and* the widget that
8601 * was focused immediately before it is the file list.
8605 else if (impl->operation_mode == OPERATION_MODE_SEARCH && impl->toplevel_last_focus_widget == impl->search_entry)
8607 search_entry_activate_cb (GTK_ENTRY (impl->search_entry), impl);
8610 else if (impl->location_entry && impl->toplevel_last_focus_widget == impl->location_entry)
8612 /* The focus is on a dialog's action area button, *and* the widget that
8613 * was focused immediately before it is the location entry.
8618 /* The focus is on a dialog's action area button or something else */
8619 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
8620 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
8625 g_assert_not_reached ();
8629 /* Implementation for GtkFileChooserEmbed::initial_focus() */
8631 gtk_file_chooser_default_initial_focus (GtkFileChooserEmbed *chooser_embed)
8633 GtkFileChooserDefault *impl;
8636 impl = GTK_FILE_CHOOSER_DEFAULT (chooser_embed);
8638 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
8639 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
8641 if (impl->location_mode == LOCATION_MODE_PATH_BAR)
8642 widget = impl->browse_files_tree_view;
8644 widget = impl->location_entry;
8646 else if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
8647 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
8648 widget = impl->location_entry;
8651 g_assert_not_reached ();
8655 g_assert (widget != NULL);
8656 gtk_widget_grab_focus (widget);
8659 /* Callback used from gtk_tree_selection_selected_foreach(); gets the selected GtkFilePaths */
8661 search_selected_foreach_get_path_cb (GtkTreeModel *model,
8667 const GtkFilePath *file_path;
8668 GtkFilePath *file_path_copy;
8672 gtk_tree_model_get (model, iter, SEARCH_MODEL_COL_PATH, &file_path, -1);
8673 file_path_copy = gtk_file_path_copy (file_path);
8674 *list = g_slist_prepend (*list, file_path_copy);
8677 /* Constructs a list of the selected paths in search mode */
8679 search_get_selected_paths (GtkFileChooserDefault *impl)
8682 GtkTreeSelection *selection;
8686 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
8687 gtk_tree_selection_selected_foreach (selection, search_selected_foreach_get_path_cb, &result);
8688 result = g_slist_reverse (result);
8693 /* Called from ::should_respond(). We return whether there are selected files
8694 * in the search list.
8697 search_should_respond (GtkFileChooserDefault *impl)
8699 GtkTreeSelection *selection;
8701 g_assert (impl->operation_mode == OPERATION_MODE_SEARCH);
8703 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
8704 return (gtk_tree_selection_count_selected_rows (selection) != 0);
8707 struct SearchHitInsertRequest
8709 GtkFileChooserDefault *impl;
8711 GtkTreeRowReference *row_ref;
8715 search_hit_get_info_cb (GtkFileSystemHandle *handle,
8716 const GtkFileInfo *info,
8717 const GError *error,
8720 gboolean cancelled = handle->cancelled;
8721 GdkPixbuf *pixbuf = NULL;
8724 GtkFileSystemHandle *model_handle;
8725 gboolean is_folder = FALSE;
8728 struct SearchHitInsertRequest *request = data;
8730 if (!request->impl->search_model)
8733 path = gtk_tree_row_reference_get_path (request->row_ref);
8737 gtk_tree_model_get_iter (GTK_TREE_MODEL (request->impl->search_model),
8739 gtk_tree_path_free (path);
8741 gtk_tree_model_get (GTK_TREE_MODEL (request->impl->search_model), &iter,
8742 SEARCH_MODEL_COL_HANDLE, &model_handle,
8744 if (handle != model_handle)
8747 /* set the handle to NULL in the model */
8748 gtk_list_store_set (request->impl->search_model, &iter,
8749 SEARCH_MODEL_COL_HANDLE, NULL,
8757 gtk_list_store_remove (request->impl->search_model, &iter);
8761 display_name = g_strdup (gtk_file_info_get_display_name (info));
8762 mime_type = g_strdup (gtk_file_info_get_mime_type (info));
8763 is_folder = gtk_file_info_get_is_folder (info);
8764 pixbuf = gtk_file_info_render_icon (info, GTK_WIDGET (request->impl),
8765 request->impl->icon_size, NULL);
8767 gtk_list_store_set (request->impl->search_model, &iter,
8768 SEARCH_MODEL_COL_PIXBUF, pixbuf,
8769 SEARCH_MODEL_COL_DISPLAY_NAME, display_name,
8770 SEARCH_MODEL_COL_MIME_TYPE, mime_type,
8771 SEARCH_MODEL_COL_IS_FOLDER, is_folder,
8775 g_object_unref (pixbuf);
8778 g_object_unref (request->impl);
8779 gtk_file_path_free (request->path);
8780 gtk_tree_row_reference_free (request->row_ref);
8783 g_object_unref (handle);
8786 /* Adds one hit from the search engine to the search_model */
8788 search_add_hit (GtkFileChooserDefault *impl,
8794 char *collation_key;
8795 struct stat statbuf;
8796 struct stat *statbuf_copy;
8799 GtkFileSystemHandle *handle;
8800 struct SearchHitInsertRequest *request;
8802 path = gtk_file_system_uri_to_path (impl->file_system, uri);
8806 filename = gtk_file_system_path_to_filename (impl->file_system, path);
8809 gtk_file_path_free (path);
8813 if (stat (filename, &statbuf) != 0)
8815 gtk_file_path_free (path);
8820 statbuf_copy = g_new (struct stat, 1);
8821 *statbuf_copy = statbuf;
8823 tmp = g_filename_display_name (filename);
8824 collation_key = g_utf8_collate_key_for_filename (tmp, -1);
8827 request = g_new0 (struct SearchHitInsertRequest, 1);
8828 request->impl = g_object_ref (impl);
8829 request->path = gtk_file_path_copy (path);
8831 gtk_list_store_append (impl->search_model, &iter);
8832 p = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->search_model), &iter);
8834 request->row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (impl->search_model), p);
8835 gtk_tree_path_free (p);
8837 handle = gtk_file_system_get_info (impl->file_system, path,
8838 GTK_FILE_INFO_IS_FOLDER | GTK_FILE_INFO_ICON | GTK_FILE_INFO_MIME_TYPE | GTK_FILE_INFO_DISPLAY_NAME,
8839 search_hit_get_info_cb,
8842 gtk_list_store_set (impl->search_model, &iter,
8843 SEARCH_MODEL_COL_PATH, path,
8844 SEARCH_MODEL_COL_COLLATION_KEY, collation_key,
8845 SEARCH_MODEL_COL_STAT, statbuf_copy,
8846 SEARCH_MODEL_COL_HANDLE, handle,
8850 /* Callback used from GtkSearchEngine when we get new hits */
8852 search_engine_hits_added_cb (GtkSearchEngine *engine,
8856 GtkFileChooserDefault *impl;
8859 impl = GTK_FILE_CHOOSER_DEFAULT (data);
8861 for (l = hits; l; l = l->next)
8862 search_add_hit (impl, (gchar*)l->data);
8865 /* Callback used from GtkSearchEngine when the query is done running */
8867 search_engine_finished_cb (GtkSearchEngine *engine,
8870 GtkFileChooserDefault *impl;
8872 impl = GTK_FILE_CHOOSER_DEFAULT (data);
8875 /* EB: setting the model here will avoid loads of row events,
8876 * but it'll make the search look like blocked.
8878 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view),
8879 GTK_TREE_MODEL (impl->search_model_filter));
8882 /* FMQ: if search was empty, say that we got no hits */
8883 set_busy_cursor (impl, FALSE);
8886 /* Displays a generic error when we cannot create a GtkSearchEngine.
8887 * It would be better if _gtk_search_engine_new() gave us a GError
8888 * with a better message, but it doesn't do that right now.
8891 search_error_could_not_create_client (GtkFileChooserDefault *impl)
8893 error_message (impl,
8894 _("Could not start the search process"),
8895 _("The program was not able to create a connection to the indexer "
8896 "daemon. Please make sure it is running."));
8900 search_engine_error_cb (GtkSearchEngine *engine,
8901 const gchar *message,
8904 GtkFileChooserDefault *impl;
8906 impl = GTK_FILE_CHOOSER_DEFAULT (data);
8908 search_stop_searching (impl, TRUE);
8909 error_message (impl, _("Could not send the search request"), message);
8911 set_busy_cursor (impl, FALSE);
8914 /* Frees the data in the search_model */
8916 search_clear_model (GtkFileChooserDefault *impl,
8917 gboolean remove_from_treeview)
8919 GtkTreeModel *model;
8922 if (!impl->search_model)
8925 model = GTK_TREE_MODEL (impl->search_model);
8927 if (gtk_tree_model_get_iter_first (model, &iter))
8931 gchar *display_name;
8932 gchar *collation_key;
8933 struct stat *statbuf;
8934 GtkFileSystemHandle *handle;
8936 gtk_tree_model_get (model, &iter,
8937 SEARCH_MODEL_COL_PATH, &path,
8938 SEARCH_MODEL_COL_DISPLAY_NAME, &display_name,
8939 SEARCH_MODEL_COL_COLLATION_KEY, &collation_key,
8940 SEARCH_MODEL_COL_STAT, &statbuf,
8941 SEARCH_MODEL_COL_HANDLE, &handle,
8945 gtk_file_system_cancel_operation (handle);
8947 gtk_file_path_free (path);
8948 g_free (display_name);
8949 g_free (collation_key);
8952 while (gtk_tree_model_iter_next (model, &iter));
8954 g_object_unref (impl->search_model);
8955 impl->search_model = NULL;
8957 g_object_unref (impl->search_model_filter);
8958 impl->search_model_filter = NULL;
8960 g_object_unref (impl->search_model_sort);
8961 impl->search_model_sort = NULL;
8963 if (remove_from_treeview)
8964 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), NULL);
8967 /* Stops any ongoing searches; does not touch the search_model */
8969 search_stop_searching (GtkFileChooserDefault *impl,
8970 gboolean remove_query)
8972 if (remove_query && impl->search_query)
8974 g_object_unref (impl->search_query);
8975 impl->search_query = NULL;
8978 if (impl->search_engine)
8980 _gtk_search_engine_stop (impl->search_engine);
8982 g_object_unref (impl->search_engine);
8983 impl->search_engine = NULL;
8987 /* Stops any pending searches, clears the file list, and switches back to OPERATION_MODE_BROWSE */
8989 search_switch_to_browse_mode (GtkFileChooserDefault *impl)
8991 g_assert (impl->operation_mode != OPERATION_MODE_BROWSE);
8993 search_stop_searching (impl, FALSE);
8994 search_clear_model (impl, TRUE);
8996 gtk_widget_destroy (impl->search_hbox);
8997 impl->search_hbox = NULL;
8998 impl->search_entry = NULL;
9000 gtk_widget_show (impl->browse_path_bar);
9001 gtk_widget_show (impl->browse_new_folder_button);
9003 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
9004 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
9006 gtk_widget_show (impl->location_button);
9008 if (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)
9009 gtk_widget_show (impl->location_entry_box);
9012 impl->operation_mode = OPERATION_MODE_BROWSE;
9014 file_list_set_sort_column_ids (impl);
9017 /* Sort callback from the path column */
9019 search_column_path_sort_func (GtkTreeModel *model,
9024 GtkFileChooserDefault *impl = user_data;
9025 GtkTreeIter child_a, child_b;
9026 const char *collation_key_a, *collation_key_b;
9027 gboolean is_folder_a, is_folder_b;
9029 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_a, a);
9030 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_b, b);
9032 gtk_tree_model_get (GTK_TREE_MODEL (impl->search_model), &child_a,
9033 SEARCH_MODEL_COL_IS_FOLDER, &is_folder_a,
9034 SEARCH_MODEL_COL_COLLATION_KEY, &collation_key_a,
9036 gtk_tree_model_get (GTK_TREE_MODEL (impl->search_model), &child_b,
9037 SEARCH_MODEL_COL_IS_FOLDER, &is_folder_b,
9038 SEARCH_MODEL_COL_COLLATION_KEY, &collation_key_b,
9041 if (!collation_key_a)
9044 if (!collation_key_b)
9047 /* always show folders first */
9048 if (is_folder_a != is_folder_b)
9049 return is_folder_a ? 1 : -1;
9051 return strcmp (collation_key_a, collation_key_b);
9054 /* Sort callback from the modification time column */
9056 search_column_mtime_sort_func (GtkTreeModel *model,
9061 GtkFileChooserDefault *impl = user_data;
9062 GtkTreeIter child_a, child_b;
9063 const struct stat *statbuf_a, *statbuf_b;
9064 gboolean is_folder_a, is_folder_b;
9066 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_a, a);
9067 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_b, b);
9069 /* Note that although we store a whole struct stat in the model, we only
9070 * compare the mtime here. If we add another column relative to a struct stat
9071 * (e.g. a file size column), we'll want another sort callback similar to this
9074 gtk_tree_model_get (GTK_TREE_MODEL (impl->search_model), &child_a,
9075 SEARCH_MODEL_COL_IS_FOLDER, &is_folder_a,
9076 SEARCH_MODEL_COL_STAT, &statbuf_a,
9078 gtk_tree_model_get (GTK_TREE_MODEL (impl->search_model), &child_b,
9079 SEARCH_MODEL_COL_IS_FOLDER, &is_folder_b,
9080 SEARCH_MODEL_COL_STAT, &statbuf_b,
9089 if (is_folder_a != is_folder_b)
9090 return is_folder_a ? 1 : -1;
9092 if (statbuf_a->st_mtime < statbuf_b->st_mtime)
9094 else if (statbuf_a->st_mtime > statbuf_b->st_mtime)
9101 search_get_is_filtered (GtkFileChooserDefault *impl,
9102 const GtkFilePath *path,
9103 const gchar *display_name,
9104 const gchar *mime_type)
9106 GtkFileFilterInfo filter_info;
9107 GtkFileFilterFlags needed;
9110 if (!impl->current_filter)
9113 filter_info.contains = GTK_FILE_FILTER_DISPLAY_NAME | GTK_FILE_FILTER_MIME_TYPE;
9114 needed = gtk_file_filter_get_needed (impl->current_filter);
9116 filter_info.display_name = display_name;
9117 filter_info.mime_type = mime_type;
9119 if (needed & GTK_FILE_FILTER_FILENAME)
9121 filter_info.filename = gtk_file_system_path_to_filename (impl->file_system, path);
9122 if (filter_info.filename)
9123 filter_info.contains |= GTK_FILE_FILTER_FILENAME;
9126 filter_info.filename = NULL;
9128 if (needed & GTK_FILE_FILTER_URI)
9130 filter_info.uri = gtk_file_system_path_to_uri (impl->file_system, path);
9131 if (filter_info.uri)
9132 filter_info.contains |= GTK_FILE_FILTER_URI;
9135 filter_info.uri = NULL;
9137 result = gtk_file_filter_filter (impl->current_filter, &filter_info);
9139 if (filter_info.filename)
9140 g_free ((gchar *) filter_info.filename);
9141 if (filter_info.uri)
9142 g_free ((gchar *) filter_info.uri);
9148 /* Visibility function for the recent filter model */
9150 search_model_visible_func (GtkTreeModel *model,
9154 GtkFileChooserDefault *impl = user_data;
9155 GtkFilePath *file_path;
9156 gchar *display_name, *mime_type;
9159 if (!impl->current_filter)
9162 gtk_tree_model_get (model, iter,
9163 SEARCH_MODEL_COL_PATH, &file_path,
9164 SEARCH_MODEL_COL_IS_FOLDER, &is_folder,
9165 SEARCH_MODEL_COL_DISPLAY_NAME, &display_name,
9166 SEARCH_MODEL_COL_MIME_TYPE, &mime_type,
9175 return !search_get_is_filtered (impl, file_path, display_name, mime_type);
9178 /* Creates the search_model and puts it in the tree view */
9180 search_setup_model (GtkFileChooserDefault *impl)
9182 g_assert (impl->search_model == NULL);
9183 g_assert (impl->search_model_filter == NULL);
9184 g_assert (impl->search_model_sort == NULL);
9186 /* We store these columns in the search model:
9188 * SEARCH_MODEL_COL_PATH - a GtkFilePath for the hit's URI, stored as a
9189 * pointer not as a GTK_TYPE_FILE_PATH
9190 * SEARCH_MODEL_COL_DISPLAY_NAME - a string with the display name, stored
9191 * as a pointer not as a G_TYPE_STRING
9192 * SEARCH_MODEL_COL_COLLATION_KEY - collation key for the filename, stored
9193 * as a pointer not as a G_TYPE_STRING
9194 * SEARCH_MODEL_COL_STAT - pointer to a struct stat
9195 * SEARCH_MODEL_COL_HANDLE - handle used when getting the hit's info
9196 * SEARCH_MODEL_COL_PIXBUF - GdkPixbuf for the hit's icon
9197 * SEARCH_MODEL_COL_MIME_TYPE - a string with the hit's MIME type
9198 * SEARCH_MODEL_COL_IS_FOLDER - a boolean flag for folders
9200 * Keep this in sync with the enumeration defined near the beginning
9203 impl->search_model = gtk_list_store_new (SEARCH_MODEL_COL_NUM_COLUMNS,
9213 impl->search_model_filter =
9214 GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (GTK_TREE_MODEL (impl->search_model), NULL));
9215 gtk_tree_model_filter_set_visible_func (impl->search_model_filter,
9216 search_model_visible_func,
9219 impl->search_model_sort =
9220 GTK_TREE_MODEL_SORT (search_model_sort_new (impl, GTK_TREE_MODEL (impl->search_model_filter)));
9221 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->search_model_sort),
9222 SEARCH_MODEL_COL_PATH,
9223 search_column_path_sort_func,
9225 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->search_model_sort),
9226 SEARCH_MODEL_COL_STAT,
9227 search_column_mtime_sort_func,
9229 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (impl->search_model_sort),
9230 SEARCH_MODEL_COL_STAT,
9231 GTK_SORT_DESCENDING);
9233 /* EB: setting the model here will make the hits list update feel
9234 * more "alive" than setting the model at the end of the search
9237 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view),
9238 GTK_TREE_MODEL (impl->search_model_sort));
9242 search_get_valid_child_iter (GtkFileChooserDefault *impl,
9243 GtkTreeIter *child_iter,
9248 if (!impl->search_model)
9251 if (!impl->search_model_filter || !impl->search_model_sort)
9254 /* pass 1: get the iterator in the filter model */
9255 gtk_tree_model_sort_convert_iter_to_child_iter (impl->search_model_sort,
9258 /* pass 2: get the iterator in the real model */
9259 gtk_tree_model_filter_convert_iter_to_child_iter (impl->search_model_filter,
9260 child_iter, &middle);
9263 /* Creates a new query with the specified text and launches it */
9265 search_start_query (GtkFileChooserDefault *impl,
9266 const gchar *query_text)
9268 search_stop_searching (impl, FALSE);
9269 search_clear_model (impl, TRUE);
9270 search_setup_model (impl);
9271 set_busy_cursor (impl, TRUE);
9273 if (impl->search_engine == NULL)
9274 impl->search_engine = _gtk_search_engine_new ();
9276 if (!impl->search_engine)
9278 set_busy_cursor (impl, FALSE);
9279 search_error_could_not_create_client (impl); /* lame; we don't get an error code or anything */
9283 if (!impl->search_query)
9285 impl->search_query = _gtk_query_new ();
9286 _gtk_query_set_text (impl->search_query, query_text);
9289 _gtk_search_engine_set_query (impl->search_engine, impl->search_query);
9291 g_signal_connect (impl->search_engine, "hits-added",
9292 G_CALLBACK (search_engine_hits_added_cb), impl);
9293 g_signal_connect (impl->search_engine, "finished",
9294 G_CALLBACK (search_engine_finished_cb), impl);
9295 g_signal_connect (impl->search_engine, "error",
9296 G_CALLBACK (search_engine_error_cb), impl);
9298 _gtk_search_engine_start (impl->search_engine);
9301 /* Callback used when the user presses Enter while typing on the search
9302 * entry; starts the query
9305 search_entry_activate_cb (GtkEntry *entry,
9308 GtkFileChooserDefault *impl;
9311 impl = GTK_FILE_CHOOSER_DEFAULT (data);
9313 text = gtk_entry_get_text (GTK_ENTRY (impl->search_entry));
9314 if (strlen (text) == 0)
9317 /* reset any existing query object */
9318 if (impl->search_query)
9320 g_object_unref (impl->search_query);
9321 impl->search_query = NULL;
9324 search_start_query (impl, text);
9327 /* Hides the path bar and creates the search entry */
9329 search_setup_widgets (GtkFileChooserDefault *impl)
9333 impl->search_hbox = gtk_hbox_new (FALSE, 12);
9337 label = gtk_label_new_with_mnemonic (_("_Search:"));
9338 gtk_box_pack_start (GTK_BOX (impl->search_hbox), label, FALSE, FALSE, 0);
9342 impl->search_entry = gtk_entry_new ();
9343 gtk_label_set_mnemonic_widget (GTK_LABEL (label), impl->search_entry);
9344 g_signal_connect (impl->search_entry, "activate",
9345 G_CALLBACK (search_entry_activate_cb),
9347 gtk_box_pack_start (GTK_BOX (impl->search_hbox), impl->search_entry, TRUE, TRUE, 0);
9349 /* if there already is a query, restart it */
9350 if (impl->search_query)
9352 gchar *query = _gtk_query_get_text (impl->search_query);
9356 gtk_entry_set_text (GTK_ENTRY (impl->search_entry), query);
9357 search_start_query (impl, query);
9363 g_object_unref (impl->search_query);
9364 impl->search_query = NULL;
9368 gtk_widget_hide (impl->browse_path_bar);
9369 gtk_widget_hide (impl->browse_new_folder_button);
9371 /* Box for search widgets */
9372 gtk_box_pack_start (GTK_BOX (impl->browse_path_bar_hbox), impl->search_hbox, TRUE, TRUE, 0);
9373 gtk_widget_show_all (impl->search_hbox);
9375 /* Hide the location widgets temporarily */
9377 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
9378 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
9380 gtk_widget_hide (impl->location_button);
9381 gtk_widget_hide (impl->location_entry_box);
9384 gtk_widget_grab_focus (impl->search_entry);
9386 /* FMQ: hide the filter combo? */
9389 /* Main entry point to the searching functions; this gets called when the user
9390 * activates the Search shortcut.
9393 search_activate (GtkFileChooserDefault *impl)
9395 OperationMode previous_mode;
9397 if (impl->operation_mode == OPERATION_MODE_SEARCH)
9399 gtk_widget_grab_focus (impl->search_entry);
9403 previous_mode = impl->operation_mode;
9404 impl->operation_mode = OPERATION_MODE_SEARCH;
9406 switch (previous_mode)
9408 case OPERATION_MODE_RECENT:
9409 recent_stop_loading (impl);
9410 recent_clear_model (impl, TRUE);
9413 case OPERATION_MODE_BROWSE:
9414 stop_loading_and_clear_list_model (impl);
9417 case OPERATION_MODE_SEARCH:
9418 g_assert_not_reached ();
9422 g_assert (impl->search_hbox == NULL);
9423 g_assert (impl->search_entry == NULL);
9424 g_assert (impl->search_model == NULL);
9425 g_assert (impl->search_model_filter == NULL);
9427 search_setup_widgets (impl);
9428 file_list_set_sort_column_ids (impl);
9432 * Recent files support
9435 /* Frees the data in the recent_model */
9437 recent_clear_model (GtkFileChooserDefault *impl,
9438 gboolean remove_from_treeview)
9440 GtkTreeModel *model;
9443 if (!impl->recent_model)
9446 model = GTK_TREE_MODEL (impl->recent_model);
9448 if (remove_from_treeview)
9449 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), NULL);
9451 if (gtk_tree_model_get_iter_first (model, &iter))
9455 GtkFilePath *file_path;
9456 GtkFileSystemHandle *handle;
9457 GtkRecentInfo *recent_info;
9458 gchar *display_name;
9460 gtk_tree_model_get (model, &iter,
9461 RECENT_MODEL_COL_DISPLAY_NAME, &display_name,
9462 RECENT_MODEL_COL_PATH, &file_path,
9463 RECENT_MODEL_COL_HANDLE, &handle,
9464 RECENT_MODEL_COL_INFO, &recent_info,
9468 gtk_file_system_cancel_operation (handle);
9470 gtk_file_path_free (file_path);
9471 gtk_recent_info_unref (recent_info);
9472 g_free (display_name);
9474 while (gtk_tree_model_iter_next (model, &iter));
9477 g_object_unref (impl->recent_model);
9478 impl->recent_model = NULL;
9480 g_object_unref (impl->recent_model_filter);
9481 impl->recent_model_filter = NULL;
9483 g_object_unref (impl->recent_model_sort);
9484 impl->recent_model_sort = NULL;
9487 /* Stops any ongoing loading of the recent files list; does
9488 * not touch the recent_model
9491 recent_stop_loading (GtkFileChooserDefault *impl)
9493 if (impl->load_recent_id)
9495 g_source_remove (impl->load_recent_id);
9496 impl->load_recent_id = 0;
9500 /* Stops any pending load, clears the file list, and switches
9501 * back to OPERATION_MODE_BROWSE
9504 recent_switch_to_browse_mode (GtkFileChooserDefault *impl)
9506 g_assert (impl->operation_mode != OPERATION_MODE_BROWSE);
9508 recent_stop_loading (impl);
9509 recent_clear_model (impl, TRUE);
9511 gtk_widget_show (impl->browse_path_bar);
9512 gtk_widget_show (impl->browse_new_folder_button);
9514 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
9515 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
9517 gtk_widget_show (impl->location_button);
9519 if (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)
9520 gtk_widget_show (impl->location_entry_box);
9523 impl->operation_mode = OPERATION_MODE_BROWSE;
9525 file_list_set_sort_column_ids (impl);
9528 /* Sort callback from the modification time column */
9530 recent_column_mtime_sort_func (GtkTreeModel *model,
9535 GtkFileChooserDefault *impl = user_data;
9536 GtkTreeIter child_a, child_b;
9537 GtkRecentInfo *info_a, *info_b;
9538 gboolean is_folder_a, is_folder_b;
9540 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_a, a);
9541 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_b, b);
9543 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &child_a,
9544 RECENT_MODEL_COL_IS_FOLDER, &is_folder_a,
9545 RECENT_MODEL_COL_INFO, &info_a,
9547 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &child_b,
9548 RECENT_MODEL_COL_IS_FOLDER, &is_folder_b,
9549 RECENT_MODEL_COL_INFO, &info_b,
9558 /* folders always go first */
9559 if (is_folder_a != is_folder_b)
9560 return is_folder_a ? 1 : -1;
9562 if (gtk_recent_info_get_modified (info_a) < gtk_recent_info_get_modified (info_b))
9564 else if (gtk_recent_info_get_modified (info_a) > gtk_recent_info_get_modified (info_b))
9571 recent_column_path_sort_func (GtkTreeModel *model,
9576 GtkFileChooserDefault *impl = user_data;
9577 GtkTreeIter child_a, child_b;
9578 gboolean is_folder_a, is_folder_b;
9579 gchar *name_a, *name_b;
9581 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_a, a);
9582 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_b, b);
9584 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &child_a,
9585 RECENT_MODEL_COL_IS_FOLDER, &is_folder_a,
9586 RECENT_MODEL_COL_DISPLAY_NAME, &name_a,
9588 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &child_b,
9589 RECENT_MODEL_COL_IS_FOLDER, &is_folder_b,
9590 RECENT_MODEL_COL_DISPLAY_NAME, &name_b,
9599 if (is_folder_a != is_folder_b)
9600 return is_folder_a ? 1 : -1;
9602 return strcmp (name_a, name_b);
9606 recent_get_is_filtered (GtkFileChooserDefault *impl,
9607 const GtkFilePath *path,
9608 GtkRecentInfo *recent_info)
9610 GtkFileFilterInfo filter_info;
9611 GtkFileFilterFlags needed;
9614 if (!impl->current_filter)
9617 filter_info.contains = GTK_FILE_FILTER_DISPLAY_NAME | GTK_FILE_FILTER_MIME_TYPE;
9618 needed = gtk_file_filter_get_needed (impl->current_filter);
9620 filter_info.display_name = gtk_recent_info_get_display_name (recent_info);
9621 filter_info.mime_type = gtk_recent_info_get_mime_type (recent_info);
9623 if (needed & GTK_FILE_FILTER_FILENAME)
9625 filter_info.filename = gtk_file_system_path_to_filename (impl->file_system, path);
9626 if (filter_info.filename)
9627 filter_info.contains |= GTK_FILE_FILTER_FILENAME;
9630 filter_info.filename = NULL;
9632 if (needed & GTK_FILE_FILTER_URI)
9634 filter_info.uri = gtk_file_system_path_to_uri (impl->file_system, path);
9635 if (filter_info.uri)
9636 filter_info.contains |= GTK_FILE_FILTER_URI;
9639 filter_info.uri = NULL;
9641 result = gtk_file_filter_filter (impl->current_filter, &filter_info);
9643 if (filter_info.filename)
9644 g_free ((gchar *) filter_info.filename);
9645 if (filter_info.uri)
9646 g_free ((gchar *) filter_info.uri);
9651 /* Visibility function for the recent filter model */
9653 recent_model_visible_func (GtkTreeModel *model,
9657 GtkFileChooserDefault *impl = user_data;
9658 GtkFilePath *file_path;
9659 GtkRecentInfo *recent_info;
9662 if (!impl->current_filter)
9665 gtk_tree_model_get (model, iter,
9666 RECENT_MODEL_COL_INFO, &recent_info,
9667 RECENT_MODEL_COL_PATH, &file_path,
9668 RECENT_MODEL_COL_IS_FOLDER, &is_folder,
9677 return !recent_get_is_filtered (impl, file_path, recent_info);
9681 recent_setup_model (GtkFileChooserDefault *impl)
9683 g_assert (impl->recent_model == NULL);
9684 g_assert (impl->recent_model_filter == NULL);
9685 g_assert (impl->recent_model_sort == NULL);
9687 /* We store these columns in the search model:
9689 * RECENT_MODEL_COL_PATH - a pointer to GtkFilePath for the hit's URI,
9690 * stored as a pointer and not as a GTK_TYPE_FILE_PATH;
9691 * RECENT_MODEL_COL_DISPLAY_NAME - a string with the display name,
9692 * stored as a pointer and not as a G_TYPE_STRING;
9693 * RECENT_MODEL_COL_INFO - GtkRecentInfo, stored as a pointer and not
9694 * as a GTK_TYPE_RECENT_INFO;
9695 * RECENT_MODEL_COL_IS_FOLDER - boolean flag;
9696 * RECENT_MODEL_COL_HANDLE - GtkFileSystemHandle, stored as a pointer
9697 * and not as a GTK_TYPE_FILE_SYSTEM_HANDLE;
9699 * Keep this in sync with the enumeration defined near the beginning of
9702 impl->recent_model = gtk_list_store_new (RECENT_MODEL_COL_NUM_COLUMNS,
9709 impl->recent_model_filter =
9710 GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (GTK_TREE_MODEL (impl->recent_model), NULL));
9711 gtk_tree_model_filter_set_visible_func (impl->recent_model_filter,
9712 recent_model_visible_func,
9716 /* this is the model that will actually be added to
9717 * the browse_files_tree_view widget; remember: we are
9718 * stuffing the real model into a filter model and then
9719 * into a sort model; this means we'll have to translate
9720 * the child iterator *twice* to get from a path or an
9721 * iterator coming from the tree view widget to the
9722 * real data inside the model.
9724 impl->recent_model_sort =
9725 GTK_TREE_MODEL_SORT (recent_model_sort_new (impl, GTK_TREE_MODEL (impl->recent_model_filter)));
9726 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->recent_model_sort),
9727 RECENT_MODEL_COL_PATH,
9728 recent_column_path_sort_func,
9730 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->recent_model_sort),
9731 RECENT_MODEL_COL_INFO,
9732 recent_column_mtime_sort_func,
9734 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (impl->recent_model_sort),
9735 RECENT_MODEL_COL_INFO,
9736 GTK_SORT_DESCENDING);
9741 GtkFileChooserDefault *impl;
9744 gint n_loaded_items;
9745 guint needs_sorting : 1;
9749 recent_idle_cleanup (gpointer data)
9751 RecentLoadData *load_data = data;
9752 GtkFileChooserDefault *impl = load_data->impl;
9754 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view),
9755 GTK_TREE_MODEL (impl->recent_model_sort));
9757 set_busy_cursor (impl, FALSE);
9759 impl->load_recent_id = 0;
9761 if (load_data->items)
9763 g_list_foreach (load_data->items, (GFunc) gtk_recent_info_unref, NULL);
9764 g_list_free (load_data->items);
9770 struct RecentItemInsertRequest
9772 GtkFileChooserDefault *impl;
9774 GtkTreeRowReference *row_ref;
9778 recent_item_get_info_cb (GtkFileSystemHandle *handle,
9779 const GtkFileInfo *info,
9780 const GError *error,
9783 gboolean cancelled = handle->cancelled;
9786 GtkFileSystemHandle *model_handle;
9787 gboolean is_folder = FALSE;
9788 struct RecentItemInsertRequest *request = data;
9790 if (!request->impl->recent_model)
9793 path = gtk_tree_row_reference_get_path (request->row_ref);
9797 gtk_tree_model_get_iter (GTK_TREE_MODEL (request->impl->recent_model),
9799 gtk_tree_path_free (path);
9801 gtk_tree_model_get (GTK_TREE_MODEL (request->impl->recent_model), &iter,
9802 RECENT_MODEL_COL_HANDLE, &model_handle,
9804 if (handle != model_handle)
9807 gtk_list_store_set (request->impl->recent_model, &iter,
9808 RECENT_MODEL_COL_HANDLE, NULL,
9816 gtk_list_store_remove (request->impl->recent_model, &iter);
9820 is_folder = gtk_file_info_get_is_folder (info);
9822 gtk_list_store_set (request->impl->recent_model, &iter,
9823 RECENT_MODEL_COL_IS_FOLDER, is_folder,
9827 g_object_unref (request->impl);
9828 gtk_file_path_free (request->path);
9829 gtk_tree_row_reference_free (request->row_ref);
9832 g_object_unref (handle);
9836 recent_sort_mru (gconstpointer a,
9839 GtkRecentInfo *info_a = (GtkRecentInfo *) a;
9840 GtkRecentInfo *info_b = (GtkRecentInfo *) b;
9842 return (gtk_recent_info_get_modified (info_b) - gtk_recent_info_get_modified (info_a));
9846 get_recent_files_limit (GtkWidget *widget)
9848 GtkSettings *settings;
9851 if (gtk_widget_has_screen (widget))
9852 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9854 settings = gtk_settings_get_default ();
9856 g_object_get (G_OBJECT (settings), "gtk-recent-files-limit", &limit, NULL);
9862 recent_idle_load (gpointer data)
9864 RecentLoadData *load_data = data;
9865 GtkFileChooserDefault *impl = load_data->impl;
9868 GtkRecentInfo *info;
9869 const gchar *uri, *display_name;
9871 GtkFileSystemHandle *handle;
9872 struct RecentItemInsertRequest *request;
9874 if (!impl->recent_manager)
9877 /* first iteration: load all the items */
9878 if (!load_data->items)
9880 load_data->items = gtk_recent_manager_get_items (impl->recent_manager);
9881 if (!load_data->items)
9884 load_data->needs_sorting = TRUE;
9889 /* second iteration: preliminary MRU sorting and clamping */
9890 if (load_data->needs_sorting)
9894 load_data->items = g_list_sort (load_data->items, recent_sort_mru);
9895 load_data->n_items = g_list_length (load_data->items);
9897 limit = get_recent_files_limit (GTK_WIDGET (impl));
9899 if (limit != -1 && (load_data->n_items > limit))
9903 clamp = g_list_nth (load_data->items, limit - 1);
9904 if (G_LIKELY (clamp))
9909 g_list_foreach (l, (GFunc) gtk_recent_info_unref, NULL);
9912 load_data->n_items = limit;
9916 load_data->n_loaded_items = 0;
9917 load_data->needs_sorting = FALSE;
9922 info = g_list_nth_data (load_data->items, load_data->n_loaded_items);
9923 g_assert (info != NULL);
9925 uri = gtk_recent_info_get_uri (info);
9926 display_name = gtk_recent_info_get_display_name (info);
9927 path = gtk_file_system_uri_to_path (impl->file_system, uri);
9931 gtk_list_store_append (impl->recent_model, &iter);
9932 p = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->recent_model), &iter);
9934 request = g_new0 (struct RecentItemInsertRequest, 1);
9935 request->impl = g_object_ref (impl);
9936 request->path = gtk_file_path_copy (path);
9937 request->row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (impl->recent_model), p);
9938 gtk_tree_path_free (p);
9940 handle = gtk_file_system_get_info (impl->file_system, path,
9941 GTK_FILE_INFO_IS_FOLDER,
9942 recent_item_get_info_cb,
9945 gtk_list_store_set (impl->recent_model, &iter,
9946 RECENT_MODEL_COL_PATH, path,
9947 RECENT_MODEL_COL_DISPLAY_NAME, g_strdup (display_name),
9948 RECENT_MODEL_COL_INFO, gtk_recent_info_ref (info),
9949 RECENT_MODEL_COL_HANDLE, handle,
9954 load_data->n_loaded_items += 1;
9956 /* finished loading items */
9957 if (load_data->n_loaded_items == load_data->n_items)
9959 g_list_foreach (load_data->items, (GFunc) gtk_recent_info_unref, NULL);
9960 g_list_free (load_data->items);
9961 load_data->items = NULL;
9970 recent_start_loading (GtkFileChooserDefault *impl)
9972 RecentLoadData *load_data;
9974 recent_stop_loading (impl);
9975 recent_clear_model (impl, TRUE);
9976 recent_setup_model (impl);
9977 set_busy_cursor (impl, TRUE);
9979 if (!impl->recent_manager)
9980 recent_manager_update (impl);
9982 g_assert (impl->load_recent_id == 0);
9984 load_data = g_new (RecentLoadData, 1);
9985 load_data->impl = impl;
9986 load_data->items = NULL;
9987 load_data->n_items = 0;
9988 load_data->n_loaded_items = 0;
9989 load_data->needs_sorting = TRUE;
9991 /* begin lazy loading the recent files into the model */
9992 impl->load_recent_id = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 30,
9995 recent_idle_cleanup);
9999 recent_selected_foreach_get_path_cb (GtkTreeModel *model,
10005 const GtkFilePath *file_path;
10006 GtkFilePath *file_path_copy;
10010 gtk_tree_model_get (model, iter, RECENT_MODEL_COL_PATH, &file_path, -1);
10011 file_path_copy = gtk_file_path_copy (file_path);
10012 *list = g_slist_prepend (*list, file_path_copy);
10015 /* Constructs a list of the selected paths in recent files mode */
10017 recent_get_selected_paths (GtkFileChooserDefault *impl)
10020 GtkTreeSelection *selection;
10024 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
10025 gtk_tree_selection_selected_foreach (selection, recent_selected_foreach_get_path_cb, &result);
10026 result = g_slist_reverse (result);
10031 /* Called from ::should_respond(). We return whether there are selected
10032 * files in the recent files list.
10035 recent_should_respond (GtkFileChooserDefault *impl)
10037 GtkTreeSelection *selection;
10039 g_assert (impl->operation_mode == OPERATION_MODE_RECENT);
10041 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
10042 return (gtk_tree_selection_count_selected_rows (selection) != 0);
10045 /* Hide the location widgets temporarily */
10047 recent_hide_entry (GtkFileChooserDefault *impl)
10049 gtk_widget_hide (impl->browse_path_bar);
10050 gtk_widget_hide (impl->browse_new_folder_button);
10052 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
10053 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
10055 gtk_widget_hide (impl->location_button);
10056 gtk_widget_hide (impl->location_entry_box);
10060 /* Main entry point to the recent files functions; this gets called when
10061 * the user activates the Recently Used shortcut.
10064 recent_activate (GtkFileChooserDefault *impl)
10066 OperationMode previous_mode;
10068 if (impl->operation_mode == OPERATION_MODE_RECENT)
10071 previous_mode = impl->operation_mode;
10072 impl->operation_mode = OPERATION_MODE_RECENT;
10074 switch (previous_mode)
10076 case OPERATION_MODE_SEARCH:
10077 search_stop_searching (impl, FALSE);
10078 search_clear_model (impl, TRUE);
10080 gtk_widget_destroy (impl->search_hbox);
10081 impl->search_hbox = NULL;
10082 impl->search_entry = NULL;
10085 case OPERATION_MODE_BROWSE:
10086 stop_loading_and_clear_list_model (impl);
10089 case OPERATION_MODE_RECENT:
10090 g_assert_not_reached ();
10094 recent_hide_entry (impl);
10095 file_list_set_sort_column_ids (impl);
10096 recent_start_loading (impl);
10099 /* convert an iterator coming from the model bound to
10100 * browse_files_tree_view to an interator inside the
10101 * real recent_model
10104 recent_get_valid_child_iter (GtkFileChooserDefault *impl,
10105 GtkTreeIter *child_iter,
10108 GtkTreeIter middle;
10110 if (!impl->recent_model)
10113 if (!impl->recent_model_filter || !impl->recent_model_sort)
10116 /* pass 1: get the iterator in the filter model */
10117 gtk_tree_model_sort_convert_iter_to_child_iter (impl->recent_model_sort,
10120 /* pass 2: get the iterator in the real model */
10121 gtk_tree_model_filter_convert_iter_to_child_iter (impl->recent_model_filter,
10128 set_current_filter (GtkFileChooserDefault *impl,
10129 GtkFileFilter *filter)
10131 if (impl->current_filter != filter)
10135 /* NULL filters are allowed to reset to non-filtered status
10137 filter_index = g_slist_index (impl->filters, filter);
10138 if (impl->filters && filter && filter_index < 0)
10141 if (impl->current_filter)
10142 g_object_unref (impl->current_filter);
10143 impl->current_filter = filter;
10144 if (impl->current_filter)
10146 g_object_ref_sink (impl->current_filter);
10150 gtk_combo_box_set_active (GTK_COMBO_BOX (impl->filter_combo),
10153 if (impl->browse_files_model)
10154 install_list_model_filter (impl);
10156 if (impl->search_model_filter)
10157 gtk_tree_model_filter_refilter (impl->search_model_filter);
10159 if (impl->recent_model_filter)
10160 gtk_tree_model_filter_refilter (impl->recent_model_filter);
10162 g_object_notify (G_OBJECT (impl), "filter");
10167 filter_combo_changed (GtkComboBox *combo_box,
10168 GtkFileChooserDefault *impl)
10170 gint new_index = gtk_combo_box_get_active (combo_box);
10171 GtkFileFilter *new_filter = g_slist_nth_data (impl->filters, new_index);
10173 set_current_filter (impl, new_filter);
10177 check_preview_change (GtkFileChooserDefault *impl)
10179 GtkTreePath *cursor_path;
10180 const GtkFilePath *new_path;
10181 const char *new_display_name;
10183 gtk_tree_view_get_cursor (GTK_TREE_VIEW (impl->browse_files_tree_view), &cursor_path, NULL);
10185 new_display_name = NULL;
10188 GtkTreeIter child_iter;
10190 if (impl->operation_mode == OPERATION_MODE_BROWSE)
10192 if (impl->sort_model)
10195 const GtkFileInfo *new_info;
10197 gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->sort_model), &iter, cursor_path);
10198 gtk_tree_path_free (cursor_path);
10200 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model, &child_iter, &iter);
10202 new_path = _gtk_file_system_model_get_path (impl->browse_files_model, &child_iter);
10203 new_info = _gtk_file_system_model_get_info (impl->browse_files_model, &child_iter);
10205 new_display_name = gtk_file_info_get_display_name (new_info);
10208 else if (impl->operation_mode == OPERATION_MODE_SEARCH)
10212 gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->search_model_sort),
10213 &iter, cursor_path);
10214 gtk_tree_path_free (cursor_path);
10216 search_get_valid_child_iter (impl, &child_iter, &iter);
10217 gtk_tree_model_get (GTK_TREE_MODEL (impl->search_model), &child_iter,
10218 SEARCH_MODEL_COL_PATH, &new_path,
10219 SEARCH_MODEL_COL_DISPLAY_NAME, &new_display_name,
10222 else if (impl->operation_mode == OPERATION_MODE_RECENT)
10226 gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->recent_model_sort),
10227 &iter, cursor_path);
10228 gtk_tree_path_free (cursor_path);
10230 recent_get_valid_child_iter (impl, &child_iter, &iter);
10231 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &child_iter,
10232 RECENT_MODEL_COL_PATH, &new_path,
10233 RECENT_MODEL_COL_DISPLAY_NAME, &new_display_name,
10238 if (new_path != impl->preview_path &&
10239 !(new_path && impl->preview_path &&
10240 gtk_file_path_compare (new_path, impl->preview_path) == 0))
10242 if (impl->preview_path)
10244 gtk_file_path_free (impl->preview_path);
10245 g_free (impl->preview_display_name);
10250 impl->preview_path = gtk_file_path_copy (new_path);
10251 impl->preview_display_name = g_strdup (new_display_name);
10255 impl->preview_path = NULL;
10256 impl->preview_display_name = NULL;
10259 if (impl->use_preview_label && impl->preview_label)
10260 gtk_label_set_text (GTK_LABEL (impl->preview_label), impl->preview_display_name);
10262 g_signal_emit_by_name (impl, "update-preview");
10267 shortcuts_activate_volume_mount_cb (GtkFileSystemHandle *handle,
10268 GtkFileSystemVolume *volume,
10269 const GError *error,
10273 gboolean cancelled = handle->cancelled;
10274 GtkFileChooserDefault *impl = data;
10276 if (handle != impl->shortcuts_activate_iter_handle)
10279 impl->shortcuts_activate_iter_handle = NULL;
10281 set_busy_cursor (impl, FALSE);
10290 msg = g_strdup_printf (_("Could not mount %s"),
10291 gtk_file_system_volume_get_display_name (impl->file_system, volume));
10292 error_message (impl, msg, error->message);
10298 path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
10301 change_folder_and_display_error (impl, path, FALSE);
10303 gtk_file_path_free (path);
10307 g_object_unref (impl);
10308 g_object_unref (handle);
10312 /* Activates a volume by mounting it if necessary and then switching to its
10316 shortcuts_activate_volume (GtkFileChooserDefault *impl,
10317 GtkFileSystemVolume *volume)
10321 switch (impl->operation_mode)
10323 case OPERATION_MODE_BROWSE:
10325 case OPERATION_MODE_SEARCH:
10326 search_switch_to_browse_mode (impl);
10328 case OPERATION_MODE_RECENT:
10329 recent_switch_to_browse_mode (impl);
10333 /* We ref the file chooser since volume_mount() may run a main loop, and the
10334 * user could close the file chooser window in the meantime.
10336 g_object_ref (impl);
10338 if (!gtk_file_system_volume_get_is_mounted (impl->file_system, volume))
10340 set_busy_cursor (impl, TRUE);
10342 impl->shortcuts_activate_iter_handle =
10343 gtk_file_system_volume_mount (impl->file_system, volume,
10344 shortcuts_activate_volume_mount_cb,
10345 g_object_ref (impl));
10349 path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
10352 change_folder_and_display_error (impl, path, FALSE);
10353 gtk_file_path_free (path);
10357 g_object_unref (impl);
10360 /* Opens the folder or volume at the specified iter in the shortcuts model */
10361 struct ShortcutsActivateData
10363 GtkFileChooserDefault *impl;
10368 shortcuts_activate_get_info_cb (GtkFileSystemHandle *handle,
10369 const GtkFileInfo *info,
10370 const GError *error,
10371 gpointer user_data)
10373 gboolean cancelled = handle->cancelled;
10374 struct ShortcutsActivateData *data = user_data;
10376 if (handle != data->impl->shortcuts_activate_iter_handle)
10379 data->impl->shortcuts_activate_iter_handle = NULL;
10384 if (!error && gtk_file_info_get_is_folder (info))
10385 change_folder_and_display_error (data->impl, data->path, FALSE);
10387 gtk_file_chooser_default_select_path (GTK_FILE_CHOOSER (data->impl),
10392 g_object_unref (data->impl);
10393 gtk_file_path_free (data->path);
10396 g_object_unref (handle);
10400 shortcuts_activate_iter (GtkFileChooserDefault *impl,
10404 ShortcutType shortcut_type;
10406 if (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY && impl->action != GTK_FILE_CHOOSER_ACTION_SAVE)
10407 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), "");
10409 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), iter,
10410 SHORTCUTS_COL_DATA, &col_data,
10411 SHORTCUTS_COL_TYPE, &shortcut_type,
10414 if (impl->shortcuts_activate_iter_handle)
10416 gtk_file_system_cancel_operation (impl->shortcuts_activate_iter_handle);
10417 impl->shortcuts_activate_iter_handle = NULL;
10420 if (shortcut_type == SHORTCUT_TYPE_SEPARATOR)
10422 else if (shortcut_type == SHORTCUT_TYPE_VOLUME)
10424 GtkFileSystemVolume *volume;
10428 shortcuts_activate_volume (impl, volume);
10430 else if (shortcut_type == SHORTCUT_TYPE_PATH)
10432 struct ShortcutsActivateData *data;
10434 data = g_new0 (struct ShortcutsActivateData, 1);
10435 data->impl = g_object_ref (impl);
10436 data->path = gtk_file_path_copy (col_data);
10438 impl->shortcuts_activate_iter_handle =
10439 gtk_file_system_get_info (impl->file_system, data->path,
10440 GTK_FILE_INFO_IS_FOLDER,
10441 shortcuts_activate_get_info_cb, data);
10443 else if (shortcut_type == SHORTCUT_TYPE_SEARCH)
10445 search_activate (impl);
10447 else if (shortcut_type == SHORTCUT_TYPE_RECENT)
10449 recent_activate (impl);
10453 /* Handler for GtkWidget::key-press-event on the shortcuts list */
10455 shortcuts_key_press_event_cb (GtkWidget *widget,
10456 GdkEventKey *event,
10457 GtkFileChooserDefault *impl)
10461 modifiers = gtk_accelerator_get_default_mod_mask ();
10463 if ((event->keyval == GDK_BackSpace
10464 || event->keyval == GDK_Delete
10465 || event->keyval == GDK_KP_Delete)
10466 && (event->state & modifiers) == 0)
10468 remove_selected_bookmarks (impl);
10472 if ((event->keyval == GDK_F2)
10473 && (event->state & modifiers) == 0)
10475 rename_selected_bookmark (impl);
10483 shortcuts_select_func (GtkTreeSelection *selection,
10484 GtkTreeModel *model,
10486 gboolean path_currently_selected,
10489 GtkFileChooserDefault *impl = data;
10490 GtkTreeIter filter_iter;
10491 ShortcutType shortcut_type;
10493 if (!gtk_tree_model_get_iter (impl->shortcuts_pane_filter_model, &filter_iter, path))
10494 g_assert_not_reached ();
10496 gtk_tree_model_get (impl->shortcuts_pane_filter_model, &filter_iter, SHORTCUTS_COL_TYPE, &shortcut_type, -1);
10498 return shortcut_type != SHORTCUT_TYPE_SEPARATOR;
10502 list_select_func (GtkTreeSelection *selection,
10503 GtkTreeModel *model,
10505 gboolean path_currently_selected,
10508 GtkFileChooserDefault *impl = data;
10510 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
10511 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
10513 GtkTreeIter iter, child_iter;
10515 switch (impl->operation_mode)
10517 case OPERATION_MODE_SEARCH:
10519 gboolean is_folder;
10521 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->search_model_sort), &iter, path))
10524 search_get_valid_child_iter (impl, &child_iter, &iter);
10525 gtk_tree_model_get (GTK_TREE_MODEL (impl->search_model), &child_iter,
10526 SEARCH_MODEL_COL_IS_FOLDER, &is_folder,
10533 case OPERATION_MODE_RECENT:
10535 gboolean is_folder;
10537 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->recent_model_sort), &iter, path))
10540 recent_get_valid_child_iter (impl, &child_iter, &iter);
10541 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &child_iter,
10542 RECENT_MODEL_COL_IS_FOLDER, &is_folder,
10549 case OPERATION_MODE_BROWSE:
10551 const GtkFileInfo *info;
10553 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->sort_model), &iter, path))
10556 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model, &child_iter, &iter);
10557 info = _gtk_file_system_model_get_info (impl->browse_files_model, &child_iter);
10558 if (info && !gtk_file_info_get_is_folder (info))
10569 list_selection_changed (GtkTreeSelection *selection,
10570 GtkFileChooserDefault *impl)
10572 /* See if we are in the new folder editable row for Save mode */
10573 if (impl->operation_mode == OPERATION_MODE_BROWSE &&
10574 impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
10576 const GtkFileInfo *info;
10577 gboolean had_selection;
10579 info = get_selected_file_info_from_file_list (impl, &had_selection);
10580 if (!had_selection)
10581 goto out; /* normal processing */
10584 return; /* We are on the editable row for New Folder */
10589 if (impl->location_entry)
10590 update_chooser_entry (impl);
10592 check_preview_change (impl);
10593 bookmarks_check_add_sensitivity (impl);
10595 g_signal_emit_by_name (impl, "selection-changed", 0);
10598 /* Callback used when a row in the file list is activated */
10600 list_row_activated (GtkTreeView *tree_view,
10602 GtkTreeViewColumn *column,
10603 GtkFileChooserDefault *impl)
10606 GtkTreeIter child_iter;
10608 switch (impl->operation_mode)
10610 case OPERATION_MODE_SEARCH:
10612 GtkFilePath *file_path;
10613 gboolean is_folder;
10615 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->search_model_sort), &iter, path))
10618 search_get_valid_child_iter (impl, &child_iter, &iter);
10619 gtk_tree_model_get (GTK_TREE_MODEL (impl->search_model), &child_iter,
10620 SEARCH_MODEL_COL_PATH, &file_path,
10621 SEARCH_MODEL_COL_IS_FOLDER, &is_folder,
10626 change_folder_and_display_error (impl, file_path, FALSE);
10630 g_signal_emit_by_name (impl, "file-activated");
10634 case OPERATION_MODE_RECENT:
10636 GtkFilePath *file_path;
10637 gboolean is_folder;
10639 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->recent_model_sort), &iter, path))
10642 recent_get_valid_child_iter (impl, &child_iter, &iter);
10643 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &child_iter,
10644 RECENT_MODEL_COL_PATH, &file_path,
10645 RECENT_MODEL_COL_IS_FOLDER, &is_folder,
10650 change_folder_and_display_error (impl, file_path, FALSE);
10654 g_signal_emit_by_name (impl, "file-activated");
10658 case OPERATION_MODE_BROWSE:
10660 const GtkFileInfo *info;
10662 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->sort_model), &iter, path))
10665 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
10666 &child_iter, &iter);
10667 info = _gtk_file_system_model_get_info (impl->browse_files_model,
10670 if (gtk_file_info_get_is_folder (info))
10672 const GtkFilePath *file_path;
10674 file_path = _gtk_file_system_model_get_path (impl->browse_files_model, &child_iter);
10675 change_folder_and_display_error (impl, file_path, FALSE);
10679 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
10680 impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
10681 g_signal_emit_by_name (impl, "file-activated");
10688 path_bar_clicked (GtkPathBar *path_bar,
10689 GtkFilePath *file_path,
10690 GtkFilePath *child_path,
10691 gboolean child_is_hidden,
10692 GtkFileChooserDefault *impl)
10695 pending_select_paths_add (impl, child_path);
10697 if (!change_folder_and_display_error (impl, file_path, FALSE))
10700 /* Say we have "/foo/bar/[.baz]" and the user clicks on "bar". We should then
10701 * show hidden files so that ".baz" appears in the file list, as it will still
10702 * be shown in the path bar: "/foo/[bar]/.baz"
10704 if (child_is_hidden)
10705 g_object_set (impl, "show-hidden", TRUE, NULL);
10708 static const GtkFileInfo *
10709 get_list_file_info (GtkFileChooserDefault *impl,
10712 GtkTreeIter child_iter;
10714 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
10718 return _gtk_file_system_model_get_info (impl->browse_files_model, &child_iter);
10722 list_icon_data_func (GtkTreeViewColumn *tree_column,
10723 GtkCellRenderer *cell,
10724 GtkTreeModel *tree_model,
10728 GtkFileChooserDefault *impl = data;
10729 GtkTreeIter child_iter;
10730 GdkPixbuf *pixbuf = NULL;
10731 gboolean sensitive = TRUE;
10733 profile_start ("start", NULL);
10735 switch (impl->operation_mode)
10737 case OPERATION_MODE_SEARCH:
10739 GtkTreeIter child_iter;
10740 gboolean is_folder;
10742 search_get_valid_child_iter (impl, &child_iter, iter);
10743 gtk_tree_model_get (GTK_TREE_MODEL (impl->search_model), &child_iter,
10744 SEARCH_MODEL_COL_PIXBUF, &pixbuf,
10745 SEARCH_MODEL_COL_IS_FOLDER, &is_folder,
10748 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
10749 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
10750 sensitive = is_folder;
10754 case OPERATION_MODE_RECENT:
10756 GtkTreeIter child_iter;
10757 GtkRecentInfo *info;
10758 gboolean is_folder;
10760 recent_get_valid_child_iter (impl, &child_iter, iter);
10761 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &child_iter,
10762 RECENT_MODEL_COL_INFO, &info,
10763 RECENT_MODEL_COL_IS_FOLDER, &is_folder,
10766 pixbuf = gtk_recent_info_get_icon (info, impl->icon_size);
10768 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
10769 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
10770 sensitive = is_folder;
10774 case OPERATION_MODE_BROWSE:
10776 const GtkFileInfo *info;
10777 const GtkFilePath *path;
10779 info = get_list_file_info (impl, iter);
10781 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
10784 path = _gtk_file_system_model_get_path (impl->browse_files_model, &child_iter);
10789 /* FIXME: NULL GError */
10790 pixbuf = gtk_file_info_render_icon (info, GTK_WIDGET (impl),
10791 impl->icon_size, NULL);
10796 /* We are on the editable row */
10801 (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
10802 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER))
10803 sensitive = gtk_file_info_get_is_folder (info);
10808 g_object_set (cell,
10810 "sensitive", sensitive,
10814 g_object_unref (pixbuf);
10816 profile_end ("end", NULL);
10820 list_name_data_func (GtkTreeViewColumn *tree_column,
10821 GtkCellRenderer *cell,
10822 GtkTreeModel *tree_model,
10826 GtkFileChooserDefault *impl = data;
10827 const GtkFileInfo *info;
10828 gboolean sensitive = TRUE;
10830 if (impl->operation_mode == OPERATION_MODE_SEARCH)
10832 GtkTreeIter child_iter;
10833 gchar *display_name;
10834 gboolean is_folder;
10836 search_get_valid_child_iter (impl, &child_iter, iter);
10837 gtk_tree_model_get (GTK_TREE_MODEL (impl->search_model), &child_iter,
10838 SEARCH_MODEL_COL_DISPLAY_NAME, &display_name,
10839 SEARCH_MODEL_COL_IS_FOLDER, &is_folder,
10842 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
10843 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
10845 sensitive = is_folder;
10848 g_object_set (cell,
10849 "text", display_name,
10850 "sensitive", sensitive,
10851 "ellipsize", PANGO_ELLIPSIZE_END,
10857 if (impl->operation_mode == OPERATION_MODE_RECENT)
10859 GtkTreeIter child_iter;
10860 GtkRecentInfo *recent_info;
10861 gchar *display_name;
10862 gboolean is_folder;
10864 recent_get_valid_child_iter (impl, &child_iter, iter);
10865 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &child_iter,
10866 RECENT_MODEL_COL_INFO, &recent_info,
10867 RECENT_MODEL_COL_IS_FOLDER, &is_folder,
10870 display_name = gtk_recent_info_get_short_name (recent_info);
10872 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
10873 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
10875 sensitive = is_folder;
10878 g_object_set (cell,
10879 "text", display_name,
10880 "sensitive", sensitive,
10881 "ellipsize", PANGO_ELLIPSIZE_END,
10884 g_free (display_name);
10889 info = get_list_file_info (impl, iter);
10894 g_object_set (cell,
10895 "text", _("Type name of new folder"),
10897 "ellipsize", PANGO_ELLIPSIZE_NONE,
10904 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
10905 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
10907 sensitive = gtk_file_info_get_is_folder (info);
10910 g_object_set (cell,
10911 "text", gtk_file_info_get_display_name (info),
10912 "sensitive", sensitive,
10913 "ellipsize", PANGO_ELLIPSIZE_END,
10919 list_size_data_func (GtkTreeViewColumn *tree_column,
10920 GtkCellRenderer *cell,
10921 GtkTreeModel *tree_model,
10925 GtkFileChooserDefault *impl = data;
10926 const GtkFileInfo *info = get_list_file_info (impl, iter);
10929 gboolean sensitive = TRUE;
10931 if (!info || gtk_file_info_get_is_folder (info))
10933 g_object_set (cell,
10935 "sensitive", sensitive,
10940 size = gtk_file_info_get_size (info);
10942 if (size < (gint64)1024)
10943 str = g_strdup_printf (ngettext ("%d byte", "%d bytes", (gint)size), (gint)size);
10944 else if (size < (gint64)1024*1024)
10945 str = g_strdup_printf (_("%.1f KB"), size / (1024.));
10946 else if (size < (gint64)1024*1024*1024)
10947 str = g_strdup_printf (_("%.1f MB"), size / (1024.*1024.));
10949 str = g_strdup_printf (_("%.1f GB"), size / (1024.*1024.*1024.));
10951 str = g_strdup_printf ("%" G_GINT64_FORMAT, size);
10952 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
10953 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
10956 g_object_set (cell,
10958 "sensitive", sensitive,
10959 "alignment", PANGO_ALIGN_RIGHT,
10966 /* Tree column data callback for the file list; fetches the mtime of a file */
10968 list_mtime_data_func (GtkTreeViewColumn *tree_column,
10969 GtkCellRenderer *cell,
10970 GtkTreeModel *tree_model,
10974 GtkFileChooserDefault *impl;
10976 gchar *date_str = NULL;
10977 gboolean sensitive = TRUE;
10979 const char *locale, *dot = NULL;
10980 gint64 codepage = -1;
10986 if (impl->operation_mode == OPERATION_MODE_SEARCH)
10988 GtkTreeIter child_iter;
10989 struct stat *statbuf;
10990 gboolean is_folder;
10992 search_get_valid_child_iter (impl, &child_iter, iter);
10993 gtk_tree_model_get (GTK_TREE_MODEL (impl->search_model), &child_iter,
10994 SEARCH_MODEL_COL_STAT, &statbuf,
10995 SEARCH_MODEL_COL_IS_FOLDER, &is_folder,
10998 time_mtime = statbuf->st_mtime;
11003 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
11004 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
11005 sensitive = is_folder;
11007 else if (impl->operation_mode == OPERATION_MODE_RECENT)
11009 GtkTreeIter child_iter;
11010 GtkRecentInfo *info;
11011 gboolean is_folder;
11013 recent_get_valid_child_iter (impl, &child_iter, iter);
11014 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &child_iter,
11015 RECENT_MODEL_COL_INFO, &info,
11016 RECENT_MODEL_COL_IS_FOLDER, &is_folder,
11020 time_mtime = gtk_recent_info_get_modified (info);
11024 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
11025 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
11026 sensitive = is_folder;
11030 const GtkFileInfo *info;
11032 info = get_list_file_info (impl, iter);
11035 g_object_set (cell,
11042 time_mtime = (time_t) gtk_file_info_get_modification_time (info);
11044 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
11045 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
11046 sensitive = gtk_file_info_get_is_folder (info);
11049 if (G_UNLIKELY (time_mtime == 0))
11050 date_str = g_strdup (_("Unknown"));
11055 struct tm tm_mtime;
11057 const gchar *format;
11058 gchar *locale_format = NULL;
11061 #ifdef HAVE_LOCALTIME_R
11062 localtime_r ((time_t *) &time_mtime, &tm_mtime);
11065 struct tm *ptm = localtime ((time_t *) &time_mtime);
11069 g_warning ("ptm != NULL failed");
11071 g_object_set (cell,
11072 "text", _("Unknown"),
11073 "sensitive", sensitive,
11078 memcpy ((void *) &tm_mtime, (void *) ptm, sizeof (struct tm));
11080 #endif /* HAVE_LOCALTIME_R */
11082 g_date_set_time_t (&mtime, time_mtime);
11083 time_now = time (NULL);
11084 g_date_set_time_t (&now, time_now);
11086 days_diff = g_date_get_julian (&now) - g_date_get_julian (&mtime);
11088 /* Translators: %H means "hours" and %M means "minutes" */
11089 if (days_diff == 0)
11090 format = _("%H:%M");
11091 else if (days_diff == 1)
11092 format = _("Yesterday at %H:%M");
11095 if (days_diff > 1 && days_diff < 7)
11096 format = "%A"; /* Days from last week */
11098 format = "%x"; /* Any other date */
11102 /* g_locale_from_utf8() returns a string in the system
11103 * code-page, which is not always the same as that used by the C
11104 * library. For instance when running a GTK+ program with
11105 * LANG=ko on an English version of Windows, the system
11106 * code-page is 1252, but the code-page used by the C library is
11107 * 949. (It's GTK+ itself that sets the C library locale when it
11108 * notices the LANG environment variable. See gtkmain.c The
11109 * Microsoft C library doesn't look at any locale environment
11110 * variables.) We need to pass strftime() a string in the C
11111 * library's code-page. See bug #509885.
11113 locale = setlocale (LC_ALL, NULL);
11114 if (locale != NULL)
11115 dot = strchr (locale, '.');
11118 codepage = g_ascii_strtoll (dot+1, NULL, 10);
11120 /* All codepages should fit in 16 bits AFAIK */
11121 if (codepage > 0 && codepage < 65536)
11123 sprintf (charset, "CP%u", (guint) codepage);
11124 locale_format = g_convert (format, -1, charset, "UTF-8", NULL, NULL, NULL);
11128 locale_format = g_locale_from_utf8 (format, -1, NULL, NULL, NULL);
11130 if (locale_format != NULL &&
11131 strftime (buf, sizeof (buf), locale_format, &tm_mtime) != 0)
11134 /* As above but in opposite direction... */
11135 if (codepage > 0 && codepage < 65536)
11136 date_str = g_convert (buf, -1, "UTF-8", charset, NULL, NULL, NULL);
11138 date_str = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
11142 if (date_str == NULL)
11143 date_str = g_strdup (_("Unknown"));
11145 g_free (locale_format);
11148 g_object_set (cell,
11150 "sensitive", sensitive,
11156 _gtk_file_chooser_default_new (const char *file_system)
11158 return g_object_new (GTK_TYPE_FILE_CHOOSER_DEFAULT,
11159 "file-system-backend", file_system,
11164 location_set_user_text (GtkFileChooserDefault *impl,
11167 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), path);
11168 gtk_editable_set_position (GTK_EDITABLE (impl->location_entry), -1);
11172 location_popup_handler (GtkFileChooserDefault *impl,
11175 if (impl->operation_mode != OPERATION_MODE_BROWSE)
11177 GtkWidget *widget_to_focus;
11179 /* This will give us the location widgets back */
11180 switch (impl->operation_mode)
11182 case OPERATION_MODE_SEARCH:
11183 search_switch_to_browse_mode (impl);
11185 case OPERATION_MODE_RECENT:
11186 recent_switch_to_browse_mode (impl);
11188 case OPERATION_MODE_BROWSE:
11189 g_assert_not_reached ();
11193 if (impl->current_folder)
11194 change_folder_and_display_error (impl, impl->current_folder, FALSE);
11196 if (impl->location_mode == LOCATION_MODE_PATH_BAR)
11197 widget_to_focus = impl->browse_files_tree_view;
11199 widget_to_focus = impl->location_entry;
11201 gtk_widget_grab_focus (widget_to_focus);
11205 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
11206 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
11208 LocationMode new_mode;
11212 /* since the user typed something, we unconditionally want to turn on the entry */
11213 new_mode = LOCATION_MODE_FILENAME_ENTRY;
11215 else if (impl->location_mode == LOCATION_MODE_PATH_BAR)
11216 new_mode = LOCATION_MODE_FILENAME_ENTRY;
11217 else if (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)
11218 new_mode = LOCATION_MODE_PATH_BAR;
11221 g_assert_not_reached ();
11225 location_mode_set (impl, new_mode, TRUE);
11226 if (new_mode == LOCATION_MODE_FILENAME_ENTRY)
11229 location_set_user_text (impl, path);
11232 location_entry_set_initial_text (impl);
11233 gtk_editable_select_region (GTK_EDITABLE (impl->location_entry), 0, -1);
11237 else if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
11238 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
11240 gtk_widget_grab_focus (impl->location_entry);
11242 location_set_user_text (impl, path);
11245 g_assert_not_reached ();
11248 /* Handler for the "up-folder" keybinding signal */
11250 up_folder_handler (GtkFileChooserDefault *impl)
11252 _gtk_path_bar_up (GTK_PATH_BAR (impl->browse_path_bar));
11255 /* Handler for the "down-folder" keybinding signal */
11257 down_folder_handler (GtkFileChooserDefault *impl)
11259 _gtk_path_bar_down (GTK_PATH_BAR (impl->browse_path_bar));
11262 /* Switches to the shortcut in the specified index */
11264 switch_to_shortcut (GtkFileChooserDefault *impl,
11269 if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos))
11270 g_assert_not_reached ();
11272 shortcuts_activate_iter (impl, &iter);
11275 /* Handler for the "home-folder" keybinding signal */
11277 home_folder_handler (GtkFileChooserDefault *impl)
11279 if (impl->has_home)
11280 switch_to_shortcut (impl, shortcuts_get_index (impl, SHORTCUTS_HOME));
11283 /* Handler for the "desktop-folder" keybinding signal */
11285 desktop_folder_handler (GtkFileChooserDefault *impl)
11287 if (impl->has_desktop)
11288 switch_to_shortcut (impl, shortcuts_get_index (impl, SHORTCUTS_DESKTOP));
11291 /* Handler for the "search-shortcut" keybinding signal */
11293 search_shortcut_handler (GtkFileChooserDefault *impl)
11295 if (impl->has_search)
11297 switch_to_shortcut (impl, shortcuts_get_index (impl, SHORTCUTS_SEARCH));
11299 /* we want the entry widget to grab the focus the first
11300 * time, not the browse_files_tree_view widget.
11302 if (impl->search_entry)
11303 gtk_widget_grab_focus (impl->search_entry);
11307 /* Handler for the "recent-shortcut" keybinding signal */
11309 recent_shortcut_handler (GtkFileChooserDefault *impl)
11311 if (impl->has_recent)
11312 switch_to_shortcut (impl, shortcuts_get_index (impl, SHORTCUTS_RECENT));
11316 quick_bookmark_handler (GtkFileChooserDefault *impl,
11317 gint bookmark_index)
11322 if (bookmark_index < 0 || bookmark_index >= impl->num_bookmarks)
11325 bookmark_pos = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS) + bookmark_index;
11327 path = gtk_tree_path_new_from_indices (bookmark_pos, -1);
11328 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view),
11331 gtk_tree_path_free (path);
11333 switch_to_shortcut (impl, bookmark_pos);
11337 show_hidden_handler (GtkFileChooserDefault *impl)
11339 g_object_set (impl,
11340 "show-hidden", !impl->show_hidden,
11345 /* Drag and drop interfaces */
11348 _shortcuts_pane_model_filter_class_init (ShortcutsPaneModelFilterClass *class)
11353 _shortcuts_pane_model_filter_init (ShortcutsPaneModelFilter *model)
11355 model->impl = NULL;
11358 /* GtkTreeDragSource::row_draggable implementation for the shortcuts filter model */
11360 shortcuts_pane_model_filter_row_draggable (GtkTreeDragSource *drag_source,
11363 ShortcutsPaneModelFilter *model;
11367 model = SHORTCUTS_PANE_MODEL_FILTER (drag_source);
11369 pos = *gtk_tree_path_get_indices (path);
11370 bookmarks_pos = shortcuts_get_index (model->impl, SHORTCUTS_BOOKMARKS);
11372 return (pos >= bookmarks_pos && pos < bookmarks_pos + model->impl->num_bookmarks);
11375 /* GtkTreeDragSource::drag_data_get implementation for the shortcuts filter model */
11377 shortcuts_pane_model_filter_drag_data_get (GtkTreeDragSource *drag_source,
11379 GtkSelectionData *selection_data)
11381 ShortcutsPaneModelFilter *model;
11383 model = SHORTCUTS_PANE_MODEL_FILTER (drag_source);
11390 /* Fill the GtkTreeDragSourceIface vtable */
11392 shortcuts_pane_model_filter_drag_source_iface_init (GtkTreeDragSourceIface *iface)
11394 iface->row_draggable = shortcuts_pane_model_filter_row_draggable;
11395 iface->drag_data_get = shortcuts_pane_model_filter_drag_data_get;
11399 /* Fill the GtkTreeDragDestIface vtable */
11401 shortcuts_pane_model_filter_drag_dest_iface_init (GtkTreeDragDestIface *iface)
11403 iface->drag_data_received = shortcuts_pane_model_filter_drag_data_received;
11404 iface->row_drop_possible = shortcuts_pane_model_filter_row_drop_possible;
11408 static GtkTreeModel *
11409 shortcuts_pane_model_filter_new (GtkFileChooserDefault *impl,
11410 GtkTreeModel *child_model,
11413 ShortcutsPaneModelFilter *model;
11415 model = g_object_new (SHORTCUTS_PANE_MODEL_FILTER_TYPE,
11416 "child-model", child_model,
11417 "virtual-root", root,
11420 model->impl = impl;
11422 return GTK_TREE_MODEL (model);
11428 recent_model_sort_row_draggable (GtkTreeDragSource *drag_source,
11431 RecentModelSort *model;
11432 GtkTreeIter iter, child_iter;
11433 gboolean is_folder;
11435 model = RECENT_MODEL_SORT (drag_source);
11436 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path))
11439 recent_get_valid_child_iter (model->impl, &child_iter, &iter);
11440 gtk_tree_model_get (GTK_TREE_MODEL (model->impl->recent_model), &child_iter,
11441 RECENT_MODEL_COL_IS_FOLDER, &is_folder,
11448 recent_model_sort_drag_data_get (GtkTreeDragSource *drag_source,
11450 GtkSelectionData *selection_data)
11452 RecentModelSort *model;
11453 GtkTreeIter iter, child_iter;
11454 GtkFilePath *file_path;
11457 model = RECENT_MODEL_SORT (drag_source);
11458 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path))
11461 recent_get_valid_child_iter (model->impl, &child_iter, &iter);
11462 gtk_tree_model_get (GTK_TREE_MODEL (model->impl->recent_model), &child_iter,
11463 RECENT_MODEL_COL_PATH, &file_path,
11465 g_assert (file_path != NULL);
11467 uris[0] = gtk_file_system_path_to_uri (model->impl->file_system, file_path);
11470 gtk_selection_data_set_uris (selection_data, uris);
11478 recent_model_sort_drag_source_iface_init (GtkTreeDragSourceIface *iface)
11480 iface->row_draggable = recent_model_sort_row_draggable;
11481 iface->drag_data_get = recent_model_sort_drag_data_get;
11485 _recent_model_sort_class_init (RecentModelSortClass *klass)
11491 _recent_model_sort_init (RecentModelSort *model)
11493 model->impl = NULL;
11496 static GtkTreeModel *
11497 recent_model_sort_new (GtkFileChooserDefault *impl,
11498 GtkTreeModel *child_model)
11500 RecentModelSort *model;
11502 model = g_object_new (RECENT_MODEL_SORT_TYPE,
11503 "model", child_model,
11505 model->impl = impl;
11507 return GTK_TREE_MODEL (model);
11513 search_model_sort_row_draggable (GtkTreeDragSource *drag_source,
11516 SearchModelSort *model;
11517 GtkTreeIter iter, child_iter;
11518 gboolean is_folder;
11520 model = SEARCH_MODEL_SORT (drag_source);
11521 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path))
11524 search_get_valid_child_iter (model->impl, &child_iter, &iter);
11525 gtk_tree_model_get (GTK_TREE_MODEL (model->impl->search_model), &child_iter,
11526 SEARCH_MODEL_COL_IS_FOLDER, &is_folder,
11533 search_model_sort_drag_data_get (GtkTreeDragSource *drag_source,
11535 GtkSelectionData *selection_data)
11537 SearchModelSort *model;
11538 GtkTreeIter iter, child_iter;
11539 GtkFilePath *file_path;
11542 model = SEARCH_MODEL_SORT (drag_source);
11543 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path))
11546 search_get_valid_child_iter (model->impl, &child_iter, &iter);
11547 gtk_tree_model_get (GTK_TREE_MODEL (model->impl->search_model), &child_iter,
11548 RECENT_MODEL_COL_PATH, &file_path,
11550 g_assert (file_path != NULL);
11552 uris[0] = gtk_file_system_path_to_uri (model->impl->file_system, file_path);
11555 gtk_selection_data_set_uris (selection_data, uris);
11563 search_model_sort_drag_source_iface_init (GtkTreeDragSourceIface *iface)
11565 iface->row_draggable = search_model_sort_row_draggable;
11566 iface->drag_data_get = search_model_sort_drag_data_get;
11570 _search_model_sort_class_init (SearchModelSortClass *klass)
11576 _search_model_sort_init (SearchModelSort *model)
11578 model->impl = NULL;
11581 static GtkTreeModel *
11582 search_model_sort_new (GtkFileChooserDefault *impl,
11583 GtkTreeModel *child_model)
11585 SearchModelSort *model;
11587 model = g_object_new (SEARCH_MODEL_SORT_TYPE,
11588 "model", child_model,
11590 model->impl = impl;
11592 return GTK_TREE_MODEL (model);