[PATCH] Re-Add "Invert Selection"



The attached patch adds an invert selection feature which has been
removed during the de-bonoboization. Feedback appreciated, especially
since I'm not sure whether the tooltip is OK.

-- 
Christian Neumair <chris gnome-de org>
Index: libnautilus-private/nautilus-icon-container.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-container.c,v
retrieving revision 1.392
diff -u -p -r1.392 nautilus-icon-container.c
--- libnautilus-private/nautilus-icon-container.c	6 Jul 2005 12:18:27 -0000	1.392
+++ libnautilus-private/nautilus-icon-container.c	13 Jul 2005 18:31:42 -0000
@@ -5497,6 +5535,29 @@ nautilus_icon_container_select_all (Naut
 				 signals[SELECTION_CHANGED], 0);
 	}
 }
+
+/**
+ * nautilus_icon_container_invert_selection:
+ * @container: An icon container widget.
+ * 
+ * Select all previously unselected icons in @container and vice versa.
+ **/
+void
+nautilus_icon_container_invert_selection (NautilusIconContainer *container)
+{
+	NautilusIcon *icon;
+	GList *p;
+
+	for (p = container->details->icons; p != NULL; p = p->next) {
+		icon = (NautilusIcon *) p->data;
+		icon_toggle_selected (container, icon);
+	}
+
+	if (!nautilus_icon_container_is_empty (container)) {
+		g_signal_emit (container, signals[SELECTION_CHANGED], 0);
+	}
+}
+
 
 /**
  * nautilus_icon_container_set_selection:
Index: libnautilus-private/nautilus-icon-container.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-container.h,v
retrieving revision 1.87
diff -u -p -r1.87 nautilus-icon-container.h
--- libnautilus-private/nautilus-icon-container.h	5 Jul 2005 12:23:34 -0000	1.87
+++ libnautilus-private/nautilus-icon-container.h	13 Jul 2005 18:31:42 -0000
@@ -243,6 +248,7 @@ void              nautilus_icon_containe
 /* operations on all icons */
 void              nautilus_icon_container_unselect_all                  (NautilusIconContainer  *view);
 void              nautilus_icon_container_select_all                    (NautilusIconContainer  *view);
+void              nautilus_icon_container_invert_selection              (NautilusIconContainer  *view);
 
 
 /* operations on the selection */
Index: src/file-manager/fm-directory-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-directory-view.c,v
retrieving revision 1.701
diff -u -p -r1.701 fm-directory-view.c
--- src/file-manager/fm-directory-view.c	11 Jul 2005 10:07:53 -0000	1.701
+++ src/file-manager/fm-directory-view.c	13 Jul 2005 18:31:50 -0000
@@ -982,6 +982,15 @@ action_select_all_callback (GtkAction *a
 }
 
 static void
+action_invert_selection_callback (GtkAction *action, 
+				  gpointer callback_data)
+{
+	g_assert (FM_IS_DIRECTORY_VIEW (callback_data));
+
+	fm_directory_view_invert_selection (callback_data);
+}
+
+static void
 pattern_select_response_cb (GtkWidget *dialog, int response, gpointer user_data)
 {
 	FMDirectoryView *view;
@@ -6176,6 +6185,10 @@ static const GtkActionEntry directory_vi
     N_("Select _All"), "<control>A",                /* label, accelerator */
     N_("Select all items in this window"),                   /* tooltip */ 
     G_CALLBACK (action_select_all_callback) },
+  { "Invert Selection", NULL,                  /* name, stock id */
+    N_("_Invert Selection"), "<control>I",                /* label, accelerator */
+    N_("Select all unselected items in this window and unselect the selected ones"),                   /* tooltip */ 
+    G_CALLBACK (action_invert_selection_callback) },
   { "Select Pattern", NULL,                  /* name, stock id */
     N_("Select _Pattern"), "<control>S",                /* label, accelerator */
     N_("Select items in this window matching a given pattern"),                   /* tooltip */ 
@@ -7824,6 +7837,23 @@ fm_directory_view_select_all (FMDirector
 		(FM_DIRECTORY_VIEW_CLASS, view,
 		 select_all, (view));
 }
+
+/**
+ * fm_directory_invert_selection:
+ *
+ * select all previously unselected items in the view and vice versa
+ * 
+ **/
+void
+fm_directory_view_invert_selection (FMDirectoryView *view)
+{
+	g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
+
+	EEL_CALL_METHOD
+		(FM_DIRECTORY_VIEW_CLASS, view,
+		 invert_selection, (view));
+}
+
 
 /**
  * fm_directory_view_set_selection:
Index: src/file-manager/fm-directory-view.h
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-directory-view.h,v
retrieving revision 1.141
diff -u -p -r1.141 fm-directory-view.h
--- src/file-manager/fm-directory-view.h	5 Jul 2005 12:23:35 -0000	1.141
+++ src/file-manager/fm-directory-view.h	13 Jul 2005 18:31:50 -0000
@@ -148,6 +148,10 @@ struct FMDirectoryViewClass {
          * select all of the items in the view */
         void     (* select_all)	         	(FMDirectoryView *view);
 
+        /* invert_selection is a function pointer that subclasses must override to
+         * select all previously unselected items in the view and vice versa */
+        void     (* invert_selection)	        (FMDirectoryView *view);
+
         /* set_selection is a function pointer that subclasses must
          * override to select the specified items (and unselect all
          * others). The argument is a list of NautilusFiles. */
@@ -328,6 +332,7 @@ NautilusZoomLevel   fm_directory_view_ge
 void                fm_directory_view_restore_default_zoom_level       (FMDirectoryView  *view);
 void                fm_directory_view_reset_to_defaults                (FMDirectoryView  *view);
 void                fm_directory_view_select_all                       (FMDirectoryView  *view);
+void                fm_directory_view_invert_selection                 (FMDirectoryView  *view);
 void                fm_directory_view_set_selection                    (FMDirectoryView  *view,
 									GList            *selection);
 GArray *            fm_directory_view_get_selected_icon_locations      (FMDirectoryView  *view);
Index: src/file-manager/fm-icon-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-icon-view.c,v
retrieving revision 1.311
diff -u -p -r1.311 fm-icon-view.c
--- src/file-manager/fm-icon-view.c	5 Jul 2005 12:23:35 -0000	1.311
+++ src/file-manager/fm-icon-view.c	13 Jul 2005 18:31:51 -0000
@@ -1600,6 +1600,18 @@ fm_icon_view_select_all (FMDirectoryView
 }
 
 static void
+fm_icon_view_invert_selection (FMDirectoryView *view)
+{
+	NautilusIconContainer *icon_container;
+
+	g_return_if_fail (FM_IS_ICON_VIEW (view));
+
+	icon_container = get_icon_container (FM_ICON_VIEW (view));
+        nautilus_icon_container_invert_selection (icon_container);
+}
+
+
+static void
 fm_icon_view_reveal_selection (FMDirectoryView *view)
 {
 	GList *selection;
@@ -2556,6 +2568,7 @@ fm_icon_view_class_init (FMIconViewClass
 	fm_directory_view_class->restore_default_zoom_level = fm_icon_view_restore_default_zoom_level;
 	fm_directory_view_class->reveal_selection = fm_icon_view_reveal_selection;
 	fm_directory_view_class->select_all = fm_icon_view_select_all;
+	fm_directory_view_class->invert_selection = fm_icon_view_invert_selection;
 	fm_directory_view_class->set_selection = fm_icon_view_set_selection;
 	fm_directory_view_class->sort_files = fm_icon_view_sort_files;
 	fm_directory_view_class->zoom_to_level = fm_icon_view_zoom_to_level;
Index: src/file-manager/fm-list-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-list-view.c,v
retrieving revision 1.253
diff -u -p -r1.253 fm-list-view.c
--- src/file-manager/fm-list-view.c	13 Jul 2005 09:36:20 -0000	1.253
+++ src/file-manager/fm-list-view.c	13 Jul 2005 18:31:52 -0000
@@ -1726,9 +1726,37 @@ fm_list_view_set_selection (FMDirectoryV
 static void
 fm_list_view_select_all (FMDirectoryView *view)
 {
+
 	gtk_tree_selection_select_all (gtk_tree_view_get_selection (FM_LIST_VIEW (view)->details->tree_view));
 }
 
+static gboolean
+invert_selection_foreach (GtkTreeModel *model,
+			  GtkTreePath *path,
+			  GtkTreeIter *iter,
+			  GtkTreeSelection *selection)
+{
+	if (gtk_tree_selection_iter_is_selected (selection, iter)) {
+		gtk_tree_selection_unselect_iter (selection, iter);
+	} else {
+		gtk_tree_selection_select_iter (selection, iter);
+	}
+
+	return FALSE;
+}
+
+static void
+fm_list_view_invert_selection (FMDirectoryView *view)
+{
+	GtkTreeSelection *selection;
+
+	selection = gtk_tree_view_get_selection (FM_LIST_VIEW (view)->details->tree_view);
+	gtk_tree_model_foreach (GTK_TREE_MODEL (FM_LIST_VIEW (view)->details->model),
+				(GtkTreeModelForeachFunc) invert_selection_foreach,
+				selection);
+}
+
+
 static void
 fm_list_view_reveal_selection (FMDirectoryView *view)
 {
@@ -2468,6 +2496,7 @@ fm_list_view_class_init (FMListViewClass
 	fm_directory_view_class->restore_default_zoom_level = fm_list_view_restore_default_zoom_level;
 	fm_directory_view_class->reveal_selection = fm_list_view_reveal_selection;
 	fm_directory_view_class->select_all = fm_list_view_select_all;
+	fm_directory_view_class->invert_selection = fm_list_view_invert_selection;
 	fm_directory_view_class->set_selection = fm_list_view_set_selection;
 	fm_directory_view_class->sort_files = fm_list_view_sort_files;
 	fm_directory_view_class->sort_directories_first_changed = fm_list_view_sort_directories_first_changed;
Index: src/file-manager/nautilus-directory-view-ui.xml
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/nautilus-directory-view-ui.xml,v
retrieving revision 1.76
diff -u -p -r1.76 nautilus-directory-view-ui.xml
--- src/file-manager/nautilus-directory-view-ui.xml	6 Jul 2005 14:02:38 -0000	1.76
+++ src/file-manager/nautilus-directory-view-ui.xml	13 Jul 2005 18:31:52 -0000
@@ -49,6 +49,7 @@
 		</placeholder>
 		<placeholder name="Select Items">
 		<menuitem name="Select All" action="Select All"/>
+		<menuitem name="Invert Selection" action="Invert Selection"/>
 		<menuitem name="Select Pattern" action="Select Pattern"/>
 		</placeholder>
 		<placeholder name="File Items Placeholder">

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]