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.
24 #include "gdk/gdkkeysyms.h"
25 #include "gtkalignment.h"
26 #include "gtkbindings.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 "gtkexpander.h"
35 #include "gtkfilechooserprivate.h"
36 #include "gtkfilechooserdefault.h"
37 #include "gtkfilechooserdialog.h"
38 #include "gtkfilechooserembed.h"
39 #include "gtkfilechooserentry.h"
40 #include "gtkfilechoosersettings.h"
41 #include "gtkfilechooserutils.h"
42 #include "gtkfilechooser.h"
43 #include "gtkfilesystem.h"
44 #include "gtkfilesystemmodel.h"
47 #include "gtkhpaned.h"
48 #include "gtkiconfactory.h"
49 #include "gtkicontheme.h"
51 #include "gtkimagemenuitem.h"
53 #include "gtkmarshalers.h"
54 #include "gtkmessagedialog.h"
55 #include "gtkmountoperation.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"
79 #include <sys/types.h>
90 #undef PROFILE_FILE_CHOOSER
91 #ifdef PROFILE_FILE_CHOOSER
98 #define PROFILE_INDENT 4
99 static int profile_indent;
102 profile_add_indent (int indent)
104 profile_indent += indent;
105 if (profile_indent < 0)
106 g_error ("You screwed up your indentation");
110 _gtk_file_chooser_profile_log (const char *func, int indent, const char *msg1, const char *msg2)
115 profile_add_indent (indent);
117 if (profile_indent == 0)
118 str = g_strdup_printf ("MARK: %s %s %s", func ? func : "", msg1 ? msg1 : "", msg2 ? msg2 : "");
120 str = g_strdup_printf ("MARK: %*c %s %s %s", profile_indent - 1, ' ', func ? func : "", msg1 ? msg1 : "", msg2 ? msg2 : "");
126 profile_add_indent (indent);
129 #define profile_start(x, y) _gtk_file_chooser_profile_log (G_STRFUNC, PROFILE_INDENT, x, y)
130 #define profile_end(x, y) _gtk_file_chooser_profile_log (G_STRFUNC, -PROFILE_INDENT, x, y)
131 #define profile_msg(x, y) _gtk_file_chooser_profile_log (NULL, 0, x, y)
133 #define profile_start(x, y)
134 #define profile_end(x, y)
135 #define profile_msg(x, y)
140 typedef struct _GtkFileChooserDefaultClass GtkFileChooserDefaultClass;
142 #define GTK_FILE_CHOOSER_DEFAULT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FILE_CHOOSER_DEFAULT, GtkFileChooserDefaultClass))
143 #define GTK_IS_FILE_CHOOSER_DEFAULT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FILE_CHOOSER_DEFAULT))
144 #define GTK_FILE_CHOOSER_DEFAULT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FILE_CHOOSER_DEFAULT, GtkFileChooserDefaultClass))
146 #define MAX_LOADING_TIME 500
148 #define DEFAULT_NEW_FOLDER_NAME _("Type name of new folder")
150 struct _GtkFileChooserDefaultClass
152 GtkVBoxClass parent_class;
158 LOCATION_POPUP_ON_PASTE,
164 LOCATION_TOGGLE_POPUP,
172 static guint signals[LAST_SIGNAL] = { 0 };
174 /* Column numbers for the shortcuts tree. Keep these in sync with shortcuts_model_create() */
176 SHORTCUTS_COL_PIXBUF,
180 SHORTCUTS_COL_REMOVABLE,
181 SHORTCUTS_COL_PIXBUF_VISIBLE,
182 SHORTCUTS_COL_CANCELLABLE,
183 SHORTCUTS_COL_NUM_COLUMNS
188 SHORTCUT_TYPE_VOLUME,
189 SHORTCUT_TYPE_SEPARATOR,
190 SHORTCUT_TYPE_SEARCH,
194 #define MODEL_ATTRIBUTES "standard::name,standard::type,standard::display-name," \
195 "standard::is-hidden,standard::is-backup,standard::size," \
196 "standard::content-type,time::modified"
198 /* the first 3 must be these due to settings caching sort column */
203 MODEL_COL_NAME_COLLATED,
207 MODEL_COL_MTIME_TEXT,
209 MODEL_COL_NUM_COLUMNS
213 RECENT_MODEL_COL_CANCELLABLE = MODEL_COL_NUM_COLUMNS,
214 RECENT_MODEL_COL_INFO,
215 RECENT_MODEL_COL_NUM_COLUMNS
218 /* Identifiers for target types */
224 search_is_possible (GtkFileChooserDefault *impl)
226 if (impl->search_engine == NULL)
227 impl->search_engine = _gtk_search_engine_new ();
229 return impl->search_engine != NULL;
232 /* Interesting places in the shortcuts bar */
236 SHORTCUTS_RECENT_SEPARATOR,
241 SHORTCUTS_BOOKMARKS_SEPARATOR,
243 SHORTCUTS_CURRENT_FOLDER_SEPARATOR,
244 SHORTCUTS_CURRENT_FOLDER
247 /* Icon size for if we can't get it from the theme */
248 #define FALLBACK_ICON_SIZE 16
250 #define PREVIEW_HBOX_SPACING 12
254 static void gtk_file_chooser_default_iface_init (GtkFileChooserIface *iface);
255 static void gtk_file_chooser_embed_default_iface_init (GtkFileChooserEmbedIface *iface);
257 static GObject* gtk_file_chooser_default_constructor (GType type,
258 guint n_construct_properties,
259 GObjectConstructParam *construct_params);
260 static void gtk_file_chooser_default_finalize (GObject *object);
261 static void gtk_file_chooser_default_set_property (GObject *object,
265 static void gtk_file_chooser_default_get_property (GObject *object,
269 static void gtk_file_chooser_default_dispose (GObject *object);
270 static void gtk_file_chooser_default_show_all (GtkWidget *widget);
271 static void gtk_file_chooser_default_realize (GtkWidget *widget);
272 static void gtk_file_chooser_default_map (GtkWidget *widget);
273 static void gtk_file_chooser_default_unmap (GtkWidget *widget);
274 static void gtk_file_chooser_default_hierarchy_changed (GtkWidget *widget,
275 GtkWidget *previous_toplevel);
276 static void gtk_file_chooser_default_style_set (GtkWidget *widget,
277 GtkStyle *previous_style);
278 static void gtk_file_chooser_default_screen_changed (GtkWidget *widget,
279 GdkScreen *previous_screen);
280 static void gtk_file_chooser_default_size_allocate (GtkWidget *widget,
281 GtkAllocation *allocation);
283 static gboolean gtk_file_chooser_default_set_current_folder (GtkFileChooser *chooser,
286 static gboolean gtk_file_chooser_default_update_current_folder (GtkFileChooser *chooser,
289 gboolean clear_entry,
291 static GFile * gtk_file_chooser_default_get_current_folder (GtkFileChooser *chooser);
292 static void gtk_file_chooser_default_set_current_name (GtkFileChooser *chooser,
294 static gboolean gtk_file_chooser_default_select_file (GtkFileChooser *chooser,
297 static void gtk_file_chooser_default_unselect_file (GtkFileChooser *chooser,
299 static void gtk_file_chooser_default_select_all (GtkFileChooser *chooser);
300 static void gtk_file_chooser_default_unselect_all (GtkFileChooser *chooser);
301 static GSList * gtk_file_chooser_default_get_files (GtkFileChooser *chooser);
302 static GFile * gtk_file_chooser_default_get_preview_file (GtkFileChooser *chooser);
303 static GtkFileSystem *gtk_file_chooser_default_get_file_system (GtkFileChooser *chooser);
304 static void gtk_file_chooser_default_add_filter (GtkFileChooser *chooser,
305 GtkFileFilter *filter);
306 static void gtk_file_chooser_default_remove_filter (GtkFileChooser *chooser,
307 GtkFileFilter *filter);
308 static GSList * gtk_file_chooser_default_list_filters (GtkFileChooser *chooser);
309 static gboolean gtk_file_chooser_default_add_shortcut_folder (GtkFileChooser *chooser,
312 static gboolean gtk_file_chooser_default_remove_shortcut_folder (GtkFileChooser *chooser,
315 static GSList * gtk_file_chooser_default_list_shortcut_folders (GtkFileChooser *chooser);
317 static void gtk_file_chooser_default_get_default_size (GtkFileChooserEmbed *chooser_embed,
319 gint *default_height);
320 static gboolean gtk_file_chooser_default_should_respond (GtkFileChooserEmbed *chooser_embed);
321 static void gtk_file_chooser_default_initial_focus (GtkFileChooserEmbed *chooser_embed);
323 static void location_popup_handler (GtkFileChooserDefault *impl,
325 static void location_popup_on_paste_handler (GtkFileChooserDefault *impl);
326 static void location_toggle_popup_handler (GtkFileChooserDefault *impl);
327 static void up_folder_handler (GtkFileChooserDefault *impl);
328 static void down_folder_handler (GtkFileChooserDefault *impl);
329 static void home_folder_handler (GtkFileChooserDefault *impl);
330 static void desktop_folder_handler (GtkFileChooserDefault *impl);
331 static void quick_bookmark_handler (GtkFileChooserDefault *impl,
332 gint bookmark_index);
333 static void show_hidden_handler (GtkFileChooserDefault *impl);
334 static void search_shortcut_handler (GtkFileChooserDefault *impl);
335 static void recent_shortcut_handler (GtkFileChooserDefault *impl);
336 static void update_appearance (GtkFileChooserDefault *impl);
338 static void set_current_filter (GtkFileChooserDefault *impl,
339 GtkFileFilter *filter);
340 static void check_preview_change (GtkFileChooserDefault *impl);
342 static void filter_combo_changed (GtkComboBox *combo_box,
343 GtkFileChooserDefault *impl);
345 static gboolean shortcuts_key_press_event_cb (GtkWidget *widget,
347 GtkFileChooserDefault *impl);
349 static gboolean shortcuts_select_func (GtkTreeSelection *selection,
352 gboolean path_currently_selected,
354 static gboolean shortcuts_get_selected (GtkFileChooserDefault *impl,
356 static void shortcuts_activate_iter (GtkFileChooserDefault *impl,
358 static int shortcuts_get_index (GtkFileChooserDefault *impl,
359 ShortcutsIndex where);
360 static int shortcut_find_position (GtkFileChooserDefault *impl,
363 static void bookmarks_check_add_sensitivity (GtkFileChooserDefault *impl);
365 static gboolean list_select_func (GtkTreeSelection *selection,
368 gboolean path_currently_selected,
371 static void list_selection_changed (GtkTreeSelection *tree_selection,
372 GtkFileChooserDefault *impl);
373 static void list_row_activated (GtkTreeView *tree_view,
375 GtkTreeViewColumn *column,
376 GtkFileChooserDefault *impl);
378 static void select_func (GtkFileSystemModel *model,
383 static void path_bar_clicked (GtkPathBar *path_bar,
386 gboolean child_is_hidden,
387 GtkFileChooserDefault *impl);
389 static void add_bookmark_button_clicked_cb (GtkButton *button,
390 GtkFileChooserDefault *impl);
391 static void remove_bookmark_button_clicked_cb (GtkButton *button,
392 GtkFileChooserDefault *impl);
393 static void save_folder_combo_changed_cb (GtkComboBox *combo,
394 GtkFileChooserDefault *impl);
396 static void update_cell_renderer_attributes (GtkFileChooserDefault *impl);
398 static void load_remove_timer (GtkFileChooserDefault *impl);
399 static void browse_files_center_selected_row (GtkFileChooserDefault *impl);
401 static void location_button_toggled_cb (GtkToggleButton *toggle,
402 GtkFileChooserDefault *impl);
403 static void location_switch_to_path_bar (GtkFileChooserDefault *impl);
405 static void search_stop_searching (GtkFileChooserDefault *impl,
406 gboolean remove_query);
407 static void search_clear_model (GtkFileChooserDefault *impl,
408 gboolean remove_from_treeview);
409 static gboolean search_should_respond (GtkFileChooserDefault *impl);
410 static void search_switch_to_browse_mode (GtkFileChooserDefault *impl);
411 static GSList *search_get_selected_files (GtkFileChooserDefault *impl);
412 static void search_entry_activate_cb (GtkEntry *entry,
414 static void settings_load (GtkFileChooserDefault *impl);
416 static void recent_stop_loading (GtkFileChooserDefault *impl);
417 static void recent_clear_model (GtkFileChooserDefault *impl,
418 gboolean remove_from_treeview);
419 static gboolean recent_should_respond (GtkFileChooserDefault *impl);
420 static void recent_switch_to_browse_mode (GtkFileChooserDefault *impl);
421 static GSList * recent_get_selected_files (GtkFileChooserDefault *impl);
422 static void recent_get_valid_child_iter (GtkFileChooserDefault *impl,
423 GtkTreeIter *child_iter,
425 static void set_file_system_backend (GtkFileChooserDefault *impl);
426 static void unset_file_system_backend (GtkFileChooserDefault *impl);
432 /* Drag and drop interface declarations */
435 GtkTreeModelFilter parent;
437 GtkFileChooserDefault *impl;
438 } ShortcutsPaneModelFilter;
441 GtkTreeModelFilterClass parent_class;
442 } ShortcutsPaneModelFilterClass;
444 #define SHORTCUTS_PANE_MODEL_FILTER_TYPE (_shortcuts_pane_model_filter_get_type ())
445 #define SHORTCUTS_PANE_MODEL_FILTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SHORTCUTS_PANE_MODEL_FILTER_TYPE, ShortcutsPaneModelFilter))
447 static void shortcuts_pane_model_filter_drag_source_iface_init (GtkTreeDragSourceIface *iface);
449 G_DEFINE_TYPE_WITH_CODE (ShortcutsPaneModelFilter,
450 _shortcuts_pane_model_filter,
451 GTK_TYPE_TREE_MODEL_FILTER,
452 G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_DRAG_SOURCE,
453 shortcuts_pane_model_filter_drag_source_iface_init))
455 static GtkTreeModel *shortcuts_pane_model_filter_new (GtkFileChooserDefault *impl,
456 GtkTreeModel *child_model,
461 GtkTreeModelSort parent;
463 GtkFileChooserDefault *impl;
467 GtkTreeModelSortClass parent_class;
468 } RecentModelSortClass;
470 #define RECENT_MODEL_SORT_TYPE (_recent_model_sort_get_type ())
471 #define RECENT_MODEL_SORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RECENT_MODEL_SORT_TYPE, RecentModelSort))
473 static void recent_model_sort_drag_source_iface_init (GtkTreeDragSourceIface *iface);
475 G_DEFINE_TYPE_WITH_CODE (RecentModelSort,
477 GTK_TYPE_TREE_MODEL_SORT,
478 G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_DRAG_SOURCE,
479 recent_model_sort_drag_source_iface_init));
481 static GtkTreeModel *recent_model_sort_new (GtkFileChooserDefault *impl,
482 GtkTreeModel *child_model);
487 G_DEFINE_TYPE_WITH_CODE (GtkFileChooserDefault, _gtk_file_chooser_default, GTK_TYPE_VBOX,
488 G_IMPLEMENT_INTERFACE (GTK_TYPE_FILE_CHOOSER,
489 gtk_file_chooser_default_iface_init)
490 G_IMPLEMENT_INTERFACE (GTK_TYPE_FILE_CHOOSER_EMBED,
491 gtk_file_chooser_embed_default_iface_init));
494 _gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class)
496 static const guint quick_bookmark_keyvals[10] = {
497 GDK_1, GDK_2, GDK_3, GDK_4, GDK_5, GDK_6, GDK_7, GDK_8, GDK_9, GDK_0
499 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
500 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
501 GtkBindingSet *binding_set;
504 gobject_class->finalize = gtk_file_chooser_default_finalize;
505 gobject_class->constructor = gtk_file_chooser_default_constructor;
506 gobject_class->set_property = gtk_file_chooser_default_set_property;
507 gobject_class->get_property = gtk_file_chooser_default_get_property;
508 gobject_class->dispose = gtk_file_chooser_default_dispose;
510 widget_class->show_all = gtk_file_chooser_default_show_all;
511 widget_class->realize = gtk_file_chooser_default_realize;
512 widget_class->map = gtk_file_chooser_default_map;
513 widget_class->unmap = gtk_file_chooser_default_unmap;
514 widget_class->hierarchy_changed = gtk_file_chooser_default_hierarchy_changed;
515 widget_class->style_set = gtk_file_chooser_default_style_set;
516 widget_class->screen_changed = gtk_file_chooser_default_screen_changed;
517 widget_class->size_allocate = gtk_file_chooser_default_size_allocate;
519 signals[LOCATION_POPUP] =
520 g_signal_new_class_handler (I_("location-popup"),
521 G_OBJECT_CLASS_TYPE (class),
522 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
523 G_CALLBACK (location_popup_handler),
525 _gtk_marshal_VOID__STRING,
526 G_TYPE_NONE, 1, G_TYPE_STRING);
528 signals[LOCATION_POPUP_ON_PASTE] =
529 g_signal_new_class_handler (I_("location-popup-on-paste"),
530 G_OBJECT_CLASS_TYPE (class),
531 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
532 G_CALLBACK (location_popup_on_paste_handler),
534 _gtk_marshal_VOID__VOID,
537 signals[LOCATION_TOGGLE_POPUP] =
538 g_signal_new_class_handler (I_("location-toggle-popup"),
539 G_OBJECT_CLASS_TYPE (class),
540 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
541 G_CALLBACK (location_toggle_popup_handler),
543 _gtk_marshal_VOID__VOID,
547 g_signal_new_class_handler (I_("up-folder"),
548 G_OBJECT_CLASS_TYPE (class),
549 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
550 G_CALLBACK (up_folder_handler),
552 _gtk_marshal_VOID__VOID,
555 signals[DOWN_FOLDER] =
556 g_signal_new_class_handler (I_("down-folder"),
557 G_OBJECT_CLASS_TYPE (class),
558 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
559 G_CALLBACK (down_folder_handler),
561 _gtk_marshal_VOID__VOID,
564 signals[HOME_FOLDER] =
565 g_signal_new_class_handler (I_("home-folder"),
566 G_OBJECT_CLASS_TYPE (class),
567 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
568 G_CALLBACK (home_folder_handler),
570 _gtk_marshal_VOID__VOID,
573 signals[DESKTOP_FOLDER] =
574 g_signal_new_class_handler (I_("desktop-folder"),
575 G_OBJECT_CLASS_TYPE (class),
576 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
577 G_CALLBACK (desktop_folder_handler),
579 _gtk_marshal_VOID__VOID,
582 signals[QUICK_BOOKMARK] =
583 g_signal_new_class_handler (I_("quick-bookmark"),
584 G_OBJECT_CLASS_TYPE (class),
585 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
586 G_CALLBACK (quick_bookmark_handler),
588 _gtk_marshal_VOID__INT,
589 G_TYPE_NONE, 1, G_TYPE_INT);
591 signals[SHOW_HIDDEN] =
592 g_signal_new_class_handler (I_("show-hidden"),
593 G_OBJECT_CLASS_TYPE (class),
594 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
595 G_CALLBACK (show_hidden_handler),
597 _gtk_marshal_VOID__VOID,
600 signals[SEARCH_SHORTCUT] =
601 g_signal_new_class_handler (I_("search-shortcut"),
602 G_OBJECT_CLASS_TYPE (class),
603 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
604 G_CALLBACK (search_shortcut_handler),
606 _gtk_marshal_VOID__VOID,
609 signals[RECENT_SHORTCUT] =
610 g_signal_new_class_handler (I_("recent-shortcut"),
611 G_OBJECT_CLASS_TYPE (class),
612 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
613 G_CALLBACK (recent_shortcut_handler),
615 _gtk_marshal_VOID__VOID,
618 binding_set = gtk_binding_set_by_class (class);
620 gtk_binding_entry_add_signal (binding_set,
621 GDK_l, GDK_CONTROL_MASK,
622 "location-toggle-popup",
625 gtk_binding_entry_add_signal (binding_set,
628 1, G_TYPE_STRING, "/");
629 gtk_binding_entry_add_signal (binding_set,
632 1, G_TYPE_STRING, "/");
635 gtk_binding_entry_add_signal (binding_set,
638 1, G_TYPE_STRING, "~");
641 gtk_binding_entry_add_signal (binding_set,
642 GDK_v, GDK_CONTROL_MASK,
643 "location-popup-on-paste",
645 gtk_binding_entry_add_signal (binding_set,
646 GDK_Up, GDK_MOD1_MASK,
649 gtk_binding_entry_add_signal (binding_set,
653 gtk_binding_entry_add_signal (binding_set,
654 GDK_KP_Up, GDK_MOD1_MASK,
658 gtk_binding_entry_add_signal (binding_set,
659 GDK_Down, GDK_MOD1_MASK,
662 gtk_binding_entry_add_signal (binding_set,
663 GDK_KP_Down, GDK_MOD1_MASK,
667 gtk_binding_entry_add_signal (binding_set,
668 GDK_Home, GDK_MOD1_MASK,
671 gtk_binding_entry_add_signal (binding_set,
672 GDK_KP_Home, GDK_MOD1_MASK,
675 gtk_binding_entry_add_signal (binding_set,
676 GDK_d, GDK_MOD1_MASK,
679 gtk_binding_entry_add_signal (binding_set,
680 GDK_h, GDK_CONTROL_MASK,
683 gtk_binding_entry_add_signal (binding_set,
684 GDK_s, GDK_MOD1_MASK,
687 gtk_binding_entry_add_signal (binding_set,
688 GDK_r, GDK_MOD1_MASK,
692 for (i = 0; i < 10; i++)
693 gtk_binding_entry_add_signal (binding_set,
694 quick_bookmark_keyvals[i], GDK_MOD1_MASK,
698 _gtk_file_chooser_install_properties (gobject_class);
702 gtk_file_chooser_default_iface_init (GtkFileChooserIface *iface)
704 iface->select_file = gtk_file_chooser_default_select_file;
705 iface->unselect_file = gtk_file_chooser_default_unselect_file;
706 iface->select_all = gtk_file_chooser_default_select_all;
707 iface->unselect_all = gtk_file_chooser_default_unselect_all;
708 iface->get_files = gtk_file_chooser_default_get_files;
709 iface->get_preview_file = gtk_file_chooser_default_get_preview_file;
710 iface->get_file_system = gtk_file_chooser_default_get_file_system;
711 iface->set_current_folder = gtk_file_chooser_default_set_current_folder;
712 iface->get_current_folder = gtk_file_chooser_default_get_current_folder;
713 iface->set_current_name = gtk_file_chooser_default_set_current_name;
714 iface->add_filter = gtk_file_chooser_default_add_filter;
715 iface->remove_filter = gtk_file_chooser_default_remove_filter;
716 iface->list_filters = gtk_file_chooser_default_list_filters;
717 iface->add_shortcut_folder = gtk_file_chooser_default_add_shortcut_folder;
718 iface->remove_shortcut_folder = gtk_file_chooser_default_remove_shortcut_folder;
719 iface->list_shortcut_folders = gtk_file_chooser_default_list_shortcut_folders;
723 gtk_file_chooser_embed_default_iface_init (GtkFileChooserEmbedIface *iface)
725 iface->get_default_size = gtk_file_chooser_default_get_default_size;
726 iface->should_respond = gtk_file_chooser_default_should_respond;
727 iface->initial_focus = gtk_file_chooser_default_initial_focus;
731 _gtk_file_chooser_default_init (GtkFileChooserDefault *impl)
733 profile_start ("start", NULL);
734 #ifdef PROFILE_FILE_CHOOSER
735 access ("MARK: *** CREATE FILE CHOOSER", F_OK);
737 impl->local_only = TRUE;
738 impl->preview_widget_active = TRUE;
739 impl->use_preview_label = TRUE;
740 impl->select_multiple = FALSE;
741 impl->show_hidden = FALSE;
742 impl->show_size_column = TRUE;
743 impl->icon_size = FALLBACK_ICON_SIZE;
744 impl->load_state = LOAD_EMPTY;
745 impl->reload_state = RELOAD_EMPTY;
746 impl->pending_select_files = NULL;
747 impl->location_mode = LOCATION_MODE_PATH_BAR;
748 impl->operation_mode = OPERATION_MODE_BROWSE;
749 impl->sort_column = MODEL_COL_NAME;
750 impl->sort_order = GTK_SORT_ASCENDING;
751 impl->recent_manager = gtk_recent_manager_get_default ();
752 impl->create_folders = TRUE;
754 gtk_box_set_spacing (GTK_BOX (impl), 12);
756 set_file_system_backend (impl);
758 profile_end ("end", NULL);
761 /* Frees the data columns for the specified iter in the shortcuts model*/
763 shortcuts_free_row_data (GtkFileChooserDefault *impl,
767 ShortcutType shortcut_type;
768 GCancellable *cancellable;
770 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), iter,
771 SHORTCUTS_COL_DATA, &col_data,
772 SHORTCUTS_COL_TYPE, &shortcut_type,
773 SHORTCUTS_COL_CANCELLABLE, &cancellable,
777 g_cancellable_cancel (cancellable);
779 if (!(shortcut_type == SHORTCUT_TYPE_FILE ||
780 shortcut_type == SHORTCUT_TYPE_VOLUME) ||
784 if (shortcut_type == SHORTCUT_TYPE_VOLUME)
786 GtkFileSystemVolume *volume;
789 _gtk_file_system_volume_free (volume);
795 g_assert (shortcut_type == SHORTCUT_TYPE_FILE);
798 g_object_unref (file);
802 /* Frees all the data columns in the shortcuts model */
804 shortcuts_free (GtkFileChooserDefault *impl)
808 if (!impl->shortcuts_model)
811 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
814 shortcuts_free_row_data (impl, &iter);
816 while (gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter));
818 g_object_unref (impl->shortcuts_model);
819 impl->shortcuts_model = NULL;
823 pending_select_files_free (GtkFileChooserDefault *impl)
825 g_slist_foreach (impl->pending_select_files, (GFunc) g_object_unref, NULL);
826 g_slist_free (impl->pending_select_files);
827 impl->pending_select_files = NULL;
831 pending_select_files_add (GtkFileChooserDefault *impl,
834 impl->pending_select_files =
835 g_slist_prepend (impl->pending_select_files, g_object_ref (file));
838 /* Used from gtk_tree_selection_selected_foreach() */
840 store_selection_foreach (GtkTreeModel *model,
845 GtkFileChooserDefault *impl;
848 impl = GTK_FILE_CHOOSER_DEFAULT (data);
850 file = _gtk_file_system_model_get_file (GTK_FILE_SYSTEM_MODEL (model), iter);
851 pending_select_files_add (impl, file);
854 /* Stores the current selection in the list of paths to select; this is used to
855 * preserve the selection when reloading the current folder.
858 pending_select_files_store_selection (GtkFileChooserDefault *impl)
860 GtkTreeSelection *selection;
862 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
863 gtk_tree_selection_selected_foreach (selection, store_selection_foreach, impl);
867 gtk_file_chooser_default_finalize (GObject *object)
869 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (object);
872 unset_file_system_backend (impl);
874 if (impl->shortcuts_pane_filter_model)
875 g_object_unref (impl->shortcuts_pane_filter_model);
877 if (impl->shortcuts_combo_filter_model)
878 g_object_unref (impl->shortcuts_combo_filter_model);
880 shortcuts_free (impl);
882 g_free (impl->browse_files_last_selected_name);
884 for (l = impl->filters; l; l = l->next)
886 GtkFileFilter *filter;
888 filter = GTK_FILE_FILTER (l->data);
889 g_object_unref (filter);
891 g_slist_free (impl->filters);
893 if (impl->current_filter)
894 g_object_unref (impl->current_filter);
896 if (impl->current_volume_file)
897 g_object_unref (impl->current_volume_file);
899 if (impl->current_folder)
900 g_object_unref (impl->current_folder);
902 if (impl->preview_file)
903 g_object_unref (impl->preview_file);
905 if (impl->browse_path_bar_size_group)
906 g_object_unref (impl->browse_path_bar_size_group);
908 load_remove_timer (impl);
910 /* Free all the Models we have */
911 if (impl->browse_files_model)
912 g_object_unref (impl->browse_files_model);
914 search_clear_model (impl, FALSE);
915 recent_clear_model (impl, FALSE);
917 g_free (impl->preview_display_name);
919 g_free (impl->edited_new_text);
921 G_OBJECT_CLASS (_gtk_file_chooser_default_parent_class)->finalize (object);
924 /* Shows an error dialog set as transient for the specified window */
926 error_message_with_parent (GtkWindow *parent,
932 dialog = gtk_message_dialog_new (parent,
933 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
938 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
941 if (parent && parent->group)
942 gtk_window_group_add_window (parent->group, GTK_WINDOW (dialog));
944 gtk_dialog_run (GTK_DIALOG (dialog));
945 gtk_widget_destroy (dialog);
948 /* Returns a toplevel GtkWindow, or NULL if none */
950 get_toplevel (GtkWidget *widget)
954 toplevel = gtk_widget_get_toplevel (widget);
955 if (!GTK_WIDGET_TOPLEVEL (toplevel))
958 return GTK_WINDOW (toplevel);
961 /* Shows an error dialog for the file chooser */
963 error_message (GtkFileChooserDefault *impl,
967 error_message_with_parent (get_toplevel (GTK_WIDGET (impl)), msg, detail);
970 /* Shows a simple error dialog relative to a path. Frees the GError as well. */
972 error_dialog (GtkFileChooserDefault *impl,
983 uri = g_file_get_uri (file);
984 text = g_strdup_printf (msg, uri);
985 error_message (impl, text, error->message);
988 g_error_free (error);
992 /* Displays an error message about not being able to get information for a file.
993 * Frees the GError as well.
996 error_getting_info_dialog (GtkFileChooserDefault *impl,
1001 _("Could not retrieve information about the file"),
1005 /* Shows an error dialog about not being able to add a bookmark */
1007 error_adding_bookmark_dialog (GtkFileChooserDefault *impl,
1012 _("Could not add a bookmark"),
1016 /* Shows an error dialog about not being able to remove a bookmark */
1018 error_removing_bookmark_dialog (GtkFileChooserDefault *impl,
1023 _("Could not remove bookmark"),
1027 /* Shows an error dialog about not being able to create a folder */
1029 error_creating_folder_dialog (GtkFileChooserDefault *impl,
1034 _("The folder could not be created"),
1038 /* Shows an error about not being able to create a folder because a file with
1039 * the same name is already there.
1042 error_creating_folder_over_existing_file_dialog (GtkFileChooserDefault *impl,
1047 _("The folder could not be created, as a file with the same "
1048 "name already exists. Try using a different name for the "
1049 "folder, or rename the file first."),
1053 /* Shows an error dialog about not being able to create a filename */
1055 error_building_filename_dialog (GtkFileChooserDefault *impl,
1058 error_dialog (impl, _("Invalid file name"),
1062 /* Shows an error dialog when we cannot switch to a folder */
1064 error_changing_folder_dialog (GtkFileChooserDefault *impl,
1068 error_dialog (impl, _("The folder contents could not be displayed"),
1072 /* Changes folders, displaying an error dialog if this fails */
1074 change_folder_and_display_error (GtkFileChooserDefault *impl,
1076 gboolean clear_entry)
1081 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1083 /* We copy the path because of this case:
1085 * list_row_activated()
1086 * fetches path from model; path belongs to the model (*)
1087 * calls change_folder_and_display_error()
1088 * calls gtk_file_chooser_set_current_folder_file()
1089 * changing folders fails, sets model to NULL, thus freeing the path in (*)
1093 result = gtk_file_chooser_default_update_current_folder (GTK_FILE_CHOOSER (impl), file, TRUE, clear_entry, &error);
1096 error_changing_folder_dialog (impl, file, error);
1102 emit_default_size_changed (GtkFileChooserDefault *impl)
1104 profile_msg (" emit default-size-changed start", NULL);
1105 g_signal_emit_by_name (impl, "default-size-changed");
1106 profile_msg (" emit default-size-changed end", NULL);
1110 update_preview_widget_visibility (GtkFileChooserDefault *impl)
1112 if (impl->use_preview_label)
1114 if (!impl->preview_label)
1116 impl->preview_label = gtk_label_new (impl->preview_display_name);
1117 gtk_box_pack_start (GTK_BOX (impl->preview_box), impl->preview_label, FALSE, FALSE, 0);
1118 gtk_box_reorder_child (GTK_BOX (impl->preview_box), impl->preview_label, 0);
1119 gtk_label_set_ellipsize (GTK_LABEL (impl->preview_label), PANGO_ELLIPSIZE_MIDDLE);
1120 gtk_widget_show (impl->preview_label);
1125 if (impl->preview_label)
1127 gtk_widget_destroy (impl->preview_label);
1128 impl->preview_label = NULL;
1132 if (impl->preview_widget_active && impl->preview_widget)
1133 gtk_widget_show (impl->preview_box);
1135 gtk_widget_hide (impl->preview_box);
1137 if (!GTK_WIDGET_MAPPED (impl))
1138 emit_default_size_changed (impl);
1142 set_preview_widget (GtkFileChooserDefault *impl,
1143 GtkWidget *preview_widget)
1145 if (preview_widget == impl->preview_widget)
1148 if (impl->preview_widget)
1149 gtk_container_remove (GTK_CONTAINER (impl->preview_box),
1150 impl->preview_widget);
1152 impl->preview_widget = preview_widget;
1153 if (impl->preview_widget)
1155 gtk_widget_show (impl->preview_widget);
1156 gtk_box_pack_start (GTK_BOX (impl->preview_box), impl->preview_widget, TRUE, TRUE, 0);
1157 gtk_box_reorder_child (GTK_BOX (impl->preview_box),
1158 impl->preview_widget,
1159 (impl->use_preview_label && impl->preview_label) ? 1 : 0);
1162 update_preview_widget_visibility (impl);
1165 /* Renders a "Search" icon at an appropriate size for a tree view */
1167 render_search_icon (GtkFileChooserDefault *impl)
1169 return gtk_widget_render_icon (GTK_WIDGET (impl), GTK_STOCK_FIND, GTK_ICON_SIZE_MENU, NULL);
1173 render_recent_icon (GtkFileChooserDefault *impl)
1175 GtkIconTheme *theme;
1178 if (gtk_widget_has_screen (GTK_WIDGET (impl)))
1179 theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl)));
1181 theme = gtk_icon_theme_get_default ();
1183 retval = gtk_icon_theme_load_icon (theme, "document-open-recent",
1189 retval = gtk_widget_render_icon (GTK_WIDGET (impl), GTK_STOCK_FILE, GTK_ICON_SIZE_MENU, NULL);
1195 /* Re-reads all the icons for the shortcuts, used when the theme changes */
1196 struct ReloadIconsData
1198 GtkFileChooserDefault *impl;
1199 GtkTreeRowReference *row_ref;
1203 shortcuts_reload_icons_get_info_cb (GCancellable *cancellable,
1205 const GError *error,
1211 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1212 struct ReloadIconsData *data = user_data;
1214 if (!g_slist_find (data->impl->reload_icon_cancellables, cancellable))
1217 data->impl->reload_icon_cancellables = g_slist_remove (data->impl->reload_icon_cancellables, cancellable);
1219 if (cancelled || error)
1222 pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (data->impl), data->impl->icon_size);
1224 path = gtk_tree_row_reference_get_path (data->row_ref);
1225 gtk_tree_model_get_iter (GTK_TREE_MODEL (data->impl->shortcuts_model), &iter, path);
1226 gtk_list_store_set (data->impl->shortcuts_model, &iter,
1227 SHORTCUTS_COL_PIXBUF, pixbuf,
1229 gtk_tree_path_free (path);
1232 g_object_unref (pixbuf);
1235 gtk_tree_row_reference_free (data->row_ref);
1236 g_object_unref (data->impl);
1239 g_object_unref (cancellable);
1243 shortcuts_reload_icons (GtkFileChooserDefault *impl)
1248 profile_start ("start", NULL);
1250 if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
1253 for (l = impl->reload_icon_cancellables; l; l = l->next)
1255 GCancellable *cancellable = G_CANCELLABLE (l->data);
1256 g_cancellable_cancel (cancellable);
1258 g_slist_free (impl->reload_icon_cancellables);
1259 impl->reload_icon_cancellables = NULL;
1264 ShortcutType shortcut_type;
1265 gboolean pixbuf_visible;
1268 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
1269 SHORTCUTS_COL_DATA, &data,
1270 SHORTCUTS_COL_TYPE, &shortcut_type,
1271 SHORTCUTS_COL_PIXBUF_VISIBLE, &pixbuf_visible,
1277 if (shortcut_type == SHORTCUT_TYPE_VOLUME)
1279 GtkFileSystemVolume *volume;
1282 pixbuf = _gtk_file_system_volume_render_icon (volume, GTK_WIDGET (impl),
1283 impl->icon_size, NULL);
1285 else if (shortcut_type == SHORTCUT_TYPE_FILE)
1287 if (g_file_is_native (G_FILE (data)))
1290 struct ReloadIconsData *info;
1291 GtkTreePath *tree_path;
1292 GCancellable *cancellable;
1296 info = g_new0 (struct ReloadIconsData, 1);
1297 info->impl = g_object_ref (impl);
1298 tree_path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
1299 info->row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (impl->shortcuts_model), tree_path);
1300 gtk_tree_path_free (tree_path);
1302 cancellable = _gtk_file_system_get_info (impl->file_system, file,
1304 shortcuts_reload_icons_get_info_cb,
1306 impl->reload_icon_cancellables = g_slist_append (impl->reload_icon_cancellables, cancellable);
1310 GtkIconTheme *icon_theme;
1312 /* Don't call get_info for remote paths to avoid latency and
1314 * If we switch to a better bookmarks file format (XBEL), we
1315 * should use mime info to get a better icon.
1317 icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl)));
1318 pixbuf = gtk_icon_theme_load_icon (icon_theme, "folder-remote",
1319 impl->icon_size, 0, NULL);
1322 else if (shortcut_type == SHORTCUT_TYPE_SEARCH)
1324 pixbuf = render_search_icon (impl);
1326 else if (shortcut_type == SHORTCUT_TYPE_RECENT)
1328 pixbuf = render_recent_icon (impl);
1331 gtk_list_store_set (impl->shortcuts_model, &iter,
1332 SHORTCUTS_COL_PIXBUF, pixbuf,
1336 g_object_unref (pixbuf);
1340 while (gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model),&iter));
1344 profile_end ("end", NULL);
1348 shortcuts_find_folder (GtkFileChooserDefault *impl,
1351 GtkTreeSelection *selection;
1355 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view));
1357 g_assert (folder != NULL);
1358 pos = shortcut_find_position (impl, folder);
1361 gtk_tree_selection_unselect_all (selection);
1365 path = gtk_tree_path_new_from_indices (pos, -1);
1366 gtk_tree_selection_select_path (selection, path);
1367 gtk_tree_path_free (path);
1370 /* If a shortcut corresponds to the current folder, selects it */
1372 shortcuts_find_current_folder (GtkFileChooserDefault *impl)
1374 shortcuts_find_folder (impl, impl->current_folder);
1377 /* Removes the specified number of rows from the shortcuts list */
1379 shortcuts_remove_rows (GtkFileChooserDefault *impl,
1385 path = gtk_tree_path_new_from_indices (start_row, -1);
1387 for (; n_rows; n_rows--)
1391 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->shortcuts_model), &iter, path))
1392 g_assert_not_reached ();
1394 shortcuts_free_row_data (impl, &iter);
1395 gtk_list_store_remove (impl->shortcuts_model, &iter);
1398 gtk_tree_path_free (path);
1402 shortcuts_update_count (GtkFileChooserDefault *impl,
1403 ShortcutsIndex type,
1408 case SHORTCUTS_HOME:
1410 impl->has_home = FALSE;
1412 impl->has_home = TRUE;
1415 case SHORTCUTS_DESKTOP:
1417 impl->has_desktop = FALSE;
1419 impl->has_desktop = TRUE;
1422 case SHORTCUTS_VOLUMES:
1423 impl->num_volumes += value;
1426 case SHORTCUTS_SHORTCUTS:
1427 impl->num_shortcuts += value;
1430 case SHORTCUTS_BOOKMARKS:
1431 impl->num_bookmarks += value;
1434 case SHORTCUTS_CURRENT_FOLDER:
1436 impl->shortcuts_current_folder_active = FALSE;
1438 impl->shortcuts_current_folder_active = TRUE;
1447 struct ShortcutsInsertRequest
1449 GtkFileChooserDefault *impl;
1453 GtkTreeRowReference *row_ref;
1454 ShortcutsIndex type;
1460 get_file_info_finished (GCancellable *cancellable,
1462 const GError *error,
1466 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1470 GCancellable *model_cancellable;
1471 struct ShortcutsInsertRequest *request = data;
1473 path = gtk_tree_row_reference_get_path (request->row_ref);
1475 /* Handle doesn't exist anymore in the model */
1478 pos = gtk_tree_path_get_indices (path)[0];
1479 gtk_tree_model_get_iter (GTK_TREE_MODEL (request->impl->shortcuts_model),
1481 gtk_tree_path_free (path);
1483 /* validate cancellable, else goto out */
1484 gtk_tree_model_get (GTK_TREE_MODEL (request->impl->shortcuts_model), &iter,
1485 SHORTCUTS_COL_CANCELLABLE, &model_cancellable,
1487 if (cancellable != model_cancellable)
1490 /* set the cancellable to NULL in the model (we unref later on) */
1491 gtk_list_store_set (request->impl->shortcuts_model, &iter,
1492 SHORTCUTS_COL_CANCELLABLE, NULL,
1500 gtk_list_store_remove (request->impl->shortcuts_model, &iter);
1501 shortcuts_update_count (request->impl, request->type, -1);
1503 if (request->type == SHORTCUTS_HOME)
1507 home = g_file_new_for_path (g_get_home_dir ());
1508 error_getting_info_dialog (request->impl, home, g_error_copy (error));
1509 g_object_unref (home);
1511 else if (request->type == SHORTCUTS_CURRENT_FOLDER)
1513 /* Remove the current folder separator */
1514 gint separator_pos = shortcuts_get_index (request->impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR);
1515 shortcuts_remove_rows (request->impl, separator_pos, 1);
1521 if (!request->label_copy)
1522 request->label_copy = g_strdup (g_file_info_get_display_name (info));
1523 pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (request->impl),
1524 request->impl->icon_size);
1526 gtk_list_store_set (request->impl->shortcuts_model, &iter,
1527 SHORTCUTS_COL_PIXBUF, pixbuf,
1528 SHORTCUTS_COL_PIXBUF_VISIBLE, TRUE,
1529 SHORTCUTS_COL_NAME, request->label_copy,
1530 SHORTCUTS_COL_TYPE, SHORTCUT_TYPE_FILE,
1531 SHORTCUTS_COL_REMOVABLE, request->removable,
1534 if (request->impl->shortcuts_pane_filter_model)
1535 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (request->impl->shortcuts_pane_filter_model));
1537 if (request->impl->shortcuts_combo_filter_model)
1538 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (request->impl->shortcuts_combo_filter_model));
1540 if (request->type == SHORTCUTS_CURRENT_FOLDER &&
1541 request->impl->save_folder_combo != NULL)
1543 /* The current folder is updated via _activate_iter(), don't
1544 * have save_folder_combo_changed_cb() call _activate_iter()
1547 g_signal_handlers_block_by_func (request->impl->save_folder_combo,
1548 G_CALLBACK (save_folder_combo_changed_cb),
1551 if (request->impl->has_search)
1554 if (request->impl->has_recent)
1557 gtk_combo_box_set_active (GTK_COMBO_BOX (request->impl->save_folder_combo), pos);
1558 g_signal_handlers_unblock_by_func (request->impl->save_folder_combo,
1559 G_CALLBACK (save_folder_combo_changed_cb),
1564 g_object_unref (pixbuf);
1567 g_object_unref (request->impl);
1568 g_object_unref (request->file);
1569 gtk_tree_row_reference_free (request->row_ref);
1570 g_free (request->label_copy);
1573 g_object_unref (cancellable);
1576 /* FIXME: GtkFileSystem needs a function to split a remote path
1577 * into hostname and path components, or maybe just have a
1578 * gtk_file_system_path_get_display_name().
1580 * This function is also used in gtkfilechooserbutton.c
1583 _gtk_file_chooser_label_for_file (GFile *file)
1585 const gchar *path, *start, *end, *p;
1586 gchar *uri, *host, *label;
1588 uri = g_file_get_uri (file);
1590 start = strstr (uri, "://");
1594 path = strchr (start, '/');
1599 end = uri + strlen (uri);
1603 /* strip username */
1604 p = strchr (start, '@');
1608 p = strchr (start, ':');
1612 host = g_strndup (start, end - start);
1614 /* Translators: the first string is a path and the second string
1615 * is a hostname. Nautilus and the panel contain the same string
1618 label = g_strdup_printf (_("%1$s on %2$s"), path, host);
1624 label = g_strdup (uri);
1632 /* Inserts a path in the shortcuts tree, making a copy of it; alternatively,
1633 * inserts a volume. A position of -1 indicates the end of the tree.
1636 shortcuts_insert_file (GtkFileChooserDefault *impl,
1638 ShortcutType shortcut_type,
1639 GtkFileSystemVolume *volume,
1643 ShortcutsIndex type)
1646 GdkPixbuf *pixbuf = NULL;
1647 gpointer data = NULL;
1649 GtkIconTheme *icon_theme;
1651 profile_start ("start shortcut", NULL);
1653 if (shortcut_type == SHORTCUT_TYPE_VOLUME)
1656 label_copy = _gtk_file_system_volume_get_display_name (volume);
1657 pixbuf = _gtk_file_system_volume_render_icon (volume, GTK_WIDGET (impl),
1658 impl->icon_size, NULL);
1660 else if (shortcut_type == SHORTCUT_TYPE_FILE)
1662 if (g_file_is_native (file))
1664 struct ShortcutsInsertRequest *request;
1665 GCancellable *cancellable;
1668 request = g_new0 (struct ShortcutsInsertRequest, 1);
1669 request->impl = g_object_ref (impl);
1670 request->file = g_object_ref (file);
1671 request->name_only = TRUE;
1672 request->removable = removable;
1674 request->type = type;
1676 request->label_copy = g_strdup (label);
1679 gtk_list_store_append (impl->shortcuts_model, &iter);
1681 gtk_list_store_insert (impl->shortcuts_model, &iter, pos);
1683 p = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
1684 request->row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (impl->shortcuts_model), p);
1685 gtk_tree_path_free (p);
1687 cancellable = _gtk_file_system_get_info (request->impl->file_system, request->file,
1688 "standard::is-hidden,standard::is-backup,standard::display-name,standard::icon",
1689 get_file_info_finished, request);
1691 gtk_list_store_set (impl->shortcuts_model, &iter,
1692 SHORTCUTS_COL_DATA, g_object_ref (file),
1693 SHORTCUTS_COL_TYPE, SHORTCUT_TYPE_FILE,
1694 SHORTCUTS_COL_CANCELLABLE, cancellable,
1697 shortcuts_update_count (impl, type, 1);
1703 /* Don't call get_info for remote paths to avoid latency and
1706 data = g_object_ref (file);
1708 label_copy = g_strdup (label);
1710 label_copy = _gtk_file_chooser_label_for_file (file);
1712 /* If we switch to a better bookmarks file format (XBEL), we
1713 * should use mime info to get a better icon.
1715 icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl)));
1716 pixbuf = gtk_icon_theme_load_icon (icon_theme, "folder-remote",
1717 impl->icon_size, 0, NULL);
1722 g_assert_not_reached ();
1728 gtk_list_store_append (impl->shortcuts_model, &iter);
1730 gtk_list_store_insert (impl->shortcuts_model, &iter, pos);
1732 shortcuts_update_count (impl, type, 1);
1734 gtk_list_store_set (impl->shortcuts_model, &iter,
1735 SHORTCUTS_COL_PIXBUF, pixbuf,
1736 SHORTCUTS_COL_PIXBUF_VISIBLE, TRUE,
1737 SHORTCUTS_COL_NAME, label_copy,
1738 SHORTCUTS_COL_DATA, data,
1739 SHORTCUTS_COL_TYPE, shortcut_type,
1740 SHORTCUTS_COL_REMOVABLE, removable,
1741 SHORTCUTS_COL_CANCELLABLE, NULL,
1744 if (impl->shortcuts_pane_filter_model)
1745 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_pane_filter_model));
1747 if (impl->shortcuts_combo_filter_model)
1748 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_combo_filter_model));
1750 if (type == SHORTCUTS_CURRENT_FOLDER && impl->save_folder_combo != NULL)
1752 /* The current folder is updated via _activate_iter(), don't
1753 * have save_folder_combo_changed_cb() call _activate_iter()
1756 gint combo_pos = shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER);
1758 if (impl->has_search)
1761 if (impl->has_recent)
1764 g_signal_handlers_block_by_func (impl->save_folder_combo,
1765 G_CALLBACK (save_folder_combo_changed_cb),
1768 gtk_combo_box_set_active (GTK_COMBO_BOX (impl->save_folder_combo), combo_pos);
1769 g_signal_handlers_unblock_by_func (impl->save_folder_combo,
1770 G_CALLBACK (save_folder_combo_changed_cb),
1774 g_free (label_copy);
1777 g_object_unref (pixbuf);
1779 profile_end ("end", NULL);
1783 shortcuts_append_search (GtkFileChooserDefault *impl)
1788 pixbuf = render_search_icon (impl);
1790 gtk_list_store_append (impl->shortcuts_model, &iter);
1791 gtk_list_store_set (impl->shortcuts_model, &iter,
1792 SHORTCUTS_COL_PIXBUF, pixbuf,
1793 SHORTCUTS_COL_PIXBUF_VISIBLE, TRUE,
1794 SHORTCUTS_COL_NAME, _("Search"),
1795 SHORTCUTS_COL_DATA, NULL,
1796 SHORTCUTS_COL_TYPE, SHORTCUT_TYPE_SEARCH,
1797 SHORTCUTS_COL_REMOVABLE, FALSE,
1801 g_object_unref (pixbuf);
1803 impl->has_search = TRUE;
1807 shortcuts_append_recent (GtkFileChooserDefault *impl)
1812 pixbuf = render_recent_icon (impl);
1814 gtk_list_store_append (impl->shortcuts_model, &iter);
1815 gtk_list_store_set (impl->shortcuts_model, &iter,
1816 SHORTCUTS_COL_PIXBUF, pixbuf,
1817 SHORTCUTS_COL_PIXBUF_VISIBLE, TRUE,
1818 SHORTCUTS_COL_NAME, _("Recently Used"),
1819 SHORTCUTS_COL_DATA, NULL,
1820 SHORTCUTS_COL_TYPE, SHORTCUT_TYPE_RECENT,
1821 SHORTCUTS_COL_REMOVABLE, FALSE,
1825 g_object_unref (pixbuf);
1827 impl->has_recent = TRUE;
1830 /* Appends an item for the user's home directory to the shortcuts model */
1832 shortcuts_append_home (GtkFileChooserDefault *impl)
1834 const char *home_path;
1837 profile_start ("start", NULL);
1839 home_path = g_get_home_dir ();
1840 if (home_path == NULL)
1842 profile_end ("end - no home directory!?", NULL);
1846 home = g_file_new_for_path (home_path);
1847 shortcuts_insert_file (impl, -1, SHORTCUT_TYPE_FILE, NULL, home, NULL, FALSE, SHORTCUTS_HOME);
1848 impl->has_home = TRUE;
1850 g_object_unref (home);
1852 profile_end ("end", NULL);
1855 /* Appends the ~/Desktop directory to the shortcuts model */
1857 shortcuts_append_desktop (GtkFileChooserDefault *impl)
1862 profile_start ("start", NULL);
1864 name = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
1865 /* "To disable a directory, point it to the homedir."
1866 * See http://freedesktop.org/wiki/Software/xdg-user-dirs
1868 if (!g_strcmp0 (name, g_get_home_dir ()))
1870 profile_end ("end", NULL);
1874 file = g_file_new_for_path (name);
1875 shortcuts_insert_file (impl, -1, SHORTCUT_TYPE_FILE, NULL, file, _("Desktop"), FALSE, SHORTCUTS_DESKTOP);
1876 impl->has_desktop = TRUE;
1878 /* We do not actually pop up an error dialog if there is no desktop directory
1879 * because some people may really not want to have one.
1882 g_object_unref (file);
1884 profile_end ("end", NULL);
1887 /* Appends a list of GFile to the shortcuts model; returns how many were inserted */
1889 shortcuts_append_bookmarks (GtkFileChooserDefault *impl,
1896 profile_start ("start", NULL);
1898 start_row = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR) + 1;
1901 for (; bookmarks; bookmarks = bookmarks->next)
1905 file = bookmarks->data;
1907 if (impl->local_only && !g_file_is_native (file))
1910 if (shortcut_find_position (impl, file) != -1)
1913 label = _gtk_file_system_get_bookmark_label (impl->file_system, file);
1915 shortcuts_insert_file (impl, start_row + num_inserted, SHORTCUT_TYPE_FILE, NULL, file, label, TRUE, SHORTCUTS_BOOKMARKS);
1921 profile_end ("end", NULL);
1923 return num_inserted;
1926 /* Returns the index for the corresponding item in the shortcuts bar */
1928 shortcuts_get_index (GtkFileChooserDefault *impl,
1929 ShortcutsIndex where)
1935 if (where == SHORTCUTS_SEARCH)
1938 n += impl->has_search ? 1 : 0;
1940 if (where == SHORTCUTS_RECENT)
1943 n += impl->has_recent ? 1 : 0;
1945 if (where == SHORTCUTS_RECENT_SEPARATOR)
1948 n += impl->has_recent ? 1 : 0;
1950 if (where == SHORTCUTS_HOME)
1953 n += impl->has_home ? 1 : 0;
1955 if (where == SHORTCUTS_DESKTOP)
1958 n += impl->has_desktop ? 1 : 0;
1960 if (where == SHORTCUTS_VOLUMES)
1963 n += impl->num_volumes;
1965 if (where == SHORTCUTS_SHORTCUTS)
1968 n += impl->num_shortcuts;
1970 if (where == SHORTCUTS_BOOKMARKS_SEPARATOR)
1973 /* If there are no bookmarks there won't be a separator */
1974 n += (impl->num_bookmarks > 0) ? 1 : 0;
1976 if (where == SHORTCUTS_BOOKMARKS)
1979 n += impl->num_bookmarks;
1981 if (where == SHORTCUTS_CURRENT_FOLDER_SEPARATOR)
1986 if (where == SHORTCUTS_CURRENT_FOLDER)
1989 g_assert_not_reached ();
1996 /* Adds all the file system volumes to the shortcuts model */
1998 shortcuts_add_volumes (GtkFileChooserDefault *impl)
2003 gboolean old_changing_folders;
2005 profile_start ("start", NULL);
2007 old_changing_folders = impl->changing_folder;
2008 impl->changing_folder = TRUE;
2010 start_row = shortcuts_get_index (impl, SHORTCUTS_VOLUMES);
2011 shortcuts_remove_rows (impl, start_row, impl->num_volumes);
2012 impl->num_volumes = 0;
2014 list = _gtk_file_system_list_volumes (impl->file_system);
2018 for (l = list; l; l = l->next)
2020 GtkFileSystemVolume *volume;
2024 if (impl->local_only)
2026 if (_gtk_file_system_volume_is_mounted (volume))
2029 gboolean base_is_native = TRUE;
2031 base_file = _gtk_file_system_volume_get_root (volume);
2032 if (base_file != NULL)
2034 base_is_native = g_file_is_native (base_file);
2035 g_object_unref (base_file);
2038 if (!base_is_native)
2043 shortcuts_insert_file (impl, start_row + n, SHORTCUT_TYPE_VOLUME, volume, NULL, NULL, FALSE, SHORTCUTS_VOLUMES);
2047 impl->num_volumes = n;
2048 g_slist_free (list);
2050 if (impl->shortcuts_pane_filter_model)
2051 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_pane_filter_model));
2053 if (impl->shortcuts_combo_filter_model)
2054 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_combo_filter_model));
2056 impl->changing_folder = old_changing_folders;
2058 profile_end ("end", NULL);
2061 /* Inserts a separator node in the shortcuts list */
2063 shortcuts_insert_separator (GtkFileChooserDefault *impl,
2064 ShortcutsIndex where)
2068 g_assert (where == SHORTCUTS_RECENT_SEPARATOR ||
2069 where == SHORTCUTS_BOOKMARKS_SEPARATOR ||
2070 where == SHORTCUTS_CURRENT_FOLDER_SEPARATOR);
2072 gtk_list_store_insert (impl->shortcuts_model, &iter,
2073 shortcuts_get_index (impl, where));
2074 gtk_list_store_set (impl->shortcuts_model, &iter,
2075 SHORTCUTS_COL_PIXBUF, NULL,
2076 SHORTCUTS_COL_PIXBUF_VISIBLE, FALSE,
2077 SHORTCUTS_COL_NAME, NULL,
2078 SHORTCUTS_COL_DATA, NULL,
2079 SHORTCUTS_COL_TYPE, SHORTCUT_TYPE_SEPARATOR,
2083 /* Updates the list of bookmarks */
2085 shortcuts_add_bookmarks (GtkFileChooserDefault *impl)
2088 gboolean old_changing_folders;
2090 GFile *list_selected = NULL;
2091 GFile *combo_selected = NULL;
2092 ShortcutType shortcut_type;
2095 profile_start ("start", NULL);
2097 old_changing_folders = impl->changing_folder;
2098 impl->changing_folder = TRUE;
2100 if (shortcuts_get_selected (impl, &iter))
2102 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model),
2104 SHORTCUTS_COL_DATA, &col_data,
2105 SHORTCUTS_COL_TYPE, &shortcut_type,
2108 if (col_data && shortcut_type == SHORTCUT_TYPE_FILE)
2109 list_selected = g_object_ref (col_data);
2112 if (impl->save_folder_combo &&
2113 gtk_combo_box_get_active_iter (GTK_COMBO_BOX (impl->save_folder_combo),
2116 GtkTreeIter child_iter;
2118 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (impl->shortcuts_combo_filter_model),
2121 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model),
2123 SHORTCUTS_COL_DATA, &col_data,
2124 SHORTCUTS_COL_TYPE, &shortcut_type,
2127 if (col_data && shortcut_type == SHORTCUT_TYPE_FILE)
2128 combo_selected = g_object_ref (col_data);
2131 if (impl->num_bookmarks > 0)
2132 shortcuts_remove_rows (impl,
2133 shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR),
2134 impl->num_bookmarks + 1);
2136 impl->num_bookmarks = 0;
2137 shortcuts_insert_separator (impl, SHORTCUTS_BOOKMARKS_SEPARATOR);
2139 bookmarks = _gtk_file_system_list_bookmarks (impl->file_system);
2140 shortcuts_append_bookmarks (impl, bookmarks);
2141 g_slist_foreach (bookmarks, (GFunc) g_object_unref, NULL);
2142 g_slist_free (bookmarks);
2144 if (impl->num_bookmarks == 0)
2145 shortcuts_remove_rows (impl, shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR), 1);
2147 if (impl->shortcuts_pane_filter_model)
2148 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_pane_filter_model));
2150 if (impl->shortcuts_combo_filter_model)
2151 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_combo_filter_model));
2155 shortcuts_find_folder (impl, list_selected);
2156 g_object_unref (list_selected);
2163 pos = shortcut_find_position (impl, combo_selected);
2166 if (impl->has_search)
2169 if (impl->has_recent)
2172 gtk_combo_box_set_active (GTK_COMBO_BOX (impl->save_folder_combo), pos);
2175 g_object_unref (combo_selected);
2178 impl->changing_folder = old_changing_folders;
2180 profile_end ("end", NULL);
2183 /* Appends a separator and a row to the shortcuts list for the current folder */
2185 shortcuts_add_current_folder (GtkFileChooserDefault *impl)
2190 g_assert (!impl->shortcuts_current_folder_active);
2194 g_assert (impl->current_folder != NULL);
2196 pos = shortcut_find_position (impl, impl->current_folder);
2199 GtkFileSystemVolume *volume;
2204 shortcuts_insert_separator (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR);
2208 pos = shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER);
2210 volume = _gtk_file_system_get_volume_for_file (impl->file_system, impl->current_folder);
2212 base_file = _gtk_file_system_volume_get_root (volume);
2216 if (base_file && g_file_equal (base_file, impl->current_folder))
2217 shortcuts_insert_file (impl, pos, SHORTCUT_TYPE_VOLUME, volume, NULL, NULL, FALSE, SHORTCUTS_CURRENT_FOLDER);
2219 shortcuts_insert_file (impl, pos, SHORTCUT_TYPE_FILE, NULL, impl->current_folder, NULL, FALSE, SHORTCUTS_CURRENT_FOLDER);
2222 g_object_unref (base_file);
2224 else if (impl->save_folder_combo != NULL)
2226 if (impl->has_search)
2229 if (impl->has_recent)
2230 pos -= 2; /* + separator */
2232 gtk_combo_box_set_active (GTK_COMBO_BOX (impl->save_folder_combo), pos);
2236 /* Updates the current folder row in the shortcuts model */
2238 shortcuts_update_current_folder (GtkFileChooserDefault *impl)
2242 pos = shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR);
2244 if (impl->shortcuts_current_folder_active)
2246 shortcuts_remove_rows (impl, pos, 2);
2247 impl->shortcuts_current_folder_active = FALSE;
2250 shortcuts_add_current_folder (impl);
2253 /* Filter function used for the shortcuts filter model */
2255 shortcuts_pane_filter_cb (GtkTreeModel *model,
2259 GtkFileChooserDefault *impl;
2263 impl = GTK_FILE_CHOOSER_DEFAULT (data);
2265 path = gtk_tree_model_get_path (model, iter);
2269 pos = *gtk_tree_path_get_indices (path);
2270 gtk_tree_path_free (path);
2272 return (pos < shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR));
2275 /* Creates the list model for shortcuts */
2277 shortcuts_model_create (GtkFileChooserDefault *impl)
2279 /* Keep this order in sync with the SHORCUTS_COL_* enum values */
2280 impl->shortcuts_model = gtk_list_store_new (SHORTCUTS_COL_NUM_COLUMNS,
2281 GDK_TYPE_PIXBUF, /* pixbuf */
2282 G_TYPE_STRING, /* name */
2283 G_TYPE_POINTER, /* path or volume */
2284 G_TYPE_INT, /* ShortcutType */
2285 G_TYPE_BOOLEAN, /* removable */
2286 G_TYPE_BOOLEAN, /* pixbuf cell visibility */
2287 G_TYPE_POINTER); /* GCancellable */
2289 if (search_is_possible (impl))
2291 shortcuts_append_search (impl);
2294 if (impl->recent_manager)
2296 shortcuts_append_recent (impl);
2297 shortcuts_insert_separator (impl, SHORTCUTS_RECENT_SEPARATOR);
2300 if (impl->file_system)
2302 shortcuts_append_home (impl);
2303 shortcuts_append_desktop (impl);
2304 shortcuts_add_volumes (impl);
2307 impl->shortcuts_pane_filter_model = shortcuts_pane_model_filter_new (impl,
2308 GTK_TREE_MODEL (impl->shortcuts_model),
2311 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (impl->shortcuts_pane_filter_model),
2312 shortcuts_pane_filter_cb,
2317 /* Callback used when the "New Folder" button is clicked */
2319 new_folder_button_clicked (GtkButton *button,
2320 GtkFileChooserDefault *impl)
2325 if (!impl->browse_files_model)
2326 return; /* FIXME: this sucks. Disable the New Folder button or something. */
2328 /* Prevent button from being clicked twice */
2329 gtk_widget_set_sensitive (impl->browse_new_folder_button, FALSE);
2331 _gtk_file_system_model_add_editable (impl->browse_files_model, &iter);
2333 path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->browse_files_model), &iter);
2334 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (impl->browse_files_tree_view),
2335 path, impl->list_name_column,
2338 g_object_set (impl->list_name_renderer, "editable", TRUE, NULL);
2339 gtk_tree_view_set_cursor (GTK_TREE_VIEW (impl->browse_files_tree_view),
2341 impl->list_name_column,
2344 gtk_tree_path_free (path);
2347 /* Idle handler for creating a new folder after editing its name cell, or for
2348 * canceling the editing.
2351 edited_idle_cb (GtkFileChooserDefault *impl)
2353 GDK_THREADS_ENTER ();
2355 g_source_destroy (impl->edited_idle);
2356 impl->edited_idle = NULL;
2358 _gtk_file_system_model_remove_editable (impl->browse_files_model);
2359 g_object_set (impl->list_name_renderer, "editable", FALSE, NULL);
2361 gtk_widget_set_sensitive (impl->browse_new_folder_button, TRUE);
2363 if (impl->edited_new_text /* not cancelled? */
2364 && (strlen (impl->edited_new_text) != 0)
2365 && (strcmp (impl->edited_new_text, DEFAULT_NEW_FOLDER_NAME) != 0)) /* Don't create folder if name is empty or has not been edited */
2367 GError *error = NULL;
2370 file = g_file_get_child_for_display_name (impl->current_folder,
2371 impl->edited_new_text,
2375 GError *error = NULL;
2377 if (g_file_make_directory (file, NULL, &error))
2378 change_folder_and_display_error (impl, file, FALSE);
2380 error_creating_folder_dialog (impl, file, error);
2382 g_object_unref (file);
2385 error_creating_folder_dialog (impl, file, error);
2387 g_free (impl->edited_new_text);
2388 impl->edited_new_text = NULL;
2391 GDK_THREADS_LEAVE ();
2397 queue_edited_idle (GtkFileChooserDefault *impl,
2398 const gchar *new_text)
2400 /* We create the folder in an idle handler so that we don't modify the tree
2404 if (!impl->edited_idle)
2406 impl->edited_idle = g_idle_source_new ();
2407 g_source_set_closure (impl->edited_idle,
2408 g_cclosure_new_object (G_CALLBACK (edited_idle_cb),
2410 g_source_attach (impl->edited_idle, NULL);
2413 g_free (impl->edited_new_text);
2414 impl->edited_new_text = g_strdup (new_text);
2417 /* Callback used from the text cell renderer when the new folder is named */
2419 renderer_edited_cb (GtkCellRendererText *cell_renderer_text,
2421 const gchar *new_text,
2422 GtkFileChooserDefault *impl)
2424 /* work around bug #154921 */
2425 g_object_set (cell_renderer_text,
2426 "mode", GTK_CELL_RENDERER_MODE_INERT, NULL);
2427 queue_edited_idle (impl, new_text);
2430 /* Callback used from the text cell renderer when the new folder edition gets
2434 renderer_editing_canceled_cb (GtkCellRendererText *cell_renderer_text,
2435 GtkFileChooserDefault *impl)
2437 /* work around bug #154921 */
2438 g_object_set (cell_renderer_text,
2439 "mode", GTK_CELL_RENDERER_MODE_INERT, NULL);
2440 queue_edited_idle (impl, NULL);
2443 /* Creates the widgets for the filter combo box */
2445 filter_create (GtkFileChooserDefault *impl)
2447 impl->filter_combo = gtk_combo_box_new_text ();
2448 gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (impl->filter_combo), FALSE);
2450 g_signal_connect (impl->filter_combo, "changed",
2451 G_CALLBACK (filter_combo_changed), impl);
2453 gtk_widget_set_tooltip_text (impl->filter_combo,
2454 _("Select which types of files are shown"));
2456 return impl->filter_combo;
2460 button_new (GtkFileChooserDefault *impl,
2462 const char *stock_id,
2470 button = gtk_button_new_with_mnemonic (text);
2471 image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
2472 gtk_button_set_image (GTK_BUTTON (button), image);
2474 gtk_widget_set_sensitive (button, sensitive);
2475 g_signal_connect (button, "clicked", callback, impl);
2478 gtk_widget_show (button);
2483 /* Looks for a path among the shortcuts; returns its index or -1 if it doesn't exist */
2485 shortcut_find_position (GtkFileChooserDefault *impl,
2490 int current_folder_separator_idx;
2492 if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
2495 current_folder_separator_idx = shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR);
2498 /* FIXME: is this still needed? */
2499 if (current_folder_separator_idx >= impl->shortcuts_model->length)
2503 for (i = 0; i < current_folder_separator_idx; i++)
2506 ShortcutType shortcut_type;
2508 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
2509 SHORTCUTS_COL_DATA, &col_data,
2510 SHORTCUTS_COL_TYPE, &shortcut_type,
2515 if (shortcut_type == SHORTCUT_TYPE_VOLUME)
2517 GtkFileSystemVolume *volume;
2522 base_file = _gtk_file_system_volume_get_root (volume);
2524 exists = base_file && g_file_equal (file, base_file);
2527 g_object_unref (base_file);
2532 else if (shortcut_type == SHORTCUT_TYPE_FILE)
2536 model_file = col_data;
2538 if (model_file && g_file_equal (model_file, file))
2543 if (i < current_folder_separator_idx - 1)
2545 if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
2546 g_assert_not_reached ();
2553 /* Tries to add a bookmark from a path name */
2555 shortcuts_add_bookmark_from_file (GtkFileChooserDefault *impl,
2561 g_return_val_if_fail (G_IS_FILE (file), FALSE);
2563 if (shortcut_find_position (impl, file) != -1)
2567 if (!_gtk_file_system_insert_bookmark (impl->file_system, file, pos, &error))
2569 error_adding_bookmark_dialog (impl, file, error);
2577 add_bookmark_foreach_cb (GtkTreeModel *model,
2582 GtkFileChooserDefault *impl;
2585 impl = (GtkFileChooserDefault *) data;
2587 gtk_tree_model_get (model, iter,
2588 MODEL_COL_FILE, &file,
2591 shortcuts_add_bookmark_from_file (impl, file, -1);
2593 g_object_unref (file);
2596 /* Adds a bookmark from the currently selected item in the file list */
2598 bookmarks_add_selected_folder (GtkFileChooserDefault *impl)
2600 GtkTreeSelection *selection;
2602 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
2604 if (gtk_tree_selection_count_selected_rows (selection) == 0)
2605 shortcuts_add_bookmark_from_file (impl, impl->current_folder, -1);
2607 gtk_tree_selection_selected_foreach (selection,
2608 add_bookmark_foreach_cb,
2612 /* Callback used when the "Add bookmark" button is clicked */
2614 add_bookmark_button_clicked_cb (GtkButton *button,
2615 GtkFileChooserDefault *impl)
2617 bookmarks_add_selected_folder (impl);
2620 /* Returns TRUE plus an iter in the shortcuts_model if a row is selected;
2621 * returns FALSE if no shortcut is selected.
2624 shortcuts_get_selected (GtkFileChooserDefault *impl,
2627 GtkTreeSelection *selection;
2628 GtkTreeIter parent_iter;
2630 if (!impl->browse_shortcuts_tree_view)
2633 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view));
2635 if (!gtk_tree_selection_get_selected (selection, NULL, &parent_iter))
2638 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (impl->shortcuts_pane_filter_model),
2644 /* Removes the selected bookmarks */
2646 remove_selected_bookmarks (GtkFileChooserDefault *impl)
2654 if (!shortcuts_get_selected (impl, &iter))
2657 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
2658 SHORTCUTS_COL_DATA, &col_data,
2659 SHORTCUTS_COL_REMOVABLE, &removable,
2665 g_assert (col_data != NULL);
2670 if (!_gtk_file_system_remove_bookmark (impl->file_system, file, &error))
2671 error_removing_bookmark_dialog (impl, file, error);
2674 /* Callback used when the "Remove bookmark" button is clicked */
2676 remove_bookmark_button_clicked_cb (GtkButton *button,
2677 GtkFileChooserDefault *impl)
2679 remove_selected_bookmarks (impl);
2682 struct selection_check_closure {
2683 GtkFileChooserDefault *impl;
2686 gboolean all_folders;
2689 /* Used from gtk_tree_selection_selected_foreach() */
2691 selection_check_foreach_cb (GtkTreeModel *model,
2696 struct selection_check_closure *closure;
2700 gtk_tree_model_get (model, iter,
2701 MODEL_COL_FILE, &file,
2702 MODEL_COL_IS_FOLDER, &is_folder,
2708 g_object_unref (file);
2711 closure->num_selected++;
2713 closure->all_folders = closure->all_folders && is_folder;
2714 closure->all_files = closure->all_files && !is_folder;
2717 /* Checks whether the selected items in the file list are all files or all folders */
2719 selection_check (GtkFileChooserDefault *impl,
2721 gboolean *all_files,
2722 gboolean *all_folders)
2724 struct selection_check_closure closure;
2725 GtkTreeSelection *selection;
2727 closure.impl = impl;
2728 closure.num_selected = 0;
2729 closure.all_files = TRUE;
2730 closure.all_folders = TRUE;
2732 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
2733 gtk_tree_selection_selected_foreach (selection,
2734 selection_check_foreach_cb,
2737 g_assert (closure.num_selected == 0 || !(closure.all_files && closure.all_folders));
2740 *num_selected = closure.num_selected;
2743 *all_files = closure.all_files;
2746 *all_folders = closure.all_folders;
2749 struct get_selected_file_closure {
2750 GtkFileChooserDefault *impl;
2755 get_selected_file_foreach_cb (GtkTreeModel *model,
2760 struct get_selected_file_closure *closure = data;
2762 gtk_tree_model_get (model, iter,
2763 MODEL_COL_FILE, &closure->file,
2766 g_object_unref (closure->file);
2769 /* Returns a selected path from the file list */
2771 get_selected_file (GtkFileChooserDefault *impl)
2773 struct get_selected_file_closure closure;
2774 GtkTreeSelection *selection;
2776 closure.impl = impl;
2777 closure.file = NULL;
2779 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
2780 gtk_tree_selection_selected_foreach (selection,
2781 get_selected_file_foreach_cb,
2784 return closure.file;
2788 GtkFileChooserDefault *impl;
2790 } UpdateTooltipData;
2793 update_tooltip (GtkTreeModel *model,
2798 UpdateTooltipData *udata = data;
2800 if (udata->tip == NULL)
2802 gchar *display_name;
2804 gtk_tree_model_get (model, iter,
2805 MODEL_COL_NAME, &display_name,
2808 udata->tip = g_strdup_printf (_("Add the folder '%s' to the bookmarks"),
2810 g_free (display_name);
2815 /* Sensitize the "add bookmark" button if all the selected items are folders, or
2816 * if there are no selected items *and* the current folder is not in the
2817 * bookmarks list. De-sensitize the button otherwise.
2820 bookmarks_check_add_sensitivity (GtkFileChooserDefault *impl)
2823 gboolean all_folders;
2827 selection_check (impl, &num_selected, NULL, &all_folders);
2829 if (num_selected == 0)
2830 active = (impl->current_folder != NULL) && (shortcut_find_position (impl, impl->current_folder) == -1);
2831 else if (num_selected == 1)
2835 file = get_selected_file (impl);
2836 active = file && all_folders && (shortcut_find_position (impl, file) == -1);
2839 active = all_folders;
2841 gtk_widget_set_sensitive (impl->browse_shortcuts_add_button, active);
2843 if (impl->browse_files_popup_menu_add_shortcut_item)
2844 gtk_widget_set_sensitive (impl->browse_files_popup_menu_add_shortcut_item,
2845 (num_selected == 0) ? FALSE : active);
2849 if (num_selected == 0)
2850 tip = g_strdup_printf (_("Add the current folder to the bookmarks"));
2851 else if (num_selected > 1)
2852 tip = g_strdup_printf (_("Add the selected folders to the bookmarks"));
2855 GtkTreeSelection *selection;
2856 UpdateTooltipData data;
2858 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
2861 gtk_tree_selection_selected_foreach (selection, update_tooltip, &data);
2865 gtk_widget_set_tooltip_text (impl->browse_shortcuts_add_button, tip);
2870 /* Sets the sensitivity of the "remove bookmark" button depending on whether a
2871 * bookmark row is selected in the shortcuts tree.
2874 bookmarks_check_remove_sensitivity (GtkFileChooserDefault *impl)
2877 gboolean removable = FALSE;
2881 if (shortcuts_get_selected (impl, &iter))
2883 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
2884 SHORTCUTS_COL_REMOVABLE, &removable,
2885 SHORTCUTS_COL_NAME, &name,
2887 gtk_widget_set_sensitive (impl->browse_shortcuts_remove_button, removable);
2890 tip = g_strdup_printf (_("Remove the bookmark '%s'"), name);
2892 tip = g_strdup_printf (_("Bookmark '%s' cannot be removed"), name);
2894 gtk_widget_set_tooltip_text (impl->browse_shortcuts_remove_button, tip);
2898 gtk_widget_set_tooltip_text (impl->browse_shortcuts_remove_button,
2899 _("Remove the selected bookmark"));
2904 shortcuts_check_popup_sensitivity (GtkFileChooserDefault *impl)
2907 gboolean removable = FALSE;
2909 if (impl->browse_shortcuts_popup_menu == NULL)
2912 if (shortcuts_get_selected (impl, &iter))
2913 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
2914 SHORTCUTS_COL_REMOVABLE, &removable,
2917 gtk_widget_set_sensitive (impl->browse_shortcuts_popup_menu_remove_item, removable);
2918 gtk_widget_set_sensitive (impl->browse_shortcuts_popup_menu_rename_item, removable);
2921 /* GtkWidget::drag-begin handler for the shortcuts list. */
2923 shortcuts_drag_begin_cb (GtkWidget *widget,
2924 GdkDragContext *context,
2925 GtkFileChooserDefault *impl)
2928 impl->shortcuts_drag_context = g_object_ref (context);
2933 /* Removes the idle handler for outside drags */
2935 shortcuts_cancel_drag_outside_idle (GtkFileChooserDefault *impl)
2937 if (!impl->shortcuts_drag_outside_idle)
2940 g_source_destroy (impl->shortcuts_drag_outside_idle);
2941 impl->shortcuts_drag_outside_idle = NULL;
2945 /* GtkWidget::drag-end handler for the shortcuts list. */
2947 shortcuts_drag_end_cb (GtkWidget *widget,
2948 GdkDragContext *context,
2949 GtkFileChooserDefault *impl)
2952 g_object_unref (impl->shortcuts_drag_context);
2954 shortcuts_cancel_drag_outside_idle (impl);
2956 if (!impl->shortcuts_drag_outside)
2959 gtk_button_clicked (GTK_BUTTON (impl->browse_shortcuts_remove_button));
2961 impl->shortcuts_drag_outside = FALSE;
2965 /* GtkWidget::drag-data-delete handler for the shortcuts list. */
2967 shortcuts_drag_data_delete_cb (GtkWidget *widget,
2968 GdkDragContext *context,
2969 GtkFileChooserDefault *impl)
2971 g_signal_stop_emission_by_name (widget, "drag-data-delete");
2975 /* Creates a suitable drag cursor to indicate that the selected bookmark will be
2979 shortcuts_drag_set_delete_cursor (GtkFileChooserDefault *impl,
2982 GtkTreeView *tree_view;
2985 GdkPixmap *row_pixmap;
2990 tree_view = GTK_TREE_VIEW (impl->browse_shortcuts_tree_view);
2992 /* Find the selected path and get its drag pixmap */
2994 if (!shortcuts_get_selected (impl, &iter))
2995 g_assert_not_reached ();
2997 path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
2999 row_pixmap = gtk_tree_view_create_row_drag_icon (tree_view, path);
3000 gtk_tree_path_free (path);
3009 pixbuf = gtk_widget_render_icon (impl->browse_shortcuts_tree_view,
3015 GdkPixmap *composite;
3016 int row_pixmap_width, row_pixmap_height;
3017 int pixbuf_width, pixbuf_height;
3018 int composite_width, composite_height;
3019 int pixbuf_x, pixbuf_y;
3020 GdkGC *gc, *mask_gc;
3022 GdkBitmap *pixbuf_mask;
3024 /* Create pixmap and mask for composite image */
3026 gdk_drawable_get_size (row_pixmap, &row_pixmap_width, &row_pixmap_height);
3027 pixbuf_width = gdk_pixbuf_get_width (pixbuf);
3028 pixbuf_height = gdk_pixbuf_get_height (pixbuf);
3030 composite_width = MAX (row_pixmap_width, pixbuf_width);
3031 composite_height = MAX (row_pixmap_height, pixbuf_height);
3033 row_pixmap_y = (composite_height - row_pixmap_height) / 2;
3035 if (gtk_widget_get_direction (impl->browse_shortcuts_tree_view) == GTK_TEXT_DIR_RTL)
3038 pixbuf_x = composite_width - pixbuf_width;
3040 pixbuf_y = (composite_height - pixbuf_height) / 2;
3042 composite = gdk_pixmap_new (row_pixmap, composite_width, composite_height, -1);
3043 gc = gdk_gc_new (composite);
3045 mask = gdk_pixmap_new (row_pixmap, composite_width, composite_height, 1);
3046 mask_gc = gdk_gc_new (mask);
3048 gdk_gc_set_foreground (mask_gc, &color);
3049 gdk_draw_rectangle (mask, mask_gc, TRUE, 0, 0, composite_width, composite_height);
3052 color.green = 0xffff;
3053 color.blue = 0xffff;
3054 gdk_gc_set_rgb_fg_color (gc, &color);
3055 gdk_draw_rectangle (composite, gc, TRUE, 0, 0, composite_width, composite_height);
3057 /* Composite the row pixmap and the pixbuf */
3059 gdk_pixbuf_render_pixmap_and_mask_for_colormap
3061 gtk_widget_get_colormap (impl->browse_shortcuts_tree_view),
3062 NULL, &pixbuf_mask, 128);
3063 gdk_draw_drawable (mask, mask_gc, pixbuf_mask,
3066 pixbuf_width, pixbuf_height);
3067 g_object_unref (pixbuf_mask);
3069 gdk_draw_drawable (composite, gc, row_pixmap,
3072 row_pixmap_width, row_pixmap_height);
3074 gdk_gc_set_foreground (mask_gc, &color);
3075 gdk_draw_rectangle (mask, mask_gc, TRUE, 0, row_pixmap_y, row_pixmap_width, row_pixmap_height);
3077 gdk_draw_pixbuf (composite, gc, pixbuf,
3080 pixbuf_width, pixbuf_height,
3084 g_object_unref (pixbuf);
3085 g_object_unref (row_pixmap);
3087 row_pixmap = composite;
3091 /* The hotspot offsets here are copied from gtk_tree_view_drag_begin(), ugh */
3093 gtk_tree_view_get_path_at_pos (tree_view,
3094 tree_view->priv->press_start_x,
3095 tree_view->priv->press_start_y,
3101 gtk_drag_set_icon_pixmap (impl->shortcuts_drag_context,
3102 gdk_drawable_get_colormap (row_pixmap),
3105 tree_view->priv->press_start_x + 1,
3106 row_pixmap_y + cell_y + 1);
3108 g_object_unref (row_pixmap);
3110 g_object_unref (mask);
3113 /* We set the delete cursor and the shortcuts_drag_outside flag in an idle
3114 * handler so that we can tell apart the drag_leave event that comes right
3115 * before a drag_drop, from a normal drag_leave. We don't want to set the
3116 * cursor nor the flag in the latter case.
3119 shortcuts_drag_outside_idle_cb (GtkFileChooserDefault *impl)
3121 GDK_THREADS_ENTER ();
3123 shortcuts_drag_set_delete_cursor (impl, TRUE);
3124 impl->shortcuts_drag_outside = TRUE;
3126 shortcuts_cancel_drag_outside_idle (impl);
3128 GDK_THREADS_LEAVE ();
3134 /* GtkWidget::drag-leave handler for the shortcuts list. We unhighlight the
3138 shortcuts_drag_leave_cb (GtkWidget *widget,
3139 GdkDragContext *context,
3141 GtkFileChooserDefault *impl)
3144 if (gtk_drag_get_source_widget (context) == widget && !impl->shortcuts_drag_outside_idle)
3146 impl->shortcuts_drag_outside_idle = g_idle_source_new ();
3147 g_source_set_closure (impl->shortcuts_drag_outside_idle,
3148 g_cclosure_new_object (G_CALLBACK (shortcuts_drag_outside_idle_cb),
3150 g_source_attach (impl->shortcuts_drag_outside_idle, NULL);
3154 gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view),
3156 GTK_TREE_VIEW_DROP_BEFORE);
3158 g_signal_stop_emission_by_name (widget, "drag-leave");
3161 /* Computes the appropriate row and position for dropping */
3163 shortcuts_compute_drop_position (GtkFileChooserDefault *impl,
3167 GtkTreeViewDropPosition *pos)
3169 GtkTreeView *tree_view;
3170 GtkTreeViewColumn *column;
3174 int bookmarks_index;
3176 tree_view = GTK_TREE_VIEW (impl->browse_shortcuts_tree_view);
3178 bookmarks_index = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS);
3180 if (!gtk_tree_view_get_path_at_pos (tree_view,
3182 y - TREE_VIEW_HEADER_HEIGHT (tree_view),
3188 row = bookmarks_index + impl->num_bookmarks - 1;
3189 *path = gtk_tree_path_new_from_indices (row, -1);
3190 *pos = GTK_TREE_VIEW_DROP_AFTER;
3194 row = *gtk_tree_path_get_indices (*path);
3195 gtk_tree_view_get_background_area (tree_view, *path, column, &cell);
3196 gtk_tree_path_free (*path);
3198 if (row < bookmarks_index)
3200 row = bookmarks_index;
3201 *pos = GTK_TREE_VIEW_DROP_BEFORE;
3203 else if (row > bookmarks_index + impl->num_bookmarks - 1)
3205 row = bookmarks_index + impl->num_bookmarks - 1;
3206 *pos = GTK_TREE_VIEW_DROP_AFTER;
3210 if (cell_y < cell.height / 2)
3211 *pos = GTK_TREE_VIEW_DROP_BEFORE;
3213 *pos = GTK_TREE_VIEW_DROP_AFTER;
3216 *path = gtk_tree_path_new_from_indices (row, -1);
3219 /* GtkWidget::drag-motion handler for the shortcuts list. We basically
3220 * implement the destination side of DnD by hand, due to limitations in
3221 * GtkTreeView's DnD API.
3224 shortcuts_drag_motion_cb (GtkWidget *widget,
3225 GdkDragContext *context,
3229 GtkFileChooserDefault *impl)
3232 GtkTreeViewDropPosition pos;
3233 GdkDragAction action;
3236 if (gtk_drag_get_source_widget (context) == widget)
3238 shortcuts_cancel_drag_outside_idle (impl);
3240 if (impl->shortcuts_drag_outside)
3242 shortcuts_drag_set_delete_cursor (impl, FALSE);
3243 impl->shortcuts_drag_outside = FALSE;
3248 if (context->suggested_action == GDK_ACTION_COPY ||
3249 (context->actions & GDK_ACTION_COPY) != 0)
3250 action = GDK_ACTION_COPY;
3251 else if (context->suggested_action == GDK_ACTION_MOVE ||
3252 (context->actions & GDK_ACTION_MOVE) != 0)
3253 action = GDK_ACTION_MOVE;
3260 shortcuts_compute_drop_position (impl, x, y, &path, &pos);
3261 gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), path, pos);
3262 gtk_tree_path_free (path);
3266 g_signal_stop_emission_by_name (widget, "drag-motion");
3270 gdk_drag_status (context, action, time_);
3277 /* GtkWidget::drag-drop handler for the shortcuts list. */
3279 shortcuts_drag_drop_cb (GtkWidget *widget,
3280 GdkDragContext *context,
3284 GtkFileChooserDefault *impl)
3287 shortcuts_cancel_drag_outside_idle (impl);
3290 g_signal_stop_emission_by_name (widget, "drag-drop");
3294 /* Parses a "text/uri-list" string and inserts its URIs as bookmarks */
3296 shortcuts_drop_uris (GtkFileChooserDefault *impl,
3297 GtkSelectionData *selection_data,
3303 uris = gtk_selection_data_get_uris (selection_data);
3307 for (i = 0; uris[i]; i++)
3313 file = g_file_new_for_uri (uri);
3315 if (shortcuts_add_bookmark_from_file (impl, file, position))
3318 g_object_unref (file);
3324 /* Reorders the selected bookmark to the specified position */
3326 shortcuts_reorder (GtkFileChooserDefault *impl,
3331 ShortcutType shortcut_type;
3334 int bookmarks_index;
3339 /* Get the selected path */
3341 if (!shortcuts_get_selected (impl, &iter))
3342 g_assert_not_reached ();
3344 path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
3345 old_position = *gtk_tree_path_get_indices (path);
3346 gtk_tree_path_free (path);
3348 bookmarks_index = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS);
3349 old_position -= bookmarks_index;
3350 g_assert (old_position >= 0 && old_position < impl->num_bookmarks);
3352 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
3353 SHORTCUTS_COL_NAME, &name,
3354 SHORTCUTS_COL_DATA, &col_data,
3355 SHORTCUTS_COL_TYPE, &shortcut_type,
3357 g_assert (col_data != NULL);
3358 g_assert (shortcut_type == SHORTCUT_TYPE_FILE);
3361 g_object_ref (file); /* removal below will free file, so we need a new ref */
3363 /* Remove the path from the old position and insert it in the new one */
3365 if (new_position > old_position)
3368 if (old_position == new_position)
3372 if (_gtk_file_system_remove_bookmark (impl->file_system, file, &error))
3374 shortcuts_add_bookmark_from_file (impl, file, new_position);
3375 _gtk_file_system_set_bookmark_label (impl->file_system, file, name);
3378 error_adding_bookmark_dialog (impl, file, error);
3382 g_object_unref (file);
3385 /* Callback used when we get the drag data for the bookmarks list. We add the
3386 * received URIs as bookmarks if they are folders.
3389 shortcuts_drag_data_received_cb (GtkWidget *widget,
3390 GdkDragContext *context,
3393 GtkSelectionData *selection_data,
3398 GtkFileChooserDefault *impl;
3399 GtkTreePath *tree_path;
3400 GtkTreeViewDropPosition tree_pos;
3402 int bookmarks_index;
3404 impl = GTK_FILE_CHOOSER_DEFAULT (data);
3406 /* Compute position */
3408 bookmarks_index = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS);
3410 shortcuts_compute_drop_position (impl, x, y, &tree_path, &tree_pos);
3411 position = *gtk_tree_path_get_indices (tree_path);
3412 gtk_tree_path_free (tree_path);
3414 if (tree_pos == GTK_TREE_VIEW_DROP_AFTER)
3417 g_assert (position >= bookmarks_index);
3418 position -= bookmarks_index;
3420 if (gtk_targets_include_uri (&selection_data->target, 1))
3421 shortcuts_drop_uris (impl, selection_data, position);
3422 else if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
3423 shortcuts_reorder (impl, position);
3425 g_signal_stop_emission_by_name (widget, "drag-data-received");
3428 /* Callback used to display a tooltip in the shortcuts tree */
3430 shortcuts_query_tooltip_cb (GtkWidget *widget,
3433 gboolean keyboard_mode,
3434 GtkTooltip *tooltip,
3435 GtkFileChooserDefault *impl)
3437 GtkTreeModel *model;
3440 if (gtk_tree_view_get_tooltip_context (GTK_TREE_VIEW (widget),
3448 ShortcutType shortcut_type;
3450 gtk_tree_model_get (model, &iter,
3451 SHORTCUTS_COL_DATA, &col_data,
3452 SHORTCUTS_COL_TYPE, &shortcut_type,
3455 if (shortcut_type == SHORTCUT_TYPE_SEPARATOR)
3457 else if (shortcut_type == SHORTCUT_TYPE_VOLUME)
3461 else if (shortcut_type == SHORTCUT_TYPE_FILE)
3466 file = G_FILE (col_data);
3467 parse_name = g_file_get_parse_name (file);
3469 gtk_tooltip_set_text (tooltip, parse_name);
3471 g_free (parse_name);
3475 else if (shortcut_type == SHORTCUT_TYPE_SEARCH)
3479 else if (shortcut_type == SHORTCUT_TYPE_RECENT)
3489 /* Callback used when the selection in the shortcuts tree changes */
3491 shortcuts_selection_changed_cb (GtkTreeSelection *selection,
3492 GtkFileChooserDefault *impl)
3495 GtkTreeIter child_iter;
3497 bookmarks_check_remove_sensitivity (impl);
3498 shortcuts_check_popup_sensitivity (impl);
3500 if (impl->changing_folder)
3503 if (gtk_tree_selection_get_selected(selection, NULL, &iter))
3505 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (impl->shortcuts_pane_filter_model),
3508 shortcuts_activate_iter (impl, &child_iter);
3513 shortcuts_row_separator_func (GtkTreeModel *model,
3517 ShortcutType shortcut_type;
3519 gtk_tree_model_get (model, iter, SHORTCUTS_COL_TYPE, &shortcut_type, -1);
3521 return shortcut_type == SHORTCUT_TYPE_SEPARATOR;
3525 shortcuts_key_press_event_after_cb (GtkWidget *tree_view,
3527 GtkFileChooserDefault *impl)
3531 /* don't screw up focus switching with Tab */
3532 if (event->keyval == GDK_Tab
3533 || event->keyval == GDK_KP_Tab
3534 || event->keyval == GDK_ISO_Left_Tab
3535 || event->length < 1)
3538 if (impl->location_entry)
3539 entry = impl->location_entry;
3540 else if (impl->search_entry)
3541 entry = impl->search_entry;
3547 gtk_widget_grab_focus (entry);
3548 return gtk_widget_event (entry, (GdkEvent *) event);
3554 /* Callback used when the file list's popup menu is detached */
3556 shortcuts_popup_menu_detach_cb (GtkWidget *attach_widget,
3559 GtkFileChooserDefault *impl;
3561 impl = g_object_get_data (G_OBJECT (attach_widget), "GtkFileChooserDefault");
3562 g_assert (GTK_IS_FILE_CHOOSER_DEFAULT (impl));
3564 impl->browse_shortcuts_popup_menu = NULL;
3565 impl->browse_shortcuts_popup_menu_remove_item = NULL;
3566 impl->browse_shortcuts_popup_menu_rename_item = NULL;
3570 remove_shortcut_cb (GtkMenuItem *item,
3571 GtkFileChooserDefault *impl)
3573 remove_selected_bookmarks (impl);
3576 /* Rename the selected bookmark */
3578 rename_selected_bookmark (GtkFileChooserDefault *impl)
3582 GtkTreeViewColumn *column;
3583 GtkCellRenderer *cell;
3586 if (shortcuts_get_selected (impl, &iter))
3588 path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
3589 column = gtk_tree_view_get_column (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), 0);
3590 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column));
3591 cell = g_list_nth_data (renderers, 1);
3592 g_list_free (renderers);
3593 g_object_set (cell, "editable", TRUE, NULL);
3594 gtk_tree_view_set_cursor_on_cell (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view),
3595 path, column, cell, TRUE);
3596 gtk_tree_path_free (path);
3601 rename_shortcut_cb (GtkMenuItem *item,
3602 GtkFileChooserDefault *impl)
3604 rename_selected_bookmark (impl);
3607 /* Constructs the popup menu for the file list if needed */
3609 shortcuts_build_popup_menu (GtkFileChooserDefault *impl)
3613 if (impl->browse_shortcuts_popup_menu)
3616 impl->browse_shortcuts_popup_menu = gtk_menu_new ();
3617 gtk_menu_attach_to_widget (GTK_MENU (impl->browse_shortcuts_popup_menu),
3618 impl->browse_shortcuts_tree_view,
3619 shortcuts_popup_menu_detach_cb);
3621 item = gtk_image_menu_item_new_with_label (_("Remove"));
3622 impl->browse_shortcuts_popup_menu_remove_item = item;
3623 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
3624 gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU));
3625 g_signal_connect (item, "activate",
3626 G_CALLBACK (remove_shortcut_cb), impl);
3627 gtk_widget_show (item);
3628 gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_shortcuts_popup_menu), item);
3630 item = gtk_menu_item_new_with_label (_("Rename..."));
3631 impl->browse_shortcuts_popup_menu_rename_item = item;
3632 g_signal_connect (item, "activate",
3633 G_CALLBACK (rename_shortcut_cb), impl);
3634 gtk_widget_show (item);
3635 gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_shortcuts_popup_menu), item);
3639 shortcuts_update_popup_menu (GtkFileChooserDefault *impl)
3641 shortcuts_build_popup_menu (impl);
3642 shortcuts_check_popup_sensitivity (impl);
3646 popup_position_func (GtkMenu *menu,
3650 gpointer user_data);
3653 shortcuts_popup_menu (GtkFileChooserDefault *impl,
3654 GdkEventButton *event)
3656 shortcuts_update_popup_menu (impl);
3658 gtk_menu_popup (GTK_MENU (impl->browse_shortcuts_popup_menu),
3659 NULL, NULL, NULL, NULL,
3660 event->button, event->time);
3663 gtk_menu_popup (GTK_MENU (impl->browse_shortcuts_popup_menu),
3665 popup_position_func, impl->browse_shortcuts_tree_view,
3666 0, GDK_CURRENT_TIME);
3667 gtk_menu_shell_select_first (GTK_MENU_SHELL (impl->browse_shortcuts_popup_menu),
3672 /* Callback used for the GtkWidget::popup-menu signal of the shortcuts list */
3674 shortcuts_popup_menu_cb (GtkWidget *widget,
3675 GtkFileChooserDefault *impl)
3677 shortcuts_popup_menu (impl, NULL);
3681 /* Callback used when a button is pressed on the shortcuts list.
3682 * We trap button 3 to bring up a popup menu.
3685 shortcuts_button_press_event_cb (GtkWidget *widget,
3686 GdkEventButton *event,
3687 GtkFileChooserDefault *impl)
3689 static gboolean in_press = FALSE;
3695 if (event->button != 3)
3699 handled = gtk_widget_event (impl->browse_shortcuts_tree_view, (GdkEvent *) event);
3705 shortcuts_popup_menu (impl, event);
3710 shortcuts_edited (GtkCellRenderer *cell,
3713 GtkFileChooserDefault *impl)
3719 g_object_set (cell, "editable", FALSE, NULL);
3721 path = gtk_tree_path_new_from_string (path_string);
3722 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->shortcuts_model), &iter, path))
3723 g_assert_not_reached ();
3725 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
3726 SHORTCUTS_COL_DATA, &shortcut,
3728 gtk_tree_path_free (path);
3730 _gtk_file_system_set_bookmark_label (impl->file_system, shortcut, new_text);
3734 shortcuts_editing_canceled (GtkCellRenderer *cell,
3735 GtkFileChooserDefault *impl)
3737 g_object_set (cell, "editable", FALSE, NULL);
3740 /* Creates the widgets for the shortcuts and bookmarks tree */
3742 shortcuts_list_create (GtkFileChooserDefault *impl)
3745 GtkTreeSelection *selection;
3746 GtkTreeViewColumn *column;
3747 GtkCellRenderer *renderer;
3749 /* Target types for dragging a row to/from the shortcuts list */
3750 const GtkTargetEntry tree_model_row_targets[] = {
3751 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, GTK_TREE_MODEL_ROW }
3754 /* Scrolled window */
3756 swin = gtk_scrolled_window_new (NULL, NULL);
3757 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin),
3758 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
3759 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swin),
3761 gtk_widget_show (swin);
3765 impl->browse_shortcuts_tree_view = gtk_tree_view_new ();
3766 gtk_tree_view_set_enable_search (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), FALSE);
3767 #ifdef PROFILE_FILE_CHOOSER
3768 g_object_set_data (G_OBJECT (impl->browse_shortcuts_tree_view), "fmq-name", "shortcuts");
3771 /* Connect "after" to key-press-event on the shortcuts pane. We want this action to be possible:
3773 * 1. user brings up a SAVE dialog
3774 * 2. user clicks on a shortcut in the shortcuts pane
3775 * 3. user starts typing a filename
3777 * Normally, the user's typing would be ignored, as the shortcuts treeview doesn't
3778 * support interactive search. However, we'd rather focus the location entry
3779 * so that the user can type *there*.
3781 * To preserve keyboard navigation in the shortcuts pane, we don't focus the
3782 * filename entry if one clicks on a shortcut; rather, we focus the entry only
3783 * if the user starts typing while the focus is in the shortcuts pane.
3785 g_signal_connect_after (impl->browse_shortcuts_tree_view, "key-press-event",
3786 G_CALLBACK (shortcuts_key_press_event_after_cb), impl);
3788 g_signal_connect (impl->browse_shortcuts_tree_view, "popup-menu",
3789 G_CALLBACK (shortcuts_popup_menu_cb), impl);
3790 g_signal_connect (impl->browse_shortcuts_tree_view, "button-press-event",
3791 G_CALLBACK (shortcuts_button_press_event_cb), impl);
3792 /* Accessible object name for the file chooser's shortcuts pane */
3793 atk_object_set_name (gtk_widget_get_accessible (impl->browse_shortcuts_tree_view), _("Places"));
3795 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), impl->shortcuts_pane_filter_model);
3797 gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view),
3799 tree_model_row_targets,
3800 G_N_ELEMENTS (tree_model_row_targets),
3803 gtk_drag_dest_set (impl->browse_shortcuts_tree_view,
3804 GTK_DEST_DEFAULT_ALL,
3805 tree_model_row_targets,
3806 G_N_ELEMENTS (tree_model_row_targets),
3807 GDK_ACTION_COPY | GDK_ACTION_MOVE);
3808 gtk_drag_dest_add_uri_targets (impl->browse_shortcuts_tree_view);
3810 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view));
3811 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
3812 gtk_tree_selection_set_select_function (selection,
3813 shortcuts_select_func,
3816 g_signal_connect (selection, "changed",
3817 G_CALLBACK (shortcuts_selection_changed_cb), impl);
3819 g_signal_connect (impl->browse_shortcuts_tree_view, "key-press-event",
3820 G_CALLBACK (shortcuts_key_press_event_cb), impl);
3822 g_signal_connect (impl->browse_shortcuts_tree_view, "drag-begin",
3823 G_CALLBACK (shortcuts_drag_begin_cb), impl);
3824 g_signal_connect (impl->browse_shortcuts_tree_view, "drag-end",
3825 G_CALLBACK (shortcuts_drag_end_cb), impl);
3826 g_signal_connect (impl->browse_shortcuts_tree_view, "drag-data-delete",
3827 G_CALLBACK (shortcuts_drag_data_delete_cb), impl);
3829 g_signal_connect (impl->browse_shortcuts_tree_view, "drag-leave",
3830 G_CALLBACK (shortcuts_drag_leave_cb), impl);
3831 g_signal_connect (impl->browse_shortcuts_tree_view, "drag-motion",
3832 G_CALLBACK (shortcuts_drag_motion_cb), impl);
3833 g_signal_connect (impl->browse_shortcuts_tree_view, "drag-drop",
3834 G_CALLBACK (shortcuts_drag_drop_cb), impl);
3835 g_signal_connect (impl->browse_shortcuts_tree_view, "drag-data-received",
3836 G_CALLBACK (shortcuts_drag_data_received_cb), impl);
3838 /* Support tooltips */
3839 gtk_widget_set_has_tooltip (impl->browse_shortcuts_tree_view, TRUE);
3840 g_signal_connect (impl->browse_shortcuts_tree_view, "query-tooltip",
3841 G_CALLBACK (shortcuts_query_tooltip_cb), impl);
3843 gtk_container_add (GTK_CONTAINER (swin), impl->browse_shortcuts_tree_view);
3844 gtk_widget_show (impl->browse_shortcuts_tree_view);
3848 column = gtk_tree_view_column_new ();
3849 /* Column header for the file chooser's shortcuts pane */
3850 gtk_tree_view_column_set_title (column, _("_Places"));
3852 renderer = gtk_cell_renderer_pixbuf_new ();
3853 gtk_tree_view_column_pack_start (column, renderer, FALSE);
3854 gtk_tree_view_column_set_attributes (column, renderer,
3855 "pixbuf", SHORTCUTS_COL_PIXBUF,
3856 "visible", SHORTCUTS_COL_PIXBUF_VISIBLE,
3859 renderer = gtk_cell_renderer_text_new ();
3860 g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
3861 g_signal_connect (renderer, "edited",
3862 G_CALLBACK (shortcuts_edited), impl);
3863 g_signal_connect (renderer, "editing-canceled",
3864 G_CALLBACK (shortcuts_editing_canceled), impl);
3865 gtk_tree_view_column_pack_start (column, renderer, TRUE);
3866 gtk_tree_view_column_set_attributes (column, renderer,
3867 "text", SHORTCUTS_COL_NAME,
3870 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view),
3871 shortcuts_row_separator_func,
3874 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), column);
3879 /* Creates the widgets for the shortcuts/bookmarks pane */
3881 shortcuts_pane_create (GtkFileChooserDefault *impl,
3882 GtkSizeGroup *size_group)
3888 vbox = gtk_vbox_new (FALSE, 6);
3889 gtk_widget_show (vbox);
3891 /* Shortcuts tree */
3893 widget = shortcuts_list_create (impl);
3894 gtk_box_pack_start (GTK_BOX (vbox), widget, TRUE, TRUE, 0);
3896 /* Box for buttons */
3898 hbox = gtk_hbox_new (TRUE, 6);
3899 gtk_size_group_add_widget (size_group, hbox);
3900 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
3901 gtk_widget_show (hbox);
3903 /* Add bookmark button */
3905 impl->browse_shortcuts_add_button = button_new (impl,
3910 G_CALLBACK (add_bookmark_button_clicked_cb));
3911 gtk_box_pack_start (GTK_BOX (hbox), impl->browse_shortcuts_add_button, TRUE, TRUE, 0);
3912 gtk_widget_set_tooltip_text (impl->browse_shortcuts_add_button,
3913 _("Add the selected folder to the Bookmarks"));
3915 /* Remove bookmark button */
3917 impl->browse_shortcuts_remove_button = button_new (impl,
3922 G_CALLBACK (remove_bookmark_button_clicked_cb));
3923 gtk_box_pack_start (GTK_BOX (hbox), impl->browse_shortcuts_remove_button, TRUE, TRUE, 0);
3924 gtk_widget_set_tooltip_text (impl->browse_shortcuts_remove_button,
3925 _("Remove the selected bookmark"));
3931 key_is_left_or_right (GdkEventKey *event)
3935 modifiers = gtk_accelerator_get_default_mod_mask ();
3937 return ((event->keyval == GDK_Right
3938 || event->keyval == GDK_KP_Right
3939 || event->keyval == GDK_Left
3940 || event->keyval == GDK_KP_Left)
3941 && (event->state & modifiers) == 0);
3944 /* Handles key press events on the file list, so that we can trap Enter to
3945 * activate the default button on our own. Also, checks to see if '/' has been
3946 * pressed. See comment by tree_view_keybinding_cb() for more details.
3949 browse_files_key_press_event_cb (GtkWidget *widget,
3953 GtkFileChooserDefault *impl;
3956 impl = (GtkFileChooserDefault *) data;
3958 modifiers = gtk_accelerator_get_default_mod_mask ();
3960 if ((event->keyval == GDK_slash
3961 || event->keyval == GDK_KP_Divide
3963 || event->keyval == GDK_asciitilde
3965 ) && ! (event->state & (~GDK_SHIFT_MASK & modifiers)))
3967 location_popup_handler (impl, event->string);
3971 if (key_is_left_or_right (event))
3973 gtk_widget_grab_focus (impl->browse_shortcuts_tree_view);
3977 if ((event->keyval == GDK_Return
3978 || event->keyval == GDK_ISO_Enter
3979 || event->keyval == GDK_KP_Enter
3980 || event->keyval == GDK_space
3981 || event->keyval == GDK_KP_Space)
3982 && ((event->state & modifiers) == 0)
3983 && !(impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
3984 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER))
3988 window = get_toplevel (widget);
3990 && widget != window->default_widget
3991 && !(widget == window->focus_widget &&
3992 (!window->default_widget || !GTK_WIDGET_SENSITIVE (window->default_widget))))
3994 gtk_window_activate_default (window);
4002 /* Callback used when the file list's popup menu is detached */
4004 popup_menu_detach_cb (GtkWidget *attach_widget,
4007 GtkFileChooserDefault *impl;
4009 impl = g_object_get_data (G_OBJECT (attach_widget), "GtkFileChooserDefault");
4010 g_assert (GTK_IS_FILE_CHOOSER_DEFAULT (impl));
4012 impl->browse_files_popup_menu = NULL;
4013 impl->browse_files_popup_menu_add_shortcut_item = NULL;
4014 impl->browse_files_popup_menu_hidden_files_item = NULL;
4017 /* Callback used when the "Add to Bookmarks" menu item is activated */
4019 add_to_shortcuts_cb (GtkMenuItem *item,
4020 GtkFileChooserDefault *impl)
4022 bookmarks_add_selected_folder (impl);
4025 /* Callback used when the "Show Hidden Files" menu item is toggled */
4027 show_hidden_toggled_cb (GtkCheckMenuItem *item,
4028 GtkFileChooserDefault *impl)
4031 "show-hidden", gtk_check_menu_item_get_active (item),
4035 /* Callback used when the "Show Size Column" menu item is toggled */
4037 show_size_column_toggled_cb (GtkCheckMenuItem *item,
4038 GtkFileChooserDefault *impl)
4040 impl->show_size_column = gtk_check_menu_item_get_active (item);
4042 if (impl->list_size_column)
4043 gtk_tree_view_column_set_visible (impl->list_size_column,
4044 impl->show_size_column);
4047 /* Shows an error dialog about not being able to select a dragged file */
4049 error_selecting_dragged_file_dialog (GtkFileChooserDefault *impl,
4054 _("Could not select file"),
4059 file_list_drag_data_select_uris (GtkFileChooserDefault *impl,
4064 GtkFileChooser *chooser = GTK_FILE_CHOOSER (impl);
4066 for (i = 1; uris[i]; i++)
4069 GError *error = NULL;
4072 file = g_file_new_for_uri (uri);
4074 gtk_file_chooser_default_select_file (chooser, file, &error);
4076 error_selecting_dragged_file_dialog (impl, file, error);
4078 g_object_unref (file);
4082 struct FileListDragData
4084 GtkFileChooserDefault *impl;
4090 file_list_drag_data_received_get_info_cb (GCancellable *cancellable,
4092 const GError *error,
4095 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
4096 struct FileListDragData *data = user_data;
4097 GtkFileChooser *chooser = GTK_FILE_CHOOSER (data->impl);
4099 if (cancellable != data->impl->file_list_drag_data_received_cancellable)
4102 data->impl->file_list_drag_data_received_cancellable = NULL;
4104 if (cancelled || error)
4107 if ((data->impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
4108 data->impl->action == GTK_FILE_CHOOSER_ACTION_SAVE) &&
4109 data->uris[1] == 0 && !error && _gtk_file_info_consider_as_directory (info))
4110 change_folder_and_display_error (data->impl, data->file, FALSE);
4113 GError *error = NULL;
4115 gtk_file_chooser_default_unselect_all (chooser);
4116 gtk_file_chooser_default_select_file (chooser, data->file, &error);
4118 error_selecting_dragged_file_dialog (data->impl, data->file, error);
4120 browse_files_center_selected_row (data->impl);
4123 if (data->impl->select_multiple)
4124 file_list_drag_data_select_uris (data->impl, data->uris);
4127 g_object_unref (data->impl);
4128 g_strfreev (data->uris);
4129 g_object_unref (data->file);
4132 g_object_unref (cancellable);
4136 file_list_drag_data_received_cb (GtkWidget *widget,
4137 GdkDragContext *context,
4140 GtkSelectionData *selection_data,
4145 GtkFileChooserDefault *impl;
4146 GtkFileChooser *chooser;
4151 impl = GTK_FILE_CHOOSER_DEFAULT (data);
4152 chooser = GTK_FILE_CHOOSER (data);
4154 /* Allow only drags from other widgets; see bug #533891. */
4155 if (gtk_drag_get_source_widget (context) == widget)
4157 g_signal_stop_emission_by_name (widget, "drag-data-received");
4161 /* Parse the text/uri-list string, navigate to the first one */
4162 uris = gtk_selection_data_get_uris (selection_data);
4163 if (uris && uris[0])
4165 struct FileListDragData *data;
4168 file = g_file_new_for_uri (uri);
4170 data = g_new0 (struct FileListDragData, 1);
4171 data->impl = g_object_ref (impl);
4175 if (impl->file_list_drag_data_received_cancellable)
4176 g_cancellable_cancel (impl->file_list_drag_data_received_cancellable);
4178 impl->file_list_drag_data_received_cancellable =
4179 _gtk_file_system_get_info (impl->file_system, file,
4181 file_list_drag_data_received_get_info_cb,
4185 g_signal_stop_emission_by_name (widget, "drag-data-received");
4188 /* Don't do anything with the drag_drop signal */
4190 file_list_drag_drop_cb (GtkWidget *widget,
4191 GdkDragContext *context,
4195 GtkFileChooserDefault *impl)
4197 g_signal_stop_emission_by_name (widget, "drag-drop");
4201 /* Disable the normal tree drag motion handler, it makes it look like you're
4202 dropping the dragged item onto a tree item */
4204 file_list_drag_motion_cb (GtkWidget *widget,
4205 GdkDragContext *context,
4209 GtkFileChooserDefault *impl)
4211 g_signal_stop_emission_by_name (widget, "drag-motion");
4215 /* Constructs the popup menu for the file list if needed */
4217 file_list_build_popup_menu (GtkFileChooserDefault *impl)
4221 if (impl->browse_files_popup_menu)
4224 impl->browse_files_popup_menu = gtk_menu_new ();
4225 gtk_menu_attach_to_widget (GTK_MENU (impl->browse_files_popup_menu),
4226 impl->browse_files_tree_view,
4227 popup_menu_detach_cb);
4229 item = gtk_image_menu_item_new_with_mnemonic (_("_Add to Bookmarks"));
4230 impl->browse_files_popup_menu_add_shortcut_item = item;
4231 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
4232 gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
4233 g_signal_connect (item, "activate",
4234 G_CALLBACK (add_to_shortcuts_cb), impl);
4235 gtk_widget_show (item);
4236 gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
4238 item = gtk_separator_menu_item_new ();
4239 gtk_widget_show (item);
4240 gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
4242 item = gtk_check_menu_item_new_with_mnemonic (_("Show _Hidden Files"));
4243 impl->browse_files_popup_menu_hidden_files_item = item;
4244 g_signal_connect (item, "toggled",
4245 G_CALLBACK (show_hidden_toggled_cb), impl);
4246 gtk_widget_show (item);
4247 gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
4249 item = gtk_check_menu_item_new_with_mnemonic (_("Show _Size Column"));
4250 impl->browse_files_popup_menu_size_column_item = item;
4251 g_signal_connect (item, "toggled",
4252 G_CALLBACK (show_size_column_toggled_cb), impl);
4253 gtk_widget_show (item);
4254 gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
4256 bookmarks_check_add_sensitivity (impl);
4259 /* Updates the popup menu for the file list, creating it if necessary */
4261 file_list_update_popup_menu (GtkFileChooserDefault *impl)
4263 file_list_build_popup_menu (impl);
4265 /* FIXME - handle OPERATION_MODE_SEARCH and OPERATION_MODE_RECENT */
4267 /* The sensitivity of the Add to Bookmarks item is set in
4268 * bookmarks_check_add_sensitivity()
4271 /* 'Show Hidden Files' */
4272 g_signal_handlers_block_by_func (impl->browse_files_popup_menu_hidden_files_item,
4273 G_CALLBACK (show_hidden_toggled_cb), impl);
4274 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (impl->browse_files_popup_menu_hidden_files_item),
4276 g_signal_handlers_unblock_by_func (impl->browse_files_popup_menu_hidden_files_item,
4277 G_CALLBACK (show_hidden_toggled_cb), impl);
4279 /* 'Show Size Column' */
4280 g_signal_handlers_block_by_func (impl->browse_files_popup_menu_size_column_item,
4281 G_CALLBACK (show_size_column_toggled_cb), impl);
4282 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (impl->browse_files_popup_menu_size_column_item),
4283 impl->show_size_column);
4284 g_signal_handlers_unblock_by_func (impl->browse_files_popup_menu_size_column_item,
4285 G_CALLBACK (show_size_column_toggled_cb), impl);
4289 popup_position_func (GtkMenu *menu,
4295 GtkWidget *widget = GTK_WIDGET (user_data);
4296 GdkScreen *screen = gtk_widget_get_screen (widget);
4299 GdkRectangle monitor;
4301 g_return_if_fail (GTK_WIDGET_REALIZED (widget));
4303 gdk_window_get_origin (widget->window, x, y);
4305 gtk_widget_size_request (GTK_WIDGET (menu), &req);
4307 *x += (widget->allocation.width - req.width) / 2;
4308 *y += (widget->allocation.height - req.height) / 2;
4310 monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
4311 gtk_menu_set_monitor (menu, monitor_num);
4312 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
4314 *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
4315 *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
4321 file_list_popup_menu (GtkFileChooserDefault *impl,
4322 GdkEventButton *event)
4324 file_list_update_popup_menu (impl);
4326 gtk_menu_popup (GTK_MENU (impl->browse_files_popup_menu),
4327 NULL, NULL, NULL, NULL,
4328 event->button, event->time);
4331 gtk_menu_popup (GTK_MENU (impl->browse_files_popup_menu),
4333 popup_position_func, impl->browse_files_tree_view,
4334 0, GDK_CURRENT_TIME);
4335 gtk_menu_shell_select_first (GTK_MENU_SHELL (impl->browse_files_popup_menu),
4341 /* Callback used for the GtkWidget::popup-menu signal of the file list */
4343 list_popup_menu_cb (GtkWidget *widget,
4344 GtkFileChooserDefault *impl)
4346 file_list_popup_menu (impl, NULL);
4350 /* Callback used when a button is pressed on the file list. We trap button 3 to
4351 * bring up a popup menu.
4354 list_button_press_event_cb (GtkWidget *widget,
4355 GdkEventButton *event,
4356 GtkFileChooserDefault *impl)
4358 static gboolean in_press = FALSE;
4364 if (event->button != 3)
4368 handled = gtk_widget_event (impl->browse_files_tree_view, (GdkEvent *) event);
4371 file_list_popup_menu (impl, event);
4376 OperationMode operation_mode;
4377 gint general_column;
4381 /* Sets the sort column IDs for the file list based on the operation mode */
4383 file_list_set_sort_column_ids (GtkFileChooserDefault *impl)
4385 gtk_tree_view_column_set_sort_column_id (impl->list_name_column, MODEL_COL_NAME);
4386 gtk_tree_view_column_set_sort_column_id (impl->list_mtime_column, MODEL_COL_MTIME);
4387 gtk_tree_view_column_set_sort_column_id (impl->list_size_column, MODEL_COL_SIZE);
4391 file_list_query_tooltip_cb (GtkWidget *widget,
4394 gboolean keyboard_tip,
4395 GtkTooltip *tooltip,
4398 GtkFileChooserDefault *impl = user_data;
4399 GtkTreeModel *model;
4405 if (impl->operation_mode == OPERATION_MODE_BROWSE)
4409 if (!gtk_tree_view_get_tooltip_context (GTK_TREE_VIEW (impl->browse_files_tree_view),
4412 &model, &path, &iter))
4415 gtk_tree_model_get (model, &iter,
4416 MODEL_COL_FILE, &file,
4421 gtk_tree_path_free (path);
4425 filename = g_file_get_path (file);
4426 gtk_tooltip_set_text (tooltip, filename);
4427 gtk_tree_view_set_tooltip_row (GTK_TREE_VIEW (impl->browse_files_tree_view),
4432 g_object_unref (file);
4433 gtk_tree_path_free (path);
4438 /* Creates the widgets for the file list */
4440 create_file_list (GtkFileChooserDefault *impl)
4443 GtkTreeSelection *selection;
4444 GtkTreeViewColumn *column;
4445 GtkCellRenderer *renderer;
4447 /* Scrolled window */
4448 swin = gtk_scrolled_window_new (NULL, NULL);
4449 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin),
4450 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
4451 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swin),
4454 /* Tree/list view */
4456 impl->browse_files_tree_view = gtk_tree_view_new ();
4457 #ifdef PROFILE_FILE_CHOOSER
4458 g_object_set_data (G_OBJECT (impl->browse_files_tree_view), "fmq-name", "file_list");
4460 g_object_set_data (G_OBJECT (impl->browse_files_tree_view), I_("GtkFileChooserDefault"), impl);
4461 atk_object_set_name (gtk_widget_get_accessible (impl->browse_files_tree_view), _("Files"));
4463 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (impl->browse_files_tree_view), TRUE);
4464 gtk_container_add (GTK_CONTAINER (swin), impl->browse_files_tree_view);
4466 gtk_drag_dest_set (impl->browse_files_tree_view,
4467 GTK_DEST_DEFAULT_ALL,
4469 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4470 gtk_drag_dest_add_uri_targets (impl->browse_files_tree_view);
4472 g_signal_connect (impl->browse_files_tree_view, "row-activated",
4473 G_CALLBACK (list_row_activated), impl);
4474 g_signal_connect (impl->browse_files_tree_view, "key-press-event",
4475 G_CALLBACK (browse_files_key_press_event_cb), impl);
4476 g_signal_connect (impl->browse_files_tree_view, "popup-menu",
4477 G_CALLBACK (list_popup_menu_cb), impl);
4478 g_signal_connect (impl->browse_files_tree_view, "button-press-event",
4479 G_CALLBACK (list_button_press_event_cb), impl);
4481 g_signal_connect (impl->browse_files_tree_view, "drag-data-received",
4482 G_CALLBACK (file_list_drag_data_received_cb), impl);
4483 g_signal_connect (impl->browse_files_tree_view, "drag-drop",
4484 G_CALLBACK (file_list_drag_drop_cb), impl);
4485 g_signal_connect (impl->browse_files_tree_view, "drag-motion",
4486 G_CALLBACK (file_list_drag_motion_cb), impl);
4488 g_object_set (impl->browse_files_tree_view, "has-tooltip", TRUE, NULL);
4489 g_signal_connect (impl->browse_files_tree_view, "query-tooltip",
4490 G_CALLBACK (file_list_query_tooltip_cb), impl);
4492 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
4493 gtk_tree_selection_set_select_function (selection,
4496 gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (impl->browse_files_tree_view),
4499 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4500 gtk_drag_source_add_uri_targets (impl->browse_files_tree_view);
4502 g_signal_connect (selection, "changed",
4503 G_CALLBACK (list_selection_changed), impl);
4505 /* Filename column */
4507 impl->list_name_column = gtk_tree_view_column_new ();
4508 gtk_tree_view_column_set_expand (impl->list_name_column, TRUE);
4509 gtk_tree_view_column_set_resizable (impl->list_name_column, TRUE);
4510 gtk_tree_view_column_set_title (impl->list_name_column, _("Name"));
4512 renderer = gtk_cell_renderer_pixbuf_new ();
4513 /* We set a fixed size so that we get an emoty row even if no icons are loaded yet */
4514 gtk_cell_renderer_set_fixed_size (renderer,
4515 renderer->xpad * 2 + impl->icon_size,
4516 renderer->ypad * 2 + impl->icon_size);
4517 gtk_tree_view_column_pack_start (impl->list_name_column, renderer, FALSE);
4519 impl->list_name_renderer = gtk_cell_renderer_text_new ();
4520 g_object_set (impl->list_name_renderer,
4521 "ellipsize", PANGO_ELLIPSIZE_END,
4523 g_signal_connect (impl->list_name_renderer, "edited",
4524 G_CALLBACK (renderer_edited_cb), impl);
4525 g_signal_connect (impl->list_name_renderer, "editing-canceled",
4526 G_CALLBACK (renderer_editing_canceled_cb), impl);
4527 gtk_tree_view_column_pack_start (impl->list_name_column, impl->list_name_renderer, TRUE);
4529 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->browse_files_tree_view), impl->list_name_column);
4533 column = gtk_tree_view_column_new ();
4534 gtk_tree_view_column_set_resizable (column, TRUE);
4535 gtk_tree_view_column_set_title (column, _("Size"));
4537 renderer = gtk_cell_renderer_text_new ();
4538 g_object_set (renderer,
4539 "alignment", PANGO_ALIGN_RIGHT,
4541 gtk_tree_view_column_pack_start (column, renderer, TRUE); /* bug: it doesn't expand */
4542 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->browse_files_tree_view), column);
4543 impl->list_size_column = column;
4545 /* Modification time column */
4547 column = gtk_tree_view_column_new ();
4548 gtk_tree_view_column_set_resizable (column, TRUE);
4549 gtk_tree_view_column_set_title (column, _("Modified"));
4551 renderer = gtk_cell_renderer_text_new ();
4552 gtk_tree_view_column_pack_start (column, renderer, TRUE);
4553 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->browse_files_tree_view), column);
4554 impl->list_mtime_column = column;
4556 file_list_set_sort_column_ids (impl);
4557 update_cell_renderer_attributes (impl);
4559 gtk_widget_show_all (swin);
4565 create_path_bar (GtkFileChooserDefault *impl)
4567 GtkWidget *path_bar;
4569 path_bar = g_object_new (GTK_TYPE_PATH_BAR, NULL);
4570 _gtk_path_bar_set_file_system (GTK_PATH_BAR (path_bar), impl->file_system);
4575 /* Creates the widgets for the files/folders pane */
4577 file_pane_create (GtkFileChooserDefault *impl,
4578 GtkSizeGroup *size_group)
4584 vbox = gtk_vbox_new (FALSE, 6);
4585 gtk_widget_show (vbox);
4587 /* Box for lists and preview */
4589 hbox = gtk_hbox_new (FALSE, PREVIEW_HBOX_SPACING);
4590 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
4591 gtk_widget_show (hbox);
4595 widget = create_file_list (impl);
4596 gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
4600 impl->preview_box = gtk_vbox_new (FALSE, 12);
4601 gtk_box_pack_start (GTK_BOX (hbox), impl->preview_box, FALSE, FALSE, 0);
4602 /* Don't show preview box initially */
4606 impl->filter_combo_hbox = gtk_hbox_new (FALSE, 12);
4608 widget = filter_create (impl);
4610 gtk_widget_show (widget);
4611 gtk_box_pack_end (GTK_BOX (impl->filter_combo_hbox), widget, FALSE, FALSE, 0);
4613 gtk_size_group_add_widget (size_group, impl->filter_combo_hbox);
4614 gtk_box_pack_end (GTK_BOX (vbox), impl->filter_combo_hbox, FALSE, FALSE, 0);
4619 /* Callback used when the "Browse for more folders" expander is toggled */
4621 expander_changed_cb (GtkExpander *expander,
4623 GtkFileChooserDefault *impl)
4625 impl->expand_folders = gtk_expander_get_expanded(GTK_EXPANDER (impl->save_expander));
4626 update_appearance (impl);
4629 /* Callback used when the selection changes in the save folder combo box */
4631 save_folder_combo_changed_cb (GtkComboBox *combo,
4632 GtkFileChooserDefault *impl)
4636 if (impl->changing_folder)
4639 if (gtk_combo_box_get_active_iter (combo, &iter))
4641 GtkTreeIter child_iter;
4643 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (impl->shortcuts_combo_filter_model),
4646 shortcuts_activate_iter (impl, &child_iter);
4651 save_folder_update_tooltip (GtkComboBox *combo,
4652 GtkFileChooserDefault *impl)
4659 if (gtk_combo_box_get_active_iter (combo, &iter))
4661 GtkTreeIter child_iter;
4663 ShortcutType shortcut_type;
4665 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (impl->shortcuts_combo_filter_model),
4668 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &child_iter,
4669 SHORTCUTS_COL_DATA, &col_data,
4670 SHORTCUTS_COL_TYPE, &shortcut_type,
4673 if (shortcut_type == SHORTCUT_TYPE_FILE)
4674 tooltip = g_file_get_parse_name (G_FILE (col_data));
4677 gtk_widget_set_tooltip_text (GTK_WIDGET (combo), tooltip);
4678 gtk_widget_set_has_tooltip (GTK_WIDGET (combo),
4679 gtk_widget_get_sensitive (GTK_WIDGET (combo)));
4683 /* Filter function used to filter out the Search item and its separator.
4684 * Used for the "Save in folder" combo box, so that these items do not appear in it.
4687 shortcuts_combo_filter_func (GtkTreeModel *model,
4691 GtkFileChooserDefault *impl;
4692 GtkTreePath *tree_path;
4697 impl = GTK_FILE_CHOOSER_DEFAULT (data);
4699 g_assert (model == GTK_TREE_MODEL (impl->shortcuts_model));
4701 tree_path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), iter);
4702 g_assert (tree_path != NULL);
4704 indices = gtk_tree_path_get_indices (tree_path);
4708 if (impl->has_search)
4710 idx = shortcuts_get_index (impl, SHORTCUTS_SEARCH);
4711 if (idx == indices[0])
4715 if (impl->has_recent)
4717 idx = shortcuts_get_index (impl, SHORTCUTS_RECENT);
4718 if (idx == indices[0])
4722 idx = shortcuts_get_index (impl, SHORTCUTS_RECENT_SEPARATOR);
4723 if (idx == indices[0])
4728 gtk_tree_path_free (tree_path);
4733 /* Creates the combo box with the save folders */
4735 save_folder_combo_create (GtkFileChooserDefault *impl)
4738 GtkCellRenderer *cell;
4740 impl->shortcuts_combo_filter_model = gtk_tree_model_filter_new (GTK_TREE_MODEL (impl->shortcuts_model), NULL);
4741 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (impl->shortcuts_combo_filter_model),
4742 shortcuts_combo_filter_func,
4746 combo = g_object_new (GTK_TYPE_COMBO_BOX,
4747 "model", impl->shortcuts_combo_filter_model,
4748 "focus-on-click", FALSE,
4750 gtk_widget_show (combo);
4752 cell = gtk_cell_renderer_pixbuf_new ();
4753 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, FALSE);
4754 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), cell,
4755 "pixbuf", SHORTCUTS_COL_PIXBUF,
4756 "visible", SHORTCUTS_COL_PIXBUF_VISIBLE,
4757 "sensitive", SHORTCUTS_COL_PIXBUF_VISIBLE,
4760 cell = gtk_cell_renderer_text_new ();
4761 g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
4762 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE);
4763 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), cell,
4764 "text", SHORTCUTS_COL_NAME,
4765 "sensitive", SHORTCUTS_COL_PIXBUF_VISIBLE,
4768 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo),
4769 shortcuts_row_separator_func,
4772 g_signal_connect (combo, "changed",
4773 G_CALLBACK (save_folder_combo_changed_cb), impl);
4774 g_signal_connect (combo, "changed",
4775 G_CALLBACK (save_folder_update_tooltip), impl);
4780 /* Creates the widgets specific to Save mode */
4782 save_widgets_create (GtkFileChooserDefault *impl)
4787 GtkWidget *alignment;
4789 if (impl->save_widgets != NULL)
4792 location_switch_to_path_bar (impl);
4794 vbox = gtk_vbox_new (FALSE, 12);
4796 table = gtk_table_new (2, 2, FALSE);
4797 gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
4798 gtk_widget_show (table);
4799 gtk_table_set_row_spacings (GTK_TABLE (table), 12);
4800 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
4804 widget = gtk_label_new_with_mnemonic (_("_Name:"));
4805 gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
4806 gtk_table_attach (GTK_TABLE (table), widget,
4810 gtk_widget_show (widget);
4812 /* Location entry */
4814 impl->location_entry = _gtk_file_chooser_entry_new (TRUE);
4815 _gtk_file_chooser_entry_set_file_system (GTK_FILE_CHOOSER_ENTRY (impl->location_entry),
4817 _gtk_file_chooser_entry_set_local_only (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->local_only);
4818 gtk_entry_set_width_chars (GTK_ENTRY (impl->location_entry), 45);
4819 gtk_entry_set_activates_default (GTK_ENTRY (impl->location_entry), TRUE);
4820 gtk_table_attach (GTK_TABLE (table), impl->location_entry,
4822 GTK_EXPAND | GTK_FILL, 0,
4824 gtk_widget_show (impl->location_entry);
4825 gtk_label_set_mnemonic_widget (GTK_LABEL (widget), impl->location_entry);
4828 impl->save_folder_label = gtk_label_new (NULL);
4829 gtk_misc_set_alignment (GTK_MISC (impl->save_folder_label), 0.0, 0.5);
4830 gtk_table_attach (GTK_TABLE (table), impl->save_folder_label,
4834 gtk_widget_show (impl->save_folder_label);
4836 impl->save_folder_combo = save_folder_combo_create (impl);
4837 gtk_table_attach (GTK_TABLE (table), impl->save_folder_combo,
4839 GTK_EXPAND | GTK_FILL, GTK_FILL,
4841 gtk_label_set_mnemonic_widget (GTK_LABEL (impl->save_folder_label), impl->save_folder_combo);
4844 alignment = gtk_alignment_new (0.0, 0.5, 1.0, 1.0);
4845 gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0);
4847 impl->save_expander = gtk_expander_new_with_mnemonic (_("_Browse for other folders"));
4848 gtk_container_add (GTK_CONTAINER (alignment), impl->save_expander);
4849 g_signal_connect (impl->save_expander, "notify::expanded",
4850 G_CALLBACK (expander_changed_cb),
4852 gtk_widget_show_all (alignment);
4854 impl->save_widgets = vbox;
4855 gtk_box_pack_start (GTK_BOX (impl), impl->save_widgets, FALSE, FALSE, 0);
4856 gtk_box_reorder_child (GTK_BOX (impl), impl->save_widgets, 0);
4857 gtk_widget_show (impl->save_widgets);
4860 /* Destroys the widgets specific to Save mode */
4862 save_widgets_destroy (GtkFileChooserDefault *impl)
4864 if (impl->save_widgets == NULL)
4867 gtk_widget_destroy (impl->save_widgets);
4868 impl->save_widgets = NULL;
4869 impl->location_entry = NULL;
4870 impl->save_folder_label = NULL;
4871 impl->save_folder_combo = NULL;
4872 impl->save_expander = NULL;
4875 /* Turns on the path bar widget. Can be called even if we are already in that
4879 location_switch_to_path_bar (GtkFileChooserDefault *impl)
4881 if (impl->location_entry)
4883 gtk_widget_destroy (impl->location_entry);
4884 impl->location_entry = NULL;
4887 gtk_widget_hide (impl->location_entry_box);
4890 /* Sets the full path of the current folder as the text in the location entry. */
4892 location_entry_set_initial_text (GtkFileChooserDefault *impl)
4894 gchar *text, *filename;
4896 if (!impl->current_folder)
4899 filename = g_file_get_path (impl->current_folder);
4903 text = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
4907 text = g_file_get_uri (impl->current_folder);
4911 gboolean need_slash;
4914 len = strlen (text);
4915 need_slash = (text[len - 1] != G_DIR_SEPARATOR);
4921 slash_text = g_new (char, len + 2);
4922 strcpy (slash_text, text);
4923 slash_text[len] = G_DIR_SEPARATOR;
4924 slash_text[len + 1] = 0;
4930 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), text);
4937 /* Turns on the location entry. Can be called even if we are already in that
4941 location_switch_to_filename_entry (GtkFileChooserDefault *impl)
4943 /* when in search or recent files mode, we are not showing the
4944 * location_entry_box container, so there's no point in switching
4947 if (impl->operation_mode == OPERATION_MODE_SEARCH ||
4948 impl->operation_mode == OPERATION_MODE_RECENT)
4951 if (impl->location_entry)
4952 gtk_widget_destroy (impl->location_entry);
4956 gtk_widget_show (impl->location_entry_box);
4960 impl->location_entry = _gtk_file_chooser_entry_new (TRUE);
4961 _gtk_file_chooser_entry_set_file_system (GTK_FILE_CHOOSER_ENTRY (impl->location_entry),
4963 gtk_entry_set_activates_default (GTK_ENTRY (impl->location_entry), TRUE);
4964 _gtk_file_chooser_entry_set_action (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->action);
4966 gtk_box_pack_start (GTK_BOX (impl->location_entry_box), impl->location_entry, TRUE, TRUE, 0);
4967 gtk_label_set_mnemonic_widget (GTK_LABEL (impl->location_label), impl->location_entry);
4969 /* Configure the entry */
4971 _gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->current_folder);
4975 gtk_widget_show (impl->location_entry);
4976 gtk_widget_grab_focus (impl->location_entry);
4979 /* Sets a new location mode. set_buttons determines whether the toggle button
4980 * for the mode will also be changed.
4983 location_mode_set (GtkFileChooserDefault *impl,
4984 LocationMode new_mode,
4985 gboolean set_button)
4987 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
4988 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
4990 GtkWindow *toplevel;
4991 GtkWidget *current_focus;
4992 gboolean button_active;
4993 gboolean switch_to_file_list;
4997 case LOCATION_MODE_PATH_BAR:
4998 button_active = FALSE;
5000 /* The location_entry will disappear when we switch to path bar mode. So,
5001 * we'll focus the file list in that case, to avoid having a window with
5002 * no focused widget.
5004 toplevel = get_toplevel (GTK_WIDGET (impl));
5005 switch_to_file_list = FALSE;
5008 current_focus = gtk_window_get_focus (toplevel);
5009 if (!current_focus || current_focus == impl->location_entry)
5010 switch_to_file_list = TRUE;
5013 location_switch_to_path_bar (impl);
5015 if (switch_to_file_list)
5016 gtk_widget_grab_focus (impl->browse_files_tree_view);
5020 case LOCATION_MODE_FILENAME_ENTRY:
5021 button_active = TRUE;
5022 location_switch_to_filename_entry (impl);
5026 g_assert_not_reached ();
5032 g_signal_handlers_block_by_func (impl->location_button,
5033 G_CALLBACK (location_button_toggled_cb), impl);
5035 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->location_button), button_active);
5037 g_signal_handlers_unblock_by_func (impl->location_button,
5038 G_CALLBACK (location_button_toggled_cb), impl);
5042 impl->location_mode = new_mode;
5046 location_toggle_popup_handler (GtkFileChooserDefault *impl)
5048 /* when in search or recent files mode, we are not showing the
5049 * location_entry_box container, so there's no point in switching
5052 if (impl->operation_mode == OPERATION_MODE_SEARCH ||
5053 impl->operation_mode == OPERATION_MODE_RECENT)
5056 /* If the file entry is not visible, show it.
5057 * If it is visible, turn it off only if it is focused. Otherwise, switch to the entry.
5059 if (impl->location_mode == LOCATION_MODE_PATH_BAR)
5061 location_mode_set (impl, LOCATION_MODE_FILENAME_ENTRY, TRUE);
5063 else if (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)
5065 if (GTK_WIDGET_HAS_FOCUS (impl->location_entry))
5067 location_mode_set (impl, LOCATION_MODE_PATH_BAR, TRUE);
5071 gtk_widget_grab_focus (impl->location_entry);
5076 /* Callback used when one of the location mode buttons is toggled */
5078 location_button_toggled_cb (GtkToggleButton *toggle,
5079 GtkFileChooserDefault *impl)
5082 LocationMode new_mode;
5084 is_active = gtk_toggle_button_get_active (toggle);
5088 g_assert (impl->location_mode == LOCATION_MODE_PATH_BAR);
5089 new_mode = LOCATION_MODE_FILENAME_ENTRY;
5093 g_assert (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY);
5094 new_mode = LOCATION_MODE_PATH_BAR;
5097 location_mode_set (impl, new_mode, FALSE);
5100 /* Creates a toggle button for the location entry. */
5102 location_button_create (GtkFileChooserDefault *impl)
5107 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_BUTTON);
5108 gtk_widget_show (image);
5110 impl->location_button = g_object_new (GTK_TYPE_TOGGLE_BUTTON,
5114 gtk_size_group_add_widget (impl->browse_path_bar_size_group, impl->location_button);
5116 g_signal_connect (impl->location_button, "toggled",
5117 G_CALLBACK (location_button_toggled_cb), impl);
5119 str = _("Type a file name");
5121 gtk_widget_set_tooltip_text (impl->location_button, str);
5122 atk_object_set_name (gtk_widget_get_accessible (impl->location_button), str);
5125 /* Creates the main hpaned with the widgets shared by Open and Save mode */
5127 browse_widgets_create (GtkFileChooserDefault *impl)
5132 GtkSizeGroup *size_group;
5134 /* size group is used by the [+][-] buttons and the filter combo */
5135 size_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
5136 vbox = gtk_vbox_new (FALSE, 12);
5138 /* Location widgets */
5139 impl->browse_path_bar_hbox = gtk_hbox_new (FALSE, 12);
5140 gtk_box_pack_start (GTK_BOX (vbox), impl->browse_path_bar_hbox, FALSE, FALSE, 0);
5141 gtk_widget_show (impl->browse_path_bar_hbox);
5143 /* Size group that allows the path bar to be the same size between modes */
5144 impl->browse_path_bar_size_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
5145 gtk_size_group_set_ignore_hidden (impl->browse_path_bar_size_group, FALSE);
5147 /* Location button */
5149 location_button_create (impl);
5150 gtk_box_pack_start (GTK_BOX (impl->browse_path_bar_hbox), impl->location_button, FALSE, FALSE, 0);
5154 impl->browse_path_bar = create_path_bar (impl);
5155 g_signal_connect (impl->browse_path_bar, "path-clicked", G_CALLBACK (path_bar_clicked), impl);
5156 gtk_widget_show_all (impl->browse_path_bar);
5157 gtk_box_pack_start (GTK_BOX (impl->browse_path_bar_hbox), impl->browse_path_bar, TRUE, TRUE, 0);
5160 impl->browse_new_folder_button = gtk_button_new_with_mnemonic (_("Create Fo_lder"));
5161 g_signal_connect (impl->browse_new_folder_button, "clicked",
5162 G_CALLBACK (new_folder_button_clicked), impl);
5163 gtk_box_pack_end (GTK_BOX (impl->browse_path_bar_hbox), impl->browse_new_folder_button, FALSE, FALSE, 0);
5165 /* Box for the location label and entry */
5167 impl->location_entry_box = gtk_hbox_new (FALSE, 12);
5168 gtk_box_pack_start (GTK_BOX (vbox), impl->location_entry_box, FALSE, FALSE, 0);
5170 impl->location_label = gtk_label_new_with_mnemonic (_("_Location:"));
5171 gtk_widget_show (impl->location_label);
5172 gtk_box_pack_start (GTK_BOX (impl->location_entry_box), impl->location_label, FALSE, FALSE, 0);
5175 hpaned = gtk_hpaned_new ();
5176 gtk_widget_show (hpaned);
5177 gtk_box_pack_start (GTK_BOX (vbox), hpaned, TRUE, TRUE, 0);
5179 widget = shortcuts_pane_create (impl, size_group);
5180 gtk_paned_pack1 (GTK_PANED (hpaned), widget, FALSE, FALSE);
5181 widget = file_pane_create (impl, size_group);
5182 gtk_paned_pack2 (GTK_PANED (hpaned), widget, TRUE, FALSE);
5184 g_object_unref (size_group);
5190 gtk_file_chooser_default_constructor (GType type,
5191 guint n_construct_properties,
5192 GObjectConstructParam *construct_params)
5194 GtkFileChooserDefault *impl;
5197 profile_start ("start", NULL);
5199 object = G_OBJECT_CLASS (_gtk_file_chooser_default_parent_class)->constructor (type,
5200 n_construct_properties,
5202 impl = GTK_FILE_CHOOSER_DEFAULT (object);
5204 g_assert (impl->file_system);
5206 gtk_widget_push_composite_child ();
5208 /* Shortcuts model */
5209 shortcuts_model_create (impl);
5211 /* The browse widgets */
5212 impl->browse_widgets = browse_widgets_create (impl);
5213 gtk_box_pack_start (GTK_BOX (impl), impl->browse_widgets, TRUE, TRUE, 0);
5215 /* Alignment to hold extra widget */
5216 impl->extra_align = gtk_alignment_new (0.0, 0.5, 1.0, 1.0);
5217 gtk_box_pack_start (GTK_BOX (impl), impl->extra_align, FALSE, FALSE, 0);
5219 gtk_widget_pop_composite_child ();
5220 update_appearance (impl);
5222 profile_end ("end", NULL);
5227 /* Sets the extra_widget by packing it in the appropriate place */
5229 set_extra_widget (GtkFileChooserDefault *impl,
5230 GtkWidget *extra_widget)
5234 g_object_ref (extra_widget);
5235 /* FIXME: is this right ? */
5236 gtk_widget_show (extra_widget);
5239 if (impl->extra_widget)
5241 gtk_container_remove (GTK_CONTAINER (impl->extra_align), impl->extra_widget);
5242 g_object_unref (impl->extra_widget);
5245 impl->extra_widget = extra_widget;
5246 if (impl->extra_widget)
5248 gtk_container_add (GTK_CONTAINER (impl->extra_align), impl->extra_widget);
5249 gtk_widget_show (impl->extra_align);
5252 gtk_widget_hide (impl->extra_align);
5256 set_local_only (GtkFileChooserDefault *impl,
5257 gboolean local_only)
5259 if (local_only != impl->local_only)
5261 impl->local_only = local_only;
5263 if (impl->location_entry)
5264 _gtk_file_chooser_entry_set_local_only (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), local_only);
5266 if (impl->shortcuts_model && impl->file_system)
5268 shortcuts_add_volumes (impl);
5269 shortcuts_add_bookmarks (impl);
5272 if (local_only && impl->current_folder &&
5273 !g_file_is_native (impl->current_folder))
5275 /* If we are pointing to a non-local folder, make an effort to change
5276 * back to a local folder, but it's really up to the app to not cause
5277 * such a situation, so we ignore errors.
5279 const gchar *home = g_get_home_dir ();
5285 home_file = g_file_new_for_path (home);
5287 gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (impl), home_file, NULL);
5289 g_object_unref (home_file);
5295 volumes_bookmarks_changed_cb (GtkFileSystem *file_system,
5296 GtkFileChooserDefault *impl)
5298 shortcuts_add_volumes (impl);
5299 shortcuts_add_bookmarks (impl);
5301 bookmarks_check_add_sensitivity (impl);
5302 bookmarks_check_remove_sensitivity (impl);
5303 shortcuts_check_popup_sensitivity (impl);
5306 /* Sets the file chooser to multiple selection mode */
5308 set_select_multiple (GtkFileChooserDefault *impl,
5309 gboolean select_multiple,
5310 gboolean property_notify)
5312 GtkTreeSelection *selection;
5313 GtkSelectionMode mode;
5315 if (select_multiple == impl->select_multiple)
5318 mode = select_multiple ? GTK_SELECTION_MULTIPLE : GTK_SELECTION_BROWSE;
5320 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
5321 gtk_tree_selection_set_mode (selection, mode);
5323 gtk_tree_view_set_rubber_banding (GTK_TREE_VIEW (impl->browse_files_tree_view), select_multiple);
5325 impl->select_multiple = select_multiple;
5326 g_object_notify (G_OBJECT (impl), "select-multiple");
5328 check_preview_change (impl);
5332 set_file_system_backend (GtkFileChooserDefault *impl)
5334 profile_start ("start for backend", "default");
5336 impl->file_system = _gtk_file_system_new ();
5338 g_signal_connect (impl->file_system, "volumes-changed",
5339 G_CALLBACK (volumes_bookmarks_changed_cb), impl);
5340 g_signal_connect (impl->file_system, "bookmarks-changed",
5341 G_CALLBACK (volumes_bookmarks_changed_cb), impl);
5343 profile_end ("end", NULL);
5347 unset_file_system_backend (GtkFileChooserDefault *impl)
5349 g_signal_handlers_disconnect_by_func (impl->file_system,
5350 G_CALLBACK (volumes_bookmarks_changed_cb), impl);
5352 g_object_unref (impl->file_system);
5354 impl->file_system = NULL;
5357 /* This function is basically a do_all function.
5359 * It sets the visibility on all the widgets based on the current state, and
5360 * moves the custom_widget if needed.
5363 update_appearance (GtkFileChooserDefault *impl)
5365 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
5366 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
5370 gtk_widget_hide (impl->location_button);
5371 save_widgets_create (impl);
5373 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
5374 text = _("Save in _folder:");
5376 text = _("Create in _folder:");
5378 gtk_label_set_text_with_mnemonic (GTK_LABEL (impl->save_folder_label), text);
5380 if (gtk_expander_get_expanded (GTK_EXPANDER (impl->save_expander)))
5382 gtk_widget_set_sensitive (impl->save_folder_label, FALSE);
5383 gtk_widget_set_sensitive (impl->save_folder_combo, FALSE);
5384 gtk_widget_set_has_tooltip (impl->save_folder_combo, FALSE);
5385 gtk_widget_show (impl->browse_widgets);
5389 gtk_widget_set_sensitive (impl->save_folder_label, TRUE);
5390 gtk_widget_set_sensitive (impl->save_folder_combo, TRUE);
5391 gtk_widget_set_has_tooltip (impl->save_folder_combo, TRUE);
5392 gtk_widget_hide (impl->browse_widgets);
5395 if (impl->select_multiple)
5397 g_warning ("Save mode cannot be set in conjunction with multiple selection mode. "
5398 "Re-setting to single selection mode.");
5399 set_select_multiple (impl, FALSE, TRUE);
5402 else if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
5403 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
5405 gtk_widget_show (impl->location_button);
5406 save_widgets_destroy (impl);
5407 gtk_widget_show (impl->browse_widgets);
5408 location_mode_set (impl, impl->location_mode, TRUE);
5411 if (impl->location_entry)
5412 _gtk_file_chooser_entry_set_action (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->action);
5414 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN || !impl->create_folders)
5415 gtk_widget_hide (impl->browse_new_folder_button);
5417 gtk_widget_show (impl->browse_new_folder_button);
5419 /* This *is* needed; we need to redraw the file list because the "sensitivity"
5420 * of files may change depending whether we are in a file or folder-only mode.
5422 gtk_widget_queue_draw (impl->browse_files_tree_view);
5424 emit_default_size_changed (impl);
5428 gtk_file_chooser_default_set_property (GObject *object,
5430 const GValue *value,
5434 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (object);
5438 case GTK_FILE_CHOOSER_PROP_ACTION:
5440 GtkFileChooserAction action = g_value_get_enum (value);
5442 if (action != impl->action)
5444 gtk_file_chooser_default_unselect_all (GTK_FILE_CHOOSER (impl));
5446 if ((action == GTK_FILE_CHOOSER_ACTION_SAVE ||
5447 action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
5448 && impl->select_multiple)
5450 g_warning ("Tried to change the file chooser action to SAVE or CREATE_FOLDER, but "
5451 "this is not allowed in multiple selection mode. Resetting the file chooser "
5452 "to single selection mode.");
5453 set_select_multiple (impl, FALSE, TRUE);
5455 impl->action = action;
5456 update_cell_renderer_attributes (impl);
5457 update_appearance (impl);
5458 settings_load (impl);
5463 case GTK_FILE_CHOOSER_PROP_FILE_SYSTEM_BACKEND:
5464 /* Ignore property */
5467 case GTK_FILE_CHOOSER_PROP_FILTER:
5468 set_current_filter (impl, g_value_get_object (value));
5471 case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
5472 set_local_only (impl, g_value_get_boolean (value));
5475 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
5476 set_preview_widget (impl, g_value_get_object (value));
5479 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE:
5480 impl->preview_widget_active = g_value_get_boolean (value);
5481 update_preview_widget_visibility (impl);
5484 case GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL:
5485 impl->use_preview_label = g_value_get_boolean (value);
5486 update_preview_widget_visibility (impl);
5489 case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
5490 set_extra_widget (impl, g_value_get_object (value));
5493 case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
5495 gboolean select_multiple = g_value_get_boolean (value);
5496 if ((impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
5497 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
5500 g_warning ("Tried to set the file chooser to multiple selection mode, but this is "
5501 "not allowed in SAVE or CREATE_FOLDER modes. Ignoring the change and "
5502 "leaving the file chooser in single selection mode.");
5506 set_select_multiple (impl, select_multiple, FALSE);
5510 case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN:
5512 gboolean show_hidden = g_value_get_boolean (value);
5513 if (show_hidden != impl->show_hidden)
5515 impl->show_hidden = show_hidden;
5517 if (impl->browse_files_model)
5518 _gtk_file_system_model_set_show_hidden (impl->browse_files_model, show_hidden);
5523 case GTK_FILE_CHOOSER_PROP_DO_OVERWRITE_CONFIRMATION:
5525 gboolean do_overwrite_confirmation = g_value_get_boolean (value);
5526 impl->do_overwrite_confirmation = do_overwrite_confirmation;
5530 case GTK_FILE_CHOOSER_PROP_CREATE_FOLDERS:
5532 gboolean create_folders = g_value_get_boolean (value);
5533 impl->create_folders = create_folders;
5534 update_appearance (impl);
5539 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
5545 gtk_file_chooser_default_get_property (GObject *object,
5550 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (object);
5554 case GTK_FILE_CHOOSER_PROP_ACTION:
5555 g_value_set_enum (value, impl->action);
5558 case GTK_FILE_CHOOSER_PROP_FILTER:
5559 g_value_set_object (value, impl->current_filter);
5562 case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
5563 g_value_set_boolean (value, impl->local_only);
5566 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
5567 g_value_set_object (value, impl->preview_widget);
5570 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE:
5571 g_value_set_boolean (value, impl->preview_widget_active);
5574 case GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL:
5575 g_value_set_boolean (value, impl->use_preview_label);
5578 case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
5579 g_value_set_object (value, impl->extra_widget);
5582 case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
5583 g_value_set_boolean (value, impl->select_multiple);
5586 case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN:
5587 g_value_set_boolean (value, impl->show_hidden);
5590 case GTK_FILE_CHOOSER_PROP_DO_OVERWRITE_CONFIRMATION:
5591 g_value_set_boolean (value, impl->do_overwrite_confirmation);
5594 case GTK_FILE_CHOOSER_PROP_CREATE_FOLDERS:
5595 g_value_set_boolean (value, impl->create_folders);
5599 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
5604 /* Removes the settings signal handler. It's safe to call multiple times */
5606 remove_settings_signal (GtkFileChooserDefault *impl,
5609 if (impl->settings_signal_id)
5611 GtkSettings *settings;
5613 settings = gtk_settings_get_for_screen (screen);
5614 g_signal_handler_disconnect (settings,
5615 impl->settings_signal_id);
5616 impl->settings_signal_id = 0;
5621 gtk_file_chooser_default_dispose (GObject *object)
5624 GtkFileChooserDefault *impl = (GtkFileChooserDefault *) object;
5626 if (impl->extra_widget)
5628 g_object_unref (impl->extra_widget);
5629 impl->extra_widget = NULL;
5632 pending_select_files_free (impl);
5634 /* cancel all pending operations */
5635 if (impl->pending_cancellables)
5637 for (l = impl->pending_cancellables; l; l = l->next)
5639 GCancellable *cancellable = G_CANCELLABLE (l->data);
5640 g_cancellable_cancel (cancellable);
5642 g_slist_free (impl->pending_cancellables);
5643 impl->pending_cancellables = NULL;
5646 if (impl->reload_icon_cancellables)
5648 for (l = impl->reload_icon_cancellables; l; l = l->next)
5650 GCancellable *cancellable = G_CANCELLABLE (l->data);
5651 g_cancellable_cancel (cancellable);
5653 g_slist_free (impl->reload_icon_cancellables);
5654 impl->reload_icon_cancellables = NULL;
5657 if (impl->loading_shortcuts)
5659 for (l = impl->loading_shortcuts; l; l = l->next)
5661 GCancellable *cancellable = G_CANCELLABLE (l->data);
5662 g_cancellable_cancel (cancellable);
5664 g_slist_free (impl->loading_shortcuts);
5665 impl->loading_shortcuts = NULL;
5668 if (impl->file_list_drag_data_received_cancellable)
5670 g_cancellable_cancel (impl->file_list_drag_data_received_cancellable);
5671 impl->file_list_drag_data_received_cancellable = NULL;
5674 if (impl->update_current_folder_cancellable)
5676 g_cancellable_cancel (impl->update_current_folder_cancellable);
5677 impl->update_current_folder_cancellable = NULL;
5680 if (impl->show_and_select_files_cancellable)
5682 g_cancellable_cancel (impl->show_and_select_files_cancellable);
5683 impl->show_and_select_files_cancellable = NULL;
5686 if (impl->should_respond_get_info_cancellable)
5688 g_cancellable_cancel (impl->should_respond_get_info_cancellable);
5689 impl->should_respond_get_info_cancellable = NULL;
5692 if (impl->update_from_entry_cancellable)
5694 g_cancellable_cancel (impl->update_from_entry_cancellable);
5695 impl->update_from_entry_cancellable = NULL;
5698 if (impl->shortcuts_activate_iter_cancellable)
5700 g_cancellable_cancel (impl->shortcuts_activate_iter_cancellable);
5701 impl->shortcuts_activate_iter_cancellable = NULL;
5704 search_stop_searching (impl, TRUE);
5705 recent_stop_loading (impl);
5707 remove_settings_signal (impl, gtk_widget_get_screen (GTK_WIDGET (impl)));
5709 G_OBJECT_CLASS (_gtk_file_chooser_default_parent_class)->dispose (object);
5712 /* We override show-all since we have internal widgets that
5713 * shouldn't be shown when you call show_all(), like the filter
5717 gtk_file_chooser_default_show_all (GtkWidget *widget)
5719 GtkFileChooserDefault *impl = (GtkFileChooserDefault *) widget;
5721 gtk_widget_show (widget);
5723 if (impl->extra_widget)
5724 gtk_widget_show_all (impl->extra_widget);
5727 /* Handler for GtkWindow::set-focus; this is where we save the last-focused
5728 * widget on our toplevel. See gtk_file_chooser_default_hierarchy_changed()
5731 toplevel_set_focus_cb (GtkWindow *window,
5733 GtkFileChooserDefault *impl)
5735 impl->toplevel_last_focus_widget = gtk_window_get_focus (window);
5738 /* We monitor the focus widget on our toplevel to be able to know which widget
5739 * was last focused at the time our "should_respond" method gets called.
5742 gtk_file_chooser_default_hierarchy_changed (GtkWidget *widget,
5743 GtkWidget *previous_toplevel)
5745 GtkFileChooserDefault *impl;
5746 GtkWidget *toplevel;
5748 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
5750 if (previous_toplevel)
5752 g_assert (impl->toplevel_set_focus_id != 0);
5753 g_signal_handler_disconnect (previous_toplevel,
5754 impl->toplevel_set_focus_id);
5755 impl->toplevel_set_focus_id = 0;
5756 impl->toplevel_last_focus_widget = NULL;
5759 g_assert (impl->toplevel_set_focus_id == 0);
5761 toplevel = gtk_widget_get_toplevel (widget);
5762 if (GTK_IS_WINDOW (toplevel))
5764 impl->toplevel_set_focus_id = g_signal_connect (toplevel, "set-focus",
5765 G_CALLBACK (toplevel_set_focus_cb), impl);
5766 impl->toplevel_last_focus_widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
5770 /* Changes the icons wherever it is needed */
5772 change_icon_theme (GtkFileChooserDefault *impl)
5774 GtkSettings *settings;
5776 GtkCellRenderer *renderer;
5779 profile_start ("start", NULL);
5781 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl)));
5783 if (gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &width, &height))
5784 impl->icon_size = MAX (width, height);
5786 impl->icon_size = FALLBACK_ICON_SIZE;
5788 shortcuts_reload_icons (impl);
5789 /* the first cell in the first column is the icon column, and we have a fixed size there */
5790 cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (
5791 gtk_tree_view_get_column (GTK_TREE_VIEW (impl->browse_files_tree_view), 0)));
5792 renderer = GTK_CELL_RENDERER (cells->data);
5793 gtk_cell_renderer_set_fixed_size (renderer,
5794 renderer->xpad * 2 + impl->icon_size,
5795 renderer->ypad * 2 + impl->icon_size);
5796 g_list_free (cells);
5797 if (impl->browse_files_model)
5798 _gtk_file_system_model_clear_cache (impl->browse_files_model, MODEL_COL_PIXBUF);
5799 gtk_widget_queue_resize (impl->browse_files_tree_view);
5801 profile_end ("end", NULL);
5804 /* Callback used when a GtkSettings value changes */
5806 settings_notify_cb (GObject *object,
5808 GtkFileChooserDefault *impl)
5812 profile_start ("start", NULL);
5814 name = g_param_spec_get_name (pspec);
5816 if (strcmp (name, "gtk-icon-theme-name") == 0 ||
5817 strcmp (name, "gtk-icon-sizes") == 0)
5818 change_icon_theme (impl);
5820 profile_end ("end", NULL);
5823 /* Installs a signal handler for GtkSettings so that we can monitor changes in
5827 check_icon_theme (GtkFileChooserDefault *impl)
5829 GtkSettings *settings;
5831 profile_start ("start", NULL);
5833 if (impl->settings_signal_id)
5835 profile_end ("end", NULL);
5839 if (gtk_widget_has_screen (GTK_WIDGET (impl)))
5841 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl)));
5842 impl->settings_signal_id = g_signal_connect (settings, "notify",
5843 G_CALLBACK (settings_notify_cb), impl);
5845 change_icon_theme (impl);
5848 profile_end ("end", NULL);
5852 gtk_file_chooser_default_style_set (GtkWidget *widget,
5853 GtkStyle *previous_style)
5855 GtkFileChooserDefault *impl;
5857 profile_start ("start", NULL);
5859 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
5861 profile_msg (" parent class style_set start", NULL);
5862 GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->style_set (widget, previous_style);
5863 profile_msg (" parent class style_set end", NULL);
5865 if (gtk_widget_has_screen (GTK_WIDGET (impl)))
5866 change_icon_theme (impl);
5868 emit_default_size_changed (impl);
5870 profile_end ("end", NULL);
5874 gtk_file_chooser_default_screen_changed (GtkWidget *widget,
5875 GdkScreen *previous_screen)
5877 GtkFileChooserDefault *impl;
5879 profile_start ("start", NULL);
5881 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
5883 if (GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->screen_changed)
5884 GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->screen_changed (widget, previous_screen);
5886 remove_settings_signal (impl, previous_screen);
5887 check_icon_theme (impl);
5889 emit_default_size_changed (impl);
5891 profile_end ("end", NULL);
5895 gtk_file_chooser_default_size_allocate (GtkWidget *widget,
5896 GtkAllocation *allocation)
5898 GtkFileChooserDefault *impl;
5900 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
5902 GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->size_allocate (widget, allocation);
5906 get_is_file_filtered (GtkFileChooserDefault *impl,
5908 GFileInfo *file_info)
5910 GtkFileFilterInfo filter_info;
5911 GtkFileFilterFlags needed;
5914 if (!impl->current_filter)
5917 filter_info.contains = GTK_FILE_FILTER_DISPLAY_NAME | GTK_FILE_FILTER_MIME_TYPE;
5919 needed = gtk_file_filter_get_needed (impl->current_filter);
5921 filter_info.display_name = g_file_info_get_display_name (file_info);
5922 filter_info.mime_type = g_content_type_get_mime_type (g_file_info_get_content_type (file_info));
5924 if (needed & GTK_FILE_FILTER_FILENAME)
5926 filter_info.filename = g_file_get_path (file);
5927 if (filter_info.filename)
5928 filter_info.contains |= GTK_FILE_FILTER_FILENAME;
5931 filter_info.filename = NULL;
5933 if (needed & GTK_FILE_FILTER_URI)
5935 filter_info.uri = g_file_get_uri (file);
5936 if (filter_info.uri)
5937 filter_info.contains |= GTK_FILE_FILTER_URI;
5940 filter_info.uri = NULL;
5942 result = gtk_file_filter_filter (impl->current_filter, &filter_info);
5944 g_free ((gchar *)filter_info.filename);
5945 g_free ((gchar *)filter_info.uri);
5946 g_free ((gchar *)filter_info.mime_type);
5952 set_sort_column (GtkFileChooserDefault *impl)
5954 GtkTreeSortable *sortable;
5956 sortable = GTK_TREE_SORTABLE (gtk_tree_view_get_model (GTK_TREE_VIEW (impl->browse_files_tree_view)));
5957 /* can happen when we're still populating the model */
5958 if (sortable == NULL)
5961 gtk_tree_sortable_set_sort_column_id (sortable,
5967 settings_load (GtkFileChooserDefault *impl)
5969 GtkFileChooserSettings *settings;
5970 LocationMode location_mode;
5971 gboolean show_hidden;
5972 gboolean expand_folders;
5973 gboolean show_size_column;
5975 GtkSortType sort_order;
5977 settings = _gtk_file_chooser_settings_new ();
5979 location_mode = _gtk_file_chooser_settings_get_location_mode (settings);
5980 show_hidden = _gtk_file_chooser_settings_get_show_hidden (settings);
5981 expand_folders = _gtk_file_chooser_settings_get_expand_folders (settings);
5982 show_size_column = _gtk_file_chooser_settings_get_show_size_column (settings);
5983 sort_column = _gtk_file_chooser_settings_get_sort_column (settings);
5984 sort_order = _gtk_file_chooser_settings_get_sort_order (settings);
5986 g_object_unref (settings);
5988 location_mode_set (impl, location_mode, TRUE);
5990 gtk_file_chooser_set_show_hidden (GTK_FILE_CHOOSER (impl), show_hidden);
5992 impl->expand_folders = expand_folders;
5993 if (impl->save_expander)
5994 gtk_expander_set_expanded (GTK_EXPANDER (impl->save_expander), expand_folders);
5996 impl->show_size_column = show_size_column;
5997 if (impl->list_size_column)
5998 gtk_tree_view_column_set_visible (impl->list_size_column, show_size_column);
6000 impl->sort_column = sort_column;
6001 impl->sort_order = sort_order;
6002 /* We don't call set_sort_column() here as the models may not have been
6003 * created yet. The individual functions that create and set the models will
6004 * call set_sort_column() themselves.
6009 save_dialog_geometry (GtkFileChooserDefault *impl, GtkFileChooserSettings *settings)
6011 GtkWindow *toplevel;
6012 int x, y, width, height;
6014 /* We don't save the geometry in non-expanded "save" mode, so that the "little
6015 * dialog" won't make future Open dialogs too small.
6017 if (!(impl->action == GTK_FILE_CHOOSER_ACTION_OPEN
6018 || impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER
6019 || impl->expand_folders))
6022 toplevel = get_toplevel (GTK_WIDGET (impl));
6024 if (!(toplevel && GTK_IS_FILE_CHOOSER_DIALOG (toplevel)))
6027 gtk_window_get_position (toplevel, &x, &y);
6028 gtk_window_get_size (toplevel, &width, &height);
6030 _gtk_file_chooser_settings_set_geometry (settings, x, y, width, height);
6034 settings_save (GtkFileChooserDefault *impl)
6036 GtkFileChooserSettings *settings;
6038 settings = _gtk_file_chooser_settings_new ();
6040 _gtk_file_chooser_settings_set_location_mode (settings, impl->location_mode);
6041 _gtk_file_chooser_settings_set_show_hidden (settings, gtk_file_chooser_get_show_hidden (GTK_FILE_CHOOSER (impl)));
6042 _gtk_file_chooser_settings_set_expand_folders (settings, impl->expand_folders);
6043 _gtk_file_chooser_settings_set_show_size_column (settings, impl->show_size_column);
6044 _gtk_file_chooser_settings_set_sort_column (settings, impl->sort_column);
6045 _gtk_file_chooser_settings_set_sort_order (settings, impl->sort_order);
6047 save_dialog_geometry (impl, settings);
6050 _gtk_file_chooser_settings_save (settings, NULL);
6052 g_object_unref (settings);
6055 /* GtkWidget::realize method */
6057 gtk_file_chooser_default_realize (GtkWidget *widget)
6059 GtkFileChooserDefault *impl;
6061 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
6063 GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->realize (widget);
6065 emit_default_size_changed (impl);
6068 /* GtkWidget::map method */
6070 gtk_file_chooser_default_map (GtkWidget *widget)
6072 GtkFileChooserDefault *impl;
6073 char *current_working_dir;
6075 profile_start ("start", NULL);
6077 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
6079 GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->map (widget);
6081 if (impl->operation_mode == OPERATION_MODE_BROWSE)
6083 switch (impl->reload_state)
6086 /* The user didn't explicitly give us a folder to
6087 * display, so we'll use the cwd
6089 current_working_dir = g_get_current_dir ();
6090 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl),
6091 current_working_dir);
6092 g_free (current_working_dir);
6095 case RELOAD_HAS_FOLDER:
6096 /* Nothing; we are already loading or loaded, so we
6097 * don't need to reload
6101 case RELOAD_WAS_UNMAPPED:
6102 /* Just reload the current folder; else continue
6105 if (impl->current_folder)
6107 pending_select_files_store_selection (impl);
6108 change_folder_and_display_error (impl, impl->current_folder, FALSE);
6113 g_assert_not_reached ();
6117 volumes_bookmarks_changed_cb (impl->file_system, impl);
6119 settings_load (impl);
6121 profile_end ("end", NULL);
6124 /* GtkWidget::unmap method */
6126 gtk_file_chooser_default_unmap (GtkWidget *widget)
6128 GtkFileChooserDefault *impl;
6130 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
6132 settings_save (impl);
6134 GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->unmap (widget);
6136 impl->reload_state = RELOAD_WAS_UNMAPPED;
6140 install_list_model_filter (GtkFileChooserDefault *impl)
6142 _gtk_file_system_model_set_filter (impl->browse_files_model,
6143 impl->current_filter);
6146 #define COMPARE_DIRECTORIES \
6147 GtkFileChooserDefault *impl = user_data; \
6148 gboolean dir_a, dir_b; \
6150 gtk_tree_model_get (model, a, MODEL_COL_IS_FOLDER, &dir_a, -1); \
6151 gtk_tree_model_get (model, b, MODEL_COL_IS_FOLDER, &dir_b, -1); \
6153 if (dir_a != dir_b) \
6154 return impl->list_sort_ascending ? (dir_a ? -1 : 1) : (dir_a ? 1 : -1) /* Directories *always* go first */
6156 /* Sort callback for the filename column */
6158 name_sort_func (GtkTreeModel *model,
6163 COMPARE_DIRECTORIES;
6166 gchar *key_a, *key_b;
6169 gtk_tree_model_get (model, a, MODEL_COL_NAME_COLLATED, &key_a, -1);
6170 gtk_tree_model_get (model, b, MODEL_COL_NAME_COLLATED, &key_b, -1);
6173 result = strcmp (key_a, key_b);
6188 /* Sort callback for the size column */
6190 size_sort_func (GtkTreeModel *model,
6195 COMPARE_DIRECTORIES;
6198 gint64 size_a, size_b;
6200 gtk_tree_model_get (model, a, MODEL_COL_SIZE, &size_a, -1);
6201 gtk_tree_model_get (model, b, MODEL_COL_SIZE, &size_b, -1);
6203 return size_a > size_b ? -1 : (size_a == size_b ? 0 : 1);
6207 /* Sort callback for the mtime column */
6209 mtime_sort_func (GtkTreeModel *model,
6214 COMPARE_DIRECTORIES;
6219 gtk_tree_model_get (model, a, MODEL_COL_MTIME, &ta, -1);
6220 gtk_tree_model_get (model, b, MODEL_COL_MTIME, &tb, -1);
6222 return ta > tb ? -1 : (ta == tb ? 0 : 1);
6226 /* Callback used when the sort column changes. We cache the sort order for use
6227 * in name_sort_func().
6230 list_sort_column_changed_cb (GtkTreeSortable *sortable,
6231 GtkFileChooserDefault *impl)
6233 gint sort_column_id;
6234 GtkSortType sort_type;
6236 if (gtk_tree_sortable_get_sort_column_id (sortable, &sort_column_id, &sort_type))
6238 impl->list_sort_ascending = (sort_type == GTK_SORT_ASCENDING);
6239 impl->sort_column = sort_column_id;
6240 impl->sort_order = sort_type;
6245 set_busy_cursor (GtkFileChooserDefault *impl,
6248 GtkWindow *toplevel;
6249 GdkDisplay *display;
6252 toplevel = get_toplevel (GTK_WIDGET (impl));
6253 if (!toplevel || !GTK_WIDGET_REALIZED (toplevel))
6256 display = gtk_widget_get_display (GTK_WIDGET (toplevel));
6259 cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
6263 gdk_window_set_cursor (GTK_WIDGET (toplevel)->window, cursor);
6264 gdk_display_flush (display);
6267 gdk_cursor_unref (cursor);
6270 /* Creates a sort model to wrap the file system model and sets it on the tree view */
6272 load_set_model (GtkFileChooserDefault *impl)
6274 profile_start ("start", NULL);
6276 g_assert (impl->browse_files_model != NULL);
6278 profile_msg (" gtk_tree_view_set_model start", NULL);
6279 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view),
6280 GTK_TREE_MODEL (impl->browse_files_model));
6281 gtk_tree_view_columns_autosize (GTK_TREE_VIEW (impl->browse_files_tree_view));
6282 gtk_tree_view_set_search_column (GTK_TREE_VIEW (impl->browse_files_tree_view),
6284 set_sort_column (impl);
6285 profile_msg (" gtk_tree_view_set_model end", NULL);
6286 impl->list_sort_ascending = TRUE;
6288 profile_end ("end", NULL);
6291 /* Timeout callback used when the loading timer expires */
6293 load_timeout_cb (gpointer data)
6295 GtkFileChooserDefault *impl;
6297 profile_start ("start", NULL);
6299 impl = GTK_FILE_CHOOSER_DEFAULT (data);
6300 g_assert (impl->load_state == LOAD_PRELOAD);
6301 g_assert (impl->load_timeout_id != 0);
6302 g_assert (impl->browse_files_model != NULL);
6304 impl->load_timeout_id = 0;
6305 impl->load_state = LOAD_LOADING;
6307 load_set_model (impl);
6309 profile_end ("end", NULL);
6314 /* Sets up a new load timer for the model and switches to the LOAD_PRELOAD state */
6316 load_setup_timer (GtkFileChooserDefault *impl)
6318 g_assert (impl->load_timeout_id == 0);
6319 g_assert (impl->load_state != LOAD_PRELOAD);
6321 impl->load_timeout_id = gdk_threads_add_timeout (MAX_LOADING_TIME, load_timeout_cb, impl);
6322 impl->load_state = LOAD_PRELOAD;
6325 /* Removes the load timeout and switches to the LOAD_FINISHED state */
6327 load_remove_timer (GtkFileChooserDefault *impl)
6329 if (impl->load_timeout_id != 0)
6331 g_assert (impl->load_state == LOAD_PRELOAD);
6333 g_source_remove (impl->load_timeout_id);
6334 impl->load_timeout_id = 0;
6335 impl->load_state = LOAD_EMPTY;
6338 g_assert (impl->load_state == LOAD_EMPTY ||
6339 impl->load_state == LOAD_LOADING ||
6340 impl->load_state == LOAD_FINISHED);
6343 /* Selects the first row in the file list */
6345 browse_files_select_first_row (GtkFileChooserDefault *impl)
6348 GtkTreeIter dummy_iter;
6349 GtkTreeModel *tree_model;
6351 path = gtk_tree_path_new_from_indices (0, -1);
6352 tree_model = gtk_tree_view_get_model (GTK_TREE_VIEW (impl->browse_files_tree_view));
6357 /* If the list is empty, do nothing. */
6358 if (gtk_tree_model_get_iter (tree_model, &dummy_iter, path))
6359 gtk_tree_view_set_cursor (GTK_TREE_VIEW (impl->browse_files_tree_view), path, NULL, FALSE);
6361 gtk_tree_path_free (path);
6364 struct center_selected_row_closure {
6365 GtkFileChooserDefault *impl;
6366 gboolean already_centered;
6369 /* Callback used from gtk_tree_selection_selected_foreach(); centers the
6370 * selected row in the tree view.
6373 center_selected_row_foreach_cb (GtkTreeModel *model,
6378 struct center_selected_row_closure *closure;
6381 if (closure->already_centered)
6384 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (closure->impl->browse_files_tree_view), path, NULL, TRUE, 0.5, 0.0);
6385 closure->already_centered = TRUE;
6388 /* Centers the selected row in the tree view */
6390 browse_files_center_selected_row (GtkFileChooserDefault *impl)
6392 struct center_selected_row_closure closure;
6393 GtkTreeSelection *selection;
6395 closure.impl = impl;
6396 closure.already_centered = FALSE;
6398 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
6399 gtk_tree_selection_selected_foreach (selection, center_selected_row_foreach_cb, &closure);
6402 struct ShowAndSelectPathsData
6404 GtkFileChooserDefault *impl;
6409 show_and_select_files_finished_loading (GtkFolder *folder,
6412 gboolean have_hidden;
6413 gboolean have_filtered;
6415 struct ShowAndSelectPathsData *data = user_data;
6417 have_hidden = FALSE;
6418 have_filtered = FALSE;
6420 for (l = data->files; l; l = l->next)
6427 info = _gtk_folder_get_info (folder, file);
6431 have_hidden = g_file_info_get_is_hidden (info)
6432 || g_file_info_get_is_backup (info);
6435 have_filtered = (! _gtk_file_info_consider_as_directory (info)) &&
6436 get_is_file_filtered (data->impl, file, info);
6438 g_object_unref (info);
6440 if (have_hidden && have_filtered)
6441 break; /* we now have all the information we need */
6445 g_signal_handlers_disconnect_by_func (folder,
6446 show_and_select_files_finished_loading,
6450 g_object_set (data->impl, "show-hidden", TRUE, NULL);
6453 set_current_filter (data->impl, NULL);
6455 for (l = data->files; l; l = l->next)
6462 if (!_gtk_file_system_model_get_iter_for_file (data->impl->browse_files_model,
6467 path = gtk_tree_model_get_path (GTK_TREE_MODEL (data->impl->browse_files_model), &iter);
6468 select_func (data->impl->browse_files_model, path, &iter, data->impl);
6469 gtk_tree_path_free (path);
6472 browse_files_center_selected_row (data->impl);
6474 g_object_unref (data->impl);
6475 g_slist_foreach (data->files, (GFunc) g_object_unref, NULL);
6476 g_slist_free (data->files);
6481 show_and_select_files_get_folder_cb (GCancellable *cancellable,
6483 const GError *error,
6486 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
6487 struct ShowAndSelectPathsData *data = user_data;
6489 if (data->impl->show_and_select_files_cancellable != cancellable)
6492 data->impl->show_and_select_files_cancellable = NULL;
6494 if (cancelled || error)
6497 g_object_unref (cancellable);
6499 if (_gtk_folder_is_finished_loading (folder))
6500 show_and_select_files_finished_loading (folder, user_data);
6502 g_signal_connect (folder, "finished-loading",
6503 G_CALLBACK (show_and_select_files_finished_loading),
6509 g_object_unref (data->impl);
6510 g_slist_foreach (data->files, (GFunc) g_object_unref, NULL);
6511 g_slist_free (data->files);
6514 g_object_unref (cancellable);
6518 show_and_select_files (GtkFileChooserDefault *impl,
6523 struct ShowAndSelectPathsData *info;
6525 profile_start ("start", NULL);
6529 profile_end ("end", NULL);
6533 info = g_new (struct ShowAndSelectPathsData, 1);
6534 info->impl = g_object_ref (impl);
6535 info->files = g_slist_copy (files);
6536 g_slist_foreach (info->files, (GFunc) g_object_ref, NULL);
6538 if (impl->show_and_select_files_cancellable)
6539 g_cancellable_cancel (impl->show_and_select_files_cancellable);
6541 impl->show_and_select_files_cancellable =
6542 _gtk_file_system_get_folder (impl->file_system, parent_file,
6543 "standard::is-hidden,standard::is-backup,standard::type,standard::name,standard::content-type",
6544 show_and_select_files_get_folder_cb, info);
6546 profile_end ("end", NULL);
6550 /* Processes the pending operation when a folder is finished loading */
6552 pending_select_files_process (GtkFileChooserDefault *impl)
6554 g_assert (impl->load_state == LOAD_FINISHED);
6555 g_assert (impl->browse_files_model != NULL);
6557 if (impl->pending_select_files)
6560 show_and_select_files (impl, impl->current_folder, impl->pending_select_files, NULL);
6561 pending_select_files_free (impl);
6562 browse_files_center_selected_row (impl);
6566 /* We only select the first row if the chooser is actually mapped ---
6567 * selecting the first row is to help the user when he is interacting with
6568 * the chooser, but sometimes a chooser works not on behalf of the user,
6569 * but rather on behalf of something else like GtkFileChooserButton. In
6570 * that case, the chooser's selection should be what the caller expects,
6571 * as the user can't see that something else got selected. See bug #165264.
6573 if (GTK_WIDGET_MAPPED (impl) && impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
6574 browse_files_select_first_row (impl);
6577 g_assert (impl->pending_select_files == NULL);
6580 /* Callback used when the file system model finishes loading */
6582 browse_files_model_finished_loading_cb (GtkFileSystemModel *model,
6584 GtkFileChooserDefault *impl)
6586 profile_start ("start", NULL);
6588 if (impl->load_state == LOAD_PRELOAD)
6590 load_remove_timer (impl);
6591 load_set_model (impl);
6593 else if (impl->load_state == LOAD_LOADING)
6599 /* We can't g_assert_not_reached(), as something other than us may have
6600 * initiated a folder reload. See #165556.
6602 profile_end ("end", NULL);
6606 g_assert (impl->load_timeout_id == 0);
6608 impl->load_state = LOAD_FINISHED;
6610 pending_select_files_process (impl);
6611 set_busy_cursor (impl, FALSE);
6612 #ifdef PROFILE_FILE_CHOOSER
6613 access ("MARK: *** FINISHED LOADING", F_OK);
6616 profile_end ("end", NULL);
6620 stop_loading_and_clear_list_model (GtkFileChooserDefault *impl)
6622 load_remove_timer (impl); /* This changes the state to LOAD_EMPTY */
6624 if (impl->browse_files_model)
6626 g_object_unref (impl->browse_files_model);
6627 impl->browse_files_model = NULL;
6630 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), NULL);
6634 my_g_format_time_for_display (glong secs)
6639 time_t time_mtime, time_now;
6640 const gchar *format;
6641 gchar *locale_format = NULL;
6643 char *date_str = NULL;
6647 #ifdef HAVE_LOCALTIME_R
6648 localtime_r ((time_t *) &time_mtime, &tm_mtime);
6651 struct tm *ptm = localtime ((time_t *) &timeval.tv_sec);
6655 g_warning ("ptm != NULL failed");
6657 return g_strdup (_("Unknown"));
6660 memcpy ((void *) &tm_mtime, (void *) ptm, sizeof (struct tm));
6662 #endif /* HAVE_LOCALTIME_R */
6664 g_date_set_time_t (&mtime, time_mtime);
6665 time_now = time (NULL);
6666 g_date_set_time_t (&now, time_now);
6668 days_diff = g_date_get_julian (&now) - g_date_get_julian (&mtime);
6670 /* Translators: %H means "hours" and %M means "minutes" */
6672 format = _("%H:%M");
6673 else if (days_diff == 1)
6674 format = _("Yesterday at %H:%M");
6677 if (days_diff > 1 && days_diff < 7)
6678 format = "%A"; /* Days from last week */
6680 format = "%x"; /* Any other date */
6684 /* g_locale_from_utf8() returns a string in the system
6685 * code-page, which is not always the same as that used by the C
6686 * library. For instance when running a GTK+ program with
6687 * LANG=ko on an English version of Windows, the system
6688 * code-page is 1252, but the code-page used by the C library is
6689 * 949. (It's GTK+ itself that sets the C library locale when it
6690 * notices the LANG environment variable. See gtkmain.c The
6691 * Microsoft C library doesn't look at any locale environment
6692 * variables.) We need to pass strftime() a string in the C
6693 * library's code-page. See bug #509885.
6695 locale = setlocale (LC_ALL, NULL);
6697 dot = strchr (locale, '.');
6700 codepage = g_ascii_strtoll (dot+1, NULL, 10);
6702 /* All codepages should fit in 16 bits AFAIK */
6703 if (codepage > 0 && codepage < 65536)
6705 sprintf (charset, "CP%u", (guint) codepage);
6706 locale_format = g_convert (format, -1, charset, "UTF-8", NULL, NULL, NULL);
6710 locale_format = g_locale_from_utf8 (format, -1, NULL, NULL, NULL);
6712 if (locale_format != NULL &&
6713 strftime (buf, sizeof (buf), locale_format, &tm_mtime) != 0)
6716 /* As above but in opposite direction... */
6717 if (codepage > 0 && codepage < 65536)
6718 date_str = g_convert (buf, -1, "UTF-8", charset, NULL, NULL, NULL);
6720 date_str = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
6724 if (date_str == NULL)
6725 date_str = g_strdup (_("Unknown"));
6727 g_free (locale_format);
6731 #define copy_attribute(to, from, attribute) G_STMT_START { \
6732 GFileAttributeType type; \
6735 if (g_file_info_get_attribute_data (from, attribute, &type, &value, NULL)) \
6736 g_file_info_set_attribute (to, attribute, type, value); \
6740 file_system_model_got_thumbnail (GObject *object, GAsyncResult *res, gpointer data)
6742 GtkFileSystemModel *model = data; /* might be unreffed if operation was cancelled */
6743 GFile *file = G_FILE (object);
6744 GFileInfo *queried, *info;
6747 queried = g_file_query_info_finish (file, res, NULL);
6748 if (queried == NULL)
6751 /* now we know model is valid */
6753 /* file was deleted */
6754 if (!_gtk_file_system_model_get_iter_for_file (model, &iter, file))
6757 info = g_file_info_dup (_gtk_file_system_model_get_info (model, &iter));
6759 copy_attribute (info, queried, G_FILE_ATTRIBUTE_THUMBNAIL_PATH);
6760 copy_attribute (info, queried, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED);
6761 copy_attribute (info, queried, G_FILE_ATTRIBUTE_STANDARD_ICON);
6763 _gtk_file_system_model_update_file (model, file, info, FALSE);
6765 g_object_unref (info);
6769 file_system_model_set (GtkFileSystemModel *model,
6776 GtkFileChooserDefault *impl = data;
6780 case MODEL_COL_FILE:
6781 g_value_set_object (value, file);
6783 case MODEL_COL_NAME:
6785 g_value_set_string (value, DEFAULT_NEW_FOLDER_NAME);
6787 g_value_set_string (value, g_file_info_get_display_name (info));
6789 case MODEL_COL_NAME_COLLATED:
6791 g_value_take_string (value, g_utf8_collate_key_for_filename (DEFAULT_NEW_FOLDER_NAME, -1));
6793 g_value_take_string (value, g_utf8_collate_key_for_filename (g_file_info_get_display_name (info), -1));
6795 case MODEL_COL_IS_FOLDER:
6796 g_value_set_boolean (value, info == NULL || _gtk_file_info_consider_as_directory (info));
6798 case MODEL_COL_PIXBUF:
6801 if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_ICON))
6803 g_value_take_object (value, _gtk_file_info_render_icon (info, GTK_WIDGET (impl), impl->icon_size));
6807 GtkTreeModel *tree_model;
6808 GtkTreePath *path, *start, *end;
6811 if (impl->browse_files_tree_view == NULL ||
6812 g_file_info_has_attribute (info, "filechooser::queried"))
6815 tree_model = gtk_tree_view_get_model (GTK_TREE_VIEW (impl->browse_files_tree_view));
6816 if (tree_model != GTK_TREE_MODEL (model))
6819 if (!_gtk_file_system_model_get_iter_for_file (model,
6822 g_assert_not_reached ();
6823 if (!gtk_tree_view_get_visible_range (GTK_TREE_VIEW (impl->browse_files_tree_view), &start, &end))
6825 path = gtk_tree_model_get_path (tree_model, &iter);
6826 if (gtk_tree_path_compare (start, path) != 1 &&
6827 gtk_tree_path_compare (path, end) != 1)
6829 g_file_info_set_attribute_boolean (info, "filechooser::queried", TRUE);
6830 g_file_query_info_async (file,
6831 G_FILE_ATTRIBUTE_THUMBNAIL_PATH ","
6832 G_FILE_ATTRIBUTE_THUMBNAILING_FAILED ","
6833 G_FILE_ATTRIBUTE_STANDARD_ICON,
6836 _gtk_file_system_model_get_cancellable (model),
6837 file_system_model_got_thumbnail,
6840 gtk_tree_path_free (path);
6841 gtk_tree_path_free (start);
6842 gtk_tree_path_free (end);
6847 g_value_set_object (value, NULL);
6849 case MODEL_COL_SIZE:
6850 g_value_set_int64 (value, info ? g_file_info_get_size (info) : 0);
6852 case MODEL_COL_SIZE_TEXT:
6853 if (info == NULL || _gtk_file_info_consider_as_directory (info))
6854 g_value_set_string (value, NULL);
6856 g_value_take_string (value, g_format_size_for_display (g_file_info_get_size (info)));
6858 case MODEL_COL_MTIME:
6859 case MODEL_COL_MTIME_TEXT:
6864 g_file_info_get_modification_time (info, &tv);
6865 if (column == MODEL_COL_MTIME)
6866 g_value_set_long (value, tv.tv_sec);
6867 else if (tv.tv_sec == 0)
6868 g_value_set_static_string (value, _("Unknown"));
6870 g_value_take_string (value, my_g_format_time_for_display (tv.tv_sec));
6873 case MODEL_COL_ELLIPSIZE:
6874 g_value_set_enum (value, info ? PANGO_ELLIPSIZE_END : PANGO_ELLIPSIZE_NONE);
6877 g_assert_not_reached ();
6884 /* Gets rid of the old list model and creates a new one for the current folder */
6886 set_list_model (GtkFileChooserDefault *impl,
6889 g_assert (impl->current_folder != NULL);
6891 profile_start ("start", NULL);
6893 stop_loading_and_clear_list_model (impl);
6895 set_busy_cursor (impl, TRUE);
6896 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), NULL);
6898 impl->browse_files_model =
6899 _gtk_file_system_model_new_for_directory (impl->current_folder,
6901 file_system_model_set,
6903 MODEL_COL_NUM_COLUMNS,
6913 PANGO_TYPE_ELLIPSIZE_MODE);
6915 _gtk_file_system_model_set_show_hidden (impl->browse_files_model, impl->show_hidden);
6917 profile_msg (" set sort function", NULL);
6918 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->browse_files_model), MODEL_COL_NAME, name_sort_func, impl, NULL);
6919 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->browse_files_model), MODEL_COL_SIZE, size_sort_func, impl, NULL);
6920 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->browse_files_model), MODEL_COL_MTIME, mtime_sort_func, impl, NULL);
6921 gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (impl->browse_files_model), NULL, NULL, NULL);
6922 set_sort_column (impl);
6923 impl->list_sort_ascending = TRUE;
6924 g_signal_connect (impl->browse_files_model, "sort-column-changed",
6925 G_CALLBACK (list_sort_column_changed_cb), impl);
6927 load_setup_timer (impl); /* This changes the state to LOAD_PRELOAD */
6929 g_signal_connect (impl->browse_files_model, "finished-loading",
6930 G_CALLBACK (browse_files_model_finished_loading_cb), impl);
6932 install_list_model_filter (impl);
6934 profile_end ("end", NULL);
6939 struct update_chooser_entry_selected_foreach_closure {
6941 GtkTreeIter first_selected_iter;
6945 compare_utf8_filenames (const gchar *a,
6948 gchar *a_folded, *b_folded;
6951 a_folded = g_utf8_strdown (a, -1);
6952 b_folded = g_utf8_strdown (b, -1);
6954 retval = strcmp (a_folded, b_folded);
6963 update_chooser_entry_selected_foreach (GtkTreeModel *model,
6968 struct update_chooser_entry_selected_foreach_closure *closure;
6971 closure->num_selected++;
6973 if (closure->num_selected == 1)
6974 closure->first_selected_iter = *iter;
6978 update_chooser_entry (GtkFileChooserDefault *impl)
6980 GtkTreeSelection *selection;
6981 struct update_chooser_entry_selected_foreach_closure closure;
6982 const char *file_part;
6984 /* no need to update the file chooser's entry if there's no entry */
6985 if (impl->operation_mode == OPERATION_MODE_SEARCH ||
6986 impl->operation_mode == OPERATION_MODE_RECENT ||
6987 !impl->location_entry)
6990 if (!(impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
6991 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER
6992 || ((impl->action == GTK_FILE_CHOOSER_ACTION_OPEN
6993 || impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
6994 && impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)))
6997 g_assert (impl->location_entry != NULL);
6999 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
7000 closure.num_selected = 0;
7001 gtk_tree_selection_selected_foreach (selection, update_chooser_entry_selected_foreach, &closure);
7005 if (closure.num_selected == 0)
7007 goto maybe_clear_entry;
7009 else if (closure.num_selected == 1)
7011 if (impl->operation_mode == OPERATION_MODE_BROWSE)
7014 gboolean change_entry;
7016 info = _gtk_file_system_model_get_info (impl->browse_files_model, &closure.first_selected_iter);
7018 /* If the cursor moved to the row of the newly created folder,
7019 * retrieving info will return NULL.
7024 g_free (impl->browse_files_last_selected_name);
7025 impl->browse_files_last_selected_name =
7026 g_strdup (g_file_info_get_display_name (info));
7028 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
7029 impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
7030 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
7032 /* We don't want the name to change when clicking on a folder... */
7033 change_entry = (! _gtk_file_info_consider_as_directory (info));
7036 change_entry = TRUE; /* ... unless we are in SELECT_FOLDER mode */
7040 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->browse_files_last_selected_name);
7042 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
7043 _gtk_file_chooser_entry_select_filename (GTK_FILE_CHOOSER_ENTRY (impl->location_entry));
7051 g_assert (!(impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
7052 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER));
7054 /* Multiple selection, so just clear the entry. */
7056 g_free (impl->browse_files_last_selected_name);
7057 impl->browse_files_last_selected_name = NULL;
7059 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), "");
7065 if ((impl->action == GTK_FILE_CHOOSER_ACTION_OPEN || impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
7066 && impl->browse_files_last_selected_name)
7068 const char *entry_text;
7070 gboolean clear_entry;
7072 entry_text = gtk_entry_get_text (GTK_ENTRY (impl->location_entry));
7073 len = strlen (entry_text);
7076 /* The file chooser entry may have appended a "/" to its text. So
7077 * take it out, and compare the result to the old selection.
7079 if (entry_text[len - 1] == G_DIR_SEPARATOR)
7083 tmp = g_strndup (entry_text, len - 1);
7084 clear_entry = (compare_utf8_filenames (impl->browse_files_last_selected_name, tmp) == 0);
7088 clear_entry = (compare_utf8_filenames (impl->browse_files_last_selected_name, entry_text) == 0);
7091 clear_entry = FALSE;
7094 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), "");
7099 gtk_file_chooser_default_set_current_folder (GtkFileChooser *chooser,
7103 return gtk_file_chooser_default_update_current_folder (chooser, file, FALSE, FALSE, error);
7107 struct UpdateCurrentFolderData
7109 GtkFileChooserDefault *impl;
7111 gboolean keep_trail;
7112 gboolean clear_entry;
7113 GFile *original_file;
7114 GError *original_error;
7118 update_current_folder_mount_enclosing_volume_cb (GCancellable *cancellable,
7119 GtkFileSystemVolume *volume,
7120 const GError *error,
7123 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
7124 struct UpdateCurrentFolderData *data = user_data;
7125 GtkFileChooserDefault *impl = data->impl;
7127 if (cancellable != impl->update_current_folder_cancellable)
7130 impl->update_current_folder_cancellable = NULL;
7131 set_busy_cursor (impl, FALSE);
7138 error_changing_folder_dialog (data->impl, data->file, g_error_copy (error));
7139 impl->reload_state = RELOAD_EMPTY;
7143 change_folder_and_display_error (impl, data->file, data->clear_entry);
7146 g_object_unref (data->file);
7149 g_object_unref (cancellable);
7153 update_current_folder_get_info_cb (GCancellable *cancellable,
7155 const GError *error,
7158 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
7159 struct UpdateCurrentFolderData *data = user_data;
7160 GtkFileChooserDefault *impl = data->impl;
7162 if (cancellable != impl->update_current_folder_cancellable)
7165 impl->update_current_folder_cancellable = NULL;
7166 impl->reload_state = RELOAD_EMPTY;
7168 set_busy_cursor (impl, FALSE);
7177 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_MOUNTED))
7179 GMountOperation *mount_operation;
7180 GtkWidget *toplevel;
7182 g_object_unref (cancellable);
7183 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (impl));
7185 mount_operation = gtk_mount_operation_new (GTK_WINDOW (toplevel));
7187 set_busy_cursor (impl, TRUE);
7189 impl->update_current_folder_cancellable =
7190 _gtk_file_system_mount_enclosing_volume (impl->file_system, data->file,
7192 update_current_folder_mount_enclosing_volume_cb,
7198 if (!data->original_file)
7200 data->original_file = g_object_ref (data->file);
7201 data->original_error = g_error_copy (error);
7204 parent_file = g_file_get_parent (data->file);
7206 /* get parent path and try to change the folder to that */
7209 g_object_unref (data->file);
7210 data->file = parent_file;
7212 g_object_unref (cancellable);
7214 /* restart the update current folder operation */
7215 impl->reload_state = RELOAD_HAS_FOLDER;
7217 impl->update_current_folder_cancellable =
7218 _gtk_file_system_get_info (impl->file_system, data->file,
7220 update_current_folder_get_info_cb,
7223 set_busy_cursor (impl, TRUE);
7229 /* Error and bail out, ignoring "not found" errors since they're useless:
7230 * they only happen when a program defaults to a folder that has been (re)moved.
7232 if (!g_error_matches (data->original_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
7233 error_changing_folder_dialog (impl, data->original_file, data->original_error);
7235 g_error_free (data->original_error);
7237 g_object_unref (data->original_file);
7243 if (data->original_file)
7245 /* Error and bail out, ignoring "not found" errors since they're useless:
7246 * they only happen when a program defaults to a folder that has been (re)moved.
7248 if (!g_error_matches (data->original_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
7249 error_changing_folder_dialog (impl, data->original_file, data->original_error);
7251 g_error_free (data->original_error);
7253 g_object_unref (data->original_file);
7256 if (! _gtk_file_info_consider_as_directory (info))
7259 if (!_gtk_path_bar_set_file (GTK_PATH_BAR (impl->browse_path_bar), data->file, data->keep_trail, NULL))
7262 if (impl->current_folder != data->file)
7264 if (impl->current_folder)
7265 g_object_unref (impl->current_folder);
7267 impl->current_folder = g_object_ref (data->file);
7270 impl->reload_state = RELOAD_HAS_FOLDER;
7272 /* Update the widgets that may trigger a folder change themselves. */
7274 if (!impl->changing_folder)
7276 impl->changing_folder = TRUE;
7278 shortcuts_update_current_folder (impl);
7280 impl->changing_folder = FALSE;
7283 /* Set the folder on the save entry */
7285 if (impl->location_entry)
7287 _gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->location_entry),
7288 impl->current_folder);
7290 if (data->clear_entry)
7291 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), "");
7294 /* Create a new list model. This is slightly evil; we store the result value
7295 * but perform more actions rather than returning immediately even if it
7296 * generates an error.
7298 set_list_model (impl, NULL);
7300 /* Refresh controls */
7302 shortcuts_find_current_folder (impl);
7304 g_signal_emit_by_name (impl, "current-folder-changed", 0);
7306 check_preview_change (impl);
7307 bookmarks_check_add_sensitivity (impl);
7309 g_signal_emit_by_name (impl, "selection-changed", 0);
7312 g_object_unref (data->file);
7315 g_object_unref (cancellable);
7319 gtk_file_chooser_default_update_current_folder (GtkFileChooser *chooser,
7321 gboolean keep_trail,
7322 gboolean clear_entry,
7325 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7326 struct UpdateCurrentFolderData *data;
7328 profile_start ("start", NULL);
7330 g_object_ref (file);
7332 switch (impl->operation_mode)
7334 case OPERATION_MODE_SEARCH:
7335 search_switch_to_browse_mode (impl);
7337 case OPERATION_MODE_RECENT:
7338 recent_switch_to_browse_mode (impl);
7340 case OPERATION_MODE_BROWSE:
7344 if (impl->local_only && !g_file_is_native (file))
7346 g_set_error_literal (error,
7347 GTK_FILE_CHOOSER_ERROR,
7348 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
7349 _("Cannot change to folder because it is not local"));
7351 g_object_unref (file);
7352 profile_end ("end - not local", NULL);
7356 if (impl->update_current_folder_cancellable)
7357 g_cancellable_cancel (impl->update_current_folder_cancellable);
7359 /* Test validity of path here. */
7360 data = g_new0 (struct UpdateCurrentFolderData, 1);
7362 data->file = g_object_ref (file);
7363 data->keep_trail = keep_trail;
7364 data->clear_entry = clear_entry;
7366 impl->reload_state = RELOAD_HAS_FOLDER;
7368 impl->update_current_folder_cancellable =
7369 _gtk_file_system_get_info (impl->file_system, file,
7371 update_current_folder_get_info_cb,
7374 set_busy_cursor (impl, TRUE);
7375 g_object_unref (file);
7377 profile_end ("end", NULL);
7382 gtk_file_chooser_default_get_current_folder (GtkFileChooser *chooser)
7384 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7386 if (impl->operation_mode == OPERATION_MODE_SEARCH ||
7387 impl->operation_mode == OPERATION_MODE_RECENT)
7390 if (impl->reload_state == RELOAD_EMPTY)
7392 char *current_working_dir;
7395 /* We are unmapped, or we had an error while loading the last folder. We'll return
7396 * the $cwd since once we get (re)mapped, we'll load $cwd anyway unless the caller
7397 * explicitly calls set_current_folder() on us.
7399 current_working_dir = g_get_current_dir ();
7400 file = g_file_new_for_path (current_working_dir);
7401 g_free (current_working_dir);
7405 if (impl->current_folder)
7406 return g_object_ref (impl->current_folder);
7412 gtk_file_chooser_default_set_current_name (GtkFileChooser *chooser,
7415 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7417 g_return_if_fail (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
7418 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER);
7420 pending_select_files_free (impl);
7421 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), name);
7425 select_func (GtkFileSystemModel *model,
7430 GtkFileChooserDefault *impl = user_data;
7431 GtkTreeSelection *selection;
7433 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
7435 gtk_tree_selection_select_iter (selection, iter);
7439 gtk_file_chooser_default_select_file (GtkFileChooser *chooser,
7443 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7447 parent_file = g_file_get_parent (file);
7450 return gtk_file_chooser_set_current_folder_file (chooser, file, error);
7452 if (impl->operation_mode == OPERATION_MODE_SEARCH ||
7453 impl->operation_mode == OPERATION_MODE_RECENT ||
7454 impl->load_state == LOAD_EMPTY)
7460 g_assert (impl->current_folder != NULL);
7462 same_path = g_file_equal (parent_file, impl->current_folder);
7465 if (same_path && impl->load_state == LOAD_FINISHED)
7470 files.data = (gpointer) file;
7473 result = show_and_select_files (impl, parent_file, &files, error);
7474 g_object_unref (parent_file);
7478 pending_select_files_add (impl, file);
7484 result = gtk_file_chooser_set_current_folder_file (chooser, parent_file, error);
7485 g_object_unref (parent_file);
7489 g_object_unref (parent_file);
7494 gtk_file_chooser_default_unselect_file (GtkFileChooser *chooser,
7497 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7498 GtkTreeView *tree_view = GTK_TREE_VIEW (impl->browse_files_tree_view);
7501 if (!impl->browse_files_model)
7504 if (!_gtk_file_system_model_get_iter_for_file (impl->browse_files_model,
7509 gtk_tree_selection_unselect_iter (gtk_tree_view_get_selection (tree_view),
7514 maybe_select (GtkTreeModel *model,
7519 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (data);
7520 GtkTreeSelection *selection;
7523 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
7525 gtk_tree_model_get (model, iter,
7526 MODEL_COL_IS_FOLDER, &is_folder,
7529 if ((is_folder && impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) ||
7530 (!is_folder && impl->action == GTK_FILE_CHOOSER_ACTION_OPEN))
7531 gtk_tree_selection_select_iter (selection, iter);
7533 gtk_tree_selection_unselect_iter (selection, iter);
7539 gtk_file_chooser_default_select_all (GtkFileChooser *chooser)
7541 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7543 if (impl->operation_mode == OPERATION_MODE_SEARCH ||
7544 impl->operation_mode == OPERATION_MODE_RECENT)
7546 GtkTreeSelection *selection;
7548 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
7549 gtk_tree_selection_select_all (selection);
7553 if (impl->select_multiple)
7554 gtk_tree_model_foreach (GTK_TREE_MODEL (impl->browse_files_model),
7555 maybe_select, impl);
7559 gtk_file_chooser_default_unselect_all (GtkFileChooser *chooser)
7561 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7562 GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
7564 gtk_tree_selection_unselect_all (selection);
7565 pending_select_files_free (impl);
7568 /* Checks whether the filename entry for the Save modes contains a well-formed filename.
7570 * is_well_formed_ret - whether what the user typed passes gkt_file_system_make_path()
7572 * is_empty_ret - whether the file entry is totally empty
7574 * is_file_part_empty_ret - whether the file part is empty (will be if user types "foobar/", and
7575 * the path will be "$cwd/foobar")
7578 check_save_entry (GtkFileChooserDefault *impl,
7580 gboolean *is_well_formed_ret,
7581 gboolean *is_empty_ret,
7582 gboolean *is_file_part_empty_ret,
7583 gboolean *is_folder)
7585 GtkFileChooserEntry *chooser_entry;
7586 GFile *current_folder;
7587 const char *file_part;
7591 g_assert (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
7592 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER
7593 || ((impl->action == GTK_FILE_CHOOSER_ACTION_OPEN
7594 || impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
7595 && impl->location_mode == LOCATION_MODE_FILENAME_ENTRY));
7597 chooser_entry = GTK_FILE_CHOOSER_ENTRY (impl->location_entry);
7599 if (strlen (gtk_entry_get_text (GTK_ENTRY (chooser_entry))) == 0)
7602 *is_well_formed_ret = TRUE;
7603 *is_empty_ret = TRUE;
7604 *is_file_part_empty_ret = TRUE;
7610 *is_empty_ret = FALSE;
7612 current_folder = _gtk_file_chooser_entry_get_current_folder (chooser_entry);
7613 if (!current_folder)
7616 *is_well_formed_ret = FALSE;
7617 *is_file_part_empty_ret = FALSE;
7623 file_part = _gtk_file_chooser_entry_get_file_part (chooser_entry);
7625 if (!file_part || file_part[0] == '\0')
7627 *file_ret = g_object_ref (current_folder);
7628 *is_well_formed_ret = TRUE;
7629 *is_file_part_empty_ret = TRUE;
7635 *is_file_part_empty_ret = FALSE;
7638 file = g_file_get_child_for_display_name (current_folder, file_part, &error);
7642 error_building_filename_dialog (impl, error);
7644 *is_well_formed_ret = FALSE;
7651 *is_well_formed_ret = TRUE;
7652 *is_folder = _gtk_file_chooser_entry_get_is_folder (chooser_entry, file);
7655 struct get_files_closure {
7656 GtkFileChooserDefault *impl;
7658 GFile *file_from_entry;
7662 get_files_foreach (GtkTreeModel *model,
7667 struct get_files_closure *info;
7669 GtkFileSystemModel *fs_model;
7672 fs_model = info->impl->browse_files_model;
7674 file = _gtk_file_system_model_get_file (fs_model, iter);
7676 return; /* We are on the editable row */
7678 if (!info->file_from_entry || !g_file_equal (info->file_from_entry, file))
7679 info->result = g_slist_prepend (info->result, g_object_ref (file));
7683 gtk_file_chooser_default_get_files (GtkFileChooser *chooser)
7685 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7686 struct get_files_closure info;
7687 GtkWindow *toplevel;
7688 GtkWidget *current_focus;
7689 gboolean file_list_seen;
7691 if (impl->operation_mode == OPERATION_MODE_SEARCH)
7692 return search_get_selected_files (impl);
7694 if (impl->operation_mode == OPERATION_MODE_RECENT)
7695 return recent_get_selected_files (impl);
7699 info.file_from_entry = NULL;
7701 toplevel = get_toplevel (GTK_WIDGET (impl));
7703 current_focus = gtk_window_get_focus (toplevel);
7705 current_focus = NULL;
7707 file_list_seen = FALSE;
7708 if (current_focus == impl->browse_files_tree_view)
7710 GtkTreeSelection *selection;
7714 file_list_seen = TRUE;
7715 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
7716 gtk_tree_selection_selected_foreach (selection, get_files_foreach, &info);
7718 /* If there is no selection in the file list, we probably have this situation:
7720 * 1. The user typed a filename in the SAVE filename entry ("foo.txt").
7721 * 2. He then double-clicked on a folder ("bar") in the file list
7723 * So we want the selection to be "bar/foo.txt". Jump to the case for the
7724 * filename entry to see if that is the case.
7726 if (info.result == NULL && impl->location_entry)
7729 else if (impl->location_entry && current_focus == impl->location_entry)
7731 gboolean is_well_formed, is_empty, is_file_part_empty, is_folder;
7735 check_save_entry (impl, &info.file_from_entry, &is_well_formed, &is_empty, &is_file_part_empty, &is_folder);
7740 if (!is_well_formed)
7743 if (is_file_part_empty && impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
7745 g_object_unref (info.file_from_entry);
7749 if (info.file_from_entry)
7750 info.result = g_slist_prepend (info.result, info.file_from_entry);
7751 else if (!file_list_seen)
7756 else if (impl->toplevel_last_focus_widget == impl->browse_files_tree_view)
7758 else if (impl->location_entry && impl->toplevel_last_focus_widget == impl->location_entry)
7762 /* The focus is on a dialog's action area button or something else */
7763 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
7764 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
7772 /* If there's no folder selected, and we're in SELECT_FOLDER mode, then we
7773 * fall back to the current directory */
7774 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER &&
7775 info.result == NULL)
7777 GFile *current_folder;
7779 current_folder = gtk_file_chooser_get_current_folder_file (chooser);
7782 info.result = g_slist_prepend (info.result, current_folder);
7785 return g_slist_reverse (info.result);
7789 gtk_file_chooser_default_get_preview_file (GtkFileChooser *chooser)
7791 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7793 if (impl->preview_file)
7794 return g_object_ref (impl->preview_file);
7799 static GtkFileSystem *
7800 gtk_file_chooser_default_get_file_system (GtkFileChooser *chooser)
7802 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7804 return impl->file_system;
7807 /* Shows or hides the filter widgets */
7809 show_filters (GtkFileChooserDefault *impl,
7813 gtk_widget_show (impl->filter_combo_hbox);
7815 gtk_widget_hide (impl->filter_combo_hbox);
7819 gtk_file_chooser_default_add_filter (GtkFileChooser *chooser,
7820 GtkFileFilter *filter)
7822 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7825 if (g_slist_find (impl->filters, filter))
7827 g_warning ("gtk_file_chooser_add_filter() called on filter already in list\n");
7831 g_object_ref_sink (filter);
7832 impl->filters = g_slist_append (impl->filters, filter);
7834 name = gtk_file_filter_get_name (filter);
7836 name = "Untitled filter"; /* Place-holder, doesn't need to be marked for translation */
7838 gtk_combo_box_append_text (GTK_COMBO_BOX (impl->filter_combo), name);
7840 if (!g_slist_find (impl->filters, impl->current_filter))
7841 set_current_filter (impl, filter);
7843 show_filters (impl, TRUE);
7847 gtk_file_chooser_default_remove_filter (GtkFileChooser *chooser,
7848 GtkFileFilter *filter)
7850 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7851 GtkTreeModel *model;
7855 filter_index = g_slist_index (impl->filters, filter);
7857 if (filter_index < 0)
7859 g_warning ("gtk_file_chooser_remove_filter() called on filter not in list\n");
7863 impl->filters = g_slist_remove (impl->filters, filter);
7865 if (filter == impl->current_filter)
7868 set_current_filter (impl, impl->filters->data);
7870 set_current_filter (impl, NULL);
7873 /* Remove row from the combo box */
7874 model = gtk_combo_box_get_model (GTK_COMBO_BOX (impl->filter_combo));
7875 if (!gtk_tree_model_iter_nth_child (model, &iter, NULL, filter_index))
7876 g_assert_not_reached ();
7878 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
7880 g_object_unref (filter);
7883 show_filters (impl, FALSE);
7887 gtk_file_chooser_default_list_filters (GtkFileChooser *chooser)
7889 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7891 return g_slist_copy (impl->filters);
7894 /* Returns the position in the shortcuts tree where the nth specified shortcut would appear */
7896 shortcuts_get_pos_for_shortcut_folder (GtkFileChooserDefault *impl,
7899 return pos + shortcuts_get_index (impl, SHORTCUTS_SHORTCUTS);
7902 struct AddShortcutData
7904 GtkFileChooserDefault *impl;
7909 add_shortcut_get_info_cb (GCancellable *cancellable,
7911 const GError *error,
7915 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
7916 struct AddShortcutData *data = user_data;
7918 if (!g_slist_find (data->impl->loading_shortcuts, cancellable))
7921 data->impl->loading_shortcuts = g_slist_remove (data->impl->loading_shortcuts, cancellable);
7923 if (cancelled || error || (! _gtk_file_info_consider_as_directory (info)))
7926 pos = shortcuts_get_pos_for_shortcut_folder (data->impl, data->impl->num_shortcuts);
7928 shortcuts_insert_file (data->impl, pos, SHORTCUT_TYPE_FILE, NULL, data->file, NULL, FALSE, SHORTCUTS_SHORTCUTS);
7931 g_object_unref (data->impl);
7932 g_object_unref (data->file);
7935 g_object_unref (cancellable);
7939 gtk_file_chooser_default_add_shortcut_folder (GtkFileChooser *chooser,
7943 GCancellable *cancellable;
7944 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
7945 struct AddShortcutData *data;
7949 /* Avoid adding duplicates */
7950 pos = shortcut_find_position (impl, file);
7951 if (pos >= 0 && pos < shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR))
7955 uri = g_file_get_uri (file);
7956 /* translators, "Shortcut" means "Bookmark" here */
7958 GTK_FILE_CHOOSER_ERROR,
7959 GTK_FILE_CHOOSER_ERROR_ALREADY_EXISTS,
7960 _("Shortcut %s already exists"),
7967 for (l = impl->loading_shortcuts; l; l = l->next)
7969 GCancellable *c = l->data;
7972 f = g_object_get_data (G_OBJECT (c), "add-shortcut-path-key");
7973 if (f && g_file_equal (file, f))
7977 uri = g_file_get_uri (file);
7979 GTK_FILE_CHOOSER_ERROR,
7980 GTK_FILE_CHOOSER_ERROR_ALREADY_EXISTS,
7981 _("Shortcut %s already exists"),
7989 data = g_new0 (struct AddShortcutData, 1);
7990 data->impl = g_object_ref (impl);
7991 data->file = g_object_ref (file);
7993 cancellable = _gtk_file_system_get_info (impl->file_system, file,
7995 add_shortcut_get_info_cb, data);
8000 impl->loading_shortcuts = g_slist_append (impl->loading_shortcuts, cancellable);
8001 g_object_set_data (G_OBJECT (cancellable), "add-shortcut-path-key", data->file);
8007 gtk_file_chooser_default_remove_shortcut_folder (GtkFileChooser *chooser,
8011 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
8018 for (l = impl->loading_shortcuts; l; l = l->next)
8020 GCancellable *c = l->data;
8023 f = g_object_get_data (G_OBJECT (c), "add-shortcut-path-key");
8024 if (f && g_file_equal (file, f))
8026 impl->loading_shortcuts = g_slist_remove (impl->loading_shortcuts, c);
8027 g_cancellable_cancel (c);
8032 if (impl->num_shortcuts == 0)
8035 pos = shortcuts_get_pos_for_shortcut_folder (impl, 0);
8036 if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos))
8037 g_assert_not_reached ();
8039 for (i = 0; i < impl->num_shortcuts; i++)
8042 ShortcutType shortcut_type;
8045 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
8046 SHORTCUTS_COL_DATA, &col_data,
8047 SHORTCUTS_COL_TYPE, &shortcut_type,
8049 g_assert (col_data != NULL);
8050 g_assert (shortcut_type == SHORTCUT_TYPE_FILE);
8052 shortcut = col_data;
8053 if (g_file_equal (shortcut, file))
8055 shortcuts_remove_rows (impl, pos + i, 1);
8056 impl->num_shortcuts--;
8060 if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
8061 g_assert_not_reached ();
8066 uri = g_file_get_uri (file);
8067 /* translators, "Shortcut" means "Bookmark" here */
8069 GTK_FILE_CHOOSER_ERROR,
8070 GTK_FILE_CHOOSER_ERROR_NONEXISTENT,
8071 _("Shortcut %s does not exist"),
8079 gtk_file_chooser_default_list_shortcut_folders (GtkFileChooser *chooser)
8081 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
8087 if (impl->num_shortcuts == 0)
8090 pos = shortcuts_get_pos_for_shortcut_folder (impl, 0);
8091 if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos))
8092 g_assert_not_reached ();
8096 for (i = 0; i < impl->num_shortcuts; i++)
8099 ShortcutType shortcut_type;
8102 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
8103 SHORTCUTS_COL_DATA, &col_data,
8104 SHORTCUTS_COL_TYPE, &shortcut_type,
8106 g_assert (col_data != NULL);
8107 g_assert (shortcut_type == SHORTCUT_TYPE_FILE);
8109 shortcut = col_data;
8110 list = g_slist_prepend (list, g_object_ref (shortcut));
8112 if (i != impl->num_shortcuts - 1)
8114 if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
8115 g_assert_not_reached ();
8119 return g_slist_reverse (list);
8122 /* Guesses a size based upon font sizes */
8124 find_good_size_from_style (GtkWidget *widget,
8128 GtkFileChooserDefault *impl;
8133 g_assert (widget->style != NULL);
8134 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
8136 screen = gtk_widget_get_screen (widget);
8139 resolution = gdk_screen_get_resolution (screen);
8140 if (resolution < 0.0) /* will be -1 if the resolution is not defined in the GdkScreen */
8144 resolution = 96.0; /* wheeee */
8146 font_size = pango_font_description_get_size (widget->style->font_desc);
8147 font_size = PANGO_PIXELS (font_size) * resolution / 72.0;
8149 *width = font_size * NUM_CHARS;
8150 *height = font_size * NUM_LINES;
8154 gtk_file_chooser_default_get_default_size (GtkFileChooserEmbed *chooser_embed,
8155 gint *default_width,
8156 gint *default_height)
8158 GtkFileChooserDefault *impl;
8161 impl = GTK_FILE_CHOOSER_DEFAULT (chooser_embed);
8163 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN
8164 || impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER
8165 || impl->expand_folders)
8167 GtkFileChooserSettings *settings;
8168 int x, y, width, height;
8170 settings = _gtk_file_chooser_settings_new ();
8171 _gtk_file_chooser_settings_get_geometry (settings, &x, &y, &width, &height);
8172 g_object_unref (settings);
8174 if (x >= 0 && y >= 0 && width > 0 && height > 0)
8176 *default_width = width;
8177 *default_height = height;
8181 find_good_size_from_style (GTK_WIDGET (chooser_embed), default_width, default_height);
8183 if (impl->preview_widget_active &&
8184 impl->preview_widget &&
8185 GTK_WIDGET_VISIBLE (impl->preview_widget))
8187 gtk_widget_size_request (impl->preview_box, &req);
8188 *default_width += PREVIEW_HBOX_SPACING + req.width;
8191 if (impl->extra_widget &&
8192 GTK_WIDGET_VISIBLE (impl->extra_widget))
8194 gtk_widget_size_request (impl->extra_align, &req);
8195 *default_height += GTK_BOX (chooser_embed)->spacing + req.height;
8200 gtk_widget_size_request (GTK_WIDGET (impl), &req);
8201 *default_width = req.width;
8202 *default_height = req.height;
8206 struct switch_folder_closure {
8207 GtkFileChooserDefault *impl;
8212 /* Used from gtk_tree_selection_selected_foreach() in switch_to_selected_folder() */
8214 switch_folder_foreach_cb (GtkTreeModel *model,
8219 struct switch_folder_closure *closure;
8223 closure->file = _gtk_file_system_model_get_file (closure->impl->browse_files_model, iter);
8224 closure->num_selected++;
8227 /* Changes to the selected folder in the list view */
8229 switch_to_selected_folder (GtkFileChooserDefault *impl)
8231 GtkTreeSelection *selection;
8232 struct switch_folder_closure closure;
8234 /* We do this with foreach() rather than get_selected() as we may be in
8235 * multiple selection mode
8238 closure.impl = impl;
8239 closure.file = NULL;
8240 closure.num_selected = 0;
8242 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
8243 gtk_tree_selection_selected_foreach (selection, switch_folder_foreach_cb, &closure);
8245 g_assert (closure.file && closure.num_selected == 1);
8247 change_folder_and_display_error (impl, closure.file, FALSE);
8250 /* Gets the GFileInfo for the selected row in the file list; assumes single
8254 get_selected_file_info_from_file_list (GtkFileChooserDefault *impl,
8255 gboolean *had_selection)
8257 GtkTreeSelection *selection;
8261 g_assert (!impl->select_multiple);
8262 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
8263 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
8265 *had_selection = FALSE;
8269 *had_selection = TRUE;
8271 info = _gtk_file_system_model_get_info (impl->browse_files_model, &iter);
8275 /* Gets the display name of the selected file in the file list; assumes single
8276 * selection mode and that something is selected.
8278 static const gchar *
8279 get_display_name_from_file_list (GtkFileChooserDefault *impl)
8282 gboolean had_selection;
8284 info = get_selected_file_info_from_file_list (impl, &had_selection);
8285 g_assert (had_selection);
8286 g_assert (info != NULL);
8288 return g_file_info_get_display_name (info);
8292 add_custom_button_to_dialog (GtkDialog *dialog,
8293 const gchar *mnemonic_label,
8294 const gchar *stock_id,
8299 button = gtk_button_new_with_mnemonic (mnemonic_label);
8300 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
8301 gtk_button_set_image (GTK_BUTTON (button),
8302 gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON));
8303 gtk_widget_show (button);
8305 gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, response_id);
8308 /* Presents an overwrite confirmation dialog; returns whether we should accept
8312 confirm_dialog_should_accept_filename (GtkFileChooserDefault *impl,
8313 const gchar *file_part,
8314 const gchar *folder_display_name)
8316 GtkWindow *toplevel;
8320 toplevel = get_toplevel (GTK_WIDGET (impl));
8322 dialog = gtk_message_dialog_new (toplevel,
8323 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
8324 GTK_MESSAGE_QUESTION,
8326 _("A file named \"%s\" already exists. Do you want to replace it?"),
8328 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
8329 _("The file already exists in \"%s\". Replacing it will "
8330 "overwrite its contents."),
8331 folder_display_name);
8333 gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
8334 add_custom_button_to_dialog (GTK_DIALOG (dialog), _("_Replace"),
8335 GTK_STOCK_SAVE_AS, GTK_RESPONSE_ACCEPT);
8336 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
8337 GTK_RESPONSE_ACCEPT,
8338 GTK_RESPONSE_CANCEL,
8340 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
8342 if (toplevel->group)
8343 gtk_window_group_add_window (toplevel->group, GTK_WINDOW (dialog));
8345 response = gtk_dialog_run (GTK_DIALOG (dialog));
8347 gtk_widget_destroy (dialog);
8349 return (response == GTK_RESPONSE_ACCEPT);
8352 struct GetDisplayNameData
8354 GtkFileChooserDefault *impl;
8359 confirmation_confirm_get_info_cb (GCancellable *cancellable,
8361 const GError *error,
8364 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
8365 gboolean should_respond = FALSE;
8366 struct GetDisplayNameData *data = user_data;
8368 if (cancellable != data->impl->should_respond_get_info_cancellable)
8371 data->impl->should_respond_get_info_cancellable = NULL;
8377 /* Huh? Did the folder disappear? Let the caller deal with it */
8378 should_respond = TRUE;
8380 should_respond = confirm_dialog_should_accept_filename (data->impl, data->file_part, g_file_info_get_display_name (info));
8382 set_busy_cursor (data->impl, FALSE);
8384 g_signal_emit_by_name (data->impl, "response-requested");
8387 g_object_unref (data->impl);
8388 g_free (data->file_part);
8391 g_object_unref (cancellable);
8394 /* Does overwrite confirmation if appropriate, and returns whether the dialog
8395 * should respond. Can get the file part from the file list or the save entry.
8398 should_respond_after_confirm_overwrite (GtkFileChooserDefault *impl,
8399 const gchar *file_part,
8402 GtkFileChooserConfirmation conf;
8404 if (!impl->do_overwrite_confirmation)
8407 conf = GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM;
8409 g_signal_emit_by_name (impl, "confirm-overwrite", &conf);
8413 case GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM:
8415 struct GetDisplayNameData *data;
8417 g_assert (file_part != NULL);
8419 data = g_new0 (struct GetDisplayNameData, 1);
8420 data->impl = g_object_ref (impl);
8421 data->file_part = g_strdup (file_part);
8423 if (impl->should_respond_get_info_cancellable)
8424 g_cancellable_cancel (impl->should_respond_get_info_cancellable);
8426 impl->should_respond_get_info_cancellable =
8427 _gtk_file_system_get_info (impl->file_system, parent_file,
8428 "standard::display-name",
8429 confirmation_confirm_get_info_cb,
8431 set_busy_cursor (data->impl, TRUE);
8435 case GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME:
8438 case GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN:
8442 g_assert_not_reached ();
8447 struct FileExistsData
8449 GtkFileChooserDefault *impl;
8450 gboolean file_exists_and_is_not_folder;
8456 save_entry_get_info_cb (GCancellable *cancellable,
8458 const GError *error,
8461 gboolean parent_is_folder;
8462 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
8463 struct FileExistsData *data = user_data;
8465 if (cancellable != data->impl->should_respond_get_info_cancellable)
8468 data->impl->should_respond_get_info_cancellable = NULL;
8470 set_busy_cursor (data->impl, FALSE);
8476 parent_is_folder = FALSE;
8478 parent_is_folder = _gtk_file_info_consider_as_directory (info);
8480 if (parent_is_folder)
8482 if (data->impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
8484 if (data->file_exists_and_is_not_folder)
8489 /* Dup the string because the string may be modified
8490 * depending on what clients do in the confirm-overwrite
8491 * signal and this corrupts the pointer
8493 file_part = g_strdup (_gtk_file_chooser_entry_get_file_part (GTK_FILE_CHOOSER_ENTRY (data->impl->location_entry)));
8494 retval = should_respond_after_confirm_overwrite (data->impl, file_part, data->parent_file);
8498 g_signal_emit_by_name (data->impl, "response-requested");
8501 g_signal_emit_by_name (data->impl, "response-requested");
8503 else /* GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER */
8505 GError *error = NULL;
8507 set_busy_cursor (data->impl, TRUE);
8508 g_file_make_directory (data->file, NULL, &error);
8509 set_busy_cursor (data->impl, FALSE);
8512 g_signal_emit_by_name (data->impl, "response-requested");
8514 error_creating_folder_dialog (data->impl, data->file, error);
8519 /* This will display an error, which is what we want */
8520 change_folder_and_display_error (data->impl, data->parent_file, FALSE);
8524 g_object_unref (data->impl);
8525 g_object_unref (data->file);
8526 g_object_unref (data->parent_file);
8529 g_object_unref (cancellable);
8533 file_exists_get_info_cb (GCancellable *cancellable,
8535 const GError *error,
8538 gboolean data_ownership_taken = FALSE;
8539 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
8540 gboolean file_exists_and_is_not_folder;
8541 struct FileExistsData *data = user_data;
8543 if (cancellable != data->impl->file_exists_get_info_cancellable)
8546 data->impl->file_exists_get_info_cancellable = NULL;
8548 set_busy_cursor (data->impl, FALSE);
8553 file_exists_and_is_not_folder = info && (! _gtk_file_info_consider_as_directory (info));
8555 if (data->impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
8556 /* user typed a filename; we are done */
8557 g_signal_emit_by_name (data->impl, "response-requested");
8558 else if (data->impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER
8559 && file_exists_and_is_not_folder)
8561 /* Oops, the user typed the name of an existing path which is not
8564 error_creating_folder_over_existing_file_dialog (data->impl, data->file,
8565 g_error_copy (error));
8569 /* check that everything up to the last component exists */
8571 data->file_exists_and_is_not_folder = file_exists_and_is_not_folder;
8572 data_ownership_taken = TRUE;
8574 if (data->impl->should_respond_get_info_cancellable)
8575 g_cancellable_cancel (data->impl->should_respond_get_info_cancellable);
8577 data->impl->should_respond_get_info_cancellable =
8578 _gtk_file_system_get_info (data->impl->file_system,
8581 save_entry_get_info_cb,
8583 set_busy_cursor (data->impl, TRUE);
8587 if (!data_ownership_taken)
8589 g_object_unref (data->impl);
8590 g_object_unref (data->file);
8591 g_object_unref (data->parent_file);
8595 g_object_unref (cancellable);
8599 paste_text_received (GtkClipboard *clipboard,
8601 GtkFileChooserDefault *impl)
8608 file = g_file_new_for_uri (text);
8610 if (!gtk_file_chooser_default_select_file (GTK_FILE_CHOOSER (impl), file, NULL))
8611 location_popup_handler (impl, text);
8613 g_object_unref (file);
8616 /* Handler for the "location-popup-on-paste" keybinding signal */
8618 location_popup_on_paste_handler (GtkFileChooserDefault *impl)
8620 GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (impl),
8621 GDK_SELECTION_CLIPBOARD);
8622 gtk_clipboard_request_text (clipboard,
8623 (GtkClipboardTextReceivedFunc) paste_text_received,
8628 /* Implementation for GtkFileChooserEmbed::should_respond() */
8630 gtk_file_chooser_default_should_respond (GtkFileChooserEmbed *chooser_embed)
8632 GtkFileChooserDefault *impl;
8633 GtkWidget *toplevel;
8634 GtkWidget *current_focus;
8636 impl = GTK_FILE_CHOOSER_DEFAULT (chooser_embed);
8638 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (impl));
8639 g_assert (GTK_IS_WINDOW (toplevel));
8641 current_focus = gtk_window_get_focus (GTK_WINDOW (toplevel));
8643 if (current_focus == impl->browse_files_tree_view)
8645 /* The following array encodes what we do based on the impl->action and the
8646 * number of files selected.
8649 NOOP, /* Do nothing (don't respond) */
8650 RESPOND, /* Respond immediately */
8651 RESPOND_OR_SWITCH, /* Respond immediately if the selected item is a file; switch to it if it is a folder */
8652 ALL_FILES, /* Respond only if everything selected is a file */
8653 ALL_FOLDERS, /* Respond only if everything selected is a folder */
8654 SAVE_ENTRY, /* Go to the code for handling the save entry */
8655 NOT_REACHED /* Sanity check */
8657 static const ActionToTake what_to_do[4][3] = {
8658 /* 0 selected 1 selected many selected */
8659 /* ACTION_OPEN */ { NOOP, RESPOND_OR_SWITCH, ALL_FILES },
8660 /* ACTION_SAVE */ { SAVE_ENTRY, RESPOND_OR_SWITCH, NOT_REACHED },
8661 /* ACTION_SELECT_FOLDER */ { RESPOND, ALL_FOLDERS, ALL_FOLDERS },
8662 /* ACTION_CREATE_FOLDER */ { SAVE_ENTRY, ALL_FOLDERS, NOT_REACHED }
8666 gboolean all_files, all_folders;
8668 ActionToTake action;
8672 g_assert (impl->action >= GTK_FILE_CHOOSER_ACTION_OPEN && impl->action <= GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER);
8674 if (impl->operation_mode == OPERATION_MODE_SEARCH)
8675 return search_should_respond (impl);
8677 if (impl->operation_mode == OPERATION_MODE_RECENT)
8678 return recent_should_respond (impl);
8680 selection_check (impl, &num_selected, &all_files, &all_folders);
8682 if (num_selected > 2)
8687 action = what_to_do [impl->action] [k];
8697 case RESPOND_OR_SWITCH:
8698 g_assert (num_selected == 1);
8702 switch_to_selected_folder (impl);
8705 else if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
8706 return should_respond_after_confirm_overwrite (impl,
8707 get_display_name_from_file_list (impl),
8708 impl->current_folder);
8722 g_assert_not_reached ();
8725 else if ((impl->location_entry != NULL) && (current_focus == impl->location_entry))
8728 gboolean is_well_formed, is_empty, is_file_part_empty;
8731 GtkFileChooserEntry *entry;
8736 g_assert (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
8737 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER
8738 || ((impl->action == GTK_FILE_CHOOSER_ACTION_OPEN
8739 || impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
8740 && impl->location_mode == LOCATION_MODE_FILENAME_ENTRY));
8742 entry = GTK_FILE_CHOOSER_ENTRY (impl->location_entry);
8743 check_save_entry (impl, &file, &is_well_formed, &is_empty, &is_file_part_empty, &is_folder);
8745 if (is_empty || !is_well_formed)
8748 g_assert (file != NULL);
8753 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
8754 impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
8756 change_folder_and_display_error (impl, file, TRUE);
8759 else if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
8760 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
8762 /* The folder already exists, so we do not need to create it.
8763 * Just respond to terminate the dialog.
8769 g_assert_not_reached ();
8775 struct FileExistsData *data;
8777 /* We need to check whether file exists and is not a folder */
8779 data = g_new0 (struct FileExistsData, 1);
8780 data->impl = g_object_ref (impl);
8781 data->file = g_object_ref (file);
8782 data->parent_file = g_object_ref (_gtk_file_chooser_entry_get_current_folder (entry));
8784 if (impl->file_exists_get_info_cancellable)
8785 g_cancellable_cancel (impl->file_exists_get_info_cancellable);
8787 impl->file_exists_get_info_cancellable =
8788 _gtk_file_system_get_info (impl->file_system, file,
8790 file_exists_get_info_cb,
8793 set_busy_cursor (impl, TRUE);
8797 g_error_free (error);
8800 g_object_unref (file);
8803 else if (impl->toplevel_last_focus_widget == impl->browse_files_tree_view)
8805 /* The focus is on a dialog's action area button, *and* the widget that
8806 * was focused immediately before it is the file list.
8810 else if (impl->operation_mode == OPERATION_MODE_SEARCH && impl->toplevel_last_focus_widget == impl->search_entry)
8812 search_entry_activate_cb (GTK_ENTRY (impl->search_entry), impl);
8815 else if (impl->location_entry && impl->toplevel_last_focus_widget == impl->location_entry)
8817 /* The focus is on a dialog's action area button, *and* the widget that
8818 * was focused immediately before it is the location entry.
8823 /* The focus is on a dialog's action area button or something else */
8824 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
8825 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
8830 g_assert_not_reached ();
8834 /* Implementation for GtkFileChooserEmbed::initial_focus() */
8836 gtk_file_chooser_default_initial_focus (GtkFileChooserEmbed *chooser_embed)
8838 GtkFileChooserDefault *impl;
8841 impl = GTK_FILE_CHOOSER_DEFAULT (chooser_embed);
8843 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
8844 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
8846 if (impl->location_mode == LOCATION_MODE_PATH_BAR)
8847 widget = impl->browse_files_tree_view;
8849 widget = impl->location_entry;
8851 else if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
8852 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
8853 widget = impl->location_entry;
8856 g_assert_not_reached ();
8860 g_assert (widget != NULL);
8861 gtk_widget_grab_focus (widget);
8864 /* Callback used from gtk_tree_selection_selected_foreach(); gets the selected GFiles */
8866 search_selected_foreach_get_file_cb (GtkTreeModel *model,
8876 gtk_tree_model_get (model, iter, MODEL_COL_FILE, &file, -1);
8877 *list = g_slist_prepend (*list, g_object_ref (file));
8880 /* Constructs a list of the selected paths in search mode */
8882 search_get_selected_files (GtkFileChooserDefault *impl)
8885 GtkTreeSelection *selection;
8889 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
8890 gtk_tree_selection_selected_foreach (selection, search_selected_foreach_get_file_cb, &result);
8891 result = g_slist_reverse (result);
8896 /* Called from ::should_respond(). We return whether there are selected files
8897 * in the search list.
8900 search_should_respond (GtkFileChooserDefault *impl)
8902 GtkTreeSelection *selection;
8904 g_assert (impl->operation_mode == OPERATION_MODE_SEARCH);
8906 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
8907 return (gtk_tree_selection_count_selected_rows (selection) != 0);
8910 /* Adds one hit from the search engine to the search_model */
8912 search_add_hit (GtkFileChooserDefault *impl,
8917 file = g_file_new_for_uri (uri);
8921 if (!g_file_is_native (file))
8923 g_object_unref (file);
8927 _gtk_file_system_model_add_and_query_file (impl->search_model,
8931 g_object_unref (file);
8934 /* Callback used from GtkSearchEngine when we get new hits */
8936 search_engine_hits_added_cb (GtkSearchEngine *engine,
8940 GtkFileChooserDefault *impl;
8943 impl = GTK_FILE_CHOOSER_DEFAULT (data);
8945 for (l = hits; l; l = l->next)
8946 search_add_hit (impl, (gchar*)l->data);
8949 /* Callback used from GtkSearchEngine when the query is done running */
8951 search_engine_finished_cb (GtkSearchEngine *engine,
8954 GtkFileChooserDefault *impl;
8956 impl = GTK_FILE_CHOOSER_DEFAULT (data);
8959 /* EB: setting the model here will avoid loads of row events,
8960 * but it'll make the search look like blocked.
8962 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view),
8963 GTK_TREE_MODEL (impl->search_model));
8966 /* FMQ: if search was empty, say that we got no hits */
8967 set_busy_cursor (impl, FALSE);
8970 /* Displays a generic error when we cannot create a GtkSearchEngine.
8971 * It would be better if _gtk_search_engine_new() gave us a GError
8972 * with a better message, but it doesn't do that right now.
8975 search_error_could_not_create_client (GtkFileChooserDefault *impl)
8977 error_message (impl,
8978 _("Could not start the search process"),
8979 _("The program was not able to create a connection to the indexer "
8980 "daemon. Please make sure it is running."));
8984 search_engine_error_cb (GtkSearchEngine *engine,
8985 const gchar *message,
8988 GtkFileChooserDefault *impl;
8990 impl = GTK_FILE_CHOOSER_DEFAULT (data);
8992 search_stop_searching (impl, TRUE);
8993 error_message (impl, _("Could not send the search request"), message);
8995 set_busy_cursor (impl, FALSE);
8998 /* Frees the data in the search_model */
9000 search_clear_model (GtkFileChooserDefault *impl,
9001 gboolean remove_from_treeview)
9003 if (!impl->search_model)
9006 g_object_unref (impl->search_model);
9007 impl->search_model = NULL;
9009 if (remove_from_treeview)
9010 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), NULL);
9013 /* Stops any ongoing searches; does not touch the search_model */
9015 search_stop_searching (GtkFileChooserDefault *impl,
9016 gboolean remove_query)
9018 if (remove_query && impl->search_query)
9020 g_object_unref (impl->search_query);
9021 impl->search_query = NULL;
9024 if (impl->search_engine)
9026 _gtk_search_engine_stop (impl->search_engine);
9028 g_object_unref (impl->search_engine);
9029 impl->search_engine = NULL;
9033 /* Stops any pending searches, clears the file list, and switches back to OPERATION_MODE_BROWSE */
9035 search_switch_to_browse_mode (GtkFileChooserDefault *impl)
9037 g_assert (impl->operation_mode != OPERATION_MODE_BROWSE);
9039 search_stop_searching (impl, FALSE);
9040 search_clear_model (impl, TRUE);
9042 gtk_widget_destroy (impl->search_hbox);
9043 impl->search_hbox = NULL;
9044 impl->search_entry = NULL;
9046 gtk_widget_show (impl->browse_path_bar);
9047 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN || !impl->create_folders)
9048 gtk_widget_hide (impl->browse_new_folder_button);
9050 gtk_widget_show (impl->browse_new_folder_button);
9053 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
9054 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
9056 gtk_widget_show (impl->location_button);
9058 if (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)
9059 gtk_widget_show (impl->location_entry_box);
9062 impl->operation_mode = OPERATION_MODE_BROWSE;
9064 file_list_set_sort_column_ids (impl);
9067 /* Creates the search_model and puts it in the tree view */
9069 search_setup_model (GtkFileChooserDefault *impl)
9071 g_assert (impl->search_model == NULL);
9073 impl->search_model = _gtk_file_system_model_new (file_system_model_set,
9075 MODEL_COL_NUM_COLUMNS,
9076 G_TYPE_STRING, /* MODEL_COL_NAME */
9077 G_TYPE_INT64, /* MODEL_COL_SIZE */
9078 G_TYPE_LONG, /* MODEL_COL_MTIME */
9079 G_TYPE_FILE, /* MODEL_COL_FILE */
9080 G_TYPE_STRING, /* MODEL_COL_NAME_COLLATED */
9081 G_TYPE_BOOLEAN, /* MODEL_COL_IS_FOLDER */
9082 GDK_TYPE_PIXBUF, /* MODEL_COL_PIXBUF */
9083 G_TYPE_STRING, /* MODEL_COL_SIZE_TEXT */
9084 G_TYPE_STRING, /* MODEL_COL_MTIME_TEXT */
9085 PANGO_TYPE_ELLIPSIZE_MODE /* MODEL_COL_ELLIPSIZE */
9088 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->search_model),
9092 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->search_model),
9096 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->search_model),
9100 set_sort_column (impl);
9102 /* EB: setting the model here will make the hits list update feel
9103 * more "alive" than setting the model at the end of the search
9106 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view),
9107 GTK_TREE_MODEL (impl->search_model));
9110 /* Creates a new query with the specified text and launches it */
9112 search_start_query (GtkFileChooserDefault *impl,
9113 const gchar *query_text)
9115 search_stop_searching (impl, FALSE);
9116 search_clear_model (impl, TRUE);
9117 search_setup_model (impl);
9118 set_busy_cursor (impl, TRUE);
9120 if (impl->search_engine == NULL)
9121 impl->search_engine = _gtk_search_engine_new ();
9123 if (!impl->search_engine)
9125 set_busy_cursor (impl, FALSE);
9126 search_error_could_not_create_client (impl); /* lame; we don't get an error code or anything */
9130 if (!impl->search_query)
9132 impl->search_query = _gtk_query_new ();
9133 _gtk_query_set_text (impl->search_query, query_text);
9136 _gtk_search_engine_set_query (impl->search_engine, impl->search_query);
9138 g_signal_connect (impl->search_engine, "hits-added",
9139 G_CALLBACK (search_engine_hits_added_cb), impl);
9140 g_signal_connect (impl->search_engine, "finished",
9141 G_CALLBACK (search_engine_finished_cb), impl);
9142 g_signal_connect (impl->search_engine, "error",
9143 G_CALLBACK (search_engine_error_cb), impl);
9145 _gtk_search_engine_start (impl->search_engine);
9148 /* Callback used when the user presses Enter while typing on the search
9149 * entry; starts the query
9152 search_entry_activate_cb (GtkEntry *entry,
9155 GtkFileChooserDefault *impl;
9158 impl = GTK_FILE_CHOOSER_DEFAULT (data);
9160 text = gtk_entry_get_text (GTK_ENTRY (impl->search_entry));
9161 if (strlen (text) == 0)
9164 /* reset any existing query object */
9165 if (impl->search_query)
9167 g_object_unref (impl->search_query);
9168 impl->search_query = NULL;
9171 search_start_query (impl, text);
9174 /* Hides the path bar and creates the search entry */
9176 search_setup_widgets (GtkFileChooserDefault *impl)
9182 impl->search_hbox = gtk_hbox_new (FALSE, 12);
9186 image = gtk_image_new_from_stock (GTK_STOCK_FIND, GTK_ICON_SIZE_BUTTON);
9187 gtk_size_group_add_widget (GTK_SIZE_GROUP (impl->browse_path_bar_size_group), image);
9188 gtk_box_pack_start (GTK_BOX (impl->search_hbox), image, FALSE, FALSE, 5);
9192 label = gtk_label_new (NULL);
9193 tmp = g_strdup_printf ("<b>%s</b>", _("Search:"));
9194 gtk_label_set_markup_with_mnemonic (GTK_LABEL (label), tmp);
9195 gtk_box_pack_start (GTK_BOX (impl->search_hbox), label, FALSE, FALSE, 0);
9200 impl->search_entry = gtk_entry_new ();
9201 gtk_label_set_mnemonic_widget (GTK_LABEL (label), impl->search_entry);
9202 g_signal_connect (impl->search_entry, "activate",
9203 G_CALLBACK (search_entry_activate_cb),
9205 gtk_box_pack_start (GTK_BOX (impl->search_hbox), impl->search_entry, TRUE, TRUE, 0);
9207 /* if there already is a query, restart it */
9208 if (impl->search_query)
9210 gchar *query = _gtk_query_get_text (impl->search_query);
9214 gtk_entry_set_text (GTK_ENTRY (impl->search_entry), query);
9215 search_start_query (impl, query);
9221 g_object_unref (impl->search_query);
9222 impl->search_query = NULL;
9226 gtk_widget_hide (impl->browse_path_bar);
9227 gtk_widget_hide (impl->browse_new_folder_button);
9229 /* Box for search widgets */
9230 gtk_box_pack_start (GTK_BOX (impl->browse_path_bar_hbox), impl->search_hbox, TRUE, TRUE, 0);
9231 gtk_widget_show_all (impl->search_hbox);
9233 /* Hide the location widgets temporarily */
9235 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
9236 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
9238 gtk_widget_hide (impl->location_button);
9239 gtk_widget_hide (impl->location_entry_box);
9242 gtk_widget_grab_focus (impl->search_entry);
9244 /* FMQ: hide the filter combo? */
9247 /* Stops running operations like populating the browse model, searches, and the recent-files model */
9249 stop_operation (GtkFileChooserDefault *impl, OperationMode mode)
9253 case OPERATION_MODE_BROWSE:
9254 stop_loading_and_clear_list_model (impl);
9257 case OPERATION_MODE_SEARCH:
9258 search_stop_searching (impl, FALSE);
9259 search_clear_model (impl, TRUE);
9261 gtk_widget_destroy (impl->search_hbox);
9262 impl->search_hbox = NULL;
9263 impl->search_entry = NULL;
9266 case OPERATION_MODE_RECENT:
9267 recent_stop_loading (impl);
9268 recent_clear_model (impl, TRUE);
9270 gtk_widget_destroy (impl->recent_hbox);
9271 impl->recent_hbox = NULL;
9276 /* Main entry point to the searching functions; this gets called when the user
9277 * activates the Search shortcut.
9280 search_activate (GtkFileChooserDefault *impl)
9282 OperationMode previous_mode;
9284 if (impl->operation_mode == OPERATION_MODE_SEARCH)
9286 gtk_widget_grab_focus (impl->search_entry);
9290 previous_mode = impl->operation_mode;
9291 impl->operation_mode = OPERATION_MODE_SEARCH;
9293 stop_operation (impl, previous_mode);
9295 g_assert (impl->search_hbox == NULL);
9296 g_assert (impl->search_entry == NULL);
9297 g_assert (impl->search_model == NULL);
9299 search_setup_widgets (impl);
9300 file_list_set_sort_column_ids (impl);
9304 * Recent files support
9307 /* Frees the data in the recent_model */
9309 recent_clear_model (GtkFileChooserDefault *impl,
9310 gboolean remove_from_treeview)
9312 GtkTreeModel *model;
9315 if (!impl->recent_model)
9318 model = GTK_TREE_MODEL (impl->recent_model);
9320 if (remove_from_treeview)
9321 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), NULL);
9323 if (gtk_tree_model_get_iter_first (model, &iter))
9328 GCancellable *cancellable;
9329 GtkRecentInfo *recent_info;
9330 gchar *display_name;
9332 gtk_tree_model_get (model, &iter,
9333 MODEL_COL_NAME, &display_name,
9334 MODEL_COL_FILE, &file,
9335 RECENT_MODEL_COL_CANCELLABLE, &cancellable,
9336 RECENT_MODEL_COL_INFO, &recent_info,
9340 g_cancellable_cancel (cancellable);
9342 g_object_unref (file);
9343 gtk_recent_info_unref (recent_info);
9344 g_free (display_name);
9346 while (gtk_tree_model_iter_next (model, &iter));
9349 g_object_unref (impl->recent_model);
9350 impl->recent_model = NULL;
9352 g_object_unref (impl->recent_model_filter);
9353 impl->recent_model_filter = NULL;
9355 g_object_unref (impl->recent_model_sort);
9356 impl->recent_model_sort = NULL;
9359 /* Stops any ongoing loading of the recent files list; does
9360 * not touch the recent_model
9363 recent_stop_loading (GtkFileChooserDefault *impl)
9365 if (impl->load_recent_id)
9367 g_source_remove (impl->load_recent_id);
9368 impl->load_recent_id = 0;
9372 /* Stops any pending load, clears the file list, and switches
9373 * back to OPERATION_MODE_BROWSE
9376 recent_switch_to_browse_mode (GtkFileChooserDefault *impl)
9378 g_assert (impl->operation_mode != OPERATION_MODE_BROWSE);
9380 recent_stop_loading (impl);
9381 recent_clear_model (impl, TRUE);
9383 gtk_widget_destroy (impl->recent_hbox);
9384 impl->recent_hbox = NULL;
9386 gtk_widget_show (impl->browse_path_bar);
9387 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN || !impl->create_folders)
9388 gtk_widget_hide (impl->browse_new_folder_button);
9390 gtk_widget_show (impl->browse_new_folder_button);
9392 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
9393 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
9395 gtk_widget_show (impl->location_button);
9397 if (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)
9398 gtk_widget_show (impl->location_entry_box);
9401 gtk_tree_view_column_set_visible (impl->list_size_column, impl->show_size_column);
9403 impl->operation_mode = OPERATION_MODE_BROWSE;
9405 file_list_set_sort_column_ids (impl);
9409 recent_get_is_filtered (GtkFileChooserDefault *impl,
9411 GtkRecentInfo *recent_info)
9413 GtkFileFilterInfo filter_info;
9414 GtkFileFilterFlags needed;
9417 if (!impl->current_filter)
9420 filter_info.contains = GTK_FILE_FILTER_DISPLAY_NAME | GTK_FILE_FILTER_MIME_TYPE;
9421 needed = gtk_file_filter_get_needed (impl->current_filter);
9423 filter_info.display_name = gtk_recent_info_get_display_name (recent_info);
9424 filter_info.mime_type = gtk_recent_info_get_mime_type (recent_info);
9426 if (needed & GTK_FILE_FILTER_FILENAME)
9428 filter_info.filename = g_file_get_path (file);
9429 if (filter_info.filename)
9430 filter_info.contains |= GTK_FILE_FILTER_FILENAME;
9433 filter_info.filename = NULL;
9435 if (needed & GTK_FILE_FILTER_URI)
9437 filter_info.uri = g_file_get_uri (file);
9438 if (filter_info.uri)
9439 filter_info.contains |= GTK_FILE_FILTER_URI;
9442 filter_info.uri = NULL;
9444 result = gtk_file_filter_filter (impl->current_filter, &filter_info);
9446 if (filter_info.filename)
9447 g_free ((gchar *) filter_info.filename);
9448 if (filter_info.uri)
9449 g_free ((gchar *) filter_info.uri);
9454 /* Visibility function for the recent filter model */
9456 recent_model_visible_func (GtkTreeModel *model,
9460 GtkFileChooserDefault *impl = user_data;
9462 GtkRecentInfo *recent_info;
9465 if (!impl->current_filter)
9468 gtk_tree_model_get (model, iter,
9469 RECENT_MODEL_COL_INFO, &recent_info,
9470 MODEL_COL_FILE, &file,
9471 MODEL_COL_IS_FOLDER, &is_folder,
9480 return !recent_get_is_filtered (impl, file, recent_info);
9484 recent_setup_model (GtkFileChooserDefault *impl)
9486 g_assert (impl->recent_model == NULL);
9487 g_assert (impl->recent_model_filter == NULL);
9488 g_assert (impl->recent_model_sort == NULL);
9490 impl->recent_model = gtk_list_store_new (RECENT_MODEL_COL_NUM_COLUMNS,
9491 G_TYPE_STRING, /* MODEL_COL_NAME */
9492 G_TYPE_INT64, /* MODEL_COL_SIZE */
9493 G_TYPE_LONG, /* MODEL_COL_MTIME */
9494 G_TYPE_FILE, /* MODEL_COL_FILE */
9495 G_TYPE_STRING, /* MODEL_COL_NAME_COLLATED */
9496 G_TYPE_BOOLEAN, /* MODEL_COL_IS_FOLDER */
9497 GDK_TYPE_PIXBUF, /* MODEL_COL_PIXBUF */
9498 G_TYPE_STRING, /* MODEL_COL_SIZE_TEXT */
9499 G_TYPE_STRING, /* MODEL_COL_MTIME_TEXT */
9500 PANGO_TYPE_ELLIPSIZE_MODE, /* MODEL_COL_ELLIPSIZE */
9501 G_TYPE_CANCELLABLE, /* RECENT_MODEL_COL_CANCELLABLE */
9502 G_TYPE_POINTER /* RECENT_MODEL_COL_INFO */
9505 impl->recent_model_filter =
9506 GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (GTK_TREE_MODEL (impl->recent_model), NULL));
9507 gtk_tree_model_filter_set_visible_func (impl->recent_model_filter,
9508 recent_model_visible_func,
9512 /* this is the model that will actually be added to
9513 * the browse_files_tree_view widget; remember: we are
9514 * stuffing the real model into a filter model and then
9515 * into a sort model; this means we'll have to translate
9516 * the child iterator *twice* to get from a path or an
9517 * iterator coming from the tree view widget to the
9518 * real data inside the model.
9520 impl->recent_model_sort =
9521 GTK_TREE_MODEL_SORT (recent_model_sort_new (impl, GTK_TREE_MODEL (impl->recent_model_filter)));
9522 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->recent_model_sort),
9526 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->recent_model_sort),
9530 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->recent_model_sort),
9534 set_sort_column (impl);
9539 GtkFileChooserDefault *impl;
9542 gint n_loaded_items;
9543 guint needs_sorting : 1;
9547 recent_idle_cleanup (gpointer data)
9549 RecentLoadData *load_data = data;
9550 GtkFileChooserDefault *impl = load_data->impl;
9552 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view),
9553 GTK_TREE_MODEL (impl->recent_model_sort));
9555 set_busy_cursor (impl, FALSE);
9557 impl->load_recent_id = 0;
9559 if (load_data->items)
9561 g_list_foreach (load_data->items, (GFunc) gtk_recent_info_unref, NULL);
9562 g_list_free (load_data->items);
9568 struct RecentItemInsertRequest
9570 GtkFileChooserDefault *impl;
9572 GtkTreeRowReference *row_ref;
9576 recent_item_get_info_cb (GCancellable *cancellable,
9578 const GError *error,
9581 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
9584 GCancellable *model_cancellable;
9585 gboolean is_folder = FALSE;
9586 struct RecentItemInsertRequest *request = data;
9590 if (!request->impl->recent_model)
9593 path = gtk_tree_row_reference_get_path (request->row_ref);
9597 gtk_tree_model_get_iter (GTK_TREE_MODEL (request->impl->recent_model),
9599 gtk_tree_path_free (path);
9601 gtk_tree_model_get (GTK_TREE_MODEL (request->impl->recent_model), &iter,
9602 RECENT_MODEL_COL_CANCELLABLE, &model_cancellable,
9604 g_object_unref (model_cancellable);
9605 if (cancellable != model_cancellable)
9608 gtk_list_store_set (request->impl->recent_model, &iter,
9609 RECENT_MODEL_COL_CANCELLABLE, NULL,
9617 gtk_list_store_remove (request->impl->recent_model, &iter);
9621 is_folder = _gtk_file_info_consider_as_directory (info);
9622 size = g_file_info_get_size (info);
9623 size_text = is_folder ? g_format_size_for_display (size) : g_strdup ("");
9625 gtk_list_store_set (request->impl->recent_model, &iter,
9626 MODEL_COL_IS_FOLDER, is_folder,
9627 MODEL_COL_SIZE, size,
9628 MODEL_COL_SIZE_TEXT, size_text,
9634 g_object_unref (request->impl);
9635 g_object_unref (request->file);
9636 gtk_tree_row_reference_free (request->row_ref);
9639 g_object_unref (cancellable);
9643 recent_sort_mru (gconstpointer a,
9646 GtkRecentInfo *info_a = (GtkRecentInfo *) a;
9647 GtkRecentInfo *info_b = (GtkRecentInfo *) b;
9649 return (gtk_recent_info_get_modified (info_b) - gtk_recent_info_get_modified (info_a));
9653 get_recent_files_limit (GtkWidget *widget)
9655 GtkSettings *settings;
9658 if (gtk_widget_has_screen (widget))
9659 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9661 settings = gtk_settings_get_default ();
9663 g_object_get (G_OBJECT (settings), "gtk-recent-files-limit", &limit, NULL);
9669 recent_idle_load (gpointer data)
9671 RecentLoadData *load_data = data;
9672 GtkFileChooserDefault *impl = load_data->impl;
9675 GtkRecentInfo *info;
9676 const gchar *uri, *display_name, *mtime_text, *collated_name;
9679 GCancellable *cancellable;
9680 struct RecentItemInsertRequest *request;
9682 if (!impl->recent_manager)
9685 /* first iteration: load all the items */
9686 if (!load_data->items)
9688 load_data->items = gtk_recent_manager_get_items (impl->recent_manager);
9689 if (!load_data->items)
9692 load_data->needs_sorting = TRUE;
9697 /* second iteration: preliminary MRU sorting and clamping */
9698 if (load_data->needs_sorting)
9702 load_data->items = g_list_sort (load_data->items, recent_sort_mru);
9703 load_data->n_items = g_list_length (load_data->items);
9705 limit = get_recent_files_limit (GTK_WIDGET (impl));
9707 if (limit != -1 && (load_data->n_items > limit))
9711 clamp = g_list_nth (load_data->items, limit - 1);
9712 if (G_LIKELY (clamp))
9717 g_list_foreach (l, (GFunc) gtk_recent_info_unref, NULL);
9720 load_data->n_items = limit;
9724 load_data->n_loaded_items = 0;
9725 load_data->needs_sorting = FALSE;
9730 info = g_list_nth_data (load_data->items, load_data->n_loaded_items);
9731 g_assert (info != NULL);
9733 uri = gtk_recent_info_get_uri (info);
9734 display_name = gtk_recent_info_get_display_name (info);
9735 file = g_file_new_for_uri (uri);
9737 gtk_list_store_append (impl->recent_model, &iter);
9738 p = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->recent_model), &iter);
9740 request = g_new0 (struct RecentItemInsertRequest, 1);
9741 request->impl = g_object_ref (impl);
9742 request->file = g_object_ref (file);
9743 request->row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (impl->recent_model), p);
9744 gtk_tree_path_free (p);
9746 cancellable = _gtk_file_system_get_info (impl->file_system, file,
9747 "standard::type,standard::size",
9748 recent_item_get_info_cb,
9751 collated_name = g_utf8_collate_key_for_filename (gtk_recent_info_get_display_name (info), -1);
9752 mtime = gtk_recent_info_get_modified (info);
9753 mtime_text = mtime ? my_g_format_time_for_display (mtime) : g_strdup (_("Unknown"));
9755 gtk_list_store_set (impl->recent_model, &iter,
9756 MODEL_COL_FILE, file,
9757 MODEL_COL_NAME, gtk_recent_info_get_display_name (info),
9758 MODEL_COL_NAME_COLLATED, collated_name,
9759 MODEL_COL_PIXBUF, gtk_recent_info_get_icon (info, impl->icon_size),
9760 MODEL_COL_MTIME, mtime,
9761 MODEL_COL_MTIME_TEXT, mtime_text,
9762 MODEL_COL_ELLIPSIZE, PANGO_ELLIPSIZE_END,
9763 RECENT_MODEL_COL_CANCELLABLE, cancellable,
9764 RECENT_MODEL_COL_INFO, gtk_recent_info_ref (info),
9767 load_data->n_loaded_items += 1;
9769 /* finished loading items */
9770 if (load_data->n_loaded_items == load_data->n_items)
9772 g_list_foreach (load_data->items, (GFunc) gtk_recent_info_unref, NULL);
9773 g_list_free (load_data->items);
9774 load_data->items = NULL;
9783 recent_start_loading (GtkFileChooserDefault *impl)
9785 RecentLoadData *load_data;
9787 recent_stop_loading (impl);
9788 recent_clear_model (impl, TRUE);
9789 recent_setup_model (impl);
9790 set_busy_cursor (impl, TRUE);
9792 g_assert (impl->load_recent_id == 0);
9794 load_data = g_new (RecentLoadData, 1);
9795 load_data->impl = impl;
9796 load_data->items = NULL;
9797 load_data->n_items = 0;
9798 load_data->n_loaded_items = 0;
9799 load_data->needs_sorting = TRUE;
9801 /* begin lazy loading the recent files into the model */
9802 impl->load_recent_id = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 30,
9805 recent_idle_cleanup);
9809 recent_selected_foreach_get_file_cb (GtkTreeModel *model,
9819 gtk_tree_model_get (model, iter, MODEL_COL_FILE, &file, -1);
9820 *list = g_slist_prepend (*list, file);
9823 /* Constructs a list of the selected paths in recent files mode */
9825 recent_get_selected_files (GtkFileChooserDefault *impl)
9828 GtkTreeSelection *selection;
9832 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
9833 gtk_tree_selection_selected_foreach (selection, recent_selected_foreach_get_file_cb, &result);
9834 result = g_slist_reverse (result);
9839 /* Called from ::should_respond(). We return whether there are selected
9840 * files in the recent files list.
9843 recent_should_respond (GtkFileChooserDefault *impl)
9845 GtkTreeSelection *selection;
9847 g_assert (impl->operation_mode == OPERATION_MODE_RECENT);
9849 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
9850 return (gtk_tree_selection_count_selected_rows (selection) != 0);
9853 /* Hide the location widgets temporarily */
9855 recent_hide_entry (GtkFileChooserDefault *impl)
9861 impl->recent_hbox = gtk_hbox_new (FALSE, 12);
9864 image = gtk_image_new_from_icon_name ("document-open-recent", GTK_ICON_SIZE_BUTTON);
9865 gtk_size_group_add_widget (impl->browse_path_bar_size_group, image);
9866 gtk_box_pack_start (GTK_BOX (impl->recent_hbox), image, FALSE, FALSE, 5);
9869 label = gtk_label_new (NULL);
9870 tmp = g_strdup_printf ("<b>%s</b>", _("Recently Used"));
9871 gtk_label_set_markup_with_mnemonic (GTK_LABEL (label), tmp);
9872 gtk_box_pack_start (GTK_BOX (impl->recent_hbox), label, FALSE, FALSE, 0);
9875 gtk_widget_hide (impl->browse_path_bar);
9876 gtk_widget_hide (impl->browse_new_folder_button);
9878 /* Box for recent widgets */
9879 gtk_box_pack_start (GTK_BOX (impl->browse_path_bar_hbox), impl->recent_hbox, TRUE, TRUE, 0);
9880 gtk_widget_show_all (impl->recent_hbox);
9882 /* Hide the location widgets temporarily */
9883 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
9884 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
9886 gtk_widget_hide (impl->location_button);
9887 gtk_widget_hide (impl->location_entry_box);
9891 /* Main entry point to the recent files functions; this gets called when
9892 * the user activates the Recently Used shortcut.
9895 recent_activate (GtkFileChooserDefault *impl)
9897 OperationMode previous_mode;
9899 if (impl->operation_mode == OPERATION_MODE_RECENT)
9902 previous_mode = impl->operation_mode;
9903 impl->operation_mode = OPERATION_MODE_RECENT;
9905 stop_operation (impl, previous_mode);
9907 recent_hide_entry (impl);
9909 /* hide the file size column if it's visible */
9910 gtk_tree_view_column_set_visible (impl->list_size_column, FALSE);
9912 file_list_set_sort_column_ids (impl);
9913 recent_start_loading (impl);
9916 /* convert an iterator coming from the model bound to
9917 * browse_files_tree_view to an interator inside the
9921 recent_get_valid_child_iter (GtkFileChooserDefault *impl,
9922 GtkTreeIter *child_iter,
9927 if (!impl->recent_model)
9930 if (!impl->recent_model_filter || !impl->recent_model_sort)
9933 /* pass 1: get the iterator in the filter model */
9934 gtk_tree_model_sort_convert_iter_to_child_iter (impl->recent_model_sort,
9937 /* pass 2: get the iterator in the real model */
9938 gtk_tree_model_filter_convert_iter_to_child_iter (impl->recent_model_filter,
9945 set_current_filter (GtkFileChooserDefault *impl,
9946 GtkFileFilter *filter)
9948 if (impl->current_filter != filter)
9952 /* NULL filters are allowed to reset to non-filtered status
9954 filter_index = g_slist_index (impl->filters, filter);
9955 if (impl->filters && filter && filter_index < 0)
9958 if (impl->current_filter)
9959 g_object_unref (impl->current_filter);
9960 impl->current_filter = filter;
9961 if (impl->current_filter)
9963 g_object_ref_sink (impl->current_filter);
9967 gtk_combo_box_set_active (GTK_COMBO_BOX (impl->filter_combo),
9970 if (impl->browse_files_model)
9971 install_list_model_filter (impl);
9973 if (impl->search_model)
9974 _gtk_file_system_model_set_filter (impl->search_model, filter);
9976 /* we want to have all the matching results, and not just a
9977 * filter of the previous model
9979 if (impl->operation_mode == OPERATION_MODE_RECENT)
9980 recent_start_loading (impl);
9982 g_object_notify (G_OBJECT (impl), "filter");
9987 filter_combo_changed (GtkComboBox *combo_box,
9988 GtkFileChooserDefault *impl)
9990 gint new_index = gtk_combo_box_get_active (combo_box);
9991 GtkFileFilter *new_filter = g_slist_nth_data (impl->filters, new_index);
9993 set_current_filter (impl, new_filter);
9997 check_preview_change (GtkFileChooserDefault *impl)
9999 GtkTreePath *cursor_path;
10001 char *new_display_name;
10002 GtkTreeModel *model;
10004 gtk_tree_view_get_cursor (GTK_TREE_VIEW (impl->browse_files_tree_view), &cursor_path, NULL);
10005 model = gtk_tree_view_get_model (GTK_TREE_VIEW (impl->browse_files_tree_view));
10010 gtk_tree_model_get_iter (model, &iter, cursor_path);
10011 gtk_tree_model_get (model, &iter,
10012 MODEL_COL_FILE, &new_file,
10013 MODEL_COL_NAME, &new_display_name,
10016 gtk_tree_path_free (cursor_path);
10021 new_display_name = NULL;
10024 if (new_file != impl->preview_file &&
10025 !(new_file && impl->preview_file &&
10026 g_file_equal (new_file, impl->preview_file)))
10028 if (impl->preview_file)
10030 g_object_unref (impl->preview_file);
10031 g_free (impl->preview_display_name);
10036 impl->preview_file = new_file;
10037 impl->preview_display_name = new_display_name;
10041 impl->preview_file = NULL;
10042 impl->preview_display_name = NULL;
10043 g_free (new_display_name);
10046 if (impl->use_preview_label && impl->preview_label)
10047 gtk_label_set_text (GTK_LABEL (impl->preview_label), impl->preview_display_name);
10049 g_signal_emit_by_name (impl, "update-preview");
10054 shortcuts_activate_volume_mount_cb (GCancellable *cancellable,
10055 GtkFileSystemVolume *volume,
10056 const GError *error,
10060 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
10061 GtkFileChooserDefault *impl = data;
10063 if (cancellable != impl->shortcuts_activate_iter_cancellable)
10066 impl->shortcuts_activate_iter_cancellable = NULL;
10068 set_busy_cursor (impl, FALSE);
10075 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED))
10079 name = _gtk_file_system_volume_get_display_name (volume);
10080 msg = g_strdup_printf (_("Could not mount %s"), name);
10082 error_message (impl, msg, error->message);
10091 file = _gtk_file_system_volume_get_root (volume);
10094 change_folder_and_display_error (impl, file, FALSE);
10095 g_object_unref (file);
10099 g_object_unref (impl);
10100 g_object_unref (cancellable);
10104 /* Activates a volume by mounting it if necessary and then switching to its
10108 shortcuts_activate_volume (GtkFileChooserDefault *impl,
10109 GtkFileSystemVolume *volume)
10113 switch (impl->operation_mode)
10115 case OPERATION_MODE_BROWSE:
10117 case OPERATION_MODE_SEARCH:
10118 search_switch_to_browse_mode (impl);
10120 case OPERATION_MODE_RECENT:
10121 recent_switch_to_browse_mode (impl);
10125 /* We ref the file chooser since volume_mount() may run a main loop, and the
10126 * user could close the file chooser window in the meantime.
10128 g_object_ref (impl);
10130 if (!_gtk_file_system_volume_is_mounted (volume))
10132 GMountOperation *mount_op;
10134 set_busy_cursor (impl, TRUE);
10136 mount_op = gtk_mount_operation_new (get_toplevel (GTK_WIDGET (impl)));
10137 impl->shortcuts_activate_iter_cancellable =
10138 _gtk_file_system_mount_volume (impl->file_system, volume, mount_op,
10139 shortcuts_activate_volume_mount_cb,
10140 g_object_ref (impl));
10141 g_object_unref (mount_op);
10145 file = _gtk_file_system_volume_get_root (volume);
10148 change_folder_and_display_error (impl, file, FALSE);
10149 g_object_unref (file);
10153 g_object_unref (impl);
10156 /* Opens the folder or volume at the specified iter in the shortcuts model */
10157 struct ShortcutsActivateData
10159 GtkFileChooserDefault *impl;
10164 shortcuts_activate_get_info_cb (GCancellable *cancellable,
10166 const GError *error,
10167 gpointer user_data)
10169 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
10170 struct ShortcutsActivateData *data = user_data;
10172 if (cancellable != data->impl->shortcuts_activate_iter_cancellable)
10175 data->impl->shortcuts_activate_iter_cancellable = NULL;
10180 if (!error && _gtk_file_info_consider_as_directory (info))
10181 change_folder_and_display_error (data->impl, data->file, FALSE);
10183 gtk_file_chooser_default_select_file (GTK_FILE_CHOOSER (data->impl),
10188 g_object_unref (data->impl);
10189 g_object_unref (data->file);
10192 g_object_unref (cancellable);
10196 shortcuts_activate_mount_enclosing_volume (GCancellable *cancellable,
10197 GtkFileSystemVolume *volume,
10198 const GError *error,
10199 gpointer user_data)
10201 struct ShortcutsActivateData *data = user_data;
10205 error_changing_folder_dialog (data->impl, data->file, g_error_copy (error));
10207 g_object_unref (data->impl);
10208 g_object_unref (data->file);
10214 data->impl->shortcuts_activate_iter_cancellable =
10215 _gtk_file_system_get_info (data->impl->file_system, data->file,
10217 shortcuts_activate_get_info_cb, data);
10221 shortcuts_activate_iter (GtkFileChooserDefault *impl,
10225 ShortcutType shortcut_type;
10227 if (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY
10228 && !(impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
10229 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER))
10230 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), "");
10232 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), iter,
10233 SHORTCUTS_COL_DATA, &col_data,
10234 SHORTCUTS_COL_TYPE, &shortcut_type,
10237 if (impl->shortcuts_activate_iter_cancellable)
10239 g_cancellable_cancel (impl->shortcuts_activate_iter_cancellable);
10240 impl->shortcuts_activate_iter_cancellable = NULL;
10243 if (shortcut_type == SHORTCUT_TYPE_SEPARATOR)
10245 else if (shortcut_type == SHORTCUT_TYPE_VOLUME)
10247 GtkFileSystemVolume *volume;
10251 shortcuts_activate_volume (impl, volume);
10253 else if (shortcut_type == SHORTCUT_TYPE_FILE)
10255 struct ShortcutsActivateData *data;
10256 GtkFileSystemVolume *volume;
10258 volume = _gtk_file_system_get_volume_for_file (impl->file_system, col_data);
10260 data = g_new0 (struct ShortcutsActivateData, 1);
10261 data->impl = g_object_ref (impl);
10262 data->file = g_object_ref (col_data);
10264 if (!volume || !_gtk_file_system_volume_is_mounted (volume))
10266 GMountOperation *mount_operation;
10267 GtkWidget *toplevel;
10269 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (impl));
10271 mount_operation = gtk_mount_operation_new (GTK_WINDOW (toplevel));
10273 impl->shortcuts_activate_iter_cancellable =
10274 _gtk_file_system_mount_enclosing_volume (impl->file_system, col_data,
10276 shortcuts_activate_mount_enclosing_volume,
10281 impl->shortcuts_activate_iter_cancellable =
10282 _gtk_file_system_get_info (impl->file_system, data->file,
10284 shortcuts_activate_get_info_cb, data);
10287 else if (shortcut_type == SHORTCUT_TYPE_SEARCH)
10289 search_activate (impl);
10291 else if (shortcut_type == SHORTCUT_TYPE_RECENT)
10293 recent_activate (impl);
10297 /* Handler for GtkWidget::key-press-event on the shortcuts list */
10299 shortcuts_key_press_event_cb (GtkWidget *widget,
10300 GdkEventKey *event,
10301 GtkFileChooserDefault *impl)
10305 modifiers = gtk_accelerator_get_default_mod_mask ();
10307 if (key_is_left_or_right (event))
10309 gtk_widget_grab_focus (impl->browse_files_tree_view);
10313 if ((event->keyval == GDK_BackSpace
10314 || event->keyval == GDK_Delete
10315 || event->keyval == GDK_KP_Delete)
10316 && (event->state & modifiers) == 0)
10318 remove_selected_bookmarks (impl);
10322 if ((event->keyval == GDK_F2)
10323 && (event->state & modifiers) == 0)
10325 rename_selected_bookmark (impl);
10333 shortcuts_select_func (GtkTreeSelection *selection,
10334 GtkTreeModel *model,
10336 gboolean path_currently_selected,
10339 GtkFileChooserDefault *impl = data;
10340 GtkTreeIter filter_iter;
10341 ShortcutType shortcut_type;
10343 if (!gtk_tree_model_get_iter (impl->shortcuts_pane_filter_model, &filter_iter, path))
10344 g_assert_not_reached ();
10346 gtk_tree_model_get (impl->shortcuts_pane_filter_model, &filter_iter, SHORTCUTS_COL_TYPE, &shortcut_type, -1);
10348 return shortcut_type != SHORTCUT_TYPE_SEPARATOR;
10352 list_select_func (GtkTreeSelection *selection,
10353 GtkTreeModel *model,
10355 gboolean path_currently_selected,
10358 GtkFileChooserDefault *impl = data;
10360 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
10361 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
10364 gboolean is_folder;
10366 if (!gtk_tree_model_get_iter (model, &iter, path))
10368 gtk_tree_model_get (model, &iter,
10369 MODEL_COL_IS_FOLDER, &is_folder,
10379 list_selection_changed (GtkTreeSelection *selection,
10380 GtkFileChooserDefault *impl)
10382 /* See if we are in the new folder editable row for Save mode */
10383 if (impl->operation_mode == OPERATION_MODE_BROWSE &&
10384 impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
10387 gboolean had_selection;
10389 info = get_selected_file_info_from_file_list (impl, &had_selection);
10390 if (!had_selection)
10391 goto out; /* normal processing */
10394 return; /* We are on the editable row for New Folder */
10399 if (impl->location_entry)
10400 update_chooser_entry (impl);
10402 check_preview_change (impl);
10403 bookmarks_check_add_sensitivity (impl);
10405 g_signal_emit_by_name (impl, "selection-changed", 0);
10408 /* Callback used when a row in the file list is activated */
10410 list_row_activated (GtkTreeView *tree_view,
10412 GtkTreeViewColumn *column,
10413 GtkFileChooserDefault *impl)
10417 GtkTreeModel *model;
10418 gboolean is_folder;
10420 model = gtk_tree_view_get_model (tree_view);
10422 if (!gtk_tree_model_get_iter (model, &iter, path))
10425 gtk_tree_model_get (model, &iter,
10426 MODEL_COL_FILE, &file,
10427 MODEL_COL_IS_FOLDER, &is_folder,
10430 if (is_folder && file)
10432 change_folder_and_display_error (impl, file, FALSE);
10436 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
10437 impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
10438 g_signal_emit_by_name (impl, "file-activated");
10441 g_object_unref (file);
10445 path_bar_clicked (GtkPathBar *path_bar,
10448 gboolean child_is_hidden,
10449 GtkFileChooserDefault *impl)
10452 pending_select_files_add (impl, child_file);
10454 if (!change_folder_and_display_error (impl, file, FALSE))
10457 /* Say we have "/foo/bar/[.baz]" and the user clicks on "bar". We should then
10458 * show hidden files so that ".baz" appears in the file list, as it will still
10459 * be shown in the path bar: "/foo/[bar]/.baz"
10461 if (child_is_hidden)
10462 g_object_set (impl, "show-hidden", TRUE, NULL);
10466 update_cell_renderer_attributes (GtkFileChooserDefault *impl)
10468 GtkTreeViewColumn *column;
10469 GtkCellRenderer *renderer;
10470 GList *walk, *list;
10471 gboolean always_sensitive;
10473 always_sensitive = impl->action != GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER &&
10474 impl->action != GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER;
10477 column = gtk_tree_view_get_column (GTK_TREE_VIEW (impl->browse_files_tree_view), 0);
10478 list = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column));
10479 for (walk = list; walk; walk = walk->next)
10481 renderer = walk->data;
10482 if (GTK_IS_CELL_RENDERER_PIXBUF (renderer))
10484 gtk_tree_view_column_set_attributes (column, renderer,
10485 "pixbuf", MODEL_COL_PIXBUF,
10490 gtk_tree_view_column_set_attributes (column, renderer,
10491 "text", MODEL_COL_NAME,
10492 "ellipsize", MODEL_COL_ELLIPSIZE,
10495 if (always_sensitive)
10496 g_object_set (renderer, "sensitive", TRUE, NULL);
10498 gtk_tree_view_column_add_attribute (column, renderer, "sensitive", MODEL_COL_IS_FOLDER);
10500 g_list_free (list);
10503 column = gtk_tree_view_get_column (GTK_TREE_VIEW (impl->browse_files_tree_view), 1);
10504 list = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column));
10505 renderer = list->data;
10506 gtk_tree_view_column_set_attributes (column, renderer,
10507 "text", MODEL_COL_SIZE_TEXT,
10509 if (always_sensitive)
10510 g_object_set (renderer, "sensitive", TRUE, NULL);
10512 gtk_tree_view_column_add_attribute (column, renderer, "sensitive", MODEL_COL_IS_FOLDER);
10513 g_list_free (list);
10516 column = gtk_tree_view_get_column (GTK_TREE_VIEW (impl->browse_files_tree_view), 2);
10517 list = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column));
10518 renderer = list->data;
10519 gtk_tree_view_column_set_attributes (column, renderer,
10520 "text", MODEL_COL_MTIME_TEXT,
10522 if (always_sensitive)
10523 g_object_set (renderer, "sensitive", TRUE, NULL);
10525 gtk_tree_view_column_add_attribute (column, renderer, "sensitive", MODEL_COL_IS_FOLDER);
10526 g_list_free (list);
10530 _gtk_file_chooser_default_new (void)
10532 return g_object_new (GTK_TYPE_FILE_CHOOSER_DEFAULT, NULL);
10536 location_set_user_text (GtkFileChooserDefault *impl,
10539 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), path);
10540 gtk_editable_set_position (GTK_EDITABLE (impl->location_entry), -1);
10544 location_popup_handler (GtkFileChooserDefault *impl,
10547 if (impl->operation_mode != OPERATION_MODE_BROWSE)
10549 GtkWidget *widget_to_focus;
10551 /* This will give us the location widgets back */
10552 switch (impl->operation_mode)
10554 case OPERATION_MODE_SEARCH:
10555 search_switch_to_browse_mode (impl);
10557 case OPERATION_MODE_RECENT:
10558 recent_switch_to_browse_mode (impl);
10560 case OPERATION_MODE_BROWSE:
10561 g_assert_not_reached ();
10565 if (impl->current_folder)
10566 change_folder_and_display_error (impl, impl->current_folder, FALSE);
10568 if (impl->location_mode == LOCATION_MODE_PATH_BAR)
10569 widget_to_focus = impl->browse_files_tree_view;
10571 widget_to_focus = impl->location_entry;
10573 gtk_widget_grab_focus (widget_to_focus);
10577 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
10578 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
10580 LocationMode new_mode;
10584 /* since the user typed something, we unconditionally want to turn on the entry */
10585 new_mode = LOCATION_MODE_FILENAME_ENTRY;
10587 else if (impl->location_mode == LOCATION_MODE_PATH_BAR)
10588 new_mode = LOCATION_MODE_FILENAME_ENTRY;
10589 else if (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)
10590 new_mode = LOCATION_MODE_PATH_BAR;
10593 g_assert_not_reached ();
10597 location_mode_set (impl, new_mode, TRUE);
10598 if (new_mode == LOCATION_MODE_FILENAME_ENTRY)
10601 location_set_user_text (impl, path);
10604 location_entry_set_initial_text (impl);
10605 gtk_editable_select_region (GTK_EDITABLE (impl->location_entry), 0, -1);
10609 else if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
10610 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
10612 gtk_widget_grab_focus (impl->location_entry);
10614 location_set_user_text (impl, path);
10617 g_assert_not_reached ();
10620 /* Handler for the "up-folder" keybinding signal */
10622 up_folder_handler (GtkFileChooserDefault *impl)
10624 _gtk_path_bar_up (GTK_PATH_BAR (impl->browse_path_bar));
10627 /* Handler for the "down-folder" keybinding signal */
10629 down_folder_handler (GtkFileChooserDefault *impl)
10631 _gtk_path_bar_down (GTK_PATH_BAR (impl->browse_path_bar));
10634 /* Switches to the shortcut in the specified index */
10636 switch_to_shortcut (GtkFileChooserDefault *impl,
10641 if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos))
10642 g_assert_not_reached ();
10644 shortcuts_activate_iter (impl, &iter);
10647 /* Handler for the "home-folder" keybinding signal */
10649 home_folder_handler (GtkFileChooserDefault *impl)
10651 if (impl->has_home)
10652 switch_to_shortcut (impl, shortcuts_get_index (impl, SHORTCUTS_HOME));
10655 /* Handler for the "desktop-folder" keybinding signal */
10657 desktop_folder_handler (GtkFileChooserDefault *impl)
10659 if (impl->has_desktop)
10660 switch_to_shortcut (impl, shortcuts_get_index (impl, SHORTCUTS_DESKTOP));
10663 /* Handler for the "search-shortcut" keybinding signal */
10665 search_shortcut_handler (GtkFileChooserDefault *impl)
10667 if (impl->has_search)
10669 switch_to_shortcut (impl, shortcuts_get_index (impl, SHORTCUTS_SEARCH));
10671 /* we want the entry widget to grab the focus the first
10672 * time, not the browse_files_tree_view widget.
10674 if (impl->search_entry)
10675 gtk_widget_grab_focus (impl->search_entry);
10679 /* Handler for the "recent-shortcut" keybinding signal */
10681 recent_shortcut_handler (GtkFileChooserDefault *impl)
10683 if (impl->has_recent)
10684 switch_to_shortcut (impl, shortcuts_get_index (impl, SHORTCUTS_RECENT));
10688 quick_bookmark_handler (GtkFileChooserDefault *impl,
10689 gint bookmark_index)
10694 if (bookmark_index < 0 || bookmark_index >= impl->num_bookmarks)
10697 bookmark_pos = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS) + bookmark_index;
10699 path = gtk_tree_path_new_from_indices (bookmark_pos, -1);
10700 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view),
10703 gtk_tree_path_free (path);
10705 switch_to_shortcut (impl, bookmark_pos);
10709 show_hidden_handler (GtkFileChooserDefault *impl)
10711 g_object_set (impl,
10712 "show-hidden", !impl->show_hidden,
10717 /* Drag and drop interfaces */
10720 _shortcuts_pane_model_filter_class_init (ShortcutsPaneModelFilterClass *class)
10725 _shortcuts_pane_model_filter_init (ShortcutsPaneModelFilter *model)
10727 model->impl = NULL;
10730 /* GtkTreeDragSource::row_draggable implementation for the shortcuts filter model */
10732 shortcuts_pane_model_filter_row_draggable (GtkTreeDragSource *drag_source,
10735 ShortcutsPaneModelFilter *model;
10739 model = SHORTCUTS_PANE_MODEL_FILTER (drag_source);
10741 pos = *gtk_tree_path_get_indices (path);
10742 bookmarks_pos = shortcuts_get_index (model->impl, SHORTCUTS_BOOKMARKS);
10744 return (pos >= bookmarks_pos && pos < bookmarks_pos + model->impl->num_bookmarks);
10747 /* GtkTreeDragSource::drag_data_get implementation for the shortcuts filter model */
10749 shortcuts_pane_model_filter_drag_data_get (GtkTreeDragSource *drag_source,
10751 GtkSelectionData *selection_data)
10753 ShortcutsPaneModelFilter *model;
10755 model = SHORTCUTS_PANE_MODEL_FILTER (drag_source);
10762 /* Fill the GtkTreeDragSourceIface vtable */
10764 shortcuts_pane_model_filter_drag_source_iface_init (GtkTreeDragSourceIface *iface)
10766 iface->row_draggable = shortcuts_pane_model_filter_row_draggable;
10767 iface->drag_data_get = shortcuts_pane_model_filter_drag_data_get;
10771 /* Fill the GtkTreeDragDestIface vtable */
10773 shortcuts_pane_model_filter_drag_dest_iface_init (GtkTreeDragDestIface *iface)
10775 iface->drag_data_received = shortcuts_pane_model_filter_drag_data_received;
10776 iface->row_drop_possible = shortcuts_pane_model_filter_row_drop_possible;
10780 static GtkTreeModel *
10781 shortcuts_pane_model_filter_new (GtkFileChooserDefault *impl,
10782 GtkTreeModel *child_model,
10785 ShortcutsPaneModelFilter *model;
10787 model = g_object_new (SHORTCUTS_PANE_MODEL_FILTER_TYPE,
10788 "child-model", child_model,
10789 "virtual-root", root,
10792 model->impl = impl;
10794 return GTK_TREE_MODEL (model);
10800 recent_model_sort_row_draggable (GtkTreeDragSource *drag_source,
10803 RecentModelSort *model;
10804 GtkTreeIter iter, child_iter;
10805 gboolean is_folder;
10807 model = RECENT_MODEL_SORT (drag_source);
10808 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path))
10811 recent_get_valid_child_iter (model->impl, &child_iter, &iter);
10812 gtk_tree_model_get (GTK_TREE_MODEL (model->impl->recent_model), &child_iter,
10813 MODEL_COL_IS_FOLDER, &is_folder,
10820 recent_model_sort_drag_data_get (GtkTreeDragSource *drag_source,
10822 GtkSelectionData *selection_data)
10824 RecentModelSort *model;
10825 GtkTreeIter iter, child_iter;
10829 model = RECENT_MODEL_SORT (drag_source);
10830 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path))
10833 recent_get_valid_child_iter (model->impl, &child_iter, &iter);
10834 gtk_tree_model_get (GTK_TREE_MODEL (model->impl->recent_model), &child_iter,
10835 MODEL_COL_FILE, &file,
10837 g_assert (file != NULL);
10839 uris[0] = g_file_get_uri (file);
10842 gtk_selection_data_set_uris (selection_data, uris);
10845 g_object_unref (file);
10851 recent_model_sort_drag_source_iface_init (GtkTreeDragSourceIface *iface)
10853 iface->row_draggable = recent_model_sort_row_draggable;
10854 iface->drag_data_get = recent_model_sort_drag_data_get;
10858 _recent_model_sort_class_init (RecentModelSortClass *klass)
10864 _recent_model_sort_init (RecentModelSort *model)
10866 model->impl = NULL;
10869 static GtkTreeModel *
10870 recent_model_sort_new (GtkFileChooserDefault *impl,
10871 GtkTreeModel *child_model)
10873 RecentModelSort *model;
10875 model = g_object_new (RECENT_MODEL_SORT_TYPE,
10876 "model", child_model,
10878 model->impl = impl;
10880 return GTK_TREE_MODEL (model);