[nautilus-actions] Renumber and relabel pasted items



commit a3763952329f154f054f4f86b6077608fe8f7dd5
Author: pierre <pierre vfedora10 virtuals pwi>
Date:   Mon Oct 5 15:31:26 2009 +0200

    Renumber and relabel pasted items

 ChangeLog                     |   25 ++++++++++++
 src/common/na-object-api.h    |    7 ++-
 src/common/na-object-id-fn.h  |    4 +-
 src/common/na-object-id.c     |   84 ++++++++++++++++++++++++++++++++++-------
 src/nact/nact-clipboard.c     |   70 ++++++++++------------------------
 src/nact/nact-clipboard.h     |   11 ++++-
 src/nact/nact-iactions-list.c |   27 ++++++++-----
 src/nact/nact-main-menubar.c  |   75 +++++++++++++++++-------------------
 src/nact/nact-main-window.c   |   31 ---------------
 src/nact/nact-main-window.h   |    1 -
 10 files changed, 185 insertions(+), 150 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d70e9b9..29037e2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2009-10-05 Pierre Wieser <pwieser trychlos org>
+
+	Restaure and fix 'Copy of' relabeling of pasted items.
+
+	* src/common/na-object-api.h:
+	* /src/common/na-object-id-fn.h:
+	* src/common/na-object-id.c
+	(na_object_set_for_copy, na_object_id_set_for_copy):
+	Removed functions.
+	(na_object_prepare_for_paste, na_object_id_prepare_for_paste,
+	na_object_id_set_copy_of_label):
+	New functions.
+
+	* src/nact/nact-clipboard.c:
+	* /src/nact/nact-clipboard.h:
+	Keep the initial copy mode in the clipboard.
+	Remove the relabeling operations from the clipboard.
+
+	* src/nact/nact-iactions-list.c:
+	Prepare pasted items here when we know the exact target.
+
+	* src/nact/nact-main-window.c:
+	* src/nact/nact-main-window.h
+	(nact_main_window_prepare_object_for_copy): Removed function.
+
 2009-10-04 Pierre Wieser <pwieser trychlos org>
 
 	Use some stored indicators to compute the action sensitivities
diff --git a/src/common/na-object-api.h b/src/common/na-object-api.h
index c5e2a20..9fb231d 100644
--- a/src/common/na-object-api.h
+++ b/src/common/na-object-api.h
@@ -65,12 +65,15 @@ G_BEGIN_DECLS
 
 /* NAObjectId
  */
-#define na_object_set_for_copy( object, relabel )	na_object_id_set_for_copy( NA_OBJECT_ID( object ), relabel )
+#define na_object_prepare_for_paste( object, pivot, renumber, action ) \
+													na_object_id_prepare_for_paste( NA_OBJECT_ID( object ), pivot, renumber, ( NAObjectAction * ) action )
+#define na_object_set_copy_of_label( object )		na_object_id_set_copy_of_label( NA_OBJECT_ID( object ))
 
 /* NAObjectItem
  */
 
-#define na_object_insert_item( object, item, before ) na_object_item_insert_item( NA_OBJECT_ITEM( object ), NA_OBJECT( item ), ( NAObject * ) before )
+#define na_object_insert_item( object, item, before ) \
+													na_object_item_insert_item( NA_OBJECT_ITEM( object ), NA_OBJECT( item ), ( NAObject * ) before )
 #define na_object_remove_item( object, item )		na_object_item_remove_item( NA_OBJECT_ITEM( object ), NA_OBJECT( item ))
 
 G_END_DECLS
diff --git a/src/common/na-object-id-fn.h b/src/common/na-object-id-fn.h
index 848cd9c..9cbaefa 100644
--- a/src/common/na-object-id-fn.h
+++ b/src/common/na-object-id-fn.h
@@ -44,10 +44,12 @@
  */
 
 #include <runtime/na-object-id-class.h>
+#include <runtime/na-pivot.h>
 
 G_BEGIN_DECLS
 
-void   na_object_id_set_for_copy( NAObjectId *object, gboolean relabel );
+void   na_object_id_prepare_for_paste( NAObjectId *object, NAPivot *pivot, gboolean renumber, NAObjectAction *action );
+void   na_object_id_set_copy_of_label( NAObjectId *object );
 
 G_END_DECLS
 
diff --git a/src/common/na-object-id.c b/src/common/na-object-id.c
index 86b58f2..607379e 100644
--- a/src/common/na-object-id.c
+++ b/src/common/na-object-id.c
@@ -39,6 +39,7 @@
 #include <runtime/na-object-id-priv.h>
 
 #include "na-object-api.h"
+#include "na-iprefs.h"
 
 /* private class data
  */
@@ -47,30 +48,85 @@ struct NAObjectIdClassPrivate {
 };
 
 /**
- * na_object_id_set_for_copy:
- * @object: the #NAObjectId object to be copied.
- * @relabel: whether this item should be relabeled ?
+ * na_object_id_prepare_for_paste:
+ * @object: the #NAObjectId object to be pasted.
+ * @pivot; the #NAPivot instance which let us access to preferences.
+ * @relabel: whether this item should be renumbered ?
+ * @action: if @object is a #NAObjectProfile, the attached #NAObjectAction.
  *
- * Prepares @object to be copied, allocating to it a new uuid if apply,
- * and relabeling it as "Copy of ..." if applies.
+ * Prepares @object to be pasted.
+ *
+ * If a #NAObjectProfile, then @object is attached to the specified
+ * #NAObjectAction @action. The identifier is always renumbered to be
+ * suitable with the already existing profiles.
+ *
+ * If a #NAObjectAction or a #NAObjectMenu, a new UUID is allocated if
+ * and only if @relabel is %TRUE.
+ *
+ * Actual relabeling takes place if @relabel is %TRUE, depending of the
+ * user preferences.
  */
 void
-na_object_id_set_for_copy( NAObjectId *object, gboolean relabel )
+na_object_id_prepare_for_paste( NAObjectId *object, NAPivot *pivot, gboolean renumber, NAObjectAction *action )
 {
-	gchar *new_label;
+	static const gchar *thisfn = "na_object_id_prepare_for_paste";
+	gboolean user_relabel;
 
 	g_return_if_fail( NA_IS_OBJECT_ID( object ));
+	g_return_if_fail( NA_IS_PIVOT( pivot ));
+	g_return_if_fail( !action || NA_IS_OBJECT_ACTION( action ));
 
 	if( !object->private->dispose_has_run ){
 
-		/* TODO: review the set_for_copy function */
-		na_object_id_set_new_id( object, NULL );
+		user_relabel = FALSE;
 
-		if( relabel ){
-			/* i18n: copied items have a label as 'Copy of original label' */
-			new_label = g_strdup_printf( _( "Copy of %s" ), object->private->label );
-			g_free( object->private->label );
-			object->private->label = new_label;
+		if( NA_IS_OBJECT_MENU( object )){
+			user_relabel = na_iprefs_read_bool( NA_IPREFS( pivot ), IPREFS_RELABEL_MENUS, FALSE );
+		} else if( NA_IS_OBJECT_ACTION( object )){
+			user_relabel = na_iprefs_read_bool( NA_IPREFS( pivot ), IPREFS_RELABEL_ACTIONS, FALSE );
+		} else if( NA_IS_OBJECT_PROFILE( object )){
+			user_relabel = na_iprefs_read_bool( NA_IPREFS( pivot ), IPREFS_RELABEL_PROFILES, FALSE );
+		} else {
+			g_warning( "%s: unknown object type at %p", thisfn, ( void * ) object );
+			g_return_if_reached();
 		}
+
+		if( NA_IS_OBJECT_PROFILE( object )){
+			na_object_profile_set_action( NA_OBJECT_PROFILE( object ), action );
+			na_object_set_new_id( object, action );
+			if( renumber && user_relabel ){
+				na_object_set_copy_of_label( object );
+			}
+
+		} else {
+			if( renumber ){
+				na_object_set_new_id( object, NULL );
+				if( user_relabel ){
+					na_object_set_copy_of_label( object );
+				}
+			}
+		}
+	}
+}
+
+/**
+ * na_object_id_set_copy_of_label:
+ * @object: the #NAObjectId object whose label is to be changed.
+ *
+ * Sets the 'Copy of' label.
+ */
+void
+na_object_id_set_copy_of_label( NAObjectId *object )
+{
+	gchar *new_label;
+
+	g_return_if_fail( NA_IS_OBJECT_ID( object ));
+
+	if( !object->private->dispose_has_run ){
+
+		/* i18n: copied items have a label as 'Copy of original label' */
+		new_label = g_strdup_printf( _( "Copy of %s" ), object->private->label );
+		g_free( object->private->label );
+		object->private->label = new_label;
 	}
 }
diff --git a/src/nact/nact-clipboard.c b/src/nact/nact-clipboard.c
index a46c76d..2da1ac3 100644
--- a/src/nact/nact-clipboard.c
+++ b/src/nact/nact-clipboard.c
@@ -55,6 +55,7 @@ struct NactClipboardPrivate {
 	gboolean      dispose_has_run;
 	GtkClipboard *dnd;
 	GtkClipboard *primary;
+	gboolean      primary_got;
 };
 
 #define NACT_CLIPBOARD_ATOM				gdk_atom_intern( "_NACT_CLIPBOARD", FALSE )
@@ -89,10 +90,11 @@ typedef struct {
 	NactClipboardDndData;
 
 typedef struct {
-	guint  nb_actions;
-	guint  nb_profiles;
-	guint  nb_menus;
-	GList *items;
+	guint    nb_actions;
+	guint    nb_profiles;
+	guint    nb_menus;
+	GList   *items;
+	gint     mode;
 }
 	NactClipboardPrimaryData;
 
@@ -111,7 +113,6 @@ static void   export_rows( NactClipboard *clipboard, NactClipboardDndData *data
 
 static void   get_from_primary_clipboard_callback( GtkClipboard *clipboard, GtkSelectionData *selection_data, guint info, guchar *data );
 static void   clear_primary_clipboard_callback( GtkClipboard *clipboard, NactClipboardPrimaryData *data );
-static void   renumber_items( NactClipboard *clipboard, GList *items );
 
 GType
 nact_clipboard_get_type( void )
@@ -561,8 +562,8 @@ export_rows( NactClipboard *clipboard, NactClipboardDndData *data )
  * nact_clipboard_primary_set:
  * @clipboard: this #NactClipboard object.
  * @items: a list of #NAObject items
- * @renumber: whether the actions or menus items should be
- * renumbered when copied in the clipboard ?
+ * @mode: where do these items come from ?
+ *  Or what is the operation which has led the items to the clipboard?
  *
  * Installs a copy of provided items in the clipboard.
  *
@@ -579,7 +580,7 @@ export_rows( NactClipboard *clipboard, NactClipboardDndData *data )
  * data out of the clipboard.
  */
 void
-nact_clipboard_primary_set( NactClipboard *clipboard, GList *items, gboolean renumber )
+nact_clipboard_primary_set( NactClipboard *clipboard, GList *items, gint mode )
 {
 	NactClipboardPrimaryData *data;
 	GList *it;
@@ -590,24 +591,17 @@ nact_clipboard_primary_set( NactClipboard *clipboard, GList *items, gboolean ren
 
 		data = g_new0( NactClipboardPrimaryData, 1 );
 
+		na_object_item_count_items( items,
+				( gint * ) &data->nb_menus, ( gint * ) &data->nb_actions, ( gint * ) &data->nb_profiles, FALSE );
+
 		for( it = items ; it ; it = it->next ){
 			data->items = g_list_prepend( data->items, na_object_duplicate( it->data ));
-
-			if( NA_IS_OBJECT_ACTION( it->data )){
-				data->nb_actions += 1;
-
-			} else if( NA_IS_OBJECT_MENU( it->data )){
-				data->nb_menus += 1;
-
-			} else if( NA_IS_OBJECT_PROFILE( it->data )){
-				data->nb_profiles += 1;
-			}
 		}
 		data->items = g_list_reverse( data->items );
 
-		if( renumber ){
-			renumber_items( clipboard, data->items );
-		}
+		data->mode = mode;
+
+		clipboard->private->primary_got = FALSE;
 
 		gtk_clipboard_set_with_data( clipboard->private->primary,
 				clipboard_formats, G_N_ELEMENTS( clipboard_formats ),
@@ -628,7 +622,7 @@ nact_clipboard_primary_set( NactClipboard *clipboard, GList *items, gboolean ren
  * time.
  */
 GList *
-nact_clipboard_primary_get( NactClipboard *clipboard )
+nact_clipboard_primary_get( NactClipboard *clipboard, gboolean *relabel )
 {
 	GtkSelectionData *selection;
 	NactClipboardPrimaryData *data;
@@ -637,6 +631,7 @@ nact_clipboard_primary_get( NactClipboard *clipboard )
 	NAObject *obj;
 
 	g_return_val_if_fail( NACT_IS_CLIPBOARD( clipboard ), NULL );
+	g_return_val_if_fail( relabel, NULL );
 
 	if( !clipboard->private->dispose_has_run ){
 
@@ -652,7 +647,10 @@ nact_clipboard_primary_get( NactClipboard *clipboard )
 			}
 			items = g_list_reverse( items );
 
-			renumber_items( clipboard, data->items );
+			*relabel = (( data->mode == CLIPBOARD_MODE_CUT && clipboard->private->primary_got ) ||
+							data->mode == CLIPBOARD_MODE_COPY );
+
+			clipboard->private->primary_got = TRUE;
 		}
 	}
 
@@ -715,29 +713,3 @@ clear_primary_clipboard_callback( GtkClipboard *clipboard, NactClipboardPrimaryD
 	g_list_free( data->items );
 	g_free( data );
 }
-
-static void
-renumber_items( NactClipboard *clipboard, GList *items )
-{
-	/*GList *it;
-	gboolean relabel_menus, relabel_actions, relabel_profiles;
-	gboolean relabel;
-
-	relabel_menus = base_iprefs_get_bool( BASE_IPREFS( clipboard ), BASE_IPREFS_RELABEL_MENUS );
-	relabel_actions = base_iprefs_get_bool( BASE_IPREFS( clipboard ), BASE_IPREFS_RELABEL_ACTIONS );
-	relabel_profiles = base_iprefs_get_bool( BASE_IPREFS( clipboard ), BASE_IPREFS_RELABEL_PROFILES );
-
-	for( it = items ; it ; it = it->next ){
-
-		if( NA_IS_OBJECT_MENU( it->data )){
-			relabel = relabel_menus;
-		} else if( NA_IS_OBJECT_ACTION( it->data )){
-			relabel = relabel_actions;
-		} else {
-			g_return_if_fail( NA_IS_OBJECT_PROFILE( it->data ));
-			relabel = relabel_profiles;
-		}
-
-		na_object_set_for_copy( it->data, relabel );
-	}*/
-}
diff --git a/src/nact/nact-clipboard.h b/src/nact/nact-clipboard.h
index c3aa459..4119bdd 100644
--- a/src/nact/nact-clipboard.h
+++ b/src/nact/nact-clipboard.h
@@ -78,6 +78,13 @@ enum {
 	NACT_XCHANGE_FORMAT_URI_LIST
 };
 
+/* mode indicator
+ */
+enum {
+	CLIPBOARD_MODE_CUT = 1,
+	CLIPBOARD_MODE_COPY
+};
+
 GType          nact_clipboard_get_type( void );
 
 NactClipboard *nact_clipboard_new( void );
@@ -88,8 +95,8 @@ gchar         *nact_clipboard_dnd_get_text( NactClipboard *clipboard, GList *row
 void           nact_clipboard_dnd_drag_end( NactClipboard *clipboard );
 void           nact_clipboard_dnd_clear( NactClipboard *clipboard );
 
-void           nact_clipboard_primary_set( NactClipboard *clipboard, GList *items, gboolean renumber_items );
-GList         *nact_clipboard_primary_get( NactClipboard *clipboard );
+void           nact_clipboard_primary_set( NactClipboard *clipboard, GList *items, gint mode );
+GList         *nact_clipboard_primary_get( NactClipboard *clipboard, gboolean *relabel );
 void           nact_clipboard_primary_counts( NactClipboard *clipboard, guint *actions, guint *profiles, guint *menus );
 
 G_END_DECLS
diff --git a/src/nact/nact-iactions-list.c b/src/nact/nact-iactions-list.c
index 0586106..6a36371 100644
--- a/src/nact/nact-iactions-list.c
+++ b/src/nact/nact-iactions-list.c
@@ -124,12 +124,12 @@ static void         interface_base_init( NactIActionsListInterface *klass );
 static void         interface_base_finalize( NactIActionsListInterface *klass );
 
 static void         free_items_callback( NactIActionsList *instance, GList *items );
-static void         decremente_counters( NactIActionsList *instance, GList *items );
+static void         decrement_counters( NactIActionsList *instance, GList *items );
 static GtkTreePath *get_selection_first_path( GtkTreeView *treeview );
 static void         do_insert_items( GtkTreeView *treeview, GtkTreeModel *model, GList *items, GtkTreePath *path, GList **parents );
 static NAObject    *do_insert_into_first( GtkTreeView *treeview, GtkTreeModel *model, GList *items, GtkTreePath *insert_path, GtkTreePath **new_path );
 static GtkTreePath *do_insert_into_second( GtkTreeView *treeview, GtkTreeModel *model, NAObject *object, GtkTreePath *insert_path, NAObject **parent );
-static void         incremente_counters( NactIActionsList *instance, GList *items );
+static void         increment_counters( NactIActionsList *instance, GList *items );
 static void         update_parents_edition_status( GList *parents, GList *items );
 
 static gchar       *v_get_treeview_name( NactIActionsList *instance );
@@ -545,7 +545,7 @@ nact_iactions_list_delete( NactIActionsList *instance, GList *items )
 
 		set_selection_changed_mode( instance, FALSE );
 
-		decremente_counters( instance, items );
+		decrement_counters( instance, items );
 
 		for( it = items ; it ; it = it->next ){
 			if( path ){
@@ -565,7 +565,7 @@ nact_iactions_list_delete( NactIActionsList *instance, GList *items )
 }
 
 static void
-decremente_counters( NactIActionsList *instance, GList *items )
+decrement_counters( NactIActionsList *instance, GList *items )
 {
 	gint menus, actions, profiles;
 	CountersStruct *cs;
@@ -866,9 +866,8 @@ nact_iactions_list_insert_at_path( NactIActionsList *instance, GList *items, Gtk
 
 		do_insert_items( treeview, model, items, insert_path, &parents );
 
-		incremente_counters( instance, items );
-
 		update_parents_edition_status( parents, items );
+		increment_counters( instance, items );
 
 		gtk_tree_model_filter_refilter( GTK_TREE_MODEL_FILTER( model ));
 
@@ -983,7 +982,7 @@ nact_iactions_list_insert_into( NactIActionsList *instance, GList *items )
 		model = gtk_tree_view_get_model( treeview );
 		insert_path = get_selection_first_path( treeview );
 
-		incremente_counters( instance, items );
+		increment_counters( instance, items );
 
 		parent = do_insert_into_first( treeview, model, items, insert_path, &new_path );
 
@@ -1098,23 +1097,26 @@ do_insert_into_second( GtkTreeView *treeview, GtkTreeModel *model, NAObject *obj
 }
 
 static void
-incremente_counters( NactIActionsList *instance, GList *items )
+increment_counters( NactIActionsList *instance, GList *items )
 {
+	static const gchar *thisfn = "nact_iactions_list_increment_counters";
 	gint menus, actions, profiles;
 	CountersStruct *cs;
 
+	g_debug( "%s: instance=%p, items=%p", thisfn, ( void * ) instance, ( void * ) items );
+
 	menus = 0;
 	actions = 0;
 	profiles = 0;
 	na_object_item_count_items( items, &menus, &actions, &profiles, TRUE );
-	/*g_debug( "incremente_counters: counted: menus=%d, actions=%d, profiles=%d", menus, actions, profiles );*/
+	/*g_debug( "increment_counters: counted: menus=%d, actions=%d, profiles=%d", menus, actions, profiles );*/
 
 	cs = ( CountersStruct * ) g_object_get_data( G_OBJECT( instance ), LIST_COUNTERS );
 	/*g_debug( "incremente_counters: cs before: menus=%d, actions=%d, profiles=%d", cs->menus, cs->actions, cs->profiles );*/
 	cs->menus += menus;
 	cs->actions += actions;
 	cs->profiles += profiles;
-	/*g_debug( "incremente_counters: cs after: menus=%d, actions=%d, profiles=%d", cs->menus, cs->actions, cs->profiles );*/
+	/*g_debug( "increment_counters: cs after: menus=%d, actions=%d, profiles=%d", cs->menus, cs->actions, cs->profiles );*/
 
 	send_list_count_updated_signal( instance, cs );
 }
@@ -1122,8 +1124,13 @@ incremente_counters( NactIActionsList *instance, GList *items )
 static void
 update_parents_edition_status( GList *parents, GList *items )
 {
+	static const gchar *thisfn = "nact_iactions_list_update_parents_edition_status";
 	GList *it;
 
+	g_debug( "%s: parents=%p (count=%d), items=%p (count=%d)", thisfn,
+			( void * ) parents, g_list_length( parents ),
+			( void * ) items, g_list_length( items ));
+
 	/*if( !parents || !g_list_length( parents )){
 		parents = g_list_copy( items );
 	}*/
diff --git a/src/nact/nact-main-menubar.c b/src/nact/nact-main-menubar.c
index 451f301..92e4279 100644
--- a/src/nact/nact-main-menubar.c
+++ b/src/nact/nact-main-menubar.c
@@ -104,6 +104,7 @@ static void     on_cut_activated( GtkAction *action, NactMainWindow *window );
 static void     on_copy_activated( GtkAction *action, NactMainWindow *window );
 static void     on_paste_activated( GtkAction *action, NactMainWindow *window );
 static void     on_paste_into_activated( GtkAction *action, NactMainWindow *window );
+static GList   *prepare_for_paste( NactMainWindow *window );
 static void     on_duplicate_activated( GtkAction *action, NactMainWindow *window );
 static void     on_delete_activated( GtkAction *action, NactMainWindow *window );
 static void     update_clipboard_counters( NactMainWindow *window );
@@ -654,7 +655,7 @@ on_cut_activated( GtkAction *gtk_action, NactMainWindow *window )
 	items = nact_iactions_list_get_selected_items( NACT_IACTIONS_LIST( window ));
 	nact_main_window_move_to_deleted( window, items );
 	clipboard = nact_main_window_get_clipboard( window );
-	nact_clipboard_primary_set( clipboard, items, FALSE );
+	nact_clipboard_primary_set( clipboard, items, CLIPBOARD_MODE_CUT );
 	update_clipboard_counters( window );
 	nact_iactions_list_delete( NACT_IACTIONS_LIST( window ), items );
 
@@ -682,7 +683,7 @@ on_copy_activated( GtkAction *gtk_action, NactMainWindow *window )
 
 	items = nact_iactions_list_get_selected_items( NACT_IACTIONS_LIST( window ));
 	clipboard = nact_main_window_get_clipboard( window );
-	nact_clipboard_primary_set( clipboard, items, TRUE );
+	nact_clipboard_primary_set( clipboard, items, CLIPBOARD_MODE_COPY );
 	update_clipboard_counters( window );
 	na_object_free_items( items );
 
@@ -704,25 +705,9 @@ on_copy_activated( GtkAction *gtk_action, NactMainWindow *window )
 static void
 on_paste_activated( GtkAction *gtk_action, NactMainWindow *window )
 {
-	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 );
-		}
-	}
+	GList *items;
 
+	items = prepare_for_paste( window );
 	nact_iactions_list_insert_items( NACT_IACTIONS_LIST( window ), items, NULL );
 	na_object_free_items( items );
 }
@@ -742,12 +727,29 @@ on_paste_activated( GtkAction *gtk_action, NactMainWindow *window )
 static void
 on_paste_into_activated( GtkAction *gtk_action, NactMainWindow *window )
 {
+	GList *items;
+
+	items = prepare_for_paste( window );
+	nact_iactions_list_insert_into( NACT_IACTIONS_LIST( window ), items );
+	na_object_free_items( items );
+}
+
+static GList *
+prepare_for_paste( NactMainWindow *window )
+{
 	GList *items, *it;
 	NactClipboard *clipboard;
-	NAObjectAction *action = NULL;
+	NAObjectAction *action;
+	gboolean renumber;
+	NactApplication *application;
+	NAPivot *pivot;
+
+	application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
+	pivot = nact_application_get_pivot( application );
 
 	clipboard = nact_main_window_get_clipboard( window );
-	items = nact_clipboard_primary_get( clipboard );
+	items = nact_clipboard_primary_get( clipboard, &renumber );
+	action = NULL;
 
 	/* if pasted items are profiles, then setup the action
 	 */
@@ -755,14 +757,13 @@ on_paste_into_activated( GtkAction *gtk_action, NactMainWindow *window )
 		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 ));
+				g_return_val_if_fail( NA_IS_OBJECT_ACTION( action ), NULL );
 			}
-			na_object_profile_set_action( NA_OBJECT_PROFILE( it->data ), action );
 		}
+		na_object_prepare_for_paste( NA_OBJECT_ITEM( it->data ), pivot, renumber, action );
 	}
 
-	nact_iactions_list_insert_into( NACT_IACTIONS_LIST( window ), items );
-	na_object_free_items( items );
+	return( items );
 }
 
 /*
@@ -778,11 +779,10 @@ on_duplicate_activated( GtkAction *gtk_action, NactMainWindow *window )
 {
 	NactApplication *application;
 	NAPivot *pivot;
+	NAObjectAction *action;
 	GList *items, *it;
 	GList *dup;
 	NAObject *obj;
-	gboolean relabel_menus, relabel_actions, relabel_profiles;
-	gboolean relabel;
 
 	g_return_if_fail( GTK_IS_ACTION( gtk_action ));
 	g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
@@ -790,24 +790,19 @@ on_duplicate_activated( GtkAction *gtk_action, NactMainWindow *window )
 	application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
 	pivot = nact_application_get_pivot( application );
 
-	relabel_menus = na_iprefs_read_bool( NA_IPREFS( pivot ), IPREFS_RELABEL_MENUS, FALSE );
-	relabel_actions = na_iprefs_read_bool( NA_IPREFS( pivot ), IPREFS_RELABEL_ACTIONS, FALSE );
-	relabel_profiles = na_iprefs_read_bool( NA_IPREFS( pivot ), IPREFS_RELABEL_PROFILES, FALSE );
-
 	items = nact_iactions_list_get_selected_items( NACT_IACTIONS_LIST( window ));
 	for( it = items ; it ; it = it->next ){
 		obj = NA_OBJECT( na_object_duplicate( it->data ));
+		action = NULL;
 
-		if( NA_IS_OBJECT_MENU( obj )){
-			relabel = relabel_menus;
-		} else if( NA_IS_OBJECT_ACTION( obj )){
-			relabel = relabel_actions;
-		} else {
-			g_return_if_fail( NA_IS_OBJECT_PROFILE( obj ));
-			relabel = relabel_profiles;
+		/* duplicating a profile
+		 * as we insert in sibling mode, the parent doesn't change
+		 */
+		if( NA_IS_OBJECT_PROFILE( obj )){
+			action = na_object_profile_get_action( NA_OBJECT_PROFILE( obj ));
 		}
 
-		na_object_set_for_copy( obj, relabel );
+		na_object_prepare_for_paste( obj, pivot, TRUE, action );
 		na_object_set_origin( obj, NULL );
 		dup = g_list_prepend( NULL, obj );
 		nact_iactions_list_insert_items( NACT_IACTIONS_LIST( window ), dup, it->data );
diff --git a/src/nact/nact-main-window.c b/src/nact/nact-main-window.c
index 7a6edb8..6883708 100644
--- a/src/nact/nact-main-window.c
+++ b/src/nact/nact-main-window.c
@@ -786,37 +786,6 @@ nact_main_window_remove_deleted( NactMainWindow *window )
 	}
 }
 
-/**
- * nact_main_window_prepare_object_for_copy:
- * @window: this #NactMainWindow instance.
- * @object: the #NAObject to be prepared.
- * @new_parent: if @object is a profile, then the new id will be computed
- * depending of already existing profiles in the @new_parent.
- *
- * Gives a new id to the object,
- * possibly relabeling it depending on current preferences.
- */
-void
-nact_main_window_prepare_object_for_copy( NactMainWindow *window, NAObject *object, NAObjectAction *new_parent )
-{
-	NactApplication *application;
-	NAPivot *pivot;
-	gboolean relabel = FALSE;
-
-	application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
-	pivot = nact_application_get_pivot( application );
-
-	if( NA_IS_OBJECT_MENU( object )){
-		relabel = na_iprefs_read_bool( NA_IPREFS( pivot ), IPREFS_RELABEL_MENUS, FALSE );
-	} else if( NA_IS_OBJECT_ACTION( object )){
-		relabel = na_iprefs_read_bool( NA_IPREFS( pivot ), IPREFS_RELABEL_ACTIONS, FALSE );
-	} else if( NA_IS_OBJECT_PROFILE( object )){
-		relabel = na_iprefs_read_bool( NA_IPREFS( pivot ), IPREFS_RELABEL_PROFILES, FALSE );
-	}
-
-	na_object_set_new_id( object, NULL );
-}
-
 /*
  * If the deleted item is a profile, then do nothing because the parent
  * action has been marked as modified when the profile has been deleted,
diff --git a/src/nact/nact-main-window.h b/src/nact/nact-main-window.h
index 660b143..6e8a6c2 100644
--- a/src/nact/nact-main-window.h
+++ b/src/nact/nact-main-window.h
@@ -81,7 +81,6 @@ gboolean        nact_main_window_has_modified_items( const NactMainWindow *windo
 void            nact_main_window_move_to_deleted( NactMainWindow *window, GList *items );
 void            nact_main_window_reload( NactMainWindow *window );
 void            nact_main_window_remove_deleted( NactMainWindow *window );
-void            nact_main_window_prepare_object_for_copy( NactMainWindow *window, NAObject *object, NAObjectAction *new_parent );
 
 G_END_DECLS
 



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