[nautilus-actions] Fix save mechanism, including NAPivot updates



commit 8133f20897a97019f0702a39eaceb2963e621450
Author: pierre <pierre vfedora10 virtuals pwi>
Date:   Mon Mar 1 18:31:10 2010 +0100

    Fix save mechanism, including NAPivot updates

 ChangeLog                    |    5 +++++
 TODO                         |    2 ++
 src/core/na-updater.c        |   25 ++++++++++++++++++++++++-
 src/core/na-updater.h        |    1 +
 src/nact/nact-main-menubar.c |   39 ++++++++++++++++++++++++++++++++++++++-
 5 files changed, 70 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 4d7eab9..94da997 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2009-03-01 Pierre Wieser <pwieser trychlos org>
 
+	* src/core/na-updater.c:
+	* src/core/na-updater.h (na_updater_append_item): New function.
+
+	* src/nact/nact-main-menubar.c (save_item): Fix save machinery.
+
 	* src/nact/nact-assistant-import.c
 	(check_for_existance): Directly use the main window.
 
diff --git a/TODO b/TODO
index 6395fbd..5974cfe 100644
--- a/TODO
+++ b/TODO
@@ -167,3 +167,5 @@
 - check adding/removing profile on desktop/gconf/xml import/export
 
 - shouldn't be able to copy an action into an action !
+
+- na_object_reset_last_allocated ??
diff --git a/src/core/na-updater.c b/src/core/na-updater.c
index 6033d31..9296b44 100644
--- a/src/core/na-updater.c
+++ b/src/core/na-updater.c
@@ -186,6 +186,29 @@ na_updater_new( void )
 }
 
 /**
+ * na_updater_append_item:
+ * @updater: this #NAUpdater object.
+ * @item: a #NAObjectItem-derived object to be appended to the tree.
+ *
+ * Append a new item at the end of the global tree.
+ */
+void
+na_updater_append_item( NAUpdater *updater, NAObjectItem *item )
+{
+	GList *tree;
+
+	g_return_if_fail( NA_IS_UPDATER( updater ));
+	g_return_if_fail( NA_IS_OBJECT_ITEM( item ));
+
+	if( !updater->private->dispose_has_run ){
+
+		g_object_get( G_OBJECT( updater ), NAPIVOT_PROP_TREE, &tree, NULL );
+		tree = g_list_append( tree, item );
+		g_object_set( G_OBJECT( updater ), NAPIVOT_PROP_TREE, tree, NULL );
+	}
+}
+
+/**
  * na_updater_insert_item:
  * @updater: this #NAUpdater object.
  * @item: a #NAObjectItem-derived object to be inserted in the tree.
@@ -217,7 +240,7 @@ na_updater_insert_item( NAUpdater *updater, NAObjectItem *item, const gchar *par
 
 		} else {
 			tree = g_list_append( tree, item );
-			g_object_set( G_OBJECT( updater ), NAPIVOT_PROP_TREE, &tree, NULL );
+			g_object_set( G_OBJECT( updater ), NAPIVOT_PROP_TREE, tree, NULL );
 		}
 	}
 }
diff --git a/src/core/na-updater.h b/src/core/na-updater.h
index 3a4eac8..0ae1348 100644
--- a/src/core/na-updater.h
+++ b/src/core/na-updater.h
@@ -73,6 +73,7 @@ NAUpdater *na_updater_new( void );
 
 /* update the tree in memory
  */
+void       na_updater_append_item( NAUpdater *updater, NAObjectItem *item );
 void       na_updater_insert_item( NAUpdater *updater, NAObjectItem *item, const gchar *parent_id, gint pos );
 void       na_updater_remove_item( NAUpdater *updater, NAObject *item );
 
diff --git a/src/nact/nact-main-menubar.c b/src/nact/nact-main-menubar.c
index 432b960..a6c6e1f 100644
--- a/src/nact/nact-main-menubar.c
+++ b/src/nact/nact-main-menubar.c
@@ -981,7 +981,6 @@ save_item( NactMainWindow *window, NAUpdater *updater, NAObjectItem *item )
 	NAObjectItem *dup_pivot;
 	GList *subitems, *it;
 	NAObjectItem *parent;
-	gchar *parent_id;
 	gint pos;
 	NAIOProvider *provider_before;
 	NAIOProvider *provider_after;
@@ -1006,9 +1005,17 @@ 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 );
 
+#if 0
+			/* if the item already existed,
+			 * then copy the treeview item to the pivot one
+			 */
 			if( origin ){
 				subitems = NULL;
 				if( NA_IS_OBJECT_ACTION( item )){
@@ -1021,6 +1028,10 @@ save_item( NactMainWindow *window, NAUpdater *updater, NAObjectItem *item )
 					na_object_unref_items( subitems );
 				}
 
+			/* this is a new item
+			 * get the actual parent and position from the treeview
+			 * and insert accordingly in the pivot tree
+			 */
 			} else {
 				dup_pivot = NA_OBJECT_ITEM( na_object_duplicate( item ));
 				na_object_reset_origin( item, dup_pivot );
@@ -1035,6 +1046,32 @@ save_item( NactMainWindow *window, NAUpdater *updater, NAObjectItem *item )
 
 				na_updater_insert_item( updater, dup_pivot, parent_id, pos );
 			}
+#endif
+
+			parent = NULL;
+			pos = -1;
+
+			if( origin ){
+				parent = na_object_get_parent( origin );
+				if( parent ){
+					pos = na_object_get_position( parent, origin );
+				}
+				g_object_unref( 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 );
+			}
+
 #if 0
 			parent = NULL;
 			pos = -1;



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