[nautilus-actions] Use GList as subitems lists
- From: Pierre Wieser <pwieser src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Use GList as subitems lists
- Date: Sat, 26 Sep 2009 22:47:05 +0000 (UTC)
commit 5d1b60acbcb4d2f444cc64bc339530ae8944ff87
Author: Pierre Wieser <pwieser trychlos org>
Date: Fri Sep 18 00:02:06 2009 +0200
Use GList as subitems lists
Instead of GSList: shorter to type, more powerful
ChangeLog | 40 ++++++++++
src/common/na-gconf-provider.c | 10 +-
src/common/na-iio-provider.c | 28 ++++----
src/common/na-iio-provider.h | 10 +-
src/common/na-obj-action.c | 2 +-
src/common/na-obj-menu.c | 2 +-
src/common/na-object-api.h | 2 +-
src/common/na-object-fn.h | 3 +
src/common/na-object-id-class.h | 12 +++
src/common/na-object-id-fn.h | 1 +
src/common/na-object-id.c | 57 ++++++++++++++
src/common/na-object-item-fn.h | 6 +-
src/common/na-object-item.c | 85 +++++++++++++--------
src/common/na-object.c | 106 +++++++++++++-------------
src/common/na-pivot.c | 14 ++--
src/common/na-pivot.h | 2 +-
src/common/na-xml-writer.c | 4 +-
src/nact/nact-assistant-export.c | 12 ++-
src/nact/nact-clipboard.c | 155 ++++++++++++++++++++++----------------
src/nact/nact-clipboard.h | 10 +-
src/nact/nact-iactions-list.c | 82 ++++++++++++--------
src/nact/nact-iactions-list.h | 12 ++--
src/nact/nact-main-menubar.c | 102 +++++++++++++++----------
src/nact/nact-main-window.c | 74 +++++++------------
src/nact/nact-main-window.h | 2 +-
src/nact/nact-tree-model.c | 53 +++++++------
src/nact/nact-tree-model.h | 4 +-
src/plugin/nautilus-actions.c | 5 +-
src/test/test-iface-iface.c | 8 +-
src/utils/nautilus-actions-new.c | 2 +-
30 files changed, 545 insertions(+), 360 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0b53a88..dd48e78 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,10 +1,50 @@
2009-09-17 Pierre Wieser <pwieser trychlos org>
+ * src/common/na-iio-provider.c
+ (get_merged_items_list, sort_tree):
+ * src/common/na-iio-provider.h
+ (read_items_list, na_iio_provider_get_items_tree):
+ * src/common/na-gconf-provider.c (iio_provider_read_items_list):
+ Now use a GList instead of a GSList (shorter, more powerful).
+
+ * src/common/na-object-api.h (na_object_set_new_id):
+ Fix declaration.
+
+ * src/common/na-object-id.c (new_id): New virtual function.
+ (na_object_id_set_new_id): new corresponding API.
+ Implements a 'most-derived' model.
+
+ * src/common/na-object-item.c:
+ Subitems are now managed in a GList instead of a GSList.
+
+ * src/common/na-obj-action.c:
+ * src/common/na-obj-menu.c:
+ * src/common/na-pivot.c:
+ * src/common/na-pivot.h:
+ * src/common/na-xml-writer.c:
+ * src/nact/nact-assistant-export.c:
+ * src/nact/nact-clipboard.c:
+ * src/nact/nact-clipboard.h:
+ * src/nact/nact-iactions-list.c:
+ * src/nact/nact-iactions-list.h:
+ * src/nact/nact-main-menubar.c
+ * src/nact/nact-main-window.c:
+ * src/nact/nact-tree-model.c:
+ * src/plugin/nautilus-actions.c:
+ * src/utils/nautilus-actions-new.c: Updated accordingly.
+
* src/nact/nact-iactions-list.c (filter_selection,
filter_selection_iter): Controls the allowed selection so that
we are only able to select profiles, or actions/menus.
Define new nact_iactions_list_set_filter_selection_mode() api.
+ * src/common/na-object.c:
+ * src/common/na-object-fn.h
+ (na_object_get_hierarchy, na_object_free_hierarchy): New functions.
+
+ * src/nact/nact-main-window.c (nact_main_window_delete_selection):
+ Renamed to nact_main_window_move_to_deleted().
+
* src/nact/nact-main-tab.c: Removed (unused) file.
2009-09-16 Pierre Wieser <pwieser trychlos org>
diff --git a/src/common/na-gconf-provider.c b/src/common/na-gconf-provider.c
index 08d85fb..bdaea71 100644
--- a/src/common/na-gconf-provider.c
+++ b/src/common/na-gconf-provider.c
@@ -73,7 +73,7 @@ static void install_monitors( NAGConfProvider *provider );
static void config_path_changed_cb( GConfClient *client, guint cnxn_id, GConfEntry *entry, NAGConfProvider *provider );
static NAPivotNotify *entry_to_notify( const GConfEntry *entry );
-static GSList *iio_provider_read_items_list( const NAIIOProvider *provider );
+static GList *iio_provider_read_items_list( const NAIIOProvider *provider );
static NAObjectItem *read_item( NAGConfProvider *provider, const gchar *path );
static void read_item_action( NAGConfProvider *provider, const gchar *path, NAObjectAction *action );
static void read_item_action_properties( NAGConfProvider *provider, GSList *entries, NAObjectAction *action );
@@ -424,12 +424,12 @@ entry_to_notify( const GConfEntry *entry )
* stored as a #NAObjectAction and its set of #NAObjectProfile of the same,
* latest, version of these classes.
*/
-static GSList *
+static GList *
iio_provider_read_items_list( const NAIIOProvider *provider )
{
static const gchar *thisfn = "na_gconf_provider_iio_provider_read_items_list";
NAGConfProvider *self;
- GSList *items_list = NULL;
+ GList *items_list = NULL;
GSList *listpath, *ip;
NAObjectItem *item;
@@ -448,7 +448,7 @@ iio_provider_read_items_list( const NAIIOProvider *provider )
item = read_item( self, path );
- items_list = g_slist_prepend( items_list, item );
+ items_list = g_list_prepend( items_list, item );
}
na_gconf_utils_free_subdirs( listpath );
@@ -791,7 +791,7 @@ write_item_action( NAGConfProvider *provider, const NAObjectAction *action, gcha
{
gchar *uuid, *name;
gboolean ret;
- GSList *profiles, *ip;
+ GList *profiles, *ip;
NAObjectProfile *profile;
if( !write_object_item( provider, NA_OBJECT_ITEM( action ), message )){
diff --git a/src/common/na-iio-provider.c b/src/common/na-iio-provider.c
index 5c2e968..a4e023c 100644
--- a/src/common/na-iio-provider.c
+++ b/src/common/na-iio-provider.c
@@ -52,13 +52,13 @@ static GType register_type( void );
static void interface_base_init( NAIIOProviderInterface *klass );
static void interface_base_finalize( NAIIOProviderInterface *klass );
-static GSList *get_merged_items_list( const NAPivot *pivot, GSList *providers );
+static GList *get_merged_items_list( const NAPivot *pivot, GSList *providers );
static guint try_write_item( const NAIIOProvider *instance, NAObject *item, gchar **message );
static gboolean do_is_willing_to_write( const NAIIOProvider *instance );
static gboolean do_is_writable( const NAIIOProvider *instance, const NAObject *item );
-static GSList *sort_tree( const NAPivot *pivot, GSList *tree );
+static GList *sort_tree( const NAPivot *pivot, GList *tree );
static gint compare_label_alpha_fn( const NAObjectId *a, const NAObjectId *b );
/**
@@ -145,16 +145,16 @@ interface_base_finalize( NAIIOProviderInterface *klass )
*
* Loads the tree from I/O storage subsystems.
*
- * Returns: a #GSList of newly allocated objects as a hierarchical tree
+ * Returns: a #GList of newly allocated objects as a hierarchical tree
* in display order. This tree may contain #NAActionMenu menus and
* #NAAction actions and their #NAActionProfile profiles.
*/
-GSList *
+GList *
na_iio_provider_get_items_tree( const NAPivot *pivot )
{
static const gchar *thisfn = "na_iio_provider_get_items_tree";
GSList *providers;
- GSList *merged;
+ GList *merged;
GSList *level_zero;
gboolean alpha_order;
@@ -183,12 +183,12 @@ na_iio_provider_get_items_tree( const NAPivot *pivot )
/*
* returns a concatened list of readen actions / menus
*/
-static GSList *
+static GList *
get_merged_items_list( const NAPivot *pivot, GSList *providers )
{
- GSList *merged = NULL;
GSList *ip;
- GSList *list, *item;
+ GList *merged = NULL;
+ GList *list, *item;
NAIIOProvider *instance;
for( ip = providers ; ip ; ip = ip->next ){
@@ -204,7 +204,7 @@ get_merged_items_list( const NAPivot *pivot, GSList *providers )
na_object_dump( item->data );
}
- merged = g_slist_concat( merged, list );
+ merged = g_list_concat( merged, list );
}
}
@@ -362,13 +362,13 @@ do_is_writable( const NAIIOProvider *instance, const NAObject *item )
return( FALSE );
}
-static GSList *
-sort_tree( const NAPivot *pivot, GSList *tree )
+static GList *
+sort_tree( const NAPivot *pivot, GList *tree )
{
- GSList *sorted;
- GSList *items, *it;
+ GList *sorted;
+ GList *items, *it;
- sorted = g_slist_sort( tree, ( GCompareFunc ) compare_label_alpha_fn );
+ sorted = g_list_sort( tree, ( GCompareFunc ) compare_label_alpha_fn );
/* recursively sort each level of the tree
*/
diff --git a/src/common/na-iio-provider.h b/src/common/na-iio-provider.h
index 3949dcf..5f81ac4 100644
--- a/src/common/na-iio-provider.h
+++ b/src/common/na-iio-provider.h
@@ -70,7 +70,7 @@ typedef struct {
* Returns: a hierarchical #GSList of menus, actions and
* profiles as #NAObject-derived objects.
*/
- GSList * ( *read_items_list ) ( const NAIIOProvider *instance );
+ GList * ( *read_items_list ) ( const NAIIOProvider *instance );
/**
* is_willing_to_write:
@@ -127,12 +127,12 @@ typedef struct {
}
NAIIOProviderInterface;
-GType na_iio_provider_get_type( void );
+GType na_iio_provider_get_type( void );
-GSList *na_iio_provider_get_items_tree( const NAPivot *pivot );
+GList *na_iio_provider_get_items_tree( const NAPivot *pivot );
/*GSList *na_iio_provider_sort_tree( const NAPivot *pivot, GSList *tree );*/
-guint na_iio_provider_write_item( const NAPivot *pivot, NAObject *item, gchar **message );
-guint na_iio_provider_delete_item( const NAPivot *pivot, const NAObject *item, gchar **message );
+guint na_iio_provider_write_item( const NAPivot *pivot, NAObject *item, gchar **message );
+guint na_iio_provider_delete_item( const NAPivot *pivot, const NAObject *item, gchar **message );
/* modification notification message to NAPivot
*/
diff --git a/src/common/na-obj-action.c b/src/common/na-obj-action.c
index bfd75b5..5f59982 100644
--- a/src/common/na-obj-action.c
+++ b/src/common/na-obj-action.c
@@ -515,7 +515,7 @@ object_copy( NAObject *target, const NAObject *source )
{
gchar *version;
gboolean readonly;
- GSList *profiles, *ip;
+ GList *profiles, *ip;
g_return_if_fail( NA_IS_OBJECT_ACTION( target ));
g_return_if_fail( !NA_OBJECT_ACTION( target )->private->dispose_has_run );
diff --git a/src/common/na-obj-menu.c b/src/common/na-obj-menu.c
index 68b1e97..07df11b 100644
--- a/src/common/na-obj-menu.c
+++ b/src/common/na-obj-menu.c
@@ -218,7 +218,7 @@ GSList *
na_object_menu_get_items_list( const NAObjectMenu *menu )
{
GSList *list = NULL;
- GSList *items, *it;
+ GList *items, *it;
gchar *uuid;
g_return_val_if_fail( NA_IS_OBJECT_MENU( menu ), NULL );
diff --git a/src/common/na-object-api.h b/src/common/na-object-api.h
index ac61cd9..9eab881 100644
--- a/src/common/na-object-api.h
+++ b/src/common/na-object-api.h
@@ -68,7 +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_new_id( object, id ) na_object_id_set_new_id( NA_OBJECT_ID( object ), id )
+#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 )
/* NAObjectItem
diff --git a/src/common/na-object-fn.h b/src/common/na-object-fn.h
index 659c9ac..b34f390 100644
--- a/src/common/na-object-fn.h
+++ b/src/common/na-object-fn.h
@@ -53,6 +53,9 @@ gchar *na_object_object_get_clipboard_id( const NAObject *object );
NAObject *na_object_object_ref( const NAObject *object );
void na_object_object_copy( NAObject *target, const NAObject *source );
+GList *na_object_get_hierarchy( const NAObject *object );
+void na_object_free_hierarchy( GList *hierarchy );
+
/* NAIDuplicable
*/
NAObject *na_object_iduplicable_duplicate( const NAObject *object );
diff --git a/src/common/na-object-id-class.h b/src/common/na-object-id-class.h
index 5bc5c7d..fbb54bb 100644
--- a/src/common/na-object-id-class.h
+++ b/src/common/na-object-id-class.h
@@ -63,6 +63,18 @@ typedef struct NAObjectIdClassPrivate NAObjectIdClassPrivate;
typedef struct {
NAObjectClass parent;
NAObjectIdClassPrivate *private;
+
+ /**
+ * new_id:
+ * @object: a #NAObjectId object.
+ *
+ * Returns: a new id suitable for this @object.
+ *
+ * This is a pure virtual function which should be implemented by
+ * the actual class. Actually, we asks for the most-derived class
+ * which implements this function.
+ */
+ gchar * ( *new_id )( const NAObjectId *object );
}
NAObjectIdClass;
diff --git a/src/common/na-object-id-fn.h b/src/common/na-object-id-fn.h
index a2e7ee2..932d4e5 100644
--- a/src/common/na-object-id-fn.h
+++ b/src/common/na-object-id-fn.h
@@ -51,6 +51,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_new_id( NAObjectId *object );
void na_object_id_set_label( NAObjectId *object, const gchar *label );
G_END_DECLS
diff --git a/src/common/na-object-id.c b/src/common/na-object-id.c
index 6a5676f..06a677b 100644
--- a/src/common/na-object-id.c
+++ b/src/common/na-object-id.c
@@ -34,6 +34,7 @@
#include <string.h>
+#include "na-object-fn.h"
#include "na-object-id-class.h"
#include "na-object-id-fn.h"
@@ -78,6 +79,9 @@ static void object_copy( NAObject *target, const NAObject *source );
static gboolean object_are_equal( const NAObject *a, const NAObject *b );
static gboolean object_is_valid( const NAObject *object );
+static gchar *v_new_id( NAObjectId *object );
+static gchar *most_derived_new_id( NAObjectId *object );
+
GType
na_object_id_get_type( void )
{
@@ -157,6 +161,8 @@ class_init( NAObjectIdClass *klass )
naobject_class->copy = object_copy;
naobject_class->are_equal = object_are_equal;
naobject_class->is_valid = object_is_valid;
+
+ klass->new_id = NULL;
}
static void
@@ -328,6 +334,28 @@ na_object_id_set_id( NAObjectId *object, const gchar *id )
}
/**
+ * na_object_id_set_new_id:
+ * @object: the #NAObjectId object whose internal identifiant is to be
+ * set.
+ *
+ * Request a new id to the derived class, and set it.
+ */
+void
+na_object_id_set_new_id( NAObjectId *object )
+{
+ gchar *id;
+
+ g_return_if_fail( NA_IS_OBJECT_ID( object ));
+ g_return_if_fail( !object->private->dispose_has_run );
+
+ id = v_new_id( object );
+
+ g_object_set( G_OBJECT( object ), NAOBJECT_ID_PROP_ID, id, NULL );
+
+ g_free( id );
+}
+
+/**
* na_object_id_set_label:
* @object: the #NAObjectId object whose label is to be set.
* @label: label to be set.
@@ -425,3 +453,32 @@ object_is_valid( const NAObject *object )
return( valid );
}
+
+static gchar *
+v_new_id( NAObjectId *object )
+{
+ return( most_derived_new_id( object ));
+}
+
+static gchar *
+most_derived_new_id( NAObjectId *object )
+{
+ gchar *new_id;
+ GList *hierarchy, *ih;
+ gboolean found;
+
+ found = FALSE;
+ new_id = NULL;
+ hierarchy = g_list_reverse( na_object_get_hierarchy( NA_OBJECT( 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;
+ }
+ }
+
+ na_object_free_hierarchy( hierarchy );
+
+ return( new_id );
+}
diff --git a/src/common/na-object-item-fn.h b/src/common/na-object-item-fn.h
index 2a00759..907c8d8 100644
--- a/src/common/na-object-item-fn.h
+++ b/src/common/na-object-item-fn.h
@@ -54,16 +54,16 @@ GdkPixbuf *na_object_item_get_pixbuf( const NAObjectItem *item, GtkWidget *w
gboolean na_object_item_is_enabled( const NAObjectItem *item );
NAIIOProvider *na_object_item_get_provider( const NAObjectItem *item );
NAObject *na_object_item_get_item( const NAObjectItem *item, const gchar *id );
-GSList *na_object_item_get_items( const NAObjectItem *item );
+GList *na_object_item_get_items( const NAObjectItem *item );
guint na_object_item_get_items_count( const NAObjectItem *item );
-void na_object_item_free_items( GSList *items );
+void na_object_item_free_items( GList *items );
void na_object_item_set_new_uuid( NAObjectItem *item );
void na_object_item_set_tooltip( NAObjectItem *item, const gchar *tooltip );
void na_object_item_set_icon( NAObjectItem *item, const gchar *icon_name );
void na_object_item_set_enabled( NAObjectItem *item, gboolean enabled );
void na_object_item_set_provider( NAObjectItem *item, const NAIIOProvider *provider );
-void na_object_item_set_items( NAObjectItem *item, GSList *items );
+void na_object_item_set_items( NAObjectItem *item, GList *items );
void na_object_item_append_item( NAObjectItem *item, const NAObject *object );
void na_object_item_insert_item( NAObjectItem *item, const NAObject *object );
diff --git a/src/common/na-object-item.c b/src/common/na-object-item.c
index d539139..2a0cd4b 100644
--- a/src/common/na-object-item.c
+++ b/src/common/na-object-item.c
@@ -59,7 +59,7 @@ struct NAObjectItemPrivate {
/* list of NAObjectId subitems
*/
- GSList *items;
+ GList *items;
/* the original provider
* required to be able to edit/delete the item
@@ -99,6 +99,8 @@ static void object_copy( NAObject *target, const NAObject *source );
static gboolean object_are_equal( const NAObject *a, const NAObject *b );
static gboolean object_is_valid( const NAObject *object );
+static gchar *object_id_new_id( const NAObjectId *object );
+
GType
na_object_item_get_type( void )
{
@@ -139,6 +141,7 @@ class_init( NAObjectItemClass *klass )
static const gchar *thisfn = "na_object_item_class_init";
GObjectClass *object_class;
NAObjectClass *naobject_class;
+ NAObjectIdClass *objectid_class;
GParamSpec *spec;
g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
@@ -189,6 +192,9 @@ class_init( NAObjectItemClass *klass )
naobject_class->copy = object_copy;
naobject_class->are_equal = object_are_equal;
naobject_class->is_valid = object_is_valid;
+
+ objectid_class = NA_OBJECT_ID_CLASS( klass );
+ objectid_class->new_id = object_id_new_id;
}
static void
@@ -482,7 +488,7 @@ na_object_item_get_provider( const NAObjectItem *item )
NAObject *
na_object_item_get_item( const NAObjectItem *item, const gchar *id )
{
- GSList *it;
+ GList *it;
NAObject *found = NULL;
NAObject *isub;
gchar *isubid;
@@ -506,27 +512,27 @@ na_object_item_get_item( const NAObjectItem *item, const gchar *id )
* na_object_item_get_items:
* @item: the #NAObjectItem from which we want a list of subitems.
*
- * Returns: a newly allocated #GSList of #NAObject objects which are
+ * Returns: a newly allocated #GList of #NAObject objects which are
* embedded in the @item. Depending of the exact nature of @item, these
* may be #NAObjectMenu, #NAObjectAction or #NAObjectProfile subitems.
*
- * The returned pointer should be na_object_item_free_items() by the
- * caller.
+ * The returned pointer should be na_object_item_free_items() or
+ * na_object_free_items() by the caller.
*/
-GSList *
+GList *
na_object_item_get_items( const NAObjectItem *item )
{
- GSList *items, *it;
+ GList *items, *it;
g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), NULL );
g_return_val_if_fail( !item->private->dispose_has_run, NULL );
items = NULL;
for( it = item->private->items ; it ; it = it->next ){
- items = g_slist_prepend( items, g_object_ref( it->data ));
+ items = g_list_prepend( items, g_object_ref( it->data ));
}
- return( g_slist_reverse( items ));
+ return( g_list_reverse( items ));
}
/**
@@ -541,7 +547,7 @@ na_object_item_get_items_count( const NAObjectItem *item )
g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), 0 );
g_return_val_if_fail( !item->private->dispose_has_run, 0 );
- return( item->private->items ? g_slist_length( item->private->items ) : 0 );
+ return( item->private->items ? g_list_length( item->private->items ) : 0 );
}
/**
@@ -552,10 +558,10 @@ na_object_item_get_items_count( const NAObjectItem *item )
* Frees the list.
*/
void
-na_object_item_free_items( GSList *items )
+na_object_item_free_items( GList *items )
{
- g_slist_foreach( items, ( GFunc ) g_object_unref, NULL );
- g_slist_free( items );
+ g_list_foreach( items, ( GFunc ) g_object_unref, NULL );
+ g_list_free( items );
}
/**
@@ -677,7 +683,7 @@ na_object_item_set_provider( NAObjectItem *item, const NAIIOProvider *provider )
/**
* na_object_item_set_items:
* @item: the #NAObjectItem whose subitems have to be set.
- * @list: a #GSList list of #NAObject subitems to be installed.
+ * @list: a #GList list of #NAObject subitems to be installed.
*
* Sets the list of the subitems for the @item.
*
@@ -687,9 +693,9 @@ na_object_item_set_provider( NAObjectItem *item, const NAIIOProvider *provider )
* by the caller.
*/
void
-na_object_item_set_items( NAObjectItem *item, GSList *items )
+na_object_item_set_items( NAObjectItem *item, GList *items )
{
- GSList *it;
+ GList *it;
g_return_if_fail( NA_IS_OBJECT_ITEM( item ));
g_return_if_fail( !item->private->dispose_has_run );
@@ -698,9 +704,9 @@ na_object_item_set_items( NAObjectItem *item, GSList *items )
item->private->items = NULL;
for( it = items ; it ; it = it->next ){
- item->private->items = g_slist_prepend( item->private->items, g_object_ref( it->data ));
+ item->private->items = g_list_prepend( item->private->items, g_object_ref( it->data ));
}
- item->private->items = g_slist_reverse( item->private->items );
+ item->private->items = g_list_reverse( item->private->items );
}
/**
@@ -719,7 +725,7 @@ na_object_item_append_item( NAObjectItem *item, const NAObject *object )
g_return_if_fail( !item->private->dispose_has_run );
g_return_if_fail( NA_IS_OBJECT( object ));
- item->private->items = g_slist_append( item->private->items, g_object_ref(( gpointer ) object ));
+ item->private->items = g_list_append( item->private->items, g_object_ref(( gpointer ) object ));
}
/**
@@ -739,7 +745,7 @@ na_object_item_insert_item( NAObjectItem *item, const NAObject *object )
g_return_if_fail( !item->private->dispose_has_run );
g_return_if_fail( NA_IS_OBJECT( object ));
- item->private->items = g_slist_prepend( item->private->items, g_object_ref(( gpointer ) object ));
+ item->private->items = g_list_prepend( item->private->items, g_object_ref(( gpointer ) object ));
}
/**
@@ -758,7 +764,7 @@ na_object_item_remove_item( NAObjectItem *item, NAObject *object )
g_return_if_fail( !item->private->dispose_has_run );
g_return_if_fail( NA_IS_OBJECT( object ));
- item->private->items = g_slist_remove( item->private->items, ( gconstpointer ) object );
+ item->private->items = g_list_remove( item->private->items, ( gconstpointer ) object );
g_object_unref( object );
}
@@ -766,7 +772,7 @@ static void
object_dump( const NAObject *item )
{
static const gchar *thisfn = "na_object_item_object_dump";
- GSList *it;
+ GList *it;
g_return_if_fail( NA_IS_OBJECT_ITEM( item ));
g_return_if_fail( !NA_OBJECT_ITEM( item )->private->dispose_has_run );
@@ -779,7 +785,7 @@ object_dump( const NAObject *item )
/* dump subitems */
g_debug( "%s: %d subitem(s) at %p",
thisfn,
- NA_OBJECT_ITEM( item )->private->items ? g_slist_length( NA_OBJECT_ITEM( item )->private->items ) : 0,
+ NA_OBJECT_ITEM( item )->private->items ? g_list_length( NA_OBJECT_ITEM( item )->private->items ) : 0,
( void * ) NA_OBJECT_ITEM( item )->private->items );
for( it = NA_OBJECT_ITEM( item )->private->items ; it ; it = it->next ){
@@ -790,7 +796,7 @@ object_dump( const NAObject *item )
static void
object_ref( const NAObject *item )
{
- g_slist_foreach( NA_OBJECT_ITEM( item )->private->items, ( GFunc ) g_object_ref, NULL );
+ g_list_foreach( NA_OBJECT_ITEM( item )->private->items, ( GFunc ) g_object_ref, NULL );
}
static void
@@ -799,7 +805,7 @@ object_copy( NAObject *target, const NAObject *source )
gchar *tooltip, *icon;
gboolean enabled;
gpointer provider;
- GSList *subitems, *it;
+ GList *subitems, *it;
g_return_if_fail( NA_IS_OBJECT_ITEM( target ));
g_return_if_fail( !NA_OBJECT_ITEM( target )->private->dispose_has_run );
@@ -825,9 +831,9 @@ object_copy( NAObject *target, const NAObject *source )
subitems = NULL;
for( it = NA_OBJECT_ITEM( source )->private->items ; it ; it = it->next ){
- subitems = g_slist_prepend( subitems, na_object_duplicate( it->data ));
+ subitems = g_list_prepend( subitems, na_object_duplicate( it->data ));
}
- subitems = g_slist_reverse( subitems );
+ subitems = g_list_reverse( subitems );
na_object_set_items( target, subitems );
na_object_free_items( subitems );
@@ -841,7 +847,7 @@ static gboolean
object_are_equal( const NAObject *a, const NAObject *b )
{
gboolean equal = TRUE;
- GSList *it;
+ GList *it;
NAObject *first_obj, *second_obj;
gchar *first_id, *second_id;
@@ -862,7 +868,7 @@ object_are_equal( const NAObject *a, const NAObject *b )
}
if( equal ){
- equal = ( g_slist_length( NA_OBJECT_ITEM( a )->private->items ) == g_slist_length( NA_OBJECT_ITEM( b )->private->items ));
+ equal = ( g_list_length( NA_OBJECT_ITEM( a )->private->items ) == g_list_length( NA_OBJECT_ITEM( b )->private->items ));
}
if( equal ){
@@ -893,7 +899,7 @@ object_are_equal( const NAObject *a, const NAObject *b )
}
}
- g_debug( "na_object_item_are_equal: %s", equal ? "True":"False" );
+ /*g_debug( "na_object_item_are_equal: %s", equal ? "True":"False" );*/
return( equal );
}
@@ -904,7 +910,7 @@ static gboolean
object_is_valid( const NAObject *object )
{
gboolean valid = TRUE;
- GSList *it;
+ GList *it;
g_return_val_if_fail( NA_IS_OBJECT_ITEM( object ), FALSE );
g_return_val_if_fail( !NA_OBJECT_ITEM( object )->private->dispose_has_run, FALSE );
@@ -917,3 +923,20 @@ object_is_valid( const NAObject *object )
return( valid );
}
+
+static gchar *
+object_id_new_id( const NAObjectId *item )
+{
+ uuid_t uuid;
+ gchar uuid_str[64];
+ gchar *new_uuid;
+
+ g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), NULL );
+ g_return_val_if_fail( !NA_OBJECT_ITEM( item )->private->dispose_has_run, NULL );
+
+ uuid_generate( uuid );
+ uuid_unparse_lower( uuid, uuid_str );
+ new_uuid = g_strdup( uuid_str );
+
+ return( new_uuid );
+}
diff --git a/src/common/na-object.c b/src/common/na-object.c
index 3746a8a..69b159d 100644
--- a/src/common/na-object.c
+++ b/src/common/na-object.c
@@ -83,9 +83,6 @@ static gboolean do_is_valid( const NAObject *object );
static void do_copy( NAObject *target, const NAObject *source );
-static GSList *get_hierarchy( const NAObject *object );
-static void free_hierarchy( GSList *hierarchy );
-
GType
na_object_get_type( void )
{
@@ -257,9 +254,9 @@ na_object_object_dump( const NAObject *object )
static void
dump_hierarchy( const NAObject *object )
{
- GSList *hierarchy, *ih;
+ GList *hierarchy, *ih;
- hierarchy = get_hierarchy( object );
+ hierarchy = na_object_get_hierarchy( object );
for( ih = hierarchy ; ih ; ih = ih->next ){
if( NA_OBJECT_CLASS( ih->data )->dump ){
@@ -267,7 +264,7 @@ dump_hierarchy( const NAObject *object )
}
}
- free_hierarchy( hierarchy );
+ na_object_free_hierarchy( hierarchy );
}
static void
@@ -302,12 +299,12 @@ static gchar *
most_derived_clipboard_id( const NAObject *object )
{
gchar *clipboard_id;
- GSList *hierarchy, *ih;
+ GList *hierarchy, *ih;
gboolean found;
found = FALSE;
clipboard_id = NULL;
- hierarchy = g_slist_reverse( get_hierarchy( object ));
+ hierarchy = g_list_reverse( na_object_get_hierarchy( object ));
for( ih = hierarchy ; ih && !found ; ih = ih->next ){
if( NA_OBJECT_CLASS( ih->data )->get_clipboard_id ){
@@ -316,7 +313,7 @@ most_derived_clipboard_id( const NAObject *object )
}
}
- free_hierarchy( hierarchy );
+ na_object_free_hierarchy( hierarchy );
return( clipboard_id );
}
@@ -344,9 +341,9 @@ na_object_object_ref( const NAObject *object )
static void
ref_hierarchy( const NAObject *object )
{
- GSList *hierarchy, *ih;
+ GList *hierarchy, *ih;
- hierarchy = get_hierarchy( object );
+ hierarchy = na_object_get_hierarchy( object );
for( ih = hierarchy ; ih ; ih = ih->next ){
if( NA_OBJECT_CLASS( ih->data )->ref ){
@@ -354,7 +351,7 @@ ref_hierarchy( const NAObject *object )
}
}
- free_hierarchy( hierarchy );
+ na_object_free_hierarchy( hierarchy );
}
/**
@@ -412,12 +409,12 @@ static NAObject *
most_derived_new( const NAObject *object )
{
NAObject *new_object;
- GSList *hierarchy, *ih;
+ GList *hierarchy, *ih;
gboolean found;
found = FALSE;
new_object = NULL;
- hierarchy = g_slist_reverse( get_hierarchy( object ));
+ hierarchy = g_list_reverse( na_object_get_hierarchy( object ));
for( ih = hierarchy ; ih && !found ; ih = ih->next ){
if( NA_OBJECT_CLASS( ih->data )->new ){
@@ -426,7 +423,7 @@ most_derived_new( const NAObject *object )
}
}
- free_hierarchy( hierarchy );
+ na_object_free_hierarchy( hierarchy );
return( new_object );
}
@@ -463,9 +460,9 @@ iduplicable_copy( NAIDuplicable *target, const NAIDuplicable *source )
static void
copy_hierarchy( NAObject *target, const NAObject *source )
{
- GSList *hierarchy, *ih;
+ GList *hierarchy, *ih;
- hierarchy = get_hierarchy( source );
+ hierarchy = na_object_get_hierarchy( source );
for( ih = hierarchy ; ih ; ih = ih->next ){
if( NA_OBJECT_CLASS( ih->data )->copy ){
@@ -473,7 +470,7 @@ copy_hierarchy( NAObject *target, const NAObject *source )
}
}
- free_hierarchy( hierarchy );
+ na_object_free_hierarchy( hierarchy );
}
static void
@@ -483,6 +480,39 @@ do_copy( NAObject *target, const NAObject *source )
}
/**
+ * na_object_get_hierarchy:
+ *
+ * Returns the class hierarchy,
+ * from the topmost base class, to the most-derived one.
+ */
+GList *
+na_object_get_hierarchy( const NAObject *object )
+{
+ GList *hierarchy;
+ GObjectClass *class;
+
+ hierarchy = NULL;
+ class = G_OBJECT_GET_CLASS( object );
+
+ while( G_OBJECT_CLASS_TYPE( class ) != NA_OBJECT_TYPE ){
+ hierarchy = g_list_prepend( hierarchy, class );
+ class = g_type_class_peek_parent( class );
+ }
+ hierarchy = g_list_prepend( hierarchy, class );
+
+ return( hierarchy );
+}
+
+/**
+ * na_object_free_hierarchy:
+ */
+void
+na_object_free_hierarchy( GList *hierarchy )
+{
+ g_list_free( hierarchy );
+}
+
+/**
* na_object_iduplicable_are_equal:
* @a: a first #NAObject object.
* @b: a second #NAObject object to be compared to the first one.
@@ -521,10 +551,10 @@ static gboolean
are_equal_hierarchy( const NAObject *a, const NAObject *b )
{
gboolean are_equal;
- GSList *hierarchy, *ih;
+ GList *hierarchy, *ih;
are_equal = TRUE;
- hierarchy = get_hierarchy( b );
+ hierarchy = na_object_get_hierarchy( b );
for( ih = hierarchy ; ih && are_equal ; ih = ih->next ){
if( NA_OBJECT_CLASS( ih->data )->are_equal ){
@@ -532,7 +562,7 @@ are_equal_hierarchy( const NAObject *a, const NAObject *b )
}
}
- free_hierarchy( hierarchy );
+ na_object_free_hierarchy( hierarchy );
return( are_equal );
}
@@ -559,10 +589,10 @@ static gboolean
is_valid_hierarchy( const NAObject *object )
{
gboolean is_valid;
- GSList *hierarchy, *ih;
+ GList *hierarchy, *ih;
is_valid = TRUE;
- hierarchy = get_hierarchy( object );
+ hierarchy = na_object_get_hierarchy( object );
for( ih = hierarchy ; ih && is_valid ; ih = ih->next ){
if( NA_OBJECT_CLASS( ih->data )->is_valid ){
@@ -570,7 +600,7 @@ is_valid_hierarchy( const NAObject *object )
}
}
- free_hierarchy( hierarchy );
+ na_object_free_hierarchy( hierarchy );
return( is_valid );
}
@@ -681,31 +711,3 @@ na_object_iduplicable_set_origin( NAObject *object, const NAObject *origin )
na_iduplicable_set_origin( NA_IDUPLICABLE( object ), NA_IDUPLICABLE( origin ));
}
-
-/*
- * returns the class hierarchy,
- * from the topmost base class, to the most-derived one.
- */
-static GSList *
-get_hierarchy( const NAObject *object )
-{
- GSList *hierarchy;
- GObjectClass *class;
-
- hierarchy = NULL;
- class = G_OBJECT_GET_CLASS( object );
-
- while( G_OBJECT_CLASS_TYPE( class ) != NA_OBJECT_TYPE ){
- hierarchy = g_slist_prepend( hierarchy, class );
- class = g_type_class_peek_parent( class );
- }
- hierarchy = g_slist_prepend( hierarchy, class );
-
- return( hierarchy );
-}
-
-static void
-free_hierarchy( GSList *hierarchy )
-{
- g_slist_free( hierarchy );
-}
diff --git a/src/common/na-pivot.c b/src/common/na-pivot.c
index fb6d956..8553524 100644
--- a/src/common/na-pivot.c
+++ b/src/common/na-pivot.c
@@ -68,7 +68,7 @@ struct NAPivotPrivate {
/* configuration tree
*/
- GSList *tree;
+ GList *tree;
/* whether to automatically reload the whole configuration tree
* when a modification has been detected in one of the underlying
@@ -341,12 +341,12 @@ void
na_pivot_dump( const NAPivot *pivot )
{
static const gchar *thisfn = "na_pivot_dump";
- GSList *it;
+ GList *it;
int i;
g_debug( "%s: consumers=%p (%d elts)", thisfn, ( void * ) pivot->private->consumers, g_slist_length( pivot->private->consumers ));
g_debug( "%s: providers=%p (%d elts)", thisfn, ( void * ) pivot->private->providers, g_slist_length( pivot->private->providers ));
- g_debug( "%s: tree=%p (%d elts)", thisfn, ( void * ) pivot->private->tree, g_slist_length( pivot->private->tree ));
+ g_debug( "%s: tree=%p (%d elts)", thisfn, ( void * ) pivot->private->tree, g_list_length( pivot->private->tree ));
for( it = pivot->private->tree, i = 0 ; it ; it = it->next ){
g_debug( "%s: [%d]: %p", thisfn, i++, it->data );
@@ -408,7 +408,7 @@ na_pivot_free_providers( GSList *providers )
* The returned list is owned by this #NAPivot object, and should not
* be g_free(), nor g_object_unref() by the caller.
*/
-GSList *
+GList *
na_pivot_get_items( const NAPivot *pivot )
{
g_return_val_if_fail( NA_IS_PIVOT( pivot ), NULL );
@@ -451,7 +451,7 @@ na_pivot_add_item( NAPivot *pivot, const NAObject *item )
g_return_if_fail( !pivot->private->dispose_has_run );
g_return_if_fail( NA_IS_OBJECT_ITEM( item ));
- pivot->private->tree = g_slist_append( pivot->private->tree, ( gpointer ) item );
+ pivot->private->tree = g_list_append( pivot->private->tree, ( gpointer ) item );
}
/**
@@ -470,7 +470,7 @@ na_pivot_remove_item( NAPivot *pivot, NAObject *item )
g_return_if_fail( !pivot->private->dispose_has_run );
g_return_if_fail( NA_IS_OBJECT_ITEM( item ));
- pivot->private->tree = g_slist_remove( pivot->private->tree, ( gconstpointer ) item );
+ pivot->private->tree = g_list_remove( pivot->private->tree, ( gconstpointer ) item );
g_object_unref( item );
}
@@ -489,7 +489,7 @@ NAObject *
na_pivot_get_item( const NAPivot *pivot, const gchar *uuid )
{
uuid_t uua, i_uub;
- GSList *ia;
+ GList *ia;
g_return_val_if_fail( NA_IS_PIVOT( pivot ), NULL );
g_return_val_if_fail( !pivot->private->dispose_has_run, NULL );
diff --git a/src/common/na-pivot.h b/src/common/na-pivot.h
index ba2cbc4..51b7e8a 100644
--- a/src/common/na-pivot.h
+++ b/src/common/na-pivot.h
@@ -110,7 +110,7 @@ void na_pivot_dump( const NAPivot *pivot );
GSList *na_pivot_get_providers( const NAPivot *pivot, GType type );
void na_pivot_free_providers( GSList *providers );
-GSList *na_pivot_get_items( const NAPivot *pivot );
+GList *na_pivot_get_items( const NAPivot *pivot );
void na_pivot_reload_items( NAPivot *pivot );
void na_pivot_add_item( NAPivot *pivot, const NAObject *item );
diff --git a/src/common/na-xml-writer.c b/src/common/na-xml-writer.c
index 968405b..b8e540c 100644
--- a/src/common/na-xml-writer.c
+++ b/src/common/na-xml-writer.c
@@ -516,7 +516,7 @@ create_xml_schema( NAXMLWriter *writer, gint format, const NAObjectAction *actio
xmlNodePtr root_node, list_node;
gchar *version, *label, *tooltip, *icon, *text;
gboolean enabled;
- GSList *profiles, *ip;
+ GList *profiles, *ip;
NAObjectProfile *profile;
gchar *profile_dir, *profile_label, *path, *parameters;
GSList *basenames, *mimetypes, *schemes;
@@ -697,7 +697,7 @@ create_xml_dump( NAXMLWriter *writer, gint format, const NAObjectAction *action
gchar *path;
gchar *version, *label, *tooltip, *icon, *text;
gboolean enabled;
- GSList *profiles, *ip;
+ GList *profiles, *ip;
NAObjectProfile *profile;
gchar *profile_dir;
gchar *profile_label, *parameters;
diff --git a/src/nact/nact-assistant-export.c b/src/nact/nact-assistant-export.c
index b18f8da..b17e18e 100644
--- a/src/nact/nact-assistant-export.c
+++ b/src/nact/nact-assistant-export.c
@@ -401,7 +401,7 @@ assistant_apply( BaseAssistant *wnd, GtkAssistant *assistant )
{
static const gchar *thisfn = "nact_assistant_export_on_apply";
NactAssistantExport *window;
- GSList *actions, *ia;
+ GList *actions, *ia;
gchar *msg = NULL;
gchar *reason = NULL;
gchar *tmp, *fname;
@@ -439,14 +439,14 @@ assistant_apply( BaseAssistant *wnd, GtkAssistant *assistant )
}
}
+ na_object_free_items( actions );
+
if( window->private->errors ){
if( !reason ){
reason = g_strdup( _( "You may not have writing permissions on selected folder." ));
}
window->private->reason = reason;
}
-
- g_slist_free( actions );
}
static void
@@ -503,7 +503,7 @@ assist_runtime_init_actions_list( NactAssistantExport *window, GtkAssistant *ass
GtkWidget *content;
NactApplication *appli;
NAPivot *pivot;
- GSList *tree;
+ GList *tree;
appli = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
pivot = nact_application_get_pivot( appli );
@@ -710,7 +710,7 @@ assist_prepare_confirm( NactAssistantExport *window, GtkAssistant *assistant, Gt
static const gchar *thisfn = "nact_assistant_export_prepare_confirm";
gchar *text, *tmp, *text2;
gchar *label1, *label2;
- GSList *actions, *ia;
+ GList *actions, *ia;
g_debug( "%s: window=%p, assistant=%p, page=%p",
thisfn, ( void * ) window, ( void * ) assistant, ( void * ) page );
@@ -733,6 +733,8 @@ assist_prepare_confirm( NactAssistantExport *window, GtkAssistant *assistant, Gt
text = tmp;
}
+ na_object_free_items( actions );
+
g_assert( window->private->uri && strlen( window->private->uri ));
/* i18n: all exported actions go to one destination folder */
diff --git a/src/nact/nact-clipboard.c b/src/nact/nact-clipboard.c
index c2e549a..cd78ef6 100644
--- a/src/nact/nact-clipboard.c
+++ b/src/nact/nact-clipboard.c
@@ -37,6 +37,7 @@
#include <common/na-object-api.h>
#include <common/na-obj-action-class.h>
+#include <common/na-obj-menu.h>
#include <common/na-obj-profile.h>
#include <common/na-xml-names.h>
#include <common/na-xml-writer.h>
@@ -67,19 +68,21 @@ static GtkTargetEntry clipboard_formats[] = {
};
typedef struct {
- gboolean only_profiles;
- GSList *items;
+ guint nb_profiles;
+ guint nb_actions;
+ guint nb_menus;
+ GList *items;
}
NactClipboardData;
static GtkClipboard *get_clipboard( void );
-static gboolean have_only_profiles( GSList *items );
-static void add_item_to_clipboard0( NAObject *object, gboolean copy_data, gboolean only_profiles, GSList **copied );
-static void add_item_to_clipboard( NAObject *object, GSList **copied );
+static void add_item_to_clipboard0( NAObject *object, gboolean copy_data, gboolean only_profiles, GList **copied );
+/*static void add_item_to_clipboard( NAObject *object, GList **copied );*/
static void export_action( const gchar *uri, const NAObject *action, GSList **exported );
static gchar *get_action_xml_buffer( const NAObject *action, GSList **exported );
static void get_from_clipboard_callback( GtkClipboard *clipboard, GtkSelectionData *selection_data, guint info, guchar *data );
static void clear_clipboard_callback( GtkClipboard *clipboard, NactClipboardData *data );
+static void renumber_items( GList *items );
/**
* nact_clipboard_get_data_for_intern_use:
@@ -90,23 +93,23 @@ static void clear_clipboard_callback( GtkClipboard *clipboard, NactClip
* able to paste them when needed.
*/
void
-nact_clipboard_get_data_for_intern_use( GSList *selected_items, gboolean copy_data )
+nact_clipboard_get_data_for_intern_use( GList *selected_items, gboolean copy_data )
{
static const gchar *thisfn = "nact_clipboard_get_data_for_intern_use";
GtkClipboard *clipboard;
NactClipboardData *data;
- GSList *item;
+ GList *it;
clipboard = get_clipboard();
data = g_new0( NactClipboardData, 1 );
- data->only_profiles = have_only_profiles( selected_items );
+ /*data->only_profiles = have_only_profiles( selected_items );*/
- for( item = selected_items ; item ; item = item->next ){
- NAObject *item_object = NA_OBJECT( item->data );
- add_item_to_clipboard0( item_object, copy_data, data->only_profiles, &data->items );
+ for( it = selected_items ; it ; it = it->next ){
+ NAObject *item_object = NA_OBJECT( it->data );
+ add_item_to_clipboard0( item_object, copy_data, FALSE /*data->only_profiles*/, &data->items );
}
- data->items = g_slist_reverse( data->items );
+ data->items = g_list_reverse( data->items );
gtk_clipboard_set_with_data( clipboard,
clipboard_formats, G_N_ELEMENTS( clipboard_formats ),
@@ -129,17 +132,17 @@ nact_clipboard_get_data_for_intern_use( GSList *selected_items, gboolean copy_da
* For now, we only exports actions as XML files.
*/
char *
-nact_clipboard_get_data_for_extern_use( GSList *selected_items )
+nact_clipboard_get_data_for_extern_use( GList *selected_items )
{
- GSList *item;
+ GList *it;
GSList *exported = NULL;
GString *data;
gchar *chunk;
data = g_string_new( "" );
- for( item = selected_items ; item ; item = item->next ){
- NAObject *item_object = NA_OBJECT( item->data );
+ for( it = selected_items ; it ; it = it->next ){
+ NAObject *item_object = NA_OBJECT( it->data );
chunk = NULL;
if( NA_IS_OBJECT_ACTION( item_object )){
@@ -170,13 +173,13 @@ nact_clipboard_get_data_for_extern_use( GSList *selected_items )
* For now, we only exports actions as XML files.
*/
void
-nact_clipboard_export_items( const gchar *uri, GSList *items )
+nact_clipboard_export_items( const gchar *uri, GList *items )
{
- GSList *item;
+ GList *it;
GSList *exported = NULL;
- for( item = items ; item ; item = item->next ){
- NAObject *item_object = NA_OBJECT( item->data );
+ for( it = items ; it ; it = it->next ){
+ NAObject *item_object = NA_OBJECT( it->data );
if( NA_IS_OBJECT_ACTION( item_object )){
export_action( uri, item_object, &exported );
@@ -213,19 +216,19 @@ nact_clipboard_is_empty( void )
/**
* nact_clipboard_get:
*
- * Returns: the list of items previously referenced in the internal
- * clipboard.
+ * Returns: a copy of the list of items previously referenced in the
+ * internal clipboard.
*
- * The list is owned by the clipboard, and should not be g_free() nor
- * g_object_unref() by the caller.
+ * We allocate a new id for items in order to be ready to paste another
+ * time.
*/
-GSList *
+GList *
nact_clipboard_get( void )
{
GtkClipboard *clipboard;
GtkSelectionData *selection;
NactClipboardData *data;
- /*GSList *items;*/
+ GList *items, *it;
if( nact_clipboard_is_empty()){
return( NULL );
@@ -235,39 +238,65 @@ nact_clipboard_get( void )
selection = gtk_clipboard_wait_for_contents( clipboard, GDK_SELECTION_PRIMARY );
data = ( NactClipboardData * ) selection->data;
- /* prepare the next paste by renumeroting the ids */
- /*for( it = items ; it ; it = it->next ){
- na_object_set_new_id( it->data );
- }*/
+ items = NULL;
+ for( it = data->items ; it ; it = it->next ){
+ items = g_list_prepend( items, na_object_duplicate( it->data ));
+ }
+
+ renumber_items( data->items );
- return( data->items );
+ return( g_list_reverse( items ));
}
/**
* nact_clipboard_set:
* @items: a list of #NAObject items
+ * @renumber_items: whether the actions or menus items should be
+ * renumbered when copied in the clipboard ?
+ *
+ * Installs a copy of provided items in the clipboard.
*
- * Takes a reference on the specified list of items, and installs them
- * in the internal clipboard.
+ * Rationale: when cutting an item to the clipboard, the next paste
+ * will keep its same original id, and it is safe because this is
+ * actually what we we want when we cut/paste.
+ *
+ * Contrarily, when we copy/paste, we are waiting for a new element
+ * which has the same characteristics that the previous one ; we so
+ * have to renumber actions/menus items when copying into the clipboard.
+ *
+ * Note that we use NAIDuplicable interface without actually taking care
+ * of what is origin or so, as origin will be reinitialized when getting
+ * data out of the clipboard.
*/
void
-nact_clipboard_set( GSList *items )
+nact_clipboard_set( GList *items, gboolean renumber )
{
GtkClipboard *clipboard;
NactClipboardData *data;
- GSList *it;
+ GList *it;
clipboard = get_clipboard();
-
gtk_clipboard_clear( clipboard );
-
data = g_new0( NactClipboardData, 1 );
- data->only_profiles = have_only_profiles( items );
for( it = items ; it ; it = it->next ){
- add_item_to_clipboard( NA_OBJECT( it->data ), &data->items );
+ 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( data->items );
}
- data->items = g_slist_reverse( data->items );
gtk_clipboard_set_with_data( clipboard,
clipboard_formats, G_N_ELEMENTS( clipboard_formats ),
@@ -290,24 +319,8 @@ get_clipboard( void )
return( clipboard );
}
-static gboolean
-have_only_profiles( GSList *items )
-{
- GSList *item;
- gboolean only_profiles = TRUE;
-
- for( item = items ; item ; item = item->next ){
- if( !NA_IS_OBJECT_PROFILE( item->data )){
- only_profiles = FALSE;
- break;
- }
- }
-
- return( only_profiles );
-}
-
static void
-add_item_to_clipboard0( NAObject *object, gboolean copy_data, gboolean only_profiles, GSList **items_list )
+add_item_to_clipboard0( NAObject *object, gboolean copy_data, gboolean only_profiles, GList **items_list )
{
NAObject *source;
gint index;
@@ -317,19 +330,19 @@ add_item_to_clipboard0( NAObject *object, gboolean copy_data, gboolean only_prof
source = NA_OBJECT( na_object_profile_get_action( NA_OBJECT_PROFILE( object )));
}
- index = g_slist_index( *items_list, ( gconstpointer ) source );
+ index = g_list_index( *items_list, ( gconstpointer ) source );
if( index != -1 ){
return;
}
- *items_list = g_slist_prepend( *items_list, na_object_ref( source ));
+ *items_list = g_list_prepend( *items_list, na_object_ref( source ));
}
-static void
-add_item_to_clipboard( NAObject *object, GSList **items_list )
+/*static void
+add_item_to_clipboard( NAObject *object, GList **items_list )
{
- *items_list = g_slist_prepend( *items_list, na_object_ref( object ));
-}
+ *items_list = g_list_prepend( *items_list, na_object_ref( object ));
+}*/
static void
export_action( const gchar *uri, const NAObject *action, GSList **exported )
@@ -390,9 +403,21 @@ clear_clipboard_callback( GtkClipboard *clipboard, NactClipboardData *data )
g_debug( "%s: clipboard=%p, data=%p", thisfn, ( void * ) clipboard, ( void * ) data );
- g_slist_foreach( data->items, ( GFunc ) g_object_unref, NULL );
- g_slist_free( data->items );
+ g_list_foreach( data->items, ( GFunc ) g_object_unref, NULL );
+ g_list_free( data->items );
g_free( data );
g_object_set_data( G_OBJECT( clipboard ), CLIPBOARD_PROP_PRIMAY_USED, GINT_TO_POINTER( FALSE ));
}
+
+static void
+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 ));
+ }
+ }
+}
diff --git a/src/nact/nact-clipboard.h b/src/nact/nact-clipboard.h
index dbffec8..b47eaf0 100644
--- a/src/nact/nact-clipboard.h
+++ b/src/nact/nact-clipboard.h
@@ -35,16 +35,16 @@
G_BEGIN_DECLS
-void nact_clipboard_get_data_for_intern_use( GSList *selected_items, gboolean copy_data );
-char *nact_clipboard_get_data_for_extern_use( GSList *selected_items );
+void nact_clipboard_get_data_for_intern_use( GList *selected_items, gboolean copy_data );
+char *nact_clipboard_get_data_for_extern_use( GList *selected_items );
gboolean nact_clipboard_is_empty( void );
-GSList *nact_clipboard_get( void );
-void nact_clipboard_set( GSList *items );
+GList *nact_clipboard_get( void );
+void nact_clipboard_set( GList *items, gboolean renumber_items );
void nact_clipboard_free_items( GSList *items );
-void nact_clipboard_export_items( const gchar *uri, GSList *items );
+void nact_clipboard_export_items( const gchar *uri, GList *items );
G_END_DECLS
diff --git a/src/nact/nact-iactions-list.c b/src/nact/nact-iactions-list.c
index 7e794f8..9bea2ab 100644
--- a/src/nact/nact-iactions-list.c
+++ b/src/nact/nact-iactions-list.c
@@ -97,7 +97,7 @@ static GType register_type( void );
static void interface_base_init( NactIActionsListInterface *klass );
static void interface_base_finalize( NactIActionsListInterface *klass );
-static void free_items_callback( NactIActionsList *instance, GSList *items );
+static void free_items_callback( NactIActionsList *instance, GList *items );
static void display_label( GtkTreeViewColumn *column, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter, NactIActionsList *instance );
static void extend_selection_to_childs( NactIActionsList *instance, GtkTreeView *treeview, GtkTreeModel *model, GtkTreeIter *parent );
@@ -108,7 +108,7 @@ static gboolean get_item( NactTreeModel *model, GtkTreePath *path, NAObject
static gboolean have_dnd_mode( NactIActionsList *instance );
static gboolean have_filter_selection_mode( NactIActionsList *instance );
static void insert_item( NactIActionsList *instance, NAObject *item );
-static gboolean is_modified_item( NactTreeModel *model, GtkTreePath *path, NAObject *object, GSList **items );
+static gboolean is_modified_item( NactTreeModel *model, GtkTreePath *path, NAObject *object, GList **items );
static void iter_on_selection( NactIActionsList *instance, FnIterOnSelection fn_iter, gpointer user_data );
static gboolean on_button_press_event( GtkWidget *widget, GdkEventButton *event, NactIActionsList *instance );
static gboolean on_key_pressed_event( GtkWidget *widget, GdkEventKey *event, NactIActionsList *instance );
@@ -224,7 +224,7 @@ interface_base_init( NactIActionsListInterface *klass )
}
static void
-free_items_callback( NactIActionsList *instance, GSList *items )
+free_items_callback( NactIActionsList *instance, GList *items )
{
na_object_free_items( items );
}
@@ -307,7 +307,7 @@ nact_iactions_list_initial_load_toplevel( NactIActionsList *instance )
* Allocates and initializes the ActionsList widget.
*/
void
-nact_iactions_list_runtime_init_toplevel( NactIActionsList *instance, GSList *items )
+nact_iactions_list_runtime_init_toplevel( NactIActionsList *instance, GList *items )
{
static const gchar *thisfn = "nact_iactions_list_runtime_init_toplevel";
GtkTreeView *treeview;
@@ -317,7 +317,7 @@ nact_iactions_list_runtime_init_toplevel( NactIActionsList *instance, GSList *it
GtkTreeSelection *selection;
g_debug( "%s: instance=%p, items=%p (%d items)",
- thisfn, ( void * ) instance, ( void * ) items, g_slist_length( items ));
+ thisfn, ( void * ) instance, ( void * ) items, g_list_length( items ));
g_return_if_fail( NACT_IS_IACTIONS_LIST( instance ));
treeview = get_actions_list_treeview( instance );
@@ -418,20 +418,17 @@ nact_iactions_list_dispose( NactIActionsList *instance )
*
* Deletes the current selection from the underlying tree store.
*
- * Returns the list of deleted #NAObject items.
- *
- * the returned @path sould be gtk_tree_path_free() by the caller.
+ * The returned @path should be gtk_tree_path_free() by the caller.
*/
-GSList *
+void
nact_iactions_list_delete_selection( NactIActionsList *instance, GtkTreePath **path )
{
GtkTreeView *treeview;
GtkTreeModel *model;
GtkTreeSelection *selection;
GList *selected;
- GSList *deleted = NULL;
- g_return_val_if_fail( NACT_IS_IACTIONS_LIST( instance ), NULL );
+ g_return_if_fail( NACT_IS_IACTIONS_LIST( instance ));
treeview = get_actions_list_treeview( instance );
selection = gtk_tree_view_get_selection( treeview );
@@ -439,13 +436,11 @@ nact_iactions_list_delete_selection( NactIActionsList *instance, GtkTreePath **p
if( g_list_length( selected )){
*path = gtk_tree_path_copy(( GtkTreePath * ) selected->data );
- deleted = nact_tree_model_remove( NACT_TREE_MODEL( model ), selected );
+ nact_tree_model_remove( NACT_TREE_MODEL( model ), selected );
}
g_list_foreach( selected, ( GFunc ) gtk_tree_path_free, NULL );
g_list_free( selected );
-
- return( deleted );
}
/**
@@ -458,7 +453,7 @@ nact_iactions_list_delete_selection( NactIActionsList *instance, GtkTreePath **p
* The selection is reset to the first line of the tree, if there is one.
*/
void
-nact_iactions_list_fill( NactIActionsList *instance, GSList *items )
+nact_iactions_list_fill( NactIActionsList *instance, GList *items )
{
static const gchar *thisfn = "nact_iactions_list_fill";
GtkTreeView *treeview;
@@ -536,12 +531,12 @@ nact_iactions_list_get_items( NactIActionsList *instance )
*
* Returns a flat list of modified items.
*
- * The returned GSList should be nact_iaction_list_free_items_list()-ed.
+ * The returned #GList should be na_object_free_items()-ed.
*/
-GSList *
+GList *
nact_iactions_list_get_modified_items( NactIActionsList *instance )
{
- GSList *items = NULL;
+ GList *items = NULL;
GtkTreeView *treeview;
NactTreeModel *model;
@@ -554,25 +549,26 @@ nact_iactions_list_get_modified_items( NactIActionsList *instance )
/*g_debug( "nact_iactions_list_get_modified_items: count=%d", g_slist_length( items ));*/
- return( g_slist_reverse( items ));
+ return( g_list_reverse( items ));
}
/**
* nact_iactions_list_get_selected_items:
* @window: this #NactIActionsList instance.
*
- * Returns the currently selected rows.
+ * Returns: the currently selected rows.
*
- * If a selected item is collapsed, we consider that all subitems are
- * also silently selected. If it is expanded, then only actually
- * selected rows are returned.
+ * We acquire here a new reference on objects corresponding to actually
+ * selected rows. It is supposed that their subitems are also concerned,
+ * but this may be caller-dependant.
*
- * The returned GSList should be nact_iaction_list_free_items_list()-ed.
+ * The caller may safely call na_object_free_items() on the returned
+ * list, or g_slist_free() if it wants keep the references somewhere.
*/
-GSList *
+GList *
nact_iactions_list_get_selected_items( NactIActionsList *instance )
{
- GSList *items = NULL;
+ GList *items = NULL;
GtkTreeView *treeview;
GtkTreeSelection *selection;
GtkTreeModel *model;
@@ -589,13 +585,13 @@ nact_iactions_list_get_selected_items( NactIActionsList *instance )
path = ( GtkTreePath * ) it->data;
gtk_tree_model_get_iter( model, &iter, path );
gtk_tree_model_get( model, &iter, IACTIONS_LIST_NAOBJECT_COLUMN, &object, -1 );
- items = g_slist_prepend( items, object );
+ items = g_list_prepend( items, object );
}
g_list_foreach( listrows, ( GFunc ) gtk_tree_path_free, NULL );
g_list_free( listrows );
- return( g_slist_reverse( items ));
+ return( g_list_reverse( items ));
}
/**
@@ -606,7 +602,7 @@ nact_iactions_list_get_selected_items( NactIActionsList *instance )
* Inserts the provided @items list in the treeview.
*
* The provided @items list is supposed to be homogeneous, i.e. referes
- * to a whole subtree.
+ * to only profiles, or only actions or menus.
*
* If the @items list contains only profiles, they can only be inserted
* into an action, and the profiles will eventually be renumbered.
@@ -623,7 +619,7 @@ nact_iactions_list_get_selected_items( NactIActionsList *instance )
* of profiles of the current action.
*/
void
-nact_iactions_list_insert_items( NactIActionsList *instance, GSList *items )
+nact_iactions_list_insert_items( NactIActionsList *instance, GList *items )
{
GtkTreeView *treeview;
GtkTreeSelection *selection;
@@ -849,6 +845,12 @@ nact_iactions_list_is_only_actions_mode( NactIActionsList *instance )
* nact_iactions_list_select_row:
* @window: this #NactIActionsList instance.
* @path: a #GtkTreePath.
+ *
+ * Select the rows at the required path, or the next following, or
+ * the immediate previous.
+ *
+ * Free the provided path, which becomes invalid when this function
+ * returns.
*/
void
nact_iactions_list_select_row( NactIActionsList *instance, GtkTreePath *path )
@@ -864,7 +866,21 @@ nact_iactions_list_select_row( NactIActionsList *instance, GtkTreePath *path )
if( gtk_tree_model_get_iter( model, &iter, path )){
gtk_tree_selection_select_iter( selection, &iter );
+
+ } else {
+ gtk_tree_path_next( path );
+ if( gtk_tree_model_get_iter( model, &iter, path )){
+ gtk_tree_selection_select_iter( selection, &iter );
+
+ } else if( gtk_tree_path_prev( path ) && gtk_tree_model_get_iter( model, &iter, path )){
+ gtk_tree_selection_select_iter( selection, &iter );
+
+ } else if( gtk_tree_path_up( path ) && gtk_tree_model_get_iter( model, &iter, path )){
+ gtk_tree_selection_select_iter( selection, &iter );
+ }
}
+
+ gtk_tree_path_free( path );
}
/**
@@ -1184,11 +1200,11 @@ have_filter_selection_mode( NactIActionsList *instance )
* count _all_ modified rows, including profiles
*/
static gboolean
-is_modified_item( NactTreeModel *model, GtkTreePath *path, NAObject *object, GSList **items )
+is_modified_item( NactTreeModel *model, GtkTreePath *path, NAObject *object, GList **items )
{
/*if( !NA_IS_ACTION_PROFILE( object )){*/
if( na_object_is_modified( object )){
- *items = g_slist_prepend( *items, g_object_ref( object ));
+ *items = g_list_prepend( *items, g_object_ref( object ));
}
/*}*/
@@ -1266,7 +1282,7 @@ on_key_pressed_event( GtkWidget *widget, GdkEventKey *event, NactIActionsList *i
static void
on_treeview_selection_changed( GtkTreeSelection *selection, NactIActionsList *instance )
{
- GSList *selected_items;
+ GList *selected_items;
selected_items = nact_iactions_list_get_selected_items( instance );
diff --git a/src/nact/nact-iactions-list.h b/src/nact/nact-iactions-list.h
index 6277356..33c52e0 100644
--- a/src/nact/nact-iactions-list.h
+++ b/src/nact/nact-iactions-list.h
@@ -72,17 +72,17 @@ typedef struct {
GType nact_iactions_list_get_type( void );
void nact_iactions_list_initial_load_toplevel( NactIActionsList *instance );
-void nact_iactions_list_runtime_init_toplevel( NactIActionsList *instance, GSList *actions );
+void nact_iactions_list_runtime_init_toplevel( NactIActionsList *instance, GList *actions );
void nact_iactions_list_all_widgets_showed( NactIActionsList *instance );
void nact_iactions_list_dispose( NactIActionsList *instance );
-GSList *nact_iactions_list_delete_selection( NactIActionsList *instance, GtkTreePath **path );
-void nact_iactions_list_fill( NactIActionsList *instance, GSList *items );
+void nact_iactions_list_delete_selection( NactIActionsList *instance, GtkTreePath **path );
+void nact_iactions_list_fill( NactIActionsList *instance, GList *items );
guint nact_iactions_list_get_items_count( NactIActionsList *instance );
GSList *nact_iactions_list_get_items( NactIActionsList *instance );
-GSList *nact_iactions_list_get_modified_items( NactIActionsList *instance );
-GSList *nact_iactions_list_get_selected_items( NactIActionsList *instance );
-void nact_iactions_list_insert_items( NactIActionsList *instance, GSList *items );
+GList *nact_iactions_list_get_modified_items( NactIActionsList *instance );
+GList *nact_iactions_list_get_selected_items( NactIActionsList *instance );
+void nact_iactions_list_insert_items( NactIActionsList *instance, GList *items );
gboolean nact_iactions_list_is_expanded( NactIActionsList *instance, const NAObject *item );
gboolean nact_iactions_list_is_filling_list( NactIActionsList *instance );
gboolean nact_iactions_list_is_only_actions_mode( NactIActionsList *instance );
diff --git a/src/nact/nact-main-menubar.c b/src/nact/nact-main-menubar.c
index 6ba2d8c..9cd56b8 100644
--- a/src/nact/nact-main-menubar.c
+++ b/src/nact/nact-main-menubar.c
@@ -252,14 +252,14 @@ nact_main_menubar_runtime_init( NactMainWindow *window )
void
nact_main_menubar_refresh_actions_sensitivity( NactMainWindow *window )
{
- GSList *selected;
+ GList *selected;
guint count;
g_return_if_fail( NACT_MAIN_WINDOW( window ));
g_return_if_fail( NACT_IS_IACTIONS_LIST( window ));
selected = nact_iactions_list_get_selected_items( NACT_IACTIONS_LIST( window ));
- count = g_slist_length( selected );
+ count = g_list_length( selected );
na_object_free_items( selected );
refresh_actions_sensitivity_with_count( window, count );
}
@@ -274,14 +274,14 @@ static void
on_new_menu_activated( GtkAction *gtk_action, NactMainWindow *window )
{
NAObjectMenu *menu;
- GSList *items = NULL;
+ GList *items = NULL;
g_return_if_fail( GTK_IS_ACTION( gtk_action ));
g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
menu = na_object_menu_new();
na_object_check_edition_status( menu );
- items = g_slist_prepend( items, menu );
+ items = g_list_prepend( items, menu );
nact_iactions_list_insert_items( NACT_IACTIONS_LIST( window ), items );
/*updates = g_slist_prepend( updates, g_object_ref( menu ));
@@ -294,7 +294,7 @@ static void
on_new_action_activated( GtkAction *gtk_action, NactMainWindow *window )
{
NAObjectAction *action;
- GSList *items = NULL;
+ GList *items = NULL;
g_return_if_fail( GTK_IS_ACTION( gtk_action ));
g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
@@ -302,7 +302,7 @@ on_new_action_activated( GtkAction *gtk_action, NactMainWindow *window )
action = na_object_action_new_with_profile();
na_object_check_edition_status( action );
/*na_object_check_edition_status( na_object_action_get_profiles( action )->data );*/
- items = g_slist_prepend( items, action );
+ items = g_list_prepend( items, action );
nact_iactions_list_insert_items( NACT_IACTIONS_LIST( window ), items );
/*updates = g_slist_prepend( updates, g_object_ref( action ));
@@ -317,7 +317,7 @@ on_new_profile_activated( GtkAction *gtk_action, NactMainWindow *window )
NAObjectAction *action;
NAObjectProfile *profile;
gchar *name;
- GSList *items = NULL;
+ GList *items = NULL;
g_return_if_fail( GTK_IS_ACTION( gtk_action ));
g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
@@ -334,7 +334,7 @@ on_new_profile_activated( GtkAction *gtk_action, NactMainWindow *window )
na_object_set_id( profile, name );
na_object_check_edition_status( NA_OBJECT( profile ));
/*na_object_check_edited_status( NA_OBJECT( action ));*/
- items = g_slist_prepend( items, profile );
+ items = g_list_prepend( items, profile );
nact_iactions_list_insert_items( NACT_IACTIONS_LIST( window ), items );
/*updates = g_slist_prepend( updates, g_object_ref( profile ));
@@ -391,7 +391,7 @@ on_save_activated( GtkAction *gtk_action, NactMainWindow *window )
static void
save_object_item( NactMainWindow *window, NAPivot *pivot, NAObjectItem *object )
{
- GSList *items, *it;
+ GList *items, *it;
if( na_object_is_modified( NA_OBJECT( object )) &&
na_object_is_valid( NA_OBJECT( object )) &&
@@ -443,63 +443,72 @@ on_quit_activated( GtkAction *gtk_action, NactMainWindow *window )
/*
* cuts the visible selection
- * - (tree) remove the selection from the treeview
- * - (main) adds the removed selection to deleted
- * - (*) set the clipboard
- * - (tree) select the next row
- *
- * The clipboard must be set with a selection suitable for insertion :
- * - if selection contains only profiles, even from different actions,
- * then these profiles can only be inserted into an action.
- * - if the selection contains only actions and menus, then these items
- * can be inserted at root or inside a menu
- * - if the selection is a mixed of profiles, and actions or menus,
- * then nothing can be done with it.
+ * - (tree) get new refs on selected items
+ * - (tree) remove selected items, unreffing objects
+ * - (main) add selected items to main list of deleted,
+ * moving newref from list_from_tree to main_list_of_deleted
+ * - (menu) install in clipboard a copy of selected objects
+ * - (tree) select next row (if any, or previous if any, or none)
*/
static void
on_cut_activated( GtkAction *gtk_action, NactMainWindow *window )
{
- GSList *items;
+ GList *items;
+ GtkTreePath *path;
g_return_if_fail( GTK_IS_ACTION( gtk_action ));
g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
- items = nact_main_window_delete_selection( window );
- nact_clipboard_set( items );
- na_object_free_items( items );
+ items = nact_iactions_list_get_selected_items( NACT_IACTIONS_LIST( window ));
+ nact_iactions_list_delete_selection( NACT_IACTIONS_LIST( window ), &path );
+ nact_main_window_move_to_deleted( window, items );
+ nact_clipboard_set( items, FALSE );
+ nact_iactions_list_select_row( NACT_IACTIONS_LIST( window ), path );
- /* the selection is modified before updating the clipboard, so we
- * need a manual refresh of actions sensitivity
- */
- nact_main_menubar_refresh_actions_sensitivity( window );
+ g_list_free( items );
}
+/*
+ * copies the visible selection
+ * - (tree) get new refs on selected items
+ * - (menu) install in clipboard a copy of selected objects
+ * renumbering actions/menus id to ensure unicity at paste time
+ * - (menu) release refs on selected items
+ * - (menu) refresh actions sensitivy (as selection doesn't change)
+ */
static void
on_copy_activated( GtkAction *gtk_action, NactMainWindow *window )
{
- GSList *items;
+ GList *items;
g_return_if_fail( GTK_IS_ACTION( gtk_action ));
g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
items = nact_iactions_list_get_selected_items( NACT_IACTIONS_LIST( window ));
- nact_clipboard_set( items );
+ nact_clipboard_set( items, TRUE );
na_object_free_items( items );
-
- /* selection is not even modified, so a manuel refresh is needed
- */
nact_main_menubar_refresh_actions_sensitivity( window );
}
+/*
+ * pastes the current coontent of the clipboard
+ * - (menu) get from clipboard a copy of installed items
+ * the clipboard will return a new copy
+ * and renumber its own data for allowing a new paste
+ * - (tree) insert new items, the tree store will ref them
+ * attaching each item to its parent
+ * checking edition status of the topmost parent
+ * selecting the first item at end
+ * - (menu) unreffing the copy got from clipboard
+ */
static void
on_paste_activated( GtkAction *gtk_action, NactMainWindow *window )
{
- GSList *items;
+ GList *items;
items = nact_clipboard_get();
nact_iactions_list_insert_items( NACT_IACTIONS_LIST( window ), items );
-
- g_signal_emit_by_name( window, IACTIONS_LIST_SIGNAL_ITEM_UPDATED, NULL );
+ na_object_free_items( items );
}
static void
@@ -508,18 +517,29 @@ on_duplicate_activated( GtkAction *gtk_action, NactMainWindow *window )
g_signal_emit_by_name( window, IACTIONS_LIST_SIGNAL_ITEM_UPDATED, NULL );
}
+/*
+ * deletes the visible selection
+ * - (tree) get new refs on selected items
+ * - (tree) remove selected items, unreffing objects
+ * - (main) add selected items to main list of deleted,
+ * moving newref from list_from_tree to main_list_of_deleted
+ * - (tree) select next row (if any, or previous if any, or none)
+ */
static void
on_delete_activated( GtkAction *gtk_action, NactMainWindow *window )
{
- GSList *items;
+ GList *items;
+ GtkTreePath *path;
g_return_if_fail( GTK_IS_ACTION( gtk_action ));
g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
- items = nact_main_window_delete_selection( window );
- na_object_free_items( items );
+ items = nact_iactions_list_get_selected_items( NACT_IACTIONS_LIST( window ));
+ nact_iactions_list_delete_selection( NACT_IACTIONS_LIST( window ), &path );
+ nact_main_window_move_to_deleted( window, items );
+ nact_iactions_list_select_row( NACT_IACTIONS_LIST( window ), path );
- g_signal_emit_by_name( window, IACTIONS_LIST_SIGNAL_ITEM_UPDATED, NULL );
+ g_list_free( items );
}
static void
diff --git a/src/nact/nact-main-window.c b/src/nact/nact-main-window.c
index fd85540..a81fe99 100644
--- a/src/nact/nact-main-window.c
+++ b/src/nact/nact-main-window.c
@@ -66,7 +66,7 @@ struct NactMainWindowPrivate {
gboolean dispose_has_run;
/* TODO: this will have to be replaced with undo-manager */
- GSList *deleted;
+ GList *deleted;
/**
* Currently edited action or menu.
@@ -554,47 +554,6 @@ nact_main_window_action_exists( const NactMainWindow *window, const gchar *uuid
}
/**
- * nact_main_window_delete_selection:
- * @window: this #NactMainWindow instance.
- *
- * Deletes the currently selected items from the treeview.
- *
- * We only delete the selected items from the treeview.
- * But, if asked for, we return the selection extended to a valid,
- * contiguous tree, suitable for a later insertion elsewhere.
- *
- * Returns: the tree of selected items, or NULL.
- *
- * The returned #GSList should be na_object_free_items() by the caller.
- */
-GSList *
-nact_main_window_delete_selection( NactMainWindow *window )
-{
- static const gchar *thisfn = "nact_main_window_delete_selection";
- GtkTreePath *path;
- GSList *deleted;
- GSList *it;
-
- g_return_val_if_fail( NACT_IS_MAIN_WINDOW( window ), 0 );
- g_return_val_if_fail( NACT_IS_IACTIONS_LIST( window ), 0 );
-
- deleted = nact_iactions_list_delete_selection( NACT_IACTIONS_LIST( window ), &path );
-
- for( it = deleted ; it ; it = it->next ){
- g_debug( "%s: deleting %s at %p", thisfn, G_OBJECT_TYPE_NAME( it->data ), ( void * ) it->data );
- window->private->deleted = g_slist_prepend( window->private->deleted, g_object_ref( NA_OBJECT( it->data )));
- }
-
- /* the next row must be selected after having updated the deleted list
- * so that count_modified will take it into account
- */
- nact_iactions_list_select_row( NACT_IACTIONS_LIST( window ), path );
- gtk_tree_path_free( path );
-
- return( deleted );
-}
-
-/**
* nact_main_window_get_all_items_count:
* @window: this #NactMainWindow instance.
*
@@ -627,7 +586,7 @@ guint
nact_main_window_get_modified_items_count( const NactMainWindow *window )
{
static const gchar *thisfn = "nact_main_window_get_modified_items_count";
- GSList *ia, *modified;
+ GList *ia, *modified;
gint count_deleted = 0;
gint count_modified = 0;
@@ -642,7 +601,7 @@ nact_main_window_get_modified_items_count( const NactMainWindow *window )
g_debug( "%s: count_deleted=%d", thisfn, count_deleted );
modified = nact_iactions_list_get_modified_items( NACT_IACTIONS_LIST( window ));
- count_modified = g_slist_length( modified );
+ count_modified = g_list_length( modified );
na_object_free_items( modified );
g_debug( "%s: count_modified=%d", thisfn, count_modified );
@@ -650,6 +609,25 @@ nact_main_window_get_modified_items_count( const NactMainWindow *window )
}
/**
+ * nact_main_window_move_to_deleted:
+ * @window: this #NactMainWindow instance.
+ * @items: list of deleted objects.
+ *
+ * Adds the given list to the deleted one.
+ *
+ * Note that we move the ref from @items list to our own deleted list.
+ * So that the caller should not try to na_object_free_items() the
+ * provided list, but should also g_slist_free() it.
+ */
+void
+nact_main_window_move_to_deleted( NactMainWindow *window, GList *items )
+{
+ g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
+
+ window->private->deleted = g_list_concat( window->private->deleted, items );
+}
+
+/**
* nact_main_window_remove_deleted:
*
* Removes the deleted items from the underlying I/O storage subsystem.
@@ -659,7 +637,7 @@ nact_main_window_remove_deleted( NactMainWindow *window )
{
NactApplication *application;
NAPivot *pivot;
- GSList *it;
+ GList *it;
NAObject *item;
application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
@@ -682,7 +660,7 @@ nact_main_window_remove_deleted( NactMainWindow *window )
static void
actually_delete_item( NactMainWindow *window, NAObject *item, NAPivot *pivot )
{
- GSList *items, *it;
+ GList *items, *it;
if( nact_window_delete_object_item( NACT_WINDOW( window ), NA_OBJECT_ITEM( item ))){
@@ -752,7 +730,7 @@ on_base_runtime_init_toplevel( NactMainWindow *window, gpointer user_data )
static const gchar *thisfn = "nact_main_window_on_base_runtime_init_toplevel";
NactApplication *application;
NAPivot *pivot;
- GSList *tree;
+ GList *tree;
g_debug( "%s: window=%p, user_data=%p", thisfn, ( void * ) window, ( void * ) user_data );
g_assert( NACT_IS_MAIN_WINDOW( window ));
@@ -857,7 +835,7 @@ set_current_object_item( NactMainWindow *window, GSList *selected_items )
{
static const gchar *thisfn = "nact_main_window_set_current_object_item";
gint count_profiles;
- GSList *profiles;
+ GList *profiles;
/*NAObject *current;*/
g_debug( "%s: window=%p, current=%p, selected_items=%p",
diff --git a/src/nact/nact-main-window.h b/src/nact/nact-main-window.h
index ca4ee1d..06f2971 100644
--- a/src/nact/nact-main-window.h
+++ b/src/nact/nact-main-window.h
@@ -69,9 +69,9 @@ GType nact_main_window_get_type( void );
NactMainWindow *nact_main_window_new( BaseApplication *application );
gboolean nact_main_window_action_exists( const NactMainWindow *window, const gchar *uuid );
-GSList *nact_main_window_delete_selection( NactMainWindow *window );
guint nact_main_window_get_all_items_count( const NactMainWindow *window );
guint nact_main_window_get_modified_items_count( const NactMainWindow *window );
+void nact_main_window_move_to_deleted( NactMainWindow *window, GList *items );
void nact_main_window_remove_deleted( NactMainWindow *window );
G_END_DECLS
diff --git a/src/nact/nact-tree-model.c b/src/nact/nact-tree-model.c
index 405214c..521701e 100644
--- a/src/nact/nact-tree-model.c
+++ b/src/nact/nact-tree-model.c
@@ -85,7 +85,7 @@ struct NactTreeModelPrivate {
guint count;
gboolean have_dnd;
gchar *drag_dest_uri;
- GSList *drag_items;
+ GList *drag_items;
};
#define MAX_XDS_ATOM_VAL_LEN 4096
@@ -153,7 +153,7 @@ static NactTreeModel *tree_model_new( BaseWindow *window, GtkTreeView *treeview
static void append_item( GtkTreeStore *model, GtkTreeView *treeview, GtkTreeIter *parent, GtkTreeIter *iter, const NAObject *object );
static void display_item( GtkTreeStore *model, GtkTreeView *treeview, GtkTreeIter *iter, const NAObject *object );
static gboolean dump_store( NactTreeModel *model, GtkTreePath *path, NAObject *object, ntmDumpStruct *ntm );
-static void fill_tree_store( GtkTreeStore *model, GtkTreeView *treeview, GSList *items, gboolean only_actions, GtkTreeIter *parent );
+static void fill_tree_store( GtkTreeStore *model, GtkTreeView *treeview, GList *items, gboolean only_actions, GtkTreeIter *parent );
static void iter_on_store( NactTreeModel *model, GtkTreeModel *store, GtkTreeIter *parent, FnIterOnStore fn, gpointer user_data );
static gboolean iter_on_store_item( NactTreeModel *model, GtkTreeModel *store, GtkTreeIter *iter, FnIterOnStore fn, gpointer user_data );
static gboolean search_for_object( NactTreeModel *model, GtkTreeModel *store, const NAObject *object, GtkTreeIter *iter );
@@ -325,7 +325,7 @@ instance_finalize( GObject *object )
self = NACT_TREE_MODEL( object );
g_free( self->private->drag_dest_uri );
- g_slist_free( self->private->drag_items );
+ g_list_free( self->private->drag_items );
g_free( self->private );
@@ -549,13 +549,13 @@ nact_tree_model_dump( NactTreeModel *model )
* tree store, so that we are able to freely edit it.
*/
void
-nact_tree_model_fill( NactTreeModel *model, GSList *items, gboolean only_actions)
+nact_tree_model_fill( NactTreeModel *model, GList *items, gboolean only_actions)
{
static const gchar *thisfn = "nact_tree_model_fill";
GtkTreeStore *ts_model;
g_debug( "%s: model=%p, items=%p (%d items), only_actions=%s",
- thisfn, ( void * ) model, ( void * ) items, g_slist_length( items ), only_actions ? "True":"False" );
+ thisfn, ( void * ) model, ( void * ) items, g_list_length( items ), only_actions ? "True":"False" );
g_return_if_fail( NACT_IS_TREE_MODEL( model ));
ts_model = GTK_TREE_STORE( gtk_tree_model_filter_get_model( GTK_TREE_MODEL_FILTER( model )));
@@ -567,10 +567,10 @@ nact_tree_model_fill( NactTreeModel *model, GSList *items, gboolean only_actions
static void
fill_tree_store( GtkTreeStore *model, GtkTreeView *treeview,
- GSList *items, gboolean only_actions, GtkTreeIter *parent )
+ GList *items, gboolean only_actions, GtkTreeIter *parent )
{
/*static const gchar *thisfn = "nact_tree_model_fill_tree_store";*/
- GSList *subitems, *it;
+ GList *subitems, *it;
NAObject *object;
NAObject *duplicate;
GtkTreeIter iter;
@@ -648,7 +648,7 @@ nact_tree_model_insert_item( NactTreeModel *model, const NAObject *object, GtkTr
GtkTreeIter *parent;
GtkTreeIter store_iter;
GtkTreeIter profile_iter;
- GSList *profiles;
+ GList *profiles;
path_str = path ? gtk_tree_path_to_string( path ) : NULL;
g_debug( "%s: model=%p, object=%p, path=%p (%s), selected=%p, iter=%p",
@@ -722,30 +722,37 @@ nact_tree_model_iter( NactTreeModel *model, FnIterOnStore fn, gpointer user_data
iter_on_store( model, GTK_TREE_MODEL( store ), NULL, fn, user_data );
}
-GSList *
+/**
+ * nact_tree_model_remove:
+ * @model: this #NactTreeModel instance.
+ * @selected: a list of #GtkTreePath as returned by
+ * gtk_tree_selection_get_selected_rows().
+ *
+ * Deletes the selected rows, unref-ing the underlying objects if any.
+ *
+ * We begin by the end, so that we are almost sure that path remain
+ * valid during the iteration.
+ */
+void
nact_tree_model_remove( NactTreeModel *model, GList *selected )
{
GList *reversed, *item;
GtkTreeIter iter;
GtkTreeStore *store;
gchar *path_str;
- GSList *deleted = NULL;
- NAObject *object;
reversed = g_list_reverse( selected );
store = GTK_TREE_STORE( gtk_tree_model_filter_get_model( GTK_TREE_MODEL_FILTER( model )));
for( item = reversed ; item ; item = item->next ){
+
path_str = gtk_tree_path_to_string(( GtkTreePath * ) item->data );
g_debug( "nact_tree_model_remove: path=%s", path_str );
g_free( path_str );
+
gtk_tree_model_get_iter( GTK_TREE_MODEL( store ), &iter, ( GtkTreePath * ) item->data );
- gtk_tree_model_get( GTK_TREE_MODEL( store ), &iter, IACTIONS_LIST_NAOBJECT_COLUMN, &object, -1 );
gtk_tree_store_remove( store, &iter );
- deleted = g_slist_prepend( deleted, object );
}
-
- return( g_slist_reverse( deleted ));
}
/**
@@ -965,7 +972,7 @@ imulti_drag_source_drag_data_get( EggTreeMultiDragSource *drag_source,
static const gchar *thisfn = "nact_tree_model_imulti_drag_source_drag_data_get";
gchar *atom_name;
NactTreeModel *model;
- GSList *selected_items;
+ GList *selected_items;
gchar *data;
gboolean ret = FALSE;
gchar *dest_folder, *folder;
@@ -985,8 +992,8 @@ imulti_drag_source_drag_data_get( EggTreeMultiDragSource *drag_source,
if( !selected_items ){
return( FALSE );
}
- if( !g_slist_length( selected_items )){
- g_slist_free( selected_items );
+ if( !g_list_length( selected_items )){
+ g_list_free( selected_items );
return( FALSE );
}
@@ -1006,7 +1013,7 @@ imulti_drag_source_drag_data_get( EggTreeMultiDragSource *drag_source,
gtk_selection_data_set( selection_data, selection_data->target, 8, ( guchar * )( is_writable ? "S" : "F" ), 1 );
if( is_writable ){
model->private->drag_dest_uri = g_strdup( dest_folder );
- model->private->drag_items = g_slist_copy( selected_items );
+ model->private->drag_items = g_list_copy( selected_items );
}
g_free( dest_folder );
ret = TRUE;
@@ -1024,7 +1031,7 @@ imulti_drag_source_drag_data_get( EggTreeMultiDragSource *drag_source,
break;
}
- g_slist_free( selected_items );
+ g_list_free( selected_items );
return( ret );
}
@@ -1091,7 +1098,7 @@ on_drag_begin( GtkWidget *widget, GdkDragContext *context, BaseWindow *window )
g_free( model->private->drag_dest_uri );
model->private->drag_dest_uri = NULL;
- g_slist_free( model->private->drag_items );
+ g_list_free( model->private->drag_items );
model->private->drag_items = NULL;
gdk_property_change(
@@ -1112,14 +1119,14 @@ on_drag_end( GtkWidget *widget, GdkDragContext *context, BaseWindow *window )
model = NACT_TREE_MODEL( gtk_tree_view_get_model( GTK_TREE_VIEW( widget )));
- if( model->private->drag_dest_uri && model->private->drag_items && g_slist_length( model->private->drag_items )){
+ if( model->private->drag_dest_uri && model->private->drag_items && g_list_length( model->private->drag_items )){
nact_clipboard_export_items( model->private->drag_dest_uri, model->private->drag_items );
}
g_free( model->private->drag_dest_uri );
model->private->drag_dest_uri = NULL;
- g_slist_free( model->private->drag_items );
+ g_list_free( model->private->drag_items );
model->private->drag_items = NULL;
gdk_property_delete( context->source_window, XDS_ATOM );
diff --git a/src/nact/nact-tree-model.h b/src/nact/nact-tree-model.h
index 9f30fac..29a04e8 100644
--- a/src/nact/nact-tree-model.h
+++ b/src/nact/nact-tree-model.h
@@ -92,11 +92,11 @@ void nact_tree_model_runtime_init( NactTreeModel *model, gboolean have_dnd );
void nact_tree_model_dispose( NactTreeModel *model );
void nact_tree_model_dump( NactTreeModel *model );
-void nact_tree_model_fill( NactTreeModel *model, GSList *items, gboolean only_actions);
+void nact_tree_model_fill( NactTreeModel *model, GList *items, gboolean only_actions);
guint nact_tree_model_get_items_count( NactTreeModel *model );
void nact_tree_model_insert_item( NactTreeModel *model, const NAObject *object, GtkTreePath *path, const NAObject *selected, GtkTreeIter *iter );
void nact_tree_model_iter( NactTreeModel *model, FnIterOnStore fn, gpointer user_data );
-GSList *nact_tree_model_remove( NactTreeModel *model, GList *selected );
+void nact_tree_model_remove( NactTreeModel *model, GList *selected );
void nact_tree_model_update_parent( NactTreeModel *model, const NAObject *object );
G_END_DECLS
diff --git a/src/plugin/nautilus-actions.c b/src/plugin/nautilus-actions.c
index 5db114c..6e85831 100644
--- a/src/plugin/nautilus-actions.c
+++ b/src/plugin/nautilus-actions.c
@@ -284,11 +284,10 @@ get_file_items( NautilusMenuProvider *provider, GtkWidget *window, GList *files
static const gchar *thisfn = "nautilus_actions_get_file_items";
NautilusActions *self;
GList *items = NULL;
- GSList* profiles;
- GSList *ia, *ip;
+ GList *profiles, *ia, *ip;
NautilusMenu *menu = NULL;
NautilusMenuItem *item;
- GSList *tree = NULL;
+ GList *tree = NULL;
gchar *label, *uuid;
gint submenus = 0;
gboolean add_about;
diff --git a/src/test/test-iface-iface.c b/src/test/test-iface-iface.c
index 7a79478..5b9cb6e 100644
--- a/src/test/test-iface-iface.c
+++ b/src/test/test-iface-iface.c
@@ -168,13 +168,13 @@ test_iface_fnb( TestIFace *object )
GTypeInterface *iface;
g_debug( "%s: %s at %p", thisfn, G_OBJECT_TYPE_NAME( object ), ( void * ) object );
- g_debug( "%s: g_type_from_instance=%u", thisfn, G_TYPE_FROM_INSTANCE( object ));
- g_debug( "%s: g_type_from_interface=%u", thisfn, G_TYPE_FROM_INTERFACE( object ));
+ g_debug( "%s: g_type_from_instance=%d", thisfn, ( gint ) G_TYPE_FROM_INSTANCE( object ));
+ g_debug( "%s: g_type_from_interface=%d", thisfn, ( gint ) G_TYPE_FROM_INTERFACE( object ));
hierarchy = NULL;
base_type = TEST_BASE_TYPE;
type = G_OBJECT_TYPE( object );
- g_debug( "%s: type=%u %s", thisfn, type, G_OBJECT_TYPE_NAME( object ));
+ g_debug( "%s: type=%d %s", thisfn, ( gint ) type, G_OBJECT_TYPE_NAME( object ));
while( TRUE ){
/*hierarchy = g_slist_prepend( hierarchy, class );*/
hierarchy = g_slist_prepend( hierarchy, GINT_TO_POINTER( type ));
@@ -191,7 +191,7 @@ test_iface_fnb( TestIFace *object )
for( ic = hierarchy ; ic ; ic = ic->next ){
type = GPOINTER_TO_INT( ic->data );
- g_debug( "%s: iterating on %u type", thisfn, type );
+ g_debug( "%s: iterating on %d type", thisfn, ( gint ) type );
class = g_type_class_peek_static( type );
g_debug( "%s: class is %s at %p", thisfn, G_OBJECT_CLASS_NAME( class ), ( void * ) class );
iface = g_type_interface_peek( class, TEST_IFACE_TYPE );
diff --git a/src/utils/nautilus-actions-new.c b/src/utils/nautilus-actions-new.c
index 1a1e359..f1c16f0 100644
--- a/src/utils/nautilus-actions-new.c
+++ b/src/utils/nautilus-actions-new.c
@@ -208,7 +208,7 @@ static NAObjectAction *
get_action_from_cmdline( void )
{
NAObjectAction *action = na_object_action_new_with_profile();
- GSList *profiles;
+ GList *profiles;
NAObjectProfile *profile;
int i = 0;
GSList *basenames = NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]