added context->serialize_props mask which enables specifying exactly which

2004-07-03  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpcontext.[ch]: added context->serialize_props mask
	which enables specifying exactly which properties will be
	serialized. Also fixes a bug that prevented undefined properties
	from being serialized, breaking tool_options and device status
	serialization.

	* app/core/gimptoolinfo.c (gimp_tool_info_new): make only the
	properties in the tool_info->context_props mask serializable, also
	configure/initialize tool_info->tool_options.

	* app/tools/gimp-tools.c (gimp_tools_register): removed
	tool_options initialization that is now done in
	gimp_tool_info_new().

	* app/widgets/gimpdeviceinfo.c: make only the properties in
	GIMP_DEVICE_INFO_CONTEXT_MASK serializable.

	* app/widgets/gimpdevicestatus.c: add the device table to its
	parent container again. Fixes "missing" devices.

	* app/core/gimptooloptions.c
	* app/widgets/gimpdevices.c: cleanup / code review.
This commit is contained in:
Michael Natterer 2004-07-03 20:27:28 +00:00 committed by Michael Natterer
parent 04ed4a8a0f
commit 23f6a194ac
9 changed files with 586 additions and 556 deletions

View File

@ -1,3 +1,28 @@
2004-07-03 Michael Natterer <mitch@gimp.org>
* app/core/gimpcontext.[ch]: added context->serialize_props mask
which enables specifying exactly which properties will be
serialized. Also fixes a bug that prevented undefined properties
from being serialized, breaking tool_options and device status
serialization.
* app/core/gimptoolinfo.c (gimp_tool_info_new): make only the
properties in the tool_info->context_props mask serializable, also
configure/initialize tool_info->tool_options.
* app/tools/gimp-tools.c (gimp_tools_register): removed
tool_options initialization that is now done in
gimp_tool_info_new().
* app/widgets/gimpdeviceinfo.c: make only the properties in
GIMP_DEVICE_INFO_CONTEXT_MASK serializable.
* app/widgets/gimpdevicestatus.c: add the device table to its
parent container again. Fixes "missing" devices.
* app/core/gimptooloptions.c
* app/widgets/gimpdevices.c: cleanup / code review.
2004-07-03 Michael Natterer <mitch@gimp.org>
* app/tools/gimppainttool.c (gimp_paint_tool_cursor_update): if

File diff suppressed because it is too large Load Diff

View File

@ -38,15 +38,16 @@ typedef struct _GimpContextClass GimpContextClass;
struct _GimpContext
{
GimpObject parent_instance;
GimpObject parent_instance;
Gimp *gimp;
GimpContext *parent;
GimpContext *parent;
guint32 defined_props;
guint32 serialize_props;
GimpImage *image;
GimpImage *image;
gpointer display;
GimpToolInfo *tool_info;
@ -55,7 +56,7 @@ struct _GimpContext
GimpRGB foreground;
GimpRGB background;
gdouble opacity;
gdouble opacity;
GimpLayerModeEffects paint_mode;
GimpBrush *brush;
@ -88,78 +89,88 @@ struct _GimpContextClass
GimpObjectClass parent_class;
void (* image_changed) (GimpContext *context,
GimpImage *image);
GimpImage *image);
void (* display_changed) (GimpContext *context,
gpointer display);
gpointer display);
void (* tool_changed) (GimpContext *context,
GimpToolInfo *tool_info);
GimpToolInfo *tool_info);
void (* foreground_changed) (GimpContext *context,
GimpRGB *color);
GimpRGB *color);
void (* background_changed) (GimpContext *context,
GimpRGB *color);
GimpRGB *color);
void (* opacity_changed) (GimpContext *context,
gdouble opacity);
gdouble opacity);
void (* paint_mode_changed) (GimpContext *context,
GimpLayerModeEffects paint_mode);
GimpLayerModeEffects paint_mode);
void (* brush_changed) (GimpContext *context,
GimpBrush *brush);
GimpBrush *brush);
void (* pattern_changed) (GimpContext *context,
GimpPattern *pattern);
GimpPattern *pattern);
void (* gradient_changed) (GimpContext *context,
GimpGradient *gradient);
GimpGradient *gradient);
void (* palette_changed) (GimpContext *context,
GimpPalette *palette);
GimpPalette *palette);
void (* font_changed) (GimpContext *context,
GimpFont *font);
GimpFont *font);
void (* buffer_changed) (GimpContext *context,
GimpBuffer *buffer);
GimpBuffer *buffer);
void (* imagefile_changed) (GimpContext *context,
GimpImagefile *imagefile);
GimpImagefile *imagefile);
void (* template_changed) (GimpContext *context,
GimpTemplate *template);
GimpTemplate *template);
};
GType gimp_context_get_type (void) G_GNUC_CONST;
GimpContext * gimp_context_new (Gimp *gimp,
const gchar *name,
GimpContext *template);
const gchar *name,
GimpContext *template);
const gchar * gimp_context_get_name (const GimpContext *context);
void gimp_context_set_name (GimpContext *context,
const gchar *name);
const gchar *name);
GimpContext * gimp_context_get_parent (const GimpContext *context);
void gimp_context_set_parent (GimpContext *context,
GimpContext *parent);
GimpContext *parent);
/* define / undefinine context properties
*
* the value of an undefined property will be taken from the parent context.
*/
void gimp_context_define_property (GimpContext *context,
GimpContextPropType prop,
gboolean defined);
GimpContextPropType prop,
gboolean defined);
gboolean gimp_context_property_defined (GimpContext *context,
GimpContextPropType prop);
GimpContextPropType prop);
void gimp_context_define_properties (GimpContext *context,
GimpContextPropMask props_mask,
gboolean defined);
GimpContextPropMask props_mask,
gboolean defined);
/* specify which context properties will be serialized
*/
void gimp_context_set_serialize_properties (GimpContext *context,
GimpContextPropMask props_mask);
GimpContextPropMask
gimp_context_get_serialize_properties (GimpContext *context);
/* copying context properties
*/
void gimp_context_copy_property (GimpContext *src,
GimpContext *dest,
GimpContextPropType prop);
GimpContext *dest,
GimpContextPropType prop);
void gimp_context_copy_properties (GimpContext *src,
GimpContext *dest,
GimpContextPropMask props_mask);
GimpContext *dest,
GimpContextPropMask props_mask);
/* manipulate by GType */

View File

@ -303,6 +303,19 @@ gimp_tool_info_new (Gimp *gimp,
g_object_set (tool_info->tool_options, "tool-info", tool_info, NULL);
if (tool_info->context_props)
{
gimp_context_define_properties (GIMP_CONTEXT (tool_info->tool_options),
tool_info->context_props, FALSE);
gimp_context_copy_properties (gimp_get_user_context (gimp),
GIMP_CONTEXT (tool_info->tool_options),
GIMP_CONTEXT_ALL_PROPS_MASK);
}
gimp_context_set_serialize_properties (GIMP_CONTEXT (tool_info->tool_options),
tool_info->context_props);
if (tool_info->tool_options_type != GIMP_TYPE_TOOL_OPTIONS)
{
tool_info->options_presets = gimp_list_new (tool_info->tool_options_type,

View File

@ -65,14 +65,14 @@ gimp_tool_options_get_type (void)
static const GTypeInfo info =
{
sizeof (GimpToolOptionsClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_tool_options_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpToolOptions),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_tool_options_init,
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_tool_options_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpToolOptions),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_tool_options_init,
};
type = g_type_register_static (GIMP_TYPE_CONTEXT,
@ -86,9 +86,7 @@ gimp_tool_options_get_type (void)
static void
gimp_tool_options_class_init (GimpToolOptionsClass *klass)
{
GObjectClass *object_class;
object_class = G_OBJECT_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
@ -117,9 +115,7 @@ gimp_tool_options_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
GimpToolOptions *options;
options = GIMP_TOOL_OPTIONS (object);
GimpToolOptions *options = GIMP_TOOL_OPTIONS (object);
switch (property_id)
{
@ -147,9 +143,7 @@ gimp_tool_options_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
GimpToolOptions *options;
options = GIMP_TOOL_OPTIONS (object);
GimpToolOptions *options = GIMP_TOOL_OPTIONS (object);
switch (property_id)
{
@ -230,10 +224,10 @@ gimp_tool_options_serialize (GimpToolOptions *tool_options,
GIMP_OBJECT (tool_options->tool_info)->name);
retval = gimp_config_serialize_to_file (GIMP_CONFIG (tool_options),
filename,
header, footer,
NULL,
error);
filename,
header, footer,
NULL,
error);
g_free (filename);
g_free (header);
@ -256,9 +250,9 @@ gimp_tool_options_deserialize (GimpToolOptions *tool_options,
filename = gimp_tool_options_build_filename (tool_options, extension);
retval = gimp_config_deserialize_file (GIMP_CONFIG (tool_options),
filename,
NULL,
error);
filename,
NULL,
error);
g_free (filename);

View File

@ -458,16 +458,6 @@ gimp_tools_register (GType tool_type,
g_object_set_data (G_OBJECT (tool_info), "gimp-tool-options-gui-func",
options_gui_func);
if (tool_info->context_props)
{
gimp_context_define_properties (GIMP_CONTEXT (tool_info->tool_options),
tool_info->context_props, FALSE);
gimp_context_copy_properties (gimp_get_user_context (gimp),
GIMP_CONTEXT (tool_info->tool_options),
GIMP_CONTEXT_ALL_PROPS_MASK);
}
gimp_container_add (gimp->tool_info_list, GIMP_OBJECT (tool_info));
g_object_unref (tool_info);

View File

@ -86,14 +86,14 @@ gimp_device_info_get_type (void)
static const GTypeInfo device_info_info =
{
sizeof (GimpDeviceInfoClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_device_info_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpDeviceInfo),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_device_info_init,
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_device_info_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpDeviceInfo),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_device_info_init,
};
device_info_type = g_type_register_static (GIMP_TYPE_CONTEXT,
@ -107,11 +107,9 @@ gimp_device_info_get_type (void)
static void
gimp_device_info_class_init (GimpDeviceInfoClass *klass)
{
GObjectClass *object_class;
GObjectClass *object_class = G_OBJECT_CLASS (klass);;
GParamSpec *array_spec;
object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
device_info_signals[CHANGED] =
@ -141,7 +139,6 @@ gimp_device_info_class_init (GimpDeviceInfoClass *klass)
GDK_AXIS_IGNORE,
G_PARAM_READWRITE),
GIMP_CONFIG_PARAM_FLAGS);
g_object_class_install_property (object_class, PROP_AXES, array_spec);
array_spec = g_param_spec_value_array ("keys",
@ -151,7 +148,6 @@ gimp_device_info_class_init (GimpDeviceInfoClass *klass)
NULL,
G_PARAM_READWRITE),
GIMP_CONFIG_PARAM_FLAGS);
g_object_class_install_property (object_class, PROP_KEYS, array_spec);
}
@ -187,6 +183,9 @@ gimp_device_info_constructor (GType type,
GIMP_CONTEXT (object),
GIMP_DEVICE_INFO_CONTEXT_MASK);
gimp_context_set_serialize_properties (GIMP_CONTEXT (object),
GIMP_DEVICE_INFO_CONTEXT_MASK);
/* FIXME: this is ugly and needs to be done via "notify" once
* the contexts' properties are dynamic.
*/
@ -215,9 +214,7 @@ gimp_device_info_constructor (GType type,
static void
gimp_device_info_finalize (GObject *object)
{
GimpDeviceInfo *device_info;
device_info = GIMP_DEVICE_INFO (object);
GimpDeviceInfo *device_info = GIMP_DEVICE_INFO (object);
if (device_info->axes)
g_free (device_info->axes);
@ -234,12 +231,8 @@ gimp_device_info_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
GimpDeviceInfo *device_info;
GdkDevice *device;
device_info = GIMP_DEVICE_INFO (object);
device = device_info->device;
GimpDeviceInfo *device_info = GIMP_DEVICE_INFO (object);
GdkDevice *device = device_info->device;
switch (property_id)
{
@ -252,9 +245,7 @@ gimp_device_info_set_property (GObject *object,
case PROP_AXES:
{
GValueArray *array;
array = g_value_get_boxed (value);
GValueArray *array = g_value_get_boxed (value);
if (array)
{
@ -290,9 +281,7 @@ gimp_device_info_set_property (GObject *object,
case PROP_KEYS:
{
GValueArray *array;
array = g_value_get_boxed (value);
GValueArray *array = g_value_get_boxed (value);
if (array)
{
@ -347,12 +336,8 @@ gimp_device_info_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
GimpDeviceInfo *device_info;
GdkDevice *device;
device_info = GIMP_DEVICE_INFO (object);
device = device_info->device;
GimpDeviceInfo *device_info = GIMP_DEVICE_INFO (object);
GdkDevice *device = device_info->device;
switch (property_id)
{

View File

@ -90,8 +90,7 @@ gimp_devices_init (Gimp *gimp,
GimpDeviceInfo *device_info;
device_info = gimp_device_info_new (gimp, device->name);
gimp_container_add (manager->device_info_list,
GIMP_OBJECT (device_info));
gimp_container_add (manager->device_info_list, GIMP_OBJECT (device_info));
g_object_unref (device_info);
gimp_device_info_set_from_device (device_info, device);
@ -125,9 +124,9 @@ gimp_devices_restore (Gimp *gimp)
filename = gimp_personal_rc_file ("devicerc");
if (! gimp_config_deserialize_file (GIMP_CONFIG (manager->device_info_list),
filename,
gimp,
&error))
filename,
gimp,
&error))
{
if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
g_message (error->message);
@ -147,7 +146,7 @@ gimp_devices_restore (Gimp *gimp)
user_context = gimp_get_user_context (gimp);
gimp_context_copy_properties (GIMP_CONTEXT (device_info), user_context,
GIMP_DEVICE_INFO_CONTEXT_MASK);
GIMP_DEVICE_INFO_CONTEXT_MASK);
gimp_context_set_parent (GIMP_CONTEXT (device_info), user_context);
}
@ -167,11 +166,11 @@ gimp_devices_save (Gimp *gimp)
filename = gimp_personal_rc_file ("devicerc");
if (! gimp_config_serialize_to_file (GIMP_CONFIG (manager->device_info_list),
filename,
"GIMP devicerc",
"end of devicerc",
NULL,
&error))
filename,
"GIMP devicerc",
"end of devicerc",
NULL,
&error))
{
g_message (error->message);
g_error_free (error);
@ -231,7 +230,7 @@ gimp_devices_select_device (Gimp *gimp,
user_context = gimp_get_user_context (gimp);
gimp_context_copy_properties (GIMP_CONTEXT (new_device_info), user_context,
GIMP_DEVICE_INFO_CONTEXT_MASK);
GIMP_DEVICE_INFO_CONTEXT_MASK);
gimp_context_set_parent (GIMP_CONTEXT (new_device_info), user_context);
if (manager->change_notify)

View File

@ -116,11 +116,7 @@ gimp_device_status_get_type (void)
static void
gimp_device_status_class_init (GimpDeviceStatusClass *klass)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
object_class = GTK_OBJECT_CLASS (klass);
widget_class = GTK_WIDGET_CLASS (klass);
GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
@ -145,6 +141,7 @@ gimp_device_status_init (GimpDeviceStatus *status)
status->table = gtk_table_new (status->num_devices * 3, 7, FALSE);
gtk_container_set_border_width (GTK_CONTAINER (status->table), 6);
gtk_table_set_col_spacings (GTK_TABLE (status->table), 6);
gtk_container_add (GTK_CONTAINER (status), status->table);
gtk_widget_show (status->table);
for (list = gdk_display_list_devices (display), i = 0;
@ -172,8 +169,8 @@ gimp_device_status_init (GimpDeviceStatus *status)
entry->separator = gtk_hbox_new (FALSE, 0);
gtk_table_attach (GTK_TABLE (status->table), entry->separator,
0, 7, row, row + 1,
GTK_FILL, GTK_FILL, 0, 2);
0, 7, row, row + 1,
GTK_FILL, GTK_FILL, 0, 2);
row++;
@ -378,7 +375,7 @@ gimp_device_status_update_entry (GimpDeviceInfo *device_info,
}
else
{
GimpContext *context;
GimpContext *context = GIMP_CONTEXT (device_info);
GimpRGB color;
guchar r, g, b;
gchar buf[64];
@ -392,8 +389,6 @@ gimp_device_status_update_entry (GimpDeviceInfo *device_info,
gtk_widget_show (entry->pattern);
gtk_widget_show (entry->gradient);
context = GIMP_CONTEXT (device_info);
gimp_context_get_foreground (context, &color);
gimp_rgb_get_uchar (&color, &r, &g, &b);
g_snprintf (buf, sizeof (buf), _("Foreground: %d, %d, %d"), r, g, b);