[nautilus-actions] Let the user enable/disable an action



commit 98fbb81546baf392391f591248e1c935cff9e520
Author: Pierre Wieser <pwieser trychlos org>
Date:   Tue Aug 11 00:07:59 2009 +0200

    Let the user enable/disable an action

 ChangeLog                                |   30 +++++++++
 NEWS                                     |    1 +
 data/nautilus-actions.schemas.in         |   11 +++
 src/common/na-action.c                   |   63 +++++++++++++++++++-
 src/common/na-action.h                   |    2 +
 src/common/na-gconf-keys.h               |    1 +
 src/common/na-gconf.c                    |   15 ++++-
 src/common/na-xml-names.h                |   58 +++++++++---------
 src/common/na-xml-writer.c               |   43 +++++++++-----
 src/nact/nact-iaction-tab.c              |   30 +++++++++
 src/nact/nact-xml-reader.c               |    4 +
 src/nact/nautilus-actions-config-tool.ui |   98 ++++++++++++++++++++++++++++--
 src/plugin/nautilus-actions.c            |    4 +
 src/utils/nautilus-actions-new.c         |    3 +
 14 files changed, 312 insertions(+), 51 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e0297fd..b9f9b4d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,33 @@
+2009-08-10 Pierre Wieser <pwieser trychlos org>
+
+	* data/nautilus-actions.schemas.in:
+	Add schema description for 'enabled' action property.
+
+	* src/common/na-action.c:
+	* src/common/na-action.h:
+	Define 'enabled' new action property.
+
+	* src/common/na-gconf-keys.h:
+	* src/common/na-xml-names.h:
+	Define GConf entry and schema description for 'enabled' property.
+
+	* src/common/na-gconf.c:
+	Read 'enabled' property from GConf.
+
+	* src/common/na-xml-writer.c:
+	* src/nact/nact-xml-reader.c:
+	Import and export 'enabled' action property.
+
+	* src/nact/nact-iaction-tab.c:
+	* src/nact/nautilus-actions-config-tool.ui:
+	Display and update 'enabled' action property.
+
+	* src/plugin/nautilus-actions.c:
+	Do not display item if action is disabled.
+
+	* src/utils/nautilus-actions-new.c:
+	Add '--enabled' command-line option.
+
 2009-08-09 Pierre Wieser <pwieser trychlos org>
 
 	* src/nact/nact-assistant-export.c:
diff --git a/NEWS b/NEWS
index bfbd8e9..07c866d 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ Version 1.11.3
 
 	Bugfixes
 
+		#325519 asked by Frederic Ruaudel (enabled property)
 		#590398 reported by Pierre Wieser (install doc)
 		#590709 reported by Claude Paroz (markup in translatable strings)
 		#590711 reported by Claude Paroz (pipe char is ambiguous to translate)
diff --git a/data/nautilus-actions.schemas.in b/data/nautilus-actions.schemas.in
index 260ed15..9efddca 100644
--- a/data/nautilus-actions.schemas.in
+++ b/data/nautilus-actions.schemas.in
@@ -52,6 +52,17 @@
     </schema>
 
     <schema>
+      <key>/schemas/apps/nautilus-actions/configurations/enabled</key>
+      <owner>nautilus-actions</owner>
+      <type>bool</type>
+      <locale name="C">
+        <short>Whether the action is enabled</short>
+        <long>If the action is disabled, it will never appear in the Nautilus context menu</long>
+      </locale>
+      <default>true</default>
+    </schema>
+
+    <schema>
       <key>/schemas/apps/nautilus-actions/configurations/desc-name</key>
       <owner>nautilus-actions</owner>
       <type>string</type>
diff --git a/src/common/na-action.c b/src/common/na-action.c
index 944c566..76afa0c 100644
--- a/src/common/na-action.c
+++ b/src/common/na-action.c
@@ -54,6 +54,7 @@ struct NAActionPrivate {
 	gchar         *version;
 	gchar         *tooltip;
 	gchar         *icon;
+	gboolean       enabled;
 
 	/* list of action's profiles as NAActionProfile objects
 	 *  (thanks, Frederic ;-))
@@ -80,6 +81,7 @@ enum {
 	PROP_NAACTION_VERSION,
 	PROP_NAACTION_TOOLTIP,
 	PROP_NAACTION_ICON,
+	PROP_NAACTION_ENABLED,
 	PROP_NAACTION_READONLY,
 	PROP_NAACTION_PROVIDER
 };
@@ -89,6 +91,7 @@ enum {
 #define PROP_NAACTION_VERSION_STR		"na-action-version"
 #define PROP_NAACTION_TOOLTIP_STR		"na-action-tooltip"
 #define PROP_NAACTION_ICON_STR			"na-action-icon"
+#define PROP_NAACTION_ENABLED_STR		"na-action-enabled"
 #define PROP_NAACTION_READONLY_STR		"na-action-read-only"
 #define PROP_NAACTION_PROVIDER_STR		"na-action-provider"
 
@@ -197,6 +200,13 @@ class_init( NAActionClass *klass )
 	g_object_class_install_property( object_class, PROP_NAACTION_ICON, spec );
 
 	spec = g_param_spec_boolean(
+			PROP_NAACTION_ENABLED_STR,
+			"Enabled",
+			"Whether this action is enabled", TRUE,
+			G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
+	g_object_class_install_property( object_class, PROP_NAACTION_ENABLED, spec );
+
+	spec = g_param_spec_boolean(
 			PROP_NAACTION_READONLY_STR,
 			"Read-only flag",
 			"Is this action only readable", FALSE,
@@ -238,6 +248,7 @@ instance_init( GTypeInstance *instance, gpointer klass )
 	self->private->version = g_strdup( NA_ACTION_LATEST_VERSION );
 	self->private->tooltip = g_strdup( "" );
 	self->private->icon = g_strdup( "" );
+	self->private->enabled = TRUE;
 	self->private->read_only = FALSE;
 	self->private->provider = NULL;
 }
@@ -269,6 +280,10 @@ instance_get_property( GObject *object, guint property_id, GValue *value, GParam
 			g_value_set_string( value, self->private->icon );
 			break;
 
+		case PROP_NAACTION_ENABLED:
+			g_value_set_boolean( value, self->private->enabled );
+			break;
+
 		case PROP_NAACTION_READONLY:
 			g_value_set_boolean( value, self->private->read_only );
 			break;
@@ -313,6 +328,10 @@ instance_set_property( GObject *object, guint property_id, const GValue *value,
 			self->private->icon = g_value_dup_string( value );
 			break;
 
+		case PROP_NAACTION_ENABLED:
+			self->private->enabled = g_value_get_boolean( value );
+			break;
+
 		case PROP_NAACTION_READONLY:
 			self->private->read_only = g_value_get_boolean( value );
 			break;
@@ -545,6 +564,26 @@ na_action_get_verified_icon_name( const NAAction *action )
 }
 
 /**
+ * na_action_is_enabled:
+ * @action: the #NAAction object to be requested.
+ *
+ * Is the specified action enabled ?
+ * When disabled, the action is never candidate to any selection
+ *
+ * Returns: %TRUE if the action is enabled, %FALSE else.
+ */
+gboolean
+na_action_is_enabled( const NAAction *action )
+{
+	g_assert( NA_IS_ACTION( action ));
+
+	gboolean enabled;
+	g_object_get( G_OBJECT( action ), PROP_NAACTION_ENABLED_STR, &enabled, NULL );
+
+	return( enabled );
+}
+
+/**
  * na_action_is_readonly:
  * @action: the #NAAction object to be requested.
  *
@@ -724,6 +763,21 @@ na_action_set_icon( NAAction *action, const gchar *icon )
 }
 
 /**
+ * na_action_set_enabled:
+ * @action: the #NAAction object to be updated.
+ * @enabled: the indicator to be set.
+ *
+ * Sets whether the action is enabled or not.
+ */
+void
+na_action_set_enabled( NAAction *action, gboolean enabled )
+{
+	g_assert( NA_IS_ACTION( action ));
+
+	g_object_set( G_OBJECT( action ), PROP_NAACTION_ENABLED_STR, enabled, NULL );
+}
+
+/**
  * na_action_set_readonly:
  * @action: the #NAAction object to be updated.
  * @readonly: the indicator to be set.
@@ -959,6 +1013,7 @@ object_dump( const NAObject *action )
 	g_debug( "%s:   version='%s'", thisfn, self->private->version );
 	g_debug( "%s:   tooltip='%s'", thisfn, self->private->tooltip );
 	g_debug( "%s:      icon='%s'", thisfn, self->private->icon );
+	g_debug( "%s:   enabled='%s'", thisfn, self->private->enabled ? "True" : "False" );
 	g_debug( "%s: read-only='%s'", thisfn, self->private->read_only ? "True" : "False" );
 	g_debug( "%s:  provider=%p", thisfn, self->private->provider );
 
@@ -989,13 +1044,14 @@ object_copy( NAObject *target, const NAObject *source )
 	g_assert( NA_IS_ACTION( target ));
 
 	gchar *version, *tooltip, *icon;
-	gboolean readonly;
+	gboolean enabled, readonly;
 	gpointer provider;
 
 	g_object_get( G_OBJECT( source ),
 			PROP_NAACTION_VERSION_STR, &version,
 			PROP_NAACTION_TOOLTIP_STR, &tooltip,
 			PROP_NAACTION_ICON_STR, &icon,
+			PROP_NAACTION_ENABLED_STR, &enabled,
 			PROP_NAACTION_READONLY_STR, &readonly,
 			PROP_NAACTION_PROVIDER_STR, &provider,
 			NULL );
@@ -1004,6 +1060,7 @@ object_copy( NAObject *target, const NAObject *source )
 			PROP_NAACTION_VERSION_STR, version,
 			PROP_NAACTION_TOOLTIP_STR, tooltip,
 			PROP_NAACTION_ICON_STR, icon,
+			PROP_NAACTION_ENABLED_STR, enabled,
 			PROP_NAACTION_READONLY_STR, readonly,
 			PROP_NAACTION_PROVIDER_STR, provider,
 			NULL );
@@ -1037,6 +1094,10 @@ object_are_equal( const NAObject *a, const NAObject *b )
 		( g_utf8_collate( first->private->icon, second->private->icon ) == 0 );
 
 	if( equal ){
+		equal = ( first->private->enabled && second->private->enabled ) ||
+				( !first->private->enabled && !second->private->enabled );
+	}
+	if( equal ){
 		equal = ( g_slist_length( first->private->profiles ) == g_slist_length( second->private->profiles ));
 	}
 	if( equal ){
diff --git a/src/common/na-action.h b/src/common/na-action.h
index 7a90c08..c9a80a8 100644
--- a/src/common/na-action.h
+++ b/src/common/na-action.h
@@ -60,6 +60,7 @@ gchar           *na_action_get_version( const NAAction *action );
 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_enabled( const NAAction *action );
 gboolean         na_action_is_readonly( const NAAction *action );
 NAIIOProvider   *na_action_get_provider( const NAAction *action );
 
@@ -69,6 +70,7 @@ void             na_action_set_label( NAAction *action, const gchar *label );
 void             na_action_set_version( NAAction *action, const gchar *version );
 void             na_action_set_tooltip( NAAction *action, const gchar *tooltip );
 void             na_action_set_icon( NAAction *action, const gchar *icon_name );
+void             na_action_set_enabled( NAAction *action, gboolean enabled );
 void             na_action_set_readonly( NAAction *action, gboolean readonly );
 void             na_action_set_provider( NAAction *action, const NAIIOProvider *provider );
 
diff --git a/src/common/na-gconf-keys.h b/src/common/na-gconf-keys.h
index d3b2bbf..a3bb325 100644
--- a/src/common/na-gconf-keys.h
+++ b/src/common/na-gconf-keys.h
@@ -44,6 +44,7 @@
 #define ACTION_LABEL_ENTRY				"label"
 #define ACTION_TOOLTIP_ENTRY			"tooltip"
 #define ACTION_ICON_ENTRY				"icon"
+#define ACTION_ENABLED_ENTRY			"enabled"
 #define ACTION_PROFILE_LABEL_ENTRY		"desc-name"
 #define ACTION_PATH_ENTRY				"path"
 #define ACTION_PARAMETERS_ENTRY			"parameters"
diff --git a/src/common/na-gconf.c b/src/common/na-gconf.c
index 403e02d..8fa2b88 100644
--- a/src/common/na-gconf.c
+++ b/src/common/na-gconf.c
@@ -583,6 +583,11 @@ fill_action_core_properties( NAGConf *gconf, NAAction *action, GSList *notifies
 		na_action_set_icon( action, icon );
 		g_free( icon );
 	}
+
+	gboolean enabled;
+	if( search_for_bool( notifies, NULL, ACTION_ENABLED_ENTRY, &enabled )){
+		na_action_set_enabled( action, enabled );
+	}
 }
 
 /*
@@ -944,7 +949,8 @@ write_v2_keys( NAGConf *gconf, const NAAction *action, gchar **message )
 		write_str( gconf, uuid, ACTION_VERSION_ENTRY, na_action_get_version( action ), message ) &&
 		write_str( gconf, uuid, ACTION_LABEL_ENTRY, na_action_get_label( action ), message ) &&
 		write_str( gconf, uuid, ACTION_TOOLTIP_ENTRY, na_action_get_tooltip( action ), message ) &&
-		write_str( gconf, uuid, ACTION_ICON_ENTRY, na_action_get_icon( action ), message );
+		write_str( gconf, uuid, ACTION_ICON_ENTRY, na_action_get_icon( action ), message ) &&
+		write_bool( gconf, uuid, NULL, ACTION_ENABLED_ENTRY, na_action_is_enabled( action ), message );
 
 	GSList *ip;
 	GSList *profiles = na_action_get_profiles( action );
@@ -1014,7 +1020,12 @@ write_bool( NAGConf *gconf, const gchar *uuid, const gchar *name, const gchar *k
 	gboolean ret = TRUE;
 	GError *error = NULL;
 
-	gchar *path = g_strdup_printf( "%s/%s/%s/%s", NA_GCONF_CONFIG_PATH, uuid, name, key );
+	gchar *path;
+	if( name && strlen( name )){
+		path = g_strdup_printf( "%s/%s/%s/%s", NA_GCONF_CONFIG_PATH, uuid, name, key );
+	} else {
+		path = g_strdup_printf( "%s/%s/%s", NA_GCONF_CONFIG_PATH, uuid, key );
+	}
 
 	if( !gconf_client_set_bool( gconf->private->gconf, path, value, &error )){
 		*message = g_strdup( error->message );
diff --git a/src/common/na-xml-names.h b/src/common/na-xml-names.h
index edd1513..f4a5959 100644
--- a/src/common/na-xml-names.h
+++ b/src/common/na-xml-names.h
@@ -98,34 +98,36 @@ enum {
 
 /* GConf schema descriptions
  */
-#define ACTION_LABEL_DESC_SHORT		_("The label of the menu item")
-#define ACTION_LABEL_DESC_LONG		_("The label of the menu item that will appear in the Nautilus popup menu when the selection matches the appearance condition settings")
-#define ACTION_TOOLTIP_DESC_SHORT	_("The tooltip of the menu item")
-#define ACTION_TOOLTIP_DESC_LONG	_("The tooltip of the menu item that will appear in the Nautilus statusbar when the user points to the Nautilus popup menu item with his/her mouse")
-#define ACTION_ICON_DESC_SHORT		_("The icon of the menu item")
-#define ACTION_ICON_DESC_LONG		_("The icon of the menu item that will appear next to the label in the Nautilus popup menu when the selection matches the appearance conditions settings")
-#define ACTION_PROFILE_NAME_DESC_SHORT	_("A description name of the profile")
-#define ACTION_PROFILE_NAME_DESC_LONG	_("The field is here to give the user a human readable name for a profile in the Nact interface. If not set there will be a default auto generated string set by default")
-#define ACTION_PATH_DESC_SHORT		_("The path of the command")
-#define ACTION_PATH_DESC_LONG		_("The path of the command to start when the user select the menu item in the Nautilus popup menu")
-#define ACTION_PARAMETERS_DESC_SHORT _("The parameters of the command")
-#define ACTION_PARAMETERS_DESC_LONG	_("The parameters of the command to start when the user selects the menu item in the Nautilus popup menu.\n\nThe parameters can contain some special tokens which are replaced by Nautilus information before starting the command:\n\n%d: base folder of the selected file(s)\n%f: the name of the selected file or the first one if many are selected\n%h: hostname of the URI\n%m: space-separated list of the basenames of the selected file(s)/folder(s)\n%M: space-separated list of the selected file(s)/folder(s), with their full paths\n%p: port number of the first URI\n%R: space-separated list of selected URIs\n%s: scheme of the URI\n%u: URI\n%U: username of the URI\n%%: a percent sign")
-#define ACTION_BASENAMES_DESC_SHORT	_("The list of pattern to match the selected file(s)/folder(s)")
-#define ACTION_BASENAMES_DESC_LONG	_("A list of strings with joker '*' or '?' to match the name of the selected file(s)/folder(s). Each selected items must match at least one of the filename patterns for the action to appear")
-#define ACTION_MATCHCASE_DESC_SHORT _("'true' if the filename patterns have to be case sensitive, 'false' otherwise")
-#define ACTION_MATCHCASE_DESC_LONG	_("If you need to match a filename in a case-sensitive manner, set this key to 'true'. If you also want, for example '*.jpg' to match 'photo.JPG', set 'false'")
-#define ACTION_MIMETYPES_DESC_SHORT	_("The list of patterns to match the mimetypes of the selected file(s)")
-#define ACTION_MIMETYPES_DESC_LONG	_("A list of strings with joker '*' or '?' to match the mimetypes of the selected file(s). Each selected items must match at least one of the mimetype patterns for the action to appear")
-#define ACTION_ISFILE_DESC_SHORT	_("'true' if the selection can have files, 'false' otherwise")
-#define ACTION_ISFILE_DESC_LONG		_("This setting is tied in with the 'isdir' setting. The valid combinations are:\n\nisfile=TRUE and isdir=FALSE: the selection may hold only files\nisfile=FALSE and isdir=TRUE: the selection may hold only folders\nisfile=TRUE and isdir=TRUE: the selection may hold both files and folders\nisfile=FALSE and isdir=FALSE: this is an invalid combination (your configuration will never appear)")
-#define ACTION_ISDIR_DESC_SHORT		_("'true' if the selection can have folders, 'false' otherwise")
-#define ACTION_ISDIR_DESC_LONG		_("This setting is tied in with the 'isfile' setting. The valid combinations are:\n\nisfile=TRUE and isdir=FALSE: the selection may hold only files\nisfile=FALSE and isdir=TRUE: the selection may hold only folders\nisfile=TRUE and isdir=TRUE: the selection may hold both files and folders\nisfile=FALSE and isdir=FALSE: this is an invalid combination (your configuration will never appear)")
-#define ACTION_MULTIPLE_DESC_SHORT	_("'true' if the selection can have several items, 'false' otherwise")
-#define ACTION_MULTIPLE_DESC_LONG	_("If you need one or more files or folders to be selected, set this key to 'true'. If you want just one file or folder, set 'false'")
-#define ACTION_SCHEMES_DESC_SHORT	_("The list of schemes where the selected files should be located")
-#define ACTION_SCHEMES_DESC_LONG	_("Defines the list of valid schemes to be matched against the selected items. The scheme is the protocol used to access the files. The keyword to use is the one used in the URI.\n\nExamples of valid URI include:\nfile:///tmp/foo.txt\nsftp:///root test example net/tmp/foo.txt\n\nThe most common schemes are:\n\n'file': local files\n'sftp': files accessed via SSH\n'ftp': files accessed via FTP\n'smb': files accessed via Samba (Windows share)\n'dav': files accessed via WebDAV\n\nAll schemes used by Nautilus can be used here.")
-#define ACTION_VERSION_DESC_SHORT	_("The version of the configuration format")
-#define ACTION_VERSION_DESC_LONG	_("The version of the configuration format that will be used to manage backward compatibility")
+#define ACTION_LABEL_DESC_SHORT		_( "The label of the menu item" )
+#define ACTION_LABEL_DESC_LONG		_( "The label of the menu item that will appear in the Nautilus popup menu when the selection matches the appearance condition settings" )
+#define ACTION_TOOLTIP_DESC_SHORT	_( "The tooltip of the menu item" )
+#define ACTION_TOOLTIP_DESC_LONG	_( "The tooltip of the menu item that will appear in the Nautilus statusbar when the user points to the Nautilus popup menu item with his/her mouse" )
+#define ACTION_ICON_DESC_SHORT		_( "The icon of the menu item" )
+#define ACTION_ICON_DESC_LONG		_( "The icon of the menu item that will appear next to the label in the Nautilus popup menu when the selection matches the appearance conditions settings" )
+#define ACTION_ENABLED_DESC_SHORT	_( "Whether the action is enabled" )
+#define ACTION_ENABLED_DESC_LONG	_( "If the action is disabled, it will never appear in the Nautilus context menu" )
+#define ACTION_PROFILE_NAME_DESC_SHORT	_( "A description name of the profile" )
+#define ACTION_PROFILE_NAME_DESC_LONG	_( "The field is here to give the user a human readable name for a profile in the Nact interface. If not set there will be a default auto generated string set by default" )
+#define ACTION_PATH_DESC_SHORT		_( "The path of the command" )
+#define ACTION_PATH_DESC_LONG		_( "The path of the command to start when the user select the menu item in the Nautilus popup menu" )
+#define ACTION_PARAMETERS_DESC_SHORT _( "The parameters of the command" )
+#define ACTION_PARAMETERS_DESC_LONG	_( "The parameters of the command to start when the user selects the menu item in the Nautilus popup menu.\n\nThe parameters can contain some special tokens which are replaced by Nautilus information before starting the command:\n\n%d: base folder of the selected file(s)\n%f: the name of the selected file or the first one if many are selected\n%h: hostname of the URI\n%m: space-separated list of the basenames of the selected file(s)/folder(s)\n%M: space-separated list of the selected file(s)/folder(s), with their full paths\n%p: port number of the first URI\n%R: space-separated list of selected URIs\n%s: scheme of the URI\n%u: URI\n%U: username of the URI\n%%: a percent sign" )
+#define ACTION_BASENAMES_DESC_SHORT	_( "The list of pattern to match the selected file(s)/folder(s)" )
+#define ACTION_BASENAMES_DESC_LONG	_( "A list of strings with joker '*' or '?' to match the name of the selected file(s)/folder(s). Each selected items must match at least one of the filename patterns for the action to appear" )
+#define ACTION_MATCHCASE_DESC_SHORT _( "'true' if the filename patterns have to be case sensitive, 'false' otherwise" )
+#define ACTION_MATCHCASE_DESC_LONG	_( "If you need to match a filename in a case-sensitive manner, set this key to 'true'. If you also want, for example '*.jpg' to match 'photo.JPG', set 'false'" )
+#define ACTION_MIMETYPES_DESC_SHORT	_( "The list of patterns to match the mimetypes of the selected file(s)" )
+#define ACTION_MIMETYPES_DESC_LONG	_( "A list of strings with joker '*' or '?' to match the mimetypes of the selected file(s). Each selected items must match at least one of the mimetype patterns for the action to appear" )
+#define ACTION_ISFILE_DESC_SHORT	_( "'true' if the selection can have files, 'false' otherwise" )
+#define ACTION_ISFILE_DESC_LONG		_( "This setting is tied in with the 'isdir' setting. The valid combinations are:\n\nisfile=TRUE and isdir=FALSE: the selection may hold only files\nisfile=FALSE and isdir=TRUE: the selection may hold only folders\nisfile=TRUE and isdir=TRUE: the selection may hold both files and folders\nisfile=FALSE and isdir=FALSE: this is an invalid combination (your configuration will never appear)" )
+#define ACTION_ISDIR_DESC_SHORT		_( "'true' if the selection can have folders, 'false' otherwise" )
+#define ACTION_ISDIR_DESC_LONG		_( "This setting is tied in with the 'isfile' setting. The valid combinations are:\n\nisfile=TRUE and isdir=FALSE: the selection may hold only files\nisfile=FALSE and isdir=TRUE: the selection may hold only folders\nisfile=TRUE and isdir=TRUE: the selection may hold both files and folders\nisfile=FALSE and isdir=FALSE: this is an invalid combination (your configuration will never appear)" )
+#define ACTION_MULTIPLE_DESC_SHORT	_( "'true' if the selection can have several items, 'false' otherwise" )
+#define ACTION_MULTIPLE_DESC_LONG	_( "If you need one or more files or folders to be selected, set this key to 'true'. If you want just one file or folder, set 'false'" )
+#define ACTION_SCHEMES_DESC_SHORT	_( "The list of schemes where the selected files should be located" )
+#define ACTION_SCHEMES_DESC_LONG	_( "Defines the list of valid schemes to be matched against the selected items. The scheme is the protocol used to access the files. The keyword to use is the one used in the URI.\n\nExamples of valid URI include:\nfile:///tmp/foo.txt\nsftp:///root test example net/tmp/foo.txt\n\nThe most common schemes are:\n\n'file': local files\n'sftp': files accessed via SSH\n'ftp': files accessed via FTP\n'smb': files accessed via Samba (Windows share)\n'dav': files accessed via WebDAV\n\nAll schemes used by Nautilus can be used here." )
+#define ACTION_VERSION_DESC_SHORT	_( "The version of the configuration format" )
+#define ACTION_VERSION_DESC_LONG	_( "The version of the configuration format that will be used to manage backward compatibility" )
 
 G_END_DECLS
 
diff --git a/src/common/na-xml-writer.c b/src/common/na-xml-writer.c
index 3610347..723f197 100644
--- a/src/common/na-xml-writer.c
+++ b/src/common/na-xml-writer.c
@@ -357,6 +357,12 @@ create_xml_schema( NAXMLWriter *writer, gint format, NAAction *action )
 	create_schema_entry( writer, format, NULL, ACTION_ICON_ENTRY, icon, doc, list_node, "string", FALSE, ACTION_ICON_DESC_SHORT, ACTION_ICON_DESC_LONG );
 	g_free( icon );
 
+	/* enabled */
+	gboolean enabled = na_action_is_enabled( action );
+	gchar *text = na_utils_boolean_to_schema( enabled );
+	create_schema_entry( writer, format, NULL, ACTION_ENABLED_ENTRY, text, doc, list_node, "bool", FALSE, ACTION_ENABLED_DESC_SHORT, ACTION_ENABLED_DESC_LONG );
+	g_free( text );
+
 	GSList *profiles = na_action_get_profiles( action );
 	GSList *ip;
 
@@ -382,7 +388,7 @@ create_xml_schema( NAXMLWriter *writer, gint format, NAAction *action )
 
 		/* basenames */
 		GSList *basenames = na_action_profile_get_basenames( profile );
-		gchar *text = na_utils_gslist_to_schema( basenames );
+		text = na_utils_gslist_to_schema( basenames );
 		create_schema_entry( writer, format, profile_dir, ACTION_BASENAMES_ENTRY, text, doc, list_node, "list", FALSE, ACTION_BASENAMES_DESC_SHORT, ACTION_BASENAMES_DESC_LONG );
 		g_free( text );
 		na_utils_free_string_list( basenames );
@@ -520,6 +526,12 @@ create_xml_dump( NAXMLWriter *writer, gint format, NAAction *action )
 	create_dump_entry( writer, format, NULL, ACTION_ICON_ENTRY, icon, doc, list_node, "string" );
 	g_free( icon );
 
+	/* enabled */
+	gboolean enabled = na_action_is_enabled( action );
+	gchar *text = na_utils_boolean_to_schema( enabled );
+	create_dump_entry( writer, format, NULL, ACTION_ENABLED_ENTRY, text, doc, list_node, "bool" );
+	g_free( text );
+
 	GSList *profiles = na_action_get_profiles( action );
 	GSList *ip;
 
@@ -545,7 +557,7 @@ create_xml_dump( NAXMLWriter *writer, gint format, NAAction *action )
 
 		/* basenames */
 		GSList *basenames = na_action_profile_get_basenames( profile );
-		gchar *text = na_utils_gslist_to_schema( basenames );
+		text = na_utils_gslist_to_schema( basenames );
 		create_dump_entry( writer, format, profile_dir, ACTION_BASENAMES_ENTRY, text, doc, list_node, "list" );
 		g_free( text );
 		na_utils_free_string_list( basenames );
@@ -639,20 +651,21 @@ create_gconf_schema( NAXMLWriter *writer )
 	xmlDocSetRootElement( doc, root_node );
 	xmlNodePtr list_node = xmlNewChild( root_node, NULL, BAD_CAST( NACT_GCONF_SCHEMA_LIST ), NULL );
 
-	create_gconf_schema_entry( writer, ACTION_VERSION_ENTRY       , doc, list_node, "string", ACTION_VERSION_DESC_SHORT     , ACTION_VERSION_DESC_LONG, NAUTILUS_ACTIONS_CONFIG_VERSION, FALSE );
-	create_gconf_schema_entry( writer, ACTION_LABEL_ENTRY         , doc, list_node, "string", ACTION_LABEL_DESC_SHORT       , ACTION_LABEL_DESC_LONG, "", TRUE );
-	create_gconf_schema_entry( writer, ACTION_TOOLTIP_ENTRY       , doc, list_node, "string", ACTION_TOOLTIP_DESC_SHORT     , ACTION_TOOLTIP_DESC_LONG, "", TRUE );
-	create_gconf_schema_entry( writer, ACTION_ICON_ENTRY          , doc, list_node, "string", ACTION_ICON_DESC_SHORT        , ACTION_ICON_DESC_LONG, "", FALSE );
+	create_gconf_schema_entry( writer, ACTION_VERSION_ENTRY       , doc, list_node, "string", ACTION_VERSION_DESC_SHORT     , ACTION_VERSION_DESC_LONG     , NAUTILUS_ACTIONS_CONFIG_VERSION, FALSE );
+	create_gconf_schema_entry( writer, ACTION_LABEL_ENTRY         , doc, list_node, "string", ACTION_LABEL_DESC_SHORT       , ACTION_LABEL_DESC_LONG       , "", TRUE );
+	create_gconf_schema_entry( writer, ACTION_TOOLTIP_ENTRY       , doc, list_node, "string", ACTION_TOOLTIP_DESC_SHORT     , ACTION_TOOLTIP_DESC_LONG     , "", TRUE );
+	create_gconf_schema_entry( writer, ACTION_ICON_ENTRY          , doc, list_node, "string", ACTION_ICON_DESC_SHORT        , ACTION_ICON_DESC_LONG        , "", FALSE );
+	create_gconf_schema_entry( writer, ACTION_ENABLED_ENTRY       , doc, list_node, "bool"  , ACTION_ENABLED_DESC_SHORT     , ACTION_ENABLED_DESC_LONG     , "true", FALSE );
 	create_gconf_schema_entry( writer, ACTION_PROFILE_LABEL_ENTRY , doc, list_node, "string", ACTION_PROFILE_NAME_DESC_SHORT, ACTION_PROFILE_NAME_DESC_LONG, NA_ACTION_PROFILE_DEFAULT_LABEL, TRUE );
-	create_gconf_schema_entry( writer, ACTION_PATH_ENTRY          , doc, list_node, "string", ACTION_PATH_DESC_SHORT        , ACTION_PATH_DESC_LONG, "", FALSE );
-	create_gconf_schema_entry( writer, ACTION_PARAMETERS_ENTRY    , doc, list_node, "string", ACTION_PARAMETERS_DESC_SHORT  , ACTION_PARAMETERS_DESC_LONG, "", FALSE );
-	create_gconf_schema_entry( writer, ACTION_BASENAMES_ENTRY     , doc, list_node, "list"  , ACTION_BASENAMES_DESC_SHORT   , ACTION_BASENAMES_DESC_LONG, "[*]", FALSE );
-	create_gconf_schema_entry( writer, ACTION_MATCHCASE_ENTRY     , doc, list_node, "bool"  , ACTION_MATCHCASE_DESC_SHORT   , ACTION_MATCHCASE_DESC_LONG, "true", FALSE );
-	create_gconf_schema_entry( writer, ACTION_MIMETYPES_ENTRY     , doc, list_node, "list"  , ACTION_MIMETYPES_DESC_SHORT   , ACTION_MIMETYPES_DESC_LONG, "[*/*]", FALSE );
-	create_gconf_schema_entry( writer, ACTION_ISFILE_ENTRY        , doc, list_node, "bool"  , ACTION_ISFILE_DESC_SHORT      , ACTION_ISFILE_DESC_LONG, "true", FALSE );
-	create_gconf_schema_entry( writer, ACTION_ISDIR_ENTRY         , doc, list_node, "bool"  , ACTION_ISDIR_DESC_SHORT       , ACTION_ISDIR_DESC_LONG, "false", FALSE );
-	create_gconf_schema_entry( writer, ACTION_MULTIPLE_ENTRY      , doc, list_node, "bool"  , ACTION_MULTIPLE_DESC_SHORT    , ACTION_MULTIPLE_DESC_LONG, "false", FALSE );
-	create_gconf_schema_entry( writer, ACTION_SCHEMES_ENTRY       , doc, list_node, "list"  , ACTION_SCHEMES_DESC_SHORT     , ACTION_SCHEMES_DESC_LONG, "[file]", FALSE );
+	create_gconf_schema_entry( writer, ACTION_PATH_ENTRY          , doc, list_node, "string", ACTION_PATH_DESC_SHORT        , ACTION_PATH_DESC_LONG        , "", FALSE );
+	create_gconf_schema_entry( writer, ACTION_PARAMETERS_ENTRY    , doc, list_node, "string", ACTION_PARAMETERS_DESC_SHORT  , ACTION_PARAMETERS_DESC_LONG  , "", FALSE );
+	create_gconf_schema_entry( writer, ACTION_BASENAMES_ENTRY     , doc, list_node, "list"  , ACTION_BASENAMES_DESC_SHORT   , ACTION_BASENAMES_DESC_LONG   , "[*]", FALSE );
+	create_gconf_schema_entry( writer, ACTION_MATCHCASE_ENTRY     , doc, list_node, "bool"  , ACTION_MATCHCASE_DESC_SHORT   , ACTION_MATCHCASE_DESC_LONG   , "true", FALSE );
+	create_gconf_schema_entry( writer, ACTION_MIMETYPES_ENTRY     , doc, list_node, "list"  , ACTION_MIMETYPES_DESC_SHORT   , ACTION_MIMETYPES_DESC_LONG   , "[*/*]", FALSE );
+	create_gconf_schema_entry( writer, ACTION_ISFILE_ENTRY        , doc, list_node, "bool"  , ACTION_ISFILE_DESC_SHORT      , ACTION_ISFILE_DESC_LONG      , "true", FALSE );
+	create_gconf_schema_entry( writer, ACTION_ISDIR_ENTRY         , doc, list_node, "bool"  , ACTION_ISDIR_DESC_SHORT       , ACTION_ISDIR_DESC_LONG       , "false", FALSE );
+	create_gconf_schema_entry( writer, ACTION_MULTIPLE_ENTRY      , doc, list_node, "bool"  , ACTION_MULTIPLE_DESC_SHORT    , ACTION_MULTIPLE_DESC_LONG    , "false", FALSE );
+	create_gconf_schema_entry( writer, ACTION_SCHEMES_ENTRY       , doc, list_node, "list"  , ACTION_SCHEMES_DESC_SHORT     , ACTION_SCHEMES_DESC_LONG     , "[file]", FALSE );
 
 	return( doc );
 }
diff --git a/src/nact/nact-iaction-tab.c b/src/nact/nact-iaction-tab.c
index c4bebf4..653b234 100644
--- a/src/nact/nact-iaction-tab.c
+++ b/src/nact/nact-iaction-tab.c
@@ -75,6 +75,8 @@ static GtkTreeModel *create_stock_icon_model( void );
 static gint          sort_stock_ids( gconstpointer a, gconstpointer b );
 static gchar        *strip_underscore( const gchar *text );
 static void          display_icon( NactWindow *window, GtkWidget *image, gboolean display );
+static void          on_enabled_toggled( GtkToggleButton *button, gpointer user_data );
+static GtkButton    *get_enabled_button( NactWindow *window );
 
 static void          display_status( NactWindow *window, const gchar *status );
 static void          hide_status( NactWindow *window );
@@ -186,6 +188,9 @@ nact_iaction_tab_runtime_init( NactWindow *dialog )
 
 	GtkWidget *button = base_window_get_widget( BASE_WINDOW( dialog ), "ActionIconBrowseButton" );
 	nact_window_signal_connect( dialog, G_OBJECT( button ), "clicked", G_CALLBACK( on_icon_browse ));
+
+	GtkButton *enabled_button = get_enabled_button( dialog );
+	nact_window_signal_connect( dialog, G_OBJECT( enabled_button ), "toggled", G_CALLBACK( on_enabled_toggled ));
 }
 
 /**
@@ -246,6 +251,11 @@ nact_iaction_tab_set_action( NactWindow *dialog, const NAAction *action )
 
 	GtkWidget *button = base_window_get_widget( BASE_WINDOW( dialog ), "ActionIconBrowseButton" );
 	gtk_widget_set_sensitive( button, enabled );
+
+	GtkButton *enabled_button = get_enabled_button( dialog );
+	gboolean enabled_action = action ? na_action_is_enabled( action ) : FALSE;
+	gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( enabled_button ), enabled_action );
+	gtk_widget_set_sensitive( GTK_WIDGET( enabled_button ), enabled );
 }
 
 /**
@@ -575,6 +585,26 @@ display_icon( NactWindow *window, GtkWidget *image, gboolean show )
 }
 
 static void
+on_enabled_toggled( GtkToggleButton *button, gpointer user_data )
+{
+	g_assert( NACT_IS_WINDOW( user_data ));
+	NactWindow *dialog = NACT_WINDOW( user_data );
+
+	NAAction *edited = v_get_edited_action( dialog );
+	if( edited ){
+		gboolean enabled = gtk_toggle_button_get_active( button );
+		na_action_set_enabled( edited, enabled );
+		v_field_modified( dialog );
+	}
+}
+
+static GtkButton *
+get_enabled_button( NactWindow *window )
+{
+	return( GTK_BUTTON( base_window_get_widget( BASE_WINDOW( window ), "ActionEnabledButton" )));
+}
+
+static void
 display_status( NactWindow *window, const gchar *status )
 {
 	GtkWidget *bar = v_get_status_bar( window );
diff --git a/src/nact/nact-xml-reader.c b/src/nact/nact-xml-reader.c
index 9898d32..86cc9d7 100644
--- a/src/nact/nact-xml-reader.c
+++ b/src/nact/nact-xml-reader.c
@@ -88,6 +88,7 @@ static GConfReaderStruct reader_str[] = {
 	{ ACTION_LABEL_ENTRY        , FALSE,  TRUE, FALSE, FALSE },
 	{ ACTION_TOOLTIP_ENTRY      , FALSE,  TRUE, FALSE, FALSE },
 	{ ACTION_ICON_ENTRY         , FALSE, FALSE, FALSE, FALSE },
+	{ ACTION_ENABLED_ENTRY      , FALSE, FALSE, FALSE, FALSE },
 	{ ACTION_PROFILE_LABEL_ENTRY, FALSE,  TRUE,  TRUE, FALSE },
 	{ ACTION_PATH_ENTRY         , FALSE, FALSE,  TRUE, FALSE },
 	{ ACTION_PARAMETERS_ENTRY   , FALSE, FALSE,  TRUE, FALSE },
@@ -1069,6 +1070,9 @@ apply_values( NactXMLReader *reader )
 		} else if( !strcmp( reader->private->entry, ACTION_ICON_ENTRY )){
 			na_action_set_icon( reader->private->action, reader->private->value );
 
+		} else if( !strcmp( reader->private->entry, ACTION_ENABLED_ENTRY )){
+			na_action_set_enabled( reader->private->action, na_utils_schema_to_boolean( reader->private->value, TRUE ));
+
 		} else if( !strcmp( reader->private->entry, ACTION_PROFILE_LABEL_ENTRY )){
 			na_action_profile_set_label( reader->private->profile, reader->private->value );
 
diff --git a/src/nact/nautilus-actions-config-tool.ui b/src/nact/nautilus-actions-config-tool.ui
index ce801cc..5cf7637 100644
--- a/src/nact/nautilus-actions-config-tool.ui
+++ b/src/nact/nautilus-actions-config-tool.ui
@@ -86,6 +86,7 @@
                       <object class="GtkVBox" id="vbox3">
                         <property name="visible">True</property>
                         <property name="border_width">6</property>
+                        <property name="spacing">10</property>
                         <child>
                           <object class="GtkVBox" id="vbox4">
                             <property name="visible">True</property>
@@ -115,6 +116,7 @@
                                     <property name="xalign">1</property>
                                   </object>
                                   <packing>
+                                    <property name="x_options">GTK_FILL</property>
                                     <property name="y_options"></property>
                                   </packing>
                                 </child>
@@ -127,6 +129,7 @@
                                   <packing>
                                     <property name="top_attach">1</property>
                                     <property name="bottom_attach">2</property>
+                                    <property name="x_options">GTK_FILL</property>
                                     <property name="y_options"></property>
                                   </packing>
                                 </child>
@@ -139,6 +142,7 @@
                                   <packing>
                                     <property name="top_attach">2</property>
                                     <property name="bottom_attach">3</property>
+                                    <property name="x_options">GTK_FILL</property>
                                     <property name="y_options"></property>
                                   </packing>
                                 </child>
@@ -244,6 +248,90 @@
                             <property name="position">0</property>
                           </packing>
                         </child>
+                        <child>
+                          <object class="GtkVBox" id="vbox15">
+                            <property name="visible">True</property>
+                            <property name="orientation">vertical</property>
+                            <property name="spacing">10</property>
+                            <child>
+                              <object class="GtkLabel" id="label3">
+                                <property name="visible">True</property>
+                                <property name="xalign">0</property>
+                                <property name="label" translatable="yes">&lt;b&gt;Action properties&lt;/b&gt;</property>
+                                <property name="use_markup">True</property>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkTable" id="table4">
+                                <property name="visible">True</property>
+                                <property name="n_rows">2</property>
+                                <property name="n_columns">2</property>
+                                <child>
+                                  <object class="GtkCheckButton" id="ActionEnabledButton">
+                                    <property name="label" translatable="yes">Enabled</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">False</property>
+                                    <property name="tooltip_text" translatable="yes">When the action is disabled, it will never appear in the Nautilus context menu.</property>
+                                    <property name="draw_indicator">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="left_attach">1</property>
+                                    <property name="right_attach">2</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkCheckButton" id="ActionReadonlyButton">
+                                    <property name="label" translatable="yes">Read-only</property>
+                                    <property name="visible">True</property>
+                                    <property name="sensitive">False</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">False</property>
+                                    <property name="tooltip_text" translatable="yes">If only readable, the action cannot be edited.</property>
+                                    <property name="draw_indicator">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="left_attach">1</property>
+                                    <property name="right_attach">2</property>
+                                    <property name="top_attach">1</property>
+                                    <property name="bottom_attach">2</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkLabel" id="label4">
+                                    <property name="width_request">20</property>
+                                    <property name="visible">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="x_options"></property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkLabel" id="label8">
+                                    <property name="width_request">20</property>
+                                    <property name="visible">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="top_attach">1</property>
+                                    <property name="bottom_attach">2</property>
+                                    <property name="x_options"></property>
+                                  </packing>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
                       </object>
                     </child>
                     <child type="tab">
@@ -1178,7 +1266,7 @@ The exported file may later be imported via :
                   <object class="GtkLabel" id="ExportGConfDumpLabel">
                     <property name="visible">True</property>
                     <property name="xalign">0</property>
-                    <property name="label" translatable="yes">This is the preferred format for newly exported actions.
+                    <property name="label" translatable="yes">This should be the preferred format for newly exported actions.
 The exported file may later be imported via :
 - Import assistant of the Nautilus Actions Configuration Tool,
 - or via the gconftool-2 --load command-line tool.</property>
@@ -1611,16 +1699,16 @@ The exported file may later be imported via :
   </object>
   <object class="GtkSizeGroup" id="CommandLabelSizeGroup">
     <widgets>
-      <widget name="ProfileLabelLabel"/>
-      <widget name="CommandPathLabel"/>
-      <widget name="CommandParametersLabel"/>
       <widget name="CommandExamplePreLabel"/>
+      <widget name="CommandParametersLabel"/>
+      <widget name="CommandPathLabel"/>
+      <widget name="ProfileLabelLabel"/>
     </widgets>
   </object>
   <object class="GtkSizeGroup" id="CommandButtonSizeGroup">
     <widgets>
-      <widget name="CommandPathButton"/>
       <widget name="CommandLegendButton"/>
+      <widget name="CommandPathButton"/>
     </widgets>
   </object>
 </interface>
diff --git a/src/plugin/nautilus-actions.c b/src/plugin/nautilus-actions.c
index 6555123..705734a 100644
--- a/src/plugin/nautilus-actions.c
+++ b/src/plugin/nautilus-actions.c
@@ -270,6 +270,10 @@ get_file_items( NautilusMenuProvider *provider, GtkWidget *window, GList *files
 
 			NAAction *action = NA_ACTION( ia->data );
 
+			if( !na_action_is_enabled( action )){
+				continue;
+			}
+
 			label = na_action_get_label( action );
 
 			if( !label || !g_utf8_strlen( label, -1 )){
diff --git a/src/utils/nautilus-actions-new.c b/src/utils/nautilus-actions-new.c
index 921adc3..630ed9c 100644
--- a/src/utils/nautilus-actions-new.c
+++ b/src/utils/nautilus-actions-new.c
@@ -46,6 +46,7 @@
 static gchar     *label           = "";
 static gchar     *tooltip         = "";
 static gchar     *icon            = "";
+static gboolean   enabled         = TRUE;
 static gchar     *command         = "";
 static gchar     *parameters      = "";
 static gchar    **basenames_array = NULL;
@@ -63,6 +64,7 @@ static GOptionEntry entries[] = {
 	{ "label"                , 'l', 0, G_OPTION_ARG_STRING      , &label          ,	N_("The label of the menu item (mandatory)"), N_("LABEL") },
 	{ "tooltip"              , 't', 0, G_OPTION_ARG_STRING      , &tooltip        , N_("The tooltip of the menu item"), N_("TOOLTIP") },
 	{ "icon"                 , 'i', 0, G_OPTION_ARG_STRING      , &icon           , N_("The icon of the menu item (filename or GTK stock ID)"), N_("ICON") },
+	{ "enabled"              , 'e', 0, G_OPTION_ARG_NONE        , &enabled        , N_("Whether the action is enabled"), NULL },
 	{ "command"              , 'c', 0, G_OPTION_ARG_FILENAME    , &command        , N_("The path of the command"), N_("PATH") },
 	{ "parameters"           , 'p', 0, G_OPTION_ARG_STRING      , &parameters     , N_("The parameters of the command"), N_("PARAMS") },
 	{ "match"                , 'm', 0, G_OPTION_ARG_STRING_ARRAY, &basenames_array, N_("A pattern to match selected files against. May include wildcards (* or ?) (you must set one option for each pattern you need)"), N_("EXPR") },
@@ -203,6 +205,7 @@ get_action_from_cmdline( void )
 	na_action_set_label( action, label );
 	na_action_set_tooltip( action, tooltip );
 	na_action_set_icon( action, icon );
+	na_action_set_enabled( action, enabled );
 
 	na_action_profile_set_path( profile, command );
 	na_action_profile_set_parameters( profile, parameters );



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