mirror of https://github.com/GNOME/gimp.git
made object properties G_PARAM_READWRITE by default. Added flag
2003-04-12 Michael Natterer <mitch@gimp.org> * app/config/gimpconfig-params.h: made object properties G_PARAM_READWRITE by default. Added flag GIMP_PARAM_AGGREGATE which indicates that an object property is not a reference but a real part of its owner. * app/config/gimpconfig-deserialize.c: g_object_set_property() object properties only if they are not GIMP_PARAM_AGGREGATE. * app/config/gimpconfig-utils.c (gimp_config_copy_properties, gimp_config_reset_properties): copy and reset GIMP_PARAM_AGGREGATE object properties correctly. * app/config/gimpconfig-serialize.c: don't call gimp_config_writer_open/close() for properties which are handled by a GimpConfigIface::serialize_property() implementation. * app/core/gimpcontext.c: removed exlicit G_PARAM_WRITABLE from object properties since that's the default now. Call gimp_config_writer_open/close() when serializing properties. * app/core/gimpviewable.c (gimp_viewable_get_property): use gimp_viewable_get_stock_id(). (gimp_viewable_set_stock_id): set stock_id to NULL if the new stock_id is the same as viewable_class->default_stock_id. Added serialize_property() which skips stock_id serialization if it is NULL. * app/tools/gimptextoptions.c: made the "text" property GIMP_PARAM_AGGREGATE. Added gimp_text_options_set_property() (which does nothing). * app/widgets/gimptemplateeditor.[ch]: added an optional GimpViewableButton to change the template's icon. * app/gui/file-new-dialog.c: create it with the icon button so it gets some testing.
This commit is contained in:
parent
8bed928dee
commit
f82440ff48
39
ChangeLog
39
ChangeLog
|
@ -1,3 +1,42 @@
|
|||
2003-04-12 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
* app/config/gimpconfig-params.h: made object properties
|
||||
G_PARAM_READWRITE by default. Added flag GIMP_PARAM_AGGREGATE
|
||||
which indicates that an object property is not a reference but a
|
||||
real part of its owner.
|
||||
|
||||
* app/config/gimpconfig-deserialize.c: g_object_set_property()
|
||||
object properties only if they are not GIMP_PARAM_AGGREGATE.
|
||||
|
||||
* app/config/gimpconfig-utils.c (gimp_config_copy_properties,
|
||||
gimp_config_reset_properties): copy and reset GIMP_PARAM_AGGREGATE
|
||||
object properties correctly.
|
||||
|
||||
* app/config/gimpconfig-serialize.c: don't call
|
||||
gimp_config_writer_open/close() for properties which are handled
|
||||
by a GimpConfigIface::serialize_property() implementation.
|
||||
|
||||
* app/core/gimpcontext.c: removed exlicit G_PARAM_WRITABLE from
|
||||
object properties since that's the default now. Call
|
||||
gimp_config_writer_open/close() when serializing properties.
|
||||
|
||||
* app/core/gimpviewable.c (gimp_viewable_get_property): use
|
||||
gimp_viewable_get_stock_id().
|
||||
(gimp_viewable_set_stock_id): set stock_id to NULL if the new
|
||||
stock_id is the same as viewable_class->default_stock_id.
|
||||
Added serialize_property() which skips stock_id serialization
|
||||
if it is NULL.
|
||||
|
||||
* app/tools/gimptextoptions.c: made the "text" property
|
||||
GIMP_PARAM_AGGREGATE. Added gimp_text_options_set_property()
|
||||
(which does nothing).
|
||||
|
||||
* app/widgets/gimptemplateeditor.[ch]: added an optional
|
||||
GimpViewableButton to change the template's icon.
|
||||
|
||||
* app/gui/file-new-dialog.c: create it with the icon button so it
|
||||
gets some testing.
|
||||
|
||||
2003-04-12 Dave Neary <bolsh@gimp.org>
|
||||
|
||||
* plug-ins/common/png.c (save_image):
|
||||
|
|
|
@ -301,8 +301,8 @@ gimp_config_deserialize_property (GObject *object,
|
|||
if (token == G_TOKEN_RIGHT_PAREN &&
|
||||
g_scanner_peek_next_token (scanner) == token)
|
||||
{
|
||||
if (!G_VALUE_HOLDS_OBJECT (&value) ||
|
||||
prop_spec->flags & G_PARAM_WRITABLE)
|
||||
if (! (G_VALUE_HOLDS_OBJECT (&value) &&
|
||||
(prop_spec->flags & GIMP_PARAM_AGGREGATE)))
|
||||
g_object_set_property (object, prop_spec->name, &value);
|
||||
}
|
||||
#if CONFIG_DEBUG
|
||||
|
|
|
@ -24,8 +24,9 @@
|
|||
|
||||
|
||||
#define GIMP_PARAM_SERIALIZE (1 << (0 + G_PARAM_USER_SHIFT))
|
||||
#define GIMP_PARAM_RESTART (1 << (1 + G_PARAM_USER_SHIFT))
|
||||
#define GIMP_PARAM_CONFIRM (1 << (2 + G_PARAM_USER_SHIFT))
|
||||
#define GIMP_PARAM_AGGREGATE (1 << (1 + G_PARAM_USER_SHIFT))
|
||||
#define GIMP_PARAM_RESTART (1 << (2 + G_PARAM_USER_SHIFT))
|
||||
#define GIMP_PARAM_CONFIRM (1 << (3 + G_PARAM_USER_SHIFT))
|
||||
|
||||
|
||||
#define GIMP_CONFIG_PARAM_FLAGS (G_PARAM_READWRITE | \
|
||||
|
@ -175,7 +176,7 @@ GParamSpec * gimp_param_spec_unit (const gchar *name,
|
|||
flags | GIMP_CONFIG_PARAM_FLAGS))
|
||||
|
||||
|
||||
/* object properties are _not_ writeable by default */
|
||||
/* object properties are _not_ G_PARAM_CONSTRUCT */
|
||||
|
||||
#define GIMP_CONFIG_INSTALL_PROP_OBJECT(class, id,\
|
||||
name, blurb, object_type, flags)\
|
||||
|
@ -183,7 +184,7 @@ GParamSpec * gimp_param_spec_unit (const gchar *name,
|
|||
g_param_spec_object (name, NULL, blurb,\
|
||||
object_type,\
|
||||
flags |\
|
||||
G_PARAM_READABLE | GIMP_PARAM_SERIALIZE))
|
||||
G_PARAM_READWRITE | GIMP_PARAM_SERIALIZE))
|
||||
|
||||
|
||||
#endif /* __GIMP_CONFIG_PARAMS_H__ */
|
||||
|
|
|
@ -205,8 +205,6 @@ gimp_config_serialize_property (GObject *object,
|
|||
if (! (param_spec->flags & GIMP_PARAM_SERIALIZE))
|
||||
return FALSE;
|
||||
|
||||
gimp_config_writer_open (writer, param_spec->name);
|
||||
|
||||
g_value_init (&value, param_spec->value_type);
|
||||
g_object_get_property (object, param_spec->name, &value);
|
||||
|
||||
|
@ -253,7 +251,8 @@ gimp_config_serialize_property (GObject *object,
|
|||
|
||||
if (! success)
|
||||
{
|
||||
if (G_VALUE_HOLDS_OBJECT (&value))
|
||||
if (G_VALUE_HOLDS_OBJECT (&value) &&
|
||||
(param_spec->flags & GIMP_PARAM_AGGREGATE))
|
||||
{
|
||||
GimpConfigInterface *gimp_config_iface = NULL;
|
||||
GObject *prop_object;
|
||||
|
@ -266,41 +265,49 @@ gimp_config_serialize_property (GObject *object,
|
|||
success = TRUE;
|
||||
|
||||
if (gimp_config_iface)
|
||||
success = gimp_config_iface->serialize (prop_object, writer, NULL);
|
||||
{
|
||||
gimp_config_writer_open (writer, param_spec->name);
|
||||
|
||||
success = gimp_config_iface->serialize (prop_object, writer,
|
||||
NULL);
|
||||
|
||||
if (success)
|
||||
gimp_config_writer_close (writer);
|
||||
else
|
||||
gimp_config_writer_revert (writer);
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (! G_VALUE_HOLDS_OBJECT (&value))
|
||||
{
|
||||
GString *str = g_string_new (NULL);
|
||||
|
||||
success = gimp_config_serialize_value (&value, str, TRUE);
|
||||
|
||||
if (success)
|
||||
gimp_config_writer_print (writer, str->str, str->len);
|
||||
{
|
||||
gimp_config_writer_open (writer, param_spec->name);
|
||||
gimp_config_writer_print (writer, str->str, str->len);
|
||||
gimp_config_writer_close (writer);
|
||||
}
|
||||
|
||||
g_string_free (str, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
if (success)
|
||||
{
|
||||
gimp_config_writer_close (writer);
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_config_writer_revert (writer);
|
||||
|
||||
/* don't warn for empty string properties */
|
||||
if (G_VALUE_HOLDS_STRING (&value))
|
||||
{
|
||||
success = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_warning ("couldn't serialize property %s::%s of type %s",
|
||||
g_type_name (G_TYPE_FROM_INSTANCE (object)),
|
||||
param_spec->name,
|
||||
g_type_name (param_spec->value_type));
|
||||
}
|
||||
if (! success)
|
||||
{
|
||||
/* don't warn for empty string properties */
|
||||
if (G_VALUE_HOLDS_STRING (&value))
|
||||
{
|
||||
success = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_warning ("couldn't serialize property %s::%s of type %s",
|
||||
g_type_name (G_TYPE_FROM_INSTANCE (object)),
|
||||
param_spec->name,
|
||||
g_type_name (param_spec->value_type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g_value_unset (&value);
|
||||
|
|
|
@ -179,21 +179,51 @@ gimp_config_copy_properties (GObject *src,
|
|||
for (i = 0; i < n_property_specs; i++)
|
||||
{
|
||||
GParamSpec *prop_spec;
|
||||
|
||||
|
||||
prop_spec = property_specs[i];
|
||||
|
||||
if (prop_spec->flags & G_PARAM_READABLE &&
|
||||
prop_spec->flags & G_PARAM_WRITABLE)
|
||||
{
|
||||
GValue value = { 0, };
|
||||
if (G_IS_PARAM_SPEC_OBJECT (prop_spec) &&
|
||||
(prop_spec->flags & GIMP_PARAM_AGGREGATE))
|
||||
{
|
||||
GValue src_value = { 0, };
|
||||
GValue dest_value = { 0, };
|
||||
GObject *src_object;
|
||||
GObject *dest_object;
|
||||
|
||||
g_value_init (&value, prop_spec->value_type);
|
||||
|
||||
g_object_get_property (src, prop_spec->name, &value);
|
||||
g_object_set_property (dest, prop_spec->name, &value);
|
||||
|
||||
g_value_unset (&value);
|
||||
}
|
||||
g_value_init (&src_value, prop_spec->value_type);
|
||||
g_value_init (&dest_value, prop_spec->value_type);
|
||||
|
||||
g_object_get_property (src, prop_spec->name, &src_value);
|
||||
g_object_get_property (dest, prop_spec->name, &dest_value);
|
||||
|
||||
src_object = g_value_get_object (&src_value);
|
||||
dest_object = g_value_get_object (&dest_value);
|
||||
|
||||
if (src_object && dest_object &&
|
||||
G_TYPE_FROM_INSTANCE (src_object) ==
|
||||
G_TYPE_FROM_INSTANCE (dest_object))
|
||||
{
|
||||
gimp_config_copy_properties (src_object, dest_object);
|
||||
}
|
||||
|
||||
g_value_unset (&src_value);
|
||||
g_value_unset (&dest_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
GValue value = { 0, };
|
||||
|
||||
g_value_init (&value, prop_spec->value_type);
|
||||
|
||||
g_object_get_property (src, prop_spec->name, &value);
|
||||
g_object_set_property (dest, prop_spec->name, &value);
|
||||
|
||||
g_value_unset (&value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g_free (property_specs);
|
||||
|
@ -234,30 +264,34 @@ gimp_config_reset_properties (GObject *object)
|
|||
|
||||
prop_spec = property_specs[i];
|
||||
|
||||
if (G_IS_PARAM_SPEC_OBJECT (prop_spec))
|
||||
if (prop_spec->flags & G_PARAM_WRITABLE)
|
||||
{
|
||||
if ((prop_spec->flags & GIMP_PARAM_SERIALIZE) &&
|
||||
g_type_interface_peek (g_type_class_peek (prop_spec->value_type),
|
||||
GIMP_TYPE_CONFIG_INTERFACE))
|
||||
if (G_IS_PARAM_SPEC_OBJECT (prop_spec))
|
||||
{
|
||||
if ((prop_spec->flags & GIMP_PARAM_SERIALIZE) &&
|
||||
(prop_spec->flags & GIMP_PARAM_AGGREGATE) &&
|
||||
g_type_interface_peek (g_type_class_peek (prop_spec->value_type),
|
||||
GIMP_TYPE_CONFIG_INTERFACE))
|
||||
{
|
||||
g_value_init (&value, prop_spec->value_type);
|
||||
|
||||
g_object_get_property (object, prop_spec->name, &value);
|
||||
|
||||
gimp_config_reset (g_value_get_object (&value));
|
||||
|
||||
g_value_unset (&value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g_value_init (&value, prop_spec->value_type);
|
||||
|
||||
g_object_get_property (object, prop_spec->name, &value);
|
||||
|
||||
gimp_config_reset (g_value_get_object (&value));
|
||||
g_param_value_set_default (prop_spec, &value);
|
||||
g_object_set_property (object, prop_spec->name, &value);
|
||||
|
||||
g_value_unset (&value);
|
||||
}
|
||||
}
|
||||
else if (prop_spec->flags & G_PARAM_WRITABLE)
|
||||
{
|
||||
g_value_init (&value, prop_spec->value_type);
|
||||
|
||||
g_param_value_set_default (prop_spec, &value);
|
||||
g_object_set_property (object, prop_spec->name, &value);
|
||||
|
||||
g_value_unset (&value);
|
||||
}
|
||||
}
|
||||
|
||||
g_free (property_specs);
|
||||
|
|
|
@ -31,8 +31,13 @@
|
|||
|
||||
#include "base/temp-buf.h"
|
||||
|
||||
#include "config/gimpconfig.h"
|
||||
#include "config/gimpconfig-params.h"
|
||||
#include "config/gimpconfig-serialize.h"
|
||||
#include "config/gimpconfig-types.h"
|
||||
#include "config/gimpconfigwriter.h"
|
||||
#include "config/gimpcoreconfig.h"
|
||||
#include "config/gimpscanner.h"
|
||||
|
||||
#include "gimp.h"
|
||||
#include "gimpbrush.h"
|
||||
|
@ -51,12 +56,6 @@
|
|||
|
||||
#include "text/gimpfont.h"
|
||||
|
||||
#include "config/gimpconfig.h"
|
||||
#include "config/gimpconfig-types.h"
|
||||
#include "config/gimpconfig-params.h"
|
||||
#include "config/gimpconfigwriter.h"
|
||||
#include "config/gimpscanner.h"
|
||||
|
||||
#include "gimp-intl.h"
|
||||
|
||||
|
||||
|
@ -583,7 +582,7 @@ gimp_context_class_init (GimpContextClass *klass)
|
|||
GIMP_CONFIG_INSTALL_PROP_OBJECT (object_class, GIMP_CONTEXT_PROP_TOOL,
|
||||
gimp_context_prop_names[GIMP_CONTEXT_PROP_TOOL], NULL,
|
||||
GIMP_TYPE_TOOL_INFO,
|
||||
G_PARAM_WRITABLE);
|
||||
0);
|
||||
|
||||
GIMP_CONFIG_INSTALL_PROP_COLOR (object_class, GIMP_CONTEXT_PROP_FOREGROUND,
|
||||
gimp_context_prop_names[GIMP_CONTEXT_PROP_FOREGROUND],
|
||||
|
@ -616,31 +615,31 @@ gimp_context_class_init (GimpContextClass *klass)
|
|||
gimp_context_prop_names[GIMP_CONTEXT_PROP_BRUSH],
|
||||
NULL,
|
||||
GIMP_TYPE_BRUSH,
|
||||
G_PARAM_WRITABLE);
|
||||
0);
|
||||
|
||||
GIMP_CONFIG_INSTALL_PROP_OBJECT (object_class, GIMP_CONTEXT_PROP_PATTERN,
|
||||
gimp_context_prop_names[GIMP_CONTEXT_PROP_PATTERN],
|
||||
NULL,
|
||||
GIMP_TYPE_PATTERN,
|
||||
G_PARAM_WRITABLE);
|
||||
0);
|
||||
|
||||
GIMP_CONFIG_INSTALL_PROP_OBJECT (object_class, GIMP_CONTEXT_PROP_GRADIENT,
|
||||
gimp_context_prop_names[GIMP_CONTEXT_PROP_GRADIENT],
|
||||
NULL,
|
||||
GIMP_TYPE_GRADIENT,
|
||||
G_PARAM_WRITABLE);
|
||||
0);
|
||||
|
||||
GIMP_CONFIG_INSTALL_PROP_OBJECT (object_class, GIMP_CONTEXT_PROP_PALETTE,
|
||||
gimp_context_prop_names[GIMP_CONTEXT_PROP_PALETTE],
|
||||
NULL,
|
||||
GIMP_TYPE_PALETTE,
|
||||
G_PARAM_WRITABLE);
|
||||
0);
|
||||
|
||||
GIMP_CONFIG_INSTALL_PROP_OBJECT (object_class, GIMP_CONTEXT_PROP_FONT,
|
||||
gimp_context_prop_names[GIMP_CONTEXT_PROP_FONT],
|
||||
NULL,
|
||||
GIMP_TYPE_FONT,
|
||||
G_PARAM_WRITABLE);
|
||||
0);
|
||||
|
||||
g_object_class_install_property (object_class, GIMP_CONTEXT_PROP_BUFFER,
|
||||
g_param_spec_object (gimp_context_prop_names[GIMP_CONTEXT_PROP_BUFFER],
|
||||
|
@ -1140,6 +1139,8 @@ gimp_context_serialize_property (GObject *object,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
gimp_config_writer_open (writer, pspec->name);
|
||||
|
||||
if (serialize_obj)
|
||||
{
|
||||
gimp_config_writer_string (writer, gimp_object_get_name (serialize_obj));
|
||||
|
@ -1149,6 +1150,8 @@ gimp_context_serialize_property (GObject *object,
|
|||
gimp_config_writer_print (writer, "NULL", 4);
|
||||
}
|
||||
|
||||
gimp_config_writer_close (writer);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* The GIMP -- an image manipulation program
|
||||
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* gimpviewable.h
|
||||
* gimpviewable.c
|
||||
* Copyright (C) 2001 Michael Natterer <mitch@gimp.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
@ -21,13 +21,17 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "core-types.h"
|
||||
|
||||
#include "base/temp-buf.h"
|
||||
|
||||
#include "config/gimpconfig.h"
|
||||
#include "config/gimpconfig-params.h"
|
||||
#include "config/gimpconfigwriter.h"
|
||||
|
||||
#include "gimpmarshal.h"
|
||||
#include "gimpviewable.h"
|
||||
|
@ -47,8 +51,9 @@ enum
|
|||
};
|
||||
|
||||
|
||||
static void gimp_viewable_class_init (GimpViewableClass *klass);
|
||||
static void gimp_viewable_init (GimpViewable *viewable);
|
||||
static void gimp_viewable_class_init (GimpViewableClass *klass);
|
||||
static void gimp_viewable_init (GimpViewable *viewable);
|
||||
static void gimp_viewable_config_iface_init (GimpConfigInterface *config_iface);
|
||||
|
||||
static void gimp_viewable_finalize (GObject *object);
|
||||
static void gimp_viewable_set_property (GObject *object,
|
||||
|
@ -72,6 +77,11 @@ static void gimp_viewable_real_get_preview_size (GimpViewable *viewable,
|
|||
gint *height);
|
||||
static gchar * gimp_viewable_real_get_description (GimpViewable *viewable,
|
||||
gchar **tooltip);
|
||||
static gboolean gimp_viewable_serialize_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec,
|
||||
GimpConfigWriter *writer);
|
||||
|
||||
|
||||
static guint viewable_signals[LAST_SIGNAL] = { 0 };
|
||||
|
@ -101,10 +111,20 @@ gimp_viewable_get_type (void)
|
|||
0, /* n_preallocs */
|
||||
(GInstanceInitFunc) gimp_viewable_init,
|
||||
};
|
||||
static const GInterfaceInfo config_iface_info =
|
||||
{
|
||||
(GInterfaceInitFunc) gimp_viewable_config_iface_init,
|
||||
NULL, /* iface_finalize */
|
||||
NULL /* iface_data */
|
||||
};
|
||||
|
||||
viewable_type = g_type_register_static (GIMP_TYPE_OBJECT,
|
||||
"GimpViewable",
|
||||
&viewable_info, 0);
|
||||
|
||||
g_type_add_interface_static (viewable_type,
|
||||
GIMP_TYPE_CONFIG_INTERFACE,
|
||||
&config_iface_info);
|
||||
}
|
||||
|
||||
return viewable_type;
|
||||
|
@ -170,6 +190,12 @@ gimp_viewable_init (GimpViewable *viewable)
|
|||
viewable->stock_id = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_viewable_config_iface_init (GimpConfigInterface *config_iface)
|
||||
{
|
||||
config_iface->serialize_property = gimp_viewable_serialize_property;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_viewable_finalize (GObject *object)
|
||||
{
|
||||
|
@ -213,7 +239,8 @@ gimp_viewable_get_property (GObject *object,
|
|||
switch (property_id)
|
||||
{
|
||||
case PROP_STOCK_ID:
|
||||
g_value_set_string (value, GIMP_VIEWABLE (object)->stock_id);
|
||||
g_value_set_string (value,
|
||||
gimp_viewable_get_stock_id (GIMP_VIEWABLE (object)));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
|
@ -288,6 +315,33 @@ gimp_viewable_real_get_description (GimpViewable *viewable,
|
|||
return g_strdup (gimp_object_get_name (GIMP_OBJECT (viewable)));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_viewable_serialize_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec,
|
||||
GimpConfigWriter *writer)
|
||||
{
|
||||
GimpViewable *viewable = GIMP_VIEWABLE (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_STOCK_ID:
|
||||
if (viewable->stock_id)
|
||||
{
|
||||
gimp_config_writer_open (writer, pspec->name);
|
||||
gimp_config_writer_string (writer, viewable->stock_id);
|
||||
gimp_config_writer_close (writer);
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
gimp_viewable_invalidate_preview (GimpViewable *viewable)
|
||||
{
|
||||
|
@ -585,10 +639,21 @@ void
|
|||
gimp_viewable_set_stock_id (GimpViewable *viewable,
|
||||
const gchar *stock_id)
|
||||
{
|
||||
GimpViewableClass *viewable_class;
|
||||
|
||||
g_return_if_fail (GIMP_IS_VIEWABLE (viewable));
|
||||
|
||||
g_free (viewable->stock_id);
|
||||
viewable->stock_id = g_strdup (stock_id);
|
||||
viewable->stock_id = NULL;
|
||||
|
||||
viewable_class = GIMP_VIEWABLE_GET_CLASS (viewable);
|
||||
|
||||
if (stock_id)
|
||||
{
|
||||
if (viewable_class->default_stock_id == NULL ||
|
||||
strcmp (stock_id, viewable_class->default_stock_id))
|
||||
viewable->stock_id = g_strdup (stock_id);
|
||||
}
|
||||
|
||||
g_object_notify (G_OBJECT (viewable), "stock-id");
|
||||
}
|
||||
|
|
|
@ -145,7 +145,7 @@ file_new_dialog_create (Gimp *gimp,
|
|||
dialog);
|
||||
|
||||
/* Template editor */
|
||||
dialog->editor = gimp_template_editor_new ();
|
||||
dialog->editor = gimp_template_editor_new (gimp, TRUE);
|
||||
gtk_box_pack_start (GTK_BOX (main_vbox), dialog->editor, FALSE, FALSE, 0);
|
||||
gtk_widget_show (dialog->editor);
|
||||
|
||||
|
|
|
@ -145,7 +145,7 @@ file_new_dialog_create (Gimp *gimp,
|
|||
dialog);
|
||||
|
||||
/* Template editor */
|
||||
dialog->editor = gimp_template_editor_new ();
|
||||
dialog->editor = gimp_template_editor_new (gimp, TRUE);
|
||||
gtk_box_pack_start (GTK_BOX (main_vbox), dialog->editor, FALSE, FALSE, 0);
|
||||
gtk_widget_show (dialog->editor);
|
||||
|
||||
|
|
|
@ -57,17 +57,21 @@ enum
|
|||
static void gimp_text_options_init (GimpTextOptions *options);
|
||||
static void gimp_text_options_class_init (GimpTextOptionsClass *options_class);
|
||||
|
||||
static void gimp_text_options_get_property (GObject *object,
|
||||
guint property_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void gimp_text_options_set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void gimp_text_options_get_property (GObject *object,
|
||||
guint property_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
|
||||
static void gimp_text_options_notify_font (GimpContext *context,
|
||||
GParamSpec *pspec,
|
||||
GimpText *text);
|
||||
static void gimp_text_notify_font (GimpText *text,
|
||||
GParamSpec *pspec,
|
||||
GimpContext *context);
|
||||
static void gimp_text_options_notify_font (GimpContext *context,
|
||||
GParamSpec *pspec,
|
||||
GimpText *text);
|
||||
static void gimp_text_notify_font (GimpText *text,
|
||||
GParamSpec *pspec,
|
||||
GimpContext *context);
|
||||
|
||||
|
||||
static GimpToolOptionsClass *parent_class = NULL;
|
||||
|
@ -110,12 +114,13 @@ gimp_text_options_class_init (GimpTextOptionsClass *klass)
|
|||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
object_class->set_property = gimp_text_options_set_property;
|
||||
object_class->get_property = gimp_text_options_get_property;
|
||||
|
||||
GIMP_CONFIG_INSTALL_PROP_OBJECT (object_class, PROP_TEXT,
|
||||
"text", NULL,
|
||||
GIMP_TYPE_TEXT,
|
||||
0);
|
||||
GIMP_PARAM_AGGREGATE);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -136,6 +141,23 @@ gimp_text_options_init (GimpTextOptions *options)
|
|||
options, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_text_options_set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_TEXT:
|
||||
/* do nothing */
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_text_options_get_property (GObject *object,
|
||||
guint property_id,
|
||||
|
|
|
@ -32,11 +32,14 @@
|
|||
#include "config/gimpconfig.h"
|
||||
|
||||
#include "core/gimp.h"
|
||||
#include "core/gimplist.h"
|
||||
#include "core/gimpcontext.h"
|
||||
#include "core/gimptemplate.h"
|
||||
|
||||
#include "gimptemplateeditor.h"
|
||||
#include "widgets/gimpenummenu.h"
|
||||
#include "widgets/gimppropwidgets.h"
|
||||
#include "gimpenummenu.h"
|
||||
#include "gimppropwidgets.h"
|
||||
#include "gimpviewablebutton.h"
|
||||
|
||||
#include "gimp-intl.h"
|
||||
|
||||
|
@ -54,6 +57,9 @@ static void gimp_template_editor_aspect_callback (GtkWidget *widget,
|
|||
static void gimp_template_editor_template_notify (GimpTemplate *template,
|
||||
GParamSpec *param_spec,
|
||||
GimpTemplateEditor *editor);
|
||||
static void gimp_template_editor_icon_changed (GimpContext *context,
|
||||
GimpTemplate *template,
|
||||
GimpTemplateEditor *editor);
|
||||
|
||||
|
||||
static GimpEditorClass *parent_class = NULL;
|
||||
|
@ -349,13 +355,79 @@ gimp_template_editor_finalize (GObject *object)
|
|||
editor->template = NULL;
|
||||
}
|
||||
|
||||
if (editor->stock_id_container)
|
||||
{
|
||||
g_object_unref (editor->stock_id_container);
|
||||
editor->stock_id_container = NULL;
|
||||
}
|
||||
|
||||
if (editor->stock_id_context)
|
||||
{
|
||||
g_object_unref (editor->stock_id_context);
|
||||
editor->stock_id_context = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
gimp_template_editor_new (void)
|
||||
gimp_template_editor_new (Gimp *gimp,
|
||||
gboolean edit_stock_id)
|
||||
{
|
||||
return g_object_new (GIMP_TYPE_TEMPLATE_EDITOR, NULL);
|
||||
GimpTemplateEditor *editor;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
||||
|
||||
editor = g_object_new (GIMP_TYPE_TEMPLATE_EDITOR, NULL);
|
||||
|
||||
if (edit_stock_id)
|
||||
{
|
||||
GtkWidget *table;
|
||||
GtkWidget *button;
|
||||
GSList *stock_list;
|
||||
GSList *list;
|
||||
|
||||
editor->stock_id_container = gimp_list_new (GIMP_TYPE_TEMPLATE,
|
||||
GIMP_CONTAINER_POLICY_STRONG);
|
||||
editor->stock_id_context = gimp_context_new (gimp, "foo", NULL);
|
||||
|
||||
g_signal_connect (editor->stock_id_context, "template_changed",
|
||||
G_CALLBACK (gimp_template_editor_icon_changed),
|
||||
editor);
|
||||
|
||||
stock_list = gtk_stock_list_ids ();
|
||||
|
||||
for (list = stock_list; list; list = g_slist_next (list))
|
||||
{
|
||||
GimpObject *object = g_object_new (GIMP_TYPE_TEMPLATE,
|
||||
"name", list->data,
|
||||
"stock-id", list->data,
|
||||
NULL);
|
||||
|
||||
gimp_container_add (editor->stock_id_container, object);
|
||||
g_object_unref (object);
|
||||
}
|
||||
|
||||
g_slist_foreach (stock_list, (GFunc) g_free, NULL);
|
||||
g_slist_free (stock_list);
|
||||
|
||||
table = gtk_table_new (1, 2, FALSE);
|
||||
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
|
||||
gtk_box_pack_start (GTK_BOX (editor), table, FALSE, FALSE, 0);
|
||||
gtk_box_reorder_child (GTK_BOX (editor), table, 0);
|
||||
gtk_widget_show (table);
|
||||
|
||||
button = gimp_viewable_button_new (editor->stock_id_container,
|
||||
editor->stock_id_context,
|
||||
GIMP_PREVIEW_SIZE_SMALL,
|
||||
NULL, NULL, NULL, NULL);
|
||||
|
||||
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
|
||||
_("_Icon:"), 1.0, 0.5,
|
||||
button, 1, TRUE);
|
||||
}
|
||||
|
||||
return GTK_WIDGET (editor);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -488,5 +560,29 @@ gimp_template_editor_template_notify (GimpTemplate *template,
|
|||
gimp_radio_group_set_active (GTK_RADIO_BUTTON (editor->aspect_button),
|
||||
GINT_TO_POINTER (aspect));
|
||||
editor->block_aspect = FALSE;
|
||||
|
||||
if (editor->stock_id_container)
|
||||
{
|
||||
GimpObject *object;
|
||||
const gchar *stock_id;
|
||||
|
||||
stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (editor->template));
|
||||
|
||||
object = gimp_container_get_child_by_name (editor->stock_id_container,
|
||||
stock_id);
|
||||
|
||||
gimp_context_set_template (editor->stock_id_context,
|
||||
(GimpTemplate *) object);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_template_editor_icon_changed (GimpContext *context,
|
||||
GimpTemplate *template,
|
||||
GimpTemplateEditor *editor)
|
||||
{
|
||||
g_object_set (editor->template,
|
||||
"stock-id", GIMP_OBJECT (template)->name,
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,9 @@ struct _GimpTemplateEditor
|
|||
GimpTemplate *template;
|
||||
gulong memsize;
|
||||
|
||||
GimpContainer *stock_id_container;
|
||||
GimpContext *stock_id_context;
|
||||
|
||||
GtkWidget *aspect_button;
|
||||
gboolean block_aspect;
|
||||
|
||||
|
@ -59,7 +62,8 @@ struct _GimpTemplateEditorClass
|
|||
|
||||
GType gimp_template_editor_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GtkWidget * gimp_template_editor_new (void);
|
||||
GtkWidget * gimp_template_editor_new (Gimp *gimp,
|
||||
gboolean edit_stock_id);
|
||||
|
||||
void gimp_template_editor_set_template (GimpTemplateEditor *editor,
|
||||
GimpTemplate *template);
|
||||
|
|
|
@ -301,8 +301,8 @@ gimp_config_deserialize_property (GObject *object,
|
|||
if (token == G_TOKEN_RIGHT_PAREN &&
|
||||
g_scanner_peek_next_token (scanner) == token)
|
||||
{
|
||||
if (!G_VALUE_HOLDS_OBJECT (&value) ||
|
||||
prop_spec->flags & G_PARAM_WRITABLE)
|
||||
if (! (G_VALUE_HOLDS_OBJECT (&value) &&
|
||||
(prop_spec->flags & GIMP_PARAM_AGGREGATE)))
|
||||
g_object_set_property (object, prop_spec->name, &value);
|
||||
}
|
||||
#if CONFIG_DEBUG
|
||||
|
|
|
@ -24,8 +24,9 @@
|
|||
|
||||
|
||||
#define GIMP_PARAM_SERIALIZE (1 << (0 + G_PARAM_USER_SHIFT))
|
||||
#define GIMP_PARAM_RESTART (1 << (1 + G_PARAM_USER_SHIFT))
|
||||
#define GIMP_PARAM_CONFIRM (1 << (2 + G_PARAM_USER_SHIFT))
|
||||
#define GIMP_PARAM_AGGREGATE (1 << (1 + G_PARAM_USER_SHIFT))
|
||||
#define GIMP_PARAM_RESTART (1 << (2 + G_PARAM_USER_SHIFT))
|
||||
#define GIMP_PARAM_CONFIRM (1 << (3 + G_PARAM_USER_SHIFT))
|
||||
|
||||
|
||||
#define GIMP_CONFIG_PARAM_FLAGS (G_PARAM_READWRITE | \
|
||||
|
@ -175,7 +176,7 @@ GParamSpec * gimp_param_spec_unit (const gchar *name,
|
|||
flags | GIMP_CONFIG_PARAM_FLAGS))
|
||||
|
||||
|
||||
/* object properties are _not_ writeable by default */
|
||||
/* object properties are _not_ G_PARAM_CONSTRUCT */
|
||||
|
||||
#define GIMP_CONFIG_INSTALL_PROP_OBJECT(class, id,\
|
||||
name, blurb, object_type, flags)\
|
||||
|
@ -183,7 +184,7 @@ GParamSpec * gimp_param_spec_unit (const gchar *name,
|
|||
g_param_spec_object (name, NULL, blurb,\
|
||||
object_type,\
|
||||
flags |\
|
||||
G_PARAM_READABLE | GIMP_PARAM_SERIALIZE))
|
||||
G_PARAM_READWRITE | GIMP_PARAM_SERIALIZE))
|
||||
|
||||
|
||||
#endif /* __GIMP_CONFIG_PARAMS_H__ */
|
||||
|
|
|
@ -205,8 +205,6 @@ gimp_config_serialize_property (GObject *object,
|
|||
if (! (param_spec->flags & GIMP_PARAM_SERIALIZE))
|
||||
return FALSE;
|
||||
|
||||
gimp_config_writer_open (writer, param_spec->name);
|
||||
|
||||
g_value_init (&value, param_spec->value_type);
|
||||
g_object_get_property (object, param_spec->name, &value);
|
||||
|
||||
|
@ -253,7 +251,8 @@ gimp_config_serialize_property (GObject *object,
|
|||
|
||||
if (! success)
|
||||
{
|
||||
if (G_VALUE_HOLDS_OBJECT (&value))
|
||||
if (G_VALUE_HOLDS_OBJECT (&value) &&
|
||||
(param_spec->flags & GIMP_PARAM_AGGREGATE))
|
||||
{
|
||||
GimpConfigInterface *gimp_config_iface = NULL;
|
||||
GObject *prop_object;
|
||||
|
@ -266,41 +265,49 @@ gimp_config_serialize_property (GObject *object,
|
|||
success = TRUE;
|
||||
|
||||
if (gimp_config_iface)
|
||||
success = gimp_config_iface->serialize (prop_object, writer, NULL);
|
||||
{
|
||||
gimp_config_writer_open (writer, param_spec->name);
|
||||
|
||||
success = gimp_config_iface->serialize (prop_object, writer,
|
||||
NULL);
|
||||
|
||||
if (success)
|
||||
gimp_config_writer_close (writer);
|
||||
else
|
||||
gimp_config_writer_revert (writer);
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (! G_VALUE_HOLDS_OBJECT (&value))
|
||||
{
|
||||
GString *str = g_string_new (NULL);
|
||||
|
||||
success = gimp_config_serialize_value (&value, str, TRUE);
|
||||
|
||||
if (success)
|
||||
gimp_config_writer_print (writer, str->str, str->len);
|
||||
{
|
||||
gimp_config_writer_open (writer, param_spec->name);
|
||||
gimp_config_writer_print (writer, str->str, str->len);
|
||||
gimp_config_writer_close (writer);
|
||||
}
|
||||
|
||||
g_string_free (str, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
if (success)
|
||||
{
|
||||
gimp_config_writer_close (writer);
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_config_writer_revert (writer);
|
||||
|
||||
/* don't warn for empty string properties */
|
||||
if (G_VALUE_HOLDS_STRING (&value))
|
||||
{
|
||||
success = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_warning ("couldn't serialize property %s::%s of type %s",
|
||||
g_type_name (G_TYPE_FROM_INSTANCE (object)),
|
||||
param_spec->name,
|
||||
g_type_name (param_spec->value_type));
|
||||
}
|
||||
if (! success)
|
||||
{
|
||||
/* don't warn for empty string properties */
|
||||
if (G_VALUE_HOLDS_STRING (&value))
|
||||
{
|
||||
success = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_warning ("couldn't serialize property %s::%s of type %s",
|
||||
g_type_name (G_TYPE_FROM_INSTANCE (object)),
|
||||
param_spec->name,
|
||||
g_type_name (param_spec->value_type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g_value_unset (&value);
|
||||
|
|
|
@ -179,21 +179,51 @@ gimp_config_copy_properties (GObject *src,
|
|||
for (i = 0; i < n_property_specs; i++)
|
||||
{
|
||||
GParamSpec *prop_spec;
|
||||
|
||||
|
||||
prop_spec = property_specs[i];
|
||||
|
||||
if (prop_spec->flags & G_PARAM_READABLE &&
|
||||
prop_spec->flags & G_PARAM_WRITABLE)
|
||||
{
|
||||
GValue value = { 0, };
|
||||
if (G_IS_PARAM_SPEC_OBJECT (prop_spec) &&
|
||||
(prop_spec->flags & GIMP_PARAM_AGGREGATE))
|
||||
{
|
||||
GValue src_value = { 0, };
|
||||
GValue dest_value = { 0, };
|
||||
GObject *src_object;
|
||||
GObject *dest_object;
|
||||
|
||||
g_value_init (&value, prop_spec->value_type);
|
||||
|
||||
g_object_get_property (src, prop_spec->name, &value);
|
||||
g_object_set_property (dest, prop_spec->name, &value);
|
||||
|
||||
g_value_unset (&value);
|
||||
}
|
||||
g_value_init (&src_value, prop_spec->value_type);
|
||||
g_value_init (&dest_value, prop_spec->value_type);
|
||||
|
||||
g_object_get_property (src, prop_spec->name, &src_value);
|
||||
g_object_get_property (dest, prop_spec->name, &dest_value);
|
||||
|
||||
src_object = g_value_get_object (&src_value);
|
||||
dest_object = g_value_get_object (&dest_value);
|
||||
|
||||
if (src_object && dest_object &&
|
||||
G_TYPE_FROM_INSTANCE (src_object) ==
|
||||
G_TYPE_FROM_INSTANCE (dest_object))
|
||||
{
|
||||
gimp_config_copy_properties (src_object, dest_object);
|
||||
}
|
||||
|
||||
g_value_unset (&src_value);
|
||||
g_value_unset (&dest_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
GValue value = { 0, };
|
||||
|
||||
g_value_init (&value, prop_spec->value_type);
|
||||
|
||||
g_object_get_property (src, prop_spec->name, &value);
|
||||
g_object_set_property (dest, prop_spec->name, &value);
|
||||
|
||||
g_value_unset (&value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g_free (property_specs);
|
||||
|
@ -234,30 +264,34 @@ gimp_config_reset_properties (GObject *object)
|
|||
|
||||
prop_spec = property_specs[i];
|
||||
|
||||
if (G_IS_PARAM_SPEC_OBJECT (prop_spec))
|
||||
if (prop_spec->flags & G_PARAM_WRITABLE)
|
||||
{
|
||||
if ((prop_spec->flags & GIMP_PARAM_SERIALIZE) &&
|
||||
g_type_interface_peek (g_type_class_peek (prop_spec->value_type),
|
||||
GIMP_TYPE_CONFIG_INTERFACE))
|
||||
if (G_IS_PARAM_SPEC_OBJECT (prop_spec))
|
||||
{
|
||||
if ((prop_spec->flags & GIMP_PARAM_SERIALIZE) &&
|
||||
(prop_spec->flags & GIMP_PARAM_AGGREGATE) &&
|
||||
g_type_interface_peek (g_type_class_peek (prop_spec->value_type),
|
||||
GIMP_TYPE_CONFIG_INTERFACE))
|
||||
{
|
||||
g_value_init (&value, prop_spec->value_type);
|
||||
|
||||
g_object_get_property (object, prop_spec->name, &value);
|
||||
|
||||
gimp_config_reset (g_value_get_object (&value));
|
||||
|
||||
g_value_unset (&value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g_value_init (&value, prop_spec->value_type);
|
||||
|
||||
g_object_get_property (object, prop_spec->name, &value);
|
||||
|
||||
gimp_config_reset (g_value_get_object (&value));
|
||||
g_param_value_set_default (prop_spec, &value);
|
||||
g_object_set_property (object, prop_spec->name, &value);
|
||||
|
||||
g_value_unset (&value);
|
||||
}
|
||||
}
|
||||
else if (prop_spec->flags & G_PARAM_WRITABLE)
|
||||
{
|
||||
g_value_init (&value, prop_spec->value_type);
|
||||
|
||||
g_param_value_set_default (prop_spec, &value);
|
||||
g_object_set_property (object, prop_spec->name, &value);
|
||||
|
||||
g_value_unset (&value);
|
||||
}
|
||||
}
|
||||
|
||||
g_free (property_specs);
|
||||
|
|
Loading…
Reference in New Issue