[nautilus-actions] Make the menu exportables



commit e584c46c6c51d5735d9e60d78724c701baaf8e5e
Author: Pierre Wieser <pwieser trychlos org>
Date:   Thu Feb 25 23:06:48 2010 +0100

    Make the menu exportables

 ChangeLog                       |    9 +++++
 src/nact/nact-iactions-list.c   |   30 ++++++++--------
 src/nact/nact-tree-model-priv.h |    2 +-
 src/nact/nact-tree-model.c      |   73 +++++++++++++++++++--------------------
 src/nact/nact-tree-model.h      |    2 +-
 5 files changed, 62 insertions(+), 54 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e4c90f7..0e46404 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2009-02-25 Pierre Wieser <pwieser trychlos org>
 
+	Make the menus exportable.
+
+	* src/nact/nact-iactions-list.c:
+	* src/nact/nact-tree-model-priv.h:
+	* src/nact/nact-tree-model.c:
+	* src/nact/nact-tree-model.h:
+	Change the 'only_actions' semantic by a 'are_profiles_displayed' one.
+	Profiles are actually stored, but not displayed.
+
 	* src/nact/nact-iactions-list.c
 	(nact_iactions_list_initial_load_toplevel):
 	The title of the label column is no more localizable.
diff --git a/src/nact/nact-iactions-list.c b/src/nact/nact-iactions-list.c
index c12bbd1..dfce198 100644
--- a/src/nact/nact-iactions-list.c
+++ b/src/nact/nact-iactions-list.c
@@ -81,6 +81,7 @@ static void     interface_base_finalize( NactIActionsListInterface *klass );
 static void     free_items_callback( NactIActionsList *instance, GList *items );
 static void     free_column_edited_callback( NactIActionsList *instance, NAObject *object, gchar *text, gint column );
 
+static gboolean are_profiles_displayed( NactIActionsList *instance, IActionsListInstanceData *ialid );
 static void     display_label( GtkTreeViewColumn *column, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter, NactIActionsList *instance );
 static gboolean filter_selection( GtkTreeSelection *selection, GtkTreeModel *model, GtkTreePath *path, gboolean path_currently_selected, NactIActionsList *instance );
 static gboolean filter_selection_is_homogeneous( GtkTreeSelection *selection, NAObject *object );
@@ -90,7 +91,6 @@ static gboolean filter_selection_is_implicitely_selected( NAObject *object );
 static void     filter_selection_set_implicitely_selected_childs( NAObject *object, gboolean select );
 static gboolean have_dnd_mode( NactIActionsList *instance, IActionsListInstanceData *ialid );
 static gboolean have_filter_selection_mode( NactIActionsList *instance, IActionsListInstanceData *ialid );
-static gboolean have_only_actions( NactIActionsList *instance, IActionsListInstanceData *ialid );
 static void     inline_edition( NactIActionsList *instance );
 static gboolean is_iduplicable_proxy( NactIActionsList *instance, IActionsListInstanceData *ialid );
 static gboolean on_button_press_event( GtkWidget *widget, GdkEventButton *event, NactIActionsList *instance );
@@ -661,7 +661,7 @@ nact_iactions_list_fill( NactIActionsList *instance, GList *items )
 	static const gchar *thisfn = "nact_iactions_list_fill";
 	GtkTreeView *treeview;
 	NactTreeModel *model;
-	gboolean only_actions;
+	gboolean profiles_are_displayed;
 	IActionsListInstanceData *ialid;
 
 	g_debug( "%s: instance=%p, items=%p", thisfn, ( void * ) instance, ( void * ) items );
@@ -675,11 +675,11 @@ nact_iactions_list_fill( NactIActionsList *instance, GList *items )
 		nact_iactions_list_bis_clear_selection( instance, treeview );
 
 		ialid = nact_iactions_list_priv_get_instance_data( instance );
-		only_actions = have_only_actions( instance, ialid );
+		profiles_are_displayed = are_profiles_displayed( instance, ialid );
 
 		ialid->selection_changed_send_allowed = FALSE;
 
-		nact_tree_model_fill( model, items, only_actions );
+		nact_tree_model_fill( model, items, profiles_are_displayed );
 
 		g_list_free( ialid->modified_items );
 		ialid->modified_items = NULL;
@@ -695,7 +695,7 @@ nact_iactions_list_fill( NactIActionsList *instance, GList *items )
 		ialid->actions = 0;
 		ialid->profiles = 0;
 
-		if( !only_actions ){
+		if( profiles_are_displayed ){
 			na_object_item_count_items( items, &ialid->menus, &ialid->actions, &ialid->profiles, TRUE );
 			nact_iactions_list_priv_send_list_count_updated_signal( instance, ialid );
 		}
@@ -845,6 +845,16 @@ nact_iactions_list_set_management_mode( NactIActionsList *instance, gint mode )
 	}
 }
 
+static gboolean
+are_profiles_displayed( NactIActionsList *instance, IActionsListInstanceData *ialid )
+{
+	gboolean display;
+
+	display = ( ialid->management_mode == IACTIONS_LIST_MANAGEMENT_MODE_EDITION );
+
+	return( display );
+}
+
 /*
  * item modified: italic
  * item not saveable (invalid): red
@@ -1049,16 +1059,6 @@ have_filter_selection_mode( NactIActionsList *instance, IActionsListInstanceData
 	return( have_filter );
 }
 
-static gboolean
-have_only_actions( NactIActionsList *instance, IActionsListInstanceData *ialid )
-{
-	gboolean only_actions;
-
-	only_actions = ( ialid->management_mode == IACTIONS_LIST_MANAGEMENT_MODE_EXPORT );
-
-	return( only_actions );
-}
-
 /*
  * triggered by 'F2' key
  * only in edition mode
diff --git a/src/nact/nact-tree-model-priv.h b/src/nact/nact-tree-model-priv.h
index 727eb0b..9cac4d8 100644
--- a/src/nact/nact-tree-model-priv.h
+++ b/src/nact/nact-tree-model-priv.h
@@ -46,7 +46,7 @@ struct NactTreeModelPrivate {
 	BaseWindow    *window;
 	GtkTreeView   *treeview;
 	gboolean       have_dnd;
-	gboolean       only_actions;
+	gboolean       are_profiles_displayed;
 	NactClipboard *clipboard;
 	gboolean       drag_has_profiles;
 	gboolean       drag_highlight;		/* defined for on_drag_motion handler */
diff --git a/src/nact/nact-tree-model.c b/src/nact/nact-tree-model.c
index cb7549d..8530adf 100644
--- a/src/nact/nact-tree-model.c
+++ b/src/nact/nact-tree-model.c
@@ -570,8 +570,9 @@ nact_tree_model_dump( NactTreeModel *model )
  * @model: this #NactTreeModel instance.
  * @ŧreeview: the #GtkTreeView widget.
  * @items: this list of items, usually from #NAPivot, which will be used
- * to fill up the tree store.
- * @only_actions: whether to store only actions, or all items.
+ *  to fill up the tree store.
+ * @are_profiles_displayed: whether to show profiles (in edition mode),
+ *  or not (in export mode).
  *
  * Fill up the tree store with specified items.
  *
@@ -580,27 +581,31 @@ nact_tree_model_dump( NactTreeModel *model )
  * tree store, so that we are able to freely edit it.
  */
 void
-nact_tree_model_fill( NactTreeModel *model, GList *items, gboolean only_actions)
+nact_tree_model_fill( NactTreeModel *model, GList *items, gboolean are_profiles_displayed )
 {
 	static const gchar *thisfn = "nact_tree_model_fill";
 	GtkTreeStore *ts_model;
 	GList *it;
 	NAObject *duplicate;
 
-	g_debug( "%s: model=%p, items=%p (%d items), only_actions=%s",
-			thisfn, ( void * ) model, ( void * ) items, g_list_length( items ), only_actions ? "True":"False" );
 	g_return_if_fail( NACT_IS_TREE_MODEL( model ));
 
+	g_debug( "%s: model=%p, items=%p (%d items), are_profiles_displayed=%s",
+			thisfn,
+			( void * ) model,
+			( void * ) items, g_list_length( items ),
+			are_profiles_displayed ? "True":"False" );
+
 	if( !model->private->dispose_has_run ){
 
-		model->private->only_actions = only_actions;
+		model->private->are_profiles_displayed = are_profiles_displayed;
 		ts_model = GTK_TREE_STORE( gtk_tree_model_filter_get_model( GTK_TREE_MODEL_FILTER( model )));
 		gtk_tree_store_clear( ts_model );
 
 		for( it = items ; it ; it = it->next ){
 			duplicate = ( NAObject * ) na_object_duplicate( it->data );
-			fill_tree_store( ts_model, model->private->treeview, duplicate, only_actions, NULL );
-			g_object_unref( duplicate );
+			fill_tree_store( ts_model, model->private->treeview, duplicate, are_profiles_displayed, NULL );
+			na_object_unref( duplicate );
 		}
 	}
 }
@@ -906,7 +911,7 @@ dump_store( NactTreeModel *model, GtkTreePath *path, NAObject *object, ntmDumpSt
 
 static void
 fill_tree_store( GtkTreeStore *model, GtkTreeView *treeview,
-					NAObject *object, gboolean only_actions, GtkTreeIter *parent )
+					NAObject *object, gboolean are_profiles_displayed, GtkTreeIter *parent )
 {
 	static const gchar *thisfn = "nact_tree_model_fill_tree_store";
 	GList *subitems, *it;
@@ -916,41 +921,37 @@ fill_tree_store( GtkTreeStore *model, GtkTreeView *treeview,
 			( void * ) object, G_OBJECT_TYPE_NAME( object ), G_OBJECT( object )->ref_count );
 
 	if( NA_IS_OBJECT_MENU( object )){
-		if( !only_actions ){
-			append_item( model, treeview, parent, &iter, object );
-		}
+		append_item( model, treeview, parent, &iter, object );
 		subitems = na_object_get_items( object );
 		for( it = subitems ; it ; it = it->next ){
-			fill_tree_store( model, treeview, it->data, only_actions, only_actions ? NULL : &iter );
+			fill_tree_store( model, treeview, it->data, are_profiles_displayed, &iter );
 		}
 	}
 
 	if( NA_IS_OBJECT_ACTION( object )){
 		g_return_if_fail( na_object_get_items_count( object ) >= 1 );
 		append_item( model, treeview, parent, &iter, object );
-		if( only_actions ){
-			na_object_set_parent( object, NULL );
-		} else {
-			subitems = na_object_get_items( object );
-			for( it = subitems ; it ; it = it->next ){
-				fill_tree_store( model, treeview, it->data, only_actions, &iter );
-			}
+		subitems = na_object_get_items( object );
+		for( it = subitems ; it ; it = it->next ){
+			fill_tree_store( model, treeview, it->data, are_profiles_displayed, &iter );
 		}
 	}
 
 	if( NA_IS_OBJECT_PROFILE( object )){
-		g_assert( !only_actions );
 		append_item( model, treeview, parent, &iter, object );
 	}
 }
 
+/*
+ * only display profiles when we are in edition mode
+ */
 static gboolean
 filter_visible( GtkTreeModel *store, GtkTreeIter *iter, NactTreeModel *model )
 {
 	/*static const gchar *thisfn = "nact_tree_model_filter_visible";*/
 	NAObject *object;
 	NAObjectAction *action;
-	gboolean only_actions;
+	gboolean are_profiles_displayed;
 	gint count;
 
 	/*g_debug( "%s: model=%p, iter=%p, window=%p", thisfn, ( void * ) model, ( void * ) iter, ( void * ) window );*/
@@ -958,34 +959,32 @@ filter_visible( GtkTreeModel *store, GtkTreeIter *iter, NactTreeModel *model )
 	/* is a GtkTreeStore */
 
 	gtk_tree_model_get( store, iter, IACTIONS_LIST_NAOBJECT_COLUMN, &object, -1 );
+	g_object_unref( object );
 
 	if( object ){
 		/*na_object_dump( object );*/
 
 		if( NA_IS_OBJECT_ACTION( object )){
-			g_object_unref( object );
 			return( TRUE );
 		}
 
-		only_actions = NACT_TREE_MODEL( model )->private->only_actions;
+		if( NA_IS_OBJECT_MENU( object )){
+			return( TRUE );
+		}
 
-		if( !only_actions ){
+		are_profiles_displayed = NACT_TREE_MODEL( model )->private->are_profiles_displayed;
 
-			if( NA_IS_OBJECT_MENU( object )){
-				g_object_unref( object );
-				return( TRUE );
-			}
+		if( NA_IS_OBJECT_PROFILE( object )){
 
-			if( NA_IS_OBJECT_PROFILE( object )){
-				action = NA_OBJECT_ACTION( na_object_get_parent( object ));
-				g_object_unref( object );
-				count = na_object_get_items_count( action );
-				/*g_debug( "action=%p: count=%d", ( void * ) action, count );*/
-				/*return( TRUE );*/
-				return( count > 1 );
+			if( !are_profiles_displayed ){
+				return( FALSE );
 			}
 
-			g_assert_not_reached();
+			action = NA_OBJECT_ACTION( na_object_get_parent( object ));
+			count = na_object_get_items_count( action );
+			/*g_debug( "action=%p: count=%d", ( void * ) action, count );*/
+			/*return( TRUE );*/
+			return( count > 1 );
 		}
 	}
 
diff --git a/src/nact/nact-tree-model.h b/src/nact/nact-tree-model.h
index e20a13e..39edb44 100644
--- a/src/nact/nact-tree-model.h
+++ b/src/nact/nact-tree-model.h
@@ -98,7 +98,7 @@ void         nact_tree_model_dispose( NactTreeModel *model );
 void         nact_tree_model_display( NactTreeModel *model, NAObject *object );
 void         nact_tree_model_display_order_change( NactTreeModel *model, gint order_mode );
 void         nact_tree_model_dump( NactTreeModel *model );
-void         nact_tree_model_fill( NactTreeModel *model, GList *items, gboolean only_actions);
+void         nact_tree_model_fill( NactTreeModel *model, GList *items, gboolean are_profiles_displayed );
 GtkTreePath *nact_tree_model_insert( NactTreeModel *model, const NAObject *object, GtkTreePath *path, NAObject **parent );
 GtkTreePath *nact_tree_model_insert_into( NactTreeModel *model, const NAObject *object, GtkTreePath *path, NAObject **parent );
 void         nact_tree_model_iter( NactTreeModel *model, FnIterOnStore fn, gpointer user_data );



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