1 /* GTK - The GIMP Toolkit
2 * gtkfilechooserdefault.c: Default implementation of GtkFileChooser
3 * Copyright (C) 2003, Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 #include "gdk/gdkkeysyms.h"
23 #include "gtkalignment.h"
24 #include "gtkbindings.h"
25 #include "gtkbutton.h"
26 #include "gtkcelllayout.h"
27 #include "gtkcellrendererpixbuf.h"
28 #include "gtkcellrenderertext.h"
29 #include "gtkcellrenderertext.h"
30 #include "gtkcheckmenuitem.h"
31 #include "gtkcombobox.h"
33 #include "gtkeventbox.h"
34 #include "gtkexpander.h"
35 #include "gtkfilechooserprivate.h"
36 #include "gtkfilechooserdefault.h"
37 #include "gtkfilechooserembed.h"
38 #include "gtkfilechooserentry.h"
39 #include "gtkfilechooserutils.h"
40 #include "gtkfilechooser.h"
41 #include "gtkfilesystemmodel.h"
44 #include "gtkhpaned.h"
45 #include "gtkiconfactory.h"
46 #include "gtkicontheme.h"
48 #include "gtkimagemenuitem.h"
51 #include "gtkmarshalers.h"
52 #include "gtkmenuitem.h"
53 #include "gtkmessagedialog.h"
54 #include "gtkpathbar.h"
55 #include "gtkprivate.h"
56 #include "gtkscrolledwindow.h"
57 #include "gtkseparatormenuitem.h"
58 #include "gtksizegroup.h"
61 #include "gtktreednd.h"
62 #include "gtktreeprivate.h"
63 #include "gtktreeselection.h"
64 #include "gtktypebuiltins.h"
67 #if defined (G_OS_UNIX)
68 #include "gtkfilesystemunix.h"
69 #elif defined (G_OS_WIN32)
70 #include "gtkfilesystemwin32.h"
89 #undef PROFILE_FILE_CHOOSER
90 #ifdef PROFILE_FILE_CHOOSER
97 #define PROFILE_INDENT 4
98 static int profile_indent;
101 profile_add_indent (int indent)
103 profile_indent += indent;
104 if (profile_indent < 0)
105 g_error ("You screwed up your indentation");
109 _gtk_file_chooser_profile_log (const char *func, int indent, const char *msg1, const char *msg2)
114 profile_add_indent (indent);
116 if (profile_indent == 0)
117 str = g_strdup_printf ("MARK: %s %s %s", func ? func : "", msg1 ? msg1 : "", msg2 ? msg2 : "");
119 str = g_strdup_printf ("MARK: %*c %s %s %s", profile_indent - 1, ' ', func ? func : "", msg1 ? msg1 : "", msg2 ? msg2 : "");
125 profile_add_indent (indent);
128 #define profile_start(x, y) _gtk_file_chooser_profile_log (G_STRFUNC, PROFILE_INDENT, x, y)
129 #define profile_end(x, y) _gtk_file_chooser_profile_log (G_STRFUNC, -PROFILE_INDENT, x, y)
130 #define profile_msg(x, y) _gtk_file_chooser_profile_log (NULL, 0, x, y)
132 #define profile_start(x, y)
133 #define profile_end(x, y)
134 #define profile_msg(x, y)
139 typedef struct _GtkFileChooserDefaultClass GtkFileChooserDefaultClass;
141 #define GTK_FILE_CHOOSER_DEFAULT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FILE_CHOOSER_DEFAULT, GtkFileChooserDefaultClass))
142 #define GTK_IS_FILE_CHOOSER_DEFAULT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FILE_CHOOSER_DEFAULT))
143 #define GTK_FILE_CHOOSER_DEFAULT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FILE_CHOOSER_DEFAULT, GtkFileChooserDefaultClass))
145 #define MAX_LOADING_TIME 500
147 struct _GtkFileChooserDefaultClass
149 GtkVBoxClass parent_class;
163 static guint signals[LAST_SIGNAL] = { 0 };
165 /* Column numbers for the shortcuts tree. Keep these in sync with shortcuts_model_create() */
167 SHORTCUTS_COL_PIXBUF,
170 SHORTCUTS_COL_IS_VOLUME,
171 SHORTCUTS_COL_REMOVABLE,
172 SHORTCUTS_COL_PIXBUF_VISIBLE,
173 SHORTCUTS_COL_NUM_COLUMNS
176 /* Column numbers for the file list */
181 FILE_LIST_COL_NUM_COLUMNS
184 /* Identifiers for target types */
190 /* Target types for dragging from the shortcuts list */
191 static const GtkTargetEntry shortcuts_source_targets[] = {
192 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, GTK_TREE_MODEL_ROW }
195 static const int num_shortcuts_source_targets = (sizeof (shortcuts_source_targets)
196 / sizeof (shortcuts_source_targets[0]));
198 /* Target types for dropping into the shortcuts list */
199 static const GtkTargetEntry shortcuts_dest_targets[] = {
200 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, GTK_TREE_MODEL_ROW },
201 { "text/uri-list", 0, TEXT_URI_LIST }
204 static const int num_shortcuts_dest_targets = (sizeof (shortcuts_dest_targets)
205 / sizeof (shortcuts_dest_targets[0]));
207 /* Target types for DnD from the file list */
208 static const GtkTargetEntry file_list_source_targets[] = {
209 { "text/uri-list", 0, TEXT_URI_LIST }
212 static const int num_file_list_source_targets = (sizeof (file_list_source_targets)
213 / sizeof (file_list_source_targets[0]));
215 /* Target types for dropping into the file list */
216 static const GtkTargetEntry file_list_dest_targets[] = {
217 { "text/uri-list", 0, TEXT_URI_LIST }
220 static const int num_file_list_dest_targets = (sizeof (file_list_dest_targets)
221 / sizeof (file_list_dest_targets[0]));
224 /* Interesting places in the shortcuts bar */
230 SHORTCUTS_BOOKMARKS_SEPARATOR,
232 SHORTCUTS_CURRENT_FOLDER_SEPARATOR,
233 SHORTCUTS_CURRENT_FOLDER
236 /* Icon size for if we can't get it from the theme */
237 #define FALLBACK_ICON_SIZE 16
239 #define PREVIEW_HBOX_SPACING 12
243 static void gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class);
244 static void gtk_file_chooser_default_iface_init (GtkFileChooserIface *iface);
245 static void gtk_file_chooser_embed_default_iface_init (GtkFileChooserEmbedIface *iface);
246 static void gtk_file_chooser_default_init (GtkFileChooserDefault *impl);
248 static GObject* gtk_file_chooser_default_constructor (GType type,
249 guint n_construct_properties,
250 GObjectConstructParam *construct_params);
251 static void gtk_file_chooser_default_finalize (GObject *object);
252 static void gtk_file_chooser_default_set_property (GObject *object,
256 static void gtk_file_chooser_default_get_property (GObject *object,
260 static void gtk_file_chooser_default_dispose (GObject *object);
261 static void gtk_file_chooser_default_show_all (GtkWidget *widget);
262 static void gtk_file_chooser_default_map (GtkWidget *widget);
263 static void gtk_file_chooser_default_unmap (GtkWidget *widget);
264 static void gtk_file_chooser_default_hierarchy_changed (GtkWidget *widget,
265 GtkWidget *previous_toplevel);
266 static void gtk_file_chooser_default_style_set (GtkWidget *widget,
267 GtkStyle *previous_style);
268 static void gtk_file_chooser_default_screen_changed (GtkWidget *widget,
269 GdkScreen *previous_screen);
271 static gboolean gtk_file_chooser_default_set_current_folder (GtkFileChooser *chooser,
272 const GtkFilePath *path,
274 static gboolean gtk_file_chooser_default_update_current_folder (GtkFileChooser *chooser,
275 const GtkFilePath *path,
278 static GtkFilePath * gtk_file_chooser_default_get_current_folder (GtkFileChooser *chooser);
279 static void gtk_file_chooser_default_set_current_name (GtkFileChooser *chooser,
281 static gboolean gtk_file_chooser_default_select_path (GtkFileChooser *chooser,
282 const GtkFilePath *path,
284 static void gtk_file_chooser_default_unselect_path (GtkFileChooser *chooser,
285 const GtkFilePath *path);
286 static void gtk_file_chooser_default_select_all (GtkFileChooser *chooser);
287 static void gtk_file_chooser_default_unselect_all (GtkFileChooser *chooser);
288 static GSList * gtk_file_chooser_default_get_paths (GtkFileChooser *chooser);
289 static GtkFilePath * gtk_file_chooser_default_get_preview_path (GtkFileChooser *chooser);
290 static GtkFileSystem *gtk_file_chooser_default_get_file_system (GtkFileChooser *chooser);
291 static void gtk_file_chooser_default_add_filter (GtkFileChooser *chooser,
292 GtkFileFilter *filter);
293 static void gtk_file_chooser_default_remove_filter (GtkFileChooser *chooser,
294 GtkFileFilter *filter);
295 static GSList * gtk_file_chooser_default_list_filters (GtkFileChooser *chooser);
296 static gboolean gtk_file_chooser_default_add_shortcut_folder (GtkFileChooser *chooser,
297 const GtkFilePath *path,
299 static gboolean gtk_file_chooser_default_remove_shortcut_folder (GtkFileChooser *chooser,
300 const GtkFilePath *path,
302 static GSList * gtk_file_chooser_default_list_shortcut_folders (GtkFileChooser *chooser);
304 static void gtk_file_chooser_default_get_default_size (GtkFileChooserEmbed *chooser_embed,
306 gint *default_height);
307 static void gtk_file_chooser_default_get_resizable_hints (GtkFileChooserEmbed *chooser_embed,
308 gboolean *resize_horizontally,
309 gboolean *resize_vertically);
310 static gboolean gtk_file_chooser_default_should_respond (GtkFileChooserEmbed *chooser_embed);
311 static void gtk_file_chooser_default_initial_focus (GtkFileChooserEmbed *chooser_embed);
313 static void location_popup_handler (GtkFileChooserDefault *impl,
315 static void up_folder_handler (GtkFileChooserDefault *impl);
316 static void down_folder_handler (GtkFileChooserDefault *impl);
317 static void home_folder_handler (GtkFileChooserDefault *impl);
318 static void desktop_folder_handler (GtkFileChooserDefault *impl);
319 static void quick_bookmark_handler (GtkFileChooserDefault *impl,
320 gint bookmark_index);
321 static void update_appearance (GtkFileChooserDefault *impl);
323 static void set_current_filter (GtkFileChooserDefault *impl,
324 GtkFileFilter *filter);
325 static void check_preview_change (GtkFileChooserDefault *impl);
327 static void filter_combo_changed (GtkComboBox *combo_box,
328 GtkFileChooserDefault *impl);
329 static void shortcuts_row_activated_cb (GtkTreeView *tree_view,
331 GtkTreeViewColumn *column,
332 GtkFileChooserDefault *impl);
334 static gboolean shortcuts_key_press_event_cb (GtkWidget *widget,
336 GtkFileChooserDefault *impl);
338 static gboolean shortcuts_select_func (GtkTreeSelection *selection,
341 gboolean path_currently_selected,
343 static gboolean shortcuts_get_selected (GtkFileChooserDefault *impl,
345 static void shortcuts_activate_iter (GtkFileChooserDefault *impl,
347 static int shortcuts_get_index (GtkFileChooserDefault *impl,
348 ShortcutsIndex where);
349 static int shortcut_find_position (GtkFileChooserDefault *impl,
350 const GtkFilePath *path);
352 static void bookmarks_check_add_sensitivity (GtkFileChooserDefault *impl);
354 static gboolean list_select_func (GtkTreeSelection *selection,
357 gboolean path_currently_selected,
360 static void list_selection_changed (GtkTreeSelection *tree_selection,
361 GtkFileChooserDefault *impl);
362 static void list_row_activated (GtkTreeView *tree_view,
364 GtkTreeViewColumn *column,
365 GtkFileChooserDefault *impl);
367 static void select_func (GtkFileSystemModel *model,
372 static void path_bar_clicked (GtkPathBar *path_bar,
373 GtkFilePath *file_path,
374 gboolean child_is_hidden,
375 GtkFileChooserDefault *impl);
377 static void add_bookmark_button_clicked_cb (GtkButton *button,
378 GtkFileChooserDefault *impl);
379 static void remove_bookmark_button_clicked_cb (GtkButton *button,
380 GtkFileChooserDefault *impl);
382 static void list_icon_data_func (GtkTreeViewColumn *tree_column,
383 GtkCellRenderer *cell,
384 GtkTreeModel *tree_model,
387 static void list_name_data_func (GtkTreeViewColumn *tree_column,
388 GtkCellRenderer *cell,
389 GtkTreeModel *tree_model,
393 static void list_size_data_func (GtkTreeViewColumn *tree_column,
394 GtkCellRenderer *cell,
395 GtkTreeModel *tree_model,
399 static void list_mtime_data_func (GtkTreeViewColumn *tree_column,
400 GtkCellRenderer *cell,
401 GtkTreeModel *tree_model,
405 static const GtkFileInfo *get_list_file_info (GtkFileChooserDefault *impl,
408 static void load_remove_timer (GtkFileChooserDefault *impl);
409 static void browse_files_center_selected_row (GtkFileChooserDefault *impl);
411 static GObjectClass *parent_class;
415 /* Drag and drop interface declarations */
418 GtkTreeModelFilter parent;
420 GtkFileChooserDefault *impl;
421 } ShortcutsModelFilter;
424 GtkTreeModelFilterClass parent_class;
425 } ShortcutsModelFilterClass;
427 #define SHORTCUTS_MODEL_FILTER_TYPE (_shortcuts_model_filter_get_type ())
428 #define SHORTCUTS_MODEL_FILTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SHORTCUTS_MODEL_FILTER_TYPE, ShortcutsModelFilter))
430 static void shortcuts_model_filter_drag_source_iface_init (GtkTreeDragSourceIface *iface);
432 G_DEFINE_TYPE_WITH_CODE (ShortcutsModelFilter,
433 _shortcuts_model_filter,
434 GTK_TYPE_TREE_MODEL_FILTER,
435 G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_DRAG_SOURCE,
436 shortcuts_model_filter_drag_source_iface_init));
438 static GtkTreeModel *shortcuts_model_filter_new (GtkFileChooserDefault *impl,
439 GtkTreeModel *child_model,
445 _gtk_file_chooser_default_get_type (void)
447 static GType file_chooser_default_type = 0;
449 if (!file_chooser_default_type)
451 static const GTypeInfo file_chooser_default_info =
453 sizeof (GtkFileChooserDefaultClass),
454 NULL, /* base_init */
455 NULL, /* base_finalize */
456 (GClassInitFunc) gtk_file_chooser_default_class_init,
457 NULL, /* class_finalize */
458 NULL, /* class_data */
459 sizeof (GtkFileChooserDefault),
461 (GInstanceInitFunc) gtk_file_chooser_default_init,
464 static const GInterfaceInfo file_chooser_info =
466 (GInterfaceInitFunc) gtk_file_chooser_default_iface_init, /* interface_init */
467 NULL, /* interface_finalize */
468 NULL /* interface_data */
471 static const GInterfaceInfo file_chooser_embed_info =
473 (GInterfaceInitFunc) gtk_file_chooser_embed_default_iface_init, /* interface_init */
474 NULL, /* interface_finalize */
475 NULL /* interface_data */
478 file_chooser_default_type = g_type_register_static (GTK_TYPE_VBOX, I_("GtkFileChooserDefault"),
479 &file_chooser_default_info, 0);
481 g_type_add_interface_static (file_chooser_default_type,
482 GTK_TYPE_FILE_CHOOSER,
484 g_type_add_interface_static (file_chooser_default_type,
485 GTK_TYPE_FILE_CHOOSER_EMBED,
486 &file_chooser_embed_info);
489 return file_chooser_default_type;
493 gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class)
495 static const guint quick_bookmark_keyvals[10] = {
496 GDK_1, GDK_2, GDK_3, GDK_4, GDK_5, GDK_6, GDK_7, GDK_8, GDK_9, GDK_0
498 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
499 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
500 GtkBindingSet *binding_set;
503 parent_class = g_type_class_peek_parent (class);
505 gobject_class->finalize = gtk_file_chooser_default_finalize;
506 gobject_class->constructor = gtk_file_chooser_default_constructor;
507 gobject_class->set_property = gtk_file_chooser_default_set_property;
508 gobject_class->get_property = gtk_file_chooser_default_get_property;
509 gobject_class->dispose = gtk_file_chooser_default_dispose;
511 widget_class->show_all = gtk_file_chooser_default_show_all;
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;
518 signals[LOCATION_POPUP] =
519 _gtk_binding_signal_new (I_("location-popup"),
520 G_OBJECT_CLASS_TYPE (class),
521 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
522 G_CALLBACK (location_popup_handler),
524 _gtk_marshal_VOID__STRING,
525 G_TYPE_NONE, 1, G_TYPE_STRING);
527 _gtk_binding_signal_new (I_("up-folder"),
528 G_OBJECT_CLASS_TYPE (class),
529 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
530 G_CALLBACK (up_folder_handler),
532 _gtk_marshal_VOID__VOID,
534 signals[DOWN_FOLDER] =
535 _gtk_binding_signal_new (I_("down-folder"),
536 G_OBJECT_CLASS_TYPE (class),
537 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
538 G_CALLBACK (down_folder_handler),
540 _gtk_marshal_VOID__VOID,
542 signals[HOME_FOLDER] =
543 _gtk_binding_signal_new (I_("home-folder"),
544 G_OBJECT_CLASS_TYPE (class),
545 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
546 G_CALLBACK (home_folder_handler),
548 _gtk_marshal_VOID__VOID,
550 signals[DESKTOP_FOLDER] =
551 _gtk_binding_signal_new (I_("desktop-folder"),
552 G_OBJECT_CLASS_TYPE (class),
553 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
554 G_CALLBACK (desktop_folder_handler),
556 _gtk_marshal_VOID__VOID,
558 signals[QUICK_BOOKMARK] =
559 _gtk_binding_signal_new (I_("quick-bookmark"),
560 G_OBJECT_CLASS_TYPE (class),
561 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
562 G_CALLBACK (quick_bookmark_handler),
564 _gtk_marshal_VOID__INT,
565 G_TYPE_NONE, 1, G_TYPE_INT);
567 binding_set = gtk_binding_set_by_class (class);
569 gtk_binding_entry_add_signal (binding_set,
570 GDK_l, GDK_CONTROL_MASK,
572 1, G_TYPE_STRING, "");
574 gtk_binding_entry_add_signal (binding_set,
577 1, G_TYPE_STRING, "/");
579 gtk_binding_entry_add_signal (binding_set,
580 GDK_Up, GDK_MOD1_MASK,
583 gtk_binding_entry_add_signal (binding_set,
587 gtk_binding_entry_add_signal (binding_set,
588 GDK_KP_Up, GDK_MOD1_MASK,
592 gtk_binding_entry_add_signal (binding_set,
593 GDK_Down, GDK_MOD1_MASK,
596 gtk_binding_entry_add_signal (binding_set,
597 GDK_KP_Down, GDK_MOD1_MASK,
601 gtk_binding_entry_add_signal (binding_set,
602 GDK_Home, GDK_MOD1_MASK,
605 gtk_binding_entry_add_signal (binding_set,
606 GDK_KP_Home, GDK_MOD1_MASK,
609 gtk_binding_entry_add_signal (binding_set,
610 GDK_d, GDK_MOD1_MASK,
614 for (i = 0; i < 10; i++)
615 gtk_binding_entry_add_signal (binding_set,
616 quick_bookmark_keyvals[i], GDK_MOD1_MASK,
620 _gtk_file_chooser_install_properties (gobject_class);
622 gtk_settings_install_property (g_param_spec_string ("gtk-file-chooser-backend",
623 P_("Default file chooser backend"),
624 P_("Name of the GtkFileChooser backend to use by default"),
626 GTK_PARAM_READWRITE));
630 gtk_file_chooser_default_iface_init (GtkFileChooserIface *iface)
632 iface->select_path = gtk_file_chooser_default_select_path;
633 iface->unselect_path = gtk_file_chooser_default_unselect_path;
634 iface->select_all = gtk_file_chooser_default_select_all;
635 iface->unselect_all = gtk_file_chooser_default_unselect_all;
636 iface->get_paths = gtk_file_chooser_default_get_paths;
637 iface->get_preview_path = gtk_file_chooser_default_get_preview_path;
638 iface->get_file_system = gtk_file_chooser_default_get_file_system;
639 iface->set_current_folder = gtk_file_chooser_default_set_current_folder;
640 iface->get_current_folder = gtk_file_chooser_default_get_current_folder;
641 iface->set_current_name = gtk_file_chooser_default_set_current_name;
642 iface->add_filter = gtk_file_chooser_default_add_filter;
643 iface->remove_filter = gtk_file_chooser_default_remove_filter;
644 iface->list_filters = gtk_file_chooser_default_list_filters;
645 iface->add_shortcut_folder = gtk_file_chooser_default_add_shortcut_folder;
646 iface->remove_shortcut_folder = gtk_file_chooser_default_remove_shortcut_folder;
647 iface->list_shortcut_folders = gtk_file_chooser_default_list_shortcut_folders;
651 gtk_file_chooser_embed_default_iface_init (GtkFileChooserEmbedIface *iface)
653 iface->get_default_size = gtk_file_chooser_default_get_default_size;
654 iface->get_resizable_hints = gtk_file_chooser_default_get_resizable_hints;
655 iface->should_respond = gtk_file_chooser_default_should_respond;
656 iface->initial_focus = gtk_file_chooser_default_initial_focus;
659 gtk_file_chooser_default_init (GtkFileChooserDefault *impl)
661 profile_start ("start", NULL);
662 #ifdef PROFILE_FILE_CHOOSER
663 access ("MARK: *** CREATE FILE CHOOSER", F_OK);
665 impl->local_only = TRUE;
666 impl->preview_widget_active = TRUE;
667 impl->use_preview_label = TRUE;
668 impl->select_multiple = FALSE;
669 impl->show_hidden = FALSE;
670 impl->icon_size = FALLBACK_ICON_SIZE;
671 impl->load_state = LOAD_EMPTY;
672 impl->reload_state = RELOAD_EMPTY;
673 impl->pending_select_paths = NULL;
675 gtk_box_set_spacing (GTK_BOX (impl), 12);
677 impl->tooltips = gtk_tooltips_new ();
678 g_object_ref (impl->tooltips);
679 gtk_object_sink (GTK_OBJECT (impl->tooltips));
681 profile_end ("end", NULL);
684 /* Frees the data columns for the specified iter in the shortcuts model*/
686 shortcuts_free_row_data (GtkFileChooserDefault *impl,
692 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), iter,
693 SHORTCUTS_COL_DATA, &col_data,
694 SHORTCUTS_COL_IS_VOLUME, &is_volume,
701 GtkFileSystemVolume *volume;
704 gtk_file_system_volume_free (impl->file_system, volume);
711 gtk_file_path_free (path);
715 /* Frees all the data columns in the shortcuts model */
717 shortcuts_free (GtkFileChooserDefault *impl)
721 if (!impl->shortcuts_model)
724 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
727 shortcuts_free_row_data (impl, &iter);
729 while (gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter));
731 g_object_unref (impl->shortcuts_model);
732 impl->shortcuts_model = NULL;
736 pending_select_paths_free (GtkFileChooserDefault *impl)
740 for (l = impl->pending_select_paths; l; l = l->next)
745 gtk_file_path_free (path);
748 g_slist_free (impl->pending_select_paths);
749 impl->pending_select_paths = NULL;
753 pending_select_paths_add (GtkFileChooserDefault *impl,
754 const GtkFilePath *path)
756 impl->pending_select_paths = g_slist_prepend (impl->pending_select_paths, gtk_file_path_copy (path));
759 /* Used from gtk_tree_selection_selected_foreach() */
761 store_selection_foreach (GtkTreeModel *model,
766 GtkFileChooserDefault *impl;
767 GtkTreeIter child_iter;
768 const GtkFilePath *file_path;
770 impl = GTK_FILE_CHOOSER_DEFAULT (data);
772 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model, &child_iter, iter);
774 file_path = _gtk_file_system_model_get_path (impl->browse_files_model, &child_iter);
775 pending_select_paths_add (impl, file_path);
778 /* Stores the current selection in the list of paths to select; this is used to
779 * preserve the selection when reloading the current folder.
782 pending_select_paths_store_selection (GtkFileChooserDefault *impl)
784 GtkTreeSelection *selection;
786 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
787 gtk_tree_selection_selected_foreach (selection, store_selection_foreach, impl);
791 gtk_file_chooser_default_finalize (GObject *object)
793 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (object);
796 if (impl->shortcuts_filter_model)
797 g_object_unref (impl->shortcuts_filter_model);
799 shortcuts_free (impl);
801 g_signal_handler_disconnect (impl->file_system, impl->volumes_changed_id);
802 impl->volumes_changed_id = 0;
803 g_signal_handler_disconnect (impl->file_system, impl->bookmarks_changed_id);
804 impl->bookmarks_changed_id = 0;
805 g_object_unref (impl->file_system);
807 for (l = impl->filters; l; l = l->next)
809 GtkFileFilter *filter;
811 filter = GTK_FILE_FILTER (l->data);
812 g_object_unref (filter);
814 g_slist_free (impl->filters);
816 if (impl->current_filter)
817 g_object_unref (impl->current_filter);
819 if (impl->current_volume_path)
820 gtk_file_path_free (impl->current_volume_path);
822 if (impl->current_folder)
823 gtk_file_path_free (impl->current_folder);
825 if (impl->preview_path)
826 gtk_file_path_free (impl->preview_path);
828 pending_select_paths_free (impl);
830 load_remove_timer (impl);
832 /* Free all the Models we have */
833 if (impl->browse_files_model)
834 g_object_unref (impl->browse_files_model);
836 if (impl->sort_model)
837 g_object_unref (impl->sort_model);
839 g_free (impl->preview_display_name);
841 g_free (impl->edited_new_text);
843 g_object_unref (impl->tooltips);
845 G_OBJECT_CLASS (parent_class)->finalize (object);
848 /* Shows an error dialog set as transient for the specified window */
850 error_message_with_parent (GtkWindow *parent,
856 dialog = gtk_message_dialog_new (parent,
857 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
862 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
866 gtk_window_group_add_window (parent->group, GTK_WINDOW (dialog));
868 gtk_dialog_run (GTK_DIALOG (dialog));
869 gtk_widget_destroy (dialog);
872 /* Returns a toplevel GtkWindow, or NULL if none */
874 get_toplevel (GtkWidget *widget)
878 toplevel = gtk_widget_get_toplevel (widget);
879 if (!GTK_WIDGET_TOPLEVEL (toplevel))
882 return GTK_WINDOW (toplevel);
885 /* Shows an error dialog for the file chooser */
887 error_message (GtkFileChooserDefault *impl,
891 error_message_with_parent (get_toplevel (GTK_WIDGET (impl)), msg, detail);
894 /* Shows a simple error dialog relative to a path. Frees the GError as well. */
896 error_dialog (GtkFileChooserDefault *impl,
898 const GtkFilePath *path,
907 uri = gtk_file_system_path_to_uri (impl->file_system, path);
908 text = g_strdup_printf (msg, uri);
909 error_message (impl, text, error->message);
912 g_error_free (error);
916 /* Displays an error message about not being able to get information for a file.
917 * Frees the GError as well.
920 error_getting_info_dialog (GtkFileChooserDefault *impl,
921 const GtkFilePath *path,
925 _("Could not retrieve information about the file"),
929 /* Shows an error dialog about not being able to add a bookmark */
931 error_adding_bookmark_dialog (GtkFileChooserDefault *impl,
932 const GtkFilePath *path,
936 _("Could not add a bookmark"),
940 /* Shows an error dialog about not being able to remove a bookmark */
942 error_removing_bookmark_dialog (GtkFileChooserDefault *impl,
943 const GtkFilePath *path,
947 _("Could not remove bookmark"),
951 /* Shows an error dialog about not being able to create a folder */
953 error_creating_folder_dialog (GtkFileChooserDefault *impl,
954 const GtkFilePath *path,
958 _("The folder could not be created"),
962 /* Shows an error about not being able to create a folder because a file with
963 * the same name is already there.
966 error_creating_folder_over_existing_file_dialog (GtkFileChooserDefault *impl,
967 const GtkFilePath *path,
971 _("The folder could not be created, as a file with the same name "
972 "already exists. Try using a different name for the folder, "
973 "or rename the file first."),
977 /* Shows an error dialog about not being able to create a filename */
979 error_building_filename_dialog (GtkFileChooserDefault *impl,
980 const GtkFilePath *folder_part,
981 const char *file_part,
984 error_dialog (impl, _("Invalid file name"),
988 /* Shows an error dialog when we cannot switch to a folder */
990 error_changing_folder_dialog (GtkFileChooserDefault *impl,
991 const GtkFilePath *path,
994 error_dialog (impl, _("The folder contents could not be displayed"),
998 /* Changes folders, displaying an error dialog if this fails */
1000 change_folder_and_display_error (GtkFileChooserDefault *impl,
1001 const GtkFilePath *path)
1005 GtkFilePath *path_copy;
1007 g_return_val_if_fail (path != NULL, FALSE);
1009 profile_start ("start", (char *) path);
1011 /* We copy the path because of this case:
1013 * list_row_activated()
1014 * fetches path from model; path belongs to the model (*)
1015 * calls change_folder_and_display_error()
1016 * calls _gtk_file_chooser_set_current_folder_path()
1017 * changing folders fails, sets model to NULL, thus freeing the path in (*)
1020 path_copy = gtk_file_path_copy (path);
1023 result = gtk_file_chooser_default_update_current_folder (GTK_FILE_CHOOSER (impl), path_copy, TRUE, &error);
1026 error_changing_folder_dialog (impl, path_copy, error);
1028 gtk_file_path_free (path_copy);
1030 profile_end ("end", (char *) path);
1036 update_preview_widget_visibility (GtkFileChooserDefault *impl)
1038 if (impl->use_preview_label)
1040 if (!impl->preview_label)
1042 impl->preview_label = gtk_label_new (impl->preview_display_name);
1043 gtk_box_pack_start (GTK_BOX (impl->preview_box), impl->preview_label, FALSE, FALSE, 0);
1044 gtk_box_reorder_child (GTK_BOX (impl->preview_box), impl->preview_label, 0);
1045 gtk_label_set_ellipsize (GTK_LABEL (impl->preview_label), PANGO_ELLIPSIZE_MIDDLE);
1046 gtk_widget_show (impl->preview_label);
1051 if (impl->preview_label)
1053 gtk_widget_destroy (impl->preview_label);
1054 impl->preview_label = NULL;
1058 if (impl->preview_widget_active && impl->preview_widget)
1059 gtk_widget_show (impl->preview_box);
1061 gtk_widget_hide (impl->preview_box);
1063 g_signal_emit_by_name (impl, "default-size-changed");
1067 set_preview_widget (GtkFileChooserDefault *impl,
1068 GtkWidget *preview_widget)
1070 if (preview_widget == impl->preview_widget)
1073 if (impl->preview_widget)
1074 gtk_container_remove (GTK_CONTAINER (impl->preview_box),
1075 impl->preview_widget);
1077 impl->preview_widget = preview_widget;
1078 if (impl->preview_widget)
1080 gtk_widget_show (impl->preview_widget);
1081 gtk_box_pack_start (GTK_BOX (impl->preview_box), impl->preview_widget, TRUE, TRUE, 0);
1082 gtk_box_reorder_child (GTK_BOX (impl->preview_box),
1083 impl->preview_widget,
1084 (impl->use_preview_label && impl->preview_label) ? 1 : 0);
1087 update_preview_widget_visibility (impl);
1090 /* Re-reads all the icons for the shortcuts, used when the theme changes */
1092 shortcuts_reload_icons (GtkFileChooserDefault *impl)
1096 profile_start ("start", NULL);
1098 if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
1104 gboolean pixbuf_visible;
1107 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
1108 SHORTCUTS_COL_DATA, &data,
1109 SHORTCUTS_COL_IS_VOLUME, &is_volume,
1110 SHORTCUTS_COL_PIXBUF_VISIBLE, &pixbuf_visible,
1113 if (pixbuf_visible && data)
1117 GtkFileSystemVolume *volume;
1120 pixbuf = gtk_file_system_volume_render_icon (impl->file_system, volume, GTK_WIDGET (impl),
1121 impl->icon_size, NULL);
1125 const GtkFilePath *path;
1128 pixbuf = gtk_file_system_render_icon (impl->file_system, path, GTK_WIDGET (impl),
1129 impl->icon_size, NULL);
1132 gtk_list_store_set (impl->shortcuts_model, &iter,
1133 SHORTCUTS_COL_PIXBUF, pixbuf,
1136 g_object_unref (pixbuf);
1138 } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model),&iter));
1142 profile_end ("end", NULL);
1146 shortcuts_find_folder (GtkFileChooserDefault *impl,
1147 GtkFilePath *folder)
1149 GtkTreeSelection *selection;
1153 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view));
1155 g_assert (folder != NULL);
1156 pos = shortcut_find_position (impl, folder);
1159 gtk_tree_selection_unselect_all (selection);
1163 path = gtk_tree_path_new_from_indices (pos, -1);
1164 gtk_tree_selection_select_path (selection, path);
1165 gtk_tree_path_free (path);
1168 /* If a shortcut corresponds to the current folder, selects it */
1170 shortcuts_find_current_folder (GtkFileChooserDefault *impl)
1172 shortcuts_find_folder (impl, impl->current_folder);
1175 /* Convenience function to get the display name and icon info for a path */
1176 static GtkFileInfo *
1177 get_file_info (GtkFileSystem *file_system,
1178 const GtkFilePath *path,
1182 GtkFilePath *parent_path;
1183 GtkFileFolder *parent_folder;
1187 profile_start ("start", (char *) path);
1192 if (!gtk_file_system_get_parent (file_system, path, &parent_path, &tmp))
1195 parent_folder = gtk_file_system_get_folder (file_system, parent_path ? parent_path : path,
1196 GTK_FILE_INFO_DISPLAY_NAME
1197 | (name_only ? 0 : GTK_FILE_INFO_IS_FOLDER),
1202 info = gtk_file_folder_get_info (parent_folder, parent_path ? path : NULL, &tmp);
1203 g_object_unref (parent_folder);
1207 gtk_file_path_free (parent_path);
1212 GTK_FILE_CHOOSER_ERROR,
1213 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1214 _("Could not get information about '%s': %s"),
1215 gtk_file_path_get_string (path),
1220 profile_end ("end", (char *) path);
1225 /* Returns whether a path is a folder */
1227 check_is_folder (GtkFileSystem *file_system,
1228 const GtkFilePath *path,
1231 GtkFileFolder *folder;
1233 profile_start ("start", (char *) path);
1235 folder = gtk_file_system_get_folder (file_system, path, 0, error);
1238 profile_end ("end - is not folder", (char *) path);
1242 g_object_unref (folder);
1244 profile_end ("end", (char *) path);
1248 /* Inserts a path in the shortcuts tree, making a copy of it; alternatively,
1249 * inserts a volume. A position of -1 indicates the end of the tree.
1252 shortcuts_insert_path (GtkFileChooserDefault *impl,
1255 GtkFileSystemVolume *volume,
1256 const GtkFilePath *path,
1266 profile_start ("start", is_volume ? "volume" : (char *) path);
1271 label_copy = gtk_file_system_volume_get_display_name (impl->file_system, volume);
1272 pixbuf = gtk_file_system_volume_render_icon (impl->file_system, volume, GTK_WIDGET (impl),
1273 impl->icon_size, NULL);
1277 if (!check_is_folder (impl->file_system, path, error))
1279 profile_end ("end - is not folder", NULL);
1284 label_copy = g_strdup (label);
1287 GtkFileInfo *info = get_file_info (impl->file_system, path, TRUE, error);
1291 profile_end ("end - could not get info", (char *) path);
1295 label_copy = g_strdup (gtk_file_info_get_display_name (info));
1296 gtk_file_info_free (info);
1299 data = gtk_file_path_copy (path);
1300 pixbuf = gtk_file_system_render_icon (impl->file_system, path, GTK_WIDGET (impl),
1301 impl->icon_size, NULL);
1305 gtk_list_store_append (impl->shortcuts_model, &iter);
1307 gtk_list_store_insert (impl->shortcuts_model, &iter, pos);
1309 gtk_list_store_set (impl->shortcuts_model, &iter,
1310 SHORTCUTS_COL_PIXBUF, pixbuf,
1311 SHORTCUTS_COL_PIXBUF_VISIBLE, TRUE,
1312 SHORTCUTS_COL_NAME, label_copy,
1313 SHORTCUTS_COL_DATA, data,
1314 SHORTCUTS_COL_IS_VOLUME, is_volume,
1315 SHORTCUTS_COL_REMOVABLE, removable,
1318 g_free (label_copy);
1321 g_object_unref (pixbuf);
1323 profile_end ("end", NULL);
1328 /* Appends an item for the user's home directory to the shortcuts model */
1330 shortcuts_append_home (GtkFileChooserDefault *impl)
1333 GtkFilePath *home_path;
1336 profile_start ("start", NULL);
1338 home = g_get_home_dir ();
1341 profile_end ("end - no home directory!?", NULL);
1345 home_path = gtk_file_system_filename_to_path (impl->file_system, home);
1348 impl->has_home = shortcuts_insert_path (impl, -1, FALSE, NULL, home_path, NULL, FALSE, &error);
1349 if (!impl->has_home)
1350 error_getting_info_dialog (impl, home_path, error);
1352 gtk_file_path_free (home_path);
1354 profile_end ("end", NULL);
1357 /* Appends the ~/Desktop directory to the shortcuts model */
1359 shortcuts_append_desktop (GtkFileChooserDefault *impl)
1365 profile_start ("start", NULL);
1368 name = _gtk_file_system_win32_get_desktop ();
1370 home = g_get_home_dir ();
1373 profile_end ("end - no home directory!?", NULL);
1377 name = g_build_filename (home, "Desktop", NULL);
1380 path = gtk_file_system_filename_to_path (impl->file_system, name);
1383 impl->has_desktop = shortcuts_insert_path (impl, -1, FALSE, NULL, path, _("Desktop"), FALSE, NULL);
1384 /* We do not actually pop up an error dialog if there is no desktop directory
1385 * because some people may really not want to have one.
1388 gtk_file_path_free (path);
1390 profile_end ("end", NULL);
1393 /* Appends a list of GtkFilePath to the shortcuts model; returns how many were inserted */
1395 shortcuts_append_paths (GtkFileChooserDefault *impl,
1402 profile_start ("start", NULL);
1404 /* As there is no separator now, we want to start there.
1406 start_row = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR);
1409 for (; paths; paths = paths->next)
1415 if (impl->local_only &&
1416 !gtk_file_system_path_is_local (impl->file_system, path))
1419 label = gtk_file_system_get_bookmark_label (impl->file_system, path);
1421 /* NULL GError, but we don't really want to show error boxes here */
1422 if (shortcuts_insert_path (impl, start_row + num_inserted, FALSE, NULL, path, label, TRUE, NULL))
1428 profile_end ("end", NULL);
1430 return num_inserted;
1433 /* Returns the index for the corresponding item in the shortcuts bar */
1435 shortcuts_get_index (GtkFileChooserDefault *impl,
1436 ShortcutsIndex where)
1442 if (where == SHORTCUTS_HOME)
1445 n += impl->has_home ? 1 : 0;
1447 if (where == SHORTCUTS_DESKTOP)
1450 n += impl->has_desktop ? 1 : 0;
1452 if (where == SHORTCUTS_VOLUMES)
1455 n += impl->num_volumes;
1457 if (where == SHORTCUTS_SHORTCUTS)
1460 n += impl->num_shortcuts;
1462 if (where == SHORTCUTS_BOOKMARKS_SEPARATOR)
1465 /* If there are no bookmarks there won't be a separator */
1466 n += (impl->num_bookmarks > 0) ? 1 : 0;
1468 if (where == SHORTCUTS_BOOKMARKS)
1471 n += impl->num_bookmarks;
1473 if (where == SHORTCUTS_CURRENT_FOLDER_SEPARATOR)
1478 if (where == SHORTCUTS_CURRENT_FOLDER)
1481 g_assert_not_reached ();
1488 /* Removes the specified number of rows from the shortcuts list */
1490 shortcuts_remove_rows (GtkFileChooserDefault *impl,
1496 path = gtk_tree_path_new_from_indices (start_row, -1);
1498 for (; n_rows; n_rows--)
1502 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->shortcuts_model), &iter, path))
1503 g_assert_not_reached ();
1505 shortcuts_free_row_data (impl, &iter);
1506 gtk_list_store_remove (impl->shortcuts_model, &iter);
1509 gtk_tree_path_free (path);
1512 /* Adds all the file system volumes to the shortcuts model */
1514 shortcuts_add_volumes (GtkFileChooserDefault *impl)
1519 gboolean old_changing_folders;
1521 profile_start ("start", NULL);
1523 old_changing_folders = impl->changing_folder;
1524 impl->changing_folder = TRUE;
1526 start_row = shortcuts_get_index (impl, SHORTCUTS_VOLUMES);
1527 shortcuts_remove_rows (impl, start_row, impl->num_volumes);
1528 impl->num_volumes = 0;
1530 list = gtk_file_system_list_volumes (impl->file_system);
1534 for (l = list; l; l = l->next)
1536 GtkFileSystemVolume *volume;
1540 if (impl->local_only)
1542 GtkFilePath *base_path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
1543 if (base_path != NULL)
1545 gboolean is_local = gtk_file_system_path_is_local (impl->file_system, base_path);
1546 gtk_file_path_free (base_path);
1550 gtk_file_system_volume_free (impl->file_system, volume);
1556 if (shortcuts_insert_path (impl, start_row + n, TRUE, volume, NULL, NULL, FALSE, NULL))
1559 gtk_file_system_volume_free (impl->file_system, volume);
1562 impl->num_volumes = n;
1563 g_slist_free (list);
1565 if (impl->shortcuts_filter_model)
1566 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_filter_model));
1568 impl->changing_folder = old_changing_folders;
1570 profile_end ("end", NULL);
1573 /* Inserts a separator node in the shortcuts list */
1575 shortcuts_insert_separator (GtkFileChooserDefault *impl,
1576 ShortcutsIndex where)
1580 g_assert (where == SHORTCUTS_BOOKMARKS_SEPARATOR || where == SHORTCUTS_CURRENT_FOLDER_SEPARATOR);
1582 gtk_list_store_insert (impl->shortcuts_model, &iter,
1583 shortcuts_get_index (impl, where));
1584 gtk_list_store_set (impl->shortcuts_model, &iter,
1585 SHORTCUTS_COL_PIXBUF, NULL,
1586 SHORTCUTS_COL_PIXBUF_VISIBLE, FALSE,
1587 SHORTCUTS_COL_NAME, NULL,
1588 SHORTCUTS_COL_DATA, NULL,
1592 /* Updates the list of bookmarks */
1594 shortcuts_add_bookmarks (GtkFileChooserDefault *impl)
1597 gboolean old_changing_folders;
1599 GtkFilePath *list_selected = NULL;
1600 GtkFilePath *combo_selected = NULL;
1604 profile_start ("start", NULL);
1606 old_changing_folders = impl->changing_folder;
1607 impl->changing_folder = TRUE;
1609 if (shortcuts_get_selected (impl, &iter))
1611 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model),
1613 SHORTCUTS_COL_DATA, &col_data,
1614 SHORTCUTS_COL_IS_VOLUME, &is_volume,
1617 if (col_data && !is_volume)
1618 list_selected = gtk_file_path_copy (col_data);
1621 if (impl->save_folder_combo &&
1622 gtk_combo_box_get_active_iter (GTK_COMBO_BOX (impl->save_folder_combo),
1625 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model),
1627 SHORTCUTS_COL_DATA, &col_data,
1628 SHORTCUTS_COL_IS_VOLUME, &is_volume,
1631 if (col_data && !is_volume)
1632 combo_selected = gtk_file_path_copy (col_data);
1635 if (impl->num_bookmarks > 0)
1636 shortcuts_remove_rows (impl,
1637 shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR),
1638 impl->num_bookmarks + 1);
1640 bookmarks = gtk_file_system_list_bookmarks (impl->file_system);
1641 impl->num_bookmarks = shortcuts_append_paths (impl, bookmarks);
1642 gtk_file_paths_free (bookmarks);
1644 if (impl->num_bookmarks > 0)
1645 shortcuts_insert_separator (impl, SHORTCUTS_BOOKMARKS_SEPARATOR);
1647 if (impl->shortcuts_filter_model)
1648 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_filter_model));
1652 shortcuts_find_folder (impl, list_selected);
1653 gtk_file_path_free (list_selected);
1660 pos = shortcut_find_position (impl, combo_selected);
1662 gtk_combo_box_set_active (GTK_COMBO_BOX (impl->save_folder_combo),
1664 gtk_file_path_free (combo_selected);
1667 impl->changing_folder = old_changing_folders;
1669 profile_end ("end", NULL);
1672 /* Appends a separator and a row to the shortcuts list for the current folder */
1674 shortcuts_add_current_folder (GtkFileChooserDefault *impl)
1679 g_assert (!impl->shortcuts_current_folder_active);
1683 g_assert (impl->current_folder != NULL);
1685 pos = shortcut_find_position (impl, impl->current_folder);
1688 GtkFileSystemVolume *volume;
1689 GtkFilePath *base_path;
1693 shortcuts_insert_separator (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR);
1697 pos = shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER);
1699 volume = gtk_file_system_get_volume_for_path (impl->file_system, impl->current_folder);
1701 base_path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
1706 strcmp (gtk_file_path_get_string (base_path), gtk_file_path_get_string (impl->current_folder)) == 0)
1708 success = shortcuts_insert_path (impl, pos, TRUE, volume, NULL, NULL, FALSE, NULL);
1713 success = shortcuts_insert_path (impl, pos, FALSE, NULL, impl->current_folder, NULL, FALSE, NULL);
1716 gtk_file_system_volume_free (impl->file_system, volume);
1719 gtk_file_path_free (base_path);
1722 shortcuts_remove_rows (impl, pos - 1, 1); /* remove the separator */
1724 impl->shortcuts_current_folder_active = success;
1727 if (success && impl->save_folder_combo != NULL)
1728 gtk_combo_box_set_active (GTK_COMBO_BOX (impl->save_folder_combo), pos);
1731 /* Updates the current folder row in the shortcuts model */
1733 shortcuts_update_current_folder (GtkFileChooserDefault *impl)
1737 pos = shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR);
1739 if (impl->shortcuts_current_folder_active)
1741 shortcuts_remove_rows (impl, pos, 2);
1742 impl->shortcuts_current_folder_active = FALSE;
1745 shortcuts_add_current_folder (impl);
1748 /* Filter function used for the shortcuts filter model */
1750 shortcuts_filter_cb (GtkTreeModel *model,
1754 GtkFileChooserDefault *impl;
1758 impl = GTK_FILE_CHOOSER_DEFAULT (data);
1760 path = gtk_tree_model_get_path (model, iter);
1764 pos = *gtk_tree_path_get_indices (path);
1765 gtk_tree_path_free (path);
1767 return (pos < shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR));
1770 /* Creates the list model for shortcuts */
1772 shortcuts_model_create (GtkFileChooserDefault *impl)
1774 /* Keep this order in sync with the SHORCUTS_COL_* enum values */
1775 impl->shortcuts_model = gtk_list_store_new (SHORTCUTS_COL_NUM_COLUMNS,
1776 GDK_TYPE_PIXBUF, /* pixbuf */
1777 G_TYPE_STRING, /* name */
1778 G_TYPE_POINTER, /* path or volume */
1779 G_TYPE_BOOLEAN, /* is the previous column a volume? */
1780 G_TYPE_BOOLEAN, /* removable */
1781 G_TYPE_BOOLEAN); /* pixbuf cell visibility */
1783 if (impl->file_system)
1785 shortcuts_append_home (impl);
1786 shortcuts_append_desktop (impl);
1787 shortcuts_add_volumes (impl);
1790 impl->shortcuts_filter_model = shortcuts_model_filter_new (impl,
1791 GTK_TREE_MODEL (impl->shortcuts_model),
1794 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (impl->shortcuts_filter_model),
1795 shortcuts_filter_cb,
1800 /* Callback used when the "New Folder" button is clicked */
1802 new_folder_button_clicked (GtkButton *button,
1803 GtkFileChooserDefault *impl)
1808 if (!impl->browse_files_model)
1809 return; /* FIXME: this sucks. Disable the New Folder button or something. */
1811 /* Prevent button from being clicked twice */
1812 gtk_widget_set_sensitive (impl->browse_new_folder_button, FALSE);
1814 _gtk_file_system_model_add_editable (impl->browse_files_model, &iter);
1816 path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->browse_files_model), &iter);
1817 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (impl->browse_files_tree_view),
1818 path, impl->list_name_column,
1821 g_object_set (impl->list_name_renderer, "editable", TRUE, NULL);
1822 gtk_tree_view_set_cursor (GTK_TREE_VIEW (impl->browse_files_tree_view),
1824 impl->list_name_column,
1827 gtk_tree_path_free (path);
1830 /* Idle handler for creating a new folder after editing its name cell, or for
1831 * canceling the editing.
1834 edited_idle_cb (GtkFileChooserDefault *impl)
1836 GDK_THREADS_ENTER ();
1838 g_source_destroy (impl->edited_idle);
1839 impl->edited_idle = NULL;
1841 _gtk_file_system_model_remove_editable (impl->browse_files_model);
1842 g_object_set (impl->list_name_renderer, "editable", FALSE, NULL);
1844 gtk_widget_set_sensitive (impl->browse_new_folder_button, TRUE);
1846 if (impl->edited_new_text) /* not cancelled? */
1849 GtkFilePath *file_path;
1852 file_path = gtk_file_system_make_path (impl->file_system, impl->current_folder, impl->edited_new_text,
1857 if (gtk_file_system_create_folder (impl->file_system, file_path, &error))
1858 change_folder_and_display_error (impl, file_path);
1860 error_creating_folder_dialog (impl, file_path, error);
1862 gtk_file_path_free (file_path);
1865 error_creating_folder_dialog (impl, file_path, error);
1867 g_free (impl->edited_new_text);
1868 impl->edited_new_text = NULL;
1871 GDK_THREADS_LEAVE ();
1877 queue_edited_idle (GtkFileChooserDefault *impl,
1878 const gchar *new_text)
1880 /* We create the folder in an idle handler so that we don't modify the tree
1884 g_assert (!impl->edited_idle);
1885 g_assert (!impl->edited_new_text);
1887 impl->edited_idle = g_idle_source_new ();
1888 g_source_set_closure (impl->edited_idle,
1889 g_cclosure_new_object (G_CALLBACK (edited_idle_cb),
1891 g_source_attach (impl->edited_idle, NULL);
1894 impl->edited_new_text = g_strdup (new_text);
1897 /* Callback used from the text cell renderer when the new folder is named */
1899 renderer_edited_cb (GtkCellRendererText *cell_renderer_text,
1901 const gchar *new_text,
1902 GtkFileChooserDefault *impl)
1904 /* work around bug #154921 */
1905 g_object_set (cell_renderer_text,
1906 "mode", GTK_CELL_RENDERER_MODE_INERT, NULL);
1907 queue_edited_idle (impl, new_text);
1910 /* Callback used from the text cell renderer when the new folder edition gets
1914 renderer_editing_canceled_cb (GtkCellRendererText *cell_renderer_text,
1915 GtkFileChooserDefault *impl)
1917 /* work around bug #154921 */
1918 g_object_set (cell_renderer_text,
1919 "mode", GTK_CELL_RENDERER_MODE_INERT, NULL);
1920 queue_edited_idle (impl, NULL);
1923 /* Creates the widgets for the filter combo box */
1925 filter_create (GtkFileChooserDefault *impl)
1927 impl->filter_combo = gtk_combo_box_new_text ();
1928 gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (impl->filter_combo), FALSE);
1930 g_signal_connect (impl->filter_combo, "changed",
1931 G_CALLBACK (filter_combo_changed), impl);
1933 return impl->filter_combo;
1937 button_new (GtkFileChooserDefault *impl,
1939 const char *stock_id,
1947 button = gtk_button_new_with_mnemonic (text);
1948 image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
1949 gtk_button_set_image (GTK_BUTTON (button), image);
1951 gtk_widget_set_sensitive (button, sensitive);
1952 g_signal_connect (button, "clicked", callback, impl);
1955 gtk_widget_show (button);
1960 /* Looks for a path among the shortcuts; returns its index or -1 if it doesn't exist */
1962 shortcut_find_position (GtkFileChooserDefault *impl,
1963 const GtkFilePath *path)
1967 int current_folder_separator_idx;
1969 if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
1972 current_folder_separator_idx = shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR);
1974 for (i = 0; i < current_folder_separator_idx; i++)
1979 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
1980 SHORTCUTS_COL_DATA, &col_data,
1981 SHORTCUTS_COL_IS_VOLUME, &is_volume,
1988 GtkFileSystemVolume *volume;
1989 GtkFilePath *base_path;
1993 base_path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
1995 exists = base_path && strcmp (gtk_file_path_get_string (path),
1996 gtk_file_path_get_string (base_path)) == 0;
2004 GtkFilePath *model_path;
2006 model_path = col_data;
2008 if (model_path && gtk_file_path_compare (model_path, path) == 0)
2013 gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
2019 /* Tries to add a bookmark from a path name */
2021 shortcuts_add_bookmark_from_path (GtkFileChooserDefault *impl,
2022 const GtkFilePath *path,
2027 g_return_val_if_fail (path != NULL, FALSE);
2029 if (shortcut_find_position (impl, path) != -1)
2032 /* FIXME: this check really belongs in gtk_file_system_insert_bookmark. */
2034 if (!check_is_folder (impl->file_system, path, &error))
2036 error_adding_bookmark_dialog (impl, path, error);
2041 if (!gtk_file_system_insert_bookmark (impl->file_system, path, pos, &error))
2043 error_adding_bookmark_dialog (impl, path, error);
2051 add_bookmark_foreach_cb (GtkTreeModel *model,
2056 GtkFileChooserDefault *impl;
2057 GtkFileSystemModel *fs_model;
2058 GtkTreeIter child_iter;
2059 const GtkFilePath *file_path;
2061 impl = (GtkFileChooserDefault *) data;
2063 fs_model = impl->browse_files_model;
2064 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model, &child_iter, iter);
2066 file_path = _gtk_file_system_model_get_path (fs_model, &child_iter);
2067 shortcuts_add_bookmark_from_path (impl, file_path, -1);
2070 /* Adds a bookmark from the currently selected item in the file list */
2072 bookmarks_add_selected_folder (GtkFileChooserDefault *impl)
2074 GtkTreeSelection *selection;
2076 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
2078 if (gtk_tree_selection_count_selected_rows (selection) == 0)
2079 shortcuts_add_bookmark_from_path (impl, impl->current_folder, -1);
2081 gtk_tree_selection_selected_foreach (selection,
2082 add_bookmark_foreach_cb,
2086 /* Callback used when the "Add bookmark" button is clicked */
2088 add_bookmark_button_clicked_cb (GtkButton *button,
2089 GtkFileChooserDefault *impl)
2091 bookmarks_add_selected_folder (impl);
2094 /* Returns TRUE plus an iter in the shortcuts_model if a row is selected;
2095 * returns FALSE if no shortcut is selected.
2098 shortcuts_get_selected (GtkFileChooserDefault *impl,
2101 GtkTreeSelection *selection;
2102 GtkTreeIter parent_iter;
2104 if (!impl->browse_shortcuts_tree_view)
2107 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view));
2109 if (!gtk_tree_selection_get_selected (selection, NULL, &parent_iter))
2112 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (impl->shortcuts_filter_model),
2118 /* Removes the selected bookmarks */
2120 remove_selected_bookmarks (GtkFileChooserDefault *impl)
2128 if (!shortcuts_get_selected (impl, &iter))
2131 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
2132 SHORTCUTS_COL_DATA, &col_data,
2133 SHORTCUTS_COL_REMOVABLE, &removable,
2135 g_assert (col_data != NULL);
2143 if (!gtk_file_system_remove_bookmark (impl->file_system, path, &error))
2144 error_removing_bookmark_dialog (impl, path, error);
2147 /* Callback used when the "Remove bookmark" button is clicked */
2149 remove_bookmark_button_clicked_cb (GtkButton *button,
2150 GtkFileChooserDefault *impl)
2152 remove_selected_bookmarks (impl);
2155 struct selection_check_closure {
2156 GtkFileChooserDefault *impl;
2159 gboolean all_folders;
2162 /* Used from gtk_tree_selection_selected_foreach() */
2164 selection_check_foreach_cb (GtkTreeModel *model,
2169 struct selection_check_closure *closure;
2170 GtkTreeIter child_iter;
2171 const GtkFileInfo *info;
2175 closure->num_selected++;
2177 gtk_tree_model_sort_convert_iter_to_child_iter (closure->impl->sort_model, &child_iter, iter);
2179 info = _gtk_file_system_model_get_info (closure->impl->browse_files_model, &child_iter);
2180 is_folder = info ? gtk_file_info_get_is_folder (info) : FALSE;
2182 closure->all_folders = closure->all_folders && is_folder;
2183 closure->all_files = closure->all_files && !is_folder;
2186 /* Checks whether the selected items in the file list are all files or all folders */
2188 selection_check (GtkFileChooserDefault *impl,
2190 gboolean *all_files,
2191 gboolean *all_folders)
2193 struct selection_check_closure closure;
2194 GtkTreeSelection *selection;
2196 closure.impl = impl;
2197 closure.num_selected = 0;
2198 closure.all_files = TRUE;
2199 closure.all_folders = TRUE;
2201 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
2202 gtk_tree_selection_selected_foreach (selection,
2203 selection_check_foreach_cb,
2206 g_assert (closure.num_selected == 0 || !(closure.all_files && closure.all_folders));
2209 *num_selected = closure.num_selected;
2212 *all_files = closure.all_files;
2215 *all_folders = closure.all_folders;
2218 struct get_selected_path_closure {
2219 GtkFileChooserDefault *impl;
2220 const GtkFilePath *path;
2224 get_selected_path_foreach_cb (GtkTreeModel *model,
2229 struct get_selected_path_closure *closure;
2230 GtkTreeIter child_iter;
2234 gtk_tree_model_sort_convert_iter_to_child_iter (closure->impl->sort_model, &child_iter, iter);
2235 closure->path = _gtk_file_system_model_get_path (closure->impl->browse_files_model, &child_iter);
2238 /* Returns a selected path from the file list */
2239 static const GtkFilePath *
2240 get_selected_path (GtkFileChooserDefault *impl)
2242 struct get_selected_path_closure closure;
2243 GtkTreeSelection *selection;
2245 closure.impl = impl;
2246 closure.path = NULL;
2248 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
2249 gtk_tree_selection_selected_foreach (selection,
2250 get_selected_path_foreach_cb,
2253 return closure.path;
2257 GtkFileChooserDefault *impl;
2259 } UpdateTooltipData;
2262 update_tooltip (GtkTreeModel *model,
2267 UpdateTooltipData *udata = data;
2268 GtkTreeIter child_iter;
2269 const GtkFileInfo *info;
2271 if (udata->tip == NULL)
2273 gtk_tree_model_sort_convert_iter_to_child_iter (udata->impl->sort_model,
2277 info = _gtk_file_system_model_get_info (udata->impl->browse_files_model, &child_iter);
2278 udata->tip = g_strdup_printf (_("Add the folder '%s' to the bookmarks"),
2279 gtk_file_info_get_display_name (info));
2284 /* Sensitize the "add bookmark" button if all the selected items are folders, or
2285 * if there are no selected items *and* the current folder is not in the
2286 * bookmarks list. De-sensitize the button otherwise.
2289 bookmarks_check_add_sensitivity (GtkFileChooserDefault *impl)
2292 gboolean all_folders;
2296 selection_check (impl, &num_selected, NULL, &all_folders);
2298 if (num_selected == 0)
2299 active = (impl->current_folder != NULL) && (shortcut_find_position (impl, impl->current_folder) == -1);
2300 else if (num_selected == 1)
2302 const GtkFilePath *path;
2304 path = get_selected_path (impl);
2305 active = all_folders && (shortcut_find_position (impl, path) == -1);
2308 active = all_folders;
2310 gtk_widget_set_sensitive (impl->browse_shortcuts_add_button, active);
2312 if (impl->browse_files_popup_menu_add_shortcut_item)
2313 gtk_widget_set_sensitive (impl->browse_files_popup_menu_add_shortcut_item,
2314 (num_selected == 0) ? FALSE : active);
2318 if (num_selected == 0)
2319 tip = g_strdup_printf (_("Add the current folder to the bookmarks"));
2320 else if (num_selected > 1)
2321 tip = g_strdup_printf (_("Add the selected folders to the bookmarks"));
2324 GtkTreeSelection *selection;
2325 UpdateTooltipData data;
2327 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
2330 gtk_tree_selection_selected_foreach (selection, update_tooltip, &data);
2334 gtk_tooltips_set_tip (impl->tooltips, impl->browse_shortcuts_add_button, tip, NULL);
2339 /* Sets the sensitivity of the "remove bookmark" button depending on whether a
2340 * bookmark row is selected in the shortcuts tree.
2343 bookmarks_check_remove_sensitivity (GtkFileChooserDefault *impl)
2346 gboolean removable = FALSE;
2349 if (shortcuts_get_selected (impl, &iter))
2350 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
2351 SHORTCUTS_COL_REMOVABLE, &removable,
2352 SHORTCUTS_COL_NAME, &name,
2355 gtk_widget_set_sensitive (impl->browse_shortcuts_remove_button, removable);
2361 tip = g_strdup_printf (_("Remove the bookmark '%s'"), name);
2362 gtk_tooltips_set_tip (impl->tooltips, impl->browse_shortcuts_remove_button,
2371 shortcuts_check_popup_sensitivity (GtkFileChooserDefault *impl)
2374 gboolean removable = FALSE;
2376 if (impl->browse_shortcuts_popup_menu == NULL)
2379 if (shortcuts_get_selected (impl, &iter))
2380 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
2381 SHORTCUTS_COL_REMOVABLE, &removable,
2384 gtk_widget_set_sensitive (impl->browse_shortcuts_popup_menu_remove_item, removable);
2385 gtk_widget_set_sensitive (impl->browse_shortcuts_popup_menu_rename_item, removable);
2388 /* GtkWidget::drag-begin handler for the shortcuts list. */
2390 shortcuts_drag_begin_cb (GtkWidget *widget,
2391 GdkDragContext *context,
2392 GtkFileChooserDefault *impl)
2395 impl->shortcuts_drag_context = g_object_ref (context);
2400 /* Removes the idle handler for outside drags */
2402 shortcuts_cancel_drag_outside_idle (GtkFileChooserDefault *impl)
2404 if (!impl->shortcuts_drag_outside_idle)
2407 g_source_destroy (impl->shortcuts_drag_outside_idle);
2408 impl->shortcuts_drag_outside_idle = NULL;
2412 /* GtkWidget::drag-end handler for the shortcuts list. */
2414 shortcuts_drag_end_cb (GtkWidget *widget,
2415 GdkDragContext *context,
2416 GtkFileChooserDefault *impl)
2419 g_object_unref (impl->shortcuts_drag_context);
2421 shortcuts_cancel_drag_outside_idle (impl);
2423 if (!impl->shortcuts_drag_outside)
2426 gtk_button_clicked (GTK_BUTTON (impl->browse_shortcuts_remove_button));
2428 impl->shortcuts_drag_outside = FALSE;
2432 /* GtkWidget::drag-data-delete handler for the shortcuts list. */
2434 shortcuts_drag_data_delete_cb (GtkWidget *widget,
2435 GdkDragContext *context,
2436 GtkFileChooserDefault *impl)
2438 g_signal_stop_emission_by_name (widget, "drag-data-delete");
2442 /* Creates a suitable drag cursor to indicate that the selected bookmark will be
2446 shortcuts_drag_set_delete_cursor (GtkFileChooserDefault *impl,
2449 GtkTreeView *tree_view;
2452 GdkPixmap *row_pixmap;
2457 tree_view = GTK_TREE_VIEW (impl->browse_shortcuts_tree_view);
2459 /* Find the selected path and get its drag pixmap */
2461 if (!shortcuts_get_selected (impl, &iter))
2462 g_assert_not_reached ();
2464 path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
2466 row_pixmap = gtk_tree_view_create_row_drag_icon (tree_view, path);
2467 gtk_tree_path_free (path);
2476 pixbuf = gtk_widget_render_icon (impl->browse_shortcuts_tree_view,
2482 GdkPixmap *composite;
2483 int row_pixmap_width, row_pixmap_height;
2484 int pixbuf_width, pixbuf_height;
2485 int composite_width, composite_height;
2486 int pixbuf_x, pixbuf_y;
2487 GdkGC *gc, *mask_gc;
2489 GdkBitmap *pixbuf_mask;
2491 /* Create pixmap and mask for composite image */
2493 gdk_drawable_get_size (row_pixmap, &row_pixmap_width, &row_pixmap_height);
2494 pixbuf_width = gdk_pixbuf_get_width (pixbuf);
2495 pixbuf_height = gdk_pixbuf_get_height (pixbuf);
2497 composite_width = MAX (row_pixmap_width, pixbuf_width);
2498 composite_height = MAX (row_pixmap_height, pixbuf_height);
2500 row_pixmap_y = (composite_height - row_pixmap_height) / 2;
2502 if (gtk_widget_get_direction (impl->browse_shortcuts_tree_view) == GTK_TEXT_DIR_RTL)
2505 pixbuf_x = composite_width - pixbuf_width;
2507 pixbuf_y = (composite_height - pixbuf_height) / 2;
2509 composite = gdk_pixmap_new (row_pixmap, composite_width, composite_height, -1);
2510 gc = gdk_gc_new (composite);
2512 mask = gdk_pixmap_new (row_pixmap, composite_width, composite_height, 1);
2513 mask_gc = gdk_gc_new (mask);
2515 gdk_gc_set_foreground (mask_gc, &color);
2516 gdk_draw_rectangle (mask, mask_gc, TRUE, 0, 0, composite_width, composite_height);
2519 color.green = 0xffff;
2520 color.blue = 0xffff;
2521 gdk_gc_set_rgb_fg_color (gc, &color);
2522 gdk_draw_rectangle (composite, gc, TRUE, 0, 0, composite_width, composite_height);
2524 /* Composite the row pixmap and the pixbuf */
2526 gdk_pixbuf_render_pixmap_and_mask_for_colormap
2528 gtk_widget_get_colormap (impl->browse_shortcuts_tree_view),
2529 NULL, &pixbuf_mask, 128);
2530 gdk_draw_drawable (mask, mask_gc, pixbuf_mask,
2533 pixbuf_width, pixbuf_height);
2534 g_object_unref (pixbuf_mask);
2536 gdk_draw_drawable (composite, gc, row_pixmap,
2539 row_pixmap_width, row_pixmap_height);
2541 gdk_gc_set_foreground (mask_gc, &color);
2542 gdk_draw_rectangle (mask, mask_gc, TRUE, 0, row_pixmap_y, row_pixmap_width, row_pixmap_height);
2544 gdk_draw_pixbuf (composite, gc, pixbuf,
2547 pixbuf_width, pixbuf_height,
2551 g_object_unref (pixbuf);
2552 g_object_unref (row_pixmap);
2554 row_pixmap = composite;
2558 /* The hotspot offsets here are copied from gtk_tree_view_drag_begin(), ugh */
2560 gtk_tree_view_get_path_at_pos (tree_view,
2561 tree_view->priv->press_start_x,
2562 tree_view->priv->press_start_y,
2568 gtk_drag_set_icon_pixmap (impl->shortcuts_drag_context,
2569 gdk_drawable_get_colormap (row_pixmap),
2572 tree_view->priv->press_start_x + 1,
2573 row_pixmap_y + cell_y + 1);
2575 g_object_unref (row_pixmap);
2577 g_object_unref (mask);
2580 /* We set the delete cursor and the shortcuts_drag_outside flag in an idle
2581 * handler so that we can tell apart the drag_leave event that comes right
2582 * before a drag_drop, from a normal drag_leave. We don't want to set the
2583 * cursor nor the flag in the latter case.
2586 shortcuts_drag_outside_idle_cb (GtkFileChooserDefault *impl)
2588 GDK_THREADS_ENTER ();
2590 shortcuts_drag_set_delete_cursor (impl, TRUE);
2591 impl->shortcuts_drag_outside = TRUE;
2593 shortcuts_cancel_drag_outside_idle (impl);
2595 GDK_THREADS_LEAVE ();
2601 /* GtkWidget::drag-leave handler for the shortcuts list. We unhighlight the
2605 shortcuts_drag_leave_cb (GtkWidget *widget,
2606 GdkDragContext *context,
2608 GtkFileChooserDefault *impl)
2611 if (gtk_drag_get_source_widget (context) == widget && !impl->shortcuts_drag_outside_idle)
2613 impl->shortcuts_drag_outside_idle = g_idle_source_new ();
2614 g_source_set_closure (impl->shortcuts_drag_outside_idle,
2615 g_cclosure_new_object (G_CALLBACK (shortcuts_drag_outside_idle_cb),
2617 g_source_attach (impl->shortcuts_drag_outside_idle, NULL);
2621 gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view),
2623 GTK_TREE_VIEW_DROP_BEFORE);
2625 g_signal_stop_emission_by_name (widget, "drag-leave");
2628 /* Computes the appropriate row and position for dropping */
2630 shortcuts_compute_drop_position (GtkFileChooserDefault *impl,
2634 GtkTreeViewDropPosition *pos)
2636 GtkTreeView *tree_view;
2637 GtkTreeViewColumn *column;
2641 int bookmarks_index;
2643 tree_view = GTK_TREE_VIEW (impl->browse_shortcuts_tree_view);
2645 bookmarks_index = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS);
2647 if (!gtk_tree_view_get_path_at_pos (tree_view,
2649 y - TREE_VIEW_HEADER_HEIGHT (tree_view),
2655 row = bookmarks_index + impl->num_bookmarks - 1;
2656 *path = gtk_tree_path_new_from_indices (row, -1);
2657 *pos = GTK_TREE_VIEW_DROP_AFTER;
2661 row = *gtk_tree_path_get_indices (*path);
2662 gtk_tree_view_get_background_area (tree_view, *path, column, &cell);
2663 gtk_tree_path_free (*path);
2665 if (row < bookmarks_index)
2667 row = bookmarks_index;
2668 *pos = GTK_TREE_VIEW_DROP_BEFORE;
2670 else if (row > bookmarks_index + impl->num_bookmarks - 1)
2672 row = bookmarks_index + impl->num_bookmarks - 1;
2673 *pos = GTK_TREE_VIEW_DROP_AFTER;
2677 if (cell_y < cell.height / 2)
2678 *pos = GTK_TREE_VIEW_DROP_BEFORE;
2680 *pos = GTK_TREE_VIEW_DROP_AFTER;
2683 *path = gtk_tree_path_new_from_indices (row, -1);
2686 /* GtkWidget::drag-motion handler for the shortcuts list. We basically
2687 * implement the destination side of DnD by hand, due to limitations in
2688 * GtkTreeView's DnD API.
2691 shortcuts_drag_motion_cb (GtkWidget *widget,
2692 GdkDragContext *context,
2696 GtkFileChooserDefault *impl)
2699 GtkTreeViewDropPosition pos;
2700 GdkDragAction action;
2703 if (gtk_drag_get_source_widget (context) == widget)
2705 shortcuts_cancel_drag_outside_idle (impl);
2707 if (impl->shortcuts_drag_outside)
2709 shortcuts_drag_set_delete_cursor (impl, FALSE);
2710 impl->shortcuts_drag_outside = FALSE;
2715 if (context->suggested_action == GDK_ACTION_COPY || (context->actions & GDK_ACTION_COPY) != 0)
2716 action = GDK_ACTION_COPY;
2717 else if (context->suggested_action == GDK_ACTION_MOVE || (context->actions & GDK_ACTION_MOVE) != 0)
2718 action = GDK_ACTION_MOVE;
2725 shortcuts_compute_drop_position (impl, x, y, &path, &pos);
2726 gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), path, pos);
2727 gtk_tree_path_free (path);
2731 g_signal_stop_emission_by_name (widget, "drag-motion");
2735 gdk_drag_status (context, action, time_);
2742 /* GtkWidget::drag-drop handler for the shortcuts list. */
2744 shortcuts_drag_drop_cb (GtkWidget *widget,
2745 GdkDragContext *context,
2749 GtkFileChooserDefault *impl)
2752 shortcuts_cancel_drag_outside_idle (impl);
2755 g_signal_stop_emission_by_name (widget, "drag-drop");
2759 /* Parses a "text/uri-list" string and inserts its URIs as bookmarks */
2761 shortcuts_drop_uris (GtkFileChooserDefault *impl,
2768 uris = g_uri_list_extract_uris (data);
2770 for (i = 0; uris[i]; i++)
2776 path = gtk_file_system_uri_to_path (impl->file_system, uri);
2780 if (shortcuts_add_bookmark_from_path (impl, path, position))
2783 gtk_file_path_free (path);
2789 g_set_error (&error,
2790 GTK_FILE_CHOOSER_ERROR,
2791 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
2792 _("Could not add a bookmark for '%s' "
2793 "because it is an invalid path name."),
2795 error_adding_bookmark_dialog (impl, path, error);
2802 /* Reorders the selected bookmark to the specified position */
2804 shortcuts_reorder (GtkFileChooserDefault *impl,
2812 int bookmarks_index;
2813 const GtkFilePath *file_path;
2814 GtkFilePath *file_path_copy;
2817 /* Get the selected path */
2819 if (!shortcuts_get_selected (impl, &iter))
2820 g_assert_not_reached ();
2822 path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
2823 old_position = *gtk_tree_path_get_indices (path);
2824 gtk_tree_path_free (path);
2826 bookmarks_index = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS);
2827 old_position -= bookmarks_index;
2828 g_assert (old_position >= 0 && old_position < impl->num_bookmarks);
2830 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
2831 SHORTCUTS_COL_DATA, &col_data,
2832 SHORTCUTS_COL_IS_VOLUME, &is_volume,
2834 g_assert (col_data != NULL);
2835 g_assert (!is_volume);
2837 file_path = col_data;
2838 file_path_copy = gtk_file_path_copy (file_path); /* removal below will free file_path, so we need a copy */
2840 /* Remove the path from the old position and insert it in the new one */
2842 if (new_position > old_position)
2845 if (old_position == new_position)
2849 if (gtk_file_system_remove_bookmark (impl->file_system, file_path_copy, &error))
2850 shortcuts_add_bookmark_from_path (impl, file_path_copy, new_position);
2852 error_adding_bookmark_dialog (impl, file_path_copy, error);
2856 gtk_file_path_free (file_path_copy);
2859 /* Callback used when we get the drag data for the bookmarks list. We add the
2860 * received URIs as bookmarks if they are folders.
2863 shortcuts_drag_data_received_cb (GtkWidget *widget,
2864 GdkDragContext *context,
2867 GtkSelectionData *selection_data,
2872 GtkFileChooserDefault *impl;
2873 GtkTreePath *tree_path;
2874 GtkTreeViewDropPosition tree_pos;
2876 int bookmarks_index;
2878 impl = GTK_FILE_CHOOSER_DEFAULT (data);
2880 /* Compute position */
2882 bookmarks_index = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS);
2884 shortcuts_compute_drop_position (impl, x, y, &tree_path, &tree_pos);
2885 position = *gtk_tree_path_get_indices (tree_path);
2886 gtk_tree_path_free (tree_path);
2888 if (tree_pos == GTK_TREE_VIEW_DROP_AFTER)
2891 g_assert (position >= bookmarks_index);
2892 position -= bookmarks_index;
2894 if (selection_data->target == gdk_atom_intern_static_string ("text/uri-list"))
2895 shortcuts_drop_uris (impl, (const char *) selection_data->data, position);
2896 else if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
2897 shortcuts_reorder (impl, position);
2899 g_signal_stop_emission_by_name (widget, "drag-data-received");
2902 /* Callback used when the selection in the shortcuts tree changes */
2904 shortcuts_selection_changed_cb (GtkTreeSelection *selection,
2905 GtkFileChooserDefault *impl)
2907 bookmarks_check_remove_sensitivity (impl);
2908 shortcuts_check_popup_sensitivity (impl);
2912 shortcuts_row_separator_func (GtkTreeModel *model,
2916 gint column = GPOINTER_TO_INT (data);
2919 gtk_tree_model_get (model, iter, column, &text, -1);
2929 /* Since GtkTreeView has a keybinding attached to '/', we need to catch
2930 * keypresses before the TreeView gets them.
2933 tree_view_keybinding_cb (GtkWidget *tree_view,
2935 GtkFileChooserDefault *impl)
2937 if (event->keyval == GDK_slash &&
2938 ! (event->state & (~GDK_SHIFT_MASK & gtk_accelerator_get_default_mod_mask ())))
2940 location_popup_handler (impl, "/");
2947 /* Callback used when the file list's popup menu is detached */
2949 shortcuts_popup_menu_detach_cb (GtkWidget *attach_widget,
2952 GtkFileChooserDefault *impl;
2954 impl = g_object_get_data (G_OBJECT (attach_widget), "GtkFileChooserDefault");
2955 g_assert (GTK_IS_FILE_CHOOSER_DEFAULT (impl));
2957 impl->browse_shortcuts_popup_menu = NULL;
2958 impl->browse_shortcuts_popup_menu_remove_item = NULL;
2959 impl->browse_shortcuts_popup_menu_rename_item = NULL;
2963 remove_shortcut_cb (GtkMenuItem *item,
2964 GtkFileChooserDefault *impl)
2966 remove_selected_bookmarks (impl);
2970 rename_shortcut_cb (GtkMenuItem *item,
2971 GtkFileChooserDefault *impl)
2975 GtkTreeViewColumn *column;
2976 GtkCellRenderer *cell;
2979 if (shortcuts_get_selected (impl, &iter))
2981 path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
2982 column = gtk_tree_view_get_column (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), 0);
2983 renderers = gtk_tree_view_column_get_cell_renderers (column);
2984 cell = g_list_nth_data (renderers, 1);
2985 g_list_free (renderers);
2986 g_object_set (cell, "editable", TRUE, NULL);
2987 gtk_tree_view_set_cursor_on_cell (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view),
2988 path, column, cell, TRUE);
2989 gtk_tree_path_free (path);
2993 /* Constructs the popup menu for the file list if needed */
2995 shortcuts_build_popup_menu (GtkFileChooserDefault *impl)
2999 if (impl->browse_shortcuts_popup_menu)
3002 impl->browse_shortcuts_popup_menu = gtk_menu_new ();
3003 gtk_menu_attach_to_widget (GTK_MENU (impl->browse_shortcuts_popup_menu),
3004 impl->browse_shortcuts_tree_view,
3005 shortcuts_popup_menu_detach_cb);
3007 item = gtk_image_menu_item_new_with_label (_("Remove"));
3008 impl->browse_shortcuts_popup_menu_remove_item = item;
3009 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
3010 gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU));
3011 g_signal_connect (item, "activate",
3012 G_CALLBACK (remove_shortcut_cb), impl);
3013 gtk_widget_show (item);
3014 gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_shortcuts_popup_menu), item);
3016 item = gtk_menu_item_new_with_label (_("Rename..."));
3017 impl->browse_shortcuts_popup_menu_rename_item = item;
3018 g_signal_connect (item, "activate",
3019 G_CALLBACK (rename_shortcut_cb), impl);
3020 gtk_widget_show (item);
3021 gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_shortcuts_popup_menu), item);
3023 shortcuts_check_popup_sensitivity (impl);
3027 shortcuts_update_popup_menu (GtkFileChooserDefault *impl)
3029 shortcuts_build_popup_menu (impl);
3033 popup_position_func (GtkMenu *menu,
3037 gpointer user_data);
3040 shortcuts_popup_menu (GtkFileChooserDefault *impl,
3041 GdkEventButton *event)
3043 shortcuts_update_popup_menu (impl);
3045 gtk_menu_popup (GTK_MENU (impl->browse_shortcuts_popup_menu),
3046 NULL, NULL, NULL, NULL,
3047 event->button, event->time);
3050 gtk_menu_popup (GTK_MENU (impl->browse_shortcuts_popup_menu),
3052 popup_position_func, impl->browse_shortcuts_tree_view,
3053 0, GDK_CURRENT_TIME);
3054 gtk_menu_shell_select_first (GTK_MENU_SHELL (impl->browse_shortcuts_popup_menu),
3059 /* Callback used for the GtkWidget::popup-menu signal of the shortcuts list */
3061 shortcuts_popup_menu_cb (GtkWidget *widget,
3062 GtkFileChooserDefault *impl)
3064 shortcuts_popup_menu (impl, NULL);
3068 /* Callback used when a button is pressed on the shortcuts list.
3069 * We trap button 3 to bring up a popup menu.
3072 shortcuts_button_press_event_cb (GtkWidget *widget,
3073 GdkEventButton *event,
3074 GtkFileChooserDefault *impl)
3076 if (event->button != 3)
3079 shortcuts_popup_menu (impl, event);
3084 shortcuts_edited (GtkCellRenderer *cell,
3087 GtkFileChooserDefault *impl)
3091 GtkFilePath *shortcut;
3093 g_object_set (cell, "editable", FALSE, NULL);
3095 path = gtk_tree_path_new_from_string (path_string);
3096 gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->shortcuts_model), &iter, path);
3097 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
3098 SHORTCUTS_COL_DATA, &shortcut,
3100 gtk_tree_path_free (path);
3102 gtk_file_system_set_bookmark_label (impl->file_system, shortcut, new_text);
3106 shortcuts_editing_canceled (GtkCellRenderer *cell,
3107 GtkFileChooserDefault *impl)
3109 g_object_set (cell, "editable", FALSE, NULL);
3112 /* Creates the widgets for the shortcuts and bookmarks tree */
3114 shortcuts_list_create (GtkFileChooserDefault *impl)
3117 GtkTreeSelection *selection;
3118 GtkTreeViewColumn *column;
3119 GtkCellRenderer *renderer;
3121 /* Scrolled window */
3123 swin = gtk_scrolled_window_new (NULL, NULL);
3124 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin),
3125 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
3126 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swin),
3128 gtk_widget_show (swin);
3132 impl->browse_shortcuts_tree_view = gtk_tree_view_new ();
3133 #ifdef PROFILE_FILE_CHOOSER
3134 g_object_set_data (G_OBJECT (impl->browse_shortcuts_tree_view), "fmq-name", "shortcuts");
3136 g_signal_connect (impl->browse_shortcuts_tree_view, "key-press-event",
3137 G_CALLBACK (tree_view_keybinding_cb), impl);
3138 g_signal_connect (impl->browse_shortcuts_tree_view, "popup-menu",
3139 G_CALLBACK (shortcuts_popup_menu_cb), impl);
3140 g_signal_connect (impl->browse_shortcuts_tree_view, "button-press-event",
3141 G_CALLBACK (shortcuts_button_press_event_cb), impl);
3142 atk_object_set_name (gtk_widget_get_accessible (impl->browse_shortcuts_tree_view), _("Shortcuts"));
3143 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), FALSE);
3145 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), impl->shortcuts_filter_model);
3147 gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view),
3149 shortcuts_source_targets,
3150 num_shortcuts_source_targets,
3153 gtk_drag_dest_set (impl->browse_shortcuts_tree_view,
3154 GTK_DEST_DEFAULT_ALL,
3155 shortcuts_dest_targets,
3156 num_shortcuts_dest_targets,
3157 GDK_ACTION_COPY | GDK_ACTION_MOVE);
3159 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view));
3160 gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
3161 gtk_tree_selection_set_select_function (selection,
3162 shortcuts_select_func,
3165 g_signal_connect (selection, "changed",
3166 G_CALLBACK (shortcuts_selection_changed_cb), impl);
3168 g_signal_connect (impl->browse_shortcuts_tree_view, "row-activated",
3169 G_CALLBACK (shortcuts_row_activated_cb), impl);
3171 g_signal_connect (impl->browse_shortcuts_tree_view, "key-press-event",
3172 G_CALLBACK (shortcuts_key_press_event_cb), impl);
3174 g_signal_connect (impl->browse_shortcuts_tree_view, "drag-begin",
3175 G_CALLBACK (shortcuts_drag_begin_cb), impl);
3176 g_signal_connect (impl->browse_shortcuts_tree_view, "drag-end",
3177 G_CALLBACK (shortcuts_drag_end_cb), impl);
3178 g_signal_connect (impl->browse_shortcuts_tree_view, "drag-data-delete",
3179 G_CALLBACK (shortcuts_drag_data_delete_cb), impl);
3181 g_signal_connect (impl->browse_shortcuts_tree_view, "drag-leave",
3182 G_CALLBACK (shortcuts_drag_leave_cb), impl);
3183 g_signal_connect (impl->browse_shortcuts_tree_view, "drag-motion",
3184 G_CALLBACK (shortcuts_drag_motion_cb), impl);
3185 g_signal_connect (impl->browse_shortcuts_tree_view, "drag-drop",
3186 G_CALLBACK (shortcuts_drag_drop_cb), impl);
3187 g_signal_connect (impl->browse_shortcuts_tree_view, "drag-data-received",
3188 G_CALLBACK (shortcuts_drag_data_received_cb), impl);
3190 gtk_container_add (GTK_CONTAINER (swin), impl->browse_shortcuts_tree_view);
3191 gtk_widget_show (impl->browse_shortcuts_tree_view);
3195 column = gtk_tree_view_column_new ();
3196 gtk_tree_view_column_set_title (column, _("Folder"));
3198 renderer = gtk_cell_renderer_pixbuf_new ();
3199 gtk_tree_view_column_pack_start (column, renderer, FALSE);
3200 gtk_tree_view_column_set_attributes (column, renderer,
3201 "pixbuf", SHORTCUTS_COL_PIXBUF,
3202 "visible", SHORTCUTS_COL_PIXBUF_VISIBLE,
3205 renderer = gtk_cell_renderer_text_new ();
3206 g_signal_connect (renderer, "edited",
3207 G_CALLBACK (shortcuts_edited), impl);
3208 g_signal_connect (renderer, "editing-canceled",
3209 G_CALLBACK (shortcuts_editing_canceled), impl);
3210 gtk_tree_view_column_pack_start (column, renderer, TRUE);
3211 gtk_tree_view_column_set_attributes (column, renderer,
3212 "text", SHORTCUTS_COL_NAME,
3215 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view),
3216 shortcuts_row_separator_func,
3217 GINT_TO_POINTER (SHORTCUTS_COL_NAME),
3220 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), column);
3225 /* Creates the widgets for the shortcuts/bookmarks pane */
3227 shortcuts_pane_create (GtkFileChooserDefault *impl,
3228 GtkSizeGroup *size_group)
3234 vbox = gtk_vbox_new (FALSE, 6);
3235 gtk_widget_show (vbox);
3237 /* Shortcuts tree */
3239 widget = shortcuts_list_create (impl);
3240 gtk_box_pack_start (GTK_BOX (vbox), widget, TRUE, TRUE, 0);
3242 /* Box for buttons */
3244 hbox = gtk_hbox_new (TRUE, 6);
3245 gtk_size_group_add_widget (size_group, hbox);
3246 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
3247 gtk_widget_show (hbox);
3249 /* Add bookmark button */
3251 impl->browse_shortcuts_add_button = button_new (impl,
3256 G_CALLBACK (add_bookmark_button_clicked_cb));
3257 gtk_box_pack_start (GTK_BOX (hbox), impl->browse_shortcuts_add_button, TRUE, TRUE, 0);
3258 gtk_tooltips_set_tip (impl->tooltips, impl->browse_shortcuts_add_button,
3259 _("Add the selected folder to the Bookmarks"), NULL);
3261 /* Remove bookmark button */
3263 impl->browse_shortcuts_remove_button = button_new (impl,
3268 G_CALLBACK (remove_bookmark_button_clicked_cb));
3269 gtk_box_pack_start (GTK_BOX (hbox), impl->browse_shortcuts_remove_button, TRUE, TRUE, 0);
3270 gtk_tooltips_set_tip (impl->tooltips, impl->browse_shortcuts_remove_button,
3271 _("Remove the selected bookmark"), NULL);
3276 /* Handles key press events on the file list, so that we can trap Enter to
3277 * activate the default button on our own. Also, checks to see if '/' has been
3278 * pressed. See comment by tree_view_keybinding_cb() for more details.
3281 trap_activate_cb (GtkWidget *widget,
3285 GtkFileChooserDefault *impl;
3288 impl = (GtkFileChooserDefault *) data;
3290 modifiers = gtk_accelerator_get_default_mod_mask ();
3292 if (event->keyval == GDK_slash &&
3293 ! (event->state & (~GDK_SHIFT_MASK & modifiers)))
3295 location_popup_handler (impl, "/");
3299 if ((event->keyval == GDK_Return
3300 || event->keyval == GDK_ISO_Enter
3301 || event->keyval == GDK_KP_Enter
3302 || event->keyval == GDK_space)
3303 && ((event->state && modifiers) == 0)
3304 && !(impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
3305 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER))
3309 window = get_toplevel (widget);
3311 && widget != window->default_widget
3312 && !(widget == window->focus_widget &&
3313 (!window->default_widget || !GTK_WIDGET_SENSITIVE (window->default_widget))))
3315 gtk_window_activate_default (window);
3323 /* Callback used when the file list's popup menu is detached */
3325 popup_menu_detach_cb (GtkWidget *attach_widget,
3328 GtkFileChooserDefault *impl;
3330 impl = g_object_get_data (G_OBJECT (attach_widget), "GtkFileChooserDefault");
3331 g_assert (GTK_IS_FILE_CHOOSER_DEFAULT (impl));
3333 impl->browse_files_popup_menu = NULL;
3334 impl->browse_files_popup_menu_add_shortcut_item = NULL;
3335 impl->browse_files_popup_menu_hidden_files_item = NULL;
3338 /* Callback used when the "Add to Bookmarks" menu item is activated */
3340 add_to_shortcuts_cb (GtkMenuItem *item,
3341 GtkFileChooserDefault *impl)
3343 bookmarks_add_selected_folder (impl);
3346 /* Callback used when the "Open Location" menu item is activated */
3348 open_location_cb (GtkMenuItem *item,
3349 GtkFileChooserDefault *impl)
3351 location_popup_handler (impl, "");
3354 /* Callback used when the "Show Hidden Files" menu item is toggled */
3356 show_hidden_toggled_cb (GtkCheckMenuItem *item,
3357 GtkFileChooserDefault *impl)
3360 "show-hidden", gtk_check_menu_item_get_active (item),
3364 /* Shows an error dialog about not being able to select a dragged file */
3366 error_selecting_dragged_file_dialog (GtkFileChooserDefault *impl,
3367 const GtkFilePath *path,
3371 _("Could not select file"),
3376 file_list_drag_data_received_cb (GtkWidget *widget,
3377 GdkDragContext *context,
3380 GtkSelectionData *selection_data,
3385 GtkFileChooserDefault *impl;
3386 GtkFileChooser *chooser;
3390 GError *error = NULL;
3393 impl = GTK_FILE_CHOOSER_DEFAULT (data);
3394 chooser = GTK_FILE_CHOOSER (data);
3396 /* Parse the text/uri-list string, navigate to the first one */
3397 uris = g_uri_list_extract_uris ((const char *) selection_data->data);
3401 path = gtk_file_system_uri_to_path (impl->file_system, uri);
3405 if ((impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
3406 impl->action == GTK_FILE_CHOOSER_ACTION_SAVE) &&
3408 check_is_folder (impl->file_system, path, NULL))
3409 change_folder_and_display_error (impl, path);
3412 gtk_file_chooser_default_unselect_all (chooser);
3413 gtk_file_chooser_default_select_path (chooser, path, &error);
3415 error_selecting_dragged_file_dialog (impl, path, error);
3417 browse_files_center_selected_row (impl);
3420 gtk_file_path_free (path);
3424 g_set_error (&error,
3425 GTK_FILE_CHOOSER_ERROR,
3426 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
3427 _("Could not select file '%s' "
3428 "because it is an invalid path name."),
3430 error_selecting_dragged_file_dialog (impl, NULL, error);
3434 if (impl->select_multiple)
3436 for (i = 1; uris[i]; i++)
3439 path = gtk_file_system_uri_to_path (impl->file_system, uri);
3443 gtk_file_chooser_default_select_path (chooser, path, &error);
3445 error_selecting_dragged_file_dialog (impl, path, error);
3447 gtk_file_path_free (path);
3455 g_signal_stop_emission_by_name (widget, "drag-data-received");
3458 /* Don't do anything with the drag_drop signal */
3460 file_list_drag_drop_cb (GtkWidget *widget,
3461 GdkDragContext *context,
3465 GtkFileChooserDefault *impl)
3467 g_signal_stop_emission_by_name (widget, "drag-drop");
3471 /* Disable the normal tree drag motion handler, it makes it look like you're
3472 dropping the dragged item onto a tree item */
3474 file_list_drag_motion_cb (GtkWidget *widget,
3475 GdkDragContext *context,
3479 GtkFileChooserDefault *impl)
3481 g_signal_stop_emission_by_name (widget, "drag-motion");
3485 /* Constructs the popup menu for the file list if needed */
3487 file_list_build_popup_menu (GtkFileChooserDefault *impl)
3491 if (impl->browse_files_popup_menu)
3494 impl->browse_files_popup_menu = gtk_menu_new ();
3495 gtk_menu_attach_to_widget (GTK_MENU (impl->browse_files_popup_menu),
3496 impl->browse_files_tree_view,
3497 popup_menu_detach_cb);
3499 item = gtk_image_menu_item_new_with_mnemonic (_("_Add to Bookmarks"));
3500 impl->browse_files_popup_menu_add_shortcut_item = item;
3501 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
3502 gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
3503 gtk_widget_set_sensitive (item, FALSE);
3504 g_signal_connect (item, "activate",
3505 G_CALLBACK (add_to_shortcuts_cb), impl);
3506 gtk_widget_show (item);
3507 gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
3509 item = gtk_image_menu_item_new_with_mnemonic (_("Open _Location"));
3510 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
3511 gtk_image_new_from_stock (GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU));
3512 g_signal_connect (item, "activate",
3513 G_CALLBACK (open_location_cb), impl);
3514 gtk_widget_show (item);
3515 gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
3517 item = gtk_separator_menu_item_new ();
3518 gtk_widget_show (item);
3519 gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
3521 item = gtk_check_menu_item_new_with_mnemonic (_("Show _Hidden Files"));
3522 impl->browse_files_popup_menu_hidden_files_item = item;
3523 g_signal_connect (item, "toggled",
3524 G_CALLBACK (show_hidden_toggled_cb), impl);
3525 gtk_widget_show (item);
3526 gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
3529 /* Updates the popup menu for the file list, creating it if necessary */
3531 file_list_update_popup_menu (GtkFileChooserDefault *impl)
3533 file_list_build_popup_menu (impl);
3535 /* The sensitivity of the Add to Bookmarks item is set in
3536 * bookmarks_check_add_sensitivity()
3539 g_signal_handlers_block_by_func (impl->browse_files_popup_menu_hidden_files_item,
3540 G_CALLBACK (show_hidden_toggled_cb), impl);
3541 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (impl->browse_files_popup_menu_hidden_files_item),
3543 g_signal_handlers_unblock_by_func (impl->browse_files_popup_menu_hidden_files_item,
3544 G_CALLBACK (show_hidden_toggled_cb), impl);
3548 popup_position_func (GtkMenu *menu,
3554 GtkWidget *widget = GTK_WIDGET (user_data);
3555 GdkScreen *screen = gtk_widget_get_screen (widget);
3558 GdkRectangle monitor;
3560 g_return_if_fail (GTK_WIDGET_REALIZED (widget));
3562 gdk_window_get_origin (widget->window, x, y);
3564 gtk_widget_size_request (GTK_WIDGET (menu), &req);
3566 *x += (widget->allocation.width - req.width) / 2;
3567 *y += (widget->allocation.height - req.height) / 2;
3569 monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
3570 gtk_menu_set_monitor (menu, monitor_num);
3571 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
3573 *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
3574 *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
3580 file_list_popup_menu (GtkFileChooserDefault *impl,
3581 GdkEventButton *event)
3583 file_list_update_popup_menu (impl);
3585 gtk_menu_popup (GTK_MENU (impl->browse_files_popup_menu),
3586 NULL, NULL, NULL, NULL,
3587 event->button, event->time);
3590 gtk_menu_popup (GTK_MENU (impl->browse_files_popup_menu),
3592 popup_position_func, impl->browse_files_tree_view,
3593 0, GDK_CURRENT_TIME);
3594 gtk_menu_shell_select_first (GTK_MENU_SHELL (impl->browse_files_popup_menu),
3600 /* Callback used for the GtkWidget::popup-menu signal of the file list */
3602 list_popup_menu_cb (GtkWidget *widget,
3603 GtkFileChooserDefault *impl)
3605 file_list_popup_menu (impl, NULL);
3609 /* Callback used when a button is pressed on the file list. We trap button 3 to
3610 * bring up a popup menu.
3613 list_button_press_event_cb (GtkWidget *widget,
3614 GdkEventButton *event,
3615 GtkFileChooserDefault *impl)
3617 if (event->button != 3)
3620 file_list_popup_menu (impl, event);
3624 /* Creates the widgets for the file list */
3626 create_file_list (GtkFileChooserDefault *impl)
3629 GtkTreeSelection *selection;
3630 GtkTreeViewColumn *column;
3631 GtkCellRenderer *renderer;
3633 /* Scrolled window */
3635 swin = gtk_scrolled_window_new (NULL, NULL);
3636 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin),
3637 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
3638 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swin),
3641 /* Tree/list view */
3643 impl->browse_files_tree_view = gtk_tree_view_new ();
3644 #ifdef PROFILE_FILE_CHOOSER
3645 g_object_set_data (G_OBJECT (impl->browse_files_tree_view), "fmq-name", "file_list");
3647 g_object_set_data (G_OBJECT (impl->browse_files_tree_view), I_("GtkFileChooserDefault"), impl);
3648 atk_object_set_name (gtk_widget_get_accessible (impl->browse_files_tree_view), _("Files"));
3650 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (impl->browse_files_tree_view), TRUE);
3651 gtk_container_add (GTK_CONTAINER (swin), impl->browse_files_tree_view);
3653 gtk_drag_dest_set (impl->browse_files_tree_view,
3654 GTK_DEST_DEFAULT_ALL,
3655 file_list_dest_targets,
3656 num_file_list_dest_targets,
3657 GDK_ACTION_COPY | GDK_ACTION_MOVE);
3659 g_signal_connect (impl->browse_files_tree_view, "row-activated",
3660 G_CALLBACK (list_row_activated), impl);
3661 g_signal_connect (impl->browse_files_tree_view, "key-press-event",
3662 G_CALLBACK (trap_activate_cb), impl);
3663 g_signal_connect (impl->browse_files_tree_view, "popup-menu",
3664 G_CALLBACK (list_popup_menu_cb), impl);
3665 g_signal_connect (impl->browse_files_tree_view, "button-press-event",
3666 G_CALLBACK (list_button_press_event_cb), impl);
3668 g_signal_connect (impl->browse_files_tree_view, "drag-data-received",
3669 G_CALLBACK (file_list_drag_data_received_cb), impl);
3670 g_signal_connect (impl->browse_files_tree_view, "drag-drop",
3671 G_CALLBACK (file_list_drag_drop_cb), impl);
3672 g_signal_connect (impl->browse_files_tree_view, "drag-motion",
3673 G_CALLBACK (file_list_drag_motion_cb), impl);
3675 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
3676 gtk_tree_selection_set_select_function (selection,
3679 gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (impl->browse_files_tree_view),
3681 file_list_source_targets,
3682 num_file_list_source_targets,
3685 g_signal_connect (selection, "changed",
3686 G_CALLBACK (list_selection_changed), impl);
3688 /* Filename column */
3690 impl->list_name_column = gtk_tree_view_column_new ();
3691 gtk_tree_view_column_set_expand (impl->list_name_column, TRUE);
3692 gtk_tree_view_column_set_resizable (impl->list_name_column, TRUE);
3693 gtk_tree_view_column_set_title (impl->list_name_column, _("Name"));
3694 gtk_tree_view_column_set_sort_column_id (impl->list_name_column, FILE_LIST_COL_NAME);
3696 renderer = gtk_cell_renderer_pixbuf_new ();
3697 gtk_tree_view_column_pack_start (impl->list_name_column, renderer, FALSE);
3698 gtk_tree_view_column_set_cell_data_func (impl->list_name_column, renderer,
3699 list_icon_data_func, impl, NULL);
3701 impl->list_name_renderer = gtk_cell_renderer_text_new ();
3702 g_object_set (impl->list_name_renderer,
3703 "ellipsize", PANGO_ELLIPSIZE_END,
3705 g_signal_connect (impl->list_name_renderer, "edited",
3706 G_CALLBACK (renderer_edited_cb), impl);
3707 g_signal_connect (impl->list_name_renderer, "editing-canceled",
3708 G_CALLBACK (renderer_editing_canceled_cb), impl);
3709 gtk_tree_view_column_pack_start (impl->list_name_column, impl->list_name_renderer, TRUE);
3710 gtk_tree_view_column_set_cell_data_func (impl->list_name_column, impl->list_name_renderer,
3711 list_name_data_func, impl, NULL);
3713 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->browse_files_tree_view), impl->list_name_column);
3717 column = gtk_tree_view_column_new ();
3718 gtk_tree_view_column_set_title (column, _("Size"));
3720 renderer = gtk_cell_renderer_text_new ();
3721 gtk_tree_view_column_pack_start (column, renderer, TRUE);
3722 gtk_tree_view_column_set_cell_data_func (column, renderer,
3723 list_size_data_func, impl, NULL);
3724 gtk_tree_view_column_set_sort_column_id (column, FILE_LIST_COL_SIZE);
3725 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->browse_files_tree_view), column);
3727 /* Modification time column */
3729 column = gtk_tree_view_column_new ();
3730 gtk_tree_view_column_set_resizable (column, TRUE);
3731 gtk_tree_view_column_set_title (column, _("Modified"));
3733 renderer = gtk_cell_renderer_text_new ();
3734 gtk_tree_view_column_pack_start (column, renderer, TRUE);
3735 gtk_tree_view_column_set_cell_data_func (column, renderer,
3736 list_mtime_data_func, impl, NULL);
3737 gtk_tree_view_column_set_sort_column_id (column, FILE_LIST_COL_MTIME);
3738 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->browse_files_tree_view), column);
3739 gtk_widget_show_all (swin);
3745 create_path_bar (GtkFileChooserDefault *impl)
3747 GtkWidget *path_bar;
3749 path_bar = g_object_new (GTK_TYPE_PATH_BAR, NULL);
3750 _gtk_path_bar_set_file_system (GTK_PATH_BAR (path_bar), impl->file_system);
3756 set_filter_tooltip (GtkWidget *widget,
3759 GtkTooltips *tooltips = (GtkTooltips *)data;
3761 if (GTK_IS_BUTTON (widget))
3762 gtk_tooltips_set_tip (tooltips, widget,
3763 _("Select which types of files are shown"),
3768 realize_filter_combo (GtkWidget *combo,
3771 GtkFileChooserDefault *impl = (GtkFileChooserDefault *)data;
3773 gtk_container_forall (GTK_CONTAINER (combo),
3778 /* Creates the widgets for the files/folders pane */
3780 file_pane_create (GtkFileChooserDefault *impl,
3781 GtkSizeGroup *size_group)
3787 vbox = gtk_vbox_new (FALSE, 6);
3788 gtk_widget_show (vbox);
3790 /* The path bar and 'Create Folder' button */
3791 hbox = gtk_hbox_new (FALSE, 12);
3792 gtk_widget_show (hbox);
3793 impl->browse_path_bar = create_path_bar (impl);
3794 g_signal_connect (impl->browse_path_bar, "path-clicked", G_CALLBACK (path_bar_clicked), impl);
3795 gtk_widget_show_all (impl->browse_path_bar);
3796 gtk_box_pack_start (GTK_BOX (hbox), impl->browse_path_bar, TRUE, TRUE, 0);
3799 impl->browse_new_folder_button = gtk_button_new_with_mnemonic (_("Create Fo_lder"));
3800 g_signal_connect (impl->browse_new_folder_button, "clicked",
3801 G_CALLBACK (new_folder_button_clicked), impl);
3802 gtk_box_pack_end (GTK_BOX (hbox), impl->browse_new_folder_button, FALSE, FALSE, 0);
3803 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
3805 /* Box for lists and preview */
3807 hbox = gtk_hbox_new (FALSE, PREVIEW_HBOX_SPACING);
3808 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
3809 gtk_widget_show (hbox);
3813 widget = create_file_list (impl);
3814 gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
3818 impl->preview_box = gtk_vbox_new (FALSE, 12);
3819 gtk_box_pack_start (GTK_BOX (hbox), impl->preview_box, FALSE, FALSE, 0);
3820 /* Don't show preview box initially */
3824 impl->filter_combo_hbox = gtk_hbox_new (FALSE, 12);
3826 widget = filter_create (impl);
3828 g_signal_connect (widget, "realize",
3829 G_CALLBACK (realize_filter_combo), impl);
3831 gtk_widget_show (widget);
3832 gtk_box_pack_end (GTK_BOX (impl->filter_combo_hbox), widget, FALSE, FALSE, 0);
3834 gtk_size_group_add_widget (size_group, impl->filter_combo_hbox);
3835 gtk_box_pack_end (GTK_BOX (vbox), impl->filter_combo_hbox, FALSE, FALSE, 0);
3840 /* Callback used when the "Browse for more folders" expander is toggled */
3842 expander_changed_cb (GtkExpander *expander,
3844 GtkFileChooserDefault *impl)
3846 update_appearance (impl);
3849 /* Callback used when the selection changes in the save folder combo box */
3851 save_folder_combo_changed_cb (GtkComboBox *combo,
3852 GtkFileChooserDefault *impl)
3856 if (impl->changing_folder)
3859 if (gtk_combo_box_get_active_iter (combo, &iter))
3860 shortcuts_activate_iter (impl, &iter);
3863 /* Creates the combo box with the save folders */
3865 save_folder_combo_create (GtkFileChooserDefault *impl)
3868 GtkCellRenderer *cell;
3870 combo = g_object_new (GTK_TYPE_COMBO_BOX,
3871 "model", impl->shortcuts_model,
3872 "focus-on-click", FALSE,
3874 gtk_widget_show (combo);
3876 cell = gtk_cell_renderer_pixbuf_new ();
3877 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, FALSE);
3878 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), cell,
3879 "pixbuf", SHORTCUTS_COL_PIXBUF,
3880 "visible", SHORTCUTS_COL_PIXBUF_VISIBLE,
3881 "sensitive", SHORTCUTS_COL_PIXBUF_VISIBLE,
3884 cell = gtk_cell_renderer_text_new ();
3885 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE);
3886 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), cell,
3887 "text", SHORTCUTS_COL_NAME,
3888 "sensitive", SHORTCUTS_COL_PIXBUF_VISIBLE,
3891 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo),
3892 shortcuts_row_separator_func,
3893 GINT_TO_POINTER (SHORTCUTS_COL_NAME),
3896 g_signal_connect (combo, "changed",
3897 G_CALLBACK (save_folder_combo_changed_cb), impl);
3902 /* Creates the widgets specific to Save mode */
3904 save_widgets_create (GtkFileChooserDefault *impl)
3909 GtkWidget *alignment;
3911 if (impl->save_widgets != NULL)
3914 vbox = gtk_vbox_new (FALSE, 12);
3916 table = gtk_table_new (2, 2, FALSE);
3917 gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
3918 gtk_widget_show (table);
3919 gtk_table_set_row_spacings (GTK_TABLE (table), 12);
3920 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
3924 widget = gtk_label_new_with_mnemonic (_("_Name:"));
3925 gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
3926 gtk_table_attach (GTK_TABLE (table), widget,
3930 gtk_widget_show (widget);
3932 impl->save_file_name_entry = _gtk_file_chooser_entry_new (TRUE);
3933 _gtk_file_chooser_entry_set_file_system (GTK_FILE_CHOOSER_ENTRY (impl->save_file_name_entry),
3935 gtk_entry_set_width_chars (GTK_ENTRY (impl->save_file_name_entry), 45);
3936 gtk_entry_set_activates_default (GTK_ENTRY (impl->save_file_name_entry), TRUE);
3937 gtk_table_attach (GTK_TABLE (table), impl->save_file_name_entry,
3939 GTK_EXPAND | GTK_FILL, 0,
3941 gtk_widget_show (impl->save_file_name_entry);
3942 gtk_label_set_mnemonic_widget (GTK_LABEL (widget), impl->save_file_name_entry);
3945 impl->save_folder_label = gtk_label_new (NULL);
3946 gtk_misc_set_alignment (GTK_MISC (impl->save_folder_label), 0.0, 0.5);
3947 gtk_table_attach (GTK_TABLE (table), impl->save_folder_label,
3951 gtk_widget_show (impl->save_folder_label);
3953 impl->save_folder_combo = save_folder_combo_create (impl);
3954 gtk_table_attach (GTK_TABLE (table), impl->save_folder_combo,
3956 GTK_EXPAND | GTK_FILL, GTK_FILL,
3958 gtk_label_set_mnemonic_widget (GTK_LABEL (impl->save_folder_label), impl->save_folder_combo);
3961 alignment = gtk_alignment_new (0.0, 0.5, 1.0, 1.0);
3962 gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0);
3964 impl->save_expander = gtk_expander_new_with_mnemonic (_("_Browse for other folders"));
3965 gtk_container_add (GTK_CONTAINER (alignment), impl->save_expander);
3966 g_signal_connect (impl->save_expander, "notify::expanded",
3967 G_CALLBACK (expander_changed_cb),
3969 gtk_widget_show_all (alignment);
3971 impl->save_widgets = vbox;
3972 gtk_box_pack_start (GTK_BOX (impl), impl->save_widgets, FALSE, FALSE, 0);
3973 gtk_box_reorder_child (GTK_BOX (impl), impl->save_widgets, 0);
3974 gtk_widget_show (impl->save_widgets);
3977 /* Destroys the widgets specific to Save mode */
3979 save_widgets_destroy (GtkFileChooserDefault *impl)
3981 if (impl->save_widgets == NULL)
3984 gtk_widget_destroy (impl->save_widgets);
3985 impl->save_widgets = NULL;
3986 impl->save_file_name_entry = NULL;
3987 impl->save_folder_label = NULL;
3988 impl->save_folder_combo = NULL;
3989 impl->save_expander = NULL;
3992 /* Creates the main hpaned with the widgets shared by Open and Save mode */
3994 browse_widgets_create (GtkFileChooserDefault *impl)
3999 GtkSizeGroup *size_group;
4001 /* size group is used by the [+][-] buttons and the filter combo */
4002 size_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
4003 vbox = gtk_vbox_new (FALSE, 12);
4006 hpaned = gtk_hpaned_new ();
4007 gtk_widget_show (hpaned);
4008 gtk_paned_set_position (GTK_PANED (hpaned), 200); /* FIXME: this sucks */
4009 gtk_box_pack_start (GTK_BOX (vbox), hpaned, TRUE, TRUE, 0);
4011 widget = shortcuts_pane_create (impl, size_group);
4012 gtk_paned_pack1 (GTK_PANED (hpaned), widget, FALSE, FALSE);
4013 widget = file_pane_create (impl, size_group);
4014 gtk_paned_pack2 (GTK_PANED (hpaned), widget, TRUE, FALSE);
4016 g_object_unref (size_group);
4022 gtk_file_chooser_default_constructor (GType type,
4023 guint n_construct_properties,
4024 GObjectConstructParam *construct_params)
4026 GtkFileChooserDefault *impl;
4029 profile_start ("start", NULL);
4031 object = parent_class->constructor (type,
4032 n_construct_properties,
4034 impl = GTK_FILE_CHOOSER_DEFAULT (object);
4036 g_assert (impl->file_system);
4038 gtk_widget_push_composite_child ();
4040 /* Shortcuts model */
4042 shortcuts_model_create (impl);
4044 /* The browse widgets */
4045 impl->browse_widgets = browse_widgets_create (impl);
4046 gtk_box_pack_start (GTK_BOX (impl), impl->browse_widgets, TRUE, TRUE, 0);
4048 /* Alignment to hold extra widget */
4049 impl->extra_align = gtk_alignment_new (0.0, 0.5, 1.0, 1.0);
4050 gtk_box_pack_start (GTK_BOX (impl), impl->extra_align, FALSE, FALSE, 0);
4052 gtk_widget_pop_composite_child ();
4053 update_appearance (impl);
4055 profile_end ("end", NULL);
4060 /* Sets the extra_widget by packing it in the appropriate place */
4062 set_extra_widget (GtkFileChooserDefault *impl,
4063 GtkWidget *extra_widget)
4067 g_object_ref (extra_widget);
4068 /* FIXME: is this right ? */
4069 gtk_widget_show (extra_widget);
4072 if (impl->extra_widget)
4074 gtk_container_remove (GTK_CONTAINER (impl->extra_align), impl->extra_widget);
4075 g_object_unref (impl->extra_widget);
4078 impl->extra_widget = extra_widget;
4079 if (impl->extra_widget)
4081 gtk_container_add (GTK_CONTAINER (impl->extra_align), impl->extra_widget);
4082 gtk_widget_show (impl->extra_align);
4085 gtk_widget_hide (impl->extra_align);
4089 set_local_only (GtkFileChooserDefault *impl,
4090 gboolean local_only)
4092 if (local_only != impl->local_only)
4094 impl->local_only = local_only;
4096 if (impl->shortcuts_model && impl->file_system)
4098 shortcuts_add_volumes (impl);
4099 shortcuts_add_bookmarks (impl);
4103 !gtk_file_system_path_is_local (impl->file_system, impl->current_folder))
4105 /* If we are pointing to a non-local folder, make an effort to change
4106 * back to a local folder, but it's really up to the app to not cause
4107 * such a situation, so we ignore errors.
4109 const gchar *home = g_get_home_dir ();
4110 GtkFilePath *home_path;
4115 home_path = gtk_file_system_filename_to_path (impl->file_system, home);
4117 _gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (impl), home_path, NULL);
4119 gtk_file_path_free (home_path);
4125 volumes_changed_cb (GtkFileSystem *file_system,
4126 GtkFileChooserDefault *impl)
4128 shortcuts_add_volumes (impl);
4131 /* Callback used when the set of bookmarks changes in the file system */
4133 bookmarks_changed_cb (GtkFileSystem *file_system,
4134 GtkFileChooserDefault *impl)
4136 shortcuts_add_bookmarks (impl);
4138 bookmarks_check_add_sensitivity (impl);
4139 bookmarks_check_remove_sensitivity (impl);
4140 shortcuts_check_popup_sensitivity (impl);
4143 /* Sets the file chooser to multiple selection mode */
4145 set_select_multiple (GtkFileChooserDefault *impl,
4146 gboolean select_multiple,
4147 gboolean property_notify)
4149 GtkTreeSelection *selection;
4150 GtkSelectionMode mode;
4152 if (select_multiple == impl->select_multiple)
4155 mode = select_multiple ? GTK_SELECTION_MULTIPLE : GTK_SELECTION_BROWSE;
4157 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
4158 gtk_tree_selection_set_mode (selection, mode);
4160 impl->select_multiple = select_multiple;
4161 g_object_notify (G_OBJECT (impl), "select-multiple");
4163 check_preview_change (impl);
4167 set_file_system_backend (GtkFileChooserDefault *impl,
4168 const char *backend)
4170 profile_start ("start for backend", backend ? backend : "default");
4172 if (impl->file_system)
4174 g_signal_handler_disconnect (impl->file_system, impl->volumes_changed_id);
4175 impl->volumes_changed_id = 0;
4176 g_signal_handler_disconnect (impl->file_system, impl->bookmarks_changed_id);
4177 impl->bookmarks_changed_id = 0;
4178 g_object_unref (impl->file_system);
4181 impl->file_system = NULL;
4183 impl->file_system = _gtk_file_system_create (backend);
4186 GtkSettings *settings = gtk_settings_get_default ();
4187 gchar *default_backend = NULL;
4189 g_object_get (settings, "gtk-file-chooser-backend", &default_backend, NULL);
4190 if (default_backend)
4192 impl->file_system = _gtk_file_system_create (default_backend);
4193 g_free (default_backend);
4197 if (!impl->file_system)
4199 #if defined (G_OS_UNIX)
4200 impl->file_system = gtk_file_system_unix_new ();
4201 #elif defined (G_OS_WIN32)
4202 impl->file_system = gtk_file_system_win32_new ();
4204 #error "No default filesystem implementation on the platform"
4208 if (impl->file_system)
4210 impl->volumes_changed_id = g_signal_connect (impl->file_system, "volumes-changed",
4211 G_CALLBACK (volumes_changed_cb),
4213 impl->bookmarks_changed_id = g_signal_connect (impl->file_system, "bookmarks-changed",
4214 G_CALLBACK (bookmarks_changed_cb),
4218 profile_end ("end", NULL);
4221 /* This function is basically a do_all function.
4223 * It sets the visibility on all the widgets based on the current state, and
4224 * moves the custom_widget if needed.
4227 update_appearance (GtkFileChooserDefault *impl)
4229 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
4230 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
4234 save_widgets_create (impl);
4236 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
4237 text = _("Save in _folder:");
4239 text = _("Create in _folder:");
4241 gtk_label_set_text_with_mnemonic (GTK_LABEL (impl->save_folder_label), text);
4243 _gtk_file_chooser_entry_set_action (GTK_FILE_CHOOSER_ENTRY (impl->save_file_name_entry), impl->action);
4245 if (gtk_expander_get_expanded (GTK_EXPANDER (impl->save_expander)))
4247 gtk_widget_set_sensitive (impl->save_folder_label, FALSE);
4248 gtk_widget_set_sensitive (impl->save_folder_combo, FALSE);
4249 gtk_widget_show (impl->browse_widgets);
4253 gtk_widget_set_sensitive (impl->save_folder_label, TRUE);
4254 gtk_widget_set_sensitive (impl->save_folder_combo, TRUE);
4255 gtk_widget_hide (impl->browse_widgets);
4258 gtk_widget_show (impl->browse_new_folder_button);
4260 if (impl->select_multiple)
4262 g_warning ("Save mode cannot be set in conjunction with multiple selection mode. "
4263 "Re-setting to single selection mode.");
4264 set_select_multiple (impl, FALSE, TRUE);
4267 else if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
4268 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
4270 save_widgets_destroy (impl);
4271 gtk_widget_show (impl->browse_widgets);
4274 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
4275 gtk_widget_hide (impl->browse_new_folder_button);
4277 gtk_widget_show (impl->browse_new_folder_button);
4279 /* This *is* needed; we need to redraw the file list because the "sensitivity"
4280 * of files may change depending whether we are in a file or folder-only mode.
4282 gtk_widget_queue_draw (impl->browse_files_tree_view);
4284 g_signal_emit_by_name (impl, "default-size-changed");
4288 gtk_file_chooser_default_set_property (GObject *object,
4290 const GValue *value,
4294 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (object);
4298 case GTK_FILE_CHOOSER_PROP_ACTION:
4300 GtkFileChooserAction action = g_value_get_enum (value);
4302 if (action != impl->action)
4304 gtk_file_chooser_default_unselect_all (GTK_FILE_CHOOSER (impl));
4306 if ((action == GTK_FILE_CHOOSER_ACTION_SAVE || action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
4307 && impl->select_multiple)
4309 g_warning ("Tried to change the file chooser action to SAVE or CREATE_FOLDER, but "
4310 "this is not allowed in multiple selection mode. Resetting the file chooser "
4311 "to single selection mode.");
4312 set_select_multiple (impl, FALSE, TRUE);
4314 impl->action = action;
4315 update_appearance (impl);
4320 case GTK_FILE_CHOOSER_PROP_FILE_SYSTEM_BACKEND:
4321 set_file_system_backend (impl, g_value_get_string (value));
4324 case GTK_FILE_CHOOSER_PROP_FILTER:
4325 set_current_filter (impl, g_value_get_object (value));
4328 case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
4329 set_local_only (impl, g_value_get_boolean (value));
4332 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
4333 set_preview_widget (impl, g_value_get_object (value));
4336 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE:
4337 impl->preview_widget_active = g_value_get_boolean (value);
4338 update_preview_widget_visibility (impl);
4341 case GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL:
4342 impl->use_preview_label = g_value_get_boolean (value);
4343 update_preview_widget_visibility (impl);
4346 case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
4347 set_extra_widget (impl, g_value_get_object (value));
4350 case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
4352 gboolean select_multiple = g_value_get_boolean (value);
4353 if ((impl->action == GTK_FILE_CHOOSER_ACTION_SAVE || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
4356 g_warning ("Tried to set the file chooser to multiple selection mode, but this is "
4357 "not allowed in SAVE or CREATE_FOLDER modes. Ignoring the change and "
4358 "leaving the file chooser in single selection mode.");
4362 set_select_multiple (impl, select_multiple, FALSE);
4366 case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN:
4368 gboolean show_hidden = g_value_get_boolean (value);
4369 if (show_hidden != impl->show_hidden)
4371 impl->show_hidden = show_hidden;
4373 if (impl->browse_files_model)
4374 _gtk_file_system_model_set_show_hidden (impl->browse_files_model, show_hidden);
4379 case GTK_FILE_CHOOSER_PROP_DO_OVERWRITE_CONFIRMATION:
4381 gboolean do_overwrite_confirmation = g_value_get_boolean (value);
4382 impl->do_overwrite_confirmation = do_overwrite_confirmation;
4387 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
4393 gtk_file_chooser_default_get_property (GObject *object,
4398 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (object);
4402 case GTK_FILE_CHOOSER_PROP_ACTION:
4403 g_value_set_enum (value, impl->action);
4406 case GTK_FILE_CHOOSER_PROP_FILTER:
4407 g_value_set_object (value, impl->current_filter);
4410 case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
4411 g_value_set_boolean (value, impl->local_only);
4414 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
4415 g_value_set_object (value, impl->preview_widget);
4418 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE:
4419 g_value_set_boolean (value, impl->preview_widget_active);
4422 case GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL:
4423 g_value_set_boolean (value, impl->use_preview_label);
4426 case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
4427 g_value_set_object (value, impl->extra_widget);
4430 case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
4431 g_value_set_boolean (value, impl->select_multiple);
4434 case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN:
4435 g_value_set_boolean (value, impl->show_hidden);
4438 case GTK_FILE_CHOOSER_PROP_DO_OVERWRITE_CONFIRMATION:
4439 g_value_set_boolean (value, impl->do_overwrite_confirmation);
4443 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
4448 /* Removes the settings signal handler. It's safe to call multiple times */
4450 remove_settings_signal (GtkFileChooserDefault *impl,
4453 if (impl->settings_signal_id)
4455 GtkSettings *settings;
4457 settings = gtk_settings_get_for_screen (screen);
4458 g_signal_handler_disconnect (settings,
4459 impl->settings_signal_id);
4460 impl->settings_signal_id = 0;
4465 gtk_file_chooser_default_dispose (GObject *object)
4467 GtkFileChooserDefault *impl = (GtkFileChooserDefault *) object;
4469 if (impl->extra_widget)
4471 g_object_unref (impl->extra_widget);
4472 impl->extra_widget = NULL;
4475 remove_settings_signal (impl, gtk_widget_get_screen (GTK_WIDGET (impl)));
4477 G_OBJECT_CLASS (parent_class)->dispose (object);
4480 /* We override show-all since we have internal widgets that
4481 * shouldn't be shown when you call show_all(), like the filter
4485 gtk_file_chooser_default_show_all (GtkWidget *widget)
4487 GtkFileChooserDefault *impl = (GtkFileChooserDefault *) widget;
4489 gtk_widget_show (widget);
4491 if (impl->extra_widget)
4492 gtk_widget_show_all (impl->extra_widget);
4495 /* Handler for GtkWindow::set-focus; this is where we save the last-focused
4496 * widget on our toplevel. See gtk_file_chooser_default_hierarchy_changed()
4499 toplevel_set_focus_cb (GtkWindow *window,
4501 GtkFileChooserDefault *impl)
4503 impl->toplevel_last_focus_widget = gtk_window_get_focus (window);
4506 /* We monitor the focus widget on our toplevel to be able to know which widget
4507 * was last focused at the time our "should_respond" method gets called.
4510 gtk_file_chooser_default_hierarchy_changed (GtkWidget *widget,
4511 GtkWidget *previous_toplevel)
4513 GtkFileChooserDefault *impl;
4514 GtkWidget *toplevel;
4516 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
4518 if (previous_toplevel)
4520 g_assert (impl->toplevel_set_focus_id != 0);
4521 g_signal_handler_disconnect (previous_toplevel, impl->toplevel_set_focus_id);
4522 impl->toplevel_set_focus_id = 0;
4523 impl->toplevel_last_focus_widget = NULL;
4526 g_assert (impl->toplevel_set_focus_id == 0);
4528 toplevel = gtk_widget_get_toplevel (widget);
4529 if (GTK_IS_WINDOW (toplevel))
4531 impl->toplevel_set_focus_id = g_signal_connect (toplevel, "set-focus",
4532 G_CALLBACK (toplevel_set_focus_cb), impl);
4533 impl->toplevel_last_focus_widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
4537 /* Changes the icons wherever it is needed */
4539 change_icon_theme (GtkFileChooserDefault *impl)
4541 GtkSettings *settings;
4544 profile_start ("start", NULL);
4546 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl)));
4548 if (gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &width, &height))
4549 impl->icon_size = MAX (width, height);
4551 impl->icon_size = FALLBACK_ICON_SIZE;
4553 shortcuts_reload_icons (impl);
4554 gtk_widget_queue_resize (impl->browse_files_tree_view);
4556 profile_end ("end", NULL);
4559 /* Callback used when a GtkSettings value changes */
4561 settings_notify_cb (GObject *object,
4563 GtkFileChooserDefault *impl)
4567 profile_start ("start", NULL);
4569 name = g_param_spec_get_name (pspec);
4571 if (strcmp (name, "gtk-icon-theme-name") == 0
4572 || strcmp (name, "gtk-icon-sizes") == 0)
4573 change_icon_theme (impl);
4575 profile_end ("end", NULL);
4578 /* Installs a signal handler for GtkSettings so that we can monitor changes in
4582 check_icon_theme (GtkFileChooserDefault *impl)
4584 GtkSettings *settings;
4586 profile_start ("start", NULL);
4588 if (impl->settings_signal_id)
4590 profile_end ("end", NULL);
4594 if (gtk_widget_has_screen (GTK_WIDGET (impl)))
4596 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl)));
4597 impl->settings_signal_id = g_signal_connect (settings, "notify",
4598 G_CALLBACK (settings_notify_cb), impl);
4600 change_icon_theme (impl);
4603 profile_end ("end", NULL);
4607 gtk_file_chooser_default_style_set (GtkWidget *widget,
4608 GtkStyle *previous_style)
4610 GtkFileChooserDefault *impl;
4612 profile_start ("start", NULL);
4614 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
4616 profile_msg (" parent class style_set start", NULL);
4617 if (GTK_WIDGET_CLASS (parent_class)->style_set)
4618 GTK_WIDGET_CLASS (parent_class)->style_set (widget, previous_style);
4619 profile_msg (" parent class style_set end", NULL);
4621 if (gtk_widget_has_screen (GTK_WIDGET (impl)))
4622 change_icon_theme (impl);
4624 profile_msg (" emit default-size-changed start", NULL);
4625 g_signal_emit_by_name (widget, "default-size-changed");
4626 profile_msg (" emit default-size-changed end", NULL);
4628 profile_end ("end", NULL);
4632 gtk_file_chooser_default_screen_changed (GtkWidget *widget,
4633 GdkScreen *previous_screen)
4635 GtkFileChooserDefault *impl;
4637 profile_start ("start", NULL);
4639 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
4641 if (GTK_WIDGET_CLASS (parent_class)->screen_changed)
4642 GTK_WIDGET_CLASS (parent_class)->screen_changed (widget, previous_screen);
4644 remove_settings_signal (impl, previous_screen);
4645 check_icon_theme (impl);
4647 g_signal_emit_by_name (widget, "default-size-changed");
4649 profile_end ("end", NULL);
4653 get_is_file_filtered (GtkFileChooserDefault *impl,
4654 const GtkFilePath *path,
4655 GtkFileInfo *file_info)
4657 GtkFileFilterInfo filter_info;
4658 GtkFileFilterFlags needed;
4661 if (!impl->current_filter)
4664 filter_info.contains = GTK_FILE_FILTER_DISPLAY_NAME | GTK_FILE_FILTER_MIME_TYPE;
4666 needed = gtk_file_filter_get_needed (impl->current_filter);
4668 filter_info.display_name = gtk_file_info_get_display_name (file_info);
4669 filter_info.mime_type = gtk_file_info_get_mime_type (file_info);
4671 if (needed & GTK_FILE_FILTER_FILENAME)
4673 filter_info.filename = gtk_file_system_path_to_filename (impl->file_system, path);
4674 if (filter_info.filename)
4675 filter_info.contains |= GTK_FILE_FILTER_FILENAME;
4678 filter_info.filename = NULL;
4680 if (needed & GTK_FILE_FILTER_URI)
4682 filter_info.uri = gtk_file_system_path_to_uri (impl->file_system, path);
4683 if (filter_info.uri)
4684 filter_info.contains |= GTK_FILE_FILTER_URI;
4687 filter_info.uri = NULL;
4689 result = gtk_file_filter_filter (impl->current_filter, &filter_info);
4691 if (filter_info.filename)
4692 g_free ((gchar *)filter_info.filename);
4693 if (filter_info.uri)
4694 g_free ((gchar *)filter_info.uri);
4699 /* GtkWidget::map method */
4701 gtk_file_chooser_default_map (GtkWidget *widget)
4703 GtkFileChooserDefault *impl;
4704 char *current_working_dir;
4706 profile_start ("start", NULL);
4708 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
4710 GTK_WIDGET_CLASS (parent_class)->map (widget);
4712 switch (impl->reload_state)
4715 /* The user didn't explicitly give us a folder to display, so we'll use the cwd */
4716 current_working_dir = g_get_current_dir ();
4717 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl), current_working_dir);
4718 g_free (current_working_dir);
4721 case RELOAD_HAS_FOLDER:
4722 /* Nothing; we are already loading or loaded, so we don't need to reload */
4725 case RELOAD_WAS_UNMAPPED:
4726 /* Just reload the current folder */
4727 g_assert (impl->current_folder != NULL);
4729 pending_select_paths_store_selection (impl);
4730 change_folder_and_display_error (impl, impl->current_folder);
4734 g_assert_not_reached ();
4737 bookmarks_changed_cb (impl->file_system, impl);
4739 profile_end ("end", NULL);
4742 /* GtkWidget::unmap method */
4744 gtk_file_chooser_default_unmap (GtkWidget *widget)
4746 GtkFileChooserDefault *impl;
4748 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
4750 GTK_WIDGET_CLASS (parent_class)->unmap (widget);
4752 impl->reload_state = RELOAD_WAS_UNMAPPED;
4756 list_model_filter_func (GtkFileSystemModel *model,
4758 const GtkFileInfo *file_info,
4761 GtkFileChooserDefault *impl = user_data;
4763 if (!impl->current_filter)
4766 if (gtk_file_info_get_is_folder (file_info))
4769 return !get_is_file_filtered (impl, path, (GtkFileInfo *) file_info);
4773 install_list_model_filter (GtkFileChooserDefault *impl)
4775 GtkFileSystemModelFilter filter;
4778 g_assert (impl->browse_files_model != NULL);
4780 if (impl->current_filter)
4782 filter = list_model_filter_func;
4791 _gtk_file_system_model_set_filter (impl->browse_files_model,
4796 #define COMPARE_DIRECTORIES \
4797 GtkFileChooserDefault *impl = user_data; \
4798 const GtkFileInfo *info_a = _gtk_file_system_model_get_info (impl->browse_files_model, a); \
4799 const GtkFileInfo *info_b = _gtk_file_system_model_get_info (impl->browse_files_model, b); \
4800 gboolean dir_a, dir_b; \
4803 dir_a = gtk_file_info_get_is_folder (info_a); \
4805 return impl->list_sort_ascending ? -1 : 1; \
4808 dir_b = gtk_file_info_get_is_folder (info_b); \
4810 return impl->list_sort_ascending ? 1 : -1; \
4812 if (dir_a != dir_b) \
4813 return impl->list_sort_ascending ? (dir_a ? -1 : 1) : (dir_a ? 1 : -1) /* Directories *always* go first */
4815 /* Sort callback for the filename column */
4817 name_sort_func (GtkTreeModel *model,
4822 COMPARE_DIRECTORIES;
4824 return strcmp (gtk_file_info_get_display_key (info_a), gtk_file_info_get_display_key (info_b));
4827 /* Sort callback for the size column */
4829 size_sort_func (GtkTreeModel *model,
4834 COMPARE_DIRECTORIES;
4837 gint64 size_a = gtk_file_info_get_size (info_a);
4838 gint64 size_b = gtk_file_info_get_size (info_b);
4840 return size_a > size_b ? -1 : (size_a == size_b ? 0 : 1);
4844 /* Sort callback for the mtime column */
4846 mtime_sort_func (GtkTreeModel *model,
4851 COMPARE_DIRECTORIES;
4854 GtkFileTime ta = gtk_file_info_get_modification_time (info_a);
4855 GtkFileTime tb = gtk_file_info_get_modification_time (info_b);
4857 return ta > tb ? -1 : (ta == tb ? 0 : 1);
4861 /* Callback used when the sort column changes. We cache the sort order for use
4862 * in name_sort_func().
4865 list_sort_column_changed_cb (GtkTreeSortable *sortable,
4866 GtkFileChooserDefault *impl)
4868 GtkSortType sort_type;
4870 if (gtk_tree_sortable_get_sort_column_id (sortable, NULL, &sort_type))
4871 impl->list_sort_ascending = (sort_type == GTK_SORT_ASCENDING);
4875 set_busy_cursor (GtkFileChooserDefault *impl,
4878 GtkWindow *toplevel;
4879 GdkDisplay *display;
4882 toplevel = get_toplevel (GTK_WIDGET (impl));
4883 if (!toplevel || !GTK_WIDGET_REALIZED (toplevel))
4886 display = gtk_widget_get_display (GTK_WIDGET (toplevel));
4889 cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
4893 gdk_window_set_cursor (GTK_WIDGET (toplevel)->window, cursor);
4894 gdk_display_flush (display);
4897 gdk_cursor_unref (cursor);
4900 /* Creates a sort model to wrap the file system model and sets it on the tree view */
4902 load_set_model (GtkFileChooserDefault *impl)
4904 profile_start ("start", NULL);
4906 g_assert (impl->browse_files_model != NULL);
4907 g_assert (impl->sort_model == NULL);
4909 profile_msg (" gtk_tree_model_sort_new_with_model start", NULL);
4910 impl->sort_model = (GtkTreeModelSort *)gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (impl->browse_files_model));
4911 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_NAME, name_sort_func, impl, NULL);
4912 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_SIZE, size_sort_func, impl, NULL);
4913 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_MTIME, mtime_sort_func, impl, NULL);
4914 gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (impl->sort_model), NULL, NULL, NULL);
4915 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_NAME, GTK_SORT_ASCENDING);
4916 impl->list_sort_ascending = TRUE;
4917 profile_msg (" gtk_tree_model_sort_new_with_model end", NULL);
4919 g_signal_connect (impl->sort_model, "sort-column-changed",
4920 G_CALLBACK (list_sort_column_changed_cb), impl);
4922 profile_msg (" gtk_tree_view_set_model start", NULL);
4923 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view),
4924 GTK_TREE_MODEL (impl->sort_model));
4925 gtk_tree_view_columns_autosize (GTK_TREE_VIEW (impl->browse_files_tree_view));
4926 gtk_tree_view_set_search_column (GTK_TREE_VIEW (impl->browse_files_tree_view),
4927 GTK_FILE_SYSTEM_MODEL_DISPLAY_NAME);
4928 profile_msg (" gtk_tree_view_set_model end", NULL);
4930 profile_end ("end", NULL);
4933 /* Timeout callback used when the loading timer expires */
4935 load_timeout_cb (gpointer data)
4937 GtkFileChooserDefault *impl;
4939 profile_start ("start", NULL);
4941 GDK_THREADS_ENTER ();
4943 impl = GTK_FILE_CHOOSER_DEFAULT (data);
4944 g_assert (impl->load_state == LOAD_PRELOAD);
4945 g_assert (impl->load_timeout_id != 0);
4946 g_assert (impl->browse_files_model != NULL);
4948 impl->load_timeout_id = 0;
4949 impl->load_state = LOAD_LOADING;
4951 load_set_model (impl);
4953 GDK_THREADS_LEAVE ();
4955 profile_end ("end", NULL);
4960 /* Sets up a new load timer for the model and switches to the LOAD_LOADING state */
4962 load_setup_timer (GtkFileChooserDefault *impl)
4964 g_assert (impl->load_timeout_id == 0);
4965 g_assert (impl->load_state != LOAD_PRELOAD);
4967 impl->load_timeout_id = g_timeout_add (MAX_LOADING_TIME, load_timeout_cb, impl);
4968 impl->load_state = LOAD_PRELOAD;
4971 /* Removes the load timeout and switches to the LOAD_FINISHED state */
4973 load_remove_timer (GtkFileChooserDefault *impl)
4975 if (impl->load_timeout_id != 0)
4977 g_assert (impl->load_state == LOAD_PRELOAD);
4979 g_source_remove (impl->load_timeout_id);
4980 impl->load_timeout_id = 0;
4981 impl->load_state = LOAD_EMPTY;
4984 g_assert (impl->load_state == LOAD_EMPTY ||
4985 impl->load_state == LOAD_LOADING ||
4986 impl->load_state == LOAD_FINISHED);
4989 /* Selects the first row in the file list */
4991 browse_files_select_first_row (GtkFileChooserDefault *impl)
4995 if (!impl->sort_model)
4998 path = gtk_tree_path_new_from_indices (0, -1);
4999 gtk_tree_view_set_cursor (GTK_TREE_VIEW (impl->browse_files_tree_view), path, NULL, FALSE);
5000 gtk_tree_path_free (path);
5003 struct center_selected_row_closure {
5004 GtkFileChooserDefault *impl;
5005 gboolean already_centered;
5008 /* Callback used from gtk_tree_selection_selected_foreach(); centers the
5009 * selected row in the tree view.
5012 center_selected_row_foreach_cb (GtkTreeModel *model,
5017 struct center_selected_row_closure *closure;
5020 if (closure->already_centered)
5023 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (closure->impl->browse_files_tree_view), path, NULL, TRUE, 0.5, 0.0);
5024 closure->already_centered = TRUE;
5027 /* Centers the selected row in the tree view */
5029 browse_files_center_selected_row (GtkFileChooserDefault *impl)
5031 struct center_selected_row_closure closure;
5032 GtkTreeSelection *selection;
5034 closure.impl = impl;
5035 closure.already_centered = FALSE;
5037 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
5038 gtk_tree_selection_selected_foreach (selection, center_selected_row_foreach_cb, &closure);
5042 show_and_select_paths (GtkFileChooserDefault *impl,
5043 const GtkFilePath *parent_path,
5044 const GtkFilePath *only_one_path,
5048 GtkFileFolder *folder;
5050 gboolean have_hidden;
5051 gboolean have_filtered;
5053 profile_start ("start", NULL);
5055 if (!only_one_path && !paths)
5057 profile_end ("end", NULL);
5061 folder = gtk_file_system_get_folder (impl->file_system, parent_path, GTK_FILE_INFO_IS_HIDDEN, error);
5064 profile_end ("end", NULL);
5069 have_hidden = FALSE;
5070 have_filtered = FALSE;
5076 info = gtk_file_folder_get_info (folder, only_one_path, error);
5080 have_hidden = gtk_file_info_get_is_hidden (info);
5081 have_filtered = get_is_file_filtered (impl, only_one_path, info);
5082 gtk_file_info_free (info);
5089 for (l = paths; l; l = l->next)
5091 const GtkFilePath *path;
5097 info = gtk_file_folder_get_info (folder, path, NULL);
5101 have_hidden = gtk_file_info_get_is_hidden (info);
5104 have_filtered = get_is_file_filtered (impl, path, info);
5106 gtk_file_info_free (info);
5108 if (have_hidden && have_filtered)
5109 break; /* we now have all the information we need */
5116 g_object_unref (folder);
5120 profile_end ("end", NULL);
5125 g_object_set (impl, "show-hidden", TRUE, NULL);
5128 set_current_filter (impl, NULL);
5131 _gtk_file_system_model_path_do (impl->browse_files_model, only_one_path, select_func, impl);
5136 for (l = paths; l; l = l->next)
5138 const GtkFilePath *path;
5141 _gtk_file_system_model_path_do (impl->browse_files_model, path, select_func, impl);
5145 profile_end ("end", NULL);
5149 /* Processes the pending operation when a folder is finished loading */
5151 pending_select_paths_process (GtkFileChooserDefault *impl)
5153 g_assert (impl->load_state == LOAD_FINISHED);
5154 g_assert (impl->browse_files_model != NULL);
5155 g_assert (impl->sort_model != NULL);
5157 if (impl->pending_select_paths)
5160 show_and_select_paths (impl, impl->current_folder, NULL, impl->pending_select_paths, NULL);
5161 pending_select_paths_free (impl);
5162 browse_files_center_selected_row (impl);
5166 /* We only select the first row if the chooser is actually mapped ---
5167 * selecting the first row is to help the user when he is interacting with
5168 * the chooser, but sometimes a chooser works not on behalf of the user,
5169 * but rather on behalf of something else like GtkFileChooserButton. In
5170 * that case, the chooser's selection should be what the caller expects,
5171 * as the user can't see that something else got selected. See bug #165264.
5173 * Also, we don't select the first file if we are not in OPEN mode. Doing
5174 * so would change the contents of the filename entry for SAVE or
5175 * CREATE_FOLDER, which is undesired; in SELECT_FOLDER, we don't want to
5176 * select a *different* folder from the one into which the user just
5179 if (GTK_WIDGET_MAPPED (impl) && impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
5180 browse_files_select_first_row (impl);
5183 g_assert (impl->pending_select_paths == NULL);
5186 /* Callback used when the file system model finishes loading */
5188 browse_files_model_finished_loading_cb (GtkFileSystemModel *model,
5189 GtkFileChooserDefault *impl)
5191 profile_start ("start", NULL);
5193 if (impl->load_state == LOAD_PRELOAD)
5195 load_remove_timer (impl);
5196 load_set_model (impl);
5198 else if (impl->load_state == LOAD_LOADING)
5204 /* We can't g_assert_not_reached(), as something other than us may have
5205 * initiated a folder reload. See #165556.
5207 profile_end ("end", NULL);
5211 g_assert (impl->load_timeout_id == 0);
5213 impl->load_state = LOAD_FINISHED;
5215 pending_select_paths_process (impl);
5216 set_busy_cursor (impl, FALSE);
5217 #ifdef PROFILE_FILE_CHOOSER
5218 access ("MARK: *** FINISHED LOADING", F_OK);
5221 profile_end ("end", NULL);
5224 /* Gets rid of the old list model and creates a new one for the current folder */
5226 set_list_model (GtkFileChooserDefault *impl,
5229 g_assert (impl->current_folder != NULL);
5231 profile_start ("start", NULL);
5233 load_remove_timer (impl); /* This changes the state to LOAD_EMPTY */
5235 if (impl->browse_files_model)
5237 g_object_unref (impl->browse_files_model);
5238 impl->browse_files_model = NULL;
5241 if (impl->sort_model)
5243 g_object_unref (impl->sort_model);
5244 impl->sort_model = NULL;
5247 set_busy_cursor (impl, TRUE);
5248 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), NULL);
5250 impl->browse_files_model = _gtk_file_system_model_new (impl->file_system,
5251 impl->current_folder, 0,
5254 if (!impl->browse_files_model)
5256 set_busy_cursor (impl, FALSE);
5257 profile_end ("end", NULL);
5261 load_setup_timer (impl); /* This changes the state to LOAD_PRELOAD */
5263 g_signal_connect (impl->browse_files_model, "finished-loading",
5264 G_CALLBACK (browse_files_model_finished_loading_cb), impl);
5266 _gtk_file_system_model_set_show_hidden (impl->browse_files_model, impl->show_hidden);
5268 install_list_model_filter (impl);
5270 profile_end ("end", NULL);
5276 update_chooser_entry (GtkFileChooserDefault *impl)
5278 GtkTreeSelection *selection;
5279 const GtkFileInfo *info;
5281 GtkTreeIter child_iter;
5282 gboolean change_entry;
5284 if (!(impl->action == GTK_FILE_CHOOSER_ACTION_SAVE || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER))
5287 g_assert (!impl->select_multiple);
5288 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
5290 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
5292 /* If nothing is selected, we only reset the file name entry if we are in
5293 * CREATE_FOLDER mode. In SAVE mode, nothing will be selected when the
5294 * user starts typeahead in the treeview, and we don't want to clear the
5295 * file name entry in that case --- the user could be typing-ahead to look
5296 * for a folder name. See http://bugzilla.gnome.org/show_bug.cgi?id=308332
5298 if (impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
5299 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->save_file_name_entry), "");
5303 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
5307 info = _gtk_file_system_model_get_info (impl->browse_files_model, &child_iter);
5309 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
5310 change_entry = !gtk_file_info_get_is_folder (info); /* We don't want the name to change when clicking on a folder... */
5312 change_entry = TRUE; /* ... unless we are in CREATE_FOLDER mode */
5315 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->save_file_name_entry),
5316 gtk_file_info_get_display_name (info));
5320 gtk_file_chooser_default_set_current_folder (GtkFileChooser *chooser,
5321 const GtkFilePath *path,
5324 return gtk_file_chooser_default_update_current_folder (chooser, path, FALSE, error);
5328 gtk_file_chooser_default_update_current_folder (GtkFileChooser *chooser,
5329 const GtkFilePath *path,
5330 gboolean keep_trail,
5333 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
5336 profile_start ("start", (char *) path);
5338 g_assert (path != NULL);
5340 if (impl->local_only &&
5341 !gtk_file_system_path_is_local (impl->file_system, path))
5344 GTK_FILE_CHOOSER_ERROR,
5345 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
5346 _("Cannot change to folder because it is not local"));
5348 profile_end ("end - not local", (char *) path);
5352 /* Test validity of path here. */
5353 if (!check_is_folder (impl->file_system, path, error))
5355 profile_end ("end - not a folder", (char *) path);
5359 if (!_gtk_path_bar_set_path (GTK_PATH_BAR (impl->browse_path_bar), path, keep_trail, error))
5361 profile_end ("end - could not set path bar", (char *) path);
5365 if (impl->current_folder != path)
5367 if (impl->current_folder)
5368 gtk_file_path_free (impl->current_folder);
5370 impl->current_folder = gtk_file_path_copy (path);
5372 impl->reload_state = RELOAD_HAS_FOLDER;
5375 /* Update the widgets that may trigger a folder change themselves. */
5377 if (!impl->changing_folder)
5379 impl->changing_folder = TRUE;
5381 shortcuts_update_current_folder (impl);
5383 impl->changing_folder = FALSE;
5386 /* Set the folder on the save entry */
5388 if (impl->save_file_name_entry)
5389 _gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->save_file_name_entry),
5390 impl->current_folder);
5392 /* Create a new list model. This is slightly evil; we store the result value
5393 * but perform more actions rather than returning immediately even if it
5394 * generates an error.
5396 result = set_list_model (impl, error);
5398 /* Refresh controls */
5400 shortcuts_find_current_folder (impl);
5402 g_signal_emit_by_name (impl, "current-folder-changed", 0);
5404 check_preview_change (impl);
5405 bookmarks_check_add_sensitivity (impl);
5407 g_signal_emit_by_name (impl, "selection-changed", 0);
5409 profile_end ("end", NULL);
5413 static GtkFilePath *
5414 gtk_file_chooser_default_get_current_folder (GtkFileChooser *chooser)
5416 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
5418 return gtk_file_path_copy (impl->current_folder);
5422 gtk_file_chooser_default_set_current_name (GtkFileChooser *chooser,
5425 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
5427 g_return_if_fail (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
5428 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER);
5430 pending_select_paths_free (impl);
5431 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->save_file_name_entry), name);
5435 select_func (GtkFileSystemModel *model,
5440 GtkFileChooserDefault *impl = user_data;
5441 GtkTreeSelection *selection;
5442 GtkTreeIter sorted_iter;
5444 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
5446 gtk_tree_model_sort_convert_child_iter_to_iter (impl->sort_model, &sorted_iter, iter);
5447 gtk_tree_selection_select_iter (selection, &sorted_iter);
5451 gtk_file_chooser_default_select_path (GtkFileChooser *chooser,
5452 const GtkFilePath *path,
5455 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
5456 GtkFilePath *parent_path;
5459 if (!gtk_file_system_get_parent (impl->file_system, path, &parent_path, error))
5463 return _gtk_file_chooser_set_current_folder_path (chooser, path, error);
5465 if (impl->load_state == LOAD_EMPTY)
5469 g_assert (impl->current_folder != NULL);
5471 same_path = gtk_file_path_compare (parent_path, impl->current_folder) == 0;
5474 if (same_path && impl->load_state == LOAD_FINISHED)
5478 result = show_and_select_paths (impl, parent_path, path, NULL, error);
5479 gtk_file_path_free (parent_path);
5483 pending_select_paths_add (impl, path);
5489 result = _gtk_file_chooser_set_current_folder_path (chooser, parent_path, error);
5490 gtk_file_path_free (parent_path);
5494 gtk_file_path_free (parent_path);
5499 unselect_func (GtkFileSystemModel *model,
5504 GtkFileChooserDefault *impl = user_data;
5505 GtkTreeView *tree_view = GTK_TREE_VIEW (impl->browse_files_tree_view);
5506 GtkTreePath *sorted_path;
5508 sorted_path = gtk_tree_model_sort_convert_child_path_to_path (impl->sort_model,
5510 gtk_tree_selection_unselect_path (gtk_tree_view_get_selection (tree_view),
5512 gtk_tree_path_free (sorted_path);
5516 gtk_file_chooser_default_unselect_path (GtkFileChooser *chooser,
5517 const GtkFilePath *path)
5519 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
5521 if (!impl->browse_files_model)
5524 _gtk_file_system_model_path_do (impl->browse_files_model, path,
5525 unselect_func, impl);
5529 maybe_select (GtkTreeModel *model,
5534 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (data);
5535 GtkTreeSelection *selection;
5536 const GtkFileInfo *info;
5539 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
5541 info = get_list_file_info (impl, iter);
5542 is_folder = gtk_file_info_get_is_folder (info);
5544 if ((is_folder && impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) ||
5545 (!is_folder && impl->action == GTK_FILE_CHOOSER_ACTION_OPEN))
5546 gtk_tree_selection_select_iter (selection, iter);
5548 gtk_tree_selection_unselect_iter (selection, iter);
5554 gtk_file_chooser_default_select_all (GtkFileChooser *chooser)
5556 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
5557 if (impl->select_multiple)
5558 gtk_tree_model_foreach (GTK_TREE_MODEL (impl->sort_model),
5559 maybe_select, impl);
5563 gtk_file_chooser_default_unselect_all (GtkFileChooser *chooser)
5565 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
5566 GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
5568 gtk_tree_selection_unselect_all (selection);
5569 pending_select_paths_free (impl);
5572 /* Checks whether the filename entry for the Save modes contains a well-formed filename.
5574 * is_well_formed_ret - whether what the user typed passes gkt_file_system_make_path()
5576 * is_empty_ret - whether the file entry is totally empty
5578 * is_file_part_empty_ret - whether the file part is empty (will be if user types "foobar/", and
5579 * the path will be "$cwd/foobar")
5582 check_save_entry (GtkFileChooserDefault *impl,
5583 GtkFilePath **path_ret,
5584 gboolean *is_well_formed_ret,
5585 gboolean *is_empty_ret,
5586 gboolean *is_file_part_empty_ret)
5588 GtkFileChooserEntry *chooser_entry;
5589 const GtkFilePath *current_folder;
5590 const char *file_part;
5594 g_assert (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
5595 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER);
5597 chooser_entry = GTK_FILE_CHOOSER_ENTRY (impl->save_file_name_entry);
5599 if (strlen (gtk_entry_get_text (GTK_ENTRY (chooser_entry))) == 0)
5602 *is_well_formed_ret = TRUE;
5603 *is_empty_ret = TRUE;
5604 *is_file_part_empty_ret = TRUE;
5609 *is_empty_ret = FALSE;
5611 current_folder = _gtk_file_chooser_entry_get_current_folder (chooser_entry);
5612 file_part = _gtk_file_chooser_entry_get_file_part (chooser_entry);
5614 if (!file_part || file_part[0] == '\0')
5616 *path_ret = gtk_file_path_copy (current_folder);
5617 *is_well_formed_ret = TRUE;
5618 *is_file_part_empty_ret = TRUE;
5623 *is_file_part_empty_ret = FALSE;
5626 path = gtk_file_system_make_path (impl->file_system, current_folder, file_part, &error);
5630 error_building_filename_dialog (impl, current_folder, file_part, error);
5632 *is_well_formed_ret = FALSE;
5638 *is_well_formed_ret = TRUE;
5641 struct get_paths_closure {
5642 GtkFileChooserDefault *impl;
5644 GtkFilePath *path_from_entry;
5648 get_paths_foreach (GtkTreeModel *model,
5653 struct get_paths_closure *info;
5654 const GtkFilePath *file_path;
5655 GtkFileSystemModel *fs_model;
5656 GtkTreeIter sel_iter;
5659 fs_model = info->impl->browse_files_model;
5660 gtk_tree_model_sort_convert_iter_to_child_iter (info->impl->sort_model, &sel_iter, iter);
5662 file_path = _gtk_file_system_model_get_path (fs_model, &sel_iter);
5664 return; /* We are on the editable row */
5666 if (!info->path_from_entry
5667 || gtk_file_path_compare (info->path_from_entry, file_path) != 0)
5668 info->result = g_slist_prepend (info->result, gtk_file_path_copy (file_path));
5672 gtk_file_chooser_default_get_paths (GtkFileChooser *chooser)
5674 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
5675 struct get_paths_closure info;
5679 info.path_from_entry = NULL;
5681 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
5682 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
5684 gboolean is_well_formed, is_empty, is_file_part_empty;
5686 check_save_entry (impl, &info.path_from_entry, &is_well_formed, &is_empty, &is_file_part_empty);
5688 if (!is_well_formed)
5693 if (is_file_part_empty && impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
5695 gtk_file_path_free (info.path_from_entry);
5701 if (!info.path_from_entry || impl->select_multiple)
5703 GtkTreeSelection *selection;
5705 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
5706 gtk_tree_selection_selected_foreach (selection, get_paths_foreach, &info);
5709 if (info.path_from_entry)
5710 info.result = g_slist_prepend (info.result, info.path_from_entry);
5712 /* If there's no folder selected, and we're in SELECT_FOLDER mode, then we
5713 * fall back to the current directory */
5714 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER &&
5715 info.result == NULL)
5717 info.result = g_slist_prepend (info.result, gtk_file_path_copy (impl->current_folder));
5720 return g_slist_reverse (info.result);
5723 static GtkFilePath *
5724 gtk_file_chooser_default_get_preview_path (GtkFileChooser *chooser)
5726 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
5728 if (impl->preview_path)
5729 return gtk_file_path_copy (impl->preview_path);
5734 static GtkFileSystem *
5735 gtk_file_chooser_default_get_file_system (GtkFileChooser *chooser)
5737 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
5739 return impl->file_system;
5742 /* Shows or hides the filter widgets */
5744 show_filters (GtkFileChooserDefault *impl,
5748 gtk_widget_show (impl->filter_combo_hbox);
5750 gtk_widget_hide (impl->filter_combo_hbox);
5754 gtk_file_chooser_default_add_filter (GtkFileChooser *chooser,
5755 GtkFileFilter *filter)
5757 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
5760 if (g_slist_find (impl->filters, filter))
5762 g_warning ("gtk_file_chooser_add_filter() called on filter already in list\n");
5766 g_object_ref (filter);
5767 gtk_object_sink (GTK_OBJECT (filter));
5768 impl->filters = g_slist_append (impl->filters, filter);
5770 name = gtk_file_filter_get_name (filter);
5772 name = "Untitled filter"; /* Place-holder, doesn't need to be marked for translation */
5774 gtk_combo_box_append_text (GTK_COMBO_BOX (impl->filter_combo), name);
5776 if (!g_slist_find (impl->filters, impl->current_filter))
5777 set_current_filter (impl, filter);
5779 show_filters (impl, TRUE);
5783 gtk_file_chooser_default_remove_filter (GtkFileChooser *chooser,
5784 GtkFileFilter *filter)
5786 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
5787 GtkTreeModel *model;
5791 filter_index = g_slist_index (impl->filters, filter);
5793 if (filter_index < 0)
5795 g_warning ("gtk_file_chooser_remove_filter() called on filter not in list\n");
5799 impl->filters = g_slist_remove (impl->filters, filter);
5801 if (filter == impl->current_filter)
5804 set_current_filter (impl, impl->filters->data);
5806 set_current_filter (impl, NULL);
5809 /* Remove row from the combo box */
5810 model = gtk_combo_box_get_model (GTK_COMBO_BOX (impl->filter_combo));
5811 gtk_tree_model_iter_nth_child (model, &iter, NULL, filter_index);
5812 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
5814 g_object_unref (filter);
5817 show_filters (impl, FALSE);
5821 gtk_file_chooser_default_list_filters (GtkFileChooser *chooser)
5823 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
5825 return g_slist_copy (impl->filters);
5828 /* Returns the position in the shortcuts tree where the nth specified shortcut would appear */
5830 shortcuts_get_pos_for_shortcut_folder (GtkFileChooserDefault *impl,
5833 return pos + shortcuts_get_index (impl, SHORTCUTS_SHORTCUTS);
5837 gtk_file_chooser_default_add_shortcut_folder (GtkFileChooser *chooser,
5838 const GtkFilePath *path,
5841 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
5845 /* Test validity of path here. */
5846 if (!check_is_folder (impl->file_system, path, error))
5849 pos = shortcuts_get_pos_for_shortcut_folder (impl, impl->num_shortcuts);
5851 result = shortcuts_insert_path (impl, pos, FALSE, NULL, path, NULL, FALSE, error);
5854 impl->num_shortcuts++;
5856 if (impl->shortcuts_filter_model)
5857 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_filter_model));
5863 gtk_file_chooser_default_remove_shortcut_folder (GtkFileChooser *chooser,
5864 const GtkFilePath *path,
5867 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
5873 if (impl->num_shortcuts == 0)
5876 pos = shortcuts_get_pos_for_shortcut_folder (impl, 0);
5877 if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos))
5878 g_assert_not_reached ();
5880 for (i = 0; i < impl->num_shortcuts; i++)
5884 GtkFilePath *shortcut;
5886 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
5887 SHORTCUTS_COL_DATA, &col_data,
5888 SHORTCUTS_COL_IS_VOLUME, &is_volume,
5890 g_assert (col_data != NULL);
5891 g_assert (!is_volume);
5893 shortcut = col_data;
5894 if (gtk_file_path_compare (shortcut, path) == 0)
5896 shortcuts_remove_rows (impl, pos + i, 1);
5897 impl->num_shortcuts--;
5901 if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
5902 g_assert_not_reached ();
5907 uri = gtk_file_system_path_to_uri (impl->file_system, path);
5909 GTK_FILE_CHOOSER_ERROR,
5910 GTK_FILE_CHOOSER_ERROR_NONEXISTENT,
5911 _("Shortcut %s does not exist"),
5919 gtk_file_chooser_default_list_shortcut_folders (GtkFileChooser *chooser)
5921 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
5927 if (impl->num_shortcuts == 0)
5930 pos = shortcuts_get_pos_for_shortcut_folder (impl, 0);
5931 if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos))
5932 g_assert_not_reached ();
5936 for (i = 0; i < impl->num_shortcuts; i++)
5940 GtkFilePath *shortcut;
5942 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
5943 SHORTCUTS_COL_DATA, &col_data,
5944 SHORTCUTS_COL_IS_VOLUME, &is_volume,
5946 g_assert (col_data != NULL);
5947 g_assert (!is_volume);
5949 shortcut = col_data;
5950 list = g_slist_prepend (list, gtk_file_path_copy (shortcut));
5952 if (i != impl->num_shortcuts - 1)
5954 if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
5955 g_assert_not_reached ();
5959 return g_slist_reverse (list);
5962 /* Guesses a size based upon font sizes */
5964 find_good_size_from_style (GtkWidget *widget,
5968 GtkFileChooserDefault *impl;
5969 gint default_width, default_height;
5972 GtkRequisition preview_req;
5974 g_assert (widget->style != NULL);
5975 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
5977 font_size = pango_font_description_get_size (widget->style->font_desc);
5978 font_size = PANGO_PIXELS (font_size);
5980 default_width = font_size * NUM_CHARS;
5981 default_height = font_size * NUM_LINES;
5983 /* Use at least the requisition size not including the preview widget */
5984 gtk_widget_size_request (widget, &req);
5986 if (impl->preview_widget_active && impl->preview_widget)
5987 gtk_widget_size_request (impl->preview_box, &preview_req);
5989 preview_req.width = 0;
5991 default_width = MAX (default_width, (req.width - (preview_req.width + PREVIEW_HBOX_SPACING)));
5992 default_height = MAX (default_height, req.height);
5994 *width = default_width;
5995 *height = default_height;
5999 gtk_file_chooser_default_get_default_size (GtkFileChooserEmbed *chooser_embed,
6000 gint *default_width,
6001 gint *default_height)
6003 GtkFileChooserDefault *impl;
6005 impl = GTK_FILE_CHOOSER_DEFAULT (chooser_embed);
6007 find_good_size_from_style (GTK_WIDGET (chooser_embed), default_width, default_height);
6009 if (impl->preview_widget_active && impl->preview_widget)
6010 *default_width += impl->preview_box->requisition.width + PREVIEW_HBOX_SPACING;
6014 gtk_file_chooser_default_get_resizable_hints (GtkFileChooserEmbed *chooser_embed,
6015 gboolean *resize_horizontally,
6016 gboolean *resize_vertically)
6018 GtkFileChooserDefault *impl;
6020 g_return_if_fail (resize_horizontally != NULL);
6021 g_return_if_fail (resize_vertically != NULL);
6023 impl = GTK_FILE_CHOOSER_DEFAULT (chooser_embed);
6025 *resize_horizontally = TRUE;
6026 *resize_vertically = TRUE;
6028 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
6029 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
6031 if (! gtk_expander_get_expanded (GTK_EXPANDER (impl->save_expander)))
6033 *resize_horizontally = FALSE;
6034 *resize_vertically = FALSE;
6039 struct switch_folder_closure {
6040 GtkFileChooserDefault *impl;
6041 const GtkFilePath *path;
6045 /* Used from gtk_tree_selection_selected_foreach() in switch_to_selected_folder() */
6047 switch_folder_foreach_cb (GtkTreeModel *model,
6052 struct switch_folder_closure *closure;
6053 GtkTreeIter child_iter;
6057 gtk_tree_model_sort_convert_iter_to_child_iter (closure->impl->sort_model, &child_iter, iter);
6059 closure->path = _gtk_file_system_model_get_path (closure->impl->browse_files_model, &child_iter);
6060 closure->num_selected++;
6063 /* Changes to the selected folder in the list view */
6065 switch_to_selected_folder (GtkFileChooserDefault *impl)
6067 GtkTreeSelection *selection;
6068 struct switch_folder_closure closure;
6070 /* We do this with foreach() rather than get_selected() as we may be in
6071 * multiple selection mode
6074 closure.impl = impl;
6075 closure.path = NULL;
6076 closure.num_selected = 0;
6078 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
6079 gtk_tree_selection_selected_foreach (selection, switch_folder_foreach_cb, &closure);
6081 g_assert (closure.path && closure.num_selected == 1);
6083 change_folder_and_display_error (impl, closure.path);
6086 /* Gets the GtkFileInfo for the selected row in the file list; assumes single
6089 static const GtkFileInfo *
6090 get_selected_file_info_from_file_list (GtkFileChooserDefault *impl,
6091 gboolean *had_selection)
6093 GtkTreeSelection *selection;
6094 GtkTreeIter iter, child_iter;
6095 const GtkFileInfo *info;
6097 g_assert (!impl->select_multiple);
6098 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
6099 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
6101 *had_selection = FALSE;
6105 *had_selection = TRUE;
6107 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
6111 info = _gtk_file_system_model_get_info (impl->browse_files_model, &child_iter);
6115 /* Gets the display name of the selected file in the file list; assumes single
6116 * selection mode and that something is selected.
6118 static const gchar *
6119 get_display_name_from_file_list (GtkFileChooserDefault *impl)
6121 const GtkFileInfo *info;
6122 gboolean had_selection;
6124 info = get_selected_file_info_from_file_list (impl, &had_selection);
6125 g_assert (had_selection);
6126 g_assert (info != NULL);
6128 return gtk_file_info_get_display_name (info);
6132 add_custom_button_to_dialog (GtkDialog *dialog,
6133 const gchar *mnemonic_label,
6134 const gchar *stock_id,
6139 button = gtk_button_new_with_mnemonic (mnemonic_label);
6140 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
6141 gtk_button_set_image (GTK_BUTTON (button),
6142 gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON));
6143 gtk_widget_show (button);
6145 gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, response_id);
6148 /* Presents an overwrite confirmation dialog; returns whether we should accept
6152 confirm_dialog_should_accept_filename (GtkFileChooserDefault *impl,
6153 const gchar *file_part,
6154 const gchar *folder_display_name)
6156 GtkWindow *toplevel;
6160 toplevel = get_toplevel (GTK_WIDGET (impl));
6162 dialog = gtk_message_dialog_new (toplevel,
6163 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
6164 GTK_MESSAGE_QUESTION,
6166 _("A file named \"%s\" already exists. Do you want to replace it?"),
6168 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
6169 _("The file already exists in \"%s\". Replacing it will "
6170 "overwrite its contents."),
6171 folder_display_name);
6173 gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
6174 add_custom_button_to_dialog (GTK_DIALOG (dialog), _("_Replace"), GTK_STOCK_SAVE_AS, GTK_RESPONSE_ACCEPT);
6175 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
6177 if (toplevel->group)
6178 gtk_window_group_add_window (toplevel->group, GTK_WINDOW (dialog));
6180 response = gtk_dialog_run (GTK_DIALOG (dialog));
6182 gtk_widget_destroy (dialog);
6184 return (response == GTK_RESPONSE_ACCEPT);
6188 get_display_name_for_folder (GtkFileChooserDefault *impl,
6189 const GtkFilePath *path)
6192 GtkFilePath *parent_path;
6193 GtkFileFolder *parent_folder;
6196 display_name = NULL;
6198 parent_folder = NULL;
6201 if (!gtk_file_system_get_parent (impl->file_system, path, &parent_path, NULL))
6204 parent_folder = gtk_file_system_get_folder (impl->file_system,
6205 parent_path ? parent_path : path,
6206 GTK_FILE_INFO_DISPLAY_NAME,
6211 info = gtk_file_folder_get_info (parent_folder, parent_path ? path : NULL, NULL);
6215 display_name = g_strdup (gtk_file_info_get_display_name (info));
6220 gtk_file_path_free (parent_path);
6223 g_object_unref (parent_folder);
6226 gtk_file_info_free (info);
6228 return display_name;
6231 /* Does overwrite confirmation if appropriate, and returns whether the dialog
6232 * should respond. Can get the file part from the file list or the save entry.
6235 should_respond_after_confirm_overwrite (GtkFileChooserDefault *impl,
6236 const gchar *file_part,
6237 const GtkFilePath *parent_path)
6239 GtkFileChooserConfirmation conf;
6241 if (!impl->do_overwrite_confirmation)
6244 conf = GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM;
6246 g_signal_emit_by_name (impl, "confirm-overwrite", &conf);
6250 case GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM:
6252 char *parent_display_name;
6255 g_assert (file_part != NULL);
6257 parent_display_name = get_display_name_for_folder (impl, parent_path);
6258 if (!parent_display_name)
6259 return TRUE; /* Huh? Did the folder disappear? Let the caller deal with it */
6261 retval = confirm_dialog_should_accept_filename (impl, file_part, parent_display_name);
6262 g_free (parent_display_name);
6266 case GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME:
6269 case GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN:
6273 g_assert_not_reached ();
6278 /* Implementation for GtkFileChooserEmbed::should_respond() */
6280 gtk_file_chooser_default_should_respond (GtkFileChooserEmbed *chooser_embed)
6282 GtkFileChooserDefault *impl;
6283 GtkWidget *toplevel;
6284 GtkWidget *current_focus;
6286 impl = GTK_FILE_CHOOSER_DEFAULT (chooser_embed);
6288 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (impl));
6289 g_assert (GTK_IS_WINDOW (toplevel));
6291 current_focus = gtk_window_get_focus (GTK_WINDOW (toplevel));
6293 if (current_focus == impl->browse_files_tree_view)
6295 /* The following array encodes what we do based on the impl->action and the
6296 * number of files selected.
6299 NOOP, /* Do nothing (don't respond) */
6300 RESPOND, /* Respond immediately */
6301 RESPOND_OR_SWITCH, /* Respond immediately if the selected item is a file; switch to it if it is a folder */
6302 ALL_FILES, /* Respond only if everything selected is a file */
6303 ALL_FOLDERS, /* Respond only if everything selected is a folder */
6304 SAVE_ENTRY, /* Go to the code for handling the save entry */
6305 NOT_REACHED /* Sanity check */
6307 static const ActionToTake what_to_do[4][3] = {
6308 /* 0 selected 1 selected many selected */
6309 /* ACTION_OPEN */ { NOOP, RESPOND_OR_SWITCH, ALL_FILES },
6310 /* ACTION_SAVE */ { SAVE_ENTRY, RESPOND_OR_SWITCH, NOT_REACHED },
6311 /* ACTION_SELECT_FOLDER */ { RESPOND, ALL_FOLDERS, ALL_FOLDERS },
6312 /* ACTION_CREATE_FOLDER */ { SAVE_ENTRY, ALL_FOLDERS, NOT_REACHED }
6316 gboolean all_files, all_folders;
6318 ActionToTake action;
6322 g_assert (impl->action >= GTK_FILE_CHOOSER_ACTION_OPEN && impl->action <= GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER);
6324 selection_check (impl, &num_selected, &all_files, &all_folders);
6326 if (num_selected > 2)
6331 action = what_to_do [impl->action] [k];
6341 case RESPOND_OR_SWITCH:
6342 g_assert (num_selected == 1);
6346 switch_to_selected_folder (impl);
6349 else if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
6350 return should_respond_after_confirm_overwrite (impl,
6351 get_display_name_from_file_list (impl),
6352 impl->current_folder);
6366 g_assert_not_reached ();
6369 else if ((impl->save_file_name_entry != NULL) && (current_focus == impl->save_file_name_entry))
6372 gboolean is_well_formed, is_empty, is_file_part_empty;
6375 GtkFileChooserEntry *entry;
6380 g_assert (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
6381 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER);
6383 entry = GTK_FILE_CHOOSER_ENTRY (impl->save_file_name_entry);
6384 check_save_entry (impl, &path, &is_well_formed, &is_empty, &is_file_part_empty);
6386 if (is_empty || !is_well_formed)
6389 g_assert (path != NULL);
6392 is_folder = check_is_folder (impl->file_system, path, &error);
6395 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
6397 _gtk_file_chooser_entry_set_file_part (entry, "");
6398 change_folder_and_display_error (impl, path);
6401 else /* GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER */
6403 /* The folder already exists, so we do not need to create it.
6404 * Just respond to terminate the dialog.
6411 gboolean file_exists_and_is_not_folder;
6413 file_exists_and_is_not_folder = g_error_matches (error, GTK_FILE_SYSTEM_ERROR, GTK_FILE_SYSTEM_ERROR_NOT_FOLDER);
6415 if (impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER && file_exists_and_is_not_folder)
6417 /* Oops, the user typed the name of an existing path which is not a folder */
6418 error_creating_folder_over_existing_file_dialog (impl, path, error);
6419 error = NULL; /* as it will be freed below for the general case */
6424 GtkFilePath *parent_path;
6425 gboolean parent_is_folder;
6427 /* check that everything up to the last component exists */
6429 parent_path = gtk_file_path_copy (_gtk_file_chooser_entry_get_current_folder (entry));
6430 parent_is_folder = check_is_folder (impl->file_system, parent_path, NULL);
6431 if (parent_is_folder)
6433 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
6435 if (file_exists_and_is_not_folder)
6437 const char *file_part;
6439 file_part = _gtk_file_chooser_entry_get_file_part (GTK_FILE_CHOOSER_ENTRY (impl->save_file_name_entry));
6440 retval = should_respond_after_confirm_overwrite (impl, file_part, parent_path);
6445 else /* GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER */
6447 GError *create_error;
6449 create_error = NULL;
6450 if (gtk_file_system_create_folder (impl->file_system, path, &create_error))
6454 error_creating_folder_dialog (impl, path, create_error);
6461 /* This will display an error, which is what we want */
6462 change_folder_and_display_error (impl, parent_path);
6466 gtk_file_path_free (parent_path);
6470 g_error_free (error);
6473 gtk_file_path_free (path);
6476 else if (impl->toplevel_last_focus_widget == impl->browse_shortcuts_tree_view)
6478 /* The focus is on a dialog's action area button, *and* the widget that
6479 * was focused immediately before it is the shortcuts list. Switch to the
6480 * selected shortcut and tell the caller not to respond.
6484 if (shortcuts_get_selected (impl, &iter))
6486 shortcuts_activate_iter (impl, &iter);
6488 gtk_widget_grab_focus (impl->browse_files_tree_view);
6495 else if (impl->toplevel_last_focus_widget == impl->browse_files_tree_view)
6497 /* The focus is on a dialog's action area button, *and* the widget that
6498 * was focused immediately before it is the file list.
6503 /* The focus is on a dialog's action area button or something else */
6504 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
6505 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
6510 g_assert_not_reached ();
6514 /* Implementation for GtkFileChooserEmbed::initial_focus() */
6516 gtk_file_chooser_default_initial_focus (GtkFileChooserEmbed *chooser_embed)
6518 GtkFileChooserDefault *impl;
6521 impl = GTK_FILE_CHOOSER_DEFAULT (chooser_embed);
6523 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN
6524 || impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
6525 widget = impl->browse_files_tree_view;
6526 else if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
6527 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
6528 widget = impl->save_file_name_entry;
6531 g_assert_not_reached ();
6535 gtk_widget_grab_focus (widget);
6539 set_current_filter (GtkFileChooserDefault *impl,
6540 GtkFileFilter *filter)
6542 if (impl->current_filter != filter)
6546 /* NULL filters are allowed to reset to non-filtered status
6548 filter_index = g_slist_index (impl->filters, filter);
6549 if (impl->filters && filter && filter_index < 0)
6552 if (impl->current_filter)
6553 g_object_unref (impl->current_filter);
6554 impl->current_filter = filter;
6555 if (impl->current_filter)
6557 g_object_ref (impl->current_filter);
6558 gtk_object_sink (GTK_OBJECT (filter));
6562 gtk_combo_box_set_active (GTK_COMBO_BOX (impl->filter_combo),
6565 if (impl->browse_files_model)
6566 install_list_model_filter (impl);
6568 g_object_notify (G_OBJECT (impl), "filter");
6573 filter_combo_changed (GtkComboBox *combo_box,
6574 GtkFileChooserDefault *impl)
6576 gint new_index = gtk_combo_box_get_active (combo_box);
6577 GtkFileFilter *new_filter = g_slist_nth_data (impl->filters, new_index);
6579 set_current_filter (impl, new_filter);
6583 check_preview_change (GtkFileChooserDefault *impl)
6585 GtkTreePath *cursor_path;
6586 const GtkFilePath *new_path;
6587 const GtkFileInfo *new_info;
6589 gtk_tree_view_get_cursor (GTK_TREE_VIEW (impl->browse_files_tree_view), &cursor_path, NULL);
6590 if (cursor_path && impl->sort_model)
6593 GtkTreeIter child_iter;
6595 gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->sort_model), &iter, cursor_path);
6596 gtk_tree_path_free (cursor_path);
6598 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model, &child_iter, &iter);
6600 new_path = _gtk_file_system_model_get_path (impl->browse_files_model, &child_iter);
6601 new_info = _gtk_file_system_model_get_info (impl->browse_files_model, &child_iter);
6609 if (new_path != impl->preview_path &&
6610 !(new_path && impl->preview_path &&
6611 gtk_file_path_compare (new_path, impl->preview_path) == 0))
6613 if (impl->preview_path)
6615 gtk_file_path_free (impl->preview_path);
6616 g_free (impl->preview_display_name);
6621 impl->preview_path = gtk_file_path_copy (new_path);
6622 impl->preview_display_name = g_strdup (gtk_file_info_get_display_name (new_info));
6626 impl->preview_path = NULL;
6627 impl->preview_display_name = NULL;
6630 if (impl->use_preview_label && impl->preview_label)
6631 gtk_label_set_text (GTK_LABEL (impl->preview_label), impl->preview_display_name);
6633 g_signal_emit_by_name (impl, "update-preview");
6637 /* Activates a volume by mounting it if necessary and then switching to its
6641 shortcuts_activate_volume (GtkFileChooserDefault *impl,
6642 GtkFileSystemVolume *volume)
6646 /* We ref the file chooser since volume_mount() may run a main loop, and the
6647 * user could close the file chooser window in the meantime.
6649 g_object_ref (impl);
6651 if (!gtk_file_system_volume_get_is_mounted (impl->file_system, volume))
6656 set_busy_cursor (impl, TRUE);
6659 result = gtk_file_system_volume_mount (impl->file_system, volume, &error);
6665 msg = g_strdup_printf (_("Could not mount %s"),
6666 gtk_file_system_volume_get_display_name (impl->file_system, volume));
6667 error_message (impl, msg, error->message);
6669 g_error_free (error);
6672 set_busy_cursor (impl, FALSE);
6678 path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
6681 change_folder_and_display_error (impl, path);
6682 gtk_file_path_free (path);
6687 g_object_unref (impl);
6690 /* Opens the folder or volume at the specified iter in the shortcuts model */
6692 shortcuts_activate_iter (GtkFileChooserDefault *impl,
6698 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), iter,
6699 SHORTCUTS_COL_DATA, &col_data,
6700 SHORTCUTS_COL_IS_VOLUME, &is_volume,
6704 return; /* We are on a separator */
6708 GtkFileSystemVolume *volume;
6712 shortcuts_activate_volume (impl, volume);
6716 const GtkFilePath *file_path;
6718 file_path = col_data;
6719 change_folder_and_display_error (impl, file_path);
6723 /* Callback used when a row in the shortcuts list is activated */
6725 shortcuts_row_activated_cb (GtkTreeView *tree_view,
6727 GtkTreeViewColumn *column,
6728 GtkFileChooserDefault *impl)
6731 GtkTreeIter child_iter;
6733 if (!gtk_tree_model_get_iter (impl->shortcuts_filter_model, &iter, path))
6736 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (impl->shortcuts_filter_model),
6739 shortcuts_activate_iter (impl, &child_iter);
6741 gtk_widget_grab_focus (impl->browse_files_tree_view);
6744 /* Handler for GtkWidget::key-press-event on the shortcuts list */
6746 shortcuts_key_press_event_cb (GtkWidget *widget,
6748 GtkFileChooserDefault *impl)
6752 modifiers = gtk_accelerator_get_default_mod_mask ();
6754 if ((event->keyval == GDK_BackSpace
6755 || event->keyval == GDK_Delete
6756 || event->keyval == GDK_KP_Delete)
6757 && (event->state & modifiers) == 0)
6759 remove_selected_bookmarks (impl);
6767 shortcuts_select_func (GtkTreeSelection *selection,
6768 GtkTreeModel *model,
6770 gboolean path_currently_selected,
6773 GtkFileChooserDefault *impl = data;
6775 return (*gtk_tree_path_get_indices (path) != shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR));
6779 list_select_func (GtkTreeSelection *selection,
6780 GtkTreeModel *model,
6782 gboolean path_currently_selected,
6785 GtkFileChooserDefault *impl = data;
6787 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
6788 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
6790 GtkTreeIter iter, child_iter;
6791 const GtkFileInfo *info;
6793 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->sort_model), &iter, path))
6796 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model, &child_iter, &iter);
6798 info = _gtk_file_system_model_get_info (impl->browse_files_model, &child_iter);
6800 if (info && !gtk_file_info_get_is_folder (info))
6808 list_selection_changed (GtkTreeSelection *selection,
6809 GtkFileChooserDefault *impl)
6811 /* See if we are in the new folder editable row for Save mode */
6812 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
6814 const GtkFileInfo *info;
6815 gboolean had_selection;
6817 info = get_selected_file_info_from_file_list (impl, &had_selection);
6819 goto out; /* normal processing */
6822 return; /* We are on the editable row for New Folder */
6827 update_chooser_entry (impl);
6828 check_preview_change (impl);
6829 bookmarks_check_add_sensitivity (impl);
6831 g_signal_emit_by_name (impl, "selection-changed", 0);
6834 /* Callback used when a row in the file list is activated */
6836 list_row_activated (GtkTreeView *tree_view,
6838 GtkTreeViewColumn *column,
6839 GtkFileChooserDefault *impl)
6841 GtkTreeIter iter, child_iter;
6842 const GtkFileInfo *info;
6844 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->sort_model), &iter, path))
6847 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model, &child_iter, &iter);
6849 info = _gtk_file_system_model_get_info (impl->browse_files_model, &child_iter);
6851 if (gtk_file_info_get_is_folder (info))
6853 const GtkFilePath *file_path;
6855 file_path = _gtk_file_system_model_get_path (impl->browse_files_model, &child_iter);
6856 change_folder_and_display_error (impl, file_path);
6861 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
6862 impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
6863 g_signal_emit_by_name (impl, "file-activated");
6867 path_bar_clicked (GtkPathBar *path_bar,
6868 GtkFilePath *file_path,
6869 gboolean child_is_hidden,
6870 GtkFileChooserDefault *impl)
6872 if (!change_folder_and_display_error (impl, file_path))
6875 /* Say we have "/foo/bar/[.baz]" and the user clicks on "bar". We should then
6876 * show hidden files so that ".baz" appears in the file list, as it will still
6877 * be shown in the path bar: "/foo/[bar]/.baz"
6879 if (child_is_hidden)
6880 g_object_set (impl, "show-hidden", TRUE, NULL);
6883 static const GtkFileInfo *
6884 get_list_file_info (GtkFileChooserDefault *impl,
6887 GtkTreeIter child_iter;
6889 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
6893 return _gtk_file_system_model_get_info (impl->browse_files_model, &child_iter);
6897 list_icon_data_func (GtkTreeViewColumn *tree_column,
6898 GtkCellRenderer *cell,
6899 GtkTreeModel *tree_model,
6903 GtkFileChooserDefault *impl = data;
6904 GtkTreeIter child_iter;
6905 const GtkFilePath *path;
6907 const GtkFileInfo *info;
6908 gboolean sensitive = TRUE;
6910 profile_start ("start", NULL);
6912 info = get_list_file_info (impl, iter);
6914 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
6917 path = _gtk_file_system_model_get_path (impl->browse_files_model, &child_iter);
6921 /* FIXME: NULL GError */
6922 pixbuf = gtk_file_system_render_icon (impl->file_system, path, GTK_WIDGET (impl),
6923 impl->icon_size, NULL);
6927 /* We are on the editable row */
6931 if (info && (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
6932 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER))
6933 sensitive = gtk_file_info_get_is_folder (info);
6937 "sensitive", sensitive,
6941 g_object_unref (pixbuf);
6943 profile_end ("end", NULL);
6947 list_name_data_func (GtkTreeViewColumn *tree_column,
6948 GtkCellRenderer *cell,
6949 GtkTreeModel *tree_model,
6953 GtkFileChooserDefault *impl = data;
6954 const GtkFileInfo *info = get_list_file_info (impl, iter);
6955 gboolean sensitive = TRUE;
6960 "text", _("Type name of new folder"),
6967 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER
6968 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
6970 sensitive = gtk_file_info_get_is_folder (info);
6974 "text", gtk_file_info_get_display_name (info),
6975 "sensitive", sensitive,
6981 list_size_data_func (GtkTreeViewColumn *tree_column,
6982 GtkCellRenderer *cell,
6983 GtkTreeModel *tree_model,
6987 GtkFileChooserDefault *impl = data;
6988 const GtkFileInfo *info = get_list_file_info (impl, iter);
6991 gboolean sensitive = TRUE;
6993 if (!info || gtk_file_info_get_is_folder (info))
6995 g_object_set (cell,"sensitive", sensitive, NULL);
6999 size = gtk_file_info_get_size (info);
7001 if (size < (gint64)1024)
7002 str = g_strdup_printf (ngettext ("%d byte", "%d bytes", (gint)size), (gint)size);
7003 else if (size < (gint64)1024*1024)
7004 str = g_strdup_printf (_("%.1f K"), size / (1024.));
7005 else if (size < (gint64)1024*1024*1024)
7006 str = g_strdup_printf (_("%.1f M"), size / (1024.*1024.));
7008 str = g_strdup_printf (_("%.1f G"), size / (1024.*1024.*1024.));
7010 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
7011 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
7016 "sensitive", sensitive,
7023 /* Tree column data callback for the file list; fetches the mtime of a file */
7025 list_mtime_data_func (GtkTreeViewColumn *tree_column,
7026 GtkCellRenderer *cell,
7027 GtkTreeModel *tree_model,
7031 GtkFileChooserDefault *impl;
7032 const GtkFileInfo *info;
7033 GtkFileTime time_mtime, time_now;
7037 gboolean sensitive = TRUE;
7041 info = get_list_file_info (impl, iter);
7051 time_mtime = gtk_file_info_get_modification_time (info);
7053 if (time_mtime == 0)
7054 strcpy (buf, _("Unknown"));
7057 g_date_set_time (&mtime, (GTime) time_mtime);
7059 time_now = (GTime ) time (NULL);
7060 g_date_set_time (&now, (GTime) time_now);
7062 days_diff = g_date_get_julian (&now) - g_date_get_julian (&mtime);
7065 strcpy (buf, _("Today"));
7066 else if (days_diff == 1)
7067 strcpy (buf, _("Yesterday"));
7072 if (days_diff > 1 && days_diff < 7)
7073 format = "%A"; /* Days from last week */
7075 format = "%x"; /* Any other date */
7077 if (g_date_strftime (buf, sizeof (buf), format, &mtime) == 0)
7078 strcpy (buf, _("Unknown"));
7082 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
7083 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
7084 sensitive = gtk_file_info_get_is_folder (info);
7088 "sensitive", sensitive,
7093 _gtk_file_chooser_default_new (const char *file_system)
7095 return g_object_new (GTK_TYPE_FILE_CHOOSER_DEFAULT,
7096 "file-system-backend", file_system,
7101 location_entry_create (GtkFileChooserDefault *impl,
7106 entry = _gtk_file_chooser_entry_new (TRUE);
7107 /* Pick a good width for the entry */
7108 gtk_entry_set_width_chars (GTK_ENTRY (entry), 30);
7109 gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
7110 _gtk_file_chooser_entry_set_file_system (GTK_FILE_CHOOSER_ENTRY (entry), impl->file_system);
7111 _gtk_file_chooser_entry_set_action (GTK_FILE_CHOOSER_ENTRY (entry), impl->action);
7114 _gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (entry),
7115 gtk_file_path_new_steal ((gchar *)path));
7116 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (entry), path);
7120 _gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (entry), impl->current_folder);
7121 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN
7122 || impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
7123 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (entry), "");
7124 else if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
7125 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
7126 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (entry),
7127 gtk_entry_get_text (GTK_ENTRY (impl->save_file_name_entry)));
7129 g_assert_not_reached ();
7132 return GTK_WIDGET (entry);
7136 update_from_entry (GtkFileChooserDefault *impl,
7138 GtkFileChooserEntry *chooser_entry)
7140 const GtkFilePath *folder_path;
7141 const char *file_part;
7143 folder_path = _gtk_file_chooser_entry_get_current_folder (chooser_entry);
7144 file_part = _gtk_file_chooser_entry_get_file_part (chooser_entry);
7146 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN && !folder_path)
7148 error_message_with_parent (parent,
7149 _("Cannot change folder"),
7150 _("The folder you specified is an invalid path."));
7154 if (file_part[0] == '\0')
7155 return change_folder_and_display_error (impl, folder_path);
7158 GtkFileFolder *folder = NULL;
7159 GtkFilePath *subfolder_path = NULL;
7160 GtkFileInfo *info = NULL;
7166 /* If the file part is non-empty, we need to figure out if it refers to a
7167 * folder within folder. We could optimize the case here where the folder
7168 * is already loaded for one of our tree models.
7172 folder = gtk_file_system_get_folder (impl->file_system, folder_path, GTK_FILE_INFO_IS_FOLDER, &error);
7176 error_getting_info_dialog (impl, folder_path, error);
7181 subfolder_path = gtk_file_system_make_path (impl->file_system, folder_path, file_part, &error);
7183 if (!subfolder_path)
7188 uri = gtk_file_system_path_to_uri (impl->file_system, folder_path);
7189 msg = g_strdup_printf (_("Could not build file name from '%s' and '%s'"),
7191 error_message (impl, msg, error->message);
7198 info = gtk_file_folder_get_info (folder, subfolder_path, &error);
7202 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
7203 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
7205 if (!change_folder_and_display_error (impl, folder_path))
7208 gtk_file_chooser_default_set_current_name (GTK_FILE_CHOOSER (impl), file_part);
7211 error_getting_info_dialog (impl, subfolder_path, error);
7216 if (gtk_file_info_get_is_folder (info))
7217 result = change_folder_and_display_error (impl, subfolder_path);
7223 result = _gtk_file_chooser_select_path (GTK_FILE_CHOOSER (impl), subfolder_path, &error);
7225 error_dialog (impl, _("Could not select item"),
7226 subfolder_path, error);
7232 g_object_unref (folder);
7234 gtk_file_path_free (subfolder_path);
7237 gtk_file_info_free (info);
7242 g_assert_not_reached ();
7246 location_popup_handler (GtkFileChooserDefault *impl,
7250 GtkWindow *toplevel;
7256 const char *accept_stock;
7260 toplevel = get_toplevel (GTK_WIDGET (impl));
7262 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN
7263 || impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
7265 title = _("Open Location");
7266 accept_stock = GTK_STOCK_OPEN;
7270 g_assert (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
7271 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER);
7272 title = _("Save in Location");
7273 accept_stock = GTK_STOCK_SAVE;
7276 dialog = gtk_dialog_new_with_buttons (title,
7278 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
7279 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
7280 accept_stock, GTK_RESPONSE_ACCEPT,
7282 if (toplevel->group)
7283 gtk_window_group_add_window (toplevel->group, GTK_WINDOW (dialog));
7285 gtk_window_set_default_size (GTK_WINDOW (dialog), 300, -1);
7286 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
7287 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 2);
7288 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
7290 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
7291 GTK_RESPONSE_ACCEPT,
7292 GTK_RESPONSE_CANCEL,
7295 hbox = gtk_hbox_new (FALSE, 12);
7296 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, FALSE, FALSE, 0);
7297 gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
7299 label = gtk_label_new_with_mnemonic (_("_Location:"));
7300 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
7302 entry = location_entry_create (impl, path);
7304 gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
7305 gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
7309 gtk_widget_show_all (dialog);
7310 /* If the dialog is brought up by typing the first characters
7311 * of a path, unselect the text in the entry, so that you can
7312 * just type on without erasing the initial part.
7315 gtk_editable_select_region (GTK_EDITABLE (entry), -1, -1);
7319 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
7321 if (update_from_entry (impl, GTK_WINDOW (dialog), GTK_FILE_CHOOSER_ENTRY (entry)))
7323 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN
7324 || impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
7326 gtk_widget_grab_focus (impl->browse_files_tree_view);
7330 g_assert (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
7331 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER);
7332 gtk_widget_grab_focus (impl->save_file_name_entry);
7340 GtkWindow *toplevel;
7342 toplevel = get_toplevel (GTK_WIDGET (impl));
7343 if (toplevel && toplevel->focus_widget)
7344 gtk_widget_grab_focus (toplevel->focus_widget);
7347 gtk_widget_destroy (dialog);
7350 /* Handler for the "up-folder" keybinding signal */
7352 up_folder_handler (GtkFileChooserDefault *impl)
7354 pending_select_paths_add (impl, impl->current_folder);
7355 _gtk_path_bar_up (GTK_PATH_BAR (impl->browse_path_bar));
7358 /* Handler for the "down-folder" keybinding signal */
7360 down_folder_handler (GtkFileChooserDefault *impl)
7362 _gtk_path_bar_down (GTK_PATH_BAR (impl->browse_path_bar));
7365 /* Switches to the shortcut in the specified index */
7367 switch_to_shortcut (GtkFileChooserDefault *impl,
7372 if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos))
7373 g_assert_not_reached ();
7375 shortcuts_activate_iter (impl, &iter);
7378 /* Handler for the "home-folder" keybinding signal */
7380 home_folder_handler (GtkFileChooserDefault *impl)
7383 switch_to_shortcut (impl, shortcuts_get_index (impl, SHORTCUTS_HOME));
7386 /* Handler for the "desktop-folder" keybinding signal */
7388 desktop_folder_handler (GtkFileChooserDefault *impl)
7390 if (impl->has_desktop)
7391 switch_to_shortcut (impl, shortcuts_get_index (impl, SHORTCUTS_DESKTOP));
7395 quick_bookmark_handler (GtkFileChooserDefault *impl,
7396 gint bookmark_index)
7401 if (bookmark_index < 0 || bookmark_index >= impl->num_bookmarks)
7404 bookmark_pos = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS) + bookmark_index;
7406 path = gtk_tree_path_new_from_indices (bookmark_pos, -1);
7407 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view),
7410 gtk_tree_path_free (path);
7412 switch_to_shortcut (impl, bookmark_pos);
7417 /* Drag and drop interfaces */
7420 _shortcuts_model_filter_class_init (ShortcutsModelFilterClass *class)
7425 _shortcuts_model_filter_init (ShortcutsModelFilter *model)
7430 /* GtkTreeDragSource::row_draggable implementation for the shortcuts filter model */
7432 shortcuts_model_filter_row_draggable (GtkTreeDragSource *drag_source,
7435 ShortcutsModelFilter *model;
7439 model = SHORTCUTS_MODEL_FILTER (drag_source);
7441 pos = *gtk_tree_path_get_indices (path);
7442 bookmarks_pos = shortcuts_get_index (model->impl, SHORTCUTS_BOOKMARKS);
7444 return (pos >= bookmarks_pos && pos < bookmarks_pos + model->impl->num_bookmarks);
7447 /* GtkTreeDragSource::drag_data_get implementation for the shortcuts filter model */
7449 shortcuts_model_filter_drag_data_get (GtkTreeDragSource *drag_source,
7451 GtkSelectionData *selection_data)
7453 ShortcutsModelFilter *model;
7455 model = SHORTCUTS_MODEL_FILTER (drag_source);
7462 /* Fill the GtkTreeDragSourceIface vtable */
7464 shortcuts_model_filter_drag_source_iface_init (GtkTreeDragSourceIface *iface)
7466 iface->row_draggable = shortcuts_model_filter_row_draggable;
7467 iface->drag_data_get = shortcuts_model_filter_drag_data_get;
7471 /* Fill the GtkTreeDragDestIface vtable */
7473 shortcuts_model_filter_drag_dest_iface_init (GtkTreeDragDestIface *iface)
7475 iface->drag_data_received = shortcuts_model_filter_drag_data_received;
7476 iface->row_drop_possible = shortcuts_model_filter_row_drop_possible;
7480 static GtkTreeModel *
7481 shortcuts_model_filter_new (GtkFileChooserDefault *impl,
7482 GtkTreeModel *child_model,
7485 ShortcutsModelFilter *model;
7487 model = g_object_new (SHORTCUTS_MODEL_FILTER_TYPE,
7488 "child-model", child_model,
7489 "virtual-root", root,
7494 return GTK_TREE_MODEL (model);
7497 #define __GTK_FILE_CHOOSER_DEFAULT_C__
7498 #include "gtkaliasdef.c"