From 30c2fc3dc0496095cb0f0885ae17e77d68acf355 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Thu, 29 Sep 2011 14:36:35 -0500 Subject: Make GtkFileChooserDefault use GtkBookmarksManager It no longer uses GtkFileSystem to deal with bookmarks. Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 2db244dc04..e52c48ac74 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -333,6 +333,9 @@ static void gtk_file_chooser_default_get_default_size (GtkFileCh static gboolean gtk_file_chooser_default_should_respond (GtkFileChooserEmbed *chooser_embed); static void gtk_file_chooser_default_initial_focus (GtkFileChooserEmbed *chooser_embed); +static void volumes_bookmarks_changed_cb (GtkFileSystem *file_system, + GtkFileChooserDefault *impl); + static void add_selection_to_recent_list (GtkFileChooserDefault *impl); static void location_popup_handler (GtkFileChooserDefault *impl, @@ -723,6 +726,14 @@ gtk_file_chooser_embed_default_iface_init (GtkFileChooserEmbedIface *iface) iface->initial_focus = gtk_file_chooser_default_initial_focus; } +static void +bookmarks_changed_cb (gpointer data) +{ + GtkFileChooserDefault *impl = data; + + volumes_bookmarks_changed_cb (impl->file_system, impl); +} + static void _gtk_file_chooser_default_init (GtkFileChooserDefault *impl) { @@ -753,6 +764,8 @@ _gtk_file_chooser_default_init (GtkFileChooserDefault *impl) set_file_system_backend (impl); + impl->bookmarks_manager = _gtk_bookmarks_manager_new (bookmarks_changed_cb, impl); + profile_end ("end", NULL); } @@ -1852,7 +1865,7 @@ shortcuts_append_bookmarks (GtkFileChooserDefault *impl, if (shortcut_find_position (impl, file) != -1) continue; - label = _gtk_file_system_get_bookmark_label (impl->file_system, file); + label = _gtk_bookmarks_manager_get_bookmark_label (impl->bookmarks_manager, file); shortcuts_insert_file (impl, start_row + num_inserted, SHORTCUT_TYPE_FILE, NULL, file, label, TRUE, SHORTCUTS_BOOKMARKS); g_free (label); @@ -2062,7 +2075,7 @@ shortcuts_add_bookmarks (GtkFileChooserDefault *impl) impl->num_bookmarks = 0; shortcuts_insert_separator (impl, SHORTCUTS_BOOKMARKS_SEPARATOR); - bookmarks = _gtk_file_system_list_bookmarks (impl->file_system); + bookmarks = _gtk_bookmarks_manager_list_bookmarks (impl->bookmarks_manager); shortcuts_append_bookmarks (impl, bookmarks); g_slist_foreach (bookmarks, (GFunc) g_object_unref, NULL); g_slist_free (bookmarks); @@ -2471,7 +2484,7 @@ shortcuts_add_bookmark_from_file (GtkFileChooserDefault *impl, return FALSE; error = NULL; - if (!_gtk_file_system_insert_bookmark (impl->file_system, file, pos, &error)) + if (!_gtk_bookmarks_manager_insert_bookmark (impl->bookmarks_manager, file, pos, &error)) { error_adding_bookmark_dialog (impl, file, error); return FALSE; @@ -2574,7 +2587,7 @@ remove_selected_bookmarks (GtkFileChooserDefault *impl) file = col_data; error = NULL; - if (!_gtk_file_system_remove_bookmark (impl->file_system, file, &error)) + if (!_gtk_bookmarks_manager_remove_bookmark (impl->bookmarks_manager, file, &error)) error_removing_bookmark_dialog (impl, file, error); } @@ -3123,10 +3136,10 @@ shortcuts_reorder (GtkFileChooserDefault *impl, goto out; error = NULL; - if (_gtk_file_system_remove_bookmark (impl->file_system, file, &error)) + if (_gtk_bookmarks_manager_remove_bookmark (impl->bookmarks_manager, file, &error)) { shortcuts_add_bookmark_from_file (impl, file, new_position); - _gtk_file_system_set_bookmark_label (impl->file_system, file, name); + _gtk_bookmarks_manager_set_bookmark_label (impl->bookmarks_manager, file, name); } else error_adding_bookmark_dialog (impl, file, error); @@ -3483,7 +3496,7 @@ shortcuts_edited (GtkCellRenderer *cell, -1); gtk_tree_path_free (path); - _gtk_file_system_set_bookmark_label (impl->file_system, shortcut, new_text); + _gtk_bookmarks_manager_set_bookmark_label (impl->bookmarks_manager, shortcut, new_text); } static void @@ -5219,8 +5232,6 @@ set_file_system_backend (GtkFileChooserDefault *impl) g_signal_connect (impl->file_system, "volumes-changed", G_CALLBACK (volumes_bookmarks_changed_cb), impl); - g_signal_connect (impl->file_system, "bookmarks-changed", - G_CALLBACK (volumes_bookmarks_changed_cb), impl); profile_end ("end", NULL); } @@ -5812,6 +5823,12 @@ gtk_file_chooser_default_dispose (GObject *object) remove_settings_signal (impl, gtk_widget_get_screen (GTK_WIDGET (impl))); + if (impl->bookmarks_manager) + { + _gtk_bookmarks_manager_free (impl->bookmarks_manager); + impl->bookmarks_manager = NULL; + } + G_OBJECT_CLASS (_gtk_file_chooser_default_parent_class)->dispose (object); } -- cgit v1.2.1 From c242e88a3754fe344b902d6ee4602aed274e9427 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Thu, 17 Nov 2011 08:08:49 -0600 Subject: #if out a few things --- gtk/gtkfilechooserdefault.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index e52c48ac74..e4c6192b22 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -175,6 +175,7 @@ enum { static guint signals[LAST_SIGNAL] = { 0 }; +#if REMOVE_FOR_PLACES_SIDEBAR /* Column numbers for the shortcuts tree. Keep these in sync with shortcuts_model_create() */ enum { SHORTCUTS_COL_PIXBUF, @@ -194,6 +195,7 @@ typedef enum { SHORTCUT_TYPE_SEARCH, SHORTCUT_TYPE_RECENT } ShortcutType; +#endif #define MODEL_ATTRIBUTES "standard::name,standard::type,standard::display-name," \ "standard::is-hidden,standard::is-backup,standard::size," \ @@ -234,6 +236,7 @@ enum { GTK_TREE_MODEL_ROW, }; +#if REMOVE_FOR_PLACES_SIDEBAR /* Interesting places in the shortcuts bar */ typedef enum { SHORTCUTS_SEARCH, @@ -248,6 +251,7 @@ typedef enum { SHORTCUTS_CURRENT_FOLDER_SEPARATOR, SHORTCUTS_CURRENT_FOLDER } ShortcutsIndex; +#endif /* Icon size for if we can't get it from the theme */ #define FALLBACK_ICON_SIZE 16 @@ -440,6 +444,7 @@ static void unset_file_system_backend (GtkFileChooserDefault *impl); +#if REMOVE_FOR_PLACES_SIDEBAR /* Drag and drop interface declarations */ typedef struct { @@ -466,6 +471,7 @@ G_DEFINE_TYPE_WITH_CODE (ShortcutsPaneModelFilter, static GtkTreeModel *shortcuts_pane_model_filter_new (GtkFileChooserDefault *impl, GtkTreeModel *child_model, GtkTreePath *root); +#endif @@ -726,6 +732,7 @@ gtk_file_chooser_embed_default_iface_init (GtkFileChooserEmbedIface *iface) iface->initial_focus = gtk_file_chooser_default_initial_focus; } +#if REMOVE_FOR_PLACES_SIDEBAR static void bookmarks_changed_cb (gpointer data) { @@ -733,6 +740,7 @@ bookmarks_changed_cb (gpointer data) volumes_bookmarks_changed_cb (impl->file_system, impl); } +#endif static void _gtk_file_chooser_default_init (GtkFileChooserDefault *impl) -- cgit v1.2.1 From 2aec19e907e284c4992f007e800156d5ffffb646 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Fri, 25 Nov 2011 14:44:07 -0600 Subject: #if out another bunch of stuff, to make the fucking thing compile --- gtk/gtkfilechooserdefault.c | 74 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 5 deletions(-) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index e4c6192b22..bb146f41f3 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -236,7 +236,7 @@ enum { GTK_TREE_MODEL_ROW, }; -#if REMOVE_FOR_PLACES_SIDEBAR +/* #if REMOVE_FOR_PLACES_SIDEBAR - this is used in operation_mode_set(), so don't remove it yet */ /* Interesting places in the shortcuts bar */ typedef enum { SHORTCUTS_SEARCH, @@ -251,7 +251,6 @@ typedef enum { SHORTCUTS_CURRENT_FOLDER_SEPARATOR, SHORTCUTS_CURRENT_FOLDER } ShortcutsIndex; -#endif /* Icon size for if we can't get it from the theme */ #define FALLBACK_ICON_SIZE 16 @@ -364,6 +363,7 @@ static void check_preview_change (GtkFileChooserDefault *impl); static void filter_combo_changed (GtkComboBox *combo_box, GtkFileChooserDefault *impl); +#if REMOVE_FOR_PLACES_SIDEBAR static gboolean shortcuts_key_press_event_cb (GtkWidget *widget, GdkEventKey *event, GtkFileChooserDefault *impl); @@ -381,6 +381,7 @@ static int shortcuts_get_index (GtkFileChooserDefault *impl, ShortcutsIndex where); static int shortcut_find_position (GtkFileChooserDefault *impl, GFile *file); +#endif static void bookmarks_check_add_sensitivity (GtkFileChooserDefault *impl); @@ -403,10 +404,12 @@ static void path_bar_clicked (GtkPathBar *path_bar, gboolean child_is_hidden, GtkFileChooserDefault *impl); +#if REMOVE_FOR_PLACES_SIDEBAR static void add_bookmark_button_clicked_cb (GtkButton *button, GtkFileChooserDefault *impl); static void remove_bookmark_button_clicked_cb (GtkButton *button, GtkFileChooserDefault *impl); +#endif static void update_cell_renderer_attributes (GtkFileChooserDefault *impl); @@ -732,7 +735,6 @@ gtk_file_chooser_embed_default_iface_init (GtkFileChooserEmbedIface *iface) iface->initial_focus = gtk_file_chooser_default_initial_focus; } -#if REMOVE_FOR_PLACES_SIDEBAR static void bookmarks_changed_cb (gpointer data) { @@ -740,7 +742,6 @@ bookmarks_changed_cb (gpointer data) volumes_bookmarks_changed_cb (impl->file_system, impl); } -#endif static void _gtk_file_chooser_default_init (GtkFileChooserDefault *impl) @@ -777,6 +778,7 @@ _gtk_file_chooser_default_init (GtkFileChooserDefault *impl) profile_end ("end", NULL); } +#if REMOVE_FOR_PLACES_SIDEBAR /* Frees the data columns for the specified iter in the shortcuts model*/ static void shortcuts_free_row_data (GtkFileChooserDefault *impl, @@ -838,6 +840,7 @@ shortcuts_free (GtkFileChooserDefault *impl) g_object_unref (impl->shortcuts_model); impl->shortcuts_model = NULL; } +#endif static void pending_select_files_free (GtkFileChooserDefault *impl) @@ -862,10 +865,12 @@ gtk_file_chooser_default_finalize (GObject *object) unset_file_system_backend (impl); +#if REMOVE_FOR_PLACES_SIDEBAR if (impl->shortcuts_pane_filter_model) g_object_unref (impl->shortcuts_pane_filter_model); shortcuts_free (impl); +#endif g_free (impl->browse_files_last_selected_name); @@ -1178,6 +1183,7 @@ set_preview_widget (GtkFileChooserDefault *impl, update_preview_widget_visibility (impl); } +#if REMOVE_FOR_PLACES_SIDEBAR /* Renders a "Search" icon at an appropriate size for a tree view */ static GdkPixbuf * render_search_icon (GtkFileChooserDefault *impl) @@ -2220,6 +2226,7 @@ shortcuts_model_create (GtkFileChooserDefault *impl) impl, NULL); } +#endif /* Callback used when the "New Folder" button is clicked */ static void @@ -2408,6 +2415,7 @@ toolbutton_new (GtkFileChooserDefault *impl, return GTK_WIDGET (item); } +#if REMOVE_FOR_PLACES_SIDEBAR /* Looks for a path among the shortcuts; returns its index or -1 if it doesn't exist */ static int shortcut_find_position (GtkFileChooserDefault *impl, @@ -2606,6 +2614,7 @@ remove_bookmark_button_clicked_cb (GtkButton *button, { remove_selected_bookmarks (impl); } +#endif struct selection_check_closure { GtkFileChooserDefault *impl; @@ -2744,7 +2753,7 @@ update_tooltip (GtkTreeModel *model, } } - +#if REMOVE_FOR_PLACES_SIDEBAR /* Sensitize the "add bookmark" button if all the selected items are folders, or * if there are no selected items *and* the current folder is not in the * bookmarks list. De-sensitize the button otherwise. @@ -3721,6 +3730,15 @@ shortcuts_pane_create (GtkFileChooserDefault *impl, return vbox; } +#endif + +/* Creates the widgets for the shortcuts/bookmarks pane */ +static GtkWidget * +shortcuts_pane_create (GtkFileChooserDefault *impl, + GtkSizeGroup *size_group) +{ + return gtk_label_new ("yay"); +} static gboolean key_is_left_or_right (GdkEventKey *event) @@ -3766,7 +3784,9 @@ browse_files_key_press_event_cb (GtkWidget *widget, if (key_is_left_or_right (event)) { +#if REMOVE_FOR_PLACES_SIDEBAR gtk_widget_grab_focus (impl->browse_shortcuts_tree_view); +#endif return TRUE; } @@ -3823,7 +3843,9 @@ static void add_to_shortcuts_cb (GtkMenuItem *item, GtkFileChooserDefault *impl) { +#if REMOVE_FOR_PLACES_SIDEBAR bookmarks_add_selected_folder (impl); +#endif } /* callback used to set data to clipboard */ @@ -4210,7 +4232,9 @@ file_list_build_popup_menu (GtkFileChooserDefault *impl) impl->browse_files_popup_menu_size_column_item = file_list_add_check_menu_item (impl, _("Show _Size Column"), G_CALLBACK (show_size_column_toggled_cb)); +#if REMOVE_FOR_PLACES_SIDEBAR bookmarks_check_add_sensitivity (impl); +#endif check_copy_file_location_sensitivity (impl); } @@ -5107,8 +5131,10 @@ gtk_file_chooser_default_constructor (GType type, gtk_widget_push_composite_child (); +#if REMOVE_FOR_PLACES_SIDEBAR /* Shortcuts model */ shortcuts_model_create (impl); +#endif /* The browse widgets */ browse_widgets_create (impl); @@ -5168,8 +5194,10 @@ set_local_only (GtkFileChooserDefault *impl, if (impl->shortcuts_model && impl->file_system) { +#if REMOVE_FOR_PLACES_SIDEBAR shortcuts_add_volumes (impl); shortcuts_add_bookmarks (impl); +#endif } if (local_only && impl->current_folder && @@ -5198,12 +5226,14 @@ static void volumes_bookmarks_changed_cb (GtkFileSystem *file_system, GtkFileChooserDefault *impl) { +#if REMOVE_FOR_PLACES_SIDEBAR shortcuts_add_volumes (impl); shortcuts_add_bookmarks (impl); bookmarks_check_add_sensitivity (impl); bookmarks_check_remove_sensitivity (impl); shortcuts_check_popup_sensitivity (impl); +#endif } /* Sets the file chooser to multiple selection mode */ @@ -5448,6 +5478,7 @@ operation_mode_set_recent (GtkFileChooserDefault *impl) static void shortcuts_select_item_without_activating (GtkFileChooserDefault *impl, int pos) { +#if REMOVE_FOR_PLACES_SIDEBAR GtkTreeSelection *selection; GtkTreePath *path; @@ -5460,6 +5491,7 @@ shortcuts_select_item_without_activating (GtkFileChooserDefault *impl, int pos) gtk_tree_path_free (path); g_signal_handlers_unblock_by_func (selection, G_CALLBACK (shortcuts_selection_changed_cb), impl); +#endif } static void @@ -5493,8 +5525,10 @@ operation_mode_set (GtkFileChooserDefault *impl, OperationMode mode) return; } +#if REMOVE_FOR_PLACES_SIDEBAR if (shortcut_to_select != SHORTCUTS_CURRENT_FOLDER) shortcuts_select_item_without_activating (impl, shortcuts_get_index (impl, shortcut_to_select)); +#endif } /* This function is basically a do_all function. @@ -5915,7 +5949,9 @@ change_icon_theme (GtkFileChooserDefault *impl) else impl->icon_size = FALLBACK_ICON_SIZE; +#if REMOVE_FOR_PLACES_SIDEBAR shortcuts_reload_icons (impl); +#endif /* the first cell in the first column is the icon column, and we have a fixed size there */ cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT ( gtk_tree_view_get_column (GTK_TREE_VIEW (impl->browse_files_tree_view), 0))); @@ -7366,7 +7402,9 @@ update_current_folder_get_info_cb (GCancellable *cancellable, { impl->changing_folder = TRUE; +#if REMOVE_FOR_PLACES_SIDEBAR shortcuts_update_current_folder (impl); +#endif impl->changing_folder = FALSE; } @@ -7390,7 +7428,9 @@ update_current_folder_get_info_cb (GCancellable *cancellable, /* Refresh controls */ +#if REMOVE_FOR_PLACES_SIDEBAR shortcuts_find_current_folder (impl); +#endif g_signal_emit_by_name (impl, "current-folder-changed", 0); @@ -7965,6 +8005,7 @@ gtk_file_chooser_default_list_filters (GtkFileChooser *chooser) return g_slist_copy (impl->filters); } +#if REMOVE_FOR_PLACES_SIDEBAR /* Returns the position in the shortcuts tree where the nth specified shortcut would appear */ static int shortcuts_get_pos_for_shortcut_folder (GtkFileChooserDefault *impl, @@ -8008,12 +8049,14 @@ out: g_object_unref (cancellable); } +#endif static gboolean gtk_file_chooser_default_add_shortcut_folder (GtkFileChooser *chooser, GFile *file, GError **error) { +#if REMOVE_FOR_PLACES_SIDEBAR GCancellable *cancellable; GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser); struct AddShortcutData *data; @@ -8075,6 +8118,9 @@ gtk_file_chooser_default_add_shortcut_folder (GtkFileChooser *chooser, g_object_set_data (G_OBJECT (cancellable), "add-shortcut-path-key", data->file); return TRUE; +#else + return FALSE; +#endif } static gboolean @@ -8082,6 +8128,7 @@ gtk_file_chooser_default_remove_shortcut_folder (GtkFileChooser *chooser, GFile *file, GError **error) { +#if REMOVE_FOR_PLACES_SIDEBAR GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser); int pos; GtkTreeIter iter; @@ -8147,11 +8194,15 @@ gtk_file_chooser_default_remove_shortcut_folder (GtkFileChooser *chooser, g_free (uri); return FALSE; +#else + return FALSE; +#endif } static GSList * gtk_file_chooser_default_list_shortcut_folders (GtkFileChooser *chooser) { +#if REMOVE_FOR_PLACES_SIDEBAR GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser); int pos; GtkTreeIter iter; @@ -8191,6 +8242,9 @@ gtk_file_chooser_default_list_shortcut_folders (GtkFileChooser *chooser) } return g_slist_reverse (list); +#else + return NULL; +#endif } /* Guesses a size based upon font sizes */ @@ -9801,6 +9855,7 @@ check_preview_change (GtkFileChooserDefault *impl) } } +#if REMOVE_FOR_PLACES_SIDEBAR static void shortcuts_activate_volume_mount_cb (GCancellable *cancellable, GtkFileSystemVolume *volume, @@ -10098,6 +10153,7 @@ shortcuts_select_func (GtkTreeSelection *selection, return shortcut_type != SHORTCUT_TYPE_SEPARATOR; } +#endif static gboolean list_select_func (GtkTreeSelection *selection, @@ -10352,20 +10408,24 @@ static void switch_to_shortcut (GtkFileChooserDefault *impl, int pos) { +#if REMOVE_FOR_PLACES_SIDEBAR GtkTreeIter iter; if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos)) g_assert_not_reached (); shortcuts_activate_iter (impl, &iter); +#endif } /* Handler for the "home-folder" keybinding signal */ static void home_folder_handler (GtkFileChooserDefault *impl) { +#if REMOVE_FOR_PLACES_SIDEBAR if (impl->has_home) switch_to_shortcut (impl, shortcuts_get_index (impl, SHORTCUTS_HOME)); +#endif } /* Handler for the "desktop-folder" keybinding signal */ @@ -10412,9 +10472,11 @@ quick_bookmark_handler (GtkFileChooserDefault *impl, bookmark_pos = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS) + bookmark_index; path = gtk_tree_path_new_from_indices (bookmark_pos, -1); +#if REMOVE_FOR_PLACES_SIDEBAR gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), path, NULL, FALSE, 0.0, 0.0); +#endif gtk_tree_path_free (path); switch_to_shortcut (impl, bookmark_pos); @@ -10429,6 +10491,7 @@ show_hidden_handler (GtkFileChooserDefault *impl) } +#if REMOVE_FOR_PLACES_SIDEBAR /* Drag and drop interfaces */ static void @@ -10507,3 +10570,4 @@ shortcuts_pane_model_filter_new (GtkFileChooserDefault *impl, return GTK_TREE_MODEL (model); } +#endif -- cgit v1.2.1 From 2e9f9d2dc543a0b166cc72256d4d1943aaad2c9c Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Mon, 3 Sep 2012 21:29:48 -0500 Subject: Fix compilation --- gtk/gtkfilechooserdefault.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index bb146f41f3..a29bbfa1be 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -381,9 +381,9 @@ static int shortcuts_get_index (GtkFileChooserDefault *impl, ShortcutsIndex where); static int shortcut_find_position (GtkFileChooserDefault *impl, GFile *file); -#endif static void bookmarks_check_add_sensitivity (GtkFileChooserDefault *impl); +#endif static gboolean list_select_func (GtkTreeSelection *selection, GtkTreeModel *model, @@ -1533,9 +1533,11 @@ get_file_info_finished (GCancellable *cancellable, } else if (request->type == SHORTCUTS_CURRENT_FOLDER) { +#if REMOVE_FOR_PLACES_SIDEBAR /* Remove the current folder separator */ gint separator_pos = shortcuts_get_index (request->impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR); shortcuts_remove_rows (request->impl, separator_pos, 1); +#endif } goto out; @@ -1570,6 +1572,7 @@ out: if (model_cancellable) g_object_unref (model_cancellable); } +#endif /* FIXME: GtkFileSystem needs a function to split a remote path * into hostname and path components, or maybe just have a @@ -1627,6 +1630,7 @@ _gtk_file_chooser_label_for_file (GFile *file) return label; } +#if REMOVE_FOR_PLACES_SIDEBAR /* Inserts a path in the shortcuts tree, making a copy of it; alternatively, * inserts a volume. A position of -1 indicates the end of the tree. */ @@ -7435,7 +7439,9 @@ update_current_folder_get_info_cb (GCancellable *cancellable, g_signal_emit_by_name (impl, "current-folder-changed", 0); check_preview_change (impl); +#if REMOVE_FOR_PLACES_SIDEBAR bookmarks_check_add_sensitivity (impl); +#endif g_signal_emit_by_name (impl, "selection-changed", 0); @@ -10211,7 +10217,9 @@ list_selection_changed (GtkTreeSelection *selection, path_bar_update (impl); check_preview_change (impl); +#if REMOVE_FOR_PLACES_SIDEBAR bookmarks_check_add_sensitivity (impl); +#endif check_copy_file_location_sensitivity (impl); g_signal_emit_by_name (impl, "selection-changed", 0); @@ -10432,8 +10440,10 @@ home_folder_handler (GtkFileChooserDefault *impl) static void desktop_folder_handler (GtkFileChooserDefault *impl) { +#if REMOVE_FOR_PLACES_SIDEBAR if (impl->has_desktop) switch_to_shortcut (impl, shortcuts_get_index (impl, SHORTCUTS_DESKTOP)); +#endif } /* Handler for the "search-shortcut" keybinding signal */ @@ -10442,7 +10452,9 @@ search_shortcut_handler (GtkFileChooserDefault *impl) { if (impl->has_search) { +#if REMOVE_FOR_PLACES_SIDEBAR switch_to_shortcut (impl, shortcuts_get_index (impl, SHORTCUTS_SEARCH)); +#endif /* we want the entry widget to grab the focus the first * time, not the browse_files_tree_view widget. @@ -10456,7 +10468,9 @@ search_shortcut_handler (GtkFileChooserDefault *impl) static void recent_shortcut_handler (GtkFileChooserDefault *impl) { +#if REMOVE_FOR_PLACES_SIDEBAR switch_to_shortcut (impl, shortcuts_get_index (impl, SHORTCUTS_RECENT)); +#endif } static void @@ -10469,7 +10483,9 @@ quick_bookmark_handler (GtkFileChooserDefault *impl, if (bookmark_index < 0 || bookmark_index >= impl->num_bookmarks) return; +#if REMOVE_FOR_PLACES_SIDEBAR bookmark_pos = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS) + bookmark_index; +#endif path = gtk_tree_path_new_from_indices (bookmark_pos, -1); #if REMOVE_FOR_PLACES_SIDEBAR -- cgit v1.2.1 From 4fe3cd8f1e7ac69d92e5ecf1668ef5b670802fc6 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Wed, 5 Sep 2012 19:48:16 -0500 Subject: Create the places sidebar instead of the old custom treeview Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index a29bbfa1be..b355c68944 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -51,6 +51,7 @@ #include "gtkmountoperation.h" #include "gtkpaned.h" #include "gtkpathbar.h" +#include "gtkplacessidebar.h" #include "gtkprivate.h" #include "gtkradiobutton.h" #include "gtkrecentfilter.h" @@ -3741,7 +3742,8 @@ static GtkWidget * shortcuts_pane_create (GtkFileChooserDefault *impl, GtkSizeGroup *size_group) { - return gtk_label_new ("yay"); + impl->places_sidebar = gtk_places_sidebar_new (); + return impl->places_sidebar; } static gboolean -- cgit v1.2.1 From 86c3274579fed906137fb538e411643e3879fdf3 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Fri, 7 Sep 2012 14:35:56 -0500 Subject: Connect to location-selected on the places sidebar, and actually switch folders\! Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index b355c68944..1eb6736dd5 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -17,6 +17,13 @@ * License along with this library. If not, see . */ +/* TODO: + * + * * Fix instances of "#if REMOVE_FOR_PLACES_SIDEBAR" + * + * * Fix FIXME-places-sidebar + */ + #include "config.h" #include "gtkfilechooserdefault.h" @@ -3737,12 +3744,42 @@ shortcuts_pane_create (GtkFileChooserDefault *impl, } #endif +static void +places_sidebar_location_selected_cb (GtkPlacesSidebar *sidebar, GFile *location, GtkPlacesOpenMode open_mode, GtkFileChooserDefault *impl) +{ + gboolean clear_entry; + + /* FIXME-places-sidebar: see shortcuts_activate_iter() for missing pieces. In particular: + * + * * Search mode + * + * * Recent-files mode + */ + + /* In the Save modes, we want to preserve what the uesr typed in the filename + * entry, so that he may choose another folder without erasing his typed name. + */ + if (impl->location_entry + && !(impl->action == GTK_FILE_CHOOSER_ACTION_SAVE + || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)) + clear_entry = TRUE; + else + clear_entry = FALSE; + + change_folder_and_display_error (impl, location, clear_entry); +} + /* Creates the widgets for the shortcuts/bookmarks pane */ static GtkWidget * shortcuts_pane_create (GtkFileChooserDefault *impl, GtkSizeGroup *size_group) { impl->places_sidebar = gtk_places_sidebar_new (); + + g_signal_connect (impl->places_sidebar, "location-selected", + G_CALLBACK (places_sidebar_location_selected_cb), + impl); + return impl->places_sidebar; } -- cgit v1.2.1 From 61a9a46bcef0e77e492761c2dbc659dcfb87ed76 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Mon, 22 Oct 2012 17:52:27 -0500 Subject: Present error dialogs from the places sidebar --- gtk/gtkfilechooserdefault.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 90baa8471b..2b98846746 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -3771,6 +3771,16 @@ places_sidebar_location_selected_cb (GtkPlacesSidebar *sidebar, GFile *location, change_folder_and_display_error (impl, location, clear_entry); } +/* Callback used when the places sidebar needs us to display an error message */ +static void +places_sidebar_show_error_message_cb (GtkPlacesSidebar *sidebar, + const char *primary, + const char *secondary, + GtkFileChooserDefault *impl) +{ + error_message (impl, primary, secondary); +} + /* Creates the widgets for the shortcuts/bookmarks pane */ static GtkWidget * shortcuts_pane_create (GtkFileChooserDefault *impl, @@ -3781,6 +3791,9 @@ shortcuts_pane_create (GtkFileChooserDefault *impl, g_signal_connect (impl->places_sidebar, "location-selected", G_CALLBACK (places_sidebar_location_selected_cb), impl); + g_signal_connect (impl->places_sidebar, "show-error-message", + G_CALLBACK (places_sidebar_show_error_message_cb), + impl); return impl->places_sidebar; } -- cgit v1.2.1 From ec9bdc639794a0d1f528eef5876ca676927336b6 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Tue, 20 Nov 2012 20:04:20 -0600 Subject: New way to show in the sidebar Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 1 + 1 file changed, 1 insertion(+) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 2b98846746..2d1923d77e 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -3787,6 +3787,7 @@ shortcuts_pane_create (GtkFileChooserDefault *impl, GtkSizeGroup *size_group) { impl->places_sidebar = gtk_places_sidebar_new (); + gtk_places_sidebar_set_show_cwd (GTK_PLACES_SIDEBAR (impl->places_sidebar), TRUE); g_signal_connect (impl->places_sidebar, "location-selected", G_CALLBACK (places_sidebar_location_selected_cb), -- cgit v1.2.1 From 043cac11f3ad588948e9594f3943ee7df998f71b Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Wed, 21 Nov 2012 10:28:26 -0600 Subject: Add a new org.gtk.SettingsFileChooser startup-mode settings key It has two possible values, 'recent' and 'cwd'. We will use these to determine whether to set the default starting mode, if a folder has not been pre-set, to showing the Recent Files list or the current working directory. Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 2d1923d77e..57a445eed9 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -275,6 +275,7 @@ typedef enum { #define SETTINGS_KEY_SORT_ORDER "sort-order" #define SETTINGS_KEY_WINDOW_POSITION "window-position" #define SETTINGS_KEY_WINDOW_SIZE "window-size" +#define SETTINGS_KEY_STARTUP_MODE "startup-mode" static void gtk_file_chooser_default_iface_init (GtkFileChooserIface *iface); static void gtk_file_chooser_embed_default_iface_init (GtkFileChooserEmbedIface *iface); @@ -6155,6 +6156,7 @@ settings_load (GtkFileChooserDefault *impl) gboolean show_size_column; gint sort_column; GtkSortType sort_order; + StartupMode startup_mode; settings_ensure (impl); @@ -6163,6 +6165,7 @@ settings_load (GtkFileChooserDefault *impl) show_size_column = g_settings_get_boolean (impl->settings, SETTINGS_KEY_SHOW_SIZE_COLUMN); sort_column = g_settings_get_enum (impl->settings, SETTINGS_KEY_SORT_COLUMN); sort_order = g_settings_get_enum (impl->settings, SETTINGS_KEY_SORT_ORDER); + startup_mode = g_settings_get_enum (impl->settings, SETTINGS_KEY_STARTUP_MODE); location_mode_set (impl, location_mode, TRUE); @@ -6177,6 +6180,8 @@ settings_load (GtkFileChooserDefault *impl) * created yet. The individual functions that create and set the models will * call set_sort_column() themselves. */ + + impl->startup_mode = startup_mode; } static void -- cgit v1.2.1 From e6b9ad404f41d9a9f5f887bee763e87c99e76141 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Wed, 21 Nov 2012 10:40:34 -0600 Subject: Switch to Recent Files or $CWD at startup Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 57a445eed9..be7a958982 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -6275,6 +6275,38 @@ get_file_for_last_folder_opened (GtkFileChooserDefault *impl) return file; } +/* Changes the current folder to $CWD */ +static void +switch_to_cwd (GtkFileChooserDefault *impl) +{ + char *current_working_dir; + + current_working_dir = g_get_current_dir (); + gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl), current_working_dir); + g_free (current_working_dir); +} + +/* Sets the file chooser to showing Recent Files or $CWD, depending on the + * user's settings. + */ +static void +set_startup_mode (GtkFileChooserDefault *impl) +{ + switch (impl->startup_mode) + { + case STARTUP_MODE_RECENT: + recent_shortcut_handler (impl); + break; + + case STARTUP_MODE_CWD: + switch_to_cwd (impl); + break; + + default: + g_assert_not_reached (); + } +} + /* GtkWidget::map method */ static void gtk_file_chooser_default_map (GtkWidget *widget) @@ -6287,12 +6319,14 @@ gtk_file_chooser_default_map (GtkWidget *widget) GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->map (widget); + settings_load (impl); + if (impl->operation_mode == OPERATION_MODE_BROWSE) { switch (impl->reload_state) { case RELOAD_EMPTY: - recent_shortcut_handler (impl); + set_startup_mode (impl); break; case RELOAD_HAS_FOLDER: @@ -6308,8 +6342,6 @@ gtk_file_chooser_default_map (GtkWidget *widget) volumes_bookmarks_changed_cb (impl->file_system, impl); - settings_load (impl); - profile_end ("end", NULL); } -- cgit v1.2.1 From f623329e95c7d6f43874cf667f5036dc01793331 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Fri, 23 Nov 2012 12:53:35 -0600 Subject: Allow switching to recent:/// even though GIO thinks it is not a native file That URI is not a native file, and so it would not show up if local_only=TRUE. Add a special case for it so that recent:/// can always be visited. Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index be7a958982..85111de0f1 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -7544,6 +7544,19 @@ out: g_object_unref (cancellable); } +static gboolean +file_is_recent_uri (GFile *file) +{ + GFile *recent; + gboolean same; + + recent = g_file_new_for_uri ("recent:///"); + same = g_file_equal (file, recent); + g_object_unref (recent); + + return same; +} + static gboolean gtk_file_chooser_default_update_current_folder (GtkFileChooser *chooser, GFile *file, @@ -7560,7 +7573,8 @@ gtk_file_chooser_default_update_current_folder (GtkFileChooser *chooser, operation_mode_set (impl, OPERATION_MODE_BROWSE); - if (impl->local_only && !g_file_is_native (file)) + if (impl->local_only && !g_file_is_native (file) + && !file_is_recent_uri (file)) /* GIO considers "recent:///" to be non-native; we special-case it so recent files *will* show up */ { g_set_error_literal (error, GTK_FILE_CHOOSER_ERROR, -- cgit v1.2.1 From fc6bfcddde940fb21aa423459f064a4c6ccfc1db Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Fri, 23 Nov 2012 13:24:55 -0600 Subject: Actually switch to recent:/// in its key shortcut handler Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 85111de0f1..ee5bad033d 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -10574,9 +10574,11 @@ search_shortcut_handler (GtkFileChooserDefault *impl) static void recent_shortcut_handler (GtkFileChooserDefault *impl) { -#if REMOVE_FOR_PLACES_SIDEBAR - switch_to_shortcut (impl, shortcuts_get_index (impl, SHORTCUTS_RECENT)); -#endif + GFile *recent; + + recent = g_file_new_for_uri ("recent:///"); + change_folder_and_display_error (impl, recent, FALSE); + g_object_unref (recent); } static void -- cgit v1.2.1 From b706e1b76b8664628202b3c238fe5afd97b266f0 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Sat, 24 Nov 2012 10:41:40 -0600 Subject: Highlight the currently-viewed location in the places sidebar Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index ee5bad033d..ff81000ba4 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -1403,13 +1403,6 @@ shortcuts_find_folder (GtkFileChooserDefault *impl, gtk_tree_path_free (path); } -/* If a shortcut corresponds to the current folder, selects it */ -static void -shortcuts_find_current_folder (GtkFileChooserDefault *impl) -{ - shortcuts_find_folder (impl, impl->current_folder); -} - /* Removes the specified number of rows from the shortcuts list */ static void shortcuts_remove_rows (GtkFileChooserDefault *impl, @@ -7524,9 +7517,7 @@ update_current_folder_get_info_cb (GCancellable *cancellable, /* Refresh controls */ -#if REMOVE_FOR_PLACES_SIDEBAR - shortcuts_find_current_folder (impl); -#endif + gtk_places_sidebar_set_current_location (GTK_PLACES_SIDEBAR (impl->places_sidebar), impl->current_folder); g_signal_emit_by_name (impl, "current-folder-changed", 0); -- cgit v1.2.1 From 1681cf9b16e55a6795c70fb70548bac0f34efd5e Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Wed, 5 Dec 2012 18:09:44 -0600 Subject: Remove the old shortcuts pane code from GtkFileChooserDefault Oh, the giant void. I stare into it and it makes me afraid that I've screwed up. But I know I haven't. Because any remaining bugs will be yours to fix. Not mine. Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 3440 ++++--------------------------------------- 1 file changed, 252 insertions(+), 3188 deletions(-) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index ff81000ba4..7b686f8a72 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -183,28 +183,6 @@ enum { static guint signals[LAST_SIGNAL] = { 0 }; -#if REMOVE_FOR_PLACES_SIDEBAR -/* Column numbers for the shortcuts tree. Keep these in sync with shortcuts_model_create() */ -enum { - SHORTCUTS_COL_PIXBUF, - SHORTCUTS_COL_NAME, - SHORTCUTS_COL_DATA, - SHORTCUTS_COL_TYPE, - SHORTCUTS_COL_REMOVABLE, - SHORTCUTS_COL_PIXBUF_VISIBLE, - SHORTCUTS_COL_CANCELLABLE, - SHORTCUTS_COL_NUM_COLUMNS -}; - -typedef enum { - SHORTCUT_TYPE_FILE, - SHORTCUT_TYPE_VOLUME, - SHORTCUT_TYPE_SEPARATOR, - SHORTCUT_TYPE_SEARCH, - SHORTCUT_TYPE_RECENT -} ShortcutType; -#endif - #define MODEL_ATTRIBUTES "standard::name,standard::type,standard::display-name," \ "standard::is-hidden,standard::is-backup,standard::size," \ "standard::content-type,time::modified" @@ -345,9 +323,6 @@ static void gtk_file_chooser_default_get_default_size (GtkFileCh static gboolean gtk_file_chooser_default_should_respond (GtkFileChooserEmbed *chooser_embed); static void gtk_file_chooser_default_initial_focus (GtkFileChooserEmbed *chooser_embed); -static void volumes_bookmarks_changed_cb (GtkFileSystem *file_system, - GtkFileChooserDefault *impl); - static void add_selection_to_recent_list (GtkFileChooserDefault *impl); static void location_popup_handler (GtkFileChooserDefault *impl, @@ -372,28 +347,6 @@ static void check_preview_change (GtkFileChooserDefault *impl); static void filter_combo_changed (GtkComboBox *combo_box, GtkFileChooserDefault *impl); -#if REMOVE_FOR_PLACES_SIDEBAR -static gboolean shortcuts_key_press_event_cb (GtkWidget *widget, - GdkEventKey *event, - GtkFileChooserDefault *impl); - -static gboolean shortcuts_select_func (GtkTreeSelection *selection, - GtkTreeModel *model, - GtkTreePath *path, - gboolean path_currently_selected, - gpointer data); -static gboolean shortcuts_get_selected (GtkFileChooserDefault *impl, - GtkTreeIter *iter); -static void shortcuts_activate_iter (GtkFileChooserDefault *impl, - GtkTreeIter *iter); -static int shortcuts_get_index (GtkFileChooserDefault *impl, - ShortcutsIndex where); -static int shortcut_find_position (GtkFileChooserDefault *impl, - GFile *file); - -static void bookmarks_check_add_sensitivity (GtkFileChooserDefault *impl); -#endif - static gboolean list_select_func (GtkTreeSelection *selection, GtkTreeModel *model, GtkTreePath *path, @@ -413,13 +366,6 @@ static void path_bar_clicked (GtkPathBar *path_bar, gboolean child_is_hidden, GtkFileChooserDefault *impl); -#if REMOVE_FOR_PLACES_SIDEBAR -static void add_bookmark_button_clicked_cb (GtkButton *button, - GtkFileChooserDefault *impl); -static void remove_bookmark_button_clicked_cb (GtkButton *button, - GtkFileChooserDefault *impl); -#endif - static void update_cell_renderer_attributes (GtkFileChooserDefault *impl); static void load_remove_timer (GtkFileChooserDefault *impl); @@ -453,40 +399,6 @@ static void set_file_system_backend (GtkFileChooserDefault *impl); static void unset_file_system_backend (GtkFileChooserDefault *impl); - - - -#if REMOVE_FOR_PLACES_SIDEBAR -/* Drag and drop interface declarations */ - -typedef struct { - GtkTreeModelFilter parent; - - GtkFileChooserDefault *impl; -} ShortcutsPaneModelFilter; - -typedef struct { - GtkTreeModelFilterClass parent_class; -} ShortcutsPaneModelFilterClass; - -#define SHORTCUTS_PANE_MODEL_FILTER_TYPE (_shortcuts_pane_model_filter_get_type ()) -#define SHORTCUTS_PANE_MODEL_FILTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SHORTCUTS_PANE_MODEL_FILTER_TYPE, ShortcutsPaneModelFilter)) - -static void shortcuts_pane_model_filter_drag_source_iface_init (GtkTreeDragSourceIface *iface); - -GType _shortcuts_pane_model_filter_get_type (void); - -G_DEFINE_TYPE_WITH_CODE (ShortcutsPaneModelFilter, - _shortcuts_pane_model_filter, - GTK_TYPE_TREE_MODEL_FILTER, - G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_DRAG_SOURCE, - shortcuts_pane_model_filter_drag_source_iface_init)) - -static GtkTreeModel *shortcuts_pane_model_filter_new (GtkFileChooserDefault *impl, - GtkTreeModel *child_model, - GtkTreePath *root); -#endif - G_DEFINE_TYPE_WITH_CODE (GtkFileChooserDefault, _gtk_file_chooser_default, GTK_TYPE_BOX, @@ -746,14 +658,6 @@ gtk_file_chooser_embed_default_iface_init (GtkFileChooserEmbedIface *iface) iface->initial_focus = gtk_file_chooser_default_initial_focus; } -static void -bookmarks_changed_cb (gpointer data) -{ - GtkFileChooserDefault *impl = data; - - volumes_bookmarks_changed_cb (impl->file_system, impl); -} - static void _gtk_file_chooser_default_init (GtkFileChooserDefault *impl) { @@ -784,75 +688,11 @@ _gtk_file_chooser_default_init (GtkFileChooserDefault *impl) set_file_system_backend (impl); - impl->bookmarks_manager = _gtk_bookmarks_manager_new (bookmarks_changed_cb, impl); + impl->bookmarks_manager = _gtk_bookmarks_manager_new (NULL, NULL); profile_end ("end", NULL); } -#if REMOVE_FOR_PLACES_SIDEBAR -/* Frees the data columns for the specified iter in the shortcuts model*/ -static void -shortcuts_free_row_data (GtkFileChooserDefault *impl, - GtkTreeIter *iter) -{ - gpointer col_data; - ShortcutType shortcut_type; - GCancellable *cancellable; - - gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), iter, - SHORTCUTS_COL_DATA, &col_data, - SHORTCUTS_COL_TYPE, &shortcut_type, - SHORTCUTS_COL_CANCELLABLE, &cancellable, - -1); - - if (cancellable) - { - g_cancellable_cancel (cancellable); - g_object_unref (cancellable); - } - - if (!(shortcut_type == SHORTCUT_TYPE_FILE || - shortcut_type == SHORTCUT_TYPE_VOLUME) || - !col_data) - return; - - if (shortcut_type == SHORTCUT_TYPE_VOLUME) - { - GtkFileSystemVolume *volume; - - volume = col_data; - _gtk_file_system_volume_unref (volume); - } - if (shortcut_type == SHORTCUT_TYPE_FILE) - { - GFile *file; - - file = col_data; - g_object_unref (file); - } -} - -/* Frees all the data columns in the shortcuts model */ -static void -shortcuts_free (GtkFileChooserDefault *impl) -{ - GtkTreeIter iter; - - if (!impl->shortcuts_model) - return; - - if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter)) - do - { - shortcuts_free_row_data (impl, &iter); - } - while (gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter)); - - g_object_unref (impl->shortcuts_model); - impl->shortcuts_model = NULL; -} -#endif - static void pending_select_files_free (GtkFileChooserDefault *impl) { @@ -876,13 +716,6 @@ gtk_file_chooser_default_finalize (GObject *object) unset_file_system_backend (impl); -#if REMOVE_FOR_PLACES_SIDEBAR - if (impl->shortcuts_pane_filter_model) - g_object_unref (impl->shortcuts_pane_filter_model); - - shortcuts_free (impl); -#endif - g_free (impl->browse_files_last_selected_name); for (l = impl->filters; l; l = l->next) @@ -993,41 +826,6 @@ error_dialog (GtkFileChooserDefault *impl, } } -/* Displays an error message about not being able to get information for a file. - * Frees the GError as well. - */ -static void -error_getting_info_dialog (GtkFileChooserDefault *impl, - GFile *file, - GError *error) -{ - error_dialog (impl, - _("Could not retrieve information about the file"), - file, error); -} - -/* Shows an error dialog about not being able to add a bookmark */ -static void -error_adding_bookmark_dialog (GtkFileChooserDefault *impl, - GFile *file, - GError *error) -{ - error_dialog (impl, - _("Could not add a bookmark"), - file, error); -} - -/* Shows an error dialog about not being able to remove a bookmark */ -static void -error_removing_bookmark_dialog (GtkFileChooserDefault *impl, - GFile *file, - GError *error) -{ - error_dialog (impl, - _("Could not remove bookmark"), - file, error); -} - /* Shows an error dialog about not being able to create a folder */ static void error_creating_folder_dialog (GtkFileChooserDefault *impl, @@ -1194,2549 +992,321 @@ set_preview_widget (GtkFileChooserDefault *impl, update_preview_widget_visibility (impl); } -#if REMOVE_FOR_PLACES_SIDEBAR -/* Renders a "Search" icon at an appropriate size for a tree view */ -static GdkPixbuf * -render_search_icon (GtkFileChooserDefault *impl) -{ - return gtk_widget_render_icon_pixbuf (GTK_WIDGET (impl), GTK_STOCK_FIND, GTK_ICON_SIZE_MENU); -} - -static GdkPixbuf * -render_recent_icon (GtkFileChooserDefault *impl) +/* FIXME: GtkFileSystem needs a function to split a remote path + * into hostname and path components, or maybe just have a + * gtk_file_system_path_get_display_name(). + * + * This function is also used in gtkfilechooserbutton.c + */ +gchar * +_gtk_file_chooser_label_for_file (GFile *file) { - GtkIconTheme *theme; - GdkPixbuf *retval; + const gchar *path, *start, *end, *p; + gchar *uri, *host, *label; - if (gtk_widget_has_screen (GTK_WIDGET (impl))) - theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl))); - else - theme = gtk_icon_theme_get_default (); + uri = g_file_get_uri (file); - retval = gtk_icon_theme_load_icon (theme, "document-open-recent", - impl->icon_size, 0, - NULL); + start = strstr (uri, "://"); + if (start) + { + start += 3; + path = strchr (start, '/'); + if (path) + end = path; + else + { + end = uri + strlen (uri); + path = "/"; + } - /* fallback */ - if (!retval) - retval = gtk_widget_render_icon_pixbuf (GTK_WIDGET (impl), GTK_STOCK_FILE, GTK_ICON_SIZE_MENU); + /* strip username */ + p = strchr (start, '@'); + if (p && p < end) + start = p + 1; + + p = strchr (start, ':'); + if (p && p < end) + end = p; + + host = g_strndup (start, end - start); + + /* Translators: the first string is a path and the second string + * is a hostname. Nautilus and the panel contain the same string + * to translate. + */ + label = g_strdup_printf (_("%1$s on %2$s"), path, host); + + g_free (host); + } + else + { + label = g_strdup (uri); + } + + g_free (uri); - return retval; + return label; } - -/* Re-reads all the icons for the shortcuts, used when the theme changes */ -struct ReloadIconsData -{ - GtkFileChooserDefault *impl; - GtkTreeRowReference *row_ref; -}; - +/* Callback used when the "New Folder" button is clicked */ static void -shortcuts_reload_icons_get_info_cb (GCancellable *cancellable, - GFileInfo *info, - const GError *error, - gpointer user_data) +new_folder_button_clicked (GtkButton *button, + GtkFileChooserDefault *impl) { - GdkPixbuf *pixbuf; GtkTreeIter iter; GtkTreePath *path; - gboolean cancelled = g_cancellable_is_cancelled (cancellable); - struct ReloadIconsData *data = user_data; - - if (!g_slist_find (data->impl->reload_icon_cancellables, cancellable)) - goto out; - data->impl->reload_icon_cancellables = g_slist_remove (data->impl->reload_icon_cancellables, cancellable); - - if (cancelled || error) - goto out; + if (!impl->browse_files_model) + return; /* FIXME: this sucks. Disable the New Folder button or something. */ - pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (data->impl), data->impl->icon_size); + /* Prevent button from being clicked twice */ + gtk_widget_set_sensitive (impl->browse_new_folder_button, FALSE); - path = gtk_tree_row_reference_get_path (data->row_ref); - if (path) - { - gtk_tree_model_get_iter (GTK_TREE_MODEL (data->impl->shortcuts_model), &iter, path); - gtk_list_store_set (data->impl->shortcuts_model, &iter, - SHORTCUTS_COL_PIXBUF, pixbuf, - -1); - gtk_tree_path_free (path); - } + _gtk_file_system_model_add_editable (impl->browse_files_model, &iter); - if (pixbuf) - g_object_unref (pixbuf); + path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->browse_files_model), &iter); + gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (impl->browse_files_tree_view), + path, impl->list_name_column, + FALSE, 0.0, 0.0); -out: - gtk_tree_row_reference_free (data->row_ref); - g_object_unref (data->impl); - g_free (data); + g_object_set (impl->list_name_renderer, "editable", TRUE, NULL); + gtk_tree_view_set_cursor (GTK_TREE_VIEW (impl->browse_files_tree_view), + path, + impl->list_name_column, + TRUE); - g_object_unref (cancellable); + gtk_tree_path_free (path); } -static void -shortcuts_reload_icons (GtkFileChooserDefault *impl) +static GSource * +add_idle_while_impl_is_alive (GtkFileChooserDefault *impl, GCallback callback) { - GSList *l; - GtkTreeIter iter; - - profile_start ("start", NULL); + GSource *source; - if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter)) - goto out; + source = g_idle_source_new (); + g_source_set_closure (source, + g_cclosure_new_object (callback, G_OBJECT (impl))); + g_source_attach (source, NULL); - for (l = impl->reload_icon_cancellables; l; l = l->next) - { - GCancellable *cancellable = G_CANCELLABLE (l->data); - g_cancellable_cancel (cancellable); - } - g_slist_free (impl->reload_icon_cancellables); - impl->reload_icon_cancellables = NULL; + return source; +} - do - { - gpointer data; - ShortcutType shortcut_type; - gboolean pixbuf_visible; - GdkPixbuf *pixbuf; +/* Idle handler for creating a new folder after editing its name cell, or for + * canceling the editing. + */ +static gboolean +edited_idle_cb (GtkFileChooserDefault *impl) +{ + gdk_threads_enter (); + + g_source_destroy (impl->edited_idle); + impl->edited_idle = NULL; - gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, - SHORTCUTS_COL_DATA, &data, - SHORTCUTS_COL_TYPE, &shortcut_type, - SHORTCUTS_COL_PIXBUF_VISIBLE, &pixbuf_visible, - -1); + _gtk_file_system_model_remove_editable (impl->browse_files_model); + g_object_set (impl->list_name_renderer, "editable", FALSE, NULL); - pixbuf = NULL; - if (pixbuf_visible) - { - if (shortcut_type == SHORTCUT_TYPE_VOLUME) - { - GtkFileSystemVolume *volume; + gtk_widget_set_sensitive (impl->browse_new_folder_button, TRUE); - volume = data; - pixbuf = _gtk_file_system_volume_render_icon (volume, GTK_WIDGET (impl), - impl->icon_size, NULL); - } - else if (shortcut_type == SHORTCUT_TYPE_FILE) - { - if (g_file_is_native (G_FILE (data))) - { - GFile *file; - struct ReloadIconsData *info; - GtkTreePath *tree_path; - GCancellable *cancellable; - - file = data; - - info = g_new0 (struct ReloadIconsData, 1); - info->impl = g_object_ref (impl); - tree_path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter); - info->row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (impl->shortcuts_model), tree_path); - gtk_tree_path_free (tree_path); - - cancellable = _gtk_file_system_get_info (impl->file_system, file, - "standard::icon", - shortcuts_reload_icons_get_info_cb, - info); - impl->reload_icon_cancellables = g_slist_append (impl->reload_icon_cancellables, cancellable); - } - else - { - GtkIconTheme *icon_theme; - - /* Don't call get_info for remote paths to avoid latency and - * auth dialogs. - * If we switch to a better bookmarks file format (XBEL), we - * should use mime info to get a better icon. - */ - icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl))); - pixbuf = gtk_icon_theme_load_icon (icon_theme, "folder-remote", - impl->icon_size, 0, NULL); - } - } - else if (shortcut_type == SHORTCUT_TYPE_SEARCH) - { - pixbuf = render_search_icon (impl); - } - else if (shortcut_type == SHORTCUT_TYPE_RECENT) - { - pixbuf = render_recent_icon (impl); - } + if (impl->edited_new_text /* not cancelled? */ + && (strlen (impl->edited_new_text) != 0) + && (strcmp (impl->edited_new_text, DEFAULT_NEW_FOLDER_NAME) != 0)) /* Don't create folder if name is empty or has not been edited */ + { + GError *error = NULL; + GFile *file; - gtk_list_store_set (impl->shortcuts_model, &iter, - SHORTCUTS_COL_PIXBUF, pixbuf, - -1); + file = g_file_get_child_for_display_name (impl->current_folder, + impl->edited_new_text, + &error); + if (file) + { + GError *error = NULL; - if (pixbuf) - g_object_unref (pixbuf); + if (g_file_make_directory (file, NULL, &error)) + change_folder_and_display_error (impl, file, FALSE); + else + error_creating_folder_dialog (impl, file, error); + g_object_unref (file); } - } - while (gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model),&iter)); - - out: + else + error_creating_folder_dialog (impl, file, error); - profile_end ("end", NULL); -} - -static void -shortcuts_find_folder (GtkFileChooserDefault *impl, - GFile *folder) -{ - GtkTreeSelection *selection; - int pos; - GtkTreePath *path; - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view)); - - g_assert (folder != NULL); - pos = shortcut_find_position (impl, folder); - if (pos == -1) - { - gtk_tree_selection_unselect_all (selection); - return; - } - - path = gtk_tree_path_new_from_indices (pos, -1); - gtk_tree_selection_select_path (selection, path); - gtk_tree_path_free (path); -} - -/* Removes the specified number of rows from the shortcuts list */ -static void -shortcuts_remove_rows (GtkFileChooserDefault *impl, - int start_row, - int n_rows) -{ - GtkTreePath *path; - - path = gtk_tree_path_new_from_indices (start_row, -1); - - for (; n_rows; n_rows--) - { - GtkTreeIter iter; - - if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->shortcuts_model), &iter, path)) - g_assert_not_reached (); - - shortcuts_free_row_data (impl, &iter); - gtk_list_store_remove (impl->shortcuts_model, &iter); - } - - gtk_tree_path_free (path); -} - -static void -shortcuts_update_count (GtkFileChooserDefault *impl, - ShortcutsIndex type, - gint value) -{ - switch (type) - { - case SHORTCUTS_HOME: - if (value < 0) - impl->has_home = FALSE; - else - impl->has_home = TRUE; - break; - - case SHORTCUTS_DESKTOP: - if (value < 0) - impl->has_desktop = FALSE; - else - impl->has_desktop = TRUE; - break; - - case SHORTCUTS_VOLUMES: - impl->num_volumes += value; - break; - - case SHORTCUTS_SHORTCUTS: - impl->num_shortcuts += value; - break; - - case SHORTCUTS_BOOKMARKS: - impl->num_bookmarks += value; - break; - - case SHORTCUTS_CURRENT_FOLDER: - if (value < 0) - impl->shortcuts_current_folder_active = FALSE; - else - impl->shortcuts_current_folder_active = TRUE; - break; - - default: - /* nothing */ - break; - } -} - -struct ShortcutsInsertRequest -{ - GtkFileChooserDefault *impl; - GFile *file; - int pos; - char *label_copy; - GtkTreeRowReference *row_ref; - ShortcutsIndex type; - gboolean name_only; - gboolean removable; -}; - -static void -get_file_info_finished (GCancellable *cancellable, - GFileInfo *info, - const GError *error, - gpointer data) -{ - gboolean cancelled = g_cancellable_is_cancelled (cancellable); - GdkPixbuf *pixbuf; - GtkTreePath *path; - GtkTreeIter iter; - GCancellable *model_cancellable = NULL; - struct ShortcutsInsertRequest *request = data; - - path = gtk_tree_row_reference_get_path (request->row_ref); - if (!path) - /* Handle doesn't exist anymore in the model */ - goto out; - - gtk_tree_model_get_iter (GTK_TREE_MODEL (request->impl->shortcuts_model), - &iter, path); - gtk_tree_path_free (path); - - /* validate cancellable, else goto out */ - gtk_tree_model_get (GTK_TREE_MODEL (request->impl->shortcuts_model), &iter, - SHORTCUTS_COL_CANCELLABLE, &model_cancellable, - -1); - if (cancellable != model_cancellable) - goto out; - - /* set the cancellable to NULL in the model (we unref later on) */ - gtk_list_store_set (request->impl->shortcuts_model, &iter, - SHORTCUTS_COL_CANCELLABLE, NULL, - -1); - - if (cancelled) - goto out; - - if (!info) - { - gtk_list_store_remove (request->impl->shortcuts_model, &iter); - shortcuts_update_count (request->impl, request->type, -1); - - if (request->type == SHORTCUTS_HOME) - { - GFile *home; - - home = g_file_new_for_path (g_get_home_dir ()); - error_getting_info_dialog (request->impl, home, g_error_copy (error)); - g_object_unref (home); - } - else if (request->type == SHORTCUTS_CURRENT_FOLDER) - { -#if REMOVE_FOR_PLACES_SIDEBAR - /* Remove the current folder separator */ - gint separator_pos = shortcuts_get_index (request->impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR); - shortcuts_remove_rows (request->impl, separator_pos, 1); -#endif - } - - goto out; - } - - if (!request->label_copy) - request->label_copy = g_strdup (g_file_info_get_display_name (info)); - pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (request->impl), - request->impl->icon_size); - - gtk_list_store_set (request->impl->shortcuts_model, &iter, - SHORTCUTS_COL_PIXBUF, pixbuf, - SHORTCUTS_COL_PIXBUF_VISIBLE, TRUE, - SHORTCUTS_COL_NAME, request->label_copy, - SHORTCUTS_COL_TYPE, SHORTCUT_TYPE_FILE, - SHORTCUTS_COL_REMOVABLE, request->removable, - -1); - - if (request->impl->shortcuts_pane_filter_model) - gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (request->impl->shortcuts_pane_filter_model)); - - if (pixbuf) - g_object_unref (pixbuf); - -out: - g_object_unref (request->impl); - g_object_unref (request->file); - gtk_tree_row_reference_free (request->row_ref); - g_free (request->label_copy); - g_free (request); - - if (model_cancellable) - g_object_unref (model_cancellable); -} -#endif - -/* FIXME: GtkFileSystem needs a function to split a remote path - * into hostname and path components, or maybe just have a - * gtk_file_system_path_get_display_name(). - * - * This function is also used in gtkfilechooserbutton.c - */ -gchar * -_gtk_file_chooser_label_for_file (GFile *file) -{ - const gchar *path, *start, *end, *p; - gchar *uri, *host, *label; - - uri = g_file_get_uri (file); - - start = strstr (uri, "://"); - if (start) - { - start += 3; - path = strchr (start, '/'); - if (path) - end = path; - else - { - end = uri + strlen (uri); - path = "/"; - } - - /* strip username */ - p = strchr (start, '@'); - if (p && p < end) - start = p + 1; - - p = strchr (start, ':'); - if (p && p < end) - end = p; - - host = g_strndup (start, end - start); - - /* Translators: the first string is a path and the second string - * is a hostname. Nautilus and the panel contain the same string - * to translate. - */ - label = g_strdup_printf (_("%1$s on %2$s"), path, host); - - g_free (host); - } - else - { - label = g_strdup (uri); - } - - g_free (uri); - - return label; -} - -#if REMOVE_FOR_PLACES_SIDEBAR -/* Inserts a path in the shortcuts tree, making a copy of it; alternatively, - * inserts a volume. A position of -1 indicates the end of the tree. - */ -static void -shortcuts_insert_file (GtkFileChooserDefault *impl, - int pos, - ShortcutType shortcut_type, - GtkFileSystemVolume *volume, - GFile *file, - const char *label, - gboolean removable, - ShortcutsIndex type) -{ - char *label_copy; - GdkPixbuf *pixbuf = NULL; - gpointer data = NULL; - GtkTreeIter iter; - GtkIconTheme *icon_theme; - - profile_start ("start shortcut", NULL); - - if (shortcut_type == SHORTCUT_TYPE_VOLUME) - { - data = volume; - label_copy = _gtk_file_system_volume_get_display_name (volume); - pixbuf = _gtk_file_system_volume_render_icon (volume, GTK_WIDGET (impl), - impl->icon_size, NULL); - } - else if (shortcut_type == SHORTCUT_TYPE_FILE) - { - if (g_file_is_native (file)) - { - struct ShortcutsInsertRequest *request; - GCancellable *cancellable; - GtkTreePath *p; - - request = g_new0 (struct ShortcutsInsertRequest, 1); - request->impl = g_object_ref (impl); - request->file = g_object_ref (file); - request->name_only = TRUE; - request->removable = removable; - request->pos = pos; - request->type = type; - if (label) - request->label_copy = g_strdup (label); - - if (pos == -1) - gtk_list_store_append (impl->shortcuts_model, &iter); - else - gtk_list_store_insert (impl->shortcuts_model, &iter, pos); - - p = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter); - request->row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (impl->shortcuts_model), p); - gtk_tree_path_free (p); - - cancellable = _gtk_file_system_get_info (request->impl->file_system, request->file, - "standard::is-hidden,standard::is-backup,standard::display-name,standard::icon", - get_file_info_finished, request); - - gtk_list_store_set (impl->shortcuts_model, &iter, - SHORTCUTS_COL_DATA, g_object_ref (file), - SHORTCUTS_COL_TYPE, SHORTCUT_TYPE_FILE, - SHORTCUTS_COL_CANCELLABLE, cancellable, - -1); - - shortcuts_update_count (impl, type, 1); - - return; - } - else - { - /* Don't call get_info for remote paths to avoid latency and - * auth dialogs. - */ - data = g_object_ref (file); - if (label) - label_copy = g_strdup (label); - else - label_copy = _gtk_file_chooser_label_for_file (file); - - /* If we switch to a better bookmarks file format (XBEL), we - * should use mime info to get a better icon. - */ - icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl))); - pixbuf = gtk_icon_theme_load_icon (icon_theme, "folder-remote", - impl->icon_size, 0, NULL); - } - } - else - { - g_assert_not_reached (); - - return; - } - - if (pos == -1) - gtk_list_store_append (impl->shortcuts_model, &iter); - else - gtk_list_store_insert (impl->shortcuts_model, &iter, pos); - - shortcuts_update_count (impl, type, 1); - - gtk_list_store_set (impl->shortcuts_model, &iter, - SHORTCUTS_COL_PIXBUF, pixbuf, - SHORTCUTS_COL_PIXBUF_VISIBLE, TRUE, - SHORTCUTS_COL_NAME, label_copy, - SHORTCUTS_COL_DATA, data, - SHORTCUTS_COL_TYPE, shortcut_type, - SHORTCUTS_COL_REMOVABLE, removable, - SHORTCUTS_COL_CANCELLABLE, NULL, - -1); - - if (impl->shortcuts_pane_filter_model) - gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_pane_filter_model)); - - g_free (label_copy); - - if (pixbuf) - g_object_unref (pixbuf); - - profile_end ("end", NULL); -} - -static void -shortcuts_append_search (GtkFileChooserDefault *impl) -{ - GdkPixbuf *pixbuf; - GtkTreeIter iter; - - pixbuf = render_search_icon (impl); - - gtk_list_store_append (impl->shortcuts_model, &iter); - gtk_list_store_set (impl->shortcuts_model, &iter, - SHORTCUTS_COL_PIXBUF, pixbuf, - SHORTCUTS_COL_PIXBUF_VISIBLE, TRUE, - SHORTCUTS_COL_NAME, _("Search"), - SHORTCUTS_COL_DATA, NULL, - SHORTCUTS_COL_TYPE, SHORTCUT_TYPE_SEARCH, - SHORTCUTS_COL_REMOVABLE, FALSE, - -1); - - if (pixbuf) - g_object_unref (pixbuf); - - impl->has_search = TRUE; -} - -static void -shortcuts_append_recent (GtkFileChooserDefault *impl) -{ - GdkPixbuf *pixbuf; - GtkTreeIter iter; - - pixbuf = render_recent_icon (impl); - - gtk_list_store_append (impl->shortcuts_model, &iter); - gtk_list_store_set (impl->shortcuts_model, &iter, - SHORTCUTS_COL_PIXBUF, pixbuf, - SHORTCUTS_COL_PIXBUF_VISIBLE, TRUE, - SHORTCUTS_COL_NAME, _("Recently Used"), - SHORTCUTS_COL_DATA, NULL, - SHORTCUTS_COL_TYPE, SHORTCUT_TYPE_RECENT, - SHORTCUTS_COL_REMOVABLE, FALSE, - -1); - - if (pixbuf) - g_object_unref (pixbuf); -} - -/* Appends an item for the user's home directory to the shortcuts model */ -static void -shortcuts_append_home (GtkFileChooserDefault *impl) -{ - const char *home_path; - GFile *home; - - profile_start ("start", NULL); - - home_path = g_get_home_dir (); - if (home_path == NULL) - { - profile_end ("end - no home directory!?", NULL); - return; - } - - home = g_file_new_for_path (home_path); - shortcuts_insert_file (impl, -1, SHORTCUT_TYPE_FILE, NULL, home, NULL, FALSE, SHORTCUTS_HOME); - impl->has_home = TRUE; - - g_object_unref (home); - - profile_end ("end", NULL); -} - -/* Appends the ~/Desktop directory to the shortcuts model */ -static void -shortcuts_append_desktop (GtkFileChooserDefault *impl) -{ - const char *name; - GFile *file; - - profile_start ("start", NULL); - - name = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP); - /* "To disable a directory, point it to the homedir." - * See http://freedesktop.org/wiki/Software/xdg-user-dirs - **/ - if (!g_strcmp0 (name, g_get_home_dir ())) - { - profile_end ("end", NULL); - return; - } - - file = g_file_new_for_path (name); - shortcuts_insert_file (impl, -1, SHORTCUT_TYPE_FILE, NULL, file, _("Desktop"), FALSE, SHORTCUTS_DESKTOP); - impl->has_desktop = TRUE; - - /* We do not actually pop up an error dialog if there is no desktop directory - * because some people may really not want to have one. - */ - - g_object_unref (file); - - profile_end ("end", NULL); -} - -/* Appends a list of GFile to the shortcuts model; returns how many were inserted */ -static int -shortcuts_append_bookmarks (GtkFileChooserDefault *impl, - GSList *bookmarks) -{ - int start_row; - int num_inserted; - gchar *label; - - profile_start ("start", NULL); - - start_row = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR) + 1; - num_inserted = 0; - - for (; bookmarks; bookmarks = bookmarks->next) - { - GFile *file; - - file = bookmarks->data; - - if (impl->local_only && !g_file_is_native (file)) - continue; - - if (shortcut_find_position (impl, file) != -1) - continue; - - label = _gtk_bookmarks_manager_get_bookmark_label (impl->bookmarks_manager, file); - - shortcuts_insert_file (impl, start_row + num_inserted, SHORTCUT_TYPE_FILE, NULL, file, label, TRUE, SHORTCUTS_BOOKMARKS); - g_free (label); - - num_inserted++; - } - - profile_end ("end", NULL); - - return num_inserted; -} - -/* Returns the index for the corresponding item in the shortcuts bar */ -static int -shortcuts_get_index (GtkFileChooserDefault *impl, - ShortcutsIndex where) -{ - int n; - - n = 0; - - if (where == SHORTCUTS_SEARCH) - goto out; - - n += impl->has_search ? 1 : 0; - - if (where == SHORTCUTS_RECENT) - goto out; - - n += 1; /* we always have the recently-used item */ - - if (where == SHORTCUTS_RECENT_SEPARATOR) - goto out; - - n += 1; /* we always have the separator after the recently-used item */ - - if (where == SHORTCUTS_HOME) - goto out; - - n += impl->has_home ? 1 : 0; - - if (where == SHORTCUTS_DESKTOP) - goto out; - - n += impl->has_desktop ? 1 : 0; - - if (where == SHORTCUTS_VOLUMES) - goto out; - - n += impl->num_volumes; - - if (where == SHORTCUTS_SHORTCUTS) - goto out; - - n += impl->num_shortcuts; - - if (where == SHORTCUTS_BOOKMARKS_SEPARATOR) - goto out; - - /* If there are no bookmarks there won't be a separator */ - n += (impl->num_bookmarks > 0) ? 1 : 0; - - if (where == SHORTCUTS_BOOKMARKS) - goto out; - - n += impl->num_bookmarks; - - if (where == SHORTCUTS_CURRENT_FOLDER_SEPARATOR) - goto out; - - n += 1; - - if (where == SHORTCUTS_CURRENT_FOLDER) - goto out; - - g_assert_not_reached (); - - out: - - return n; -} - -/* Adds all the file system volumes to the shortcuts model */ -static void -shortcuts_add_volumes (GtkFileChooserDefault *impl) -{ - int start_row; - GSList *list, *l; - int n; - gboolean old_changing_folders; - - profile_start ("start", NULL); - - old_changing_folders = impl->changing_folder; - impl->changing_folder = TRUE; - - start_row = shortcuts_get_index (impl, SHORTCUTS_VOLUMES); - shortcuts_remove_rows (impl, start_row, impl->num_volumes); - impl->num_volumes = 0; - - list = _gtk_file_system_list_volumes (impl->file_system); - - n = 0; - - for (l = list; l; l = l->next) - { - GtkFileSystemVolume *volume; - - volume = l->data; - - if (impl->local_only) - { - if (_gtk_file_system_volume_is_mounted (volume)) - { - GFile *base_file; - gboolean base_is_native = TRUE; - - base_file = _gtk_file_system_volume_get_root (volume); - if (base_file != NULL) - { - base_is_native = g_file_is_native (base_file); - g_object_unref (base_file); - } - - if (!base_is_native) - continue; - } - } - - shortcuts_insert_file (impl, - start_row + n, - SHORTCUT_TYPE_VOLUME, - _gtk_file_system_volume_ref (volume), - NULL, - NULL, - FALSE, - SHORTCUTS_VOLUMES); - n++; - } - - impl->num_volumes = n; - g_slist_free (list); - - if (impl->shortcuts_pane_filter_model) - gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_pane_filter_model)); - - impl->changing_folder = old_changing_folders; - - profile_end ("end", NULL); -} - -/* Inserts a separator node in the shortcuts list */ -static void -shortcuts_insert_separator (GtkFileChooserDefault *impl, - ShortcutsIndex where) -{ - GtkTreeIter iter; - - g_assert (where == SHORTCUTS_RECENT_SEPARATOR || - where == SHORTCUTS_BOOKMARKS_SEPARATOR || - where == SHORTCUTS_CURRENT_FOLDER_SEPARATOR); - - gtk_list_store_insert (impl->shortcuts_model, &iter, - shortcuts_get_index (impl, where)); - gtk_list_store_set (impl->shortcuts_model, &iter, - SHORTCUTS_COL_PIXBUF, NULL, - SHORTCUTS_COL_PIXBUF_VISIBLE, FALSE, - SHORTCUTS_COL_NAME, NULL, - SHORTCUTS_COL_DATA, NULL, - SHORTCUTS_COL_TYPE, SHORTCUT_TYPE_SEPARATOR, - -1); -} - -/* Updates the list of bookmarks */ -static void -shortcuts_add_bookmarks (GtkFileChooserDefault *impl) -{ - GSList *bookmarks; - gboolean old_changing_folders; - GtkTreeIter iter; - GFile *list_selected = NULL; - ShortcutType shortcut_type; - gpointer col_data; - - profile_start ("start", NULL); - - old_changing_folders = impl->changing_folder; - impl->changing_folder = TRUE; - - if (shortcuts_get_selected (impl, &iter)) - { - gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), - &iter, - SHORTCUTS_COL_DATA, &col_data, - SHORTCUTS_COL_TYPE, &shortcut_type, - -1); - - if (col_data && shortcut_type == SHORTCUT_TYPE_FILE) - list_selected = g_object_ref (col_data); - } - - if (impl->num_bookmarks > 0) - shortcuts_remove_rows (impl, - shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR), - impl->num_bookmarks + 1); - - impl->num_bookmarks = 0; - shortcuts_insert_separator (impl, SHORTCUTS_BOOKMARKS_SEPARATOR); - - bookmarks = _gtk_bookmarks_manager_list_bookmarks (impl->bookmarks_manager); - shortcuts_append_bookmarks (impl, bookmarks); - g_slist_foreach (bookmarks, (GFunc) g_object_unref, NULL); - g_slist_free (bookmarks); - - if (impl->num_bookmarks == 0) - shortcuts_remove_rows (impl, shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR), 1); - - if (impl->shortcuts_pane_filter_model) - gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_pane_filter_model)); - - if (list_selected) - { - shortcuts_find_folder (impl, list_selected); - g_object_unref (list_selected); - } - - impl->changing_folder = old_changing_folders; - - profile_end ("end", NULL); -} - -/* Appends a separator and a row to the shortcuts list for the current folder */ -static void -shortcuts_add_current_folder (GtkFileChooserDefault *impl) -{ - int pos; - - g_assert (!impl->shortcuts_current_folder_active); - - g_assert (impl->current_folder != NULL); - - pos = shortcut_find_position (impl, impl->current_folder); - if (pos == -1) - { - GtkFileSystemVolume *volume; - GFile *base_file; - - /* Separator */ - shortcuts_insert_separator (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR); - - /* Item */ - pos = shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER); - - volume = _gtk_file_system_get_volume_for_file (impl->file_system, impl->current_folder); - if (volume) - base_file = _gtk_file_system_volume_get_root (volume); - else - base_file = NULL; - - if (base_file && g_file_equal (base_file, impl->current_folder)) - shortcuts_insert_file (impl, pos, SHORTCUT_TYPE_VOLUME, volume, NULL, NULL, FALSE, SHORTCUTS_CURRENT_FOLDER); - else - shortcuts_insert_file (impl, pos, SHORTCUT_TYPE_FILE, NULL, impl->current_folder, NULL, FALSE, SHORTCUTS_CURRENT_FOLDER); - - if (base_file) - g_object_unref (base_file); - } -} - -/* Updates the current folder row in the shortcuts model */ -static void -shortcuts_update_current_folder (GtkFileChooserDefault *impl) -{ - int pos; - - pos = shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR); - - if (impl->shortcuts_current_folder_active) - { - shortcuts_remove_rows (impl, pos, 2); - impl->shortcuts_current_folder_active = FALSE; - } - - shortcuts_add_current_folder (impl); -} - -/* Filter function used for the shortcuts filter model */ -static gboolean -shortcuts_pane_filter_cb (GtkTreeModel *model, - GtkTreeIter *iter, - gpointer data) -{ - GtkFileChooserDefault *impl; - GtkTreePath *path; - int pos; - - impl = GTK_FILE_CHOOSER_DEFAULT (data); - - path = gtk_tree_model_get_path (model, iter); - if (!path) - return FALSE; - - pos = *gtk_tree_path_get_indices (path); - gtk_tree_path_free (path); - - return (pos < shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR)); -} - -/* Creates the list model for shortcuts */ -static void -shortcuts_model_create (GtkFileChooserDefault *impl) -{ - /* Keep this order in sync with the SHORCUTS_COL_* enum values */ - impl->shortcuts_model = gtk_list_store_new (SHORTCUTS_COL_NUM_COLUMNS, - GDK_TYPE_PIXBUF, /* pixbuf */ - G_TYPE_STRING, /* name */ - G_TYPE_POINTER, /* path or volume */ - G_TYPE_INT, /* ShortcutType */ - G_TYPE_BOOLEAN, /* removable */ - G_TYPE_BOOLEAN, /* pixbuf cell visibility */ - G_TYPE_POINTER); /* GCancellable */ - - shortcuts_append_search (impl); - - if (impl->recent_manager) - { - shortcuts_append_recent (impl); - shortcuts_insert_separator (impl, SHORTCUTS_RECENT_SEPARATOR); - } - - if (impl->file_system) - { - shortcuts_append_home (impl); - shortcuts_append_desktop (impl); - shortcuts_add_volumes (impl); - } - - impl->shortcuts_pane_filter_model = shortcuts_pane_model_filter_new (impl, - GTK_TREE_MODEL (impl->shortcuts_model), - NULL); - - gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (impl->shortcuts_pane_filter_model), - shortcuts_pane_filter_cb, - impl, - NULL); -} -#endif - -/* Callback used when the "New Folder" button is clicked */ -static void -new_folder_button_clicked (GtkButton *button, - GtkFileChooserDefault *impl) -{ - GtkTreeIter iter; - GtkTreePath *path; - - if (!impl->browse_files_model) - return; /* FIXME: this sucks. Disable the New Folder button or something. */ - - /* Prevent button from being clicked twice */ - gtk_widget_set_sensitive (impl->browse_new_folder_button, FALSE); - - _gtk_file_system_model_add_editable (impl->browse_files_model, &iter); - - path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->browse_files_model), &iter); - gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (impl->browse_files_tree_view), - path, impl->list_name_column, - FALSE, 0.0, 0.0); - - g_object_set (impl->list_name_renderer, "editable", TRUE, NULL); - gtk_tree_view_set_cursor (GTK_TREE_VIEW (impl->browse_files_tree_view), - path, - impl->list_name_column, - TRUE); - - gtk_tree_path_free (path); -} - -static GSource * -add_idle_while_impl_is_alive (GtkFileChooserDefault *impl, GCallback callback) -{ - GSource *source; - - source = g_idle_source_new (); - g_source_set_closure (source, - g_cclosure_new_object (callback, G_OBJECT (impl))); - g_source_attach (source, NULL); - - return source; -} - -/* Idle handler for creating a new folder after editing its name cell, or for - * canceling the editing. - */ -static gboolean -edited_idle_cb (GtkFileChooserDefault *impl) -{ - gdk_threads_enter (); - - g_source_destroy (impl->edited_idle); - impl->edited_idle = NULL; - - _gtk_file_system_model_remove_editable (impl->browse_files_model); - g_object_set (impl->list_name_renderer, "editable", FALSE, NULL); - - gtk_widget_set_sensitive (impl->browse_new_folder_button, TRUE); - - if (impl->edited_new_text /* not cancelled? */ - && (strlen (impl->edited_new_text) != 0) - && (strcmp (impl->edited_new_text, DEFAULT_NEW_FOLDER_NAME) != 0)) /* Don't create folder if name is empty or has not been edited */ - { - GError *error = NULL; - GFile *file; - - file = g_file_get_child_for_display_name (impl->current_folder, - impl->edited_new_text, - &error); - if (file) - { - GError *error = NULL; - - if (g_file_make_directory (file, NULL, &error)) - change_folder_and_display_error (impl, file, FALSE); - else - error_creating_folder_dialog (impl, file, error); - - g_object_unref (file); - } - else - error_creating_folder_dialog (impl, file, error); - - g_free (impl->edited_new_text); - impl->edited_new_text = NULL; - } - - gdk_threads_leave (); - - return FALSE; -} - -static void -queue_edited_idle (GtkFileChooserDefault *impl, - const gchar *new_text) -{ - /* We create the folder in an idle handler so that we don't modify the tree - * just now. - */ - - if (!impl->edited_idle) - impl->edited_idle = add_idle_while_impl_is_alive (impl, G_CALLBACK (edited_idle_cb)); - - g_free (impl->edited_new_text); - impl->edited_new_text = g_strdup (new_text); -} - -/* Callback used from the text cell renderer when the new folder is named */ -static void -renderer_edited_cb (GtkCellRendererText *cell_renderer_text, - const gchar *path, - const gchar *new_text, - GtkFileChooserDefault *impl) -{ - /* work around bug #154921 */ - g_object_set (cell_renderer_text, - "mode", GTK_CELL_RENDERER_MODE_INERT, NULL); - queue_edited_idle (impl, new_text); -} - -/* Callback used from the text cell renderer when the new folder edition gets - * canceled. - */ -static void -renderer_editing_canceled_cb (GtkCellRendererText *cell_renderer_text, - GtkFileChooserDefault *impl) -{ - /* work around bug #154921 */ - g_object_set (cell_renderer_text, - "mode", GTK_CELL_RENDERER_MODE_INERT, NULL); - queue_edited_idle (impl, NULL); -} - -/* Creates the widgets for the filter combo box */ -static GtkWidget * -filter_create (GtkFileChooserDefault *impl) -{ - GtkCellRenderer *cell; - GList *cells; - - impl->filter_combo = gtk_combo_box_text_new (); - gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (impl->filter_combo), FALSE); - - /* Get the combo's text renderer and set ellipsize parameters */ - cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (impl->filter_combo)); - g_assert (cells); - cell = cells->data; - - g_object_set (G_OBJECT (cell), - "ellipsize", PANGO_ELLIPSIZE_END, - NULL); - - g_list_free (cells); - - g_signal_connect (impl->filter_combo, "changed", - G_CALLBACK (filter_combo_changed), impl); - - gtk_widget_set_tooltip_text (impl->filter_combo, - _("Select which types of files are shown")); - - return impl->filter_combo; -} - -static GtkWidget * -toolbutton_new (GtkFileChooserDefault *impl, - GIcon *icon, - gboolean sensitive, - gboolean show, - GCallback callback) -{ - GtkToolItem *item; - GtkWidget *image; - - item = gtk_tool_button_new (NULL, NULL); - image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_SMALL_TOOLBAR); - gtk_widget_show (image); - gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (item), image); - - gtk_widget_set_sensitive (GTK_WIDGET (item), sensitive); - g_signal_connect (item, "clicked", callback, impl); - - if (show) - gtk_widget_show (GTK_WIDGET (item)); - - return GTK_WIDGET (item); -} - -#if REMOVE_FOR_PLACES_SIDEBAR -/* Looks for a path among the shortcuts; returns its index or -1 if it doesn't exist */ -static int -shortcut_find_position (GtkFileChooserDefault *impl, - GFile *file) -{ - GtkTreeIter iter; - int i; - int current_folder_separator_idx; - - if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter)) - return -1; - - current_folder_separator_idx = shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR); - -#if 0 - /* FIXME: is this still needed? */ - if (current_folder_separator_idx >= impl->shortcuts_model->length) - return -1; -#endif - - for (i = 0; i < current_folder_separator_idx; i++) - { - gpointer col_data; - ShortcutType shortcut_type; - - gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, - SHORTCUTS_COL_DATA, &col_data, - SHORTCUTS_COL_TYPE, &shortcut_type, - -1); - - if (col_data) - { - if (shortcut_type == SHORTCUT_TYPE_VOLUME) - { - GtkFileSystemVolume *volume; - GFile *base_file; - gboolean exists; - - volume = col_data; - base_file = _gtk_file_system_volume_get_root (volume); - - exists = base_file && g_file_equal (file, base_file); - - if (base_file) - g_object_unref (base_file); - - if (exists) - return i; - } - else if (shortcut_type == SHORTCUT_TYPE_FILE) - { - GFile *model_file; - - model_file = col_data; - - if (model_file && g_file_equal (model_file, file)) - return i; - } - } - - if (i < current_folder_separator_idx - 1) - { - if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter)) - g_assert_not_reached (); - } - } - - return -1; -} - -/* Tries to add a bookmark from a path name */ -static gboolean -shortcuts_add_bookmark_from_file (GtkFileChooserDefault *impl, - GFile *file, - int pos) -{ - GError *error; - - g_return_val_if_fail (G_IS_FILE (file), FALSE); - - if (shortcut_find_position (impl, file) != -1) - return FALSE; - - error = NULL; - if (!_gtk_bookmarks_manager_insert_bookmark (impl->bookmarks_manager, file, pos, &error)) - { - error_adding_bookmark_dialog (impl, file, error); - return FALSE; - } - - return TRUE; -} - -static void -add_bookmark_foreach_cb (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - gpointer data) -{ - GtkFileChooserDefault *impl; - GFile *file; - - impl = (GtkFileChooserDefault *) data; - - gtk_tree_model_get (model, iter, - MODEL_COL_FILE, &file, - -1); - - shortcuts_add_bookmark_from_file (impl, file, -1); - - g_object_unref (file); -} - -/* Adds a bookmark from the currently selected item in the file list */ -static void -bookmarks_add_selected_folder (GtkFileChooserDefault *impl) -{ - GtkTreeSelection *selection; - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view)); - - if (gtk_tree_selection_count_selected_rows (selection) == 0) - shortcuts_add_bookmark_from_file (impl, impl->current_folder, -1); - else - gtk_tree_selection_selected_foreach (selection, - add_bookmark_foreach_cb, - impl); -} - -/* Callback used when the "Add bookmark" button is clicked */ -static void -add_bookmark_button_clicked_cb (GtkButton *button, - GtkFileChooserDefault *impl) -{ - bookmarks_add_selected_folder (impl); -} - -/* Returns TRUE plus an iter in the shortcuts_model if a row is selected; - * returns FALSE if no shortcut is selected. - */ -static gboolean -shortcuts_get_selected (GtkFileChooserDefault *impl, - GtkTreeIter *iter) -{ - GtkTreeSelection *selection; - GtkTreeIter parent_iter; - - if (!impl->browse_shortcuts_tree_view) - return FALSE; - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view)); - - if (!gtk_tree_selection_get_selected (selection, NULL, &parent_iter)) - return FALSE; - - gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (impl->shortcuts_pane_filter_model), - iter, - &parent_iter); - return TRUE; -} - -/* Removes the selected bookmarks */ -static void -remove_selected_bookmarks (GtkFileChooserDefault *impl) -{ - GtkTreeIter iter; - gpointer col_data; - GFile *file; - gboolean removable; - GError *error; - - if (!shortcuts_get_selected (impl, &iter)) - return; - - gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, - SHORTCUTS_COL_DATA, &col_data, - SHORTCUTS_COL_REMOVABLE, &removable, - -1); - - if (!removable) - return; - - g_assert (col_data != NULL); - - file = col_data; - - error = NULL; - if (!_gtk_bookmarks_manager_remove_bookmark (impl->bookmarks_manager, file, &error)) - error_removing_bookmark_dialog (impl, file, error); -} - -/* Callback used when the "Remove bookmark" button is clicked */ -static void -remove_bookmark_button_clicked_cb (GtkButton *button, - GtkFileChooserDefault *impl) -{ - remove_selected_bookmarks (impl); -} -#endif - -struct selection_check_closure { - GtkFileChooserDefault *impl; - int num_selected; - gboolean all_files; - gboolean all_folders; -}; - -/* Used from gtk_tree_selection_selected_foreach() */ -static void -selection_check_foreach_cb (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - gpointer data) -{ - struct selection_check_closure *closure; - gboolean is_folder; - GFile *file; - - gtk_tree_model_get (model, iter, - MODEL_COL_FILE, &file, - MODEL_COL_IS_FOLDER, &is_folder, - -1); - - if (file == NULL) - return; - - g_object_unref (file); - - closure = data; - closure->num_selected++; - - closure->all_folders = closure->all_folders && is_folder; - closure->all_files = closure->all_files && !is_folder; -} - -/* Checks whether the selected items in the file list are all files or all folders */ -static void -selection_check (GtkFileChooserDefault *impl, - gint *num_selected, - gboolean *all_files, - gboolean *all_folders) -{ - struct selection_check_closure closure; - GtkTreeSelection *selection; - - closure.impl = impl; - closure.num_selected = 0; - closure.all_files = TRUE; - closure.all_folders = TRUE; - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view)); - gtk_tree_selection_selected_foreach (selection, - selection_check_foreach_cb, - &closure); - - g_assert (closure.num_selected == 0 || !(closure.all_files && closure.all_folders)); - - if (num_selected) - *num_selected = closure.num_selected; - - if (all_files) - *all_files = closure.all_files; - - if (all_folders) - *all_folders = closure.all_folders; -} - -struct get_selected_file_closure { - GtkFileChooserDefault *impl; - GFile *file; -}; - -static void -get_selected_file_foreach_cb (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - gpointer data) -{ - struct get_selected_file_closure *closure = data; - - if (closure->file) - { - /* Just in case this function gets run more than once with a multiple selection; we only care about one file */ - g_object_unref (closure->file); - closure->file = NULL; - } - - gtk_tree_model_get (model, iter, - MODEL_COL_FILE, &closure->file, /* this will give us a reffed file */ - -1); -} - -/* Returns a selected path from the file list */ -static GFile * -get_selected_file (GtkFileChooserDefault *impl) -{ - struct get_selected_file_closure closure; - GtkTreeSelection *selection; - - closure.impl = impl; - closure.file = NULL; - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view)); - gtk_tree_selection_selected_foreach (selection, - get_selected_file_foreach_cb, - &closure); - - return closure.file; -} - -typedef struct { - GtkFileChooserDefault *impl; - gchar *tip; -} UpdateTooltipData; - -static void -update_tooltip (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - gpointer data) -{ - UpdateTooltipData *udata = data; - - if (udata->tip == NULL) - { - gchar *display_name; - - gtk_tree_model_get (model, iter, - MODEL_COL_NAME, &display_name, - -1); - - udata->tip = g_strdup_printf (_("Add the folder '%s' to the bookmarks"), - display_name); - g_free (display_name); - } -} - -#if REMOVE_FOR_PLACES_SIDEBAR -/* Sensitize the "add bookmark" button if all the selected items are folders, or - * if there are no selected items *and* the current folder is not in the - * bookmarks list. De-sensitize the button otherwise. - */ -static void -bookmarks_check_add_sensitivity (GtkFileChooserDefault *impl) -{ - gint num_selected; - gboolean all_folders; - gboolean active; - gchar *tip; - - selection_check (impl, &num_selected, NULL, &all_folders); - - if (num_selected == 0) - active = (impl->current_folder != NULL) && (shortcut_find_position (impl, impl->current_folder) == -1); - else if (num_selected == 1) - { - GFile *file; - - file = get_selected_file (impl); - active = file && all_folders && (shortcut_find_position (impl, file) == -1); - if (file) - g_object_unref (file); - } - else - active = all_folders; - - gtk_widget_set_sensitive (impl->browse_shortcuts_add_button, active); - - if (impl->browse_files_popup_menu_add_shortcut_item) - gtk_widget_set_sensitive (impl->browse_files_popup_menu_add_shortcut_item, - (num_selected == 0) ? FALSE : active); - - if (active) - { - if (num_selected == 0) - tip = g_strdup_printf (_("Add the current folder to the bookmarks")); - else if (num_selected > 1) - tip = g_strdup_printf (_("Add the selected folders to the bookmarks")); - else - { - GtkTreeSelection *selection; - UpdateTooltipData data; - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view)); - data.impl = impl; - data.tip = NULL; - gtk_tree_selection_selected_foreach (selection, update_tooltip, &data); - tip = data.tip; - } - - gtk_widget_set_tooltip_text (impl->browse_shortcuts_add_button, tip); - g_free (tip); - } -} - -/* Sets the sensitivity of the "remove bookmark" button depending on whether a - * bookmark row is selected in the shortcuts tree. - */ -static void -bookmarks_check_remove_sensitivity (GtkFileChooserDefault *impl) -{ - GtkTreeIter iter; - gboolean removable = FALSE; - gchar *name = NULL; - gchar *tip; - - if (shortcuts_get_selected (impl, &iter)) - { - gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, - SHORTCUTS_COL_REMOVABLE, &removable, - SHORTCUTS_COL_NAME, &name, - -1); - gtk_widget_set_sensitive (impl->browse_shortcuts_remove_button, removable); - - if (removable) - tip = g_strdup_printf (_("Remove the bookmark '%s'"), name); - else - tip = g_strdup_printf (_("Bookmark '%s' cannot be removed"), name); - - gtk_widget_set_tooltip_text (impl->browse_shortcuts_remove_button, tip); - g_free (tip); - } - else - gtk_widget_set_tooltip_text (impl->browse_shortcuts_remove_button, - _("Remove the selected bookmark")); - g_free (name); -} - -static void -shortcuts_check_popup_sensitivity (GtkFileChooserDefault *impl) -{ - GtkTreeIter iter; - gboolean removable = FALSE; - - if (impl->browse_shortcuts_popup_menu == NULL) - return; - - if (shortcuts_get_selected (impl, &iter)) - gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, - SHORTCUTS_COL_REMOVABLE, &removable, - -1); - - gtk_widget_set_sensitive (impl->browse_shortcuts_popup_menu_remove_item, removable); - gtk_widget_set_sensitive (impl->browse_shortcuts_popup_menu_rename_item, removable); -} - -/* GtkWidget::drag-begin handler for the shortcuts list. */ -static void -shortcuts_drag_begin_cb (GtkWidget *widget, - GdkDragContext *context, - GtkFileChooserDefault *impl) -{ -#if 0 - impl->shortcuts_drag_context = g_object_ref (context); -#endif -} - -#if 0 -/* Removes the idle handler for outside drags */ -static void -shortcuts_cancel_drag_outside_idle (GtkFileChooserDefault *impl) -{ - if (!impl->shortcuts_drag_outside_idle) - return; - - g_source_destroy (impl->shortcuts_drag_outside_idle); - impl->shortcuts_drag_outside_idle = NULL; -} -#endif - -/* GtkWidget::drag-end handler for the shortcuts list. */ -static void -shortcuts_drag_end_cb (GtkWidget *widget, - GdkDragContext *context, - GtkFileChooserDefault *impl) -{ -#if 0 - g_object_unref (impl->shortcuts_drag_context); - - shortcuts_cancel_drag_outside_idle (impl); - - if (!impl->shortcuts_drag_outside) - return; - - gtk_button_clicked (GTK_BUTTON (impl->browse_shortcuts_remove_button)); - - impl->shortcuts_drag_outside = FALSE; -#endif -} - -/* GtkWidget::drag-data-delete handler for the shortcuts list. */ -static void -shortcuts_drag_data_delete_cb (GtkWidget *widget, - GdkDragContext *context, - GtkFileChooserDefault *impl) -{ - g_signal_stop_emission_by_name (widget, "drag-data-delete"); -} - -/* GtkWidget::drag-leave handler for the shortcuts list. We unhighlight the - * drop position. - */ -static void -shortcuts_drag_leave_cb (GtkWidget *widget, - GdkDragContext *context, - guint time_, - GtkFileChooserDefault *impl) -{ -#if 0 - if (gtk_drag_get_source_widget (context) == widget && !impl->shortcuts_drag_outside_idle) - { - impl->shortcuts_drag_outside_idle = add_idle_while_impl_is_alive (impl, G_CALLBACK (shortcuts_drag_outside_idle_cb)); - } -#endif - - gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), - NULL, - GTK_TREE_VIEW_DROP_BEFORE); - - g_signal_stop_emission_by_name (widget, "drag-leave"); -} - -/* Computes the appropriate row and position for dropping */ -static void -shortcuts_compute_drop_position (GtkFileChooserDefault *impl, - int x, - int y, - GtkTreePath **path, - GtkTreeViewDropPosition *pos) -{ - GtkTreeView *tree_view; - GtkTreeViewColumn *column; - int cell_y; - GdkRectangle cell; - int row; - int bookmarks_index; - int header_height = 0; - - tree_view = GTK_TREE_VIEW (impl->browse_shortcuts_tree_view); - - if (gtk_tree_view_get_headers_visible (tree_view)) - header_height = _gtk_tree_view_get_header_height (tree_view); - - bookmarks_index = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS); - - if (!gtk_tree_view_get_path_at_pos (tree_view, - x, - y - header_height, - path, - &column, - NULL, - &cell_y)) - { - row = bookmarks_index + impl->num_bookmarks - 1; - *path = gtk_tree_path_new_from_indices (row, -1); - *pos = GTK_TREE_VIEW_DROP_AFTER; - return; - } - - row = *gtk_tree_path_get_indices (*path); - gtk_tree_view_get_background_area (tree_view, *path, column, &cell); - gtk_tree_path_free (*path); - - if (row < bookmarks_index) - { - row = bookmarks_index; - *pos = GTK_TREE_VIEW_DROP_BEFORE; - } - else if (row > bookmarks_index + impl->num_bookmarks - 1) - { - row = bookmarks_index + impl->num_bookmarks - 1; - *pos = GTK_TREE_VIEW_DROP_AFTER; - } - else - { - if (cell_y < cell.height / 2) - *pos = GTK_TREE_VIEW_DROP_BEFORE; - else - *pos = GTK_TREE_VIEW_DROP_AFTER; - } - - *path = gtk_tree_path_new_from_indices (row, -1); -} - -/* GtkWidget::drag-motion handler for the shortcuts list. We basically - * implement the destination side of DnD by hand, due to limitations in - * GtkTreeView's DnD API. - */ -static gboolean -shortcuts_drag_motion_cb (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time_, - GtkFileChooserDefault *impl) -{ - GtkTreePath *path; - GtkTreeViewDropPosition pos; - GdkDragAction action; - -#if 0 - if (gtk_drag_get_source_widget (context) == widget) - { - shortcuts_cancel_drag_outside_idle (impl); - - if (impl->shortcuts_drag_outside) - { - shortcuts_drag_set_delete_cursor (impl, FALSE); - impl->shortcuts_drag_outside = FALSE; - } - } -#endif - - if (gdk_drag_context_get_suggested_action (context) == GDK_ACTION_COPY || - (gdk_drag_context_get_actions (context) & GDK_ACTION_COPY) != 0) - action = GDK_ACTION_COPY; - else if (gdk_drag_context_get_suggested_action (context) == GDK_ACTION_MOVE || - (gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0) - action = GDK_ACTION_MOVE; - else - { - action = 0; - goto out; - } - - shortcuts_compute_drop_position (impl, x, y, &path, &pos); - gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), path, pos); - gtk_tree_path_free (path); - - out: - - g_signal_stop_emission_by_name (widget, "drag-motion"); - - if (action != 0) - { - gdk_drag_status (context, action, time_); - return TRUE; - } - else - return FALSE; -} - -/* GtkWidget::drag-drop handler for the shortcuts list. */ -static gboolean -shortcuts_drag_drop_cb (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time_, - GtkFileChooserDefault *impl) -{ -#if 0 - shortcuts_cancel_drag_outside_idle (impl); -#endif - - g_signal_stop_emission_by_name (widget, "drag-drop"); - return TRUE; -} - -/* Parses a "text/uri-list" string and inserts its URIs as bookmarks */ -static void -shortcuts_drop_uris (GtkFileChooserDefault *impl, - GtkSelectionData *selection_data, - int position) -{ - gchar **uris; - gint i; - - uris = gtk_selection_data_get_uris (selection_data); - if (!uris) - return; - - for (i = 0; uris[i]; i++) - { - char *uri; - GFile *file; - - uri = uris[i]; - file = g_file_new_for_uri (uri); - - if (shortcuts_add_bookmark_from_file (impl, file, position)) - position++; - - g_object_unref (file); - } - - g_strfreev (uris); -} - -/* Reorders the selected bookmark to the specified position */ -static void -shortcuts_reorder (GtkFileChooserDefault *impl, - int new_position) -{ - GtkTreeIter iter; - gpointer col_data; - ShortcutType shortcut_type; - GtkTreePath *path; - int old_position; - int bookmarks_index; - GFile *file; - GError *error; - gchar *name = NULL; - - /* Get the selected path */ - - if (!shortcuts_get_selected (impl, &iter)) - g_assert_not_reached (); - - path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter); - old_position = *gtk_tree_path_get_indices (path); - gtk_tree_path_free (path); - - bookmarks_index = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS); - old_position -= bookmarks_index; - g_assert (old_position >= 0 && old_position < impl->num_bookmarks); - - gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, - SHORTCUTS_COL_NAME, &name, - SHORTCUTS_COL_DATA, &col_data, - SHORTCUTS_COL_TYPE, &shortcut_type, - -1); - g_assert (col_data != NULL); - g_assert (shortcut_type == SHORTCUT_TYPE_FILE); - - file = col_data; - g_object_ref (file); /* removal below will free file, so we need a new ref */ - - /* Remove the path from the old position and insert it in the new one */ - - if (new_position > old_position) - new_position--; - - if (old_position == new_position) - goto out; - - error = NULL; - if (_gtk_bookmarks_manager_remove_bookmark (impl->bookmarks_manager, file, &error)) - { - shortcuts_add_bookmark_from_file (impl, file, new_position); - _gtk_bookmarks_manager_set_bookmark_label (impl->bookmarks_manager, file, name); - } - else - error_adding_bookmark_dialog (impl, file, error); - - out: - - g_object_unref (file); - g_free (name); -} - -/* Callback used when we get the drag data for the bookmarks list. We add the - * received URIs as bookmarks if they are folders. - */ -static void -shortcuts_drag_data_received_cb (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *selection_data, - guint info, - guint time_, - gpointer data) -{ - GtkFileChooserDefault *impl; - GtkTreePath *tree_path; - GtkTreeViewDropPosition tree_pos; - GdkAtom target; - int position; - int bookmarks_index; - - impl = GTK_FILE_CHOOSER_DEFAULT (data); - - /* Compute position */ - - bookmarks_index = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS); - - shortcuts_compute_drop_position (impl, x, y, &tree_path, &tree_pos); - position = *gtk_tree_path_get_indices (tree_path); - gtk_tree_path_free (tree_path); - - if (tree_pos == GTK_TREE_VIEW_DROP_AFTER) - position++; - - g_assert (position >= bookmarks_index); - position -= bookmarks_index; - - target = gtk_selection_data_get_target (selection_data); - - if (gtk_targets_include_uri (&target, 1)) - shortcuts_drop_uris (impl, selection_data, position); - else if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW")) - shortcuts_reorder (impl, position); - - g_signal_stop_emission_by_name (widget, "drag-data-received"); -} - -/* Callback used to display a tooltip in the shortcuts tree */ -static gboolean -shortcuts_query_tooltip_cb (GtkWidget *widget, - gint x, - gint y, - gboolean keyboard_mode, - GtkTooltip *tooltip, - GtkFileChooserDefault *impl) -{ - GtkTreeModel *model; - GtkTreeIter iter; - - if (gtk_tree_view_get_tooltip_context (GTK_TREE_VIEW (widget), - &x, &y, - keyboard_mode, - &model, - NULL, - &iter)) - { - gpointer col_data; - ShortcutType shortcut_type; - - gtk_tree_model_get (model, &iter, - SHORTCUTS_COL_DATA, &col_data, - SHORTCUTS_COL_TYPE, &shortcut_type, - -1); - - if (shortcut_type == SHORTCUT_TYPE_SEPARATOR) - return FALSE; - else if (shortcut_type == SHORTCUT_TYPE_VOLUME) - return FALSE; - else if (shortcut_type == SHORTCUT_TYPE_FILE) - { - GFile *file; - char *parse_name; - - file = G_FILE (col_data); - parse_name = g_file_get_parse_name (file); - - gtk_tooltip_set_text (tooltip, parse_name); - - g_free (parse_name); - - return TRUE; - } - else if (shortcut_type == SHORTCUT_TYPE_SEARCH) - { - return FALSE; - } - else if (shortcut_type == SHORTCUT_TYPE_RECENT) - { - return FALSE; - } - } - - return FALSE; -} - - -/* Callback used when the selection in the shortcuts tree changes */ -static void -shortcuts_selection_changed_cb (GtkTreeSelection *selection, - GtkFileChooserDefault *impl) -{ - GtkTreeIter iter; - GtkTreeIter child_iter; - - bookmarks_check_remove_sensitivity (impl); - shortcuts_check_popup_sensitivity (impl); - - if (impl->changing_folder) - return; - - if (gtk_tree_selection_get_selected(selection, NULL, &iter)) - { - gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (impl->shortcuts_pane_filter_model), - &child_iter, - &iter); - shortcuts_activate_iter (impl, &child_iter); - } -} - -static gboolean -shortcuts_row_separator_func (GtkTreeModel *model, - GtkTreeIter *iter, - gpointer data) -{ - ShortcutType shortcut_type; - - gtk_tree_model_get (model, iter, SHORTCUTS_COL_TYPE, &shortcut_type, -1); - - return shortcut_type == SHORTCUT_TYPE_SEPARATOR; -} - -static gboolean -shortcuts_key_press_event_after_cb (GtkWidget *tree_view, - GdkEventKey *event, - GtkFileChooserDefault *impl) -{ - GtkWidget *entry; - - /* don't screw up focus switching with Tab */ - if (event->keyval == GDK_KEY_Tab - || event->keyval == GDK_KEY_KP_Tab - || event->keyval == GDK_KEY_ISO_Left_Tab - || event->length < 1) - return FALSE; - - if (impl->location_entry) - entry = impl->location_entry; - else if (impl->search_entry) - entry = impl->search_entry; - else - entry = NULL; - - if (entry) - { - gtk_widget_grab_focus (entry); - return gtk_widget_event (entry, (GdkEvent *) event); - } - else - return FALSE; -} - -/* Callback used when the file list's popup menu is detached */ -static void -shortcuts_popup_menu_detach_cb (GtkWidget *attach_widget, - GtkMenu *menu) -{ - GtkFileChooserDefault *impl; - - impl = g_object_get_data (G_OBJECT (attach_widget), "GtkFileChooserDefault"); - g_assert (GTK_IS_FILE_CHOOSER_DEFAULT (impl)); - - impl->browse_shortcuts_popup_menu = NULL; - impl->browse_shortcuts_popup_menu_remove_item = NULL; - impl->browse_shortcuts_popup_menu_rename_item = NULL; -} - -static void -remove_shortcut_cb (GtkMenuItem *item, - GtkFileChooserDefault *impl) -{ - remove_selected_bookmarks (impl); -} - -/* Rename the selected bookmark */ -static void -rename_selected_bookmark (GtkFileChooserDefault *impl) -{ - GtkTreeIter iter; - GtkTreePath *path; - GtkTreeViewColumn *column; - GtkCellRenderer *cell; - GList *renderers; - - if (shortcuts_get_selected (impl, &iter)) - { - path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter); - column = gtk_tree_view_get_column (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), 0); - renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column)); - cell = g_list_nth_data (renderers, 1); - g_list_free (renderers); - g_object_set (cell, "editable", TRUE, NULL); - gtk_tree_view_set_cursor_on_cell (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), - path, column, cell, TRUE); - gtk_tree_path_free (path); - } -} - -static void -rename_shortcut_cb (GtkMenuItem *item, - GtkFileChooserDefault *impl) -{ - rename_selected_bookmark (impl); -} - -/* Constructs the popup menu for the file list if needed */ -static void -shortcuts_build_popup_menu (GtkFileChooserDefault *impl) -{ - GtkWidget *item; - - if (impl->browse_shortcuts_popup_menu) - return; - - impl->browse_shortcuts_popup_menu = gtk_menu_new (); - gtk_menu_attach_to_widget (GTK_MENU (impl->browse_shortcuts_popup_menu), - impl->browse_shortcuts_tree_view, - shortcuts_popup_menu_detach_cb); - - item = gtk_image_menu_item_new_with_label (_("Remove")); - impl->browse_shortcuts_popup_menu_remove_item = item; - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), - gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU)); - g_signal_connect (item, "activate", - G_CALLBACK (remove_shortcut_cb), impl); - gtk_widget_show (item); - gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_shortcuts_popup_menu), item); - - item = gtk_menu_item_new_with_label (_("Rename...")); - impl->browse_shortcuts_popup_menu_rename_item = item; - g_signal_connect (item, "activate", - G_CALLBACK (rename_shortcut_cb), impl); - gtk_widget_show (item); - gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_shortcuts_popup_menu), item); -} - -static void -shortcuts_update_popup_menu (GtkFileChooserDefault *impl) -{ - shortcuts_build_popup_menu (impl); - shortcuts_check_popup_sensitivity (impl); -} - -static void -popup_position_func (GtkMenu *menu, - gint *x, - gint *y, - gboolean *push_in, - gpointer user_data); - -static void -shortcuts_popup_menu (GtkFileChooserDefault *impl, - GdkEventButton *event) -{ - shortcuts_update_popup_menu (impl); - if (event) - gtk_menu_popup (GTK_MENU (impl->browse_shortcuts_popup_menu), - NULL, NULL, NULL, NULL, - event->button, event->time); - else - { - gtk_menu_popup (GTK_MENU (impl->browse_shortcuts_popup_menu), - NULL, NULL, - popup_position_func, impl->browse_shortcuts_tree_view, - 0, GDK_CURRENT_TIME); - gtk_menu_shell_select_first (GTK_MENU_SHELL (impl->browse_shortcuts_popup_menu), - FALSE); - } -} - -/* Callback used for the GtkWidget::popup-menu signal of the shortcuts list */ -static gboolean -shortcuts_popup_menu_cb (GtkWidget *widget, - GtkFileChooserDefault *impl) -{ - shortcuts_popup_menu (impl, NULL); - return TRUE; -} - -/* Callback used when a button is pressed on the shortcuts list. - * We trap button 3 to bring up a popup menu. - */ -static gboolean -shortcuts_button_press_event_cb (GtkWidget *widget, - GdkEventButton *event, - GtkFileChooserDefault *impl) -{ - static gboolean in_press = FALSE; - gboolean handled; - - if (in_press) - return FALSE; - - if (!gdk_event_triggers_context_menu ((GdkEvent *) event)) - return FALSE; - - in_press = TRUE; - handled = gtk_widget_event (impl->browse_shortcuts_tree_view, (GdkEvent *) event); - in_press = FALSE; + g_free (impl->edited_new_text); + impl->edited_new_text = NULL; + } - if (!handled) - return FALSE; + gdk_threads_leave (); - shortcuts_popup_menu (impl, event); - return TRUE; + return FALSE; } static void -shortcuts_edited (GtkCellRenderer *cell, - gchar *path_string, - gchar *new_text, - GtkFileChooserDefault *impl) +queue_edited_idle (GtkFileChooserDefault *impl, + const gchar *new_text) { - GtkTreePath *path; - GtkTreeIter iter; - GFile *shortcut; + /* We create the folder in an idle handler so that we don't modify the tree + * just now. + */ - g_object_set (cell, "editable", FALSE, NULL); + if (!impl->edited_idle) + impl->edited_idle = add_idle_while_impl_is_alive (impl, G_CALLBACK (edited_idle_cb)); - path = gtk_tree_path_new_from_string (path_string); - if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->shortcuts_model), &iter, path)) - g_assert_not_reached (); + g_free (impl->edited_new_text); + impl->edited_new_text = g_strdup (new_text); +} - gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, - SHORTCUTS_COL_DATA, &shortcut, - -1); - gtk_tree_path_free (path); - - _gtk_bookmarks_manager_set_bookmark_label (impl->bookmarks_manager, shortcut, new_text); +/* Callback used from the text cell renderer when the new folder is named */ +static void +renderer_edited_cb (GtkCellRendererText *cell_renderer_text, + const gchar *path, + const gchar *new_text, + GtkFileChooserDefault *impl) +{ + /* work around bug #154921 */ + g_object_set (cell_renderer_text, + "mode", GTK_CELL_RENDERER_MODE_INERT, NULL); + queue_edited_idle (impl, new_text); } +/* Callback used from the text cell renderer when the new folder edition gets + * canceled. + */ static void -shortcuts_editing_canceled (GtkCellRenderer *cell, - GtkFileChooserDefault *impl) +renderer_editing_canceled_cb (GtkCellRendererText *cell_renderer_text, + GtkFileChooserDefault *impl) { - g_object_set (cell, "editable", FALSE, NULL); + /* work around bug #154921 */ + g_object_set (cell_renderer_text, + "mode", GTK_CELL_RENDERER_MODE_INERT, NULL); + queue_edited_idle (impl, NULL); } -/* Creates the widgets for the shortcuts and bookmarks tree */ +/* Creates the widgets for the filter combo box */ static GtkWidget * -shortcuts_list_create (GtkFileChooserDefault *impl) +filter_create (GtkFileChooserDefault *impl) { - GtkWidget *swin; - GtkTreeSelection *selection; - GtkTreeViewColumn *column; - GtkCellRenderer *renderer; - - /* Target types for dragging a row to/from the shortcuts list */ - const GtkTargetEntry tree_model_row_targets[] = { - { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, GTK_TREE_MODEL_ROW } - }; - - /* Scrolled window */ + GtkCellRenderer *cell; + GList *cells; - swin = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin), - GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swin), - GTK_SHADOW_IN); - gtk_widget_show (swin); + impl->filter_combo = gtk_combo_box_text_new (); + gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (impl->filter_combo), FALSE); - /* Tree */ - impl->browse_shortcuts_tree_view = gtk_tree_view_new (); - gtk_style_context_add_class (gtk_widget_get_style_context (impl->browse_shortcuts_tree_view), - GTK_STYLE_CLASS_SIDEBAR); - gtk_tree_view_set_enable_search (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), FALSE); -#ifdef PROFILE_FILE_CHOOSER - g_object_set_data (G_OBJECT (impl->browse_shortcuts_tree_view), "fmq-name", "shortcuts"); -#endif + /* Get the combo's text renderer and set ellipsize parameters */ + cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (impl->filter_combo)); + g_assert (cells); + cell = cells->data; - /* Connect "after" to key-press-event on the shortcuts pane. We want this action to be possible: - * - * 1. user brings up a SAVE dialog - * 2. user clicks on a shortcut in the shortcuts pane - * 3. user starts typing a filename - * - * Normally, the user's typing would be ignored, as the shortcuts treeview doesn't - * support interactive search. However, we'd rather focus the location entry - * so that the user can type *there*. - * - * To preserve keyboard navigation in the shortcuts pane, we don't focus the - * filename entry if one clicks on a shortcut; rather, we focus the entry only - * if the user starts typing while the focus is in the shortcuts pane. - */ - g_signal_connect_after (impl->browse_shortcuts_tree_view, "key-press-event", - G_CALLBACK (shortcuts_key_press_event_after_cb), impl); + g_object_set (G_OBJECT (cell), + "ellipsize", PANGO_ELLIPSIZE_END, + NULL); - g_signal_connect (impl->browse_shortcuts_tree_view, "popup-menu", - G_CALLBACK (shortcuts_popup_menu_cb), impl); - g_signal_connect (impl->browse_shortcuts_tree_view, "button-press-event", - G_CALLBACK (shortcuts_button_press_event_cb), impl); - /* Accessible object name for the file chooser's shortcuts pane */ - atk_object_set_name (gtk_widget_get_accessible (impl->browse_shortcuts_tree_view), _("Places")); + g_list_free (cells); - gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), impl->shortcuts_pane_filter_model); + g_signal_connect (impl->filter_combo, "changed", + G_CALLBACK (filter_combo_changed), impl); - gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), - GDK_BUTTON1_MASK, - tree_model_row_targets, - G_N_ELEMENTS (tree_model_row_targets), - GDK_ACTION_MOVE); + gtk_widget_set_tooltip_text (impl->filter_combo, + _("Select which types of files are shown")); - gtk_drag_dest_set (impl->browse_shortcuts_tree_view, - GTK_DEST_DEFAULT_ALL, - tree_model_row_targets, - G_N_ELEMENTS (tree_model_row_targets), - GDK_ACTION_COPY | GDK_ACTION_MOVE); - gtk_drag_dest_add_uri_targets (impl->browse_shortcuts_tree_view); + return impl->filter_combo; +} - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view)); - gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); - gtk_tree_selection_set_select_function (selection, - shortcuts_select_func, - impl, NULL); +struct selection_check_closure { + GtkFileChooserDefault *impl; + int num_selected; + gboolean all_files; + gboolean all_folders; +}; - g_signal_connect (selection, "changed", - G_CALLBACK (shortcuts_selection_changed_cb), impl); +/* Used from gtk_tree_selection_selected_foreach() */ +static void +selection_check_foreach_cb (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + gpointer data) +{ + struct selection_check_closure *closure; + gboolean is_folder; + GFile *file; - g_signal_connect (impl->browse_shortcuts_tree_view, "key-press-event", - G_CALLBACK (shortcuts_key_press_event_cb), impl); + gtk_tree_model_get (model, iter, + MODEL_COL_FILE, &file, + MODEL_COL_IS_FOLDER, &is_folder, + -1); - g_signal_connect (impl->browse_shortcuts_tree_view, "drag-begin", - G_CALLBACK (shortcuts_drag_begin_cb), impl); - g_signal_connect (impl->browse_shortcuts_tree_view, "drag-end", - G_CALLBACK (shortcuts_drag_end_cb), impl); - g_signal_connect (impl->browse_shortcuts_tree_view, "drag-data-delete", - G_CALLBACK (shortcuts_drag_data_delete_cb), impl); + if (file == NULL) + return; - g_signal_connect (impl->browse_shortcuts_tree_view, "drag-leave", - G_CALLBACK (shortcuts_drag_leave_cb), impl); - g_signal_connect (impl->browse_shortcuts_tree_view, "drag-motion", - G_CALLBACK (shortcuts_drag_motion_cb), impl); - g_signal_connect (impl->browse_shortcuts_tree_view, "drag-drop", - G_CALLBACK (shortcuts_drag_drop_cb), impl); - g_signal_connect (impl->browse_shortcuts_tree_view, "drag-data-received", - G_CALLBACK (shortcuts_drag_data_received_cb), impl); + g_object_unref (file); - /* Support tooltips */ - gtk_widget_set_has_tooltip (impl->browse_shortcuts_tree_view, TRUE); - g_signal_connect (impl->browse_shortcuts_tree_view, "query-tooltip", - G_CALLBACK (shortcuts_query_tooltip_cb), impl); + closure = data; + closure->num_selected++; - gtk_container_add (GTK_CONTAINER (swin), impl->browse_shortcuts_tree_view); - gtk_widget_show (impl->browse_shortcuts_tree_view); + closure->all_folders = closure->all_folders && is_folder; + closure->all_files = closure->all_files && !is_folder; +} - /* Column */ +/* Checks whether the selected items in the file list are all files or all folders */ +static void +selection_check (GtkFileChooserDefault *impl, + gint *num_selected, + gboolean *all_files, + gboolean *all_folders) +{ + struct selection_check_closure closure; + GtkTreeSelection *selection; - column = gtk_tree_view_column_new (); - /* Column header for the file chooser's shortcuts pane */ - gtk_tree_view_column_set_title (column, _("_Places")); + closure.impl = impl; + closure.num_selected = 0; + closure.all_files = TRUE; + closure.all_folders = TRUE; - renderer = gtk_cell_renderer_pixbuf_new (); - gtk_tree_view_column_pack_start (column, renderer, FALSE); - gtk_tree_view_column_set_attributes (column, renderer, - "pixbuf", SHORTCUTS_COL_PIXBUF, - "visible", SHORTCUTS_COL_PIXBUF_VISIBLE, - NULL); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view)); + gtk_tree_selection_selected_foreach (selection, + selection_check_foreach_cb, + &closure); - renderer = gtk_cell_renderer_text_new (); - g_object_set (renderer, - "width-chars", 12, - "ellipsize", PANGO_ELLIPSIZE_END, - NULL); - g_signal_connect (renderer, "edited", - G_CALLBACK (shortcuts_edited), impl); - g_signal_connect (renderer, "editing-canceled", - G_CALLBACK (shortcuts_editing_canceled), impl); - gtk_tree_view_column_pack_start (column, renderer, TRUE); - gtk_tree_view_column_set_attributes (column, renderer, - "text", SHORTCUTS_COL_NAME, - NULL); + g_assert (closure.num_selected == 0 || !(closure.all_files && closure.all_folders)); - gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), - shortcuts_row_separator_func, - NULL, NULL); + if (num_selected) + *num_selected = closure.num_selected; - gtk_tree_view_append_column (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), column); + if (all_files) + *all_files = closure.all_files; - return swin; + if (all_folders) + *all_folders = closure.all_folders; } -/* Creates the widgets for the shortcuts/bookmarks pane */ -static GtkWidget * -shortcuts_pane_create (GtkFileChooserDefault *impl, - GtkSizeGroup *size_group) +#if REMOVE_FOR_PLACES_SIDEBAR +/* Parses a "text/uri-list" string and inserts its URIs as bookmarks */ +static void +shortcuts_drop_uris (GtkFileChooserDefault *impl, + GtkSelectionData *selection_data, + int position) { - GtkWidget *vbox; - GtkWidget *toolbar; - GtkWidget *widget; - GtkStyleContext *context; - GIcon *icon; - - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - gtk_widget_show (vbox); - - /* Shortcuts tree */ - - widget = shortcuts_list_create (impl); + gchar **uris; + gint i; - gtk_size_group_add_widget (size_group, widget); - context = gtk_widget_get_style_context (widget); - gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM); + uris = gtk_selection_data_get_uris (selection_data); + if (!uris) + return; - gtk_box_pack_start (GTK_BOX (vbox), widget, TRUE, TRUE, 0); + for (i = 0; uris[i]; i++) + { + char *uri; + GFile *file; - /* Box for buttons */ + uri = uris[i]; + file = g_file_new_for_uri (uri); - toolbar = gtk_toolbar_new (); - gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS); - gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_MENU); + if (shortcuts_add_bookmark_from_file (impl, file, position)) + position++; - context = gtk_widget_get_style_context (toolbar); - gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP); - gtk_style_context_add_class (context, GTK_STYLE_CLASS_INLINE_TOOLBAR); - - gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0); - gtk_widget_show (toolbar); - - /* Add bookmark button */ - icon = g_themed_icon_new_with_default_fallbacks ("list-add-symbolic"); - impl->browse_shortcuts_add_button = toolbutton_new (impl, - icon, - FALSE, - TRUE, - G_CALLBACK (add_bookmark_button_clicked_cb)); - g_object_unref (icon); - - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (impl->browse_shortcuts_add_button), 0); - gtk_widget_set_tooltip_text (impl->browse_shortcuts_add_button, - _("Add the selected folder to the Bookmarks")); - - /* Remove bookmark button */ - icon = g_themed_icon_new_with_default_fallbacks ("list-remove-symbolic"); - impl->browse_shortcuts_remove_button = toolbutton_new (impl, - icon, - FALSE, - TRUE, - G_CALLBACK (remove_bookmark_button_clicked_cb)); - g_object_unref (icon); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (impl->browse_shortcuts_remove_button), 1); - gtk_widget_set_tooltip_text (impl->browse_shortcuts_remove_button, - _("Remove the selected bookmark")); + g_object_unref (file); + } - return vbox; + g_strfreev (uris); } #endif @@ -3837,9 +1407,7 @@ browse_files_key_press_event_cb (GtkWidget *widget, if (key_is_left_or_right (event)) { -#if REMOVE_FOR_PLACES_SIDEBAR - gtk_widget_grab_focus (impl->browse_shortcuts_tree_view); -#endif + gtk_widget_grab_focus (impl->places_sidebar); return TRUE; } @@ -4285,9 +1853,6 @@ file_list_build_popup_menu (GtkFileChooserDefault *impl) impl->browse_files_popup_menu_size_column_item = file_list_add_check_menu_item (impl, _("Show _Size Column"), G_CALLBACK (show_size_column_toggled_cb)); -#if REMOVE_FOR_PLACES_SIDEBAR - bookmarks_check_add_sensitivity (impl); -#endif check_copy_file_location_sensitivity (impl); } @@ -5184,11 +2749,6 @@ gtk_file_chooser_default_constructor (GType type, gtk_widget_push_composite_child (); -#if REMOVE_FOR_PLACES_SIDEBAR - /* Shortcuts model */ - shortcuts_model_create (impl); -#endif - /* The browse widgets */ browse_widgets_create (impl); @@ -5245,14 +2805,6 @@ set_local_only (GtkFileChooserDefault *impl, if (impl->location_entry) _gtk_file_chooser_entry_set_local_only (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), local_only); - if (impl->shortcuts_model && impl->file_system) - { -#if REMOVE_FOR_PLACES_SIDEBAR - shortcuts_add_volumes (impl); - shortcuts_add_bookmarks (impl); -#endif - } - if (local_only && impl->current_folder && !g_file_is_native (impl->current_folder)) { @@ -5275,20 +2827,6 @@ set_local_only (GtkFileChooserDefault *impl, } } -static void -volumes_bookmarks_changed_cb (GtkFileSystem *file_system, - GtkFileChooserDefault *impl) -{ -#if REMOVE_FOR_PLACES_SIDEBAR - shortcuts_add_volumes (impl); - shortcuts_add_bookmarks (impl); - - bookmarks_check_add_sensitivity (impl); - bookmarks_check_remove_sensitivity (impl); - shortcuts_check_popup_sensitivity (impl); -#endif -} - /* Sets the file chooser to multiple selection mode */ static void set_select_multiple (GtkFileChooserDefault *impl, @@ -5321,18 +2859,12 @@ set_file_system_backend (GtkFileChooserDefault *impl) impl->file_system = _gtk_file_system_new (); - g_signal_connect (impl->file_system, "volumes-changed", - G_CALLBACK (volumes_bookmarks_changed_cb), impl); - profile_end ("end", NULL); } static void unset_file_system_backend (GtkFileChooserDefault *impl) { - g_signal_handlers_disconnect_by_func (impl->file_system, - G_CALLBACK (volumes_bookmarks_changed_cb), impl); - g_object_unref (impl->file_system); impl->file_system = NULL; @@ -5527,11 +3059,11 @@ operation_mode_set_recent (GtkFileChooserDefault *impl) recent_start_loading (impl); } +#if REMOVE_FOR_PLACES_SIDEBAR /* Sometimes we need to frob the selection in the shortcuts list manually */ static void shortcuts_select_item_without_activating (GtkFileChooserDefault *impl, int pos) { -#if REMOVE_FOR_PLACES_SIDEBAR GtkTreeSelection *selection; GtkTreePath *path; @@ -5544,8 +3076,8 @@ shortcuts_select_item_without_activating (GtkFileChooserDefault *impl, int pos) gtk_tree_path_free (path); g_signal_handlers_unblock_by_func (selection, G_CALLBACK (shortcuts_selection_changed_cb), impl); -#endif } +#endif static void operation_mode_set (GtkFileChooserDefault *impl, OperationMode mode) @@ -6002,9 +3534,6 @@ change_icon_theme (GtkFileChooserDefault *impl) else impl->icon_size = FALLBACK_ICON_SIZE; -#if REMOVE_FOR_PLACES_SIDEBAR - shortcuts_reload_icons (impl); -#endif /* the first cell in the first column is the icon column, and we have a fixed size there */ cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT ( gtk_tree_view_get_column (GTK_TREE_VIEW (impl->browse_files_tree_view), 0))); @@ -6333,8 +3862,6 @@ gtk_file_chooser_default_map (GtkWidget *widget) } } - volumes_bookmarks_changed_cb (impl->file_system, impl); - profile_end ("end", NULL); } @@ -7485,19 +5012,6 @@ update_current_folder_get_info_cb (GCancellable *cancellable, impl->reload_state = RELOAD_HAS_FOLDER; - /* Update the widgets that may trigger a folder change themselves. */ - - if (!impl->changing_folder) - { - impl->changing_folder = TRUE; - -#if REMOVE_FOR_PLACES_SIDEBAR - shortcuts_update_current_folder (impl); -#endif - - impl->changing_folder = FALSE; - } - /* Set the folder on the save entry */ if (impl->location_entry) @@ -7522,9 +5036,6 @@ update_current_folder_get_info_cb (GCancellable *cancellable, g_signal_emit_by_name (impl, "current-folder-changed", 0); check_preview_change (impl); -#if REMOVE_FOR_PLACES_SIDEBAR - bookmarks_check_add_sensitivity (impl); -#endif g_signal_emit_by_name (impl, "selection-changed", 0); @@ -8097,62 +5608,16 @@ gtk_file_chooser_default_remove_filter (GtkFileChooser *chooser, g_object_unref (filter); if (!impl->filters) - show_filters (impl, FALSE); -} - -static GSList * -gtk_file_chooser_default_list_filters (GtkFileChooser *chooser) -{ - GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser); - - return g_slist_copy (impl->filters); -} - -#if REMOVE_FOR_PLACES_SIDEBAR -/* Returns the position in the shortcuts tree where the nth specified shortcut would appear */ -static int -shortcuts_get_pos_for_shortcut_folder (GtkFileChooserDefault *impl, - int pos) -{ - return pos + shortcuts_get_index (impl, SHORTCUTS_SHORTCUTS); -} - -struct AddShortcutData -{ - GtkFileChooserDefault *impl; - GFile *file; -}; - -static void -add_shortcut_get_info_cb (GCancellable *cancellable, - GFileInfo *info, - const GError *error, - gpointer user_data) -{ - int pos; - gboolean cancelled = g_cancellable_is_cancelled (cancellable); - struct AddShortcutData *data = user_data; - - if (!g_slist_find (data->impl->loading_shortcuts, cancellable)) - goto out; - - data->impl->loading_shortcuts = g_slist_remove (data->impl->loading_shortcuts, cancellable); - - if (cancelled || error || (! _gtk_file_info_consider_as_directory (info))) - goto out; - - pos = shortcuts_get_pos_for_shortcut_folder (data->impl, data->impl->num_shortcuts); - - shortcuts_insert_file (data->impl, pos, SHORTCUT_TYPE_FILE, NULL, data->file, NULL, FALSE, SHORTCUTS_SHORTCUTS); - -out: - g_object_unref (data->impl); - g_object_unref (data->file); - g_free (data); + show_filters (impl, FALSE); +} - g_object_unref (cancellable); +static GSList * +gtk_file_chooser_default_list_filters (GtkFileChooser *chooser) +{ + GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser); + + return g_slist_copy (impl->filters); } -#endif static gboolean gtk_file_chooser_default_add_shortcut_folder (GtkFileChooser *chooser, @@ -9958,306 +7423,6 @@ check_preview_change (GtkFileChooserDefault *impl) } } -#if REMOVE_FOR_PLACES_SIDEBAR -static void -shortcuts_activate_volume_mount_cb (GCancellable *cancellable, - GtkFileSystemVolume *volume, - const GError *error, - gpointer data) -{ - GFile *file; - gboolean cancelled = g_cancellable_is_cancelled (cancellable); - GtkFileChooserDefault *impl = data; - - if (cancellable != impl->shortcuts_activate_iter_cancellable) - goto out; - - impl->shortcuts_activate_iter_cancellable = NULL; - - set_busy_cursor (impl, FALSE); - - if (cancelled) - goto out; - - if (error) - { - if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED)) - { - char *msg, *name; - - name = _gtk_file_system_volume_get_display_name (volume); - msg = g_strdup_printf (_("Could not mount %s"), name); - - error_message (impl, msg, error->message); - - g_free (msg); - g_free (name); - } - - goto out; - } - - file = _gtk_file_system_volume_get_root (volume); - if (file != NULL) - { - change_folder_and_display_error (impl, file, FALSE); - g_object_unref (file); - } - -out: - g_object_unref (impl); - g_object_unref (cancellable); -} - - -/* Activates a volume by mounting it if necessary and then switching to its - * base path. - */ -static void -shortcuts_activate_volume (GtkFileChooserDefault *impl, - GtkFileSystemVolume *volume) -{ - GFile *file; - - operation_mode_set (impl, OPERATION_MODE_BROWSE); - - /* We ref the file chooser since volume_mount() may run a main loop, and the - * user could close the file chooser window in the meantime. - */ - g_object_ref (impl); - - if (!_gtk_file_system_volume_is_mounted (volume)) - { - GMountOperation *mount_op; - - set_busy_cursor (impl, TRUE); - - mount_op = gtk_mount_operation_new (get_toplevel (GTK_WIDGET (impl))); - impl->shortcuts_activate_iter_cancellable = - _gtk_file_system_mount_volume (impl->file_system, volume, mount_op, - shortcuts_activate_volume_mount_cb, - g_object_ref (impl)); - g_object_unref (mount_op); - } - else - { - file = _gtk_file_system_volume_get_root (volume); - if (file != NULL) - { - change_folder_and_display_error (impl, file, FALSE); - g_object_unref (file); - } - } - - g_object_unref (impl); -} - -/* Opens the folder or volume at the specified iter in the shortcuts model */ -struct ShortcutsActivateData -{ - GtkFileChooserDefault *impl; - GFile *file; -}; - -static void -shortcuts_activate_get_info_cb (GCancellable *cancellable, - GFileInfo *info, - const GError *error, - gpointer user_data) -{ - gboolean cancelled = g_cancellable_is_cancelled (cancellable); - struct ShortcutsActivateData *data = user_data; - - if (cancellable != data->impl->shortcuts_activate_iter_cancellable) - goto out; - - data->impl->shortcuts_activate_iter_cancellable = NULL; - - if (cancelled) - goto out; - - if (!error && _gtk_file_info_consider_as_directory (info)) - change_folder_and_display_error (data->impl, data->file, FALSE); - else - gtk_file_chooser_default_select_file (GTK_FILE_CHOOSER (data->impl), - data->file, - NULL); - -out: - g_object_unref (data->impl); - g_object_unref (data->file); - g_free (data); - - g_object_unref (cancellable); -} - -static void -shortcuts_activate_mount_enclosing_volume (GCancellable *cancellable, - GtkFileSystemVolume *volume, - const GError *error, - gpointer user_data) -{ - struct ShortcutsActivateData *data = user_data; - - if (error) - { - error_changing_folder_dialog (data->impl, data->file, g_error_copy (error)); - - g_object_unref (data->impl); - g_object_unref (data->file); - g_free (data); - - return; - } - - data->impl->shortcuts_activate_iter_cancellable = - _gtk_file_system_get_info (data->impl->file_system, data->file, - "standard::type", - shortcuts_activate_get_info_cb, data); - - if (volume) - _gtk_file_system_volume_unref (volume); -} - -static void -shortcuts_activate_iter (GtkFileChooserDefault *impl, - GtkTreeIter *iter) -{ - gpointer col_data; - ShortcutType shortcut_type; - - /* In the Save modes, we want to preserve what the uesr typed in the filename - * entry, so that he may choose another folder without erasing his typed name. - */ - if (impl->location_entry - && !(impl->action == GTK_FILE_CHOOSER_ACTION_SAVE - || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)) - gtk_entry_set_text (GTK_ENTRY (impl->location_entry), ""); - - gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), iter, - SHORTCUTS_COL_DATA, &col_data, - SHORTCUTS_COL_TYPE, &shortcut_type, - -1); - - if (impl->shortcuts_activate_iter_cancellable) - { - g_cancellable_cancel (impl->shortcuts_activate_iter_cancellable); - impl->shortcuts_activate_iter_cancellable = NULL; - } - - if (shortcut_type == SHORTCUT_TYPE_SEPARATOR) - return; - else if (shortcut_type == SHORTCUT_TYPE_VOLUME) - { - GtkFileSystemVolume *volume; - - volume = col_data; - - operation_mode_set (impl, OPERATION_MODE_BROWSE); - - shortcuts_activate_volume (impl, volume); - } - else if (shortcut_type == SHORTCUT_TYPE_FILE) - { - struct ShortcutsActivateData *data; - GtkFileSystemVolume *volume; - - operation_mode_set (impl, OPERATION_MODE_BROWSE); - - volume = _gtk_file_system_get_volume_for_file (impl->file_system, col_data); - - data = g_new0 (struct ShortcutsActivateData, 1); - data->impl = g_object_ref (impl); - data->file = g_object_ref (col_data); - - if (!volume || !_gtk_file_system_volume_is_mounted (volume)) - { - GMountOperation *mount_operation; - GtkWidget *toplevel; - - toplevel = gtk_widget_get_toplevel (GTK_WIDGET (impl)); - - mount_operation = gtk_mount_operation_new (GTK_WINDOW (toplevel)); - - impl->shortcuts_activate_iter_cancellable = - _gtk_file_system_mount_enclosing_volume (impl->file_system, col_data, - mount_operation, - shortcuts_activate_mount_enclosing_volume, - data); - } - else - { - impl->shortcuts_activate_iter_cancellable = - _gtk_file_system_get_info (impl->file_system, data->file, - "standard::type", - shortcuts_activate_get_info_cb, data); - } - } - else if (shortcut_type == SHORTCUT_TYPE_SEARCH) - { - operation_mode_set (impl, OPERATION_MODE_SEARCH); - } - else if (shortcut_type == SHORTCUT_TYPE_RECENT) - { - operation_mode_set (impl, OPERATION_MODE_RECENT); - } -} - -/* Handler for GtkWidget::key-press-event on the shortcuts list */ -static gboolean -shortcuts_key_press_event_cb (GtkWidget *widget, - GdkEventKey *event, - GtkFileChooserDefault *impl) -{ - guint modifiers; - - modifiers = gtk_accelerator_get_default_mod_mask (); - - if (key_is_left_or_right (event)) - { - gtk_widget_grab_focus (impl->browse_files_tree_view); - return TRUE; - } - - if ((event->keyval == GDK_KEY_BackSpace - || event->keyval == GDK_KEY_Delete - || event->keyval == GDK_KEY_KP_Delete) - && (event->state & modifiers) == 0) - { - remove_selected_bookmarks (impl); - return TRUE; - } - - if ((event->keyval == GDK_KEY_F2) - && (event->state & modifiers) == 0) - { - rename_selected_bookmark (impl); - return TRUE; - } - - return FALSE; -} - -static gboolean -shortcuts_select_func (GtkTreeSelection *selection, - GtkTreeModel *model, - GtkTreePath *path, - gboolean path_currently_selected, - gpointer data) -{ - GtkFileChooserDefault *impl = data; - GtkTreeIter filter_iter; - ShortcutType shortcut_type; - - if (!gtk_tree_model_get_iter (impl->shortcuts_pane_filter_model, &filter_iter, path)) - g_assert_not_reached (); - - gtk_tree_model_get (impl->shortcuts_pane_filter_model, &filter_iter, SHORTCUTS_COL_TYPE, &shortcut_type, -1); - - return shortcut_type != SHORTCUT_TYPE_SEPARATOR; -} -#endif - static gboolean list_select_func (GtkTreeSelection *selection, GtkTreeModel *model, @@ -10314,9 +7479,6 @@ list_selection_changed (GtkTreeSelection *selection, path_bar_update (impl); check_preview_change (impl); -#if REMOVE_FOR_PLACES_SIDEBAR - bookmarks_check_add_sensitivity (impl); -#endif check_copy_file_location_sensitivity (impl); g_signal_emit_by_name (impl, "selection-changed", 0); @@ -10508,21 +7670,6 @@ down_folder_handler (GtkFileChooserDefault *impl) _gtk_path_bar_down (GTK_PATH_BAR (impl->browse_path_bar)); } -/* Switches to the shortcut in the specified index */ -static void -switch_to_shortcut (GtkFileChooserDefault *impl, - int pos) -{ -#if REMOVE_FOR_PLACES_SIDEBAR - GtkTreeIter iter; - - if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos)) - g_assert_not_reached (); - - shortcuts_activate_iter (impl, &iter); -#endif -} - /* Handler for the "home-folder" keybinding signal */ static void home_folder_handler (GtkFileChooserDefault *impl) @@ -10576,25 +7723,24 @@ static void quick_bookmark_handler (GtkFileChooserDefault *impl, gint bookmark_index) { +#if REMOVE_FOR_PLACES_SIDEBAR int bookmark_pos; GtkTreePath *path; if (bookmark_index < 0 || bookmark_index >= impl->num_bookmarks) return; -#if REMOVE_FOR_PLACES_SIDEBAR bookmark_pos = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS) + bookmark_index; -#endif path = gtk_tree_path_new_from_indices (bookmark_pos, -1); -#if REMOVE_FOR_PLACES_SIDEBAR + gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), path, NULL, FALSE, 0.0, 0.0); -#endif gtk_tree_path_free (path); switch_to_shortcut (impl, bookmark_pos); +#endif } static void @@ -10604,85 +7750,3 @@ show_hidden_handler (GtkFileChooserDefault *impl) "show-hidden", !impl->show_hidden, NULL); } - - -#if REMOVE_FOR_PLACES_SIDEBAR -/* Drag and drop interfaces */ - -static void -_shortcuts_pane_model_filter_class_init (ShortcutsPaneModelFilterClass *class) -{ -} - -static void -_shortcuts_pane_model_filter_init (ShortcutsPaneModelFilter *model) -{ - model->impl = NULL; -} - -/* GtkTreeDragSource::row_draggable implementation for the shortcuts filter model */ -static gboolean -shortcuts_pane_model_filter_row_draggable (GtkTreeDragSource *drag_source, - GtkTreePath *path) -{ - ShortcutsPaneModelFilter *model; - int pos; - int bookmarks_pos; - - model = SHORTCUTS_PANE_MODEL_FILTER (drag_source); - - pos = *gtk_tree_path_get_indices (path); - bookmarks_pos = shortcuts_get_index (model->impl, SHORTCUTS_BOOKMARKS); - - return (pos >= bookmarks_pos && pos < bookmarks_pos + model->impl->num_bookmarks); -} - -/* GtkTreeDragSource::drag_data_get implementation for the shortcuts - * filter model - */ -static gboolean -shortcuts_pane_model_filter_drag_data_get (GtkTreeDragSource *drag_source, - GtkTreePath *path, - GtkSelectionData *selection_data) -{ - /* FIXME */ - - return FALSE; -} - -/* Fill the GtkTreeDragSourceIface vtable */ -static void -shortcuts_pane_model_filter_drag_source_iface_init (GtkTreeDragSourceIface *iface) -{ - iface->row_draggable = shortcuts_pane_model_filter_row_draggable; - iface->drag_data_get = shortcuts_pane_model_filter_drag_data_get; -} - -#if 0 -/* Fill the GtkTreeDragDestIface vtable */ -static void -shortcuts_pane_model_filter_drag_dest_iface_init (GtkTreeDragDestIface *iface) -{ - iface->drag_data_received = shortcuts_pane_model_filter_drag_data_received; - iface->row_drop_possible = shortcuts_pane_model_filter_row_drop_possible; -} -#endif - -static GtkTreeModel * -shortcuts_pane_model_filter_new (GtkFileChooserDefault *impl, - GtkTreeModel *child_model, - GtkTreePath *root) -{ - ShortcutsPaneModelFilter *model; - - model = g_object_new (SHORTCUTS_PANE_MODEL_FILTER_TYPE, - "child-model", child_model, - "virtual-root", root, - NULL); - - model->impl = impl; - - return GTK_TREE_MODEL (model); -} - -#endif -- cgit v1.2.1 From 976672ad4bff61748af259dfec2eef3aad0ce362 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Mon, 10 Dec 2012 13:48:42 -0600 Subject: Implement the application-side shortcuts in GtkFileChooserDefault Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 174 +------------------------------------------- 1 file changed, 3 insertions(+), 171 deletions(-) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 7b686f8a72..018070960d 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -5624,71 +5624,9 @@ gtk_file_chooser_default_add_shortcut_folder (GtkFileChooser *chooser, GFile *file, GError **error) { -#if REMOVE_FOR_PLACES_SIDEBAR - GCancellable *cancellable; GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser); - struct AddShortcutData *data; - GSList *l; - int pos; - - /* Avoid adding duplicates */ - pos = shortcut_find_position (impl, file); - if (pos >= 0 && pos < shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR)) - { - gchar *uri; - - uri = g_file_get_uri (file); - /* translators, "Shortcut" means "Bookmark" here */ - g_set_error (error, - GTK_FILE_CHOOSER_ERROR, - GTK_FILE_CHOOSER_ERROR_ALREADY_EXISTS, - _("Shortcut %s already exists"), - uri); - g_free (uri); - - return FALSE; - } - - for (l = impl->loading_shortcuts; l; l = l->next) - { - GCancellable *c = l->data; - GFile *f; - - f = g_object_get_data (G_OBJECT (c), "add-shortcut-path-key"); - if (f && g_file_equal (file, f)) - { - gchar *uri; - - uri = g_file_get_uri (file); - g_set_error (error, - GTK_FILE_CHOOSER_ERROR, - GTK_FILE_CHOOSER_ERROR_ALREADY_EXISTS, - _("Shortcut %s already exists"), - uri); - g_free (uri); - - return FALSE; - } - } - - data = g_new0 (struct AddShortcutData, 1); - data->impl = g_object_ref (impl); - data->file = g_object_ref (file); - cancellable = _gtk_file_system_get_info (impl->file_system, file, - "standard::type", - add_shortcut_get_info_cb, data); - - if (!cancellable) - return FALSE; - - impl->loading_shortcuts = g_slist_append (impl->loading_shortcuts, cancellable); - g_object_set_data (G_OBJECT (cancellable), "add-shortcut-path-key", data->file); - - return TRUE; -#else - return FALSE; -#endif + return gtk_places_sidebar_add_shortcut (GTK_PLACES_SIDEBAR (impl->places_sidebar), file, error); } static gboolean @@ -5696,123 +5634,17 @@ gtk_file_chooser_default_remove_shortcut_folder (GtkFileChooser *chooser, GFile *file, GError **error) { -#if REMOVE_FOR_PLACES_SIDEBAR GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser); - int pos; - GtkTreeIter iter; - GSList *l; - char *uri; - int i; - - for (l = impl->loading_shortcuts; l; l = l->next) - { - GCancellable *c = l->data; - GFile *f; - - f = g_object_get_data (G_OBJECT (c), "add-shortcut-path-key"); - if (f && g_file_equal (file, f)) - { - impl->loading_shortcuts = g_slist_remove (impl->loading_shortcuts, c); - g_cancellable_cancel (c); - return TRUE; - } - } - - if (impl->num_shortcuts == 0) - goto out; - - pos = shortcuts_get_pos_for_shortcut_folder (impl, 0); - if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos)) - g_assert_not_reached (); - - for (i = 0; i < impl->num_shortcuts; i++) - { - gpointer col_data; - ShortcutType shortcut_type; - GFile *shortcut; - - gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, - SHORTCUTS_COL_DATA, &col_data, - SHORTCUTS_COL_TYPE, &shortcut_type, - -1); - g_assert (col_data != NULL); - g_assert (shortcut_type == SHORTCUT_TYPE_FILE); - - shortcut = col_data; - if (g_file_equal (shortcut, file)) - { - shortcuts_remove_rows (impl, pos + i, 1); - impl->num_shortcuts--; - return TRUE; - } - - if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter)) - g_assert_not_reached (); - } - - out: - - uri = g_file_get_uri (file); - /* translators, "Shortcut" means "Bookmark" here */ - g_set_error (error, - GTK_FILE_CHOOSER_ERROR, - GTK_FILE_CHOOSER_ERROR_NONEXISTENT, - _("Shortcut %s does not exist"), - uri); - g_free (uri); - return FALSE; -#else - return FALSE; -#endif + return gtk_places_sidebar_remove_shortcut (GTK_PLACES_SIDEBAR (impl->places_sidebar), file, error); } static GSList * gtk_file_chooser_default_list_shortcut_folders (GtkFileChooser *chooser) { -#if REMOVE_FOR_PLACES_SIDEBAR GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser); - int pos; - GtkTreeIter iter; - int i; - GSList *list; - - if (impl->num_shortcuts == 0) - return NULL; - - pos = shortcuts_get_pos_for_shortcut_folder (impl, 0); - if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos)) - g_assert_not_reached (); - - list = NULL; - - for (i = 0; i < impl->num_shortcuts; i++) - { - gpointer col_data; - ShortcutType shortcut_type; - GFile *shortcut; - - gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, - SHORTCUTS_COL_DATA, &col_data, - SHORTCUTS_COL_TYPE, &shortcut_type, - -1); - g_assert (col_data != NULL); - g_assert (shortcut_type == SHORTCUT_TYPE_FILE); - - shortcut = col_data; - list = g_slist_prepend (list, g_object_ref (shortcut)); - - if (i != impl->num_shortcuts - 1) - { - if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter)) - g_assert_not_reached (); - } - } - return g_slist_reverse (list); -#else - return NULL; -#endif + return gtk_places_sidebar_list_shortcuts (GTK_PLACES_SIDEBAR (impl->places_sidebar)); } /* Guesses a size based upon font sizes */ -- cgit v1.2.1 From 0dca40e8512343203581916efa8947ae9ff14db6 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Mon, 10 Dec 2012 14:09:40 -0600 Subject: Remove an obsolete function --- gtk/gtkfilechooserdefault.c | 32 -------------------------------- 1 file changed, 32 deletions(-) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 018070960d..af6e53cdf5 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -1278,38 +1278,6 @@ selection_check (GtkFileChooserDefault *impl, *all_folders = closure.all_folders; } -#if REMOVE_FOR_PLACES_SIDEBAR -/* Parses a "text/uri-list" string and inserts its URIs as bookmarks */ -static void -shortcuts_drop_uris (GtkFileChooserDefault *impl, - GtkSelectionData *selection_data, - int position) -{ - gchar **uris; - gint i; - - uris = gtk_selection_data_get_uris (selection_data); - if (!uris) - return; - - for (i = 0; uris[i]; i++) - { - char *uri; - GFile *file; - - uri = uris[i]; - file = g_file_new_for_uri (uri); - - if (shortcuts_add_bookmark_from_file (impl, file, position)) - position++; - - g_object_unref (file); - } - - g_strfreev (uris); -} -#endif - static void places_sidebar_location_selected_cb (GtkPlacesSidebar *sidebar, GFile *location, GtkPlacesOpenMode open_mode, GtkFileChooserDefault *impl) { -- cgit v1.2.1 From f3beff7556a256743f2d8a980f6d7d2b1cbca64e Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Mon, 10 Dec 2012 14:18:00 -0600 Subject: Implement the 'Add to bookmarks' command as before Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index af6e53cdf5..7f3e745646 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -1427,14 +1427,41 @@ popup_menu_detach_cb (GtkWidget *attach_widget, impl->browse_files_popup_menu_copy_file_location_item = NULL; } +/* Callback used from gtk_tree_selection_selected_foreach(); adds a bookmark for + * each selected item in the file list. + */ +static void +add_bookmark_foreach_cb (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + gpointer data) +{ + GtkFileChooserDefault *impl; + GFile *file; + + impl = (GtkFileChooserDefault *) data; + + gtk_tree_model_get (model, iter, + MODEL_COL_FILE, &file, + -1); + + _gtk_bookmarks_manager_insert_bookmark (impl->bookmarks_manager, file, 0, NULL); /* NULL-GError */ + + g_object_unref (file); +} + /* Callback used when the "Add to Bookmarks" menu item is activated */ static void add_to_shortcuts_cb (GtkMenuItem *item, GtkFileChooserDefault *impl) { -#if REMOVE_FOR_PLACES_SIDEBAR - bookmarks_add_selected_folder (impl); -#endif + GtkTreeSelection *selection; + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view)); + + gtk_tree_selection_selected_foreach (selection, + add_bookmark_foreach_cb, + impl); } /* callback used to set data to clipboard */ -- cgit v1.2.1 From e6ba6e7e06360ab2b02c54950c269d32ad5c6c3a Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Mon, 10 Dec 2012 14:23:06 -0600 Subject: Implement the Home keyboard shortcut Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 7f3e745646..da6a5f0706 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -2789,6 +2789,22 @@ set_extra_widget (GtkFileChooserDefault *impl, gtk_widget_hide (impl->extra_align); } +static void +switch_to_home_dir (GtkFileChooserDefault *impl) +{ + const gchar *home = g_get_home_dir (); + GFile *home_file; + + if (home == NULL) + return; + + home_file = g_file_new_for_path (home); + + gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (impl), home_file, NULL); /* NULL-GError */ + + g_object_unref (home_file); +} + static void set_local_only (GtkFileChooserDefault *impl, gboolean local_only) @@ -2807,17 +2823,7 @@ set_local_only (GtkFileChooserDefault *impl, * back to a local folder, but it's really up to the app to not cause * such a situation, so we ignore errors. */ - const gchar *home = g_get_home_dir (); - GFile *home_file; - - if (home == NULL) - return; - - home_file = g_file_new_for_path (home); - - gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (impl), home_file, NULL); - - g_object_unref (home_file); + switch_to_home_dir (impl); } } } @@ -7501,10 +7507,7 @@ down_folder_handler (GtkFileChooserDefault *impl) static void home_folder_handler (GtkFileChooserDefault *impl) { -#if REMOVE_FOR_PLACES_SIDEBAR - if (impl->has_home) - switch_to_shortcut (impl, shortcuts_get_index (impl, SHORTCUTS_HOME)); -#endif + switch_to_home_dir (impl); } /* Handler for the "desktop-folder" keybinding signal */ -- cgit v1.2.1 From 8b0aea9f3d5e85b683a908695d04fe13e1d16e7e Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Mon, 10 Dec 2012 14:45:18 -0600 Subject: Implement the Desktop keyboard shortcut Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index da6a5f0706..cd86086e2d 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -7514,10 +7514,17 @@ home_folder_handler (GtkFileChooserDefault *impl) static void desktop_folder_handler (GtkFileChooserDefault *impl) { -#if REMOVE_FOR_PLACES_SIDEBAR - if (impl->has_desktop) - switch_to_shortcut (impl, shortcuts_get_index (impl, SHORTCUTS_DESKTOP)); -#endif + const char *name; + + name = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP); + /* "To disable a directory, point it to the homedir." + * See http://freedesktop.org/wiki/Software/xdg-user-dirs + **/ + if (!g_strcmp0 (name, g_get_home_dir ())) { + return; + } + + gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl), name); } /* Handler for the "search-shortcut" keybinding signal */ -- cgit v1.2.1 From c26293eacdd936582fc2fc617b8f00df4aa12a0b Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Mon, 10 Dec 2012 16:00:42 -0600 Subject: Implement the Alt-number quick bookmark shortcuts Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index cd86086e2d..f0986d1f43 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -7560,24 +7560,15 @@ static void quick_bookmark_handler (GtkFileChooserDefault *impl, gint bookmark_index) { -#if REMOVE_FOR_PLACES_SIDEBAR - int bookmark_pos; - GtkTreePath *path; - - if (bookmark_index < 0 || bookmark_index >= impl->num_bookmarks) - return; - - bookmark_pos = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS) + bookmark_index; + GFile *file; - path = gtk_tree_path_new_from_indices (bookmark_pos, -1); + file = gtk_places_sidebar_get_nth_bookmark (GTK_PLACES_SIDEBAR (impl->places_sidebar), bookmark_index); - gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), - path, NULL, - FALSE, 0.0, 0.0); - gtk_tree_path_free (path); - - switch_to_shortcut (impl, bookmark_pos); -#endif + if (file) + { + change_folder_and_display_error (impl, file, FALSE); + g_object_unref (file); + } } static void -- cgit v1.2.1 From 016dd28a9fea01cc494e601be37adfc59f8658e7 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Mon, 10 Dec 2012 16:05:18 -0600 Subject: Remove an obsolete function --- gtk/gtkfilechooserdefault.c | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index f0986d1f43..2be1764337 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -3060,26 +3060,6 @@ operation_mode_set_recent (GtkFileChooserDefault *impl) recent_start_loading (impl); } -#if REMOVE_FOR_PLACES_SIDEBAR -/* Sometimes we need to frob the selection in the shortcuts list manually */ -static void -shortcuts_select_item_without_activating (GtkFileChooserDefault *impl, int pos) -{ - GtkTreeSelection *selection; - GtkTreePath *path; - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view)); - - g_signal_handlers_block_by_func (selection, G_CALLBACK (shortcuts_selection_changed_cb), impl); - - path = gtk_tree_path_new_from_indices (pos, -1); - gtk_tree_selection_select_path (selection, path); - gtk_tree_path_free (path); - - g_signal_handlers_unblock_by_func (selection, G_CALLBACK (shortcuts_selection_changed_cb), impl); -} -#endif - static void operation_mode_set (GtkFileChooserDefault *impl, OperationMode mode) { -- cgit v1.2.1 From c1c1823634b500e1266122eabbd16701a5a2786f Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Mon, 10 Dec 2012 17:14:12 -0600 Subject: Go back to our machinery for Recent files instead of reading recent:/// as-is Reading recent:/// as-is is probably fine for OPEN mode. But for SAVE mode, we want to present a list of recent directories. So, we go back to our old machinery for now; in the future we'll probably just use recent:/// and extract the list of recent directories from there. This also fixes showing the Recent item as highlighted when the file chooser starts up. Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 70 +++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 38 deletions(-) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 2be1764337..adbbcb36ad 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -340,6 +340,8 @@ static void search_shortcut_handler (GtkFileChooserDefault *impl); static void recent_shortcut_handler (GtkFileChooserDefault *impl); static void update_appearance (GtkFileChooserDefault *impl); +static void operation_mode_set (GtkFileChooserDefault *impl, OperationMode mode); + static void set_current_filter (GtkFileChooserDefault *impl, GtkFileFilter *filter); static void check_preview_change (GtkFileChooserDefault *impl); @@ -1278,18 +1280,24 @@ selection_check (GtkFileChooserDefault *impl, *all_folders = closure.all_folders; } +static gboolean +file_is_recent_uri (GFile *file) +{ + GFile *recent; + gboolean same; + + recent = g_file_new_for_uri ("recent:///"); + same = g_file_equal (file, recent); + g_object_unref (recent); + + return same; +} + static void places_sidebar_location_selected_cb (GtkPlacesSidebar *sidebar, GFile *location, GtkPlacesOpenMode open_mode, GtkFileChooserDefault *impl) { gboolean clear_entry; - /* FIXME-places-sidebar: see shortcuts_activate_iter() for missing pieces. In particular: - * - * * Search mode - * - * * Recent-files mode - */ - /* In the Save modes, we want to preserve what the uesr typed in the filename * entry, so that he may choose another folder without erasing his typed name. */ @@ -1300,7 +1308,16 @@ places_sidebar_location_selected_cb (GtkPlacesSidebar *sidebar, GFile *location, else clear_entry = FALSE; - change_folder_and_display_error (impl, location, clear_entry); + /* FIXME-places-sidebar: + * + * GtkPlacesSidebar doesn't have a Search item anymore. We should put that function in a toolbar-like button, like + * in Nautilus, and do operation_mode_set (impl, OPERATION_MODE_SEARCH); + */ + + if (file_is_recent_uri (location)) + operation_mode_set (impl, OPERATION_MODE_RECENT); + else + change_folder_and_display_error (impl, location, clear_entry); } /* Callback used when the places sidebar needs us to display an error message */ @@ -3063,7 +3080,7 @@ operation_mode_set_recent (GtkFileChooserDefault *impl) static void operation_mode_set (GtkFileChooserDefault *impl, OperationMode mode) { - ShortcutsIndex shortcut_to_select; + GFile *file; operation_mode_stop (impl, impl->operation_mode); @@ -3073,28 +3090,23 @@ operation_mode_set (GtkFileChooserDefault *impl, OperationMode mode) { case OPERATION_MODE_BROWSE: operation_mode_set_browse (impl); - shortcut_to_select = SHORTCUTS_CURRENT_FOLDER; break; case OPERATION_MODE_SEARCH: operation_mode_set_search (impl); - shortcut_to_select = SHORTCUTS_SEARCH; break; case OPERATION_MODE_RECENT: operation_mode_set_recent (impl); - shortcut_to_select = SHORTCUTS_RECENT; + file = g_file_new_for_uri ("recent:///"); + gtk_places_sidebar_set_current_location (GTK_PLACES_SIDEBAR (impl->places_sidebar), file); + g_object_unref (file); break; default: g_assert_not_reached (); return; } - -#if REMOVE_FOR_PLACES_SIDEBAR - if (shortcut_to_select != SHORTCUTS_CURRENT_FOLDER) - shortcuts_select_item_without_activating (impl, shortcuts_get_index (impl, shortcut_to_select)); -#endif } /* This function is basically a do_all function. @@ -3798,7 +3810,7 @@ set_startup_mode (GtkFileChooserDefault *impl) switch (impl->startup_mode) { case STARTUP_MODE_RECENT: - recent_shortcut_handler (impl); + operation_mode_set (impl, OPERATION_MODE_RECENT); break; case STARTUP_MODE_CWD: @@ -5027,19 +5039,6 @@ out: g_object_unref (cancellable); } -static gboolean -file_is_recent_uri (GFile *file) -{ - GFile *recent; - gboolean same; - - recent = g_file_new_for_uri ("recent:///"); - same = g_file_equal (file, recent); - g_object_unref (recent); - - return same; -} - static gboolean gtk_file_chooser_default_update_current_folder (GtkFileChooser *chooser, GFile *file, @@ -5056,8 +5055,7 @@ gtk_file_chooser_default_update_current_folder (GtkFileChooser *chooser, operation_mode_set (impl, OPERATION_MODE_BROWSE); - if (impl->local_only && !g_file_is_native (file) - && !file_is_recent_uri (file)) /* GIO considers "recent:///" to be non-native; we special-case it so recent files *will* show up */ + if (impl->local_only && !g_file_is_native (file)) { g_set_error_literal (error, GTK_FILE_CHOOSER_ERROR, @@ -7529,11 +7527,7 @@ search_shortcut_handler (GtkFileChooserDefault *impl) static void recent_shortcut_handler (GtkFileChooserDefault *impl) { - GFile *recent; - - recent = g_file_new_for_uri ("recent:///"); - change_folder_and_display_error (impl, recent, FALSE); - g_object_unref (recent); + operation_mode_set (impl, OPERATION_MODE_RECENT); } static void -- cgit v1.2.1 From bd28aad834cf1f3086b76327d12920722111cbb3 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Mon, 10 Dec 2012 17:16:36 -0600 Subject: Remove unused code --- gtk/gtkfilechooserdefault.c | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index adbbcb36ad..e677f84059 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -222,22 +222,6 @@ enum { GTK_TREE_MODEL_ROW, }; -/* #if REMOVE_FOR_PLACES_SIDEBAR - this is used in operation_mode_set(), so don't remove it yet */ -/* Interesting places in the shortcuts bar */ -typedef enum { - SHORTCUTS_SEARCH, - SHORTCUTS_RECENT, - SHORTCUTS_RECENT_SEPARATOR, - SHORTCUTS_HOME, - SHORTCUTS_DESKTOP, - SHORTCUTS_VOLUMES, - SHORTCUTS_SHORTCUTS, - SHORTCUTS_BOOKMARKS_SEPARATOR, - SHORTCUTS_BOOKMARKS, - SHORTCUTS_CURRENT_FOLDER_SEPARATOR, - SHORTCUTS_CURRENT_FOLDER -} ShortcutsIndex; - /* Icon size for if we can't get it from the theme */ #define FALLBACK_ICON_SIZE 16 -- cgit v1.2.1 From 9124766d7b981aa418e51537ef58ebdb4c21e6c0 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Mon, 10 Dec 2012 17:26:46 -0600 Subject: Implement the Search keyboard shortcut We still lack a button to activate Search, like in Nautilus, but that will come later. And with this, the last REMOVE_FOR_PLACES_SIDEBAR is gone! Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index e677f84059..4c4e54f477 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -18,8 +18,6 @@ */ /* TODO: - * - * * Fix instances of "#if REMOVE_FOR_PLACES_SIDEBAR" * * * Fix FIXME-places-sidebar */ @@ -7493,18 +7491,13 @@ desktop_folder_handler (GtkFileChooserDefault *impl) static void search_shortcut_handler (GtkFileChooserDefault *impl) { - if (impl->has_search) - { -#if REMOVE_FOR_PLACES_SIDEBAR - switch_to_shortcut (impl, shortcuts_get_index (impl, SHORTCUTS_SEARCH)); -#endif + operation_mode_set (impl, OPERATION_MODE_SEARCH); - /* we want the entry widget to grab the focus the first - * time, not the browse_files_tree_view widget. - */ - if (impl->search_entry) - gtk_widget_grab_focus (impl->search_entry); - } + /* we want the entry widget to grab the focus the first + * time, not the browse_files_tree_view widget. + */ + if (impl->search_entry) + gtk_widget_grab_focus (impl->search_entry); } /* Handler for the "recent-shortcut" keybinding signal */ -- cgit v1.2.1 From 72ce506cfce2296cacc396c0af1b053b556f9756 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Tue, 11 Dec 2012 12:09:13 -0600 Subject: Rename signal location-selected to open-location Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 4c4e54f477..cb126fa414 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -1276,7 +1276,7 @@ file_is_recent_uri (GFile *file) } static void -places_sidebar_location_selected_cb (GtkPlacesSidebar *sidebar, GFile *location, GtkPlacesOpenMode open_mode, GtkFileChooserDefault *impl) +places_sidebar_open_location_cb (GtkPlacesSidebar *sidebar, GFile *location, GtkPlacesOpenMode open_mode, GtkFileChooserDefault *impl) { gboolean clear_entry; @@ -1320,8 +1320,8 @@ shortcuts_pane_create (GtkFileChooserDefault *impl, impl->places_sidebar = gtk_places_sidebar_new (); gtk_places_sidebar_set_show_cwd (GTK_PLACES_SIDEBAR (impl->places_sidebar), TRUE); - g_signal_connect (impl->places_sidebar, "location-selected", - G_CALLBACK (places_sidebar_location_selected_cb), + g_signal_connect (impl->places_sidebar, "open-location", + G_CALLBACK (places_sidebar_open_location_cb), impl); g_signal_connect (impl->places_sidebar, "show-error-message", G_CALLBACK (places_sidebar_show_error_message_cb), -- cgit v1.2.1 From c4f40a92ca3aa182f05d5796054cb94a0e4c438f Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Tue, 11 Dec 2012 15:29:11 -0600 Subject: Remove the GError from the shortcut-related functions See https://bugzilla.gnome.org/show_bug.cgi?id=650363#c8 and the next comment; this argument just makes the API harder to use without real benefit. Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index cb126fa414..330c591d0a 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -5587,7 +5587,8 @@ gtk_file_chooser_default_add_shortcut_folder (GtkFileChooser *chooser, { GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser); - return gtk_places_sidebar_add_shortcut (GTK_PLACES_SIDEBAR (impl->places_sidebar), file, error); + gtk_places_sidebar_add_shortcut (GTK_PLACES_SIDEBAR (impl->places_sidebar), file); + return TRUE; } static gboolean @@ -5597,7 +5598,8 @@ gtk_file_chooser_default_remove_shortcut_folder (GtkFileChooser *chooser, { GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser); - return gtk_places_sidebar_remove_shortcut (GTK_PLACES_SIDEBAR (impl->places_sidebar), file, error); + gtk_places_sidebar_remove_shortcut (GTK_PLACES_SIDEBAR (impl->places_sidebar), file); + return TRUE; } static GSList * -- cgit v1.2.1 From 42d239f6d5c97bd0c4a9a3e1359a48374dfd7ebe Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Tue, 11 Dec 2012 15:52:17 -0600 Subject: Remove gtk_places_sidebar_set_show_cwd(), implement that in the file chooser This removes more idiosyncratic API from the sidebar. Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 60 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 330c591d0a..776d7baac8 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -1318,7 +1318,6 @@ shortcuts_pane_create (GtkFileChooserDefault *impl, GtkSizeGroup *size_group) { impl->places_sidebar = gtk_places_sidebar_new (); - gtk_places_sidebar_set_show_cwd (GTK_PLACES_SIDEBAR (impl->places_sidebar), TRUE); g_signal_connect (impl->places_sidebar, "open-location", G_CALLBACK (places_sidebar_open_location_cb), @@ -3804,6 +3803,63 @@ set_startup_mode (GtkFileChooserDefault *impl) } } +static gboolean +shortcut_exists (GtkFileChooserDefault *impl, GFile *needle) +{ + GSList *haystack; + GSList *l; + gboolean exists; + + exists = FALSE; + + haystack = gtk_places_sidebar_list_shortcuts (GTK_PLACES_SIDEBAR (impl->places_sidebar)); + for (l = haystack; l; l = l->next) + { + GFile *hay; + + hay = G_FILE (l->data); + if (g_file_equal (hay, needle)) + { + exists = TRUE; + break; + } + } + g_slist_free_full (haystack, g_object_unref); + + return exists; +} + +static void +add_cwd_to_sidebar_if_needed (GtkFileChooserDefault *impl) +{ + char *cwd; + GFile *cwd_file; + GFile *home_file; + + cwd = g_get_current_dir (); + cwd_file = g_file_new_for_path (cwd); + g_free (cwd); + + if (shortcut_exists (impl, cwd_file)) + goto out; + + home_file = g_file_new_for_path (g_get_home_dir ()); + + /* We only add an item for $CWD if it is different from $HOME. This way, + * applications which get launched from a shell in a terminal (by someone who + * knows what they are doing) will get an item for $CWD in the places sidebar, + * and "normal" applications launched from the desktop shell (whose $CWD is + * $HOME) won't get any extra clutter in the sidebar. + */ + if (!g_file_equal (home_file, cwd_file)) + gtk_places_sidebar_add_shortcut (GTK_PLACES_SIDEBAR (impl->places_sidebar), cwd_file); + + g_object_unref (home_file); + + out: + g_object_unref (cwd_file); +} + /* GtkWidget::map method */ static void gtk_file_chooser_default_map (GtkWidget *widget) @@ -3818,6 +3874,8 @@ gtk_file_chooser_default_map (GtkWidget *widget) settings_load (impl); + add_cwd_to_sidebar_if_needed (impl); + if (impl->operation_mode == OPERATION_MODE_BROWSE) { switch (impl->reload_state) -- cgit v1.2.1 From 0b4183234b23866b3857cb00a145b34c954ac2d1 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Thu, 10 Jan 2013 16:19:03 -0600 Subject: New API, gtk_places_sidebar_set_open_flags() This lets us handle the 'Open in new tab' and 'Open in new window' menu items on our own, and allows callers to have less code to deal with each mode. Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 776d7baac8..ced3722005 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -1276,7 +1276,7 @@ file_is_recent_uri (GFile *file) } static void -places_sidebar_open_location_cb (GtkPlacesSidebar *sidebar, GFile *location, GtkPlacesOpenMode open_mode, GtkFileChooserDefault *impl) +places_sidebar_open_location_cb (GtkPlacesSidebar *sidebar, GFile *location, GtkPlacesOpenFlags open_flags, GtkFileChooserDefault *impl) { gboolean clear_entry; -- cgit v1.2.1 From da2e081786552a69dd7e278d713689c8d5606a87 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Thu, 10 Jan 2013 18:12:15 -0600 Subject: Make the set_location()/get_location() API consistent We used to have set_current_location() and get_selected_location(), with confusing semantics. Now they are symmetric, with the exception that if set_location() is called with a location that is not shown in the sidebar, then it will both clear the selection in the list and make get_selection() return NULL. Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gtk/gtkfilechooserdefault.c') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index ced3722005..b65047f5cc 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -3080,7 +3080,7 @@ operation_mode_set (GtkFileChooserDefault *impl, OperationMode mode) case OPERATION_MODE_RECENT: operation_mode_set_recent (impl); file = g_file_new_for_uri ("recent:///"); - gtk_places_sidebar_set_current_location (GTK_PLACES_SIDEBAR (impl->places_sidebar), file); + gtk_places_sidebar_set_location (GTK_PLACES_SIDEBAR (impl->places_sidebar), file); g_object_unref (file); break; @@ -5064,7 +5064,7 @@ update_current_folder_get_info_cb (GCancellable *cancellable, /* Refresh controls */ - gtk_places_sidebar_set_current_location (GTK_PLACES_SIDEBAR (impl->places_sidebar), impl->current_folder); + gtk_places_sidebar_set_location (GTK_PLACES_SIDEBAR (impl->places_sidebar), impl->current_folder); g_signal_emit_by_name (impl, "current-folder-changed", 0); -- cgit v1.2.1