[nautilus-actions] Implement delete and duplicate actions



commit 90d87818d7a5ebefbf6d54205ea2b4ac4c9b2f69
Author: Pierre Wieser <pwieser trychlos org>
Date:   Sun Jun 28 18:54:13 2009 +0200

    Implement delete and duplicate actions

 ChangeLog                    |   13 +++++++-
 po/POTFILES.in               |    4 +-
 src/common/na-action.c       |   60 +++++++++++++++++++++++++++++++++++-----
 src/common/na-action.h       |   15 ++++++----
 src/common/na-gconf.c        |   36 ++++++++++++++++++++++++
 src/common/na-iio-provider.c |   36 ++++++++++++++++++++++++-
 src/common/na-iio-provider.h |    2 +
 src/common/na-pivot.c        |   25 ++++++++++++++++-
 src/common/na-pivot.h        |    5 +--
 src/nact/Makefile.am         |    2 -
 src/nact/base-application.c  |   19 +++++++++++++
 src/nact/base-application.h  |    1 +
 src/nact/base-window.c       |   14 +++++++++
 src/nact/base-window.h       |    3 ++
 src/nact/nact-main-window.c  |   61 ++++++++++++++++++++++++++----------------
 15 files changed, 247 insertions(+), 49 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 16a61eb..40dd9e3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,10 +1,15 @@
 2009-06-28 Pierre Wieser <pwieser trychlos org>
 
+	* po/POTFILES.in:
+	Replace src/nact/nact.c with src/nact/nact-main-window.c.
+	Replace src/nact/nautilus-actions-config.glade with
+	src/nact/nautilus-actions-config.ui.
+
 	* src/common/na-action.c:
 	* src/common/na-action.h:
 	UUID is no more a contruction only property.
 	NAAction is now initialized with suitable default values.
-	na_action_new_with_profile: new function.
+	na_action_new_with_profile, na_action_get_provider: new functions.
 
 	* src/common/na-action-profile.c:
 	* src/common/na-action-profile.h:
@@ -12,8 +17,12 @@
 	na_action_profile_copy function is renamed as
 	na_action_profile_duplicate.
 
-	* src/na/na-gconf.c:
+	* src/common/na-gconf.c:
 	Temporarily suspend test of writability status.
+	Record the last provider of an action.
+
+	* src/common/na-iio-provider.c:
+	delete_action: new function.
 
 	* src/nact/nact-action-conditions-editor.c:
 	* src/nact/nact-action-conditions-editor.h:
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 81f10d1..2dfa4c2 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,8 +1,8 @@
 src/common/nautilus-actions-config.c
 src/common/nautilus-actions-config-gconf-private.h
 src/common/nautilus-actions-config-schema-reader.c
-src/nact/nact.c
 src/nact/nact-application.c
+src/nact/nact-main-window.c
 src/nact/nact.desktop.in
 src/nact/nact-action-editor.c
 src/nact/nact-editor.c
@@ -10,6 +10,6 @@ src/nact/nact-import-export.c
 src/nact/nact-prefs.c
 src/nact/nact-profile-editor.c
 src/nact/nact-utils.c
-src/nact/nautilus-actions-config.glade
+src/nact/nautilus-actions-config.ui
 src/utils/nautilus-actions-new-config.c
 src/utils/nautilus-actions-tools-utils.c
diff --git a/src/common/na-action.c b/src/common/na-action.c
index 19ab83d..2564848 100644
--- a/src/common/na-action.c
+++ b/src/common/na-action.c
@@ -67,6 +67,11 @@ struct NAActionPrivate {
 	 * defaults to FALSE unless a write has already returned an error
 	 */
 	gboolean  read_only;
+
+	/* the original provider
+	 * required to be able to edit/delete the action
+	 */
+	gpointer  provider;
 };
 
 /* instance properties
@@ -79,16 +84,10 @@ enum {
 	PROP_ACTION_LABEL,
 	PROP_ACTION_TOOLTIP,
 	PROP_ACTION_ICON,
-	PROP_ACTION_READONLY
+	PROP_ACTION_READONLY,
+	PROP_ACTION_PROVIDER
 };
 
-#define PROP_ACTION_UUID_STR		"uuid"
-#define PROP_ACTION_VERSION_STR		"version"
-#define PROP_ACTION_LABEL_STR		"label"
-#define PROP_ACTION_TOOLTIP_STR		"tooltip"
-#define PROP_ACTION_ICON_STR		"icon"
-#define PROP_ACTION_READONLY_STR	"read-only"
-
 #define NA_ACTION_LATEST_VERSION	"2.0"
 
 static NAObjectClass *st_parent_class = NULL;
@@ -196,6 +195,13 @@ class_init( NAActionClass *klass )
 			G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
 	g_object_class_install_property( object_class, PROP_ACTION_READONLY, spec );
 
+	spec = g_param_spec_pointer(
+			PROP_ACTION_PROVIDER_STR,
+			PROP_ACTION_PROVIDER_STR,
+			"Original provider",
+			G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
+	g_object_class_install_property( object_class, PROP_ACTION_PROVIDER, spec );
+
 	klass->private = g_new0( NAActionClassPrivate, 1 );
 
 	NA_OBJECT_CLASS( klass )->dump = do_dump;
@@ -223,6 +229,7 @@ instance_init( GTypeInstance *instance, gpointer klass )
 	self->private->tooltip = g_strdup( "" );
 	self->private->icon = g_strdup( "" );
 	self->private->read_only = FALSE;
+	self->private->provider = NULL;
 }
 
 static void
@@ -256,6 +263,10 @@ instance_get_property( GObject *object, guint property_id, GValue *value, GParam
 			g_value_set_boolean( value, self->private->read_only );
 			break;
 
+		case PROP_ACTION_PROVIDER:
+			g_value_set_pointer( value, self->private->provider );
+			break;
+
 		default:
 			G_OBJECT_WARN_INVALID_PROPERTY_ID( object, property_id, spec );
 			break;
@@ -298,6 +309,10 @@ instance_set_property( GObject *object, guint property_id, const GValue *value,
 			self->private->read_only = g_value_get_boolean( value );
 			break;
 
+		case PROP_ACTION_PROVIDER:
+			self->private->provider = g_value_get_pointer( value );
+			break;
+
 		default:
 			G_OBJECT_WARN_INVALID_PROPERTY_ID( object, property_id, spec );
 			break;
@@ -410,6 +425,7 @@ na_action_duplicate( const NAAction *action )
 	duplicate->private->tooltip = g_strdup( action->private->tooltip );
 	duplicate->private->icon = g_strdup( action->private->icon );
 	duplicate->private->read_only = action->private->read_only;
+	duplicate->private->provider = action->private->provider;
 
 	GSList *ip;
 	for( ip = action->private->profiles ; ip ; ip = ip->next ){
@@ -440,6 +456,7 @@ do_dump( const NAObject *action )
 	g_debug( "%s:   tooltip='%s'", thisfn, self->private->tooltip );
 	g_debug( "%s:      icon='%s'", thisfn, self->private->icon );
 	g_debug( "%s: read-only='%s'", thisfn, self->private->read_only ? "True" : "False" );
+	g_debug( "%s:  provider=%p", thisfn, self->private->provider );
 
 	/* dump profiles */
 	g_debug( "%s: %d profile(s) at %p", thisfn, na_action_get_profiles_count( self ), self->private->profiles );
@@ -602,6 +619,19 @@ na_action_is_readonly( const NAAction *action )
 }
 
 /**
+ * Returns the initial provider of the action (or the last which has
+ * accepted a write).
+ *
+ * @action: an NAAction object.
+ */
+gpointer
+na_action_get_provider( const NAAction *action )
+{
+	g_assert( NA_IS_ACTION( action ));
+	return( action->private->provider );
+}
+
+/**
  * Set a new UUID for the action.
  *
  * @action: action whose UUID is to be set.
@@ -620,6 +650,20 @@ na_action_set_new_uuid( NAAction *action )
 }
 
 /**
+ * Set a new label for the action.
+ *
+ * @action: action whose UUID is to be set.
+ *
+ * @label: new label.
+ */
+void
+na_action_set_label( NAAction *action, const gchar *label )
+{
+	g_assert( NA_IS_ACTION( action ));
+	g_object_set( G_OBJECT( action ), PROP_ACTION_LABEL_STR, label, NULL );
+}
+
+/**
  * Returns the list of profiles of the actions as a GSList of
  * NAActionProfile GObjects.
  *
diff --git a/src/common/na-action.h b/src/common/na-action.h
index 259b3db..f630fa4 100644
--- a/src/common/na-action.h
+++ b/src/common/na-action.h
@@ -71,12 +71,13 @@ typedef struct {
  * please note that property names must have the same spelling as the
  * NactIIOProvider parameters
  */
-#define PROP_ACTION_UUID_STR			"uuid"
-#define PROP_ACTION_VERSION_STR			"version"
-#define PROP_ACTION_LABEL_STR			"label"
-#define PROP_ACTION_TOOLTIP_STR			"tooltip"
-#define PROP_ACTION_ICON_STR			"icon"
-#define PROP_ACTION_READONLY_STR		"read-only"
+#define PROP_ACTION_UUID_STR			"action-uuid"
+#define PROP_ACTION_VERSION_STR			"action-version"
+#define PROP_ACTION_LABEL_STR			"action-label"
+#define PROP_ACTION_TOOLTIP_STR			"action-tooltip"
+#define PROP_ACTION_ICON_STR			"action-icon"
+#define PROP_ACTION_READONLY_STR		"action-read-only"
+#define PROP_ACTION_PROVIDER_STR		"action-provider"
 
 GType     na_action_get_type( void );
 
@@ -91,8 +92,10 @@ gchar    *na_action_get_tooltip( const NAAction *action );
 gchar    *na_action_get_icon( const NAAction *action );
 gchar    *na_action_get_verified_icon_name( const NAAction *action );
 gboolean  na_action_is_readonly( const NAAction *action );
+gpointer  na_action_get_provider( const NAAction *action );
 
 void      na_action_set_new_uuid( NAAction *action );
+void      na_action_set_label( NAAction *action, const gchar *label );
 
 GSList   *na_action_get_profiles( const NAAction *action );
 void      na_action_set_profiles( NAAction *action, GSList *list );
diff --git a/src/common/na-gconf.c b/src/common/na-gconf.c
index 8601c4a..ccd6a98 100644
--- a/src/common/na-gconf.c
+++ b/src/common/na-gconf.c
@@ -106,6 +106,7 @@ static gboolean       do_is_writable( NAIIOProvider *provider );
 static gboolean       do_is_willing_to_write( NAIIOProvider *provider, const GObject *action );
 
 static guint          do_write_action( NAIIOProvider *provider, const GObject *action, gchar **message );
+static guint          do_delete_action( NAIIOProvider *provider, const GObject *action, gchar **message );
 static gboolean       key_is_writable( NAGConf *gconf, const gchar *path );
 static gboolean       write_v2_keys( NAGConf *gconf, const NAAction *action, gchar **message );
 static gboolean       write_str( NAGConf *gconf, const gchar *uuid, const gchar *key, gchar *value, gchar **message );
@@ -195,6 +196,7 @@ iio_provider_iface_init( NAIIOProviderInterface *iface )
 	iface->is_writable = do_is_writable;
 	iface->is_willing_to_write = do_is_willing_to_write;
 	iface->write_action = do_write_action;
+	iface->delete_action = do_delete_action;
 }
 
 static void
@@ -602,6 +604,7 @@ set_action_properties( NAGConf *gconf, NAAction *action, GSList *properties )
 			PROP_ACTION_LABEL_STR, label,
 			PROP_ACTION_TOOLTIP_STR, tooltip,
 			PROP_ACTION_ICON_STR, icon,
+			PROP_ACTION_PROVIDER_STR, gconf,
 			NULL );
 
 	g_free( icon );
@@ -909,9 +912,42 @@ do_write_action( NAIIOProvider *provider, const GObject *obj_action, gchar **mes
 		return( NA_IIO_PROVIDER_WRITE_ERROR );
 	}
 
+	g_object_set( G_OBJECT( action ), PROP_ACTION_PROVIDER_STR, provider, NULL );
+
 	return( NA_IIO_PROVIDER_WRITE_OK );
 }
 
+static guint
+do_delete_action( NAIIOProvider *provider, const GObject *obj_action, gchar **message )
+{
+	static const gchar *thisfn = "nacf_gconf_do_delete_action";
+	g_debug( "%s: provider=%p, action=%p, message=%p", thisfn, provider, obj_action, message );
+
+	g_assert( NA_IS_IIO_PROVIDER( provider ));
+	g_assert( NA_IS_GCONF( provider ));
+	NAGConf *self = NA_GCONF( provider );
+
+	message = NULL;
+	guint ret = NA_IIO_PROVIDER_WRITE_OK;
+
+	g_assert( NA_IS_ACTION( obj_action ));
+	NAAction *action = NA_ACTION( obj_action );
+
+	gchar *uuid = na_action_get_uuid( action );
+	gchar *path = g_strdup_printf( "%s/%s", NA_GCONF_CONFIG_PATH, uuid );
+	GError *error = NULL;
+
+	if( !gconf_client_recursive_unset( self->private->gconf, path, 0, &error )){
+		*message = g_strdup( error->message );
+		g_error_free( error );
+		ret = NA_IIO_PROVIDER_WRITE_ERROR;
+	}
+
+	g_free( path );
+	g_free( uuid );
+	return( ret );
+}
+
 /*
  * gconf_client_key_is_writable doesn't work as I expect: it returns
  * FALSE without error for our keys !
diff --git a/src/common/na-iio-provider.c b/src/common/na-iio-provider.c
index 3533a6f..ca9e89a 100644
--- a/src/common/na-iio-provider.c
+++ b/src/common/na-iio-provider.c
@@ -189,7 +189,7 @@ na_iio_provider_read_actions( const GObject *object )
  * @message: the I/O provider can allocate and store here an error
  * message.
  *
- * Returns TRUE if the write is successfull, FALSE else.
+ * Returns the IIOProvider return code.
  */
 guint
 na_iio_provider_write_action( const GObject *obj_pivot, const GObject *obj_action, gchar **message )
@@ -223,6 +223,40 @@ na_iio_provider_write_action( const GObject *obj_pivot, const GObject *obj_actio
 	return( ret );
 }
 
+/**
+ * Deletes an action from the storage subsystem.
+ *
+ * @obj_pivot: the pivot object which owns the list of registered
+ * interface providers.
+ *
+ * @obj_action: the action to be deleted.
+ *
+ * @message: the I/O provider can allocate and store here an error
+ * message.
+ *
+ * Returns the IIOProvider return code.
+ */
+guint
+na_iio_provider_delete_action( const GObject *obj_pivot, const GObject *obj_action, gchar **message )
+{
+	static const gchar *thisfn = "na_iio_provider_delete_action";
+	g_debug( "%s: pivot=%p, action=%p, message=%p", thisfn, obj_pivot, obj_action, message );
+
+	g_assert( NA_IS_ACTION( obj_action ));
+	guint ret = NA_IIO_PROVIDER_NOT_WRITABLE;
+
+	NAIIOProvider *instance = NA_IIO_PROVIDER( na_action_get_provider( NA_ACTION( obj_action )));
+	if( instance ){
+		g_assert( NA_IS_IIO_PROVIDER( instance ));
+
+		if( NA_IIO_PROVIDER_GET_INTERFACE( instance )->delete_action ){
+			ret = NA_IIO_PROVIDER_GET_INTERFACE( instance )->delete_action( instance, obj_action, message );
+		}
+	}
+
+	return( ret );
+}
+
 static gboolean
 do_is_writable( NAIIOProvider *instance )
 {
diff --git a/src/common/na-iio-provider.h b/src/common/na-iio-provider.h
index 37be550..4c691cc 100644
--- a/src/common/na-iio-provider.h
+++ b/src/common/na-iio-provider.h
@@ -64,6 +64,7 @@ typedef struct {
 	gboolean ( *is_writable )        ( NAIIOProvider *instance );
 	gboolean ( *is_willing_to_write )( NAIIOProvider *instance, const GObject *action );
 	guint    ( *write_action )       ( NAIIOProvider *instance, const GObject *action, gchar **message );
+	guint    ( *delete_action )      ( NAIIOProvider *instance, const GObject *action, gchar **message );
 }
 	NAIIOProviderInterface;
 
@@ -72,6 +73,7 @@ GType    na_iio_provider_get_type( void );
 GSList  *na_iio_provider_read_actions( const GObject *pivot );
 
 guint    na_iio_provider_write_action( const GObject *pivot, const GObject *action, gchar **message );
+guint    na_iio_provider_delete_action( const GObject *pivot, const GObject *action, gchar **message );
 
 /* modification notification message to NAPivot
  */
diff --git a/src/common/na-pivot.c b/src/common/na-pivot.c
index 042f20b..f26801a 100644
--- a/src/common/na-pivot.c
+++ b/src/common/na-pivot.c
@@ -380,9 +380,9 @@ na_pivot_get_action( NAPivot *pivot, const gchar *uuid )
  * @message: the I/O provider can allocate and store here an error
  * message.
  *
- * Returns TRUE if the write is successfull, FALSE else.
+ * Returns the IIOProvider return code.
  */
-gboolean
+guint
 na_pivot_write_action( NAPivot *pivot, const GObject *action, gchar **message )
 {
 	g_assert( NA_IS_PIVOT( pivot ));
@@ -391,6 +391,27 @@ na_pivot_write_action( NAPivot *pivot, const GObject *action, gchar **message )
 	return( na_iio_provider_write_action( G_OBJECT( pivot ), action, message ));
 }
 
+/**
+ * Delete an action.
+ *
+ * @pivot: this NAPivot object.
+ *
+ * @action: action to be deleted from the storage subsystem.
+ *
+ * @message: the I/O provider can allocate and store here an error
+ * message.
+ *
+ * Returns the IIOProvider return code.
+ */
+guint
+na_pivot_delete_action( NAPivot *pivot, const GObject *action, gchar **message )
+{
+	g_assert( NA_IS_PIVOT( pivot ));
+	g_assert( NA_IS_ACTION( action ));
+	g_assert( message );
+	return( na_iio_provider_delete_action( G_OBJECT( pivot ), action, message ));
+}
+
 /*
  * this handler is trigerred by IIOProviders when an action is changed
  * in the underlying storage subsystems
diff --git a/src/common/na-pivot.h b/src/common/na-pivot.h
index 546db3b..db57e58 100644
--- a/src/common/na-pivot.h
+++ b/src/common/na-pivot.h
@@ -74,12 +74,11 @@ NAPivot *na_pivot_new( const GObject *notified );
 GSList  *na_pivot_get_providers( const NAPivot *pivot, GType type );
 
 GSList  *na_pivot_get_actions( const NAPivot *pivot );
-
 void     na_pivot_free_actions( GSList *actions );
 
 GObject *na_pivot_get_action( NAPivot *pivot, const gchar *uuid );
-
-gboolean na_pivot_write_action( NAPivot *pivot, const GObject *action, gchar **message );
+guint    na_pivot_write_action( NAPivot *pivot, const GObject *action, gchar **message );
+guint    na_pivot_delete_action( NAPivot *pivot, const GObject *action, gchar **message );
 
 /* data passed from the storage subsystem when an action is changed
  */
diff --git a/src/nact/Makefile.am b/src/nact/Makefile.am
index 0dede13..f5da17d 100644
--- a/src/nact/Makefile.am
+++ b/src/nact/Makefile.am
@@ -71,8 +71,6 @@ nautilus_actions_config_SOURCES = \
 	nact-profile-editor.h								\
 	nact-editor.c										\
 	nact-editor.h										\
-	nact-action-editor.c								\
-	nact-action-editor.h								\
 	nact-window.c										\
 	nact-window.h										\
 	$(NULL)
diff --git a/src/nact/base-application.c b/src/nact/base-application.c
index 9405ac6..4df9728 100644
--- a/src/nact/base-application.c
+++ b/src/nact/base-application.c
@@ -1015,3 +1015,22 @@ base_application_error_dlg(
 
 	gtk_widget_destroy( dialog );
 }
+
+gboolean
+base_application_yesno_dlg( BaseApplication *application, GtkMessageType type, const gchar *msg )
+{
+	g_assert( BASE_IS_APPLICATION( application ));
+
+	GtkWidget *dialog = gtk_message_dialog_new(
+			NULL, GTK_DIALOG_MODAL, type, GTK_BUTTONS_YES_NO, msg );
+
+	const gchar *name = g_get_application_name();
+
+	g_object_set( G_OBJECT( dialog ) , "title", name, NULL );
+
+	gint result = gtk_dialog_run( GTK_DIALOG( dialog ));
+
+	gtk_widget_destroy( dialog );
+
+	return( result == GTK_RESPONSE_YES );
+}
diff --git a/src/nact/base-application.h b/src/nact/base-application.h
index b7cf0d0..dd97dd2 100644
--- a/src/nact/base-application.h
+++ b/src/nact/base-application.h
@@ -108,6 +108,7 @@ GObject   *base_application_get_main_window( BaseApplication *application );
 GtkWidget *base_application_get_widget( BaseApplication *application, const gchar *name );
 
 void       base_application_error_dlg( BaseApplication *application, GtkMessageType type, const gchar *primary, const gchar *secondary );
+gboolean   base_application_yesno_dlg( BaseApplication *application, GtkMessageType type, const gchar *msg );
 
 G_END_DECLS
 
diff --git a/src/nact/base-window.c b/src/nact/base-window.c
index 8281341..1ddbd39 100644
--- a/src/nact/base-window.c
+++ b/src/nact/base-window.c
@@ -592,3 +592,17 @@ is_main_window( BaseWindow *window )
 
 	return( main_widget == this_widget );
 }
+
+void
+base_window_error_dlg( BaseWindow *window, GtkMessageType type, const gchar *primary, const gchar *secondary )
+{
+	g_assert( BASE_IS_WINDOW( window ));
+	base_application_error_dlg( window->private->application, type, primary, secondary );
+}
+
+gboolean
+base_window_yesno_dlg( BaseWindow *window, GtkMessageType type, const gchar *msg )
+{
+	g_assert( BASE_IS_WINDOW( window ));
+	return( base_application_yesno_dlg( window->private->application, type, msg ));
+}
diff --git a/src/nact/base-window.h b/src/nact/base-window.h
index e121392..87cc4e8 100644
--- a/src/nact/base-window.h
+++ b/src/nact/base-window.h
@@ -95,6 +95,9 @@ GtkWidget *base_window_get_widget( BaseWindow *window, const gchar *name );
 
 void       base_window_connect( BaseWindow *window, const gchar *widget, const gchar *signal, GCallback handler );
 
+void       base_window_error_dlg( BaseWindow *window, GtkMessageType type, const gchar *primary, const gchar *secondary );
+gboolean   base_window_yesno_dlg( BaseWindow *window, GtkMessageType type, const gchar *msg );
+
 G_END_DECLS
 
 #endif /* __BASE_WINDOW_H__ */
diff --git a/src/nact/nact-main-window.c b/src/nact/nact-main-window.c
index 5b74e70..8669f58 100644
--- a/src/nact/nact-main-window.c
+++ b/src/nact/nact-main-window.c
@@ -40,6 +40,7 @@
 #include <common/na-action.h>
 #include <common/na-action-profile.h>
 #include <common/na-pivot.h>
+#include <common/na-iio-provider.h>
 #include <common/na-ipivot-container.h>
 
 #include "nact-application.h"
@@ -398,8 +399,7 @@ on_add_button_clicked( GtkButton *button, gpointer user_data )
 	nact_action_conditions_editor_run_editor( wndmain, NULL );
 
 	/* TODO: set the selection to the newly created action
-	 * or restore the previous selection
-	 */
+	 * or restore the previous selection */
 }
 
 /*
@@ -437,6 +437,8 @@ on_edit_button_clicked( GtkButton *button, gpointer user_data )
 	} else {
 		g_assert_not_reached();
 	}
+
+	/* TODO: reset the selection to the edited action */
 }
 
 static void
@@ -449,29 +451,32 @@ on_duplicate_button_clicked( GtkButton *button, gpointer user_data )
 	NactWindow *wndmain = NACT_WINDOW( user_data );
 
 	NAAction *action = NA_ACTION( nact_iactions_list_get_selected_action( wndmain ));
-
 	if( action ){
+
 		NAAction *duplicate = na_action_duplicate( action );
 		na_action_set_new_uuid( duplicate );
+		gchar *label = na_action_get_label( action );
+		gchar *label2 = g_strdup_printf( _( "Copy of %s"), label );
+		na_action_set_label( duplicate, label2 );
+		g_free( label2 );
 
 		gchar *msg = NULL;
 		NAPivot *pivot = NA_PIVOT( nact_window_get_pivot( wndmain ));
-		if( !na_pivot_write_action( pivot, G_OBJECT( duplicate ), &msg )){
+		if( na_pivot_write_action( pivot, G_OBJECT( duplicate ), &msg ) != NA_IIO_PROVIDER_WRITE_OK ){
 
-			BaseApplication *application;
-			g_object_get( G_OBJECT( wndmain ), PROP_WINDOW_APPLICATION_STR, &application, NULL );
-			g_assert( NACT_IS_APPLICATION( application ));
-			gchar *label = na_action_get_label( action );
 			gchar *first = g_strdup_printf( _( "Unable to duplicate \"%s\" action." ), label );
-			base_application_error_dlg( application, GTK_MESSAGE_ERROR, first, msg );
+			base_window_error_dlg( BASE_WINDOW( wndmain ), GTK_MESSAGE_ERROR, first, msg );
 			g_free( first );
-			g_free( label );
 			g_free( msg );
 		}
 
+		g_free( label );
+
 	} else {
 		g_assert_not_reached();
 	}
+
+	/* TODO: set the selection to the newly created action */
 }
 
 static void
@@ -480,24 +485,34 @@ on_delete_button_clicked( GtkButton *button, gpointer user_data )
 	static const gchar *thisfn = "nact_main_window_on_delete_button_clicked";
 	g_debug( "%s: button=%p, user_data=%p", thisfn, button, user_data );
 
-	/*GtkTreeSelection *selection;
-	GtkTreeIter iter;
-	GtkWidget *nact_actions_list;
-	GtkTreeModel* model;
+	g_assert( NACT_IS_MAIN_WINDOW( user_data ));
+	NactWindow *wndmain = NACT_WINDOW( user_data );
 
-	nact_actions_list = nact_get_glade_widget ("ActionsList");
+	NAAction *action = NA_ACTION( nact_iactions_list_get_selected_action( wndmain ));
+	if( action ){
 
-	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (nact_actions_list));
+		gchar *label = na_action_get_label( action );
+		gchar *sure = g_strdup_printf( _( "Are you sure you want to delete \"%s\" action ?" ), label );
+		if( base_window_yesno_dlg( BASE_WINDOW( wndmain ), GTK_MESSAGE_WARNING, sure )){
 
-	if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
-		gchar *uuid;
+			gchar *msg = NULL;
+			NAPivot *pivot = NA_PIVOT( nact_window_get_pivot( wndmain ));
+			if( na_pivot_delete_action( pivot, G_OBJECT( action ), &msg ) != NA_IIO_PROVIDER_WRITE_OK ){
 
-		gtk_tree_model_get (model, &iter, IACTIONS_LIST_UUID_COLUMN, &uuid, -1);*/
-		/*nautilus_actions_config_remove_action (NAUTILUS_ACTIONS_CONFIG (config), uuid);*/
-		/*fill_actions_list (nact_actions_list);
+				gchar *first = g_strdup_printf( _( "Unable to delete \"%s\" action." ), label );
+				base_window_error_dlg( BASE_WINDOW( wndmain ), GTK_MESSAGE_ERROR, first, msg );
+				g_free( first );
+				g_free( msg );
+			}
+		}
+		g_free( sure );
+		g_free( label );
 
-		g_free (uuid);
-	}*/
+	} else {
+		g_assert_not_reached();
+	}
+	/* TODO: set the selection to the previous action if any
+	 * or to the next one */
 }
 
 static void



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