[nautilus-actions] Fix duplicate action sensitivity



commit e350360d4ac1615c44a8154a9597642a372b8912
Author: Pierre Wieser <pwieser trychlos org>
Date:   Fri Feb 18 09:13:46 2011 +0100

    Fix duplicate action sensitivity

 src/nact/nact-menubar-edit.c |   17 ++++++++++-----
 src/nact/nact-menubar-priv.h |    3 +-
 src/nact/nact-menubar.c      |   43 +++++++++++++++++++----------------------
 3 files changed, 33 insertions(+), 30 deletions(-)
---
diff --git a/src/nact/nact-menubar-edit.c b/src/nact/nact-menubar-edit.c
index b481588..854fee3 100644
--- a/src/nact/nact-menubar-edit.c
+++ b/src/nact/nact-menubar-edit.c
@@ -56,6 +56,11 @@ static void    update_clipboard_counters( BaseWindow *window );
  * @bar: this #NactMenubar object.
  *
  * Update sensitivity of items of the Edit menu.
+ *
+ * Each action (cut, copy, delete, etc.) takes itself care of whether it
+ * can safely apply to all the selection or not. The action can at least
+ * assume that at least one item will be a valid candidate (this is the
+ * Menubar rule).
  */
 void
 nact_menubar_edit_on_update_sensitivities( const NactMenubar *bar )
@@ -74,12 +79,14 @@ nact_menubar_edit_on_update_sensitivities( const NactMenubar *bar )
 	is_clipboard_empty = ( bar->private->clipboard_menus + bar->private->clipboard_actions + bar->private->clipboard_profiles == 0 );
 
 	/* cut requires a non-empty selection
-	 * and that the selection is writable
+	 * and that the selection is writable (can be modified, i.e. is not read-only)
 	 * and that all parents are writable (as implies a delete operation)
 	 */
-	cut_enabled = bar->private->treeview_has_focus || bar->private->popup_handler;
-	cut_enabled &= bar->private->count_selected > 0;
-	cut_enabled &= bar->private->are_parents_writable;
+	duplicate_enabled = bar->private->treeview_has_focus || bar->private->popup_handler;
+	duplicate_enabled &= bar->private->count_selected > 0;
+	duplicate_enabled &= bar->private->are_parents_writable;
+	cut_enabled = duplicate_enabled;
+	cut_enabled &= bar->private->are_items_writable;
 	nact_menubar_enable_item( bar, "CutItem", cut_enabled );
 
 	/* copy only requires a non-empty selection */
@@ -153,9 +160,7 @@ nact_menubar_edit_on_update_sensitivities( const NactMenubar *bar )
 	/* duplicate items will be duplicated besides each one
 	 * selection must be non-empty
 	 * each parent must be writable
-	 * -> so this is the same than cut
 	 */
-	duplicate_enabled = cut_enabled;
 	nact_menubar_enable_item( bar, "DuplicateItem", duplicate_enabled );
 
 	/* delete is same that cut
diff --git a/src/nact/nact-menubar-priv.h b/src/nact/nact-menubar-priv.h
index e49d021..89d0686 100644
--- a/src/nact/nact-menubar-priv.h
+++ b/src/nact/nact-menubar-priv.h
@@ -71,7 +71,8 @@ struct _NactMenubarPrivate {
 	gboolean         is_parent_writable;		/* new menu/new action/paste menu or action */
 	gboolean         enable_new_profile;		/* new profile/paste a profile */
 	gboolean         is_action_writable;
-	gboolean         are_parents_writable;		/* cut/delete */
+	gboolean         are_parents_writable;		/* duplicate */
+	gboolean         are_items_writable;		/* cut/delete */
 
 	/* set when the count of modified or deleted NAObjectItem changes
 	 * or when the lever zero is changed
diff --git a/src/nact/nact-menubar.c b/src/nact/nact-menubar.c
index 59dd682..7240f3c 100644
--- a/src/nact/nact-menubar.c
+++ b/src/nact/nact-menubar.c
@@ -710,6 +710,12 @@ on_tree_view_modified_status_changed( BaseWindow *window, gboolean is_modified,
  *
  * It happens that this function is triggered after all tabs have already
  * dealt with the MAIN_SIGNAL_SELECTION_CHANGED signal
+ *
+ * We are trying to precompute here all indicators which are needed to
+ * make actions sensitive. As a multiple selection may have multiple
+ * sort of indicators, we assure here that at least one item will be a
+ * valid candidate to the target action, the action taking care itself
+ * of applying to valid candidates, and rejecting the others.
  */
 static void
 on_tree_view_selection_changed( BaseWindow *window, GList *selected, gpointer user_data )
@@ -717,6 +723,7 @@ on_tree_view_selection_changed( BaseWindow *window, GList *selected, gpointer us
 	static const gchar *thisfn = "nact_menubar_on_tree_view_selection_changed";
 	NAObject *first;
 	NAObject *selected_action;
+	NAObject *row, *parent;
 	GList *is;
 
 	BAR_WINDOW_VOID( window );
@@ -800,36 +807,26 @@ on_tree_view_selection_changed( BaseWindow *window, GList *selected, gpointer us
 	 * if some selection is at level zero, then it must be writable
 	 * (Edit: Cut/Delete)
 	 */
-	bar->private->are_parents_writable = TRUE;
 	if( selected ){
+		bar->private->are_parents_writable = TRUE;
+		bar->private->are_items_writable = TRUE;
 		for( is = selected ; is ; is = is->next ){
-			first = ( NAObject * ) is->data;
-			if( NA_IS_OBJECT_PROFILE( is->data )){
-				first = NA_OBJECT( na_object_get_parent( is->data ));
+			row = ( NAObject * ) is->data;
+			if( NA_IS_OBJECT_PROFILE( row )){
+				row = NA_OBJECT( na_object_get_parent( row ));
 			}
-			gchar *label = na_object_get_label( first );
-			gboolean writable = na_object_is_finally_writable( first, NULL );
+			gchar *label = na_object_get_label( row );
+			gboolean writable = na_object_is_finally_writable( row, NULL );
 			g_debug( "%s: label=%s, writable=%s", thisfn, label, writable ? "True":"False" );
 			g_free( label );
-			if( !writable ){
-				bar->private->are_parents_writable = FALSE;
-				break;
-			}
-			if( NA_IS_OBJECT_ITEM( is->data )){
-				first = ( NAObject * ) na_object_get_parent( is->data );
-				if( first ){
-					if( !na_object_is_finally_writable( first, NULL )){
-						bar->private->are_parents_writable = FALSE;
-						break;
-					}
-				} else if( !bar->private->is_level_zero_writable ){
-					bar->private->are_parents_writable = FALSE;
-					break;
-				}
+			bar->private->are_items_writable &= writable;
+			parent = ( NAObject * ) na_object_get_parent( row );
+			if( parent ){
+				bar->private->are_parents_writable &= na_object_is_finally_writable( parent, NULL );
+			} else {
+				bar->private->are_parents_writable &= bar->private->is_level_zero_writable;
 			}
 		}
-	} else {
-		bar->private->are_parents_writable = bar->private->is_level_zero_writable;
 	}
 
 	g_signal_emit_by_name( bar, MENUBAR_SIGNAL_UPDATE_SENSITIVITIES );



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