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> 2004-07-03 Michael Natterer <mitch@gimp.org>
* app/tools/gimppainttool.c (gimp_paint_tool_cursor_update): if * 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 struct _GimpContext
{ {
GimpObject parent_instance; GimpObject parent_instance;
Gimp *gimp; Gimp *gimp;
GimpContext *parent; GimpContext *parent;
guint32 defined_props; guint32 defined_props;
guint32 serialize_props;
GimpImage *image; GimpImage *image;
gpointer display; gpointer display;
GimpToolInfo *tool_info; GimpToolInfo *tool_info;
@ -55,7 +56,7 @@ struct _GimpContext
GimpRGB foreground; GimpRGB foreground;
GimpRGB background; GimpRGB background;
gdouble opacity; gdouble opacity;
GimpLayerModeEffects paint_mode; GimpLayerModeEffects paint_mode;
GimpBrush *brush; GimpBrush *brush;
@ -88,78 +89,88 @@ struct _GimpContextClass
GimpObjectClass parent_class; GimpObjectClass parent_class;
void (* image_changed) (GimpContext *context, void (* image_changed) (GimpContext *context,
GimpImage *image); GimpImage *image);
void (* display_changed) (GimpContext *context, void (* display_changed) (GimpContext *context,
gpointer display); gpointer display);
void (* tool_changed) (GimpContext *context, void (* tool_changed) (GimpContext *context,
GimpToolInfo *tool_info); GimpToolInfo *tool_info);
void (* foreground_changed) (GimpContext *context, void (* foreground_changed) (GimpContext *context,
GimpRGB *color); GimpRGB *color);
void (* background_changed) (GimpContext *context, void (* background_changed) (GimpContext *context,
GimpRGB *color); GimpRGB *color);
void (* opacity_changed) (GimpContext *context, void (* opacity_changed) (GimpContext *context,
gdouble opacity); gdouble opacity);
void (* paint_mode_changed) (GimpContext *context, void (* paint_mode_changed) (GimpContext *context,
GimpLayerModeEffects paint_mode); GimpLayerModeEffects paint_mode);
void (* brush_changed) (GimpContext *context, void (* brush_changed) (GimpContext *context,
GimpBrush *brush); GimpBrush *brush);
void (* pattern_changed) (GimpContext *context, void (* pattern_changed) (GimpContext *context,
GimpPattern *pattern); GimpPattern *pattern);
void (* gradient_changed) (GimpContext *context, void (* gradient_changed) (GimpContext *context,
GimpGradient *gradient); GimpGradient *gradient);
void (* palette_changed) (GimpContext *context, void (* palette_changed) (GimpContext *context,
GimpPalette *palette); GimpPalette *palette);
void (* font_changed) (GimpContext *context, void (* font_changed) (GimpContext *context,
GimpFont *font); GimpFont *font);
void (* buffer_changed) (GimpContext *context, void (* buffer_changed) (GimpContext *context,
GimpBuffer *buffer); GimpBuffer *buffer);
void (* imagefile_changed) (GimpContext *context, void (* imagefile_changed) (GimpContext *context,
GimpImagefile *imagefile); GimpImagefile *imagefile);
void (* template_changed) (GimpContext *context, void (* template_changed) (GimpContext *context,
GimpTemplate *template); GimpTemplate *template);
}; };
GType gimp_context_get_type (void) G_GNUC_CONST; GType gimp_context_get_type (void) G_GNUC_CONST;
GimpContext * gimp_context_new (Gimp *gimp, GimpContext * gimp_context_new (Gimp *gimp,
const gchar *name, const gchar *name,
GimpContext *template); GimpContext *template);
const gchar * gimp_context_get_name (const GimpContext *context); const gchar * gimp_context_get_name (const GimpContext *context);
void gimp_context_set_name (GimpContext *context, void gimp_context_set_name (GimpContext *context,
const gchar *name); const gchar *name);
GimpContext * gimp_context_get_parent (const GimpContext *context); GimpContext * gimp_context_get_parent (const GimpContext *context);
void gimp_context_set_parent (GimpContext *context, void gimp_context_set_parent (GimpContext *context,
GimpContext *parent); GimpContext *parent);
/* define / undefinine context properties /* define / undefinine context properties
* *
* the value of an undefined property will be taken from the parent context. * the value of an undefined property will be taken from the parent context.
*/ */
void gimp_context_define_property (GimpContext *context, void gimp_context_define_property (GimpContext *context,
GimpContextPropType prop, GimpContextPropType prop,
gboolean defined); gboolean defined);
gboolean gimp_context_property_defined (GimpContext *context, gboolean gimp_context_property_defined (GimpContext *context,
GimpContextPropType prop); GimpContextPropType prop);
void gimp_context_define_properties (GimpContext *context, void gimp_context_define_properties (GimpContext *context,
GimpContextPropMask props_mask, GimpContextPropMask props_mask,
gboolean defined); 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 /* copying context properties
*/ */
void gimp_context_copy_property (GimpContext *src, void gimp_context_copy_property (GimpContext *src,
GimpContext *dest, GimpContext *dest,
GimpContextPropType prop); GimpContextPropType prop);
void gimp_context_copy_properties (GimpContext *src, void gimp_context_copy_properties (GimpContext *src,
GimpContext *dest, GimpContext *dest,
GimpContextPropMask props_mask); GimpContextPropMask props_mask);
/* manipulate by GType */ /* 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); 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) if (tool_info->tool_options_type != GIMP_TYPE_TOOL_OPTIONS)
{ {
tool_info->options_presets = gimp_list_new (tool_info->tool_options_type, 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 = static const GTypeInfo info =
{ {
sizeof (GimpToolOptionsClass), sizeof (GimpToolOptionsClass),
(GBaseInitFunc) NULL, (GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL, (GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_tool_options_class_init, (GClassInitFunc) gimp_tool_options_class_init,
NULL, /* class_finalize */ NULL, /* class_finalize */
NULL, /* class_data */ NULL, /* class_data */
sizeof (GimpToolOptions), sizeof (GimpToolOptions),
0, /* n_preallocs */ 0, /* n_preallocs */
(GInstanceInitFunc) gimp_tool_options_init, (GInstanceInitFunc) gimp_tool_options_init,
}; };
type = g_type_register_static (GIMP_TYPE_CONTEXT, type = g_type_register_static (GIMP_TYPE_CONTEXT,
@ -86,9 +86,7 @@ gimp_tool_options_get_type (void)
static void static void
gimp_tool_options_class_init (GimpToolOptionsClass *klass) gimp_tool_options_class_init (GimpToolOptionsClass *klass)
{ {
GObjectClass *object_class; GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass); parent_class = g_type_class_peek_parent (klass);
@ -117,9 +115,7 @@ gimp_tool_options_set_property (GObject *object,
const GValue *value, const GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GimpToolOptions *options; GimpToolOptions *options = GIMP_TOOL_OPTIONS (object);
options = GIMP_TOOL_OPTIONS (object);
switch (property_id) switch (property_id)
{ {
@ -147,9 +143,7 @@ gimp_tool_options_get_property (GObject *object,
GValue *value, GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GimpToolOptions *options; GimpToolOptions *options = GIMP_TOOL_OPTIONS (object);
options = GIMP_TOOL_OPTIONS (object);
switch (property_id) switch (property_id)
{ {
@ -230,10 +224,10 @@ gimp_tool_options_serialize (GimpToolOptions *tool_options,
GIMP_OBJECT (tool_options->tool_info)->name); GIMP_OBJECT (tool_options->tool_info)->name);
retval = gimp_config_serialize_to_file (GIMP_CONFIG (tool_options), retval = gimp_config_serialize_to_file (GIMP_CONFIG (tool_options),
filename, filename,
header, footer, header, footer,
NULL, NULL,
error); error);
g_free (filename); g_free (filename);
g_free (header); g_free (header);
@ -256,9 +250,9 @@ gimp_tool_options_deserialize (GimpToolOptions *tool_options,
filename = gimp_tool_options_build_filename (tool_options, extension); filename = gimp_tool_options_build_filename (tool_options, extension);
retval = gimp_config_deserialize_file (GIMP_CONFIG (tool_options), retval = gimp_config_deserialize_file (GIMP_CONFIG (tool_options),
filename, filename,
NULL, NULL,
error); error);
g_free (filename); 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", g_object_set_data (G_OBJECT (tool_info), "gimp-tool-options-gui-func",
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)); gimp_container_add (gimp->tool_info_list, GIMP_OBJECT (tool_info));
g_object_unref (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 = static const GTypeInfo device_info_info =
{ {
sizeof (GimpDeviceInfoClass), sizeof (GimpDeviceInfoClass),
(GBaseInitFunc) NULL, (GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL, (GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_device_info_class_init, (GClassInitFunc) gimp_device_info_class_init,
NULL, /* class_finalize */ NULL, /* class_finalize */
NULL, /* class_data */ NULL, /* class_data */
sizeof (GimpDeviceInfo), sizeof (GimpDeviceInfo),
0, /* n_preallocs */ 0, /* n_preallocs */
(GInstanceInitFunc) gimp_device_info_init, (GInstanceInitFunc) gimp_device_info_init,
}; };
device_info_type = g_type_register_static (GIMP_TYPE_CONTEXT, device_info_type = g_type_register_static (GIMP_TYPE_CONTEXT,
@ -107,11 +107,9 @@ gimp_device_info_get_type (void)
static void static void
gimp_device_info_class_init (GimpDeviceInfoClass *klass) gimp_device_info_class_init (GimpDeviceInfoClass *klass)
{ {
GObjectClass *object_class; GObjectClass *object_class = G_OBJECT_CLASS (klass);;
GParamSpec *array_spec; GParamSpec *array_spec;
object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass); parent_class = g_type_class_peek_parent (klass);
device_info_signals[CHANGED] = device_info_signals[CHANGED] =
@ -141,7 +139,6 @@ gimp_device_info_class_init (GimpDeviceInfoClass *klass)
GDK_AXIS_IGNORE, GDK_AXIS_IGNORE,
G_PARAM_READWRITE), G_PARAM_READWRITE),
GIMP_CONFIG_PARAM_FLAGS); GIMP_CONFIG_PARAM_FLAGS);
g_object_class_install_property (object_class, PROP_AXES, array_spec); g_object_class_install_property (object_class, PROP_AXES, array_spec);
array_spec = g_param_spec_value_array ("keys", array_spec = g_param_spec_value_array ("keys",
@ -151,7 +148,6 @@ gimp_device_info_class_init (GimpDeviceInfoClass *klass)
NULL, NULL,
G_PARAM_READWRITE), G_PARAM_READWRITE),
GIMP_CONFIG_PARAM_FLAGS); GIMP_CONFIG_PARAM_FLAGS);
g_object_class_install_property (object_class, PROP_KEYS, array_spec); 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_CONTEXT (object),
GIMP_DEVICE_INFO_CONTEXT_MASK); 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 /* FIXME: this is ugly and needs to be done via "notify" once
* the contexts' properties are dynamic. * the contexts' properties are dynamic.
*/ */
@ -215,9 +214,7 @@ gimp_device_info_constructor (GType type,
static void static void
gimp_device_info_finalize (GObject *object) gimp_device_info_finalize (GObject *object)
{ {
GimpDeviceInfo *device_info; GimpDeviceInfo *device_info = GIMP_DEVICE_INFO (object);
device_info = GIMP_DEVICE_INFO (object);
if (device_info->axes) if (device_info->axes)
g_free (device_info->axes); g_free (device_info->axes);
@ -234,12 +231,8 @@ gimp_device_info_set_property (GObject *object,
const GValue *value, const GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GimpDeviceInfo *device_info; GimpDeviceInfo *device_info = GIMP_DEVICE_INFO (object);
GdkDevice *device; GdkDevice *device = device_info->device;
device_info = GIMP_DEVICE_INFO (object);
device = device_info->device;
switch (property_id) switch (property_id)
{ {
@ -252,9 +245,7 @@ gimp_device_info_set_property (GObject *object,
case PROP_AXES: case PROP_AXES:
{ {
GValueArray *array; GValueArray *array = g_value_get_boxed (value);
array = g_value_get_boxed (value);
if (array) if (array)
{ {
@ -290,9 +281,7 @@ gimp_device_info_set_property (GObject *object,
case PROP_KEYS: case PROP_KEYS:
{ {
GValueArray *array; GValueArray *array = g_value_get_boxed (value);
array = g_value_get_boxed (value);
if (array) if (array)
{ {
@ -347,12 +336,8 @@ gimp_device_info_get_property (GObject *object,
GValue *value, GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GimpDeviceInfo *device_info; GimpDeviceInfo *device_info = GIMP_DEVICE_INFO (object);
GdkDevice *device; GdkDevice *device = device_info->device;
device_info = GIMP_DEVICE_INFO (object);
device = device_info->device;
switch (property_id) switch (property_id)
{ {

View File

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

View File

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