[Nautilus-list] select all, unselect all and invert selection patch



Hi,

the attached patch improves the behaviour of the 'Select All' menu item 
and adds two new menu items to the 'Edit' menu: 'Unselect All' 
and 'Invert Selection'.

This is my first patch to Nautilus, so please be nice ;)

Regards,

	Benedikt
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/nautilus/ChangeLog,v
retrieving revision 1.4657
diff -r1.4657 ChangeLog
0a1,33
> 2001-06-14  Benedikt Roth  <Benedikt Roth gmx net>
> 
> 	* libnautilus-private/nautilus-icon-container.c:
> 	(nautilus_icon_container_invert_selection),
> 	(nautilus_icon_container_all_icons_selected):	
> 	* libnautilus-private/nautilus-icon-container.h:
> 	* libnautilus/nautilus-bonobo-ui.h:
> 	* libnautilus/nautilus-clipboard-ui.xml:
> 	* libnautilus/nautilus-clipboard.c: (unselect_all_callback),
> 	(initialize_clipboard_component_with_callback_data):
> 	* src/file-manager/fm-directory-view.c:
> 	(bonobo_menu_unselect_all_callback),
> 	(bonobo_menu_invert_selection_callback), (real_merge_menus),
> 	(real_update_menus), (fm_directory_view_unselect_all),
> 	(fm_directory_view_invert_selection),
> 	(fm_directory_view_all_selected),
> 	(fm_directory_view_initialize_class):
> 	* src/file-manager/fm-directory-view.h:
> 	* src/file-manager/fm-icon-view.c: (fm_icon_view_unselect_all),
> 	(fm_icon_view_invert_selection), (fm_icon_view_all_selected),
> 	(fm_icon_view_initialize_class):
> 	* src/file-manager/fm-list-view.c: (fm_list_view_initialize_class),
> 	(fm_list_view_select_all), (fm_list_view_unselect_all),
> 	(fm_list_view_invert_selection), (fm_list_view_all_selected):
> 	* src/file-manager/nautilus-directory-view-ui.xml:
> 	* src/nautilus-shell-ui.xml:
> 	Made the 'Select All' menu item insensitive when already all items
> 	in a directory view are selected.
> 	Added 'Unselect All' menu item and made it work in directory icon/list 
> 	view and nautilus-clipboard.
> 	Added 'Invert Selection' menu item and made it work in 
> 	directory icon and list view.
>
Index: libnautilus/nautilus-bonobo-ui.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus/nautilus-bonobo-ui.h,v
retrieving revision 1.12
diff -r1.12 nautilus-bonobo-ui.h
57a58,59
> #define NAUTILUS_MENU_PATH_UNSELECT_ALL_ITEM		"/menu/Edit/Unselect All"
> #define NAUTILUS_MENU_PATH_INVERT_SELECTION_ITEM	"/menu/Edit/Invert Selection"
63a66,67
> #define NAUTILUS_COMMAND_UNSELECT_ALL			"/commands/Unselect All"
> #define NAUTILUS_COMMAND_INVERT_SELECTION		"/commands/Invert Selection"
Index: libnautilus/nautilus-clipboard-ui.xml
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus/nautilus-clipboard-ui.xml,v
retrieving revision 1.6
diff -r1.6 nautilus-clipboard-ui.xml
22a23,26
> 	<cmd name="Unselect All"
> 	 _label="Unselect All"
> 	 _tip="Unselect all the text in a text field"
> 	 accel="*Control*s"/>
45a50,52
> 			<menuitem name="Unselect All"
> 				  _label="_Unselect All"
> 				  verb="Unselect All"/>
Index: libnautilus/nautilus-clipboard.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus/nautilus-clipboard.c,v
retrieving revision 1.25
diff -r1.25 nautilus-clipboard.c
184a185,195
> unselect_all_callback (BonoboUIComponent *ui,
> 		       gpointer callback_data,
> 		       const char *command_name)
> {
> 	g_assert (BONOBO_IS_UI_COMPONENT (ui));
> 	g_assert (strcmp (command_name, "Unselect All") == 0);
> 
> 	gtk_editable_select_region (GTK_EDITABLE (callback_data), 0, 0);
> }
> 
> static void
408c419,420
< 		BONOBO_UI_VERB ("Select All", select_all_callback),
---
>  		BONOBO_UI_VERB ("Select All", select_all_callback), 
> 		BONOBO_UI_VERB ("Unselect All", unselect_all_callback),
Index: libnautilus-private/nautilus-icon-container.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-container.c,v
retrieving revision 1.214
diff -r1.214 nautilus-icon-container.c
4258a4259,4315
>  * nautilus_icon_container_invert_selection:
>  * @container: An icon container widget.
>  * 
>  * Invert the selection of items in @container.
>  **/
> void
> nautilus_icon_container_invert_selection (NautilusIconContainer *container)
> {
> 	gboolean selection_changed;
> 	GList *p;
> 	NautilusIcon *icon;
> 
> 	g_return_if_fail (NAUTILUS_IS_ICON_CONTAINER (container));
> 
> 	selection_changed = FALSE;
> 
> 	for (p = container->details->icons; p != NULL; p = p->next) {
> 		icon = p->data;
> 	
> 		if (icon->is_selected) {	
> 			selection_changed |= icon_set_selected (container, icon, FALSE);
> 		} else if (!icon->is_selected) {
> 			selection_changed |= icon_set_selected (container, icon, TRUE);
> 		}
> 	}
> 
> 	if (selection_changed) {
> 		gtk_signal_emit (GTK_OBJECT (container),
> 				 signals[SELECTION_CHANGED]);
> 	}
> }
> 
> /**
>  * nautilus_icon_container_all_icons_selected:
>  * @container: An icon container widget.
>  * 
>  * Returns TRUE if all icons in the container are selected
>  **/
> gboolean
> nautilus_icon_container_all_icons_selected (NautilusIconContainer *container)
> {
> 	GList *p;
> 	NautilusIcon *icon;
> 
> 	g_return_val_if_fail (NAUTILUS_IS_ICON_CONTAINER (container), FALSE);
> 
> 	for (p = container->details->icons; p != NULL; p = p->next) {
> 		icon = p->data;
> 	
> 		if (!icon->is_selected) {
> 			return FALSE;
> 		}
> 	}
> 	return TRUE;
> }
> 
> /**
Index: libnautilus-private/nautilus-icon-container.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-container.h,v
retrieving revision 1.58
diff -r1.58 nautilus-icon-container.h
191c191,192
< 
---
> void              nautilus_icon_container_invert_selection              (NautilusIconContainer  *view);
> gboolean          nautilus_icon_container_all_icons_selected            (NautilusIconContainer  *container);
Index: src/nautilus-shell-ui.xml
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-shell-ui.xml,v
retrieving revision 1.67
diff -r1.67 nautilus-shell-ui.xml
27a28,29
> 	<cmd name="Unselect All" accel="*Control*s" sensitive="0"/>
> 	<cmd name="Invert Selection" accel="*Control*i" sensitive="0"/>
125a128,135
> 
> 		<menuitem name="Unselect All"
> 			  _label="_Unselect All" 
> 			  verb="Unselect All"/>
> 
> 		<menuitem name="Invert Selection"
> 			  _label="_Invert Selection" 
> 			  verb="Invert 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.459
diff -r1.459 fm-directory-view.c
325a326
> EEL_IMPLEMENT_MUST_OVERRIDE_SIGNAL (fm_directory_view, unselect_all)
869a871,890
> bonobo_menu_unselect_all_callback (BonoboUIComponent *component, 
> 				   gpointer callback_data, 
> 				   const char *verb)
> {
> 	g_assert (FM_IS_DIRECTORY_VIEW (callback_data));
> 
> 	fm_directory_view_unselect_all (callback_data);
> }
> 
> static void
> bonobo_menu_invert_selection_callback (BonoboUIComponent *component, 
> 				       gpointer callback_data, 
> 				       const char *verb)
> {
> 	g_assert (FM_IS_DIRECTORY_VIEW (callback_data));
> 
> 	fm_directory_view_invert_selection (callback_data);
> }
> 
> static void
3916a3938,3939
> 		BONOBO_UI_VERB ("Unselect All", bonobo_menu_unselect_all_callback),
> 		BONOBO_UI_VERB ("Invert Selection", bonobo_menu_invert_selection_callback),
4112a4136,4143
> 				       !fm_directory_view_all_selected (view));
> 
> 	nautilus_bonobo_set_sensitive (view->details->ui, 
> 				       NAUTILUS_COMMAND_UNSELECT_ALL,
> 				       selection_count);
> 
> 	nautilus_bonobo_set_sensitive (view->details->ui, 
> 				       NAUTILUS_COMMAND_INVERT_SELECTION,
4945a4977,5024
>  * fm_directory_view_unselect_all:
>  *
>  * unselect all the items in the view
>  * 
>  **/
> void
> fm_directory_view_unselect_all (FMDirectoryView *view)
> {
> 	g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
> 
> 	EEL_CALL_METHOD
> 		(FM_DIRECTORY_VIEW_CLASS, view,
> 		 unselect_all, (view));
> }
> 
> /**
>  * fm_directory_view_invert_selection:
>  *
>  * invert selection in the view
>  * 
>  **/
> 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_all_selected:
>  *
>  * returns TRUE if all items in the view are selected
>  * 
>  **/
> gboolean
> fm_directory_view_all_selected (FMDirectoryView *view)
> {
> 	g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), FALSE);
> 
> 	return EEL_CALL_METHOD_WITH_RETURN_VALUE
> 		       (FM_DIRECTORY_VIEW_CLASS, view,
> 		        all_selected, (view));
> }
> 
> /**
5539a5619
> 	EEL_ASSIGN_MUST_OVERRIDE_SIGNAL (klass, fm_directory_view, unselect_all);
Index: src/file-manager/fm-directory-view.h
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-directory-view.h,v
retrieving revision 1.120
diff -r1.120 fm-directory-view.h
139c139,152
<         void     (* select_all)	         	(FMDirectoryView *view);
---
>         void     (* select_all)	                (FMDirectoryView *view);
> 
>         /* select_all is a function pointer that subclasses must override to
>          * select all of the items in the view */
>         void     (* unselect_all)         	(FMDirectoryView *view);
> 
>         /* invert_selection is a function pointer that subclasses must override to
>          * invert the selection of the items in the view */
>         void     (* invert_selection)         	(FMDirectoryView *view);
> 
> 	/* all_selected is a function pointer that subclasses must
> 	 * override to report whether all items in the view are selected.
> 	 */
> 	gboolean (* all_selected)	        (FMDirectoryView *view);
304a318,320
> void                fm_directory_view_unselect_all                     (FMDirectoryView  *view);
> void                fm_directory_view_invert_selection                 (FMDirectoryView  *view);
> gboolean            fm_directory_view_all_selected                     (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.207
diff -r1.207 fm-icon-view.c
1472a1473,1505
> fm_icon_view_unselect_all (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_unselect_all (icon_container);
> }
> 
> 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 gboolean
> fm_icon_view_all_selected (FMDirectoryView *view)
> {
> 	NautilusIconContainer *icon_container;
> 
> 	g_return_val_if_fail (FM_IS_ICON_VIEW (view), FALSE);
> 
> 	icon_container = get_icon_container (FM_ICON_VIEW (view));
>         return nautilus_icon_container_all_icons_selected (icon_container);
> }
> 
> static void
2287a2321,2323
> 	fm_directory_view_class->unselect_all = fm_icon_view_unselect_all;
> 	fm_directory_view_class->invert_selection = fm_icon_view_invert_selection;
> 	fm_directory_view_class->all_selected = fm_icon_view_all_selected;
Index: src/file-manager/fm-list-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-list-view.c,v
retrieving revision 1.137
diff -r1.137 fm-list-view.c
131a132,134
> static void                 fm_list_view_unselect_all                 (FMDirectoryView    *view);
> static void                 fm_list_view_invert_selection             (FMDirectoryView    *view);
> static gboolean             fm_list_view_all_selected                 (FMDirectoryView    *view);
222a226,228
> 	fm_directory_view_class->unselect_all = fm_list_view_unselect_all;
> 	fm_directory_view_class->invert_selection = fm_list_view_invert_selection;
> 	fm_directory_view_class->all_selected = fm_list_view_all_selected;	
1812a1819,1878
> }
> 
> /* unselect all of the items in the view */
> static void
> fm_list_view_unselect_all (FMDirectoryView *view)
> {
> 	EelCList *clist;
> 	g_return_if_fail (FM_IS_LIST_VIEW (view));
> 	
>         clist = EEL_CLIST (get_list (FM_LIST_VIEW (view)));
>         eel_clist_unselect_all (clist);
> }
> 
> /* invert the selection of the items in the view */
> static void
> fm_list_view_invert_selection (FMDirectoryView *view)
> {
> 	EelCList *clist;
> 	GList *selection;
> 	GList *element;
> 	int row;
> 	g_return_if_fail (FM_IS_LIST_VIEW (view));
> 	
>         clist = EEL_CLIST (get_list (FM_LIST_VIEW (view)));
>        
> 	selection = g_list_copy (clist->selection);
> 
> 	for( row=0; row < clist->rows; row++ ) {
> 		element = g_list_find (selection, GINT_TO_POINTER (row) );		
> 		if( element ) {
> 			eel_clist_unselect_row (EEL_CLIST (clist), row, 0);
> 		} else {
> 			eel_clist_select_row (EEL_CLIST (clist), row, 0);
> 		}			
> 	}
> 	g_list_free (selection);
> }
> 
> /* return TRUE if all items in the view are selected */
> static gboolean
> fm_list_view_all_selected (FMDirectoryView *view)
> {
> 	EelCList *clist;
> 	GList *selection;
> 	GList *element;
> 	int row;
> 	g_return_val_if_fail (FM_IS_LIST_VIEW (view), FALSE);
> 	
>         clist = EEL_CLIST (get_list (FM_LIST_VIEW (view)));
> 	selection = g_list_copy (clist->selection);
> 
> 	for( row=0; row < clist->rows; row++ ) {
> 		element = g_list_find (selection, GINT_TO_POINTER (row) );		
> 		if( !element ) {
> 			g_list_free (selection);
> 			return FALSE;
> 		}
> 	}
> 	g_list_free (selection);
> 	return TRUE;
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.32
diff -r1.32 nautilus-directory-view-ui.xml
53a54,59
> 	<cmd name="Unselect All"
>          _label="Unselect All Files"
> 	 _tip="Unselect all items in this window"/>
> 	<cmd name="Invert Selection"
>          _label="_Invert Selection"
> 	 _tip="Invert the selection in this window"/>
163a170,177
> 		<menuitem name="Unselect All"
> 			  _label="_Unselect All Files" 
> 			  accel="*Control*s"
> 			  verb="Unselect All"/>
> 		<menuitem name="Invert Selection"
> 			  _label="_Invert the selection" 
> 			  accel="*Control*i"
> 			  verb="Invert Selection"/>


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