[nautilus-actions] Use new ArgFromDataDef structure to display a suitable help
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Use new ArgFromDataDef structure to display a suitable help
- Date: Tue, 16 Mar 2010 21:37:46 +0000 (UTC)
commit 9ac0dd4f1e567ae2b9410d382e043c1dad3ca3fa
Author: Pierre Wieser <pwieser trychlos org>
Date: Mon Mar 15 06:46:03 2010 +0100
Use new ArgFromDataDef structure to display a suitable help
ChangeLog | 13 ++++
src/api/na-data-def.h | 2 +
src/core/Makefile.am | 1 +
src/core/na-data-def.c | 68 +++++++++++++++++++++
src/core/na-icontextual-factory.c | 8 +-
src/core/na-object-profile-factory.c | 2 +-
src/utils/nautilus-actions-new.c | 110 ++++++++++++++++++++++++++++------
7 files changed, 180 insertions(+), 24 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 385d29a..a3cb166 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
2009-03-15 Pierre Wieser <pwieser trychlos org>
+ * src/api/na-data-def.h (na_data_def_get_data_def): New function.
+
+ * src/core/na-data-def.c: New file.
+
+ * src/core/Makefile.am: Updated accordingly.
+
+ * src/core/na-icontextual-factory.c:
+ * src/core/na-object-profile-factory.c:
+ Update command-line options to not have duplicates.
+
+ * src/utils/nautilus-actions-new.c:
+ Use new ArgFromDataDef structure and display suitable help.
+
* src/core/na-icontextual-factory.c:
* src/core/na-object-action-factory.c:
* src/core/na-object-item-factory.c:
diff --git a/src/api/na-data-def.h b/src/api/na-data-def.h
index 23d21da..1367cc1 100644
--- a/src/api/na-data-def.h
+++ b/src/api/na-data-def.h
@@ -124,6 +124,8 @@ typedef struct {
}
NADataGroup;
+const NADataDef *na_data_def_get_data_def( const NADataGroup *group, const gchar *group_name, const gchar *name );
+
G_END_DECLS
#endif /* __NAUTILUS_ACTIONS_API_NA_FACTORY_DATA_DEF_H__ */
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index 50bbf2d..6a87ff9 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -41,6 +41,7 @@ AM_CPPFLAGS += \
libna_core_la_SOURCES = \
na-core-utils.c \
na-data-boxed.c \
+ na-data-def.c \
na-data-types.c \
na-exporter.c \
na-exporter.h \
diff --git a/src/core/na-data-def.c b/src/core/na-data-def.c
new file mode 100644
index 0000000..76f3d8d
--- /dev/null
+++ b/src/core/na-data-def.c
@@ -0,0 +1,68 @@
+/*
+ * Nautilus Actions
+ * A Nautilus extension which offers configurable context menu actions.
+ *
+ * Copyright (C) 2005 The GNOME Foundation
+ * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
+ * Copyright (C) 2009, 2010 Pierre Wieser and others (see AUTHORS)
+ *
+ * This Program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this Library; see the file COPYING. If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place,
+ * Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Authors:
+ * Frederic Ruaudel <grumz grumz net>
+ * Rodrigo Moya <rodrigo gnome-db org>
+ * Pierre Wieser <pwieser trychlos org>
+ * ... and many others (see AUTHORS)
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+
+#include <api/na-data-def.h>
+
+/**
+ * na_data_def_get_data_def:
+ * @group: a #NADataGroup structure array.
+ * @group_name: the searched group name.
+ * @name: the searched data name.
+ *
+ * Returns: a pointer to the #NADataDef structure, or %NULL if not found.
+ */
+const NADataDef *
+na_data_def_get_data_def( const NADataGroup *group, const gchar *group_name, const gchar *name )
+{
+ NADataGroup *igroup;
+ NADataDef *idef;
+
+ igroup = ( NADataGroup * ) group;
+ while( igroup->group ){
+ if( !strcmp( igroup->group, group_name )){
+ idef = igroup->def;
+ while( idef->name ){
+ if( !strcmp( idef->name, name )){
+ return( idef );
+ }
+ idef++;
+ }
+ }
+ igroup++;
+ }
+
+ return( NULL );
+}
diff --git a/src/core/na-icontextual-factory.c b/src/core/na-icontextual-factory.c
index c67a8be..3af98ab 100644
--- a/src/core/na-icontextual-factory.c
+++ b/src/core/na-icontextual-factory.c
@@ -85,8 +85,8 @@ NADataDef data_def_conditions [] = {
FALSE,
FALSE,
"matchcase",
- 'c',
- "case",
+ 'a',
+ "match-case",
0,
G_OPTION_ARG_NONE,
NULL,
@@ -249,11 +249,11 @@ NADataDef data_def_conditions [] = {
FALSE,
FALSE,
"folders",
- 'd',
+ 'r',
"folder",
0,
G_OPTION_ARG_STRING,
- N_( "The path of a directory for which folders or toolbar action will be displayed. " \
+ N_( "The path of a directory for which the item will be displayed. " \
"You must set one option for each folder you need" ),
N_( "<PATH>" ) },
diff --git a/src/core/na-object-profile-factory.c b/src/core/na-object-profile-factory.c
index 2932118..c426a10 100644
--- a/src/core/na-object-profile-factory.c
+++ b/src/core/na-object-profile-factory.c
@@ -78,7 +78,7 @@ static NADataDef data_def_profile [] = {
TRUE,
FALSE,
"path",
- 'c',
+ 'x',
"command",
0,
G_OPTION_ARG_FILENAME,
diff --git a/src/utils/nautilus-actions-new.c b/src/utils/nautilus-actions-new.c
index 8e62f5e..dd58ff2 100644
--- a/src/utils/nautilus-actions-new.c
+++ b/src/utils/nautilus-actions-new.c
@@ -48,8 +48,10 @@
#include "console-utils.h"
typedef struct {
- gchar *name;
- void *arg_data;
+ NADataGroup *group;
+ gchar *group_name;
+ gchar *data_name;
+ void *arg_data;
}
ArgFromDataDef;
@@ -59,12 +61,15 @@ static gchar *icon = "";
static gboolean enabled = FALSE;
static gboolean disabled = FALSE;
static gboolean target_selection = FALSE;
+static gboolean nocontext = FALSE;
static gboolean target_toolbar = FALSE;
+static gboolean notoolbar = FALSE;
static gchar *label_toolbar = "";
static gchar *command = "";
static gchar *parameters = "";
static gchar **basenames_array = NULL;
static gboolean matchcase = FALSE;
+static gboolean nocase = FALSE;
static gchar **mimetypes_array = NULL;
static gboolean isfile = FALSE;
static gboolean isdir = FALSE;
@@ -75,27 +80,44 @@ static gchar *output_dir = NULL;
static gboolean output_gconf = FALSE;
static gboolean version = FALSE;
+extern NADataGroup action_data_groups[]; /* defined in na-object-action-factory.c */
+extern NADataGroup profile_data_groups[]; /* defined in na-object-profile-factory.c */
+
static const ArgFromDataDef st_arg_from_data_def[] = {
- { NAFO_DATA_LABEL, &label },
- { NAFO_DATA_TOOLTIP, &tooltip },
- { NAFO_DATA_ICON, &icon },
- { NAFO_DATA_ENABLED, &enabled },
- { NAFO_DATA_TARGET_SELECTION, &target_selection },
- { NAFO_DATA_TARGET_TOOLBAR, &target_toolbar },
- { NAFO_DATA_TOOLBAR_LABEL, &label_toolbar },
- { NAFO_DATA_PATH, &command },
- { NAFO_DATA_PARAMETERS, ¶meters },
- { NAFO_DATA_BASENAMES, &basenames_array },
- { NAFO_DATA_MATCHCASE, &matchcase },
- { NAFO_DATA_MIMETYPES, &mimetypes_array },
- { NAFO_DATA_ISFILE, &isfile },
- { NAFO_DATA_ISDIR, &isdir },
- { NAFO_DATA_MULTIPLE, &accept_multiple },
- { NAFO_DATA_SCHEMES, &schemes_array },
- { NAFO_DATA_FOLDERS, &folders_array },
+ { action_data_groups, NA_FACTORY_OBJECT_ITEM_GROUP, NAFO_DATA_LABEL, &label },
+ { action_data_groups, NA_FACTORY_OBJECT_ITEM_GROUP, NAFO_DATA_TOOLTIP, &tooltip },
+ { action_data_groups, NA_FACTORY_OBJECT_ITEM_GROUP, NAFO_DATA_ICON, &icon },
+ { action_data_groups, NA_FACTORY_OBJECT_ITEM_GROUP, NAFO_DATA_ENABLED, &enabled },
+ { action_data_groups, NA_FACTORY_OBJECT_ACTION_GROUP, NAFO_DATA_TARGET_SELECTION, &target_selection },
+ { action_data_groups, NA_FACTORY_OBJECT_ACTION_GROUP, NAFO_DATA_TARGET_TOOLBAR, &target_toolbar },
+ { action_data_groups, NA_FACTORY_OBJECT_ACTION_GROUP, NAFO_DATA_TOOLBAR_LABEL, &label_toolbar },
+ { profile_data_groups, NA_FACTORY_OBJECT_PROFILE_GROUP, NAFO_DATA_PATH, &command },
+ { profile_data_groups, NA_FACTORY_OBJECT_PROFILE_GROUP, NAFO_DATA_PARAMETERS, ¶meters },
+ { profile_data_groups, NA_FACTORY_OBJECT_CONDITIONS_GROUP, NAFO_DATA_BASENAMES, &basenames_array },
+ { profile_data_groups, NA_FACTORY_OBJECT_CONDITIONS_GROUP, NAFO_DATA_MATCHCASE, &matchcase },
+ { profile_data_groups, NA_FACTORY_OBJECT_CONDITIONS_GROUP, NAFO_DATA_MIMETYPES, &mimetypes_array },
+ { profile_data_groups, NA_FACTORY_OBJECT_CONDITIONS_GROUP, NAFO_DATA_ISFILE, &isfile },
+ { profile_data_groups, NA_FACTORY_OBJECT_CONDITIONS_GROUP, NAFO_DATA_ISDIR, &isdir },
+ { profile_data_groups, NA_FACTORY_OBJECT_CONDITIONS_GROUP, NAFO_DATA_MULTIPLE, &accept_multiple },
+ { profile_data_groups, NA_FACTORY_OBJECT_CONDITIONS_GROUP, NAFO_DATA_SCHEMES, &schemes_array },
+ { profile_data_groups, NA_FACTORY_OBJECT_CONDITIONS_GROUP, NAFO_DATA_FOLDERS, &folders_array },
{ NULL }
};
+static GOptionEntry st_added_entries[] = {
+
+ { "disabled" , 'E', 0, G_OPTION_ARG_NONE , &disabled,
+ N_( "Set it if the item should be disabled at creation" ), NULL },
+ { "nocontext" , 'C', 0, G_OPTION_ARG_NONE , &nocontext,
+ N_( "Set it if the item doesn't target the context menu" ), NULL },
+ { "notoolbar" , 'O', 0, G_OPTION_ARG_NONE , ¬oolbar,
+ N_( "Set it if the item doesn't target the toolbar" ), NULL },
+ { "nocase" , 'A', 0, G_OPTION_ARG_NONE , &nocase,
+ N_( "Set it if the basename patterns are case insensitive" ), NULL },
+ { NULL }
+};
+
+#if 0
static GOptionEntry entries[] = {
{ "label" , 'l', 0, G_OPTION_ARG_STRING , &label,
@@ -136,6 +158,7 @@ static GOptionEntry entries[] = {
N_( "The URI of a directory for which folders or toolbar action will be displayed. You must set one option for each folder you need" ), N_( "<URI>" ) },
{ NULL }
};
+#endif
static GOptionEntry output_entries[] = {
@@ -153,6 +176,7 @@ static GOptionEntry misc_entries[] = {
{ NULL }
};
+static GOptionEntry *build_option_entries( const ArgFromDataDef *defs, guint nbdefs, const GOptionEntry *adds, guint nbadds );
static GOptionContext *init_options( void );
static NAObjectAction *get_action_from_cmdline( void );
static gboolean write_to_gconf( NAObjectAction *action, GSList **msg );
@@ -250,6 +274,50 @@ main( int argc, char** argv )
exit( status );
}
+static GOptionEntry *
+build_option_entries( const ArgFromDataDef *defs, guint nbdefs, const GOptionEntry *adds, guint nbadds )
+{
+ static const gchar *thisfn = "nautilus_actions_new_build_option_entries";
+ GOptionEntry *entries;
+ GOptionEntry *ient;
+ const GOptionEntry *iadd;
+ const ArgFromDataDef *idef;
+ const NADataDef *data_def;
+
+ entries = g_new0( GOptionEntry, 1+nbdefs+nbadds );
+ ient = entries;
+
+ idef = defs;
+ while( idef->group ){
+ data_def = na_data_def_get_data_def( idef->group, idef->group_name, idef->data_name );
+
+ if( data_def ){
+ ient->long_name = data_def->option_long;
+ ient->short_name = data_def->option_short;
+ ient->flags = data_def->option_flags;
+ ient->arg = data_def->option_arg;
+ ient->arg_data = idef->arg_data;
+ ient->description = data_def->option_label ? data_def->option_label : data_def->short_label;
+ ient->arg_description = data_def->option_arg_label;
+
+ } else {
+ g_warning( "%s: group=%s, name=%s: unable to find NADataDef structure", thisfn, idef->group_name, idef->data_name );
+ }
+
+ idef++;
+ ient++;
+ }
+
+ iadd = adds;
+ while( iadd->long_name ){
+ memcpy( ient, iadd, sizeof( GOptionEntry ));
+ iadd++;
+ ient++;
+ }
+
+ return( entries );
+}
+
/*
* init options context
*/
@@ -260,12 +328,15 @@ init_options( void )
gchar* description;
GOptionGroup *output_group;
GOptionGroup *misc_group;
+ GOptionEntry *entries;
context = g_option_context_new( _( "Define a new action.\n\n"
" The created action defaults to be written to stdout.\n"
" It can also be written to an output folder, in a file later suitable for an import in NACT.\n"
" Or you may choose to directly write the action into your GConf configuration." ));
+ entries = build_option_entries( st_arg_from_data_def, G_N_ELEMENTS( st_arg_from_data_def ), st_added_entries, G_N_ELEMENTS( st_added_entries ) );
+
#ifdef ENABLE_NLS
bindtextdomain( GETTEXT_PACKAGE, GNOMELOCALEDIR );
# ifdef HAVE_BIND_TEXTDOMAIN_CODESET
@@ -283,6 +354,7 @@ init_options( void )
g_option_context_set_description( context, description );
+ /* g_free( entries ); */
g_free( description );
output_group = g_option_group_new(
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]