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.
21 #include "gdk/gdkkeysyms.h"
22 #include "gtkalignment.h"
23 #include "gtkbindings.h"
24 #include "gtkbutton.h"
25 #include "gtkcellrendererpixbuf.h"
26 #include "gtkcellrendererseptext.h"
27 #include "gtkcellrenderertext.h"
28 #include "gtkcombobox.h"
30 #include "gtkexpander.h"
31 #include "gtkfilechooserdefault.h"
32 #include "gtkfilechooserentry.h"
33 #include "gtkfilechooserutils.h"
34 #include "gtkfilechooser.h"
35 #include "gtkfilesystemmodel.h"
38 #include "gtkhpaned.h"
39 #include "gtkicontheme.h"
43 #include "gtkmarshalers.h"
44 #include "gtkmenuitem.h"
45 #include "gtkmessagedialog.h"
46 #include "gtkpathbar.h"
47 #include "gtkprivate.h"
48 #include "gtkscrolledwindow.h"
49 #include "gtksizegroup.h"
52 #include "gtktreeview.h"
53 #include "gtktreemodelsort.h"
54 #include "gtktreeselection.h"
55 #include "gtktreestore.h"
56 #include "gtktypebuiltins.h"
59 #if defined (G_OS_UNIX)
60 #include "gtkfilesystemunix.h"
61 #elif defined (G_OS_WIN32)
62 #include "gtkfilesystemwin32.h"
68 typedef struct _GtkFileChooserDefaultClass GtkFileChooserDefaultClass;
70 #define GTK_FILE_CHOOSER_DEFAULT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FILE_CHOOSER_DEFAULT, GtkFileChooserDefaultClass))
71 #define GTK_IS_FILE_CHOOSER_DEFAULT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FILE_CHOOSER_DEFAULT))
72 #define GTK_FILE_CHOOSER_DEFAULT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FILE_CHOOSER_DEFAULT, GtkFileChooserDefaultClass))
74 struct _GtkFileChooserDefaultClass
76 GtkVBoxClass parent_class;
79 struct _GtkFileChooserDefault
81 GtkVBox parent_instance;
83 GtkFileChooserAction action;
85 GtkFileSystem *file_system;
87 /* Things common to Open and Save mode */
91 GtkFileSystemModel *tree_model;
92 GtkTreeStore *shortcuts_model;
93 GtkFileSystemModel *list_model;
94 GtkTreeModelSort *sort_model;
96 GtkFileFilter *current_filter;
100 gboolean has_desktop;
106 guint volumes_changed_id;
107 guint bookmarks_changed_id;
109 GtkFilePath *current_volume_path;
110 GtkFilePath *current_folder;
111 GtkFilePath *preview_path;
113 GtkWidget *new_folder_button;
115 GtkWidget *preview_frame;
117 GtkWidget *filter_combo;
118 GtkWidget *tree_scrollwin;
120 GtkWidget *shortcuts_scrollwin;
121 GtkWidget *shortcuts_tree;
122 GtkWidget *add_bookmark_button;
123 GtkWidget *remove_bookmark_button;
124 GtkWidget *list_scrollwin;
126 GtkWidget *preview_widget;
127 GtkWidget *extra_widget;
130 GtkTreeViewColumn *list_name_column;
131 GtkCellRenderer *list_name_renderer;
133 /* Things for Save mode */
135 GtkWidget *save_widgets;
138 GtkWidget *save_folder_combo;
142 guint folder_mode : 1;
143 guint local_only : 1;
144 guint preview_widget_active : 1;
145 guint select_multiple : 1;
146 guint show_hidden : 1;
147 guint list_sort_ascending : 1;
148 guint changing_folder : 1;
159 static guint signals[LAST_SIGNAL] = { 0 };
161 /* Column numbers for the shortcuts tree. Keep these in sync with create_shortcuts_model() */
163 SHORTCUTS_COL_PIXBUF,
166 SHORTCUTS_COL_REMOVABLE,
167 SHORTCUTS_COL_NUM_COLUMNS
170 /* Column numbers for the file list */
175 FILE_LIST_COL_NUM_COLUMNS
178 /* Identifiers for target types */
183 /* Target types for DnD in the shortcuts list */
184 static GtkTargetEntry shortcuts_targets[] = {
185 { "text/uri-list", 0, TEXT_URI_LIST }
188 static const int num_shortcuts_targets = sizeof (shortcuts_targets) / sizeof (shortcuts_targets[0]);
190 /* Interesting places in the shortcuts bar */
200 /* Standard icon size */
201 /* FIXME: maybe this should correspond to the font size in the tree views... */
204 static void gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class);
205 static void gtk_file_chooser_default_iface_init (GtkFileChooserIface *iface);
206 static void gtk_file_chooser_default_init (GtkFileChooserDefault *impl);
208 static GObject* gtk_file_chooser_default_constructor (GType type,
209 guint n_construct_properties,
210 GObjectConstructParam *construct_params);
211 static void gtk_file_chooser_default_finalize (GObject *object);
212 static void gtk_file_chooser_default_set_property (GObject *object,
216 static void gtk_file_chooser_default_get_property (GObject *object,
220 static void gtk_file_chooser_default_show_all (GtkWidget *widget);
222 static void gtk_file_chooser_default_set_current_folder (GtkFileChooser *chooser,
223 const GtkFilePath *path);
224 static GtkFilePath * gtk_file_chooser_default_get_current_folder (GtkFileChooser *chooser);
225 static void gtk_file_chooser_default_set_current_name (GtkFileChooser *chooser,
227 static void gtk_file_chooser_default_select_path (GtkFileChooser *chooser,
228 const GtkFilePath *path);
229 static void gtk_file_chooser_default_unselect_path (GtkFileChooser *chooser,
230 const GtkFilePath *path);
231 static void gtk_file_chooser_default_select_all (GtkFileChooser *chooser);
232 static void gtk_file_chooser_default_unselect_all (GtkFileChooser *chooser);
233 static GSList * gtk_file_chooser_default_get_paths (GtkFileChooser *chooser);
234 static GtkFilePath * gtk_file_chooser_default_get_preview_path (GtkFileChooser *chooser);
235 static GtkFileSystem *gtk_file_chooser_default_get_file_system (GtkFileChooser *chooser);
236 static void gtk_file_chooser_default_add_filter (GtkFileChooser *chooser,
237 GtkFileFilter *filter);
238 static void gtk_file_chooser_default_remove_filter (GtkFileChooser *chooser,
239 GtkFileFilter *filter);
240 static GSList * gtk_file_chooser_default_list_filters (GtkFileChooser *chooser);
241 static gboolean gtk_file_chooser_default_add_shortcut_folder (GtkFileChooser *chooser,
242 const GtkFilePath *path,
244 static gboolean gtk_file_chooser_default_remove_shortcut_folder (GtkFileChooser *chooser,
245 const GtkFilePath *path,
247 static GSList * gtk_file_chooser_default_list_shortcut_folders (GtkFileChooser *chooser);
249 static void location_popup_handler (GtkFileChooserDefault *impl);
250 static void up_folder_handler (GtkFileChooserDefault *impl);
251 static void home_folder_handler (GtkFileChooserDefault *impl);
253 static void set_current_filter (GtkFileChooserDefault *impl,
254 GtkFileFilter *filter);
255 static void check_preview_change (GtkFileChooserDefault *impl);
257 static void filter_combo_changed (GtkComboBox *combo_box,
258 GtkFileChooserDefault *impl);
259 static void tree_selection_changed (GtkTreeSelection *tree_selection,
260 GtkFileChooserDefault *impl);
262 static void shortcuts_row_activated_cb (GtkTreeView *tree_view,
264 GtkTreeViewColumn *column,
265 GtkFileChooserDefault *impl);
266 static gboolean shortcuts_select_func (GtkTreeSelection *selection,
269 gboolean path_currently_selected,
272 static void list_selection_changed (GtkTreeSelection *tree_selection,
273 GtkFileChooserDefault *impl);
274 static void list_row_activated (GtkTreeView *tree_view,
276 GtkTreeViewColumn *column,
277 GtkFileChooserDefault *impl);
279 static void path_bar_clicked (GtkPathBar *path_bar,
280 GtkFilePath *file_path,
281 GtkFileChooserDefault *impl);
283 static void add_bookmark_button_clicked_cb (GtkButton *button,
284 GtkFileChooserDefault *impl);
285 static void remove_bookmark_button_clicked_cb (GtkButton *button,
286 GtkFileChooserDefault *impl);
288 static void tree_name_data_func (GtkTreeViewColumn *tree_column,
289 GtkCellRenderer *cell,
290 GtkTreeModel *tree_model,
293 static void list_icon_data_func (GtkTreeViewColumn *tree_column,
294 GtkCellRenderer *cell,
295 GtkTreeModel *tree_model,
298 static void list_name_data_func (GtkTreeViewColumn *tree_column,
299 GtkCellRenderer *cell,
300 GtkTreeModel *tree_model,
304 static void list_size_data_func (GtkTreeViewColumn *tree_column,
305 GtkCellRenderer *cell,
306 GtkTreeModel *tree_model,
310 static void list_mtime_data_func (GtkTreeViewColumn *tree_column,
311 GtkCellRenderer *cell,
312 GtkTreeModel *tree_model,
316 static GObjectClass *parent_class;
319 _gtk_file_chooser_default_get_type (void)
321 static GType file_chooser_default_type = 0;
323 if (!file_chooser_default_type)
325 static const GTypeInfo file_chooser_default_info =
327 sizeof (GtkFileChooserDefaultClass),
328 NULL, /* base_init */
329 NULL, /* base_finalize */
330 (GClassInitFunc) gtk_file_chooser_default_class_init,
331 NULL, /* class_finalize */
332 NULL, /* class_data */
333 sizeof (GtkFileChooserDefault),
335 (GInstanceInitFunc) gtk_file_chooser_default_init,
338 static const GInterfaceInfo file_chooser_info =
340 (GInterfaceInitFunc) gtk_file_chooser_default_iface_init, /* interface_init */
341 NULL, /* interface_finalize */
342 NULL /* interface_data */
345 file_chooser_default_type = g_type_register_static (GTK_TYPE_VBOX, "GtkFileChooserDefault",
346 &file_chooser_default_info, 0);
347 g_type_add_interface_static (file_chooser_default_type,
348 GTK_TYPE_FILE_CHOOSER,
352 return file_chooser_default_type;
356 gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class)
358 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
359 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
360 GtkBindingSet *binding_set;
362 parent_class = g_type_class_peek_parent (class);
364 gobject_class->finalize = gtk_file_chooser_default_finalize;
365 gobject_class->constructor = gtk_file_chooser_default_constructor;
366 gobject_class->set_property = gtk_file_chooser_default_set_property;
367 gobject_class->get_property = gtk_file_chooser_default_get_property;
369 widget_class->show_all = gtk_file_chooser_default_show_all;
371 signals[LOCATION_POPUP] =
372 _gtk_binding_signal_new ("location-popup",
373 G_OBJECT_CLASS_TYPE (class),
374 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
375 G_CALLBACK (location_popup_handler),
377 _gtk_marshal_VOID__VOID,
380 _gtk_binding_signal_new ("up-folder",
381 G_OBJECT_CLASS_TYPE (class),
382 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
383 G_CALLBACK (up_folder_handler),
385 _gtk_marshal_VOID__VOID,
387 signals[HOME_FOLDER] =
388 _gtk_binding_signal_new ("home-folder",
389 G_OBJECT_CLASS_TYPE (class),
390 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
391 G_CALLBACK (home_folder_handler),
393 _gtk_marshal_VOID__VOID,
396 binding_set = gtk_binding_set_by_class (class);
398 gtk_binding_entry_add_signal (binding_set,
399 GDK_l, GDK_CONTROL_MASK,
403 gtk_binding_entry_add_signal (binding_set,
404 GDK_Up, GDK_MOD1_MASK,
407 gtk_binding_entry_add_signal (binding_set,
408 GDK_KP_Up, GDK_MOD1_MASK,
412 gtk_binding_entry_add_signal (binding_set,
413 GDK_Home, GDK_MOD1_MASK,
416 gtk_binding_entry_add_signal (binding_set,
417 GDK_KP_Home, GDK_MOD1_MASK,
421 _gtk_file_chooser_install_properties (gobject_class);
425 gtk_file_chooser_default_iface_init (GtkFileChooserIface *iface)
427 iface->select_path = gtk_file_chooser_default_select_path;
428 iface->unselect_path = gtk_file_chooser_default_unselect_path;
429 iface->select_all = gtk_file_chooser_default_select_all;
430 iface->unselect_all = gtk_file_chooser_default_unselect_all;
431 iface->get_paths = gtk_file_chooser_default_get_paths;
432 iface->get_preview_path = gtk_file_chooser_default_get_preview_path;
433 iface->get_file_system = gtk_file_chooser_default_get_file_system;
434 iface->set_current_folder = gtk_file_chooser_default_set_current_folder;
435 iface->get_current_folder = gtk_file_chooser_default_get_current_folder;
436 iface->set_current_name = gtk_file_chooser_default_set_current_name;
437 iface->add_filter = gtk_file_chooser_default_add_filter;
438 iface->remove_filter = gtk_file_chooser_default_remove_filter;
439 iface->list_filters = gtk_file_chooser_default_list_filters;
440 iface->add_shortcut_folder = gtk_file_chooser_default_add_shortcut_folder;
441 iface->remove_shortcut_folder = gtk_file_chooser_default_remove_shortcut_folder;
442 iface->list_shortcut_folders = gtk_file_chooser_default_list_shortcut_folders;
446 gtk_file_chooser_default_init (GtkFileChooserDefault *impl)
448 impl->folder_mode = FALSE;
449 impl->local_only = TRUE;
450 impl->preview_widget_active = TRUE;
451 impl->select_multiple = FALSE;
452 impl->show_hidden = FALSE;
454 gtk_box_set_spacing (GTK_BOX (impl), 12);
458 gtk_file_chooser_default_finalize (GObject *object)
460 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (object);
463 g_signal_handler_disconnect (impl->file_system, impl->volumes_changed_id);
464 impl->volumes_changed_id = 0;
465 g_signal_handler_disconnect (impl->file_system, impl->bookmarks_changed_id);
466 impl->bookmarks_changed_id = 0;
467 g_object_unref (impl->file_system);
469 for (l = impl->filters; l; l = l->next)
471 GtkFileFilter *filter;
473 filter = GTK_FILE_FILTER (l->data);
474 g_object_unref (filter);
476 g_slist_free (impl->filters);
478 if (impl->current_filter)
479 g_object_unref (impl->current_filter);
481 if (impl->current_volume_path)
482 gtk_file_path_free (impl->current_volume_path);
484 if (impl->current_folder)
485 gtk_file_path_free (impl->current_folder);
487 if (impl->preview_path)
488 gtk_file_path_free (impl->preview_path);
490 G_OBJECT_CLASS (parent_class)->finalize (object);
493 /* Shows an error dialog set as transient for the specified window */
495 error_message_with_parent (GtkWindow *parent,
500 dialog = gtk_message_dialog_new (parent,
501 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
506 gtk_dialog_run (GTK_DIALOG (dialog));
507 gtk_widget_destroy (dialog);
510 /* Shows an error dialog for the file chooser */
512 error_message (GtkFileChooserDefault *impl,
517 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (impl));
518 if (!GTK_WIDGET_TOPLEVEL (toplevel))
521 error_message_with_parent (toplevel ? GTK_WINDOW (toplevel) : NULL,
525 /* Shows a simple error dialog relative to a path. Frees the GError as well. */
527 error_dialog (GtkFileChooserDefault *impl,
529 const GtkFilePath *path,
534 text = g_strdup_printf (msg,
535 gtk_file_path_get_string (path),
537 error_message (impl, text);
539 g_error_free (error);
542 /* Displays an error message about not being able to get information for a file.
543 * Frees the GError as well.
546 error_getting_info_dialog (GtkFileChooserDefault *impl,
547 const GtkFilePath *path,
551 _("Could not retrieve information about %s:\n%s"),
555 /* Shows an error dialog about not being able to add a bookmark */
557 error_could_not_add_bookmark_dialog (GtkFileChooserDefault *impl,
558 const GtkFilePath *path,
562 _("Could not add a bookmark for %s:\n%s"),
566 /* Shows an error dialog about not being able to compose a filename */
568 error_building_filename_dialog (GtkFileChooserDefault *impl,
569 const GtkFilePath *base_path,
570 const char *file_part,
575 msg = g_strdup_printf (_("Could not build file name from '%s' and '%s':\n%s"),
576 gtk_file_path_get_string (base_path),
579 error_message (impl, msg);
581 g_error_free (error);
585 update_preview_widget_visibility (GtkFileChooserDefault *impl)
587 if (impl->preview_widget_active && impl->preview_widget)
588 gtk_widget_show (impl->preview_frame);
590 gtk_widget_hide (impl->preview_frame);
594 set_preview_widget (GtkFileChooserDefault *impl,
595 GtkWidget *preview_widget)
597 if (preview_widget == impl->preview_widget)
600 if (impl->preview_widget)
601 gtk_container_remove (GTK_CONTAINER (impl->preview_frame),
602 impl->preview_widget);
604 impl->preview_widget = preview_widget;
605 if (impl->preview_widget)
607 gtk_widget_show_all (impl->preview_widget);
608 gtk_container_add (GTK_CONTAINER (impl->preview_frame),
609 impl->preview_widget);
612 update_preview_widget_visibility (impl);
615 /* Clears the selection in the shortcuts tree */
617 shortcuts_unselect_all (GtkFileChooserDefault *impl)
619 GtkTreeSelection *selection;
621 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_tree));
622 gtk_tree_selection_unselect_all (selection);
625 /* Convenience function to get the display name and icon info for a path */
627 get_file_info (GtkFileSystem *file_system, const GtkFilePath *path, GError **error)
629 GtkFilePath *parent_path;
630 GtkFileFolder *parent_folder;
633 if (!gtk_file_system_get_parent (file_system, path, &parent_path, error))
636 parent_folder = gtk_file_system_get_folder (file_system, parent_path,
637 GTK_FILE_INFO_DISPLAY_NAME
641 | GTK_FILE_INFO_IS_FOLDER,
643 gtk_file_path_free (parent_path);
648 info = gtk_file_folder_get_info (parent_folder, path, error);
649 g_object_unref (parent_folder);
654 /* Inserts a path in the shortcuts tree, making a copy of it; alternatively,
655 * inserts a volume. A position of -1 indicates the end of the tree.
658 shortcuts_insert_path (GtkFileChooserDefault *impl,
661 GtkFileSystemVolume *volume,
662 const GtkFilePath *path,
675 label_copy = gtk_file_system_volume_get_display_name (impl->file_system, volume);
676 pixbuf = gtk_file_system_volume_render_icon (impl->file_system,
686 info = get_file_info (impl->file_system, path, error);
690 data = gtk_file_path_copy (path);
693 label_copy = g_strdup (label);
695 label_copy = g_strdup (gtk_file_info_get_display_name (info));
697 pixbuf = gtk_file_system_render_icon (impl->file_system, path, GTK_WIDGET (impl), ICON_SIZE, NULL);
699 gtk_file_info_free (info);
702 gtk_tree_store_insert (impl->shortcuts_model, &iter, NULL, pos);
704 gtk_tree_store_set (impl->shortcuts_model, &iter,
705 SHORTCUTS_COL_PIXBUF, pixbuf,
706 SHORTCUTS_COL_NAME, label_copy,
707 SHORTCUTS_COL_PATH, data,
708 SHORTCUTS_COL_REMOVABLE, removable,
714 g_object_unref (pixbuf);
719 /* Appends an item for the user's home directory to the shortcuts model */
721 shortcuts_append_home (GtkFileChooserDefault *impl)
724 GtkFilePath *home_path;
727 home = g_get_home_dir ();
728 home_path = gtk_file_system_filename_to_path (impl->file_system, home);
731 impl->has_home = shortcuts_insert_path (impl, -1, FALSE, NULL, home_path, _("Home"), FALSE, &error);
733 error_getting_info_dialog (impl, home_path, error);
735 gtk_file_path_free (home_path);
738 /* Appends the ~/Desktop directory to the shortcuts model */
740 shortcuts_append_desktop (GtkFileChooserDefault *impl)
745 name = g_build_filename (g_get_home_dir (), "Desktop", NULL);
746 path = gtk_file_system_filename_to_path (impl->file_system, name);
749 impl->has_desktop = shortcuts_insert_path (impl, -1, FALSE, NULL, path, NULL, FALSE, NULL);
750 /* We do not actually pop up an error dialog if there is no desktop directory
751 * because some people may really not want to have one.
754 gtk_file_path_free (path);
757 /* Appends a list of GtkFilePath to the shortcuts model; returns how many were inserted */
759 shortcuts_append_paths (GtkFileChooserDefault *impl,
766 for (; paths; paths = paths->next)
774 /* NULL GError, but we don't really want to show error boxes here */
776 if (shortcuts_insert_path (impl, -1, FALSE, NULL, path, NULL, TRUE, NULL))
783 /* Returns the index for the corresponding item in the shortcuts bar */
785 shortcuts_get_index (GtkFileChooserDefault *impl,
786 ShortcutsIndex where)
792 if (where == SHORTCUTS_HOME)
795 n += impl->has_home ? 1 : 0;
797 if (where == SHORTCUTS_DESKTOP)
800 n += impl->has_desktop ? 1 : 0;
802 if (where == SHORTCUTS_VOLUMES)
805 n += impl->num_volumes;
807 if (where == SHORTCUTS_SHORTCUTS)
810 n += impl->num_shortcuts;
812 if (where == SHORTCUTS_SEPARATOR)
817 if (where == SHORTCUTS_BOOKMARKS)
820 g_assert_not_reached ();
827 typedef void (* RemoveFunc) (GtkFileChooserDefault *impl, gpointer data);
829 /* Removes the specified number of rows from the shortcuts list */
831 shortcuts_remove_rows (GtkFileChooserDefault *impl,
834 RemoveFunc remove_fn)
838 path = gtk_tree_path_new_from_indices (start_row, -1);
840 for (; n_rows; n_rows--)
845 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->shortcuts_model), &iter, path))
846 g_assert_not_reached ();
850 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, SHORTCUTS_COL_PATH, &data, -1);
851 (* remove_fn) (impl, data);
854 gtk_tree_store_remove (impl->shortcuts_model, &iter);
857 gtk_tree_path_free (path);
860 /* Used from shortcuts_remove_rows() */
862 volume_remove_cb (GtkFileChooserDefault *impl, gpointer data)
864 GtkFileSystemVolume *volume;
867 gtk_file_system_volume_free (impl->file_system, volume);
870 /* Adds all the file system volumes to the shortcuts model */
872 shortcuts_add_volumes (GtkFileChooserDefault *impl)
878 start_row = shortcuts_get_index (impl, SHORTCUTS_VOLUMES);
879 shortcuts_remove_rows (impl, start_row, impl->num_volumes, volume_remove_cb);
880 impl->num_volumes = 0;
882 list = gtk_file_system_list_volumes (impl->file_system);
886 for (l = list; l; l = l->next)
888 GtkFileSystemVolume *volume;
892 shortcuts_insert_path (impl, start_row + n, TRUE, volume, NULL, NULL, FALSE, NULL);
896 impl->num_volumes = n;
901 /* Used from shortcuts_remove_rows() */
903 remove_bookmark_cb (GtkFileChooserDefault *impl, gpointer data)
908 gtk_file_path_free (path);
911 /* Updates the list of bookmarks */
913 shortcuts_add_bookmarks (GtkFileChooserDefault *impl)
917 shortcuts_remove_rows (impl,
918 shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS),
922 bookmarks = gtk_file_system_list_bookmarks (impl->file_system);
923 impl->num_bookmarks = shortcuts_append_paths (impl, bookmarks);
924 gtk_file_paths_free (bookmarks);
927 /* Appends the bookmarks separator node and the bookmarks from the file system. */
929 shortcuts_append_bookmarks (GtkFileChooserDefault *impl)
933 gtk_tree_store_append (impl->shortcuts_model, &iter, NULL);
934 gtk_tree_store_set (impl->shortcuts_model, &iter,
935 SHORTCUTS_COL_PIXBUF, NULL,
936 SHORTCUTS_COL_NAME, NULL,
937 SHORTCUTS_COL_PATH, NULL,
939 shortcuts_add_bookmarks (impl);
942 /* Creates the GtkTreeStore used as the shortcuts model */
944 create_shortcuts_model (GtkFileChooserDefault *impl)
946 if (impl->shortcuts_model)
947 g_object_unref (impl->shortcuts_model);
949 /* Keep this order in sync with the SHORCUTS_COL_* enum values */
950 impl->shortcuts_model = gtk_tree_store_new (SHORTCUTS_COL_NUM_COLUMNS,
951 GDK_TYPE_PIXBUF, /* pixbuf */
952 G_TYPE_STRING, /* name */
953 G_TYPE_POINTER, /* path or volume */
954 G_TYPE_BOOLEAN); /* removable */
956 if (impl->file_system)
958 shortcuts_append_home (impl);
959 shortcuts_append_desktop (impl);
960 shortcuts_add_volumes (impl);
961 shortcuts_append_bookmarks (impl);
964 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->shortcuts_tree), GTK_TREE_MODEL (impl->shortcuts_model));
967 /* Callback used when the "New Folder" toolbar button is clicked */
969 new_folder_button_clicked (GtkButton *button,
970 GtkFileChooserDefault *impl)
975 /* FIXME: this doesn't work for folder mode, just for file mode */
977 _gtk_file_system_model_add_editable (impl->list_model, &iter);
978 g_object_set (impl->list_name_renderer, "editable", TRUE, NULL);
980 path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->list_model), &iter);
981 gtk_tree_view_set_cursor (GTK_TREE_VIEW (impl->list),
983 impl->list_name_column,
987 /* Callback used from the text cell renderer when the new folder is named */
989 renderer_edited_cb (GtkCellRendererText *cell_renderer_text,
991 const gchar *new_text,
992 GtkFileChooserDefault *impl)
995 GtkFilePath *file_path;
997 _gtk_file_system_model_remove_editable (impl->list_model);
998 g_object_set (impl->list_name_renderer, "editable", FALSE, NULL);
1001 file_path = gtk_file_system_make_path (impl->file_system, impl->current_folder, new_text, &error);
1004 error_building_filename_dialog (impl, impl->current_folder, new_text, error);
1009 if (!gtk_file_system_create_folder (impl->file_system, file_path, &error))
1011 _("Could not create folder %s:\n%s"),
1014 gtk_file_path_free (file_path);
1016 /* FIXME: scroll to the new folder and select it */
1019 /* Callback used from the text cell renderer when the new folder edition gets
1023 renderer_editing_canceled_cb (GtkCellRendererText *cell_renderer_text,
1024 GtkFileChooserDefault *impl)
1026 _gtk_file_system_model_remove_editable (impl->list_model);
1027 g_object_set (impl->list_name_renderer, "editable", FALSE, NULL);
1030 /* Creates the widgets for the filter combo box */
1032 filter_create (GtkFileChooserDefault *impl)
1034 impl->filter_combo = gtk_combo_box_new_text ();
1035 g_signal_connect (impl->filter_combo, "changed",
1036 G_CALLBACK (filter_combo_changed), impl);
1038 return impl->filter_combo;
1042 button_new (GtkFileChooserDefault *impl,
1044 const char *stock_id,
1054 button = gtk_button_new ();
1055 hbox = gtk_hbox_new (FALSE, 2);
1056 align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
1058 gtk_container_add (GTK_CONTAINER (button), align);
1059 gtk_container_add (GTK_CONTAINER (align), hbox);
1060 widget = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
1062 gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
1064 widget = gtk_label_new (text);
1065 gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
1067 gtk_widget_set_sensitive (button, sensitive);
1068 g_signal_connect (button, "clicked", callback, impl);
1070 gtk_widget_show_all (align);
1073 gtk_widget_show (button);
1078 /* Creates the widgets for the folder tree */
1080 create_folder_tree (GtkFileChooserDefault *impl)
1082 GtkTreeSelection *selection;
1084 /* Scrolled window */
1086 impl->tree_scrollwin = gtk_scrolled_window_new (NULL, NULL);
1087 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (impl->tree_scrollwin),
1088 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1089 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (impl->tree_scrollwin),
1091 if (impl->folder_mode)
1092 gtk_widget_show (impl->tree_scrollwin);
1096 impl->tree = gtk_tree_view_new ();
1097 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (impl->tree), FALSE);
1099 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->tree));
1100 g_signal_connect (selection, "changed",
1101 G_CALLBACK (tree_selection_changed), impl);
1103 gtk_container_add (GTK_CONTAINER (impl->tree_scrollwin), impl->tree);
1104 gtk_widget_show (impl->tree);
1108 gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (impl->tree), 0,
1110 gtk_cell_renderer_text_new (),
1111 tree_name_data_func, impl, NULL);
1112 gtk_tree_view_set_search_column (GTK_TREE_VIEW (impl->tree),
1113 GTK_FILE_SYSTEM_MODEL_DISPLAY_NAME);
1115 return impl->tree_scrollwin;
1118 /* Tries to add a bookmark from a path name */
1120 shortcuts_add_bookmark_from_path (GtkFileChooserDefault *impl,
1121 const GtkFilePath *path)
1127 info = get_file_info (impl->file_system, path, &error);
1130 error_getting_info_dialog (impl, path, error);
1131 else if (!gtk_file_info_get_is_folder (info))
1135 msg = g_strdup_printf (_("Could not add bookmark for %s because it is not a folder."),
1136 gtk_file_path_get_string (path));
1137 error_message (impl, msg);
1143 if (!gtk_file_system_add_bookmark (impl->file_system, path, &error))
1144 error_could_not_add_bookmark_dialog (impl, path, error);
1148 /* Callback used when the "Add bookmark" button is clicked */
1150 add_bookmark_button_clicked_cb (GtkButton *button,
1151 GtkFileChooserDefault *impl)
1153 shortcuts_add_bookmark_from_path (impl, impl->current_folder);
1156 /* Callback used when the "Remove bookmark" button is clicked */
1158 remove_bookmark_button_clicked_cb (GtkButton *button,
1159 GtkFileChooserDefault *impl)
1161 GtkTreeSelection *selection;
1167 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_tree));
1169 if (gtk_tree_selection_get_selected (selection, NULL, &iter))
1171 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
1172 SHORTCUTS_COL_PATH, &path,
1173 SHORTCUTS_COL_REMOVABLE, &removable, -1);
1176 g_assert_not_reached ();
1181 if (!gtk_file_system_remove_bookmark (impl->file_system, path, &error))
1183 _("Could not remove bookmark for %s:\n%s"),
1189 /* Sensitize the "add bookmark" button if the current folder is not in the
1190 * bookmarks list, or de-sensitize it otherwise.
1193 bookmarks_check_add_sensitivity (GtkFileChooserDefault *impl)
1202 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
1206 separator_idx = shortcuts_get_index (impl, SHORTCUTS_SEPARATOR);
1207 volumes_idx = shortcuts_get_index (impl, SHORTCUTS_VOLUMES);
1215 if (i == separator_idx)
1218 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, SHORTCUTS_COL_PATH, &data, -1);
1220 if (i >= volumes_idx && i < volumes_idx + impl->num_volumes)
1222 GtkFileSystemVolume *volume;
1223 GtkFilePath *base_path;
1226 base_path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
1228 exists = strcmp (gtk_file_path_get_string (impl->current_folder),
1229 gtk_file_path_get_string (base_path)) == 0;
1241 if (path && gtk_file_path_compare (path, impl->current_folder) == 0)
1248 while (gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter));
1251 gtk_widget_set_sensitive (impl->add_bookmark_button, !exists);
1254 /* Sets the sensitivity of the "remove bookmark" button depending on whether a
1255 * bookmark row is selected in the shortcuts tree.
1258 bookmarks_check_remove_sensitivity (GtkFileChooserDefault *impl)
1260 GtkTreeSelection *selection;
1262 gboolean removable = FALSE;
1264 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_tree));
1266 if (gtk_tree_selection_get_selected (selection, NULL, &iter))
1267 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
1268 SHORTCUTS_COL_REMOVABLE, &removable,
1271 gtk_widget_set_sensitive (impl->remove_bookmark_button, removable);
1274 /* Converts raw selection data from text/uri-list to a list of strings */
1276 split_uris (const char *data)
1279 const char *p, *start;
1285 for (p = start; *p != 0; p++)
1286 if (*p == '\r' && *(p + 1) == '\n')
1290 name = g_strndup (start, p - start);
1291 uris = g_slist_prepend (uris, name);
1297 uris = g_slist_reverse (uris);
1301 /* Callback used when we get the drag data for the bookmarks list. We add the
1302 * received URIs as bookmarks if they are folders.
1305 shortcuts_drag_data_received_cb (GtkWidget *widget,
1306 GdkDragContext *context,
1309 GtkSelectionData *selection_data,
1314 GtkFileChooserDefault *impl;
1317 impl = GTK_FILE_CHOOSER_DEFAULT (data);
1319 uris = split_uris (selection_data->data);
1321 for (l = uris; l; l = l->next)
1327 path = gtk_file_system_uri_to_path (impl->file_system, uri);
1331 shortcuts_add_bookmark_from_path (impl, path);
1332 gtk_file_path_free (path);
1338 msg = g_strdup_printf (_("Could not add a bookmark for %s because it is an invalid path name."),
1340 error_message (impl, msg);
1347 g_slist_free (uris);
1350 /* Callback used when the selection in the shortcuts tree changes */
1352 shortcuts_selection_changed_cb (GtkTreeSelection *selection,
1353 GtkFileChooserDefault *impl)
1355 bookmarks_check_remove_sensitivity (impl);
1358 /* Creates the widgets for the shortcuts and bookmarks tree */
1360 shortcuts_tree_create (GtkFileChooserDefault *impl)
1362 GtkTreeSelection *selection;
1363 GtkTreeViewColumn *column;
1364 GtkCellRenderer *renderer;
1366 /* Scrolled window */
1368 impl->shortcuts_scrollwin = gtk_scrolled_window_new (NULL, NULL);
1369 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (impl->shortcuts_scrollwin),
1370 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1371 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (impl->shortcuts_scrollwin),
1373 gtk_widget_show (impl->shortcuts_scrollwin);
1377 impl->shortcuts_tree = gtk_tree_view_new ();
1378 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (impl->shortcuts_tree), FALSE);
1380 gtk_drag_dest_set (impl->shortcuts_tree,
1381 GTK_DEST_DEFAULT_ALL,
1383 num_shortcuts_targets,
1386 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_tree));
1387 gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
1388 gtk_tree_selection_set_select_function (selection,
1389 shortcuts_select_func,
1392 g_signal_connect (selection, "changed",
1393 G_CALLBACK (shortcuts_selection_changed_cb), impl);
1395 g_signal_connect (impl->shortcuts_tree, "row-activated",
1396 G_CALLBACK (shortcuts_row_activated_cb), impl);
1398 g_signal_connect (impl->shortcuts_tree, "drag-data-received",
1399 G_CALLBACK (shortcuts_drag_data_received_cb), impl);
1401 gtk_container_add (GTK_CONTAINER (impl->shortcuts_scrollwin), impl->shortcuts_tree);
1402 gtk_widget_show (impl->shortcuts_tree);
1406 create_shortcuts_model (impl);
1410 column = gtk_tree_view_column_new ();
1411 gtk_tree_view_column_set_title (column, _("Folder"));
1413 renderer = gtk_cell_renderer_pixbuf_new ();
1414 gtk_tree_view_column_pack_start (column, renderer, FALSE);
1415 gtk_tree_view_column_set_attributes (column, renderer,
1416 "pixbuf", SHORTCUTS_COL_PIXBUF,
1419 renderer = _gtk_cell_renderer_sep_text_new ();
1420 gtk_tree_view_column_pack_start (column, renderer, TRUE);
1421 gtk_tree_view_column_set_attributes (column, renderer,
1422 "text", SHORTCUTS_COL_NAME,
1425 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->shortcuts_tree), column);
1427 return impl->shortcuts_scrollwin;
1430 /* Creates the widgets for the shortcuts/bookmarks pane */
1432 shortcuts_pane_create (GtkFileChooserDefault *impl,
1433 GtkSizeGroup *size_group)
1439 vbox = gtk_vbox_new (FALSE, 6);
1440 gtk_widget_show (vbox);
1442 /* Shortcuts tree */
1444 widget = shortcuts_tree_create (impl);
1445 gtk_box_pack_start (GTK_BOX (vbox), widget, TRUE, TRUE, 0);
1447 /* Box for buttons */
1449 hbox = gtk_hbox_new (TRUE, 6);
1450 gtk_size_group_add_widget (size_group, hbox);
1451 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
1452 gtk_widget_show (hbox);
1454 /* Add bookmark button */
1456 impl->add_bookmark_button = button_new (impl,
1461 G_CALLBACK (add_bookmark_button_clicked_cb));
1462 gtk_box_pack_start (GTK_BOX (hbox), impl->add_bookmark_button, TRUE, TRUE, 0);
1464 /* Remove bookmark button */
1466 impl->remove_bookmark_button = button_new (impl,
1471 G_CALLBACK (remove_bookmark_button_clicked_cb));
1472 gtk_box_pack_start (GTK_BOX (hbox), impl->remove_bookmark_button, TRUE, TRUE, 0);
1477 /* Creates the widgets for the file list */
1479 create_file_list (GtkFileChooserDefault *impl)
1481 GtkTreeSelection *selection;
1482 GtkTreeViewColumn *column;
1483 GtkCellRenderer *renderer;
1485 /* Scrolled window */
1487 impl->list_scrollwin = gtk_scrolled_window_new (NULL, NULL);
1488 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (impl->list_scrollwin),
1489 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1490 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (impl->list_scrollwin),
1492 if (!impl->folder_mode)
1493 gtk_widget_show (impl->list_scrollwin);
1495 /* Tree/list view */
1497 impl->list = gtk_tree_view_new ();
1498 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (impl->list), TRUE);
1499 gtk_container_add (GTK_CONTAINER (impl->list_scrollwin), impl->list);
1500 g_signal_connect (impl->list, "row_activated",
1501 G_CALLBACK (list_row_activated), impl);
1502 gtk_widget_show (impl->list);
1504 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
1505 g_signal_connect (selection, "changed",
1506 G_CALLBACK (list_selection_changed), impl);
1508 /* Filename column */
1510 impl->list_name_column = gtk_tree_view_column_new ();
1511 gtk_tree_view_column_set_expand (impl->list_name_column, TRUE);
1512 gtk_tree_view_column_set_title (impl->list_name_column, _("File name"));
1513 gtk_tree_view_column_set_sort_column_id (impl->list_name_column, FILE_LIST_COL_NAME);
1515 renderer = gtk_cell_renderer_pixbuf_new ();
1516 gtk_tree_view_column_pack_start (impl->list_name_column, renderer, FALSE);
1517 gtk_tree_view_column_set_cell_data_func (impl->list_name_column, renderer,
1518 list_icon_data_func, impl, NULL);
1520 impl->list_name_renderer = gtk_cell_renderer_text_new ();
1521 g_signal_connect (impl->list_name_renderer, "edited",
1522 G_CALLBACK (renderer_edited_cb), impl);
1523 g_signal_connect (impl->list_name_renderer, "editing-canceled",
1524 G_CALLBACK (renderer_editing_canceled_cb), impl);
1525 gtk_tree_view_column_pack_start (impl->list_name_column, impl->list_name_renderer, TRUE);
1526 gtk_tree_view_column_set_cell_data_func (impl->list_name_column, impl->list_name_renderer,
1527 list_name_data_func, impl, NULL);
1529 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->list), impl->list_name_column);
1533 column = gtk_tree_view_column_new ();
1534 gtk_tree_view_column_set_title (column, _("Size"));
1536 renderer = gtk_cell_renderer_text_new ();
1537 gtk_tree_view_column_pack_start (column, renderer, TRUE);
1538 gtk_tree_view_column_set_cell_data_func (column, renderer,
1539 list_size_data_func, impl, NULL);
1540 gtk_tree_view_column_set_sort_column_id (column, FILE_LIST_COL_SIZE);
1541 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->list), column);
1543 /* Modification time column */
1545 column = gtk_tree_view_column_new ();
1546 gtk_tree_view_column_set_title (column, _("Modified"));
1548 renderer = gtk_cell_renderer_text_new ();
1549 gtk_tree_view_column_pack_start (column, renderer, TRUE);
1550 gtk_tree_view_column_set_cell_data_func (column, renderer,
1551 list_mtime_data_func, impl, NULL);
1552 gtk_tree_view_column_set_sort_column_id (column, FILE_LIST_COL_MTIME);
1553 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->list), column);
1555 return impl->list_scrollwin;
1559 create_filename_entry_and_filter_combo (GtkFileChooserDefault *impl)
1564 hbox = gtk_hbox_new (FALSE, 12);
1565 gtk_widget_show (hbox);
1569 widget = filter_create (impl);
1570 gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
1575 /* Creates the widgets for the files/folders pane */
1577 file_pane_create (GtkFileChooserDefault *impl,
1578 GtkSizeGroup *size_group)
1584 vbox = gtk_vbox_new (FALSE, 6);
1585 gtk_widget_show (vbox);
1587 /* The path bar and 'Create Folder' button */
1588 hbox = gtk_hbox_new (FALSE, 12);
1589 gtk_widget_show (hbox);
1590 impl->path_bar = g_object_new (GTK_TYPE_PATH_BAR, NULL);
1591 g_signal_connect (impl->path_bar, "path_clicked", G_CALLBACK (path_bar_clicked), impl);
1592 gtk_widget_show_all (impl->path_bar);
1593 gtk_box_pack_start (GTK_BOX (hbox), impl->path_bar, TRUE, TRUE, 0);
1596 impl->new_folder_button = gtk_button_new_with_mnemonic (_("Create _Folder"));
1597 g_signal_connect (impl->new_folder_button, "clicked",
1598 G_CALLBACK (new_folder_button_clicked), impl);
1599 gtk_box_pack_end (GTK_BOX (hbox), impl->new_folder_button, FALSE, FALSE, 0);
1601 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
1603 gtk_widget_show (impl->new_folder_button);
1604 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
1606 /* Box for lists and preview */
1608 hbox = gtk_hbox_new (FALSE, 12);
1609 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
1610 gtk_widget_show (hbox);
1614 widget = create_folder_tree (impl);
1615 gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
1619 widget = create_file_list (impl);
1620 gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
1624 impl->preview_frame = gtk_frame_new (_("Preview"));
1625 gtk_box_pack_start (GTK_BOX (hbox), impl->preview_frame, FALSE, FALSE, 0);
1626 /* Don't show preview frame initially */
1628 /* Filename entry and filter combo */
1629 hbox = gtk_hbox_new (FALSE, 0);
1630 gtk_size_group_add_widget (size_group, hbox);
1631 widget = create_filename_entry_and_filter_combo (impl);
1632 gtk_box_pack_end (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
1633 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
1634 gtk_widget_show (hbox);
1638 /* Callback used when the "Browse for more folders" expander is toggled */
1640 expander_activate_cb (GtkExpander *expander,
1641 GtkFileChooserDefault *impl)
1645 active = gtk_expander_get_expanded (expander);
1648 gtk_widget_show (impl->hpaned);
1650 gtk_widget_hide (impl->hpaned);
1653 /* Creates the widgets specific to Save mode */
1655 save_widgets_create (GtkFileChooserDefault *impl)
1659 GtkWidget *alignment;
1661 table = gtk_table_new (3, 2, FALSE);
1662 gtk_table_set_row_spacings (GTK_TABLE (table), 12);
1663 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
1667 widget = gtk_label_new_with_mnemonic (_("_Name:"));
1668 gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
1669 gtk_table_attach (GTK_TABLE (table), widget,
1673 gtk_widget_show (widget);
1675 impl->entry = _gtk_file_chooser_entry_new ();
1676 gtk_entry_set_activates_default (GTK_ENTRY (impl->entry), TRUE);
1677 _gtk_file_chooser_entry_set_file_system (GTK_FILE_CHOOSER_ENTRY (impl->entry), impl->file_system);
1678 _gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->entry), impl->current_folder);
1680 gtk_table_attach (GTK_TABLE (table), impl->entry,
1682 GTK_EXPAND | GTK_FILL, 0,
1684 gtk_widget_show (impl->entry);
1685 gtk_label_set_mnemonic_widget (GTK_LABEL (widget), impl->entry);
1689 widget = gtk_label_new_with_mnemonic (_("Save in _Folder:"));
1690 gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
1691 gtk_table_attach (GTK_TABLE (table), widget,
1695 gtk_widget_show (widget);
1697 /* FIXME: create the combo */
1701 alignment = gtk_alignment_new (0.0, 0.5, 1.0, 1.0);
1702 gtk_table_attach (GTK_TABLE (table), alignment,
1706 gtk_widget_show (alignment);
1708 widget = gtk_expander_new_with_mnemonic (_("_Browse for other folders"));
1709 gtk_container_add (GTK_CONTAINER (alignment), widget);
1710 gtk_widget_show (widget);
1711 g_signal_connect (widget, "activate",
1712 G_CALLBACK (expander_activate_cb),
1718 /* Creates the main hpaned with the widgets shared by Open and Save mode */
1720 main_paned_create (GtkFileChooserDefault *impl)
1724 GtkSizeGroup *size_group;
1726 /* size group is used by the [+][-] buttons, as well as the filter. */
1727 size_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
1731 hpaned = gtk_hpaned_new ();
1732 gtk_paned_set_position (GTK_PANED (hpaned), 200); /* FIXME: this sucks */
1734 /* Shortcuts pane */
1736 widget = shortcuts_pane_create (impl, size_group);
1737 gtk_paned_pack1 (GTK_PANED (hpaned), widget, FALSE, FALSE);
1739 /* File/folder pane */
1741 widget = file_pane_create (impl, size_group);
1742 gtk_paned_pack2 (GTK_PANED (hpaned), widget, TRUE, FALSE);
1748 gtk_file_chooser_default_constructor (GType type,
1749 guint n_construct_properties,
1750 GObjectConstructParam *construct_params)
1752 GtkFileChooserDefault *impl;
1754 GtkWidget *show_widget;
1756 object = parent_class->constructor (type,
1757 n_construct_properties,
1759 impl = GTK_FILE_CHOOSER_DEFAULT (object);
1761 g_assert (impl->file_system);
1763 gtk_widget_push_composite_child ();
1765 /* Widgets for Save mode */
1767 impl->save_widgets = save_widgets_create (impl);
1768 gtk_box_pack_start (GTK_BOX (impl), impl->save_widgets, FALSE, FALSE, 0);
1770 /* Widgets for Open and Save mode */
1772 impl->hpaned = main_paned_create (impl);
1773 gtk_box_pack_start (GTK_BOX (impl), impl->hpaned, TRUE, TRUE, 0);
1775 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
1776 show_widget = impl->hpaned;
1778 show_widget = impl->save_widgets;
1780 gtk_widget_show (show_widget);
1782 gtk_widget_pop_composite_child ();
1787 /* Sets the extra_widget by packing it in the appropriate place */
1789 set_extra_widget (GtkFileChooserDefault *impl,
1790 GtkWidget *extra_widget)
1792 if (extra_widget == impl->extra_widget)
1795 if (impl->extra_widget)
1796 gtk_container_remove (GTK_CONTAINER (impl), impl->extra_widget);
1798 impl->extra_widget = extra_widget;
1799 if (impl->extra_widget)
1801 gtk_widget_show_all (impl->extra_widget);
1802 gtk_box_pack_end (GTK_BOX (impl), impl->extra_widget, FALSE, FALSE, 0);
1807 volumes_changed_cb (GtkFileSystem *file_system,
1808 GtkFileChooserDefault *impl)
1810 shortcuts_add_volumes (impl);
1813 /* Callback used when the set of bookmarks changes in the file system */
1815 bookmarks_changed_cb (GtkFileSystem *file_system,
1816 GtkFileChooserDefault *impl)
1818 shortcuts_add_bookmarks (impl);
1820 bookmarks_check_add_sensitivity (impl);
1821 bookmarks_check_remove_sensitivity (impl);
1824 /* Sets the file chooser to multiple selection mode */
1826 set_select_multiple (GtkFileChooserDefault *impl,
1827 gboolean select_multiple,
1828 gboolean property_notify)
1830 GtkTreeSelection *selection;
1831 GtkSelectionMode mode;
1833 if (select_multiple == impl->select_multiple)
1836 impl->select_multiple = select_multiple;
1838 mode = select_multiple ? GTK_SELECTION_MULTIPLE : GTK_SELECTION_BROWSE;
1840 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->tree));
1841 gtk_tree_selection_set_mode (selection, mode);
1843 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
1844 gtk_tree_selection_set_mode (selection, mode);
1846 g_object_notify (G_OBJECT (impl), "select-multiple");
1848 /* FIXME #132255: See note in check_preview_change() */
1849 check_preview_change (impl);
1853 set_file_system_backend (GtkFileChooserDefault *impl,
1854 const char *backend)
1856 if (impl->file_system)
1858 g_signal_handler_disconnect (impl->file_system, impl->volumes_changed_id);
1859 impl->volumes_changed_id = 0;
1860 g_signal_handler_disconnect (impl->file_system, impl->bookmarks_changed_id);
1861 impl->bookmarks_changed_id = 0;
1862 g_object_unref (impl->file_system);
1865 impl->file_system = NULL;
1867 impl->file_system = _gtk_file_system_create (backend);
1869 if (!impl->file_system)
1871 #if defined (G_OS_UNIX)
1872 impl->file_system = gtk_file_system_unix_new ();
1873 #elif defined (G_OS_WIN32)
1874 impl->file_system = gtk_file_system_win32_new ();
1876 #error "No default filesystem implementation on the platform"
1880 if (impl->file_system)
1882 impl->volumes_changed_id = g_signal_connect (impl->file_system, "volumes-changed",
1883 G_CALLBACK (volumes_changed_cb),
1885 impl->bookmarks_changed_id = g_signal_connect (impl->file_system, "bookmarks-changed",
1886 G_CALLBACK (bookmarks_changed_cb),
1892 gtk_file_chooser_default_set_property (GObject *object,
1894 const GValue *value,
1898 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (object);
1902 case GTK_FILE_CHOOSER_PROP_ACTION:
1903 impl->action = g_value_get_enum (value);
1904 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
1906 gtk_widget_hide (impl->hpaned);
1907 gtk_widget_show (impl->save_widgets);
1908 gtk_widget_show (impl->new_folder_button);
1910 if (impl->select_multiple)
1912 g_warning ("Save mode cannot be set in conjunction with multiple selection mode. "
1913 "Re-setting to single selection mode.");
1914 set_select_multiple (impl, FALSE, TRUE);
1919 gtk_widget_hide (impl->save_widgets);
1920 gtk_widget_show (impl->hpaned);
1922 if (impl->folder_mode)
1923 gtk_widget_show (impl->new_folder_button);
1925 gtk_widget_hide (impl->new_folder_button);
1929 case GTK_FILE_CHOOSER_PROP_FILE_SYSTEM_BACKEND:
1930 set_file_system_backend (impl, g_value_get_string (value));
1932 case GTK_FILE_CHOOSER_PROP_FILTER:
1933 set_current_filter (impl, g_value_get_object (value));
1935 case GTK_FILE_CHOOSER_PROP_FOLDER_MODE:
1937 gboolean folder_mode = g_value_get_boolean (value);
1938 if (folder_mode != impl->folder_mode)
1940 impl->folder_mode = folder_mode;
1941 if (impl->folder_mode)
1943 gtk_widget_hide (impl->list_scrollwin);
1944 gtk_widget_show (impl->tree_scrollwin);
1945 gtk_widget_show (impl->new_folder_button);
1949 gtk_widget_hide (impl->tree_scrollwin);
1950 gtk_widget_show (impl->list_scrollwin);
1951 gtk_widget_hide (impl->new_folder_button);
1956 case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
1957 impl->local_only = g_value_get_boolean (value);
1959 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
1960 set_preview_widget (impl, g_value_get_object (value));
1962 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE:
1963 impl->preview_widget_active = g_value_get_boolean (value);
1964 update_preview_widget_visibility (impl);
1966 case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
1967 set_extra_widget (impl, g_value_get_object (value));
1969 case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
1971 gboolean select_multiple = g_value_get_boolean (value);
1972 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE && select_multiple)
1974 g_warning ("Multiple selection mode is not allowed in Save mode");
1978 set_select_multiple (impl, select_multiple, FALSE);
1981 case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN:
1983 gboolean show_hidden = g_value_get_boolean (value);
1984 if (show_hidden != impl->show_hidden)
1986 impl->show_hidden = show_hidden;
1987 _gtk_file_system_model_set_show_hidden (impl->tree_model, show_hidden);
1988 _gtk_file_system_model_set_show_hidden (impl->list_model, show_hidden);
1993 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1999 gtk_file_chooser_default_get_property (GObject *object,
2004 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (object);
2008 case GTK_FILE_CHOOSER_PROP_ACTION:
2009 g_value_set_enum (value, impl->action);
2011 case GTK_FILE_CHOOSER_PROP_FILTER:
2012 g_value_set_object (value, impl->current_filter);
2014 case GTK_FILE_CHOOSER_PROP_FOLDER_MODE:
2015 g_value_set_boolean (value, impl->folder_mode);
2017 case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
2018 g_value_set_boolean (value, impl->local_only);
2020 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
2021 g_value_set_object (value, impl->preview_widget);
2023 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE:
2024 g_value_set_boolean (value, impl->preview_widget_active);
2026 case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
2027 g_value_set_object (value, impl->extra_widget);
2029 case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
2030 g_value_set_boolean (value, impl->select_multiple);
2032 case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN:
2033 g_value_set_boolean (value, impl->show_hidden);
2036 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2041 /* We override show-all since we have internal widgets that
2042 * shouldn't be shown when you call show_all(), like the filter
2046 gtk_file_chooser_default_show_all (GtkWidget *widget)
2048 gtk_widget_show (widget);
2052 expand_and_select_func (GtkFileSystemModel *model,
2057 GtkFileChooserDefault *impl = user_data;
2058 GtkTreeView *tree_view;
2060 if (model == impl->tree_model)
2061 tree_view = GTK_TREE_VIEW (impl->tree);
2063 tree_view = GTK_TREE_VIEW (impl->list);
2065 gtk_tree_view_expand_to_path (tree_view, path);
2066 gtk_tree_view_expand_row (tree_view, path, FALSE);
2067 gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE);
2068 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (impl->tree), path, NULL, TRUE, 0.3, 0.5);
2072 list_model_filter_func (GtkFileSystemModel *model,
2074 const GtkFileInfo *file_info,
2077 GtkFileChooserDefault *impl = user_data;
2078 GtkFileFilterInfo filter_info;
2079 GtkFileFilterFlags needed;
2082 if (!impl->current_filter)
2085 if (gtk_file_info_get_is_folder (file_info))
2088 filter_info.contains = GTK_FILE_FILTER_DISPLAY_NAME | GTK_FILE_FILTER_MIME_TYPE;
2090 needed = gtk_file_filter_get_needed (impl->current_filter);
2092 filter_info.display_name = gtk_file_info_get_display_name (file_info);
2093 filter_info.mime_type = gtk_file_info_get_mime_type (file_info);
2095 if (needed & GTK_FILE_FILTER_FILENAME)
2097 filter_info.filename = gtk_file_system_path_to_filename (impl->file_system, path);
2098 if (filter_info.filename)
2099 filter_info.contains |= GTK_FILE_FILTER_FILENAME;
2102 filter_info.filename = NULL;
2104 if (needed & GTK_FILE_FILTER_URI)
2106 filter_info.uri = gtk_file_system_path_to_uri (impl->file_system, path);
2107 if (filter_info.filename)
2108 filter_info.contains |= GTK_FILE_FILTER_URI;
2111 filter_info.uri = NULL;
2113 result = gtk_file_filter_filter (impl->current_filter, &filter_info);
2115 if (filter_info.filename)
2116 g_free ((gchar *)filter_info.filename);
2117 if (filter_info.uri)
2118 g_free ((gchar *)filter_info.uri);
2124 install_list_model_filter (GtkFileChooserDefault *impl)
2126 if (impl->current_filter)
2127 _gtk_file_system_model_set_filter (impl->list_model,
2128 list_model_filter_func,
2132 #define COMPARE_DIRECTORIES \
2133 GtkFileChooserDefault *impl = user_data; \
2134 const GtkFileInfo *info_a = _gtk_file_system_model_get_info (impl->list_model, a); \
2135 const GtkFileInfo *info_b = _gtk_file_system_model_get_info (impl->list_model, b); \
2136 gboolean dir_a, dir_b; \
2139 dir_a = gtk_file_info_get_is_folder (info_a); \
2141 return impl->list_sort_ascending ? -1 : 1; \
2144 dir_b = gtk_file_info_get_is_folder (info_b); \
2146 return impl->list_sort_ascending ? 1 : -1; \
2148 if (dir_a != dir_b) \
2149 return impl->list_sort_ascending ? (dir_a ? -1 : 1) : (dir_a ? 1 : -1) /* Directories *always* go first */
2151 /* Sort callback for the filename column */
2153 name_sort_func (GtkTreeModel *model,
2158 COMPARE_DIRECTORIES;
2160 return strcmp (gtk_file_info_get_display_key (info_a), gtk_file_info_get_display_key (info_b));
2163 /* Sort callback for the size column */
2165 size_sort_func (GtkTreeModel *model,
2170 COMPARE_DIRECTORIES;
2173 gint64 size_a = gtk_file_info_get_size (info_a);
2174 gint64 size_b = gtk_file_info_get_size (info_b);
2176 return size_a > size_b ? -1 : (size_a == size_b ? 0 : 1);
2180 /* Sort callback for the mtime column */
2182 mtime_sort_func (GtkTreeModel *model,
2187 COMPARE_DIRECTORIES;
2190 GtkFileTime ta = gtk_file_info_get_modification_time (info_a);
2191 GtkFileTime tb = gtk_file_info_get_modification_time (info_b);
2193 return ta > tb ? -1 : (ta == tb ? 0 : 1);
2197 /* Callback used when the sort column changes. We cache the sort order for use
2198 * in name_sort_func().
2201 list_sort_column_changed_cb (GtkTreeSortable *sortable,
2202 GtkFileChooserDefault *impl)
2204 GtkSortType sort_type;
2206 if (gtk_tree_sortable_get_sort_column_id (sortable, NULL, &sort_type))
2207 impl->list_sort_ascending = (sort_type == GTK_SORT_ASCENDING);
2210 /* Gets rid of the old list model and creates a new one for the current folder */
2212 set_list_model (GtkFileChooserDefault *impl)
2214 if (impl->list_model)
2216 g_object_unref (impl->list_model);
2217 g_object_unref (impl->sort_model);
2220 impl->list_model = _gtk_file_system_model_new (impl->file_system,
2221 impl->current_folder, 0,
2223 _gtk_file_system_model_set_show_hidden (impl->list_model, impl->show_hidden);
2224 install_list_model_filter (impl);
2226 impl->sort_model = (GtkTreeModelSort *)gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (impl->list_model));
2227 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_NAME, name_sort_func, impl, NULL);
2228 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_SIZE, size_sort_func, impl, NULL);
2229 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_MTIME, mtime_sort_func, impl, NULL);
2230 gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (impl->sort_model), NULL, NULL, NULL);
2231 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_NAME, GTK_SORT_ASCENDING);
2232 impl->list_sort_ascending = TRUE;
2234 g_signal_connect (impl->sort_model, "sort_column_changed",
2235 G_CALLBACK (list_sort_column_changed_cb), impl);
2237 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->list),
2238 GTK_TREE_MODEL (impl->sort_model));
2239 gtk_tree_view_columns_autosize (GTK_TREE_VIEW (impl->list));
2240 gtk_tree_view_set_search_column (GTK_TREE_VIEW (impl->list),
2241 GTK_FILE_SYSTEM_MODEL_DISPLAY_NAME);
2244 /* Gets rid of the old folder tree model and creates a new one for the volume
2245 * corresponding to the specified path.
2248 set_tree_model (GtkFileChooserDefault *impl, const GtkFilePath *path)
2250 GtkFileSystemVolume *volume;
2251 GtkFilePath *base_path, *parent_path;
2255 volume = gtk_file_system_get_volume_for_path (impl->file_system, path);
2258 base_path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
2260 if (base_path == NULL)
2262 base_path = gtk_file_path_copy (path);
2263 while (gtk_file_system_get_parent (impl->file_system,
2267 parent_path != NULL)
2269 gtk_file_path_free (base_path);
2270 base_path = parent_path;
2274 if (impl->current_volume_path && gtk_file_path_compare (base_path, impl->current_volume_path) == 0)
2277 if (impl->tree_model)
2278 g_object_unref (impl->tree_model);
2280 impl->current_volume_path = gtk_file_path_copy (base_path);
2282 impl->tree_model = _gtk_file_system_model_new (impl->file_system, impl->current_volume_path, -1,
2283 GTK_FILE_INFO_DISPLAY_NAME);
2284 _gtk_file_system_model_set_show_files (impl->tree_model, FALSE);
2285 _gtk_file_system_model_set_show_hidden (impl->tree_model, impl->show_hidden);
2287 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->tree),
2288 GTK_TREE_MODEL (impl->tree_model));
2292 gtk_file_path_free (base_path);
2294 gtk_file_system_volume_free (impl->file_system, volume);
2298 update_chooser_entry (GtkFileChooserDefault *impl)
2300 GtkTreeSelection *selection;
2301 const GtkFileInfo *info;
2303 GtkTreeIter child_iter;
2305 if (impl->action != GTK_FILE_CHOOSER_ACTION_SAVE)
2308 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
2310 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
2313 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
2317 info = _gtk_file_system_model_get_info (impl->list_model, &child_iter);
2319 if (!gtk_file_info_get_is_folder (info))
2320 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->entry),
2321 gtk_file_info_get_display_name (info));
2325 gtk_file_chooser_default_set_current_folder (GtkFileChooser *chooser,
2326 const GtkFilePath *path)
2328 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
2330 if (impl->current_folder)
2331 gtk_file_path_free (impl->current_folder);
2333 impl->current_folder = gtk_file_path_copy (path);
2335 /* Change the current folder label */
2336 gtk_path_bar_set_path (GTK_PATH_BAR (impl->path_bar), path, impl->file_system, NULL);
2338 /* Update the folder tree */
2340 if (!impl->changing_folder)
2342 impl->changing_folder = TRUE;
2343 set_tree_model (impl, impl->current_folder);
2344 _gtk_file_system_model_path_do (impl->tree_model, path,
2345 expand_and_select_func, impl);
2346 impl->changing_folder = FALSE;
2349 /* Notify the save entry */
2351 _gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->entry), impl->current_folder);
2353 /* Create a new list model */
2354 set_list_model (impl);
2356 /* Refresh controls */
2358 shortcuts_unselect_all (impl);
2360 g_signal_emit_by_name (impl, "current-folder-changed", 0);
2362 update_chooser_entry (impl);
2363 check_preview_change (impl);
2364 bookmarks_check_add_sensitivity (impl);
2366 g_signal_emit_by_name (impl, "selection-changed", 0);
2369 static GtkFilePath *
2370 gtk_file_chooser_default_get_current_folder (GtkFileChooser *chooser)
2372 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
2374 return gtk_file_path_copy (impl->current_folder);
2378 gtk_file_chooser_default_set_current_name (GtkFileChooser *chooser,
2381 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
2383 g_return_if_fail (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE);
2385 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->entry), name);
2389 select_func (GtkFileSystemModel *model,
2394 GtkFileChooserDefault *impl = user_data;
2395 GtkTreeView *tree_view = GTK_TREE_VIEW (impl->list);
2396 GtkTreePath *sorted_path;
2398 sorted_path = gtk_tree_model_sort_convert_child_path_to_path (impl->sort_model, path);
2399 gtk_tree_view_set_cursor (tree_view, sorted_path, NULL, FALSE);
2400 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (impl->tree), sorted_path, NULL, TRUE, 0.3, 0.0);
2401 gtk_tree_path_free (sorted_path);
2405 gtk_file_chooser_default_select_path (GtkFileChooser *chooser,
2406 const GtkFilePath *path)
2408 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
2409 GtkFilePath *parent_path;
2413 if (!gtk_file_system_get_parent (impl->file_system, path, &parent_path, &error))
2415 error_getting_info_dialog (impl, path, error);
2421 _gtk_file_chooser_set_current_folder_path (chooser, path);
2425 _gtk_file_chooser_set_current_folder_path (chooser, parent_path);
2426 gtk_file_path_free (parent_path);
2427 _gtk_file_system_model_path_do (impl->list_model, path,
2433 unselect_func (GtkFileSystemModel *model,
2438 GtkFileChooserDefault *impl = user_data;
2439 GtkTreeView *tree_view = GTK_TREE_VIEW (impl->list);
2440 GtkTreePath *sorted_path;
2442 sorted_path = gtk_tree_model_sort_convert_child_path_to_path (impl->sort_model,
2444 gtk_tree_selection_unselect_path (gtk_tree_view_get_selection (tree_view),
2446 gtk_tree_path_free (sorted_path);
2450 gtk_file_chooser_default_unselect_path (GtkFileChooser *chooser,
2451 const GtkFilePath *path)
2453 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
2455 _gtk_file_system_model_path_do (impl->list_model, path,
2456 unselect_func, impl);
2460 gtk_file_chooser_default_select_all (GtkFileChooser *chooser)
2462 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
2463 if (impl->select_multiple)
2465 GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
2466 gtk_tree_selection_select_all (selection);
2471 gtk_file_chooser_default_unselect_all (GtkFileChooser *chooser)
2473 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
2474 GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
2476 gtk_tree_selection_unselect_all (selection);
2479 struct get_paths_closure {
2480 GtkFileChooserDefault *impl;
2482 GtkFilePath *path_from_entry;
2486 get_paths_foreach (GtkTreeModel *model,
2491 struct get_paths_closure *info;
2492 const GtkFilePath *file_path;
2493 GtkFileSystemModel *fs_model;
2494 GtkTreeIter sel_iter;
2498 if (info->impl->folder_mode)
2500 fs_model = info->impl->tree_model;
2505 fs_model = info->impl->list_model;
2506 gtk_tree_model_sort_convert_iter_to_child_iter (info->impl->sort_model, &sel_iter, iter);
2509 file_path = _gtk_file_system_model_get_path (fs_model, &sel_iter);
2511 if (!info->path_from_entry
2512 || gtk_file_path_compare (info->path_from_entry, file_path) != 0)
2513 info->result = g_slist_prepend (info->result, gtk_file_path_copy (file_path));
2517 gtk_file_chooser_default_get_paths (GtkFileChooser *chooser)
2519 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
2520 struct get_paths_closure info;
2524 info.path_from_entry = NULL;
2526 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
2528 GtkFileChooserEntry *chooser_entry;
2529 const GtkFilePath *folder_path;
2530 const gchar *file_part;
2532 chooser_entry = GTK_FILE_CHOOSER_ENTRY (impl->entry);
2533 folder_path = _gtk_file_chooser_entry_get_current_folder (chooser_entry);
2534 file_part = _gtk_file_chooser_entry_get_file_part (chooser_entry);
2536 if (file_part != NULL && file_part[0] != '\0')
2538 GtkFilePath *selected;
2539 GError *error = NULL;
2541 selected = gtk_file_system_make_path (impl->file_system, folder_path, file_part, &error);
2545 error_building_filename_dialog (impl, folder_path, file_part, error);
2549 info.path_from_entry = selected;
2553 if (!info.path_from_entry || impl->select_multiple)
2555 GtkTreeSelection *selection;
2559 if (impl->folder_mode)
2561 if (impl->tree_model)
2562 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->tree));
2566 if (impl->sort_model)
2567 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
2571 gtk_tree_selection_selected_foreach (selection, get_paths_foreach, &info);
2574 if (info.path_from_entry)
2575 info.result = g_slist_prepend (info.result, info.path_from_entry);
2577 return g_slist_reverse (info.result);
2580 static GtkFilePath *
2581 gtk_file_chooser_default_get_preview_path (GtkFileChooser *chooser)
2583 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
2585 if (impl->preview_path)
2586 return gtk_file_path_copy (impl->preview_path);
2591 static GtkFileSystem *
2592 gtk_file_chooser_default_get_file_system (GtkFileChooser *chooser)
2594 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
2596 return impl->file_system;
2599 /* Shows or hides the filter widgets */
2601 toolbar_show_filters (GtkFileChooserDefault *impl,
2605 gtk_widget_show (impl->filter_combo);
2607 gtk_widget_hide (impl->filter_combo);
2611 gtk_file_chooser_default_add_filter (GtkFileChooser *chooser,
2612 GtkFileFilter *filter)
2614 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
2617 if (g_slist_find (impl->filters, filter))
2619 g_warning ("gtk_file_chooser_add_filter() called on filter already in list\n");
2623 g_object_ref (filter);
2624 gtk_object_sink (GTK_OBJECT (filter));
2625 impl->filters = g_slist_append (impl->filters, filter);
2627 name = gtk_file_filter_get_name (filter);
2629 name = "Untitled filter"; /* Place-holder, doesn't need to be marked for translation */
2631 gtk_combo_box_append_text (GTK_COMBO_BOX (impl->filter_combo), name);
2633 if (!g_slist_find (impl->filters, impl->current_filter))
2634 set_current_filter (impl, filter);
2636 toolbar_show_filters (impl, TRUE);
2640 gtk_file_chooser_default_remove_filter (GtkFileChooser *chooser,
2641 GtkFileFilter *filter)
2643 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
2644 GtkTreeModel *model;
2648 filter_index = g_slist_index (impl->filters, filter);
2650 if (filter_index < 0)
2652 g_warning ("gtk_file_chooser_remove_filter() called on filter not in list\n");
2656 impl->filters = g_slist_remove (impl->filters, filter);
2658 if (filter == impl->current_filter)
2661 set_current_filter (impl, impl->filters->data);
2663 set_current_filter (impl, NULL);
2666 /* Remove row from the combo box */
2667 model = gtk_combo_box_get_model (GTK_COMBO_BOX (impl->filter_combo));
2668 gtk_tree_model_iter_nth_child (model, &iter, NULL, filter_index);
2669 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
2671 g_object_unref (filter);
2674 toolbar_show_filters (impl, FALSE);
2678 gtk_file_chooser_default_list_filters (GtkFileChooser *chooser)
2680 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
2682 return g_slist_copy (impl->filters);
2685 /* Returns the position in the shortcuts tree where the nth specified shortcut would appear */
2687 shortcuts_get_pos_for_shortcut_folder (GtkFileChooserDefault *impl,
2690 return pos + shortcuts_get_index (impl, SHORTCUTS_SHORTCUTS);
2694 gtk_file_chooser_default_add_shortcut_folder (GtkFileChooser *chooser,
2695 const GtkFilePath *path,
2698 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
2702 pos = shortcuts_get_pos_for_shortcut_folder (impl, impl->num_shortcuts);
2704 result = shortcuts_insert_path (impl, pos, FALSE, NULL, path, NULL, FALSE, error);
2707 impl->num_shortcuts++;
2713 gtk_file_chooser_default_remove_shortcut_folder (GtkFileChooser *chooser,
2714 const GtkFilePath *path,
2717 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
2722 if (impl->num_shortcuts == 0)
2725 pos = shortcuts_get_pos_for_shortcut_folder (impl, 0);
2726 if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos))
2727 g_assert_not_reached ();
2729 for (i = 0; i < impl->num_shortcuts; i++)
2731 GtkFilePath *shortcut;
2733 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, SHORTCUTS_COL_PATH, &shortcut, -1);
2734 g_assert (shortcut != NULL);
2736 if (gtk_file_path_compare (shortcut, path) == 0)
2738 /* The other columns are freed by the GtkTreeStore */
2739 gtk_file_path_free (shortcut);
2740 gtk_tree_store_remove (impl->shortcuts_model, &iter);
2741 impl->num_shortcuts--;
2745 if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
2746 g_assert_not_reached ();
2752 GTK_FILE_CHOOSER_ERROR,
2753 GTK_FILE_CHOOSER_ERROR_NONEXISTENT,
2754 _("shortcut %s does not exist"),
2755 gtk_file_path_get_string (path));
2761 gtk_file_chooser_default_list_shortcut_folders (GtkFileChooser *chooser)
2763 GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
2769 pos = shortcuts_get_pos_for_shortcut_folder (impl, 0);
2770 if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos))
2771 g_assert_not_reached ();
2775 for (i = 0; i < impl->num_shortcuts; i++)
2777 GtkFilePath *shortcut;
2779 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, SHORTCUTS_COL_PATH, &shortcut, -1);
2780 g_assert (shortcut != NULL);
2782 list = g_slist_prepend (list, gtk_file_path_copy (shortcut));
2784 if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
2785 g_assert_not_reached ();
2788 return g_slist_reverse (list);
2792 set_current_filter (GtkFileChooserDefault *impl,
2793 GtkFileFilter *filter)
2795 if (impl->current_filter != filter)
2799 /* If we have filters, new filter must be one of them
2801 filter_index = g_slist_index (impl->filters, filter);
2802 if (impl->filters && filter_index < 0)
2805 if (impl->current_filter)
2806 g_object_unref (impl->current_filter);
2807 impl->current_filter = filter;
2808 if (impl->current_filter)
2810 g_object_ref (impl->current_filter);
2811 gtk_object_sink (GTK_OBJECT (filter));
2815 gtk_combo_box_set_active (GTK_COMBO_BOX (impl->filter_combo),
2818 install_list_model_filter (impl);
2820 g_object_notify (G_OBJECT (impl), "filter");
2825 open_and_close (GtkTreeView *tree_view,
2826 GtkTreePath *target_path)
2828 GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
2832 path = gtk_tree_path_new ();
2833 gtk_tree_path_append_index (path, 0);
2835 gtk_tree_model_get_iter (model, &iter, path);
2839 if (gtk_tree_path_is_ancestor (path, target_path) ||
2840 gtk_tree_path_compare (path, target_path) == 0)
2842 GtkTreeIter child_iter;
2843 gtk_tree_view_expand_row (tree_view, path, FALSE);
2844 if (gtk_tree_model_iter_children (model, &child_iter, &iter))
2847 gtk_tree_path_down (path);
2852 gtk_tree_view_collapse_row (tree_view, path);
2856 GtkTreeIter parent_iter;
2857 GtkTreeIter next_iter;
2860 if (gtk_tree_model_iter_next (model, &next_iter))
2863 gtk_tree_path_next (path);
2867 if (!gtk_tree_model_iter_parent (model, &parent_iter, &iter))
2871 gtk_tree_path_up (path);
2878 gtk_tree_path_free (path);
2882 filter_combo_changed (GtkComboBox *combo_box,
2883 GtkFileChooserDefault *impl)
2885 gint new_index = gtk_combo_box_get_active (combo_box);
2886 GtkFileFilter *new_filter = g_slist_nth_data (impl->filters, new_index);
2888 set_current_filter (impl, new_filter);
2892 check_preview_change (GtkFileChooserDefault *impl)
2894 const GtkFilePath *new_path = NULL;
2896 /* FIXME #132255: Fixing preview for multiple selection involves getting the
2897 * full selection and diffing to find out what the most recently selected file
2898 * is; there is logic in GtkFileSelection that probably can be
2901 if (impl->sort_model && !impl->select_multiple)
2903 GtkTreeSelection *selection;
2906 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
2907 if (gtk_tree_selection_get_selected (selection, NULL, &iter))
2909 GtkTreeIter child_iter;
2911 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
2912 &child_iter, &iter);
2914 new_path = _gtk_file_system_model_get_path (impl->list_model, &child_iter);
2918 if (new_path != impl->preview_path &&
2919 !(new_path && impl->preview_path &&
2920 gtk_file_path_compare (new_path, impl->preview_path) == 0))
2922 if (impl->preview_path)
2923 gtk_file_path_free (impl->preview_path);
2926 impl->preview_path = gtk_file_path_copy (new_path);
2928 impl->preview_path = NULL;
2930 g_signal_emit_by_name (impl, "update-preview");
2935 tree_selection_changed (GtkTreeSelection *selection,
2936 GtkFileChooserDefault *impl)
2939 const GtkFilePath *file_path;
2942 /* FIXME #132255: Fixing this for multiple selection involves getting the full
2943 * selection and diffing to find out what the most recently selected file is;
2944 * there is logic in GtkFileSelection that probably can be copied;
2945 * check_preview_change() is similar.
2947 if (impl->select_multiple
2948 || !gtk_tree_selection_get_selected (selection, NULL, &iter))
2951 file_path = _gtk_file_system_model_get_path (impl->tree_model, &iter);
2952 if (impl->current_folder && gtk_file_path_compare (file_path, impl->current_folder) == 0)
2955 /* Close the tree up to only the parents of the newly selected
2956 * node and it's immediate children are visible.
2958 path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->tree_model), &iter);
2959 open_and_close (GTK_TREE_VIEW (impl->tree), path);
2960 gtk_tree_path_free (path);
2962 if (!impl->changing_folder)
2963 _gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (impl), file_path);
2966 /* Activates a volume by mounting it if necessary and then switching to its
2970 shortcuts_activate_volume (GtkFileChooserDefault *impl,
2971 GtkFileSystemVolume *volume)
2975 if (!gtk_file_system_volume_get_is_mounted (impl->file_system, volume))
2980 if (!gtk_file_system_volume_mount (impl->file_system, volume, &error))
2984 msg = g_strdup_printf ("Could not mount %s:\n%s",
2985 gtk_file_system_volume_get_display_name (impl->file_system, volume),
2987 error_message (impl, msg);
2989 g_error_free (error);
2995 path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
2996 _gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (impl), path);
2997 gtk_file_path_free (path);
3000 /* Callback used when a row in the shortcuts list is activated */
3002 shortcuts_row_activated_cb (GtkTreeView *tree_view,
3004 GtkTreeViewColumn *column,
3005 GtkFileChooserDefault *impl)
3008 int selected, start_row;
3011 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->shortcuts_model), &iter, path))
3014 selected = *gtk_tree_path_get_indices (path);
3016 if (selected == shortcuts_get_index (impl, SHORTCUTS_SEPARATOR))
3019 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, SHORTCUTS_COL_PATH, &data, -1);
3021 start_row = shortcuts_get_index (impl, SHORTCUTS_VOLUMES);
3022 if (selected >= start_row && selected < start_row + impl->num_volumes)
3024 GtkFileSystemVolume *volume;
3027 shortcuts_activate_volume (impl, volume);
3031 GtkFilePath *file_path;
3034 _gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (impl), file_path);
3039 shortcuts_select_func (GtkTreeSelection *selection,
3040 GtkTreeModel *model,
3042 gboolean path_currently_selected,
3045 GtkFileChooserDefault *impl = data;
3047 return (*gtk_tree_path_get_indices (path) != shortcuts_get_index (impl, SHORTCUTS_SEPARATOR));
3051 list_selection_changed (GtkTreeSelection *selection,
3052 GtkFileChooserDefault *impl)
3054 /* See if we are in the new folder editable row for Save mode */
3055 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
3057 GtkTreeSelection *selection;
3058 GtkTreeIter iter, child_iter;
3059 const GtkFileInfo *info;
3061 g_assert (!impl->select_multiple);
3062 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
3063 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
3066 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
3070 info = _gtk_file_system_model_get_info (impl->list_model, &child_iter);
3072 return; /* We are on the editable row for New Folder */
3075 update_chooser_entry (impl);
3076 check_preview_change (impl);
3078 g_signal_emit_by_name (impl, "selection-changed", 0);
3081 /* Callback used when a row in the file list is activated */
3083 list_row_activated (GtkTreeView *tree_view,
3085 GtkTreeViewColumn *column,
3086 GtkFileChooserDefault *impl)
3088 GtkTreeIter iter, child_iter;
3089 const GtkFileInfo *info;
3091 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->sort_model), &iter, path))
3094 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model, &child_iter, &iter);
3096 info = _gtk_file_system_model_get_info (impl->list_model, &child_iter);
3098 if (gtk_file_info_get_is_folder (info))
3100 const GtkFilePath *file_path;
3102 file_path = _gtk_file_system_model_get_path (impl->list_model, &child_iter);
3103 _gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (impl), file_path);
3108 g_signal_emit_by_name (impl, "file-activated");
3112 path_bar_clicked (GtkPathBar *path_bar,
3113 GtkFilePath *file_path,
3114 GtkFileChooserDefault *impl)
3116 _gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (impl), file_path);
3119 static const GtkFileInfo *
3120 get_list_file_info (GtkFileChooserDefault *impl,
3123 GtkTreeIter child_iter;
3125 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
3129 return _gtk_file_system_model_get_info (impl->list_model, &child_iter);
3133 tree_name_data_func (GtkTreeViewColumn *tree_column,
3134 GtkCellRenderer *cell,
3135 GtkTreeModel *tree_model,
3139 GtkFileChooserDefault *impl = data;
3140 const GtkFileInfo *info = _gtk_file_system_model_get_info (impl->tree_model, iter);
3145 "text", gtk_file_info_get_display_name (info),
3151 list_icon_data_func (GtkTreeViewColumn *tree_column,
3152 GtkCellRenderer *cell,
3153 GtkTreeModel *tree_model,
3157 GtkFileChooserDefault *impl = data;
3158 GtkTreeIter child_iter;
3159 const GtkFilePath *path;
3162 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
3165 path = _gtk_file_system_model_get_path (impl->list_model, &child_iter);
3169 /* FIXME: NULL GError */
3170 pixbuf = gtk_file_system_render_icon (impl->file_system, path, GTK_WIDGET (impl), ICON_SIZE, NULL);
3176 g_object_unref (pixbuf);
3179 /* Sets a cellrenderer's text, making it bold if the GtkFileInfo is a folder */
3181 set_cell_text_bold_if_folder (const GtkFileInfo *info, GtkCellRenderer *cell, const char *text)
3185 "weight", gtk_file_info_get_is_folder (info) ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL,
3190 list_name_data_func (GtkTreeViewColumn *tree_column,
3191 GtkCellRenderer *cell,
3192 GtkTreeModel *tree_model,
3196 GtkFileChooserDefault *impl = data;
3197 const GtkFileInfo *info = get_list_file_info (impl, iter);
3202 "text", _("Type name of new folder"),
3207 set_cell_text_bold_if_folder (info, cell, gtk_file_info_get_display_name (info));
3212 list_size_data_func (GtkTreeViewColumn *tree_column,
3213 GtkCellRenderer *cell,
3214 GtkTreeModel *tree_model,
3218 GtkFileChooserDefault *impl = data;
3219 const GtkFileInfo *info = get_list_file_info (impl, iter);
3223 if (!info || gtk_file_info_get_is_folder (info))
3226 size = gtk_file_info_get_size (info);
3228 if (size < (gint64)1024)
3229 str = g_strdup_printf (ngettext ("%d byte", "%d bytes", (gint)size), (gint)size);
3230 else if (size < (gint64)1024*1024)
3231 str = g_strdup_printf (_("%.1f K"), size / (1024.));
3232 else if (size < (gint64)1024*1024*1024)
3233 str = g_strdup_printf (_("%.1f M"), size / (1024.*1024.));
3235 str = g_strdup_printf (_("%.1f G"), size / (1024.*1024.*1024.));
3245 /* Tree column data callback for the file list; fetches the mtime of a file */
3247 list_mtime_data_func (GtkTreeViewColumn *tree_column,
3248 GtkCellRenderer *cell,
3249 GtkTreeModel *tree_model,
3253 GtkFileChooserDefault *impl;
3254 const GtkFileInfo *info;
3255 GtkFileTime time_mtime, time_now;
3262 info = get_list_file_info (impl, iter);
3271 time_mtime = gtk_file_info_get_modification_time (info);
3272 g_date_set_time (&mtime, (GTime) time_mtime);
3274 time_now = (GTime ) time (NULL);
3275 g_date_set_time (&now, (GTime) time_now);
3277 days_diff = g_date_get_julian (&now) - g_date_get_julian (&mtime);
3280 strcpy (buf, _("Today"));
3281 else if (days_diff == 1)
3282 strcpy (buf, _("Yesterday"));
3287 if (days_diff > 1 && days_diff < 7)
3288 format = "%A"; /* Days from last week */
3290 format = _("%d/%b/%Y"); /* Any other date */
3292 if (g_date_strftime (buf, sizeof (buf), format, &mtime) == 0)
3293 strcpy (buf, _("Unknown"));
3296 set_cell_text_bold_if_folder (info, cell, buf);
3300 _gtk_file_chooser_default_new (const char *file_system)
3302 return g_object_new (GTK_TYPE_FILE_CHOOSER_DEFAULT,
3303 "file-system-backend", file_system,
3308 location_entry_create (GtkFileChooserDefault *impl)
3312 entry = _gtk_file_chooser_entry_new ();
3313 gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
3314 _gtk_file_chooser_entry_set_file_system (GTK_FILE_CHOOSER_ENTRY (entry), impl->file_system);
3315 _gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (entry), impl->current_folder);
3317 return GTK_WIDGET (entry);
3321 update_from_entry (GtkFileChooserDefault *impl,
3323 GtkFileChooserEntry *chooser_entry)
3325 const GtkFilePath *folder_path;
3326 const char *file_part;
3328 folder_path = _gtk_file_chooser_entry_get_current_folder (chooser_entry);
3329 file_part = _gtk_file_chooser_entry_get_file_part (chooser_entry);
3331 if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN && !folder_path)
3333 error_message_with_parent (parent,
3334 _("Cannot change to the folder you specified as it is an invalid path."));
3338 if (file_part[0] == '\0')
3340 _gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (impl), folder_path);
3345 GtkFileFolder *folder = NULL;
3346 GtkFilePath *subfolder_path = NULL;
3347 GtkFileInfo *info = NULL;
3350 /* If the file part is non-empty, we need to figure out if it refers to a
3351 * folder within folder. We could optimize the case here where the folder
3352 * is already loaded for one of our tree models.
3356 folder = gtk_file_system_get_folder (impl->file_system, folder_path, GTK_FILE_INFO_IS_FOLDER, &error);
3360 error_getting_info_dialog (impl, folder_path, error);
3365 subfolder_path = gtk_file_system_make_path (impl->file_system, folder_path, file_part, &error);
3367 if (!subfolder_path)
3371 msg = g_strdup_printf (_("Could not build file name from '%s' and '%s':\n%s"),
3372 gtk_file_path_get_string (folder_path),
3375 error_message (impl, msg);
3377 g_object_unref (folder);
3382 info = gtk_file_folder_get_info (folder, subfolder_path, &error);
3387 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
3389 g_object_unref (folder);
3390 gtk_file_path_free (subfolder_path);
3394 error_getting_info_dialog (impl, subfolder_path, error);
3395 g_object_unref (folder);
3396 gtk_file_path_free (subfolder_path);
3400 if (gtk_file_info_get_is_folder (info))
3401 _gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (impl), subfolder_path);
3403 _gtk_file_chooser_select_path (GTK_FILE_CHOOSER (impl), subfolder_path);
3405 g_object_unref (folder);
3406 gtk_file_path_free (subfolder_path);
3407 gtk_file_info_free (info);
3412 location_popup_handler (GtkFileChooserDefault *impl)
3415 GtkWidget *toplevel;
3422 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (impl));
3423 if (!GTK_WIDGET_TOPLEVEL (toplevel))
3426 dialog = gtk_dialog_new_with_buttons (_("Open Location"),
3427 GTK_WINDOW (toplevel),
3428 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
3429 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
3430 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
3432 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
3434 hbox = gtk_hbox_new (FALSE, 12);
3435 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, FALSE, FALSE, 0);
3437 label = gtk_label_new_with_mnemonic (_("_Location:"));
3438 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
3440 entry = location_entry_create (impl);
3441 gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
3442 gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
3446 gtk_widget_show_all (dialog);
3447 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
3448 update_from_entry (impl, GTK_WINDOW (dialog), GTK_FILE_CHOOSER_ENTRY (entry));
3450 gtk_widget_destroy (dialog);
3453 /* Handler for the "up-folder" keybinding signal */
3455 up_folder_handler (GtkFileChooserDefault *impl)
3457 GtkFilePath *parent_path;
3461 if (gtk_file_system_get_parent (impl->file_system, impl->current_folder, &parent_path, &error))
3463 if (parent_path) /* If we were on a root, parent_path will be NULL */
3465 _gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (impl), parent_path);
3466 gtk_file_path_free (parent_path);
3471 _("Could not go to the parent folder of %s:\n%s"),
3472 impl->current_folder,
3476 /* Handler for the "home-folder" keybinding signal */
3478 home_folder_handler (GtkFileChooserDefault *impl)
3482 /* Should we pull this information from impl->has_home and the shortcuts data
3483 * instead? Sounds like a bit of overkill...
3486 home = g_get_home_dir ();
3487 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl), home);