[nautilus-actions] Review default values
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Review default values
- Date: Sat, 27 Feb 2010 23:18:55 +0000 (UTC)
commit 2566e5dadf7e149fc3ada0efcc6c1778ff6e1821
Author: Pierre Wieser <pwieser trychlos org>
Date: Fri Feb 26 03:10:21 2010 +0100
Review default values
ChangeLog | 39 +++++
src/api/na-ifactory-object.h | 15 --
src/api/na-object-action.h | 1 +
src/api/na-object-menu.h | 1 +
src/api/na-object-profile.h | 1 +
src/core/na-factory-object.c | 268 +++++++---------------------------
src/core/na-factory-object.h | 38 ++---
src/core/na-ifactory-object.c | 1 -
src/core/na-object-action-factory.c | 8 +-
src/core/na-object-action.c | 44 ++++---
src/core/na-object-item-factory.c | 12 +-
src/core/na-object-menu.c | 43 +++---
src/core/na-object-profile-factory.c | 16 +-
src/core/na-object-profile.c | 41 +++---
src/nact/nact-iaction-tab.c | 15 ++
src/nact/nact-icommand-tab.c | 9 +
src/nact/nact-iconditions-tab.c | 6 +
src/nact/nact-main-menubar.c | 13 +-
src/utils/nautilus-actions-new.c | 2 +-
19 files changed, 233 insertions(+), 340 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 925cedc..33d85ea 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,45 @@
2009-02-25 Pierre Wieser <pwieser trychlos org>
* src/api/na-ifactory-object.h:
+ * src/core/na-ifactory-object.c:
+ Remove get_default() function from the interface.
+
+ * src/api/na-object-action.h:
+ * src/core/na-object-action.c (na_object_action_new_with_defaults):
+ New function.
+ Remove ifactory_object_get_default() implementation.
+
+ * src/api/na-object-menu.h:
+ * src/core/na-object-menu.c (na_object_menu_new_with_defaults):
+ New function.
+ Remove ifactory_object_get_default() implementation.
+
+ * src/api/na-object-profile.h:
+ * src/core/na-object-profile.c (na_object_profile_new_with_defaults):
+ New function.
+ Remove ifactory_object_get_default() implementation.
+
+ * src/core/na-factory-object.c:
+ * src/core/na-factory-object.h
+ (na_factory_object_set_defaults): New function.
+ (na_factory_object_attach_with_default): Removed function.
+ Cleanup the code.
+
+ * src/core/na-object-action-factory.c:
+ * src/core/na-object-item-factory.c:
+ * src/core/na-object-profile-factory.c:
+ Review default values.
+
+ * src/nact/nact-iaction-tab.c:
+ * src/nact/nact-icommand-tab.c:
+ * src/nact/nact-iconditions-tab.c:
+ Fix the display of NULL texts.
+
+ * src/nact/nact-main-menubar.c:
+ * src/utils/nautilus-actions-new.c:
+ Allocate new objects with defaults.
+
+ * src/api/na-ifactory-object.h:
* src/api/na-ifactory-provider.h:
* src/api/na-object-api.h:
* src/api/na-object-item.h:
diff --git a/src/api/na-ifactory-object.h b/src/api/na-ifactory-object.h
index 26e8d4e..bcbd250 100644
--- a/src/api/na-ifactory-object.h
+++ b/src/api/na-ifactory-object.h
@@ -85,21 +85,6 @@ typedef struct {
NADataGroup * ( *get_groups ) ( const NAIFactoryObject *instance );
/**
- * get_default:
- * @instance: this #NAIFactoryObject instance.
- * @iddef: the #NADataDef structure which defines the data whose
- * default value is searched for.
- *
- * The @instance may take advantage of this method to setup a default
- * value for a specific instance, or even for instances of a class when
- * several classes share some elementary data via common #NADataGroup.
- *
- * Returns: a newly allocated string which defines the suitable
- * default value, or %NULL.
- */
- gchar * ( *get_default )( const NAIFactoryObject *instance, const NADataDef *iddef );
-
- /**
* copy:
* @instance: the target #NAIFactoryObject instance.
* @source: the source #NAIFactoryObject instance.
diff --git a/src/api/na-object-action.h b/src/api/na-object-action.h
index d3db7ad..37923a1 100644
--- a/src/api/na-object-action.h
+++ b/src/api/na-object-action.h
@@ -77,6 +77,7 @@ GType na_object_action_get_type( void );
NAObjectAction *na_object_action_new( void );
NAObjectAction *na_object_action_new_with_profile( void );
+NAObjectAction *na_object_action_new_with_defaults( void );
gchar *na_object_action_get_new_profile_name( const NAObjectAction *action );
void na_object_action_attach_profile( NAObjectAction *action, NAObjectProfile *profile );
diff --git a/src/api/na-object-menu.h b/src/api/na-object-menu.h
index deb4366..4d0240c 100644
--- a/src/api/na-object-menu.h
+++ b/src/api/na-object-menu.h
@@ -67,6 +67,7 @@ typedef struct {
GType na_object_menu_get_type( void );
NAObjectMenu *na_object_menu_new( void );
+NAObjectMenu *na_object_menu_new_with_defaults( void );
G_END_DECLS
diff --git a/src/api/na-object-profile.h b/src/api/na-object-profile.h
index d425860..c874e11 100644
--- a/src/api/na-object-profile.h
+++ b/src/api/na-object-profile.h
@@ -70,6 +70,7 @@ typedef struct {
GType na_object_profile_get_type( void );
NAObjectProfile *na_object_profile_new( void );
+NAObjectProfile *na_object_profile_new_with_defaults( void );
void na_object_profile_set_scheme ( NAObjectProfile *profile, const gchar *scheme, gboolean selected );
void na_object_profile_replace_folder( NAObjectProfile *profile, const gchar *old, const gchar *new );
diff --git a/src/core/na-factory-object.c b/src/core/na-factory-object.c
index 86848bd..81d1082 100644
--- a/src/core/na-factory-object.c
+++ b/src/core/na-factory-object.c
@@ -43,9 +43,6 @@
#include <api/na-data-boxed.h>
#include "na-factory-object.h"
-#if 0
-#include "na-ifactory-object-priv.h"
-#endif
#include "na-factory-provider.h"
typedef gboolean ( *NADataDefIterFunc )( NADataDef *def, void *user_data );
@@ -78,28 +75,23 @@ typedef struct {
}
NafoValidIter;
-#if 0
/* while iterating on set defaults
*/
typedef struct {
NAIFactoryObject *object;
- gboolean creation;
}
- NadfNewIter;
-#endif
+ NafoDefaultIter;
#define NA_IFACTORY_OBJECT_PROP_DATA "na-ifactory-object-prop-data"
extern gboolean ifactory_object_initialized;
extern gboolean ifactory_object_finalized;
-#if 0
-extern NAIFactoryObjectInterface *ifactory_object_klass;
-#endif
static gboolean define_class_properties_iter( const NADataDef *def, GObjectClass *class );
-static gboolean factory_object_is_valid_mandatory_iter( const NADataDef *def, NafoValidIter *data );
-static gboolean factory_object_read_data_iter( NADataDef *def, NafoReadIter *iter );
-static gboolean factory_object_write_data_iter( const NAIFactoryObject *object, NADataBoxed *boxed, NafoWriteIter *iter );
+static gboolean set_defaults_iter( NADataDef *def, NafoDefaultIter *data );
+static gboolean is_valid_mandatory_iter( const NADataDef *def, NafoValidIter *data );
+static gboolean read_data_iter( NADataDef *def, NafoReadIter *iter );
+static gboolean write_data_iter( const NAIFactoryObject *object, NADataBoxed *boxed, NafoWriteIter *iter );
static NADataGroup *v_get_groups( const NAIFactoryObject *object );
static void v_copy( NAIFactoryObject *target, const NAIFactoryObject *source );
@@ -115,53 +107,6 @@ static NADataBoxed *data_boxed_from_name( const NAIFactoryObject *object, const
static void free_data_boxed_list( NAIFactoryObject *object );
static void iter_on_data_defs( const NADataGroup *idgroups, gboolean serializable_only, NADataDefIterFunc pfn, void *user_data );
-#if 0
-static gboolean factory_object_init_instance_iter( const NADataDef *def, NAIFactoryObject *object );
-static gchar *v_get_default( const NAIFactoryObject *object, const NADataDef *def );
-#endif
-
-#if 0
-/**
- * na_factory_object_register_type:
- * @type: the #GType of the implementation class.
- * @groups: a table of #NADataGroup structures which defines the
- * serializable properties which will be attached to each instance of
- * this class.
- *
- * Registers the implementation #GType @type.
- */
-void
-na_factory_object_register_type( GType type, const NADataGroup *groups )
-{
- static const gchar *thisfn = "na_factory_object_register_type";
- NADataImplement *known;
- NADataGroup *registered;
-
- if( ifactory_object_initialized && !ifactory_object_finalized ){
-
- g_debug( "%s: type=%lu, groups=%p",
- thisfn, ( unsigned long ) type, ( void * ) groups );
-
- g_return_if_fail( groups != NULL );
-
- registered = na_factory_object_get_data_groups_from_type( type );
- if( registered ){
- g_warning( "%s: type=%lu: already registered", thisfn, ( unsigned long ) type );
-
- } else {
- /* register the implementation
- */
- known = g_new0( NADataImplement, 1 );
- known->type = type;
- known->groups = ( NADataGroup * ) groups;
-
- ifactory_object_klass->private->registered =
- g_list_prepend( ifactory_object_klass->private->registered, known );
- }
- }
-}
-#endif
-
/**
* na_factory_object_define_properties:
* @class: the #GObjectClass.
@@ -183,7 +128,7 @@ na_factory_object_define_properties( GObjectClass *class, const NADataGroup *gro
/* define class properties
*/
- iter_on_data_defs( groups, FALSE, ( NADataDefIterFunc ) &define_class_properties_iter, class );
+ iter_on_data_defs( groups, FALSE, ( NADataDefIterFunc ) define_class_properties_iter, class );
}
}
@@ -304,33 +249,62 @@ na_factory_object_iter_on_boxed( const NAIFactoryObject *object, NAFactoryObject
}
/**
- * na_factory_object_attach_with_default:
+ * na_factory_object_set_defaults:
* @object: this #NAIFactoryObject object.
- * @name: a #NADataDef name.
*
- * Attach a new #NADataBoxed element to this @object, initializing it
- * with its default value.
+ * Implement default values in this new @object.
*/
void
-na_factory_object_attach_with_default( NAIFactoryObject *object, const gchar *name )
+na_factory_object_set_defaults( NAIFactoryObject *object )
{
- static const gchar *thisfn = "na_factory_object_attach_with_default";
+ static const gchar *thisfn = "na_factory_object_set_defaults";
+ NADataGroup *groups;
+ NafoDefaultIter *iter_data;
g_return_if_fail( NA_IS_IFACTORY_OBJECT( object ));
if( ifactory_object_initialized && !ifactory_object_finalized ){
- NADataDef *def = na_factory_object_get_data_def( object, name );
-
- if( !def ){
- g_warning( "%s: no NADataDef found for %s", thisfn, name );
+ groups = v_get_groups( object );
+ if( !groups ){
+ g_warning( "%s: no NADataGroup found for %s", thisfn, G_OBJECT_TYPE_NAME( object ));
} else {
- NADataBoxed *boxed = na_data_boxed_new( def );
- na_data_boxed_set_default( boxed );
- attach_boxed_to_object( object, boxed );
+ iter_data = g_new0( NafoDefaultIter, 1 );
+ iter_data->object = object;
+
+ iter_on_data_defs( groups, FALSE, ( NADataDefIterFunc ) set_defaults_iter, iter_data );
+
+ g_free( iter_data );
+ }
+ }
+}
+
+static gboolean
+set_defaults_iter( NADataDef *def, NafoDefaultIter *data )
+{
+ NADataBoxed *boxed;
+ gboolean is_null;
+
+ if( !def->obsoleted ){
+ if( def->default_value ){
+ is_null = TRUE;
+ boxed = data_boxed_from_name( data->object, def->name );
+ if( boxed ){
+ is_null = ( na_data_boxed_get_as_void( boxed ) == NULL );
+ }
+ if( is_null ){
+ if( !boxed ){
+ boxed = na_data_boxed_new( def );
+ attach_boxed_to_object( data->object, boxed );
+ }
+ na_data_boxed_set_from_string( boxed, def->default_value );
+ }
}
}
+
+ /* do not stop */
+ return( FALSE );
}
/**
@@ -467,7 +441,7 @@ na_factory_object_is_valid( const NAIFactoryObject *object )
groups = v_get_groups( object );
if( groups ){
- iter_on_data_defs( groups, FALSE, ( NADataDefIterFunc ) factory_object_is_valid_mandatory_iter, &iter_data );
+ iter_on_data_defs( groups, FALSE, ( NADataDefIterFunc ) is_valid_mandatory_iter, &iter_data );
}
is_valid = iter_data.is_valid;
@@ -483,7 +457,7 @@ na_factory_object_is_valid( const NAIFactoryObject *object )
}
static gboolean
-factory_object_is_valid_mandatory_iter( const NADataDef *def, NafoValidIter *data )
+is_valid_mandatory_iter( const NADataDef *def, NafoValidIter *data )
{
NADataBoxed *boxed;
@@ -537,69 +511,6 @@ na_factory_object_dump( const NAIFactoryObject *object )
}
}
-#if 0
-/**
- * na_factory_object_init_instance:
- * @object: the #NAIFactoryObject being initialized.
- *
- * Initializes properties attached to the @object.
- *
- * This essentially consists of creating a #NADataBoxed for each
- * defined elementary data, initializing it to its default value.
- */
-void
-na_factory_object_init_instance( NAIFactoryObject *object )
-{
- static const gchar *thisfn = "na_factory_object_init_instance";
- NADataGroup *groups;
-
- g_debug( "%s: object=%p (%s)", thisfn, ( void * ) object, G_OBJECT_TYPE_NAME( object ));
- g_return_if_fail( NA_IS_IFACTORY_OBJECT( object ));
-
- /* do not allocate any NADataBoxed now
- * just ensure that the GList which will host them is initialized
- */
- g_object_set_data( G_OBJECT( object ), NA_IFACTORY_OBJECT_PROP_DATA, NULL );
-
- if( FALSE ){
- groups = na_factory_object_get_data_groups_from_type( G_OBJECT_TYPE( object ));
- if( groups ){
- iter_on_data_defs( groups, FALSE, ( NADataDefIterFunc ) &factory_object_init_instance_iter, object );
-
- } else {
- g_warning( "%s: class=%s: groups not found", thisfn, G_OBJECT_TYPE_NAME( object ));
- }
- }
-}
-
-static gboolean
-factory_object_init_instance_iter( const NADataDef *def, NAIFactoryObject *object )
-{
- gboolean stop;
- GList *list;
- NADataBoxed *element;
- NadfDataValue *data;
- gchar *default_value;
-
- stop = FALSE;
-
- default_value = v_get_default( object, def );
- element = na_data_boxed_new( def );
- na_data_boxed_set_from_string( element, ( const void * )( default_value ? default_value : def->default_value ));
- g_free( default_value );
-
- data = g_new0( NadfDataValue, 1 );
- data->def = ( NADataDef * ) def;
- data->element = element;
-
- list = g_object_get_data( G_OBJECT( object ), NA_IFACTORY_OBJECT_PROP_DATA );
- list = g_list_prepend( list, data );
- g_object_set_data( G_OBJECT( object ), NA_IFACTORY_OBJECT_PROP_DATA, list );
-
- return( stop );
-}
-#endif
-
/**
* na_factory_object_finalize_instance:
* @object: the #NAIFactoryObject being finalized.
@@ -643,7 +554,7 @@ na_factory_object_read_item( NAIFactoryObject *serializable, const NAIFactoryPro
iter->reader_data = reader_data;
iter->messages = messages;
- iter_on_data_defs( groups, TRUE, ( NADataDefIterFunc ) &factory_object_read_data_iter, iter );
+ iter_on_data_defs( groups, TRUE, ( NADataDefIterFunc ) read_data_iter, iter );
g_free( iter );
@@ -657,7 +568,7 @@ na_factory_object_read_item( NAIFactoryObject *serializable, const NAIFactoryPro
}
static gboolean
-factory_object_read_data_iter( NADataDef *def, NafoReadIter *iter )
+read_data_iter( NADataDef *def, NafoReadIter *iter )
{
gboolean stop;
@@ -725,7 +636,7 @@ na_factory_object_write_item( NAIFactoryObject *serializable, const NAIFactoryPr
iter->messages = messages;
iter->code = code;
- na_factory_object_iter_on_boxed( serializable, ( NAFactoryObjectIterBoxedFn ) &factory_object_write_data_iter, iter );
+ na_factory_object_iter_on_boxed( serializable, ( NAFactoryObjectIterBoxedFn ) write_data_iter, iter );
code = iter->code;
g_free( iter );
@@ -739,7 +650,7 @@ na_factory_object_write_item( NAIFactoryObject *serializable, const NAIFactoryPr
}
static gboolean
-factory_object_write_data_iter( const NAIFactoryObject *object, NADataBoxed *boxed, NafoWriteIter *iter )
+write_data_iter( const NAIFactoryObject *object, NADataBoxed *boxed, NafoWriteIter *iter )
{
NADataDef *def = na_data_boxed_get_data_def( boxed );
@@ -751,32 +662,6 @@ factory_object_write_data_iter( const NAIFactoryObject *object, NADataBoxed *box
return( iter->code == NA_IIO_PROVIDER_CODE_OK );
}
-#if 0
-/**
- * na_factory_provider_get_data_groups:
- * @type: a previously registered #GType.
- *
- * Returns the #NADataGroups table which has been registered for this @type,
- * or %NULL.
- */
-NADataGroup *
-na_factory_object_get_data_groups_from_type( GType type )
-{
- GList *it;
-
- if( ifactory_object_initialized && !ifactory_object_finalized ){
-
- for( it = ifactory_object_klass->private->registered ; it ; it = it->next ){
- if((( NADataImplement * ) it->data )->type == type ){
- return((( NADataImplement * ) it->data )->groups );
- }
- }
- }
-
- return( NULL );
-}
-#endif
-
/**
* na_factory_object_get_as_value:
* @object: this #NAIFactoryObject instance.
@@ -949,51 +834,6 @@ v_is_valid( const NAIFactoryObject *object )
return( is_valid );
}
-#if 0
-/**
- * na_factory_object_new:
- * @type: the GType type of the object we want allocate.
- *
- * Returns: a newly allocated #NAObject-derived object, or %NULL.
- *
- * The function checks that @type has been previously registered in the
- * data factory management system (cf. #na_factory_object_init_class()),
- * and if so invoke an empty constructor with this @type.
- */
-NAIFactoryObject *
-na_factory_object_new( GType type )
-{
- NAIFactoryObject *object;
- NADataGroup *groups;
-
- object = NULL;
-
- /* check that @type has been registered
- */
- groups = na_factory_object_get_data_groups_from_type( type );
- if( groups ){
-
- object = NA_IFACTORY_OBJECT( g_object_new( type, NULL ));
- }
-
- return( object );
-}
-
-static gchar *
-v_get_default( const NAIFactoryObject *object, const NADataDef *def )
-{
- gchar *default_value;
-
- default_value = NULL;
-
- if( NA_IFACTORY_OBJECT_GET_INTERFACE( object )->get_default ){
- default_value = NA_IFACTORY_OBJECT_GET_INTERFACE( object )->get_default( object, def );
- }
-
- return( default_value );
-}
-#endif
-
static void
v_read_start( NAIFactoryObject *serializable, const NAIFactoryProvider *reader, void *reader_data, GSList **messages )
{
diff --git a/src/core/na-factory-object.h b/src/core/na-factory-object.h
index 30101cf..a5ab315 100644
--- a/src/core/na-factory-object.h
+++ b/src/core/na-factory-object.h
@@ -46,36 +46,32 @@ G_BEGIN_DECLS
typedef gboolean ( *NAFactoryObjectIterBoxedFn )( const NAIFactoryObject *object, NADataBoxed *boxed, void *data );
-#if 0
-void na_factory_object_register_type ( GType type, const NADataGroup *groups );
-#endif
-void na_factory_object_define_properties ( GObjectClass *class, const NADataGroup *groups );
-NADataDef *na_factory_object_get_data_def ( const NAIFactoryObject *object, const gchar *name );
-NADataGroup *na_factory_object_get_data_groups ( const NAIFactoryObject *object );
-void na_factory_object_iter_on_boxed ( const NAIFactoryObject *object, NAFactoryObjectIterBoxedFn pfn, void *data );
+void na_factory_object_define_properties( GObjectClass *class, const NADataGroup *groups );
+NADataDef *na_factory_object_get_data_def ( const NAIFactoryObject *object, const gchar *name );
+NADataGroup *na_factory_object_get_data_groups ( const NAIFactoryObject *object );
+void na_factory_object_iter_on_boxed ( const NAIFactoryObject *object, NAFactoryObjectIterBoxedFn pfn, void *data );
-void na_factory_object_attach_with_default( NAIFactoryObject *object, const gchar *name );
+void na_factory_object_set_defaults ( NAIFactoryObject *object );
-void na_factory_object_move_boxed ( NAIFactoryObject *target, const NAIFactoryObject *source, NADataBoxed *boxed );
+void na_factory_object_move_boxed ( NAIFactoryObject *target, const NAIFactoryObject *source, NADataBoxed *boxed );
-void na_factory_object_copy ( NAIFactoryObject *target, const NAIFactoryObject *source );
-gboolean na_factory_object_are_equal ( const NAIFactoryObject *a, const NAIFactoryObject *b );
-gboolean na_factory_object_is_valid ( const NAIFactoryObject *object );
-void na_factory_object_dump ( const NAIFactoryObject *object );
-void na_factory_object_finalize_instance ( NAIFactoryObject *object );
+void na_factory_object_copy ( NAIFactoryObject *target, const NAIFactoryObject *source );
+gboolean na_factory_object_are_equal ( const NAIFactoryObject *a, const NAIFactoryObject *b );
+gboolean na_factory_object_is_valid ( const NAIFactoryObject *object );
+void na_factory_object_dump ( const NAIFactoryObject *object );
+void na_factory_object_finalize_instance( NAIFactoryObject *object );
-void na_factory_object_read_item ( NAIFactoryObject *object, const NAIFactoryProvider *reader, void *reader_data, GSList **messages );
-guint na_factory_object_write_item ( NAIFactoryObject *object, const NAIFactoryProvider *writer, void *writer_data, GSList **messages );
+void na_factory_object_read_item ( NAIFactoryObject *object, const NAIFactoryProvider *reader, void *reader_data, GSList **messages );
+guint na_factory_object_write_item ( NAIFactoryObject *object, const NAIFactoryProvider *writer, void *writer_data, GSList **messages );
-void *na_factory_object_get_as_void ( const NAIFactoryObject *object, const gchar *name );
-void na_factory_object_get_as_value ( const NAIFactoryObject *object, const gchar *name, GValue *value );
+void *na_factory_object_get_as_void ( const NAIFactoryObject *object, const gchar *name );
+void na_factory_object_get_as_value ( const NAIFactoryObject *object, const gchar *name, GValue *value );
-void na_factory_object_set_from_value ( NAIFactoryObject *object, const gchar *name, const GValue *value );
-void na_factory_object_set_from_void ( NAIFactoryObject *object, const gchar *name, const void *data );
+void na_factory_object_set_from_value ( NAIFactoryObject *object, const gchar *name, const GValue *value );
+void na_factory_object_set_from_void ( NAIFactoryObject *object, const gchar *name, const void *data );
#if 0
void na_factory_object_set_from_string ( NAIFactoryObject *object, const gchar *name, const gchar *data );
-void *na_factory_object_get ( const NAIFactoryObject *object, guint data_id );
#endif
G_END_DECLS
diff --git a/src/core/na-ifactory-object.c b/src/core/na-ifactory-object.c
index 89bee3f..90b406a 100644
--- a/src/core/na-ifactory-object.c
+++ b/src/core/na-ifactory-object.c
@@ -111,7 +111,6 @@ interface_base_init( NAIFactoryObjectInterface *klass )
klass->get_version = ifactory_object_get_version;
klass->get_groups = NULL;
- klass->get_default = NULL;
klass->copy = NULL;
klass->are_equal = NULL;
klass->is_valid = NULL;
diff --git a/src/core/na-object-action-factory.c b/src/core/na-object-action-factory.c
index 751e35a..2cadb64 100644
--- a/src/core/na-object-action-factory.c
+++ b/src/core/na-object-action-factory.c
@@ -60,7 +60,7 @@ static NADataDef data_def_action [] = {
"Target a selection context menu",
"Does the action target the context menu when there is some selection ?",
NAFD_TYPE_BOOLEAN,
- "TRUE",
+ "true",
TRUE,
TRUE,
FALSE,
@@ -74,7 +74,7 @@ static NADataDef data_def_action [] = {
"Target the folder context menu",
"Does the action target the context menu when there is no selection ?",
NAFD_TYPE_BOOLEAN,
- "FALSE",
+ "false",
TRUE,
TRUE,
FALSE,
@@ -90,7 +90,7 @@ static NADataDef data_def_action [] = {
"Only an action may target the toolbar as Nautilus, as of 2.28, " \
"doesn't support menus in toolbar.",
NAFD_TYPE_BOOLEAN,
- "FALSE",
+ "false",
TRUE,
TRUE,
FALSE,
@@ -105,7 +105,7 @@ static NADataDef data_def_action [] = {
"Label of the action in the toolbar. " \
"Defaults to main label if empty or not set.",
NAFD_TYPE_LOCALE_STRING,
- "",
+ NULL,
TRUE,
TRUE,
FALSE,
diff --git a/src/core/na-object-action.c b/src/core/na-object-action.c
index ab32e1c..16a8b4e 100644
--- a/src/core/na-object-action.c
+++ b/src/core/na-object-action.c
@@ -81,7 +81,6 @@ static gboolean object_is_valid( const NAObject *object );
static void ifactory_object_iface_init( NAIFactoryObjectInterface *iface );
static guint ifactory_object_get_version( const NAIFactoryObject *instance );
static NADataGroup *ifactory_object_get_groups( const NAIFactoryObject *instance );
-static gchar *ifactory_object_get_default( const NAIFactoryObject *instance, const NADataDef *iddef );
static void ifactory_object_copy( NAIFactoryObject *target, const NAIFactoryObject *source );
static gboolean ifactory_object_are_equal( const NAIFactoryObject *a, const NAIFactoryObject *b );
static gboolean ifactory_object_is_valid( const NAIFactoryObject *object );
@@ -275,7 +274,6 @@ ifactory_object_iface_init( NAIFactoryObjectInterface *iface )
iface->get_version = ifactory_object_get_version;
iface->get_groups = ifactory_object_get_groups;
- iface->get_default = ifactory_object_get_default;
iface->copy = ifactory_object_copy;
iface->are_equal = ifactory_object_are_equal;
iface->is_valid = ifactory_object_is_valid;
@@ -297,22 +295,6 @@ ifactory_object_get_groups( const NAIFactoryObject *instance )
return( action_data_groups );
}
-static gchar *
-ifactory_object_get_default( const NAIFactoryObject *instance, const NADataDef *def )
-{
- gchar *value;
-
- value = NULL;
-
- if( !strcmp( def->name, NAFO_DATA_LABEL ) ||
- !strcmp( def->name, NAFO_DATA_TOOLBAR_LABEL )){
-
- value = g_strdup( NEW_NAUTILUS_ACTION );
- }
-
- return( value );
-}
-
static void
ifactory_object_copy( NAIFactoryObject *target, const NAIFactoryObject *source )
{
@@ -516,6 +498,32 @@ na_object_action_new_with_profile( void )
}
/**
+ * na_object_action_new_with_defaults:
+ *
+ * Allocates a new #NAObjectAction object along with a default profile.
+ * These two objects have suitable default values.
+ *
+ * Returns: the newly allocated #NAObjectAction action.
+ */
+NAObjectAction *
+na_object_action_new_with_defaults( void )
+{
+ NAObjectAction *action;
+ NAObjectProfile *profile;
+
+ action = na_object_action_new();
+ na_object_set_new_id( action, NULL );
+ na_object_set_label( action, NEW_NAUTILUS_ACTION );
+ na_object_set_toolbar_label( action, NEW_NAUTILUS_ACTION );
+ na_factory_object_set_defaults( NA_IFACTORY_OBJECT( action ));
+
+ profile = na_object_profile_new_with_defaults();
+ na_object_action_attach_profile( action, profile );
+
+ return( action );
+}
+
+/**
* na_object_action_get_new_profile_name:
* @action: the #NAObjectAction object which will receive a new profile.
*
diff --git a/src/core/na-object-item-factory.c b/src/core/na-object-item-factory.c
index 99dabd2..ea0a048 100644
--- a/src/core/na-object-item-factory.c
+++ b/src/core/na-object-item-factory.c
@@ -46,7 +46,7 @@ NADataDef data_def_item [] = {
"Main label of the NAObjectItem object. " \
"Serves as a default for the toolbar label of an action.",
NAFD_TYPE_LOCALE_STRING,
- "",
+ NULL,
TRUE,
TRUE,
FALSE,
@@ -60,7 +60,7 @@ NADataDef data_def_item [] = {
"Item tooltip",
"Tooltip associated to the item in the context menu or in the toolbar.",
NAFD_TYPE_LOCALE_STRING,
- "",
+ NULL,
TRUE,
TRUE,
FALSE,
@@ -75,7 +75,7 @@ NADataDef data_def_item [] = {
"Icon displayed in the context menu and in the toolbar. " \
"May be the name of a themed icon, or the full path to any appropriate image.",
NAFD_TYPE_LOCALE_STRING,
- "",
+ NULL,
TRUE,
TRUE,
FALSE,
@@ -90,7 +90,7 @@ NADataDef data_def_item [] = {
"Some text which explains the goal of the menu or the action. " \
"Will be used, e.g. when displaying available items on a web site.",
NAFD_TYPE_LOCALE_STRING,
- "",
+ NULL,
TRUE,
TRUE,
FALSE,
@@ -135,7 +135,7 @@ NADataDef data_def_item [] = {
"When FALSE, the item will never be candidate to the context menu," \
"nor to the toolbar.",
NAFD_TYPE_BOOLEAN,
- "TRUE",
+ "true",
TRUE,
TRUE,
FALSE,
@@ -154,7 +154,7 @@ NADataDef data_def_item [] = {
"Also, a property initially set to FALSE when first unserializing may be set to" \
"TRUE if an eccor occurs on a later write operation.",
NAFD_TYPE_BOOLEAN,
- "FALSE",
+ "false",
TRUE,
FALSE,
FALSE,
diff --git a/src/core/na-object-menu.c b/src/core/na-object-menu.c
index 1e091cb..dc00ed7 100644
--- a/src/core/na-object-menu.c
+++ b/src/core/na-object-menu.c
@@ -74,7 +74,6 @@ static gboolean object_is_valid( const NAObject *object );
static void ifactory_object_iface_init( NAIFactoryObjectInterface *iface );
static guint ifactory_object_get_version( const NAIFactoryObject *instance );
static NADataGroup *ifactory_object_get_groups( const NAIFactoryObject *instance );
-static gchar *ifactory_object_get_default( const NAIFactoryObject *instance, const NADataDef *iddef );
static void ifactory_object_copy( NAIFactoryObject *target, const NAIFactoryObject *source );
static gboolean ifactory_object_are_equal( const NAIFactoryObject *a, const NAIFactoryObject *b );
static gboolean ifactory_object_is_valid( const NAIFactoryObject *object );
@@ -128,10 +127,6 @@ register_type( void )
g_type_add_interface_static( type, NA_IFACTORY_OBJECT_TYPE, &ifactory_object_iface_info );
-#if 0
- na_factory_object_register_type( type, menu_id_groups );
-#endif
-
return( type );
}
@@ -265,7 +260,6 @@ ifactory_object_iface_init( NAIFactoryObjectInterface *iface )
iface->get_version = ifactory_object_get_version;
iface->get_groups = ifactory_object_get_groups;
- iface->get_default = ifactory_object_get_default;
iface->copy = ifactory_object_copy;
iface->are_equal = ifactory_object_are_equal;
iface->is_valid = ifactory_object_is_valid;
@@ -287,21 +281,6 @@ ifactory_object_get_groups( const NAIFactoryObject *instance )
return( menu_data_groups );
}
-static gchar *
-ifactory_object_get_default( const NAIFactoryObject *instance, const NADataDef *def )
-{
- gchar *value;
-
- value = NULL;
-
- if( !strcmp( def->name, NAFO_DATA_LABEL )){
-
- value = g_strdup( NEW_NAUTILUS_MENU );
- }
-
- return( value );
-}
-
static void
ifactory_object_copy( NAIFactoryObject *target, const NAIFactoryObject *source )
{
@@ -399,9 +378,6 @@ is_valid_label( const NAObjectMenu *menu )
*
* Allocates a new #NAObjectMenu object.
*
- * The new #NAObjectMenu object is initialized with suitable default values,
- * but without any profile.
- *
* Returns: the newly allocated #NAObjectMenu object.
*/
NAObjectMenu *
@@ -413,3 +389,22 @@ na_object_menu_new( void )
return( menu );
}
+
+/**
+ * na_object_menu_new_with_defaults:
+ *
+ * Allocates a new #NAObjectMenu object, and setup default values.
+ *
+ * Returns: the newly allocated #NAObjectMenu object.
+ */
+NAObjectMenu *
+na_object_menu_new_with_defaults( void )
+{
+ NAObjectMenu *menu = na_object_menu_new();
+
+ na_object_set_new_id( menu, NULL );
+ na_object_set_label( menu, NEW_NAUTILUS_MENU );
+ na_factory_object_set_defaults( NA_IFACTORY_OBJECT( menu ));
+
+ return( menu );
+}
diff --git a/src/core/na-object-profile-factory.c b/src/core/na-object-profile-factory.c
index 9f81b95..f452dbc 100644
--- a/src/core/na-object-profile-factory.c
+++ b/src/core/na-object-profile-factory.c
@@ -32,6 +32,8 @@
#include <config.h>
#endif
+#include <glib/gi18n.h>
+
#include <api/na-ifactory-object-data.h>
#include <api/na-data-def.h>
#include <api/na-data-types.h>
@@ -46,7 +48,7 @@ static NADataDef data_def_profile [] = {
"Main label of the NAObjectProfile profile. " \
"May be used as a description for the function of the profile.",
NAFD_TYPE_LOCALE_STRING,
- "",
+ N_( "Default profile" ),
TRUE,
TRUE,
FALSE,
@@ -60,7 +62,7 @@ static NADataDef data_def_profile [] = {
"Command path",
"The path to the command.",
NAFD_TYPE_STRING,
- "",
+ NULL,
TRUE,
TRUE,
TRUE,
@@ -74,7 +76,7 @@ static NADataDef data_def_profile [] = {
"Command parameters",
"The parameters of the command.",
NAFD_TYPE_STRING,
- "",
+ NULL,
TRUE,
TRUE,
FALSE,
@@ -104,7 +106,7 @@ static NADataDef data_def_profile [] = {
"Whether the specified basenames are case sensitive." \
"Defaults to 'true'.",
NAFD_TYPE_BOOLEAN,
- "TRUE",
+ "true",
TRUE,
TRUE,
FALSE,
@@ -134,7 +136,7 @@ static NADataDef data_def_profile [] = {
"Whether the profile only applies to files." \
"Defaults to 'true'",
NAFD_TYPE_BOOLEAN,
- "TRUE",
+ "true",
TRUE,
TRUE,
FALSE,
@@ -149,7 +151,7 @@ static NADataDef data_def_profile [] = {
"Whether the profile applies to directories only." \
"Defaults to 'false'",
NAFD_TYPE_BOOLEAN,
- "FALSE",
+ "false",
TRUE,
TRUE,
FALSE,
@@ -164,7 +166,7 @@ static NADataDef data_def_profile [] = {
"Whether the selection may be multiple." \
"Defaults to 'false'.",
NAFD_TYPE_BOOLEAN,
- "FALSE",
+ "false",
TRUE,
TRUE,
FALSE,
diff --git a/src/core/na-object-profile.c b/src/core/na-object-profile.c
index 6c203b2..b092abf 100644
--- a/src/core/na-object-profile.c
+++ b/src/core/na-object-profile.c
@@ -81,7 +81,6 @@ static gboolean object_is_valid( const NAObject *object );
static void ifactory_object_iface_init( NAIFactoryObjectInterface *iface );
static guint ifactory_object_get_version( const NAIFactoryObject *instance );
static NADataGroup *ifactory_object_get_groups( const NAIFactoryObject *instance );
-static gchar *ifactory_object_get_default( const NAIFactoryObject *instance, const NADataDef *iddef );
static gboolean ifactory_object_is_valid( const NAIFactoryObject *object );
static void ifactory_object_read_done( NAIFactoryObject *instance, const NAIFactoryProvider *reader, void *reader_data, GSList **messages );
static guint ifactory_object_write_done( NAIFactoryObject *instance, const NAIFactoryProvider *writer, void *writer_data, GSList **messages );
@@ -152,10 +151,6 @@ register_type( void )
g_type_add_interface_static( type, NA_IFACTORY_OBJECT_TYPE, &ifactory_object_iface_info );
-#if 0
- na_factory_object_register_type( type, profile_id_groups );
-#endif
-
return( type );
}
@@ -295,7 +290,6 @@ ifactory_object_iface_init( NAIFactoryObjectInterface *iface )
iface->get_version = ifactory_object_get_version;
iface->get_groups = ifactory_object_get_groups;
- iface->get_default = ifactory_object_get_default;
iface->copy = NULL;
iface->are_equal = NULL;
iface->is_valid = ifactory_object_is_valid;
@@ -317,23 +311,6 @@ ifactory_object_get_groups( const NAIFactoryObject *instance )
return( profile_data_groups );
}
-static gchar *
-ifactory_object_get_default( const NAIFactoryObject *instance, const NADataDef *def )
-{
- gchar *value;
-
- value = NULL;
-
- if( !strcmp( def->name, NAFO_DATA_ID )){
- value = g_strdup( PROFILE_NAME_PREFIX "zero" );
-
- } else if( !strcmp( def->name, NAFO_DATA_LABEL )){
- value = g_strdup( DEFAULT_PROFILE );
- }
-
- return( value );
-}
-
static gboolean
ifactory_object_is_valid( const NAIFactoryObject *object )
{
@@ -547,6 +524,24 @@ na_object_profile_new( void )
}
/**
+ * na_object_profile_new_with_defaults:
+ *
+ * Allocates a new profile, and set default values.
+ *
+ * Returns: the newly allocated #NAObjectProfile profile.
+ */
+NAObjectProfile *
+na_object_profile_new_with_defaults( void )
+{
+ NAObjectProfile *profile = na_object_profile_new();
+
+ na_object_set_id( profile, "profile-zero" );
+ na_factory_object_set_defaults( NA_IFACTORY_OBJECT( profile ));
+
+ return( profile );
+}
+
+/**
* na_object_profile_set_scheme:
* @profile: the #NAObjectProfile to be updated.
* @scheme: name of the scheme.
diff --git a/src/nact/nact-iaction-tab.c b/src/nact/nact-iaction-tab.c
index 7b62669..34be660 100644
--- a/src/nact/nact-iaction-tab.c
+++ b/src/nact/nact-iaction-tab.c
@@ -462,6 +462,9 @@ on_tab_updatable_selection_changed( NactIActionTab *instance, gint count_selecte
enable_label = ( item && ( NA_IS_OBJECT_MENU( item ) || target_selection || target_background ));
label_widget = base_window_get_widget( BASE_WINDOW( instance ), "ActionMenuLabelEntry" );
label = item ? na_object_get_label( item ) : g_strdup( "" );
+ if( !label ){
+ label = g_strdup( "" );
+ }
gtk_entry_set_text( GTK_ENTRY( label_widget ), label );
if( item ){
check_for_label( instance, GTK_ENTRY( label_widget ), label );
@@ -483,6 +486,9 @@ on_tab_updatable_selection_changed( NactIActionTab *instance, gint count_selecte
label_widget = base_window_get_widget( BASE_WINDOW( instance ), "ActionIconLabelEntry" );
label = item && NA_IS_OBJECT_ACTION( item ) ? na_object_get_toolbar_label( NA_OBJECT_ACTION( item )) : g_strdup( "" );
+ if( !label ){
+ label = g_strdup( "" );
+ }
gtk_entry_set_text( GTK_ENTRY( label_widget ), label );
g_free( label );
toolbar_label_set_sensitive( instance, item );
@@ -490,6 +496,9 @@ on_tab_updatable_selection_changed( NactIActionTab *instance, gint count_selecte
tooltip_widget = base_window_get_widget( BASE_WINDOW( instance ), "ActionTooltipEntry" );
tooltip = item ? na_object_get_tooltip( item ) : g_strdup( "" );
+ if( !tooltip ){
+ tooltip = g_strdup( "" );
+ }
gtk_entry_set_text( GTK_ENTRY( tooltip_widget ), tooltip );
g_free( tooltip );
gtk_widget_set_sensitive( tooltip_widget, item != NULL );
@@ -497,6 +506,9 @@ on_tab_updatable_selection_changed( NactIActionTab *instance, gint count_selecte
icon_widget = base_window_get_widget( BASE_WINDOW( instance ), "ActionIconComboBoxEntry" );
icon = item ? na_object_get_icon( item ) : g_strdup( "" );
+ if( !icon ){
+ icon = g_strdup( "" );
+ }
gtk_entry_set_text( GTK_ENTRY( GTK_BIN( icon_widget )->child ), icon );
g_free( icon );
gtk_widget_set_sensitive( icon_widget, item != NULL );
@@ -535,6 +547,9 @@ on_tab_updatable_selection_changed( NactIActionTab *instance, gint count_selecte
label_widget = base_window_get_widget( BASE_WINDOW( instance ), "ActionItemID" );
label = item ? na_object_get_id( item ) : g_strdup( "" );
+ if( !label ){
+ label = g_strdup( "" );
+ }
gtk_label_set_text( GTK_LABEL( label_widget ), label );
g_free( label );
gtk_widget_set_sensitive( label_widget, item != NULL );
diff --git a/src/nact/nact-icommand-tab.c b/src/nact/nact-icommand-tab.c
index d942fec..e5adc38 100644
--- a/src/nact/nact-icommand-tab.c
+++ b/src/nact/nact-icommand-tab.c
@@ -340,6 +340,9 @@ on_tab_updatable_selection_changed( NactICommandTab *instance, gint count_select
label_entry = get_label_entry( instance );
label = profile ? na_object_get_label( profile ) : g_strdup( "" );
+ if( !label ){
+ label = g_strdup( "" );
+ }
gtk_entry_set_text( GTK_ENTRY( label_entry ), label );
check_for_label( instance, GTK_ENTRY( label_entry ), label );
g_free( label );
@@ -348,6 +351,9 @@ on_tab_updatable_selection_changed( NactICommandTab *instance, gint count_select
path_entry = get_path_entry( instance );
path = profile ? na_object_get_path( profile ) : g_strdup( "" );
+ if( !path ){
+ path = g_strdup( "" );
+ }
gtk_entry_set_text( GTK_ENTRY( path_entry ), path );
g_free( path );
gtk_widget_set_sensitive( path_entry, profile != NULL );
@@ -359,6 +365,9 @@ on_tab_updatable_selection_changed( NactICommandTab *instance, gint count_select
parameters_entry = get_parameters_entry( instance );
parameters = profile ? na_object_get_parameters( profile ) : g_strdup( "" );
+ if( !parameters ){
+ parameters = g_strdup( "" );
+ }
gtk_entry_set_text( GTK_ENTRY( parameters_entry ), parameters );
g_free( parameters );
gtk_widget_set_sensitive( parameters_entry, profile != NULL );
diff --git a/src/nact/nact-iconditions-tab.c b/src/nact/nact-iconditions-tab.c
index c8c0936..3ef7d49 100644
--- a/src/nact/nact-iconditions-tab.c
+++ b/src/nact/nact-iconditions-tab.c
@@ -332,6 +332,9 @@ on_tab_updatable_selection_changed( NactIConditionsTab *instance, gint count_sel
basenames_widget = get_basenames_entry( instance );
basenames = profile ? na_object_get_basenames( profile ) : NULL;
basenames_text = profile ? na_core_utils_slist_to_text( basenames ) : g_strdup( "" );
+ if( !basenames_text ){
+ basenames_text = g_strdup( "" );
+ }
gtk_entry_set_text( GTK_ENTRY( basenames_widget ), basenames_text );
g_free( basenames_text );
na_core_utils_slist_free( basenames );
@@ -347,6 +350,9 @@ on_tab_updatable_selection_changed( NactIConditionsTab *instance, gint count_sel
mimetypes_widget = get_mimetypes_entry( instance );
mimetypes = profile ? na_object_get_mimetypes( profile ) : NULL;
mimetypes_text = profile ? na_core_utils_slist_to_text( mimetypes ) : g_strdup( "" );
+ if( !mimetypes_text ){
+ mimetypes_text = g_strdup( "" );
+ }
gtk_entry_set_text( GTK_ENTRY( mimetypes_widget ), mimetypes_text );
g_free( mimetypes_text );
na_core_utils_slist_free( mimetypes );
diff --git a/src/nact/nact-main-menubar.c b/src/nact/nact-main-menubar.c
index ca51e70..f2f9483 100644
--- a/src/nact/nact-main-menubar.c
+++ b/src/nact/nact-main-menubar.c
@@ -846,7 +846,7 @@ on_new_menu_activated( GtkAction *gtk_action, NactMainWindow *window )
g_return_if_fail( GTK_IS_ACTION( gtk_action ));
g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
- menu = na_object_menu_new();
+ menu = na_object_menu_new_with_defaults();
na_object_check_status( menu );
items = g_list_prepend( NULL, menu );
nact_iactions_list_bis_insert_items( NACT_IACTIONS_LIST( window ), items, NULL );
@@ -862,7 +862,7 @@ on_new_action_activated( GtkAction *gtk_action, NactMainWindow *window )
g_return_if_fail( GTK_IS_ACTION( gtk_action ));
g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
- action = na_object_action_new_with_profile();
+ action = na_object_action_new_with_defaults();
na_object_check_status( action );
items = g_list_prepend( NULL, action );
nact_iactions_list_bis_insert_items( NACT_IACTIONS_LIST( window ), items, NULL );
@@ -885,18 +885,19 @@ on_new_profile_activated( GtkAction *gtk_action, NactMainWindow *window )
TAB_UPDATABLE_PROP_EDITED_ACTION, &action,
NULL );
- profile = na_object_profile_new();
+ profile = na_object_profile_new_with_defaults();
name = na_object_action_get_new_profile_name( action );
- na_object_set_parent( profile, action );
na_object_set_id( profile, name );
+ g_free( name );
+
+ na_object_attach_profile( action, profile );
+
na_object_check_status( profile );
items = g_list_prepend( NULL, profile );
nact_iactions_list_bis_insert_items( NACT_IACTIONS_LIST( window ), items, NULL );
-
na_object_unref_items( items );
- g_free( name );
}
/*
diff --git a/src/utils/nautilus-actions-new.c b/src/utils/nautilus-actions-new.c
index f81212f..2f7d584 100644
--- a/src/utils/nautilus-actions-new.c
+++ b/src/utils/nautilus-actions-new.c
@@ -292,7 +292,7 @@ get_action_from_cmdline( void )
GSList *schemes;
GSList *folders;
- action = na_object_action_new_with_profile();
+ action = na_object_action_new_with_defaults();
profile = NA_OBJECT_PROFILE(( GList * ) na_object_get_items( action )->data );
na_object_set_label( action, label );
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]