[Xfce4-commits] <thunar:master> Implement selection invertion.
Nick Schermer
noreply at xfce.org
Tue Sep 18 22:44:01 CEST 2012
Updating branch refs/heads/master
to d385dd9d08f84cb11797ec3421f2f0076446499f (commit)
from c21dc002c6cac3347bb94bc73627aef1d407cca6 (commit)
commit d385dd9d08f84cb11797ec3421f2f0076446499f
Author: Nick Schermer <nick at xfce.org>
Date: Tue Sep 18 22:42:39 2012 +0200
Implement selection invertion.
thunar/thunar-abstract-icon-view.c | 11 +++++++
thunar/thunar-details-view.c | 52 ++++++++++++++++++++++++++++++++++++
thunar/thunar-standard-view-ui.xml | 1 +
thunar/thunar-standard-view.c | 21 ++++++++++++++
thunar/thunar-standard-view.h | 3 ++
5 files changed, 88 insertions(+), 0 deletions(-)
diff --git a/thunar/thunar-abstract-icon-view.c b/thunar/thunar-abstract-icon-view.c
index b2f3164..d244a79 100644
--- a/thunar/thunar-abstract-icon-view.c
+++ b/thunar/thunar-abstract-icon-view.c
@@ -44,6 +44,7 @@ static void thunar_abstract_icon_view_disconnect_ui_manager (ThunarStand
static GList *thunar_abstract_icon_view_get_selected_items (ThunarStandardView *standard_view);
static void thunar_abstract_icon_view_select_all (ThunarStandardView *standard_view);
static void thunar_abstract_icon_view_unselect_all (ThunarStandardView *standard_view);
+static void thunar_abstract_icon_view_selection_invert (ThunarStandardView *standard_view);
static void thunar_abstract_icon_view_select_path (ThunarStandardView *standard_view,
GtkTreePath *path);
static void thunar_abstract_icon_view_set_cursor (ThunarStandardView *standard_view,
@@ -153,6 +154,7 @@ thunar_abstract_icon_view_class_init (ThunarAbstractIconViewClass *klass)
thunarstandard_view_class->get_selected_items = thunar_abstract_icon_view_get_selected_items;
thunarstandard_view_class->select_all = thunar_abstract_icon_view_select_all;
thunarstandard_view_class->unselect_all = thunar_abstract_icon_view_unselect_all;
+ thunarstandard_view_class->selection_invert = thunar_abstract_icon_view_selection_invert;
thunarstandard_view_class->select_path = thunar_abstract_icon_view_select_path;
thunarstandard_view_class->set_cursor = thunar_abstract_icon_view_set_cursor;
thunarstandard_view_class->scroll_to_path = thunar_abstract_icon_view_scroll_to_path;
@@ -319,6 +321,15 @@ thunar_abstract_icon_view_unselect_all (ThunarStandardView *standard_view)
static void
+thunar_abstract_icon_view_selection_invert (ThunarStandardView *standard_view)
+{
+ _thunar_return_if_fail (THUNAR_IS_ABSTRACT_ICON_VIEW (standard_view));
+ exo_icon_view_selection_invert (EXO_ICON_VIEW (GTK_BIN (standard_view)->child));
+}
+
+
+
+static void
thunar_abstract_icon_view_select_path (ThunarStandardView *standard_view,
GtkTreePath *path)
{
diff --git a/thunar/thunar-details-view.c b/thunar/thunar-details-view.c
index 09b9429..7bb2957 100644
--- a/thunar/thunar-details-view.c
+++ b/thunar/thunar-details-view.c
@@ -58,6 +58,7 @@ static void thunar_details_view_disconnect_ui_manager (ThunarStandardV
static GList *thunar_details_view_get_selected_items (ThunarStandardView *standard_view);
static void thunar_details_view_select_all (ThunarStandardView *standard_view);
static void thunar_details_view_unselect_all (ThunarStandardView *standard_view);
+static void thunar_details_view_selection_invert (ThunarStandardView *standard_view);
static void thunar_details_view_select_path (ThunarStandardView *standard_view,
GtkTreePath *path);
static void thunar_details_view_set_cursor (ThunarStandardView *standard_view,
@@ -156,6 +157,7 @@ thunar_details_view_class_init (ThunarDetailsViewClass *klass)
thunarstandard_view_class->get_selected_items = thunar_details_view_get_selected_items;
thunarstandard_view_class->select_all = thunar_details_view_select_all;
thunarstandard_view_class->unselect_all = thunar_details_view_unselect_all;
+ thunarstandard_view_class->selection_invert = thunar_details_view_selection_invert;
thunarstandard_view_class->select_path = thunar_details_view_select_path;
thunarstandard_view_class->set_cursor = thunar_details_view_set_cursor;
thunarstandard_view_class->scroll_to_path = thunar_details_view_scroll_to_path;
@@ -460,6 +462,56 @@ thunar_details_view_unselect_all (ThunarStandardView *standard_view)
static void
+thunar_details_view_selection_invert_foreach (GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ GList **list = data;
+
+ *list = g_list_prepend (*list, gtk_tree_path_copy (path));
+}
+
+
+
+static void
+thunar_details_view_selection_invert (ThunarStandardView *standard_view)
+{
+ GtkTreeSelection *selection;
+ GList *selected_paths = NULL;
+ GList *lp;
+ GtkTreePath *path;
+
+ _thunar_return_if_fail (THUNAR_IS_DETAILS_VIEW (standard_view));
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (GTK_BIN (standard_view)->child));
+
+ /* block updates */
+ g_signal_handlers_block_by_func (selection, thunar_standard_view_selection_changed, standard_view);
+
+ /* get paths of selected files */
+ gtk_tree_selection_selected_foreach (selection, thunar_details_view_selection_invert_foreach, &selected_paths);
+
+ gtk_tree_selection_select_all (selection);
+
+ for (lp = selected_paths; lp != NULL; lp = lp->next)
+ {
+ path = lp->data;
+ gtk_tree_selection_unselect_path (selection, path);
+ gtk_tree_path_free (path);
+ }
+
+ g_list_free (selected_paths);
+
+ /* unblock updates */
+ g_signal_handlers_unblock_by_func (selection, thunar_standard_view_selection_changed, standard_view);
+
+ thunar_standard_view_selection_changed (THUNAR_STANDARD_VIEW (standard_view));
+}
+
+
+
+static void
thunar_details_view_select_path (ThunarStandardView *standard_view,
GtkTreePath *path)
{
diff --git a/thunar/thunar-standard-view-ui.xml b/thunar/thunar-standard-view-ui.xml
index 3892f3a..f79853b 100644
--- a/thunar/thunar-standard-view-ui.xml
+++ b/thunar/thunar-standard-view-ui.xml
@@ -31,6 +31,7 @@
<placeholder name="placeholder-edit-select-actions">
<menuitem action="select-all-files" />
<menuitem action="select-by-pattern" />
+ <menuitem action="invert-selection" />
</placeholder>
<placeholder name="placeholder-edit-alter-actions">
<menuitem action="duplicate" />
diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c
index 0077d8b..78ea179 100644
--- a/thunar/thunar-standard-view.c
+++ b/thunar/thunar-standard-view.c
@@ -181,6 +181,8 @@ static void thunar_standard_view_action_select_all_files (Gtk
ThunarStandardView *standard_view);
static void thunar_standard_view_action_select_by_pattern (GtkAction *action,
ThunarStandardView *standard_view);
+static void thunar_standard_view_action_selection_invert (GtkAction *action,
+ ThunarStandardView *standard_view);
static void thunar_standard_view_action_duplicate (GtkAction *action,
ThunarStandardView *standard_view);
static void thunar_standard_view_action_make_link (GtkAction *action,
@@ -289,6 +291,7 @@ struct _ThunarStandardViewPrivate
GtkAction *action_paste_into_folder;
GtkAction *action_select_all_files;
GtkAction *action_select_by_pattern;
+ GtkAction *action_selection_invert;
GtkAction *action_duplicate;
GtkAction *action_make_link;
GtkAction *action_rename;
@@ -366,6 +369,7 @@ static const GtkActionEntry action_entries[] =
{ "paste-into-folder", GTK_STOCK_PASTE, N_ ("Paste Into Folder"), NULL, N_ ("Move or copy files previously selected by a Cut or Copy command into the selected folder"), G_CALLBACK (thunar_standard_view_action_paste_into_folder), },
{ "select-all-files", NULL, N_ ("Select _all Files"), NULL, N_ ("Select all files in this window"), G_CALLBACK (thunar_standard_view_action_select_all_files), },
{ "select-by-pattern", NULL, N_ ("Select _by Pattern..."), "<control>S", N_ ("Select all files that match a certain pattern"), G_CALLBACK (thunar_standard_view_action_select_by_pattern), },
+ { "invert-selection", NULL, N_ ("_Invert Selection"), NULL, N_ ("Select all and only the items that are not currently selected"), G_CALLBACK (thunar_standard_view_action_selection_invert), },
{ "duplicate", NULL, N_ ("Du_plicate"), NULL, NULL, G_CALLBACK (thunar_standard_view_action_duplicate), },
{ "make-link", NULL, N_ ("Ma_ke Link"), NULL, NULL, G_CALLBACK (thunar_standard_view_action_make_link), },
{ "rename", NULL, N_ ("_Rename..."), "F2", NULL, G_CALLBACK (thunar_standard_view_action_rename), },
@@ -580,6 +584,7 @@ thunar_standard_view_init (ThunarStandardView *standard_view)
standard_view->priv->action_paste_into_folder = gtk_action_group_get_action (standard_view->action_group, "paste-into-folder");
standard_view->priv->action_select_all_files = gtk_action_group_get_action (standard_view->action_group, "select-all-files");
standard_view->priv->action_select_by_pattern = gtk_action_group_get_action (standard_view->action_group, "select-by-pattern");
+ standard_view->priv->action_selection_invert = gtk_action_group_get_action (standard_view->action_group, "invert-selection");
standard_view->priv->action_duplicate = gtk_action_group_get_action (standard_view->action_group, "duplicate");
standard_view->priv->action_make_link = gtk_action_group_get_action (standard_view->action_group, "make-link");
standard_view->priv->action_rename = gtk_action_group_get_action (standard_view->action_group, "rename");
@@ -2163,6 +2168,22 @@ thunar_standard_view_action_select_by_pattern (GtkAction *action,
static void
+thunar_standard_view_action_selection_invert (GtkAction *action,
+ ThunarStandardView *standard_view)
+{
+ _thunar_return_if_fail (GTK_IS_ACTION (action));
+ _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW (standard_view));
+
+ /* grab the focus to the view */
+ gtk_widget_grab_focus (GTK_WIDGET (standard_view));
+
+ /* invert all files in the real view */
+ (*THUNAR_STANDARD_VIEW_GET_CLASS (standard_view)->selection_invert) (standard_view);
+}
+
+
+
+static void
thunar_standard_view_action_duplicate (GtkAction *action,
ThunarStandardView *standard_view)
{
diff --git a/thunar/thunar-standard-view.h b/thunar/thunar-standard-view.h
index 0fa1e25..db6eeca 100644
--- a/thunar/thunar-standard-view.h
+++ b/thunar/thunar-standard-view.h
@@ -61,6 +61,9 @@ struct _ThunarStandardViewClass
/* Unselects all items in the view */
void (*unselect_all) (ThunarStandardView *standard_view);
+ /* Invert selection in the view */
+ void (*selection_invert) (ThunarStandardView *standard_view);
+
/* Selects the given item */
void (*select_path) (ThunarStandardView *standard_view,
GtkTreePath *path);
More information about the Xfce4-commits
mailing list