From 21a30978dcbe711d1e755703e332fcd4f32bfbc3 Mon Sep 17 00:00:00 2001 From: Josselin Mouette Date: Mon, 26 Nov 2007 23:16:19 +0000 Subject: [PATCH] reviewed by: Federico Mena Quintero 2007-11-26 Josselin Mouette reviewed by: Federico Mena Quintero * gtk/gtkfilechooserdefault.c: (shortcuts_append_paths), (shortcuts_add_bookmarks), (shortcuts_selection_changed_cb), (shortcuts_list_create), (gtk_file_chooser_default_should_respond): Make the shortcuts activate with a single click. (#148828) Fix a few things affected by the change: - Set selection mode to GTK_SELECTION_SINGLE to allow a case where no shortcut is selected. - Don't activate a shortcut in the response callback. - Filter out duplicate entries in volumes and bookmarks to avoid the selection to change when reordering them with DnD. svn path=/trunk/; revision=19072 --- ChangeLog | 15 ++++++++ gtk/gtkfilechooserdefault.c | 72 +++++++++++-------------------------- 2 files changed, 36 insertions(+), 51 deletions(-) diff --git a/ChangeLog b/ChangeLog index ac6fc00c74..43c5559c5d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2007-11-26 Josselin Mouette + + reviewed by: Federico Mena Quintero + + * gtk/gtkfilechooserdefault.c: (shortcuts_append_paths), + (shortcuts_add_bookmarks), (shortcuts_selection_changed_cb), + (shortcuts_list_create), (gtk_file_chooser_default_should_respond): + Make the shortcuts activate with a single click. (#148828) + Fix a few things affected by the change: + - Set selection mode to GTK_SELECTION_SINGLE to allow a case + where no shortcut is selected. + - Don't activate a shortcut in the response callback. + - Filter out duplicate entries in volumes and bookmarks to + avoid the selection to change when reordering them with DnD. + 2007-11-26 Matthias Clasen * gtk/gtkmain.c: diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 33eb2648fb..fe958b408a 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -390,10 +390,6 @@ static void check_preview_change (GtkFileChooserDefault *impl); static void filter_combo_changed (GtkComboBox *combo_box, GtkFileChooserDefault *impl); -static void shortcuts_row_activated_cb (GtkTreeView *tree_view, - GtkTreePath *path, - GtkTreeViewColumn *column, - GtkFileChooserDefault *impl); static gboolean shortcuts_key_press_event_cb (GtkWidget *widget, GdkEventKey *event, @@ -2002,9 +1998,7 @@ shortcuts_append_paths (GtkFileChooserDefault *impl, profile_start ("start", NULL); - /* As there is no separator now, we want to start there. - */ - start_row = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR); + start_row = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR) + 1; num_inserted = 0; for (; paths; paths = paths->next) @@ -2016,6 +2010,8 @@ shortcuts_append_paths (GtkFileChooserDefault *impl, if (impl->local_only && !gtk_file_system_path_is_local (impl->file_system, path)) continue; + if (shortcut_find_position (impl, path) != -1) + continue; label = gtk_file_system_get_bookmark_label (impl->file_system, path); @@ -2245,13 +2241,14 @@ shortcuts_add_bookmarks (GtkFileChooserDefault *impl) impl->num_bookmarks + 1); impl->num_bookmarks = 0; + shortcuts_insert_separator (impl, SHORTCUTS_BOOKMARKS_SEPARATOR); bookmarks = gtk_file_system_list_bookmarks (impl->file_system); shortcuts_append_paths (impl, bookmarks); gtk_file_paths_free (bookmarks); - if (impl->num_bookmarks > 0) - shortcuts_insert_separator (impl, SHORTCUTS_BOOKMARKS_SEPARATOR); + 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)); @@ -3657,8 +3654,22 @@ 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 @@ -3930,7 +3941,7 @@ shortcuts_list_create (GtkFileChooserDefault *impl) GDK_ACTION_COPY | GDK_ACTION_MOVE); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view)); - gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE); + gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); gtk_tree_selection_set_select_function (selection, shortcuts_select_func, impl, NULL); @@ -3938,9 +3949,6 @@ shortcuts_list_create (GtkFileChooserDefault *impl) g_signal_connect (selection, "changed", G_CALLBACK (shortcuts_selection_changed_cb), impl); - g_signal_connect (impl->browse_shortcuts_tree_view, "row_activated", - G_CALLBACK (shortcuts_row_activated_cb), impl); - g_signal_connect (impl->browse_shortcuts_tree_view, "key_press_event", G_CALLBACK (shortcuts_key_press_event_cb), impl); @@ -8604,25 +8612,6 @@ gtk_file_chooser_default_should_respond (GtkFileChooserEmbed *chooser_embed) gtk_file_path_free (path); return retval; } - else if (impl->toplevel_last_focus_widget == impl->browse_shortcuts_tree_view) - { - /* The focus is on a dialog's action area button, *and* the widget that - * was focused immediately before it is the shortcuts list. Switch to the - * selected shortcut and tell the caller not to respond. - */ - GtkTreeIter iter; - - if (shortcuts_get_selected (impl, &iter)) - { - shortcuts_activate_iter (impl, &iter); - - focus_browse_tree_view_if_possible (impl); - } - else - goto file_list; - - return FALSE; - } else if (impl->toplevel_last_focus_widget == impl->browse_files_tree_view) { /* The focus is on a dialog's action area button, *and* the widget that @@ -10482,25 +10471,6 @@ shortcuts_activate_iter (GtkFileChooserDefault *impl, } } -/* Callback used when a row in the shortcuts list is activated */ -static void -shortcuts_row_activated_cb (GtkTreeView *tree_view, - GtkTreePath *path, - GtkTreeViewColumn *column, - GtkFileChooserDefault *impl) -{ - GtkTreeIter iter; - GtkTreeIter child_iter; - - if (!gtk_tree_model_get_iter (impl->shortcuts_pane_filter_model, &iter, path)) - return; - - 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); -} - /* Handler for GtkWidget::key-press-event on the shortcuts list */ static gboolean shortcuts_key_press_event_cb (GtkWidget *widget,