[nautilus-actions] Duplicate all tree store to a new pivot when saving



commit 8bf96129b165fa3da1f5de9910fd201cc405c796
Author: Pierre Wieser <pwieser trychlos org>
Date:   Mon Jun 28 05:34:41 2010 +0200

    Duplicate all tree store to a new pivot when saving

 ChangeLog                         |   12 +++++
 src/core/na-iduplicable.c         |    6 ++-
 src/core/na-object.c              |    8 +--
 src/core/na-pivot.c               |   28 ++++++++++-
 src/core/na-pivot.h               |    1 +
 src/nact/nact-main-menubar-file.c |   95 +++++++++++++++++--------------------
 6 files changed, 91 insertions(+), 59 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 44e8eeb..8a8f6f1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2010-06-28 Pierre Wieser <pwieser trychlos org>
+
+	* src/core/na-iduplicable.c (na_iduplicable_check_status):
+	* src/core/na-object.c (na_object_object_unref):
+	Review debug messages.
+
+	* src/core/na-pivot.c:
+	* src/core/na-pivot.h (na_pivot_set_new_items): New function.
+
+	* src/nact/nact-main-menubar-file.c (save_item):
+	Duplicate all current tree store to a new pivot.
+
 2010-06-23 Pierre Wieser <pwieser trychlos org>
 
 	* src/nact/nact-ienvironment-tab.c (on_tab_updatable_selection_changed):
diff --git a/src/core/na-iduplicable.c b/src/core/na-iduplicable.c
index f186c00..cf2212b 100644
--- a/src/core/na-iduplicable.c
+++ b/src/core/na-iduplicable.c
@@ -307,11 +307,12 @@ na_iduplicable_check_status( const NAIDuplicable *object )
 	gboolean was_modified, was_valid;
 	gboolean changed;
 
-	g_debug( "%s: object=%p (%s)", thisfn, ( void * ) object, G_OBJECT_TYPE_NAME( object ));
 	g_return_if_fail( NA_IS_IDUPLICABLE( object ));
 
 	if( st_initialized && !st_finalized ){
 
+		g_debug( "%s: object=%p (%s)", thisfn, ( void * ) object, G_OBJECT_TYPE_NAME( object ));
+
 		str = get_duplicable_str( object );
 
 		was_modified = str->modified;
@@ -319,7 +320,10 @@ na_iduplicable_check_status( const NAIDuplicable *object )
 		changed = FALSE;
 
 		if( str->origin ){
+			g_debug( "%s: origin=%p (%s)", thisfn, ( void * ) str->origin, G_OBJECT_TYPE_NAME( str->origin ));
+			g_return_if_fail( NA_IS_IDUPLICABLE( str->origin ));
 			str->modified = !v_are_equal( str->origin, object );
+
 		} else {
 			str->modified = TRUE;
 		}
diff --git a/src/core/na-object.c b/src/core/na-object.c
index 01b8882..96d8e03 100644
--- a/src/core/na-object.c
+++ b/src/core/na-object.c
@@ -717,11 +717,10 @@ na_object_object_unref( NAObject *object )
 
 	if( !object->private->dispose_has_run ){
 
-		g_debug( "na_object_object_unref:enter: object=%p (%s, ref_count=%d)",
+		g_debug( "na_object_object_unref: object=%p (%s, ref_count=%d)",
 				( void * ) object, G_OBJECT_TYPE_NAME( object ), G_OBJECT( object )->ref_count );
 
 		if( NA_IS_OBJECT_ITEM( object )){
-
 #if 0
 			while( TRUE ){
 				children = na_object_get_items( object );
@@ -732,7 +731,6 @@ na_object_object_unref( NAObject *object )
 				}
 			}
 #endif
-
 			children = na_object_get_items( object );
 			for( ic = children ; ic ; ic = icnext ){
 				icnext = ic->next;
@@ -740,8 +738,8 @@ na_object_object_unref( NAObject *object )
 			}
 		}
 
-		g_debug( "na_object_object_unref:about_to_unref: object=%p (%s, ref_count=%d)",
-				( void * ) object, G_OBJECT_TYPE_NAME( object ), G_OBJECT( object )->ref_count );
+		/*g_debug( "na_object_object_unref:about_to_unref: object=%p (%s, ref_count=%d)",
+				( void * ) object, G_OBJECT_TYPE_NAME( object ), G_OBJECT( object )->ref_count );*/
 
 		g_object_unref( object );
 	}
diff --git a/src/core/na-pivot.c b/src/core/na-pivot.c
index 894a7ef..34a2603 100644
--- a/src/core/na-pivot.c
+++ b/src/core/na-pivot.c
@@ -542,11 +542,12 @@ na_pivot_load_items( NAPivot *pivot )
 	static const gchar *thisfn = "na_pivot_load_items";
 	GSList *messages, *im;
 
-	g_debug( "%s: pivot=%p", thisfn, ( void * ) pivot );
 	g_return_if_fail( NA_IS_PIVOT( pivot ));
 
 	if( !pivot->private->dispose_has_run ){
 
+		g_debug( "%s: pivot=%p", thisfn, ( void * ) pivot );
+
 		na_object_unref_items( pivot->private->tree );
 
 		messages = NULL;
@@ -562,6 +563,31 @@ na_pivot_load_items( NAPivot *pivot )
 }
 
 /**
+ * na_pivot_set_new_items:
+ * @pivot: this #NAPivot instance.
+ * @tree: the new tree of items.
+ *
+ * Replace the current list with this one.
+ */
+void
+na_pivot_set_new_items( NAPivot *pivot, GList *items )
+{
+	static const gchar *thisfn = "na_pivot_set_new_items";
+
+	g_return_if_fail( NA_IS_PIVOT( pivot ));
+
+	if( !pivot->private->dispose_has_run ){
+
+		g_debug( "%s: pivot=%p, items=%p (count=%d)",
+				thisfn, ( void * ) pivot, ( void * ) items, items ? g_list_length( items ) : 0 );
+
+		na_object_unref_items( pivot->private->tree );
+
+		pivot->private->tree = items;
+	}
+}
+
+/**
  * na_pivot_item_changed_handler:
  * @provider: the #NAIIOProvider which has emitted the signal.
  * @id: the id of the changed #NAObjectItem-derived object.
diff --git a/src/core/na-pivot.h b/src/core/na-pivot.h
index 791394a..1f7b310 100644
--- a/src/core/na-pivot.h
+++ b/src/core/na-pivot.h
@@ -136,6 +136,7 @@ void          na_pivot_free_providers( GList *providers );
 NAObjectItem *na_pivot_get_item( const NAPivot *pivot, const gchar *id );
 GList        *na_pivot_get_items( const NAPivot *pivot );
 void          na_pivot_load_items( NAPivot *pivot );
+void          na_pivot_set_new_items( NAPivot *pivot, GList *tree );
 
 void          na_pivot_item_changed_handler( NAIIOProvider *provider, const gchar *id, NAPivot *pivot  );
 
diff --git a/src/nact/nact-main-menubar-file.c b/src/nact/nact-main-menubar-file.c
index 42245ac..ea833a2 100644
--- a/src/nact/nact-main-menubar-file.c
+++ b/src/nact/nact-main-menubar-file.c
@@ -255,10 +255,13 @@ nact_main_menubar_file_save_items( NactMainWindow *window )
 	NAUpdater *updater;
 	MenubarIndicatorsStruct *mis;
 	gchar *label;
+	GList *new_pivot;
+	NAObjectItem *duplicate;
 
-	g_debug( "%s: window=%p", thisfn, ( void * ) window );
 	g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
 
+	g_debug( "%s: window=%p", thisfn, ( void * ) window );
+
 	/* remove deleted items
 	 * so that new actions with same id do not risk to be deleted later
 	 */
@@ -270,8 +273,8 @@ nact_main_menubar_file_save_items( NactMainWindow *window )
 	application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
 	updater = nact_application_get_updater( application );
 	items = nact_iactions_list_bis_get_items( NACT_IACTIONS_LIST( window ));
-	na_pivot_write_level_zero( NA_PIVOT( updater ), items );
 
+	na_pivot_write_level_zero( NA_PIVOT( updater ), items );
 	mis = ( MenubarIndicatorsStruct * ) g_object_get_data( G_OBJECT( window ), MENUBAR_PROP_INDICATORS );
 	mis->level_zero_order_changed = FALSE;
 
@@ -280,6 +283,8 @@ nact_main_menubar_file_save_items( NactMainWindow *window )
 	 * above all, it is less costly to check the status here, than to check
 	 * recursively each and every modified item
 	 */
+	new_pivot = NULL;
+
 	for( it = items ; it ; it = it->next ){
 		label = na_object_get_label( it->data );
 		g_debug( "%s saving item %s %p (%s), modified=%s",
@@ -287,10 +292,17 @@ nact_main_menubar_file_save_items( NactMainWindow *window )
 				G_OBJECT_TYPE_NAME( it->data ),
 				( void * ) it->data, label,
 				na_object_is_modified( it->data ) ? "True":"False" );
+		g_free( label );
+
 		save_item( window, updater, NA_OBJECT_ITEM( it->data ));
+
+		duplicate = NA_OBJECT_ITEM( na_object_duplicate( it->data ));
+		na_object_reset_origin( it->data, duplicate );
 		na_object_check_status( it->data );
-		g_free( label );
+		new_pivot = g_list_prepend( new_pivot, duplicate );
 	}
+
+	na_pivot_set_new_items( NA_PIVOT( updater ), g_list_reverse( new_pivot ));
 	g_list_free( items );
 
 	/* get ride of notification messages of IOProviders
@@ -299,35 +311,38 @@ nact_main_menubar_file_save_items( NactMainWindow *window )
 }
 
 /*
- * iterates here on each and every row stored in the tree
- * - do not deal with profiles as they are directly managed by their
- *   action parent
- * - do not deal with not modified, or not valid, items, but allow
- *   for save their subitems
+ * iterates here on each and every NAObjectItem row stored in the tree
+ *
+ * do not deal with profiles as they are directly managed by the action
+ * they are attached to
+ *
+ * level zero order has already been saved from tree store order, so that
+ * we actually do not care of the exact order of level zero NAPivot items
+ *
+ * saving means non-recursively save modified NAObjectItem, simultaneously
+ * reproducing the new item in NAPivot
+ *  +- A
+ *  |  +- B
+ *  |  |  +- C
+ *  |  |  |  +- D
+ *  |  |  |  +- E
+ *  |  |  +- F
+ *  |  +- G
+ *  +- H
+ *  |  +- ...
+ *  save order: A-B-C-D-E-F-G-H (first parent, then children)
  */
 static void
 save_item( NactMainWindow *window, NAUpdater *updater, NAObjectItem *item )
 {
-	static const gchar *thisfn = "nact_main_menubar_file_save_item";
-	NAObjectItem *origin;
-	NAObjectItem *dup_pivot;
-	GList *subitems, *it;
-	NAObjectItem *parent;
-	gint pos;
 	NAIOProvider *provider_before;
 	NAIOProvider *provider_after;
+	GList *subitems, *it;
 
 	g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
 	g_return_if_fail( NA_IS_UPDATER( updater ));
 	g_return_if_fail( NA_IS_OBJECT_ITEM( item ));
 
-	if( NA_IS_OBJECT_MENU( item )){
-		subitems = na_object_get_items( item );
-		for( it = subitems ; it ; it = it->next ){
-			save_item( window, updater, NA_OBJECT_ITEM( it->data ));
-		}
-	}
-
 	provider_before = na_object_get_provider( item );
 
 	if( na_object_is_modified( item ) &&
@@ -337,37 +352,6 @@ save_item( NactMainWindow *window, NAUpdater *updater, NAObjectItem *item )
 				na_object_reset_last_allocated( item );
 			}
 
-			/* now that the NAObjectItem has been (non recursively) saved,
-			 * we have to update NAPivot so that the next na_object_check_status()
-			 * will show us that this treeview item is no more modified
-			 */
-			origin = ( NAObjectItem * ) na_object_get_origin( item );
-			g_debug( "%s: origin=%p", thisfn, ( void * ) origin );
-
-			parent = NULL;
-			pos = -1;
-
-			if( origin ){
-				parent = na_object_get_parent( origin );
-				if( parent ){
-					pos = na_object_get_position( parent, origin );
-				}
-				na_updater_remove_item( updater, NA_OBJECT( origin ));
-			}
-
-			dup_pivot = NA_OBJECT_ITEM( na_object_duplicate( item ));
-			na_object_reset_origin( item, dup_pivot );
-			na_object_set_parent( dup_pivot, parent );
-			if( parent ){
-				if( pos == -1 ){
-					na_object_append_item( parent, dup_pivot );
-				} else {
-					na_object_insert_at( parent, dup_pivot, pos );
-				}
-			} else {
-				na_updater_append_item( updater, dup_pivot );
-			}
-
 			nact_iactions_list_bis_remove_modified( NACT_IACTIONS_LIST( window ), item );
 
 			provider_after = na_object_get_provider( item );
@@ -375,6 +359,13 @@ save_item( NactMainWindow *window, NAUpdater *updater, NAObjectItem *item )
 				g_signal_emit_by_name( window, TAB_UPDATABLE_SIGNAL_PROVIDER_CHANGED, item );
 			}
 	}
+
+	if( NA_IS_OBJECT_MENU( item )){
+		subitems = na_object_get_items( item );
+		for( it = subitems ; it ; it = it->next ){
+			save_item( window, updater, NA_OBJECT_ITEM( it->data ));
+		}
+	}
 }
 
 /**



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