[nautilus-actions] Copied objects are relabeled



commit 7712f4b5a82de98d572079572b4b82161930d0c0
Author: Pierre Wieser <pwieser trychlos org>
Date:   Sun Sep 27 19:37:37 2009 +0200

    Copied objects are relabeled

 ChangeLog                    |    7 +++++++
 src/common/na-object-api.h   |    1 +
 src/common/na-object-id-fn.h |    1 +
 src/common/na-object-id.c    |   27 +++++++++++++++++++++++++++
 src/nact/nact-clipboard.c    |    4 +---
 src/nact/nact-main-menubar.c |    4 +---
 6 files changed, 38 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 004c088..145464a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2009-09-27 Pierre Wieser <pwieser trychlos org>
 
+	* src/common/na-object-api.h (na_object_set_for_copy): New function.
+
+	* src/common/na-object-id-fn.h:
+	* src/common/na-object-id.c (na_object_id_set_for_copy): New function.
+
 	* src/common/na-object-item.c (na_object_item_remove_item):
 	Release the reference on the removed item.
 
@@ -7,12 +12,14 @@
 	* src/nact/nact-clipboard.h (nact_clipboard_primary_set,
 	nact_clipboard_primary_get, nact_clipboard_primary_counts):
 	Now use the NactClipboard convenience object.
+	Uses na_object_id_set_for_copy().
 
 	* src/nact/nact-iactions-list.c (on_treeview_selection_changed):
 	Only get selected items when about to send the message.
 
 	* src/nact/nact-main-menubar.c:
 	Now use the NactClipboard convenience object.
+	Uses na_object_id_set_for_copy().
 
 	* src/nact/nact-main-window.c:
 	* src/nact/nact-main-window.h (nact_main_window_get_clipboard):
diff --git a/src/common/na-object-api.h b/src/common/na-object-api.h
index bc40017..3752882 100644
--- a/src/common/na-object-api.h
+++ b/src/common/na-object-api.h
@@ -68,6 +68,7 @@ G_BEGIN_DECLS
 #define na_object_get_label( object )				na_object_id_get_label( NA_OBJECT_ID( object ))
 
 #define na_object_set_id( object, id )				na_object_id_set_id( NA_OBJECT_ID( object ), id )
+#define na_object_set_for_copy( object )			na_object_id_set_for_copy( NA_OBJECT_ID( object ))
 #define na_object_set_new_id( object )				na_object_id_set_new_id( NA_OBJECT_ID( object ))
 #define na_object_set_label( object, label )		na_object_id_set_label( NA_OBJECT_ID( object ), label )
 
diff --git a/src/common/na-object-id-fn.h b/src/common/na-object-id-fn.h
index 3019b9b..79ecaae 100644
--- a/src/common/na-object-id-fn.h
+++ b/src/common/na-object-id-fn.h
@@ -50,6 +50,7 @@ gchar *na_object_id_get_id( const NAObjectId *object );
 gchar *na_object_id_get_label( const NAObjectId *object );
 
 void   na_object_id_set_id( NAObjectId *object, const gchar *id );
+void   na_object_id_set_for_copy( NAObjectId *object );
 void   na_object_id_set_new_id( NAObjectId *object );
 void   na_object_id_set_label( NAObjectId *object, const gchar *label );
 
diff --git a/src/common/na-object-id.c b/src/common/na-object-id.c
index d697294..74d5f8b 100644
--- a/src/common/na-object-id.c
+++ b/src/common/na-object-id.c
@@ -32,9 +32,11 @@
 #include <config.h>
 #endif
 
+#include <glib/gi18n.h>
 #include <string.h>
 
 #include "na-iduplicable.h"
+#include "na-object-api.h"
 #include "na-object-fn.h"
 #include "na-object-id-class.h"
 #include "na-object-id-fn.h"
@@ -343,6 +345,31 @@ na_object_id_set_id( NAObjectId *object, const gchar *id )
 }
 
 /**
+ * na_object_id_set_for_copy:
+ * @object: the #NAObjectId object to be copied.
+ *
+ * Prepares @object to be copied, allocating to it a new uuid if apply,
+ * and relabeling it as "Copy of ...".
+ */
+void
+na_object_id_set_for_copy( NAObjectId *object )
+{
+	gchar *new_label;
+
+	g_return_if_fail( NA_IS_OBJECT_ID( object ));
+
+	if( !object->private->dispose_has_run ){
+
+		na_object_id_set_new_id( object );
+
+		/* 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;
+	}
+}
+
+/**
  * na_object_id_set_new_id:
  * @object: the #NAObjectId object whose internal identifiant is to be
  * set.
diff --git a/src/nact/nact-clipboard.c b/src/nact/nact-clipboard.c
index 5a7c1da..c7f910a 100644
--- a/src/nact/nact-clipboard.c
+++ b/src/nact/nact-clipboard.c
@@ -593,8 +593,6 @@ renumber_items( GList *items )
 	GList *it;
 
 	for( it = items ; it ; it = it->next ){
-		if( NA_IS_OBJECT_ITEM( it->data )){
-			na_object_set_new_id( NA_OBJECT_ITEM( it->data ));
-		}
+		na_object_set_for_copy( it->data );
 	}
 }
diff --git a/src/nact/nact-main-menubar.c b/src/nact/nact-main-menubar.c
index 26a14b0..8573457 100644
--- a/src/nact/nact-main-menubar.c
+++ b/src/nact/nact-main-menubar.c
@@ -566,9 +566,7 @@ on_duplicate_activated( GtkAction *gtk_action, NactMainWindow *window )
 	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 ));
-		if( NA_IS_OBJECT_ITEM( obj )){
-			na_object_set_new_id( obj );
-		}
+		na_object_set_for_copy( obj );
 		na_object_set_origin( obj, NULL );
 		dup = g_list_prepend( NULL, obj );
 		nact_iactions_list_insert_items( NACT_IACTIONS_LIST( window ), dup, it->data );



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