[nautilus-actions] Paste a profile from the clipboard



commit 8d2c3e94f049a01b86070d39fcb32e4e73f26091
Author: Pierre Wieser <pwieser trychlos org>
Date:   Sun Sep 27 21:54:24 2009 +0200

    Paste a profile from the clipboard

 ChangeLog                    |    3 +++
 src/common/na-object-id.c    |    4 ++++
 src/common/na-object-item.c  |   10 +++++++++-
 src/nact/nact-main-menubar.c |   16 +++++++++++++++-
 src/nact/nact-tree-model.c   |    9 +++++++++
 5 files changed, 40 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2e926b0..0609518 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,9 +4,11 @@
 
 	* src/common/na-object-id-fn.h:
 	* src/common/na-object-id.c (na_object_id_set_for_copy): New function.
+	(most_derived_new_id): Do not search in NAObjectClass.
 
 	* src/common/na-object-item.c (na_object_item_remove_item):
 	Release the reference on the removed item.
+	Only release the reference when action or menu, not profile.
 
 	* src/nact/nact-clipboard.c:
 	* src/nact/nact-clipboard.h (nact_clipboard_primary_set,
@@ -21,6 +23,7 @@
 	* src/nact/nact-main-menubar.c:
 	Now use the NactClipboard convenience object.
 	Uses na_object_id_set_for_copy().
+	(on_paste_activated): Setup the new action when pasting a profile.
 
 	* src/nact/nact-main-window.c:
 	* src/nact/nact-main-window.h (nact_main_window_get_clipboard):
diff --git a/src/common/na-object-id.c b/src/common/na-object-id.c
index 74d5f8b..05277ee 100644
--- a/src/common/na-object-id.c
+++ b/src/common/na-object-id.c
@@ -524,12 +524,16 @@ most_derived_new_id( NAObjectId *object )
 	found = FALSE;
 	new_id = NULL;
 	hierarchy = g_list_reverse( na_object_get_hierarchy( NA_OBJECT( object )));
+	g_debug( "na_object_id_most_derived_id: object=%p (%s)", ( void * ) object, G_OBJECT_TYPE_NAME( object ));
 
 	for( ih = hierarchy ; ih && !found ; ih = ih->next ){
 		if( NA_OBJECT_ID_CLASS( ih->data )->new_id ){
 			new_id = NA_OBJECT_ID_CLASS( ih->data )->new_id( object );
 			found = TRUE;
 		}
+		if( G_OBJECT_CLASS_TYPE( ih->data ) == NA_OBJECT_ID_TYPE ){
+			break;
+		}
 	}
 
 	na_object_free_hierarchy( hierarchy );
diff --git a/src/common/na-object-item.c b/src/common/na-object-item.c
index 1f7b60a..c9612d6 100644
--- a/src/common/na-object-item.c
+++ b/src/common/na-object-item.c
@@ -565,6 +565,7 @@ na_object_item_get_items_count( const NAObjectItem *item )
 {
 	guint count = 0;
 
+	/*g_debug( "na_object_item_get_items_count: item=%p (%s)", ( void * ) item, G_OBJECT_TYPE_NAME( item ));*/
 	g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), 0 );
 
 	if( !item->private->dispose_has_run ){
@@ -803,7 +804,14 @@ na_object_item_remove_item( NAObjectItem *item, const NAObject *object )
 
 		if( g_list_find( item->private->items, ( gconstpointer ) object )){
 			item->private->items = g_list_remove( item->private->items, ( gconstpointer ) object );
-			g_object_unref(( gpointer ) object );
+
+			/* don't understand why !?
+			 * it appears as if embedded actions and menus would have one sur-ref
+			 * that profiles don't have
+			 */
+			if( NA_IS_OBJECT_ITEM( object )){
+				g_object_unref(( gpointer ) object );
+			}
 		}
 	}
 }
diff --git a/src/nact/nact-main-menubar.c b/src/nact/nact-main-menubar.c
index 8573457..0e08d74 100644
--- a/src/nact/nact-main-menubar.c
+++ b/src/nact/nact-main-menubar.c
@@ -536,11 +536,25 @@ on_copy_activated( GtkAction *gtk_action, NactMainWindow *window )
 static void
 on_paste_activated( GtkAction *gtk_action, NactMainWindow *window )
 {
-	GList *items;
+	GList *items, *it;
 	NactClipboard *clipboard;
+	NAObjectAction *action = NULL;
 
 	clipboard = nact_main_window_get_clipboard( window );
 	items = nact_clipboard_primary_get( clipboard );
+
+	/* if pasted items are profiles, then setup the action
+	 */
+	for( it = items ; it ; it = it->next ){
+		if( NA_IS_OBJECT_PROFILE( it->data )){
+			if( !action ){
+				g_object_get( G_OBJECT( window ), TAB_UPDATABLE_PROP_EDITED_ACTION, &action, NULL );
+				g_return_if_fail( NA_IS_OBJECT_ACTION( action ));
+			}
+			na_object_profile_set_action( NA_OBJECT_PROFILE( it->data ), action );
+		}
+	}
+
 	nact_iactions_list_insert_items( NACT_IACTIONS_LIST( window ), items, NULL );
 	na_object_free_items( items );
 }
diff --git a/src/nact/nact-tree-model.c b/src/nact/nact-tree-model.c
index b1231e9..50fc02f 100644
--- a/src/nact/nact-tree-model.c
+++ b/src/nact/nact-tree-model.c
@@ -756,6 +756,9 @@ nact_tree_model_insert( NactTreeModel *model, const NAObject *object, GtkTreePat
 	return( path_str );
 }
 
+/*
+ * inserts an action
+ */
 static void
 insert_get_iters_action( GtkTreeModel *model, const NAObject *select_object, GtkTreePath *select_path, const NAObject *object, GtkTreeIter *parent_iter, gboolean *has_parent_iter, GtkTreeIter *sibling_iter, gboolean *has_sibling_iter, NAObject **parent_object )
 {
@@ -788,6 +791,9 @@ insert_get_iters_action( GtkTreeModel *model, const NAObject *select_object, Gtk
 	}
 }
 
+/*
+ * insert a profile
+ */
 static void
 insert_get_iters_profile( GtkTreeModel *model, const NAObject *select_object, GtkTreePath *select_path, const NAObject *object, GtkTreeIter *parent_iter, gboolean *has_parent_iter, GtkTreeIter *sibling_iter, gboolean *has_sibling_iter, NAObject **parent_object )
 {
@@ -806,6 +812,9 @@ insert_get_iters_profile( GtkTreeModel *model, const NAObject *select_object, Gt
 	}
 }
 
+/*
+ * insert a menu
+ */
 static void
 insert_get_iters_menu( GtkTreeModel *model, const NAObject *select_object, GtkTreePath *select_path, const NAObject *object, GtkTreeIter *parent_iter, gboolean *has_parent_iter, GtkTreeIter *sibling_iter, gboolean *has_sibling_iter, NAObject **parent_object )
 {



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