[nautilus-actions] Do not sort profiles



commit dcb1a93a966751266bca5227c0e0deabd7fa7641
Author: Pierre Wieser <pwieser trychlos org>
Date:   Tue Oct 13 21:39:31 2009 +0200

    Do not sort profiles
    
    Define a SELECTED_ROW property to only enable new action and new menu when on an action or a menu.

 ChangeLog                     |   10 ++++++++++
 src/nact/nact-main-menubar.c  |    6 ++++++
 src/nact/nact-main-tab.h      |    1 +
 src/nact/nact-main-window.c   |   34 +++++++++++++++++++++++++++++++---
 src/nact/nact-tree-model.c    |    8 ++++++--
 src/runtime/na-iio-provider.c |    2 +-
 6 files changed, 55 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c9351cb..cefd9d6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,15 @@
 	* src/nact/nact-iactions-list.c (on_tab_updatable_item_updated):
 	Recursively update the display of parents of the updated item.
 
+	* src/nact/nact-main-menubar.c (on_update_sensitivities):
+	Only enable new menu and new action when on an action or a menu.
+
+	* src/nact/nact-main-tab.h:
+	* src/nact/nact-main-window.c: New SELECTED_ROW property.
+
+	* src/nact/nact-tree-model.c (sort_actions_list):
+	Do not sort profiles.
+
 	* src/runtime/na-gconf-provider-keys.h:
 	OBJECT_ITEM_TYPE_ENTRY: new key which defines the type of the entry.
 	MENU_ITEMS_ENTRY: renamed to OBJECT_ITEM_LIST_ENTRY.
@@ -23,6 +32,7 @@
 
 	* src/runtime/na-iio-provider.c (build_hierarchy):
 	Use na_object_item_get_items_string_list.
+	(sort_tree): Do not sort profiles.
 
 	* src/runtime/na-object-item-fn.h:
 	* src/runtime/na-object-item-priv.h:
diff --git a/src/nact/nact-main-menubar.c b/src/nact/nact-main-menubar.c
index 87f6328..ab9a33b 100644
--- a/src/nact/nact-main-menubar.c
+++ b/src/nact/nact-main-menubar.c
@@ -473,6 +473,7 @@ on_update_sensitivities( NactMainWindow *window, gpointer user_data )
 	MenubarIndicatorsStruct *mis;
 	NAObject *item;
 	NAObject *profile;
+	NAObject *selected_row;
 	gboolean has_modified;
 	gint count_list;
 	gint count_selected;
@@ -483,6 +484,7 @@ on_update_sensitivities( NactMainWindow *window, gpointer user_data )
 	gboolean duplicate_enabled;
 	gboolean delete_enabled;
 	gboolean clipboard_is_empty;
+	gboolean new_item_enabled;
 
 	g_debug( "%s: window=%p", thisfn, ( void * ) window );
 	g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
@@ -493,6 +495,7 @@ on_update_sensitivities( NactMainWindow *window, gpointer user_data )
 			G_OBJECT( window ),
 			TAB_UPDATABLE_PROP_EDITED_ACTION, &item,
 			TAB_UPDATABLE_PROP_EDITED_PROFILE, &profile,
+			TAB_UPDATABLE_PROP_SELECTED_ROW, &selected_row,
 			NULL );
 	g_return_if_fail( !item || NA_IS_OBJECT_ITEM( item ));
 	g_return_if_fail( !profile || NA_IS_OBJECT_PROFILE( profile ));
@@ -547,6 +550,9 @@ on_update_sensitivities( NactMainWindow *window, gpointer user_data )
 
 	/* new menu always enabled */
 	/* new action always enabled */
+	new_item_enabled = ( selected_row == NULL || NA_IS_OBJECT_ITEM( selected_row ));
+	enable_item( window, "NewMenuItem", new_item_enabled );
+	enable_item( window, "NewActionItem", new_item_enabled );
 	/* new profile enabled if selection is relative to only one action */
 	enable_item( window, "NewProfileItem", item != NULL && !NA_IS_OBJECT_MENU( item ));
 	/* save enabled if at least one item has been modified */
diff --git a/src/nact/nact-main-tab.h b/src/nact/nact-main-tab.h
index 713e752..5a0d7e5 100644
--- a/src/nact/nact-main-tab.h
+++ b/src/nact/nact-main-tab.h
@@ -43,6 +43,7 @@
  */
 #define TAB_UPDATABLE_PROP_EDITED_ACTION				"nact-tab-updatable-edited-action"
 #define TAB_UPDATABLE_PROP_EDITED_PROFILE				"nact-tab-updatable-edited-profile"
+#define TAB_UPDATABLE_PROP_SELECTED_ROW					"nact-tab-updatable-selected-row"
 
 /* signals
  */
diff --git a/src/nact/nact-main-window.c b/src/nact/nact-main-window.c
index ad759b8..de9384c 100644
--- a/src/nact/nact-main-window.c
+++ b/src/nact/nact-main-window.c
@@ -87,11 +87,19 @@ struct NactMainWindowPrivate {
 	 * Conditions and Advanced ; it may be different of the row being
 	 * currently selected.
 	 *
-	 * Can be null if @edited_item is a menu or an invalid action.
+	 * Can be null if @edited_item is a menu, or an action with more
+	 * than one profile and action is selected, or an action without
+	 * any profile.
 	 */
 	NAObjectProfile *edited_profile;
 
 	/**
+	 * Currently selected row.
+	 * May be null if list is empty or selection is multiple.
+	 */
+	NAObjectId      *selected_row;
+
+	/**
 	 * The convenience clipboard object.
 	 */
 	NactClipboard   *clipboard;
@@ -101,7 +109,8 @@ struct NactMainWindowPrivate {
  */
 enum {
 	PROP_EDITED_ITEM = 1,
-	PROP_EDITED_PROFILE
+	PROP_EDITED_PROFILE,
+	PROP_SELECTED_ROW
 };
 
 /* signals
@@ -290,6 +299,13 @@ class_init( NactMainWindowClass *klass )
 			G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
 	g_object_class_install_property( object_class, PROP_EDITED_PROFILE, spec );
 
+	spec = g_param_spec_pointer(
+			TAB_UPDATABLE_PROP_SELECTED_ROW,
+			"Selected NAObjectId",
+			"A pointer to the currently selected row",
+			G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
+	g_object_class_install_property( object_class, PROP_SELECTED_ROW, spec );
+
 	klass->private = g_new0( NactMainWindowClassPrivate, 1 );
 
 	base_class = BASE_WINDOW_CLASS( klass );
@@ -512,6 +528,10 @@ instance_get_property( GObject *object, guint property_id, GValue *value, GParam
 				g_value_set_pointer( value, self->private->edited_profile );
 				break;
 
+			case PROP_SELECTED_ROW	:
+				g_value_set_pointer( value, self->private->selected_row );
+				break;
+
 			default:
 				G_OBJECT_WARN_INVALID_PROPERTY_ID( object, property_id, spec );
 				break;
@@ -538,6 +558,10 @@ instance_set_property( GObject *object, guint property_id, const GValue *value,
 				self->private->edited_profile = g_value_get_pointer( value );
 				break;
 
+			case PROP_SELECTED_ROW:
+				self->private->selected_row = g_value_get_pointer( value );
+				break;
+
 			default:
 				G_OBJECT_WARN_INVALID_PROPERTY_ID( object, property_id, spec );
 				break;
@@ -639,7 +663,7 @@ nact_main_window_action_exists( const NactMainWindow *window, const gchar *uuid
 
 	if( !window->private->dispose_has_run ){
 
-		/* leave here this dead code, if case I change of opinion later */
+		/* leave here this dead code, in case I change of opinion later */
 		if( FALSE ){
 			application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
 			pivot = nact_application_get_pivot( application );
@@ -975,7 +999,10 @@ on_iactions_list_selection_changed( NactIActionsList *instance, GSList *selected
 	}
 
 	if( count == 1 ){
+		g_return_if_fail( NA_IS_OBJECT_ID( selected_items->data ));
 		object = NA_OBJECT( selected_items->data );
+		window->private->selected_row = NA_OBJECT_ID( object );
+
 		if( NA_IS_OBJECT_ITEM( object )){
 			window->private->edited_item = NA_OBJECT_ITEM( object );
 			set_current_object_item( window, selected_items );
@@ -987,6 +1014,7 @@ on_iactions_list_selection_changed( NactIActionsList *instance, GSList *selected
 		}
 
 	} else {
+		window->private->selected_row = NULL;
 		window->private->edited_item = NULL;
 		set_current_object_item( window, selected_items );
 	}
diff --git a/src/nact/nact-tree-model.c b/src/nact/nact-tree-model.c
index 1eaf9fe..10407b2 100644
--- a/src/nact/nact-tree-model.c
+++ b/src/nact/nact-tree-model.c
@@ -1962,11 +1962,15 @@ sort_actions_list( GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer
 	gtk_tree_model_get( model, a, IACTIONS_LIST_NAOBJECT_COLUMN, &obj_a, -1 );
 	gtk_tree_model_get( model, b, IACTIONS_LIST_NAOBJECT_COLUMN, &obj_b, -1 );
 
-	ret = na_pivot_sort_alpha_asc( obj_a, obj_b );
-
 	g_object_unref( obj_b );
 	g_object_unref( obj_a );
 
+	if( NA_IS_OBJECT_PROFILE( obj_a )){
+		ret = 0;
+	} else {
+		ret = na_pivot_sort_alpha_asc( obj_a, obj_b );
+	}
+
 	/*g_debug( "%s: ret=%d", thisfn, ret );*/
 	return( ret );
 }
diff --git a/src/runtime/na-iio-provider.c b/src/runtime/na-iio-provider.c
index 9571d62..87e78bf 100644
--- a/src/runtime/na-iio-provider.c
+++ b/src/runtime/na-iio-provider.c
@@ -490,7 +490,7 @@ sort_tree( const NAPivot *pivot, GList *tree, GCompareFunc fn )
 	/* recursively sort each level of the tree
 	 */
 	for( it = sorted ; it ; it = it->next ){
-		if( NA_IS_OBJECT_ITEM( it->data )){
+		if( NA_IS_OBJECT_MENU( it->data )){
 			items = na_object_get_items_list( it->data );
 			items = sort_tree( pivot, items, fn );
 			na_object_set_items_list( it->data, items );



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