From 569b262e2ddb2e8cf89bd08e92eb40e3533a3741 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Mon, 23 Jan 2012 22:40:49 +0100 Subject: [PATCH] app: various tool options and tool preset fixes - move the code that sets the tool options' "defined" and "serialize" properties from GimpToolInto to GimpToolOptions so they are always set correctly. - make GimpToolOptions fix broken serialized NULL tools automatically. - make sure a GimpToolPreset's tool options always has a tool set. If all fails, set a NULL tool explicitly and let the logic in GimpToolOptions find the right tool. - set GimpToolPreset's "use" booleans to FALSE for context properties that have no effect on the tool. - set GimpToolPresetEditor's toggle insensitive for these properties. --- app/core/gimptoolinfo.c | 9 --- app/core/gimptooloptions.c | 17 +++-- app/core/gimptoolpreset.c | 100 ++++++++++++++++++++++++----- app/widgets/gimptoolpreseteditor.c | 86 ++++++++++++++++++------- 4 files changed, 159 insertions(+), 53 deletions(-) diff --git a/app/core/gimptoolinfo.c b/app/core/gimptoolinfo.c index 013d82ede3..57dc6659f9 100644 --- a/app/core/gimptoolinfo.c +++ b/app/core/gimptoolinfo.c @@ -292,15 +292,6 @@ gimp_tool_info_new (Gimp *gimp, "tool", tool_info, "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_set_serialize_properties (GIMP_CONTEXT (tool_info->tool_options), - tool_info->context_props); - if (tool_info->tool_options_type != GIMP_TYPE_TOOL_OPTIONS) { GimpContainer *presets; diff --git a/app/core/gimptooloptions.c b/app/core/gimptooloptions.c index b8981d7188..21ef6b2708 100644 --- a/app/core/gimptooloptions.c +++ b/app/core/gimptooloptions.c @@ -137,7 +137,7 @@ gimp_tool_options_check_tool_info (GimpToolOptions *options, GimpToolInfo *tool_info, gboolean warn) { - if (G_OBJECT_TYPE (options) == tool_info->tool_options_type) + if (tool_info && G_OBJECT_TYPE (options) == tool_info->tool_options_type) { return tool_info; } @@ -145,7 +145,7 @@ gimp_tool_options_check_tool_info (GimpToolOptions *options, { GList *list; - for (list = gimp_get_tool_info_iter (tool_info->gimp); + for (list = gimp_get_tool_info_iter (GIMP_CONTEXT (options)->gimp); list; list = g_list_next (list)) { @@ -157,7 +157,7 @@ gimp_tool_options_check_tool_info (GimpToolOptions *options, g_printerr ("%s: correcting bogus deserialized tool " "type '%s' with right type '%s'\n", g_type_name (G_OBJECT_TYPE (options)), - gimp_object_get_name (tool_info), + tool_info ? gimp_object_get_name (tool_info) : "NULL", gimp_object_get_name (new_info)); return new_info; @@ -205,7 +205,16 @@ gimp_tool_options_set_property (GObject *object, tool_info = gimp_tool_options_check_tool_info (options, tool_info, TRUE); if (! options->tool_info) - options->tool_info = g_value_dup_object (value); + { + options->tool_info = g_object_ref (tool_info); + + if (tool_info->context_props) + gimp_context_define_properties (GIMP_CONTEXT (options), + tool_info->context_props, FALSE); + + gimp_context_set_serialize_properties (GIMP_CONTEXT (options), + tool_info->context_props); + } } break; diff --git a/app/core/gimptoolpreset.c b/app/core/gimptoolpreset.c index a4a248b28f..650a479036 100644 --- a/app/core/gimptoolpreset.c +++ b/app/core/gimptoolpreset.c @@ -335,9 +335,10 @@ gimp_tool_preset_deserialize_property (GimpConfig *config, { case PROP_TOOL_OPTIONS: { - GObject *options; - gchar *type_name; - GType type; + GObject *options; + gchar *type_name; + GType type; + GimpContextPropMask serialize_props; if (! gimp_scanner_parse_string (scanner, &type_name)) { @@ -381,10 +382,37 @@ gimp_tool_preset_deserialize_property (GimpConfig *config, break; } - /* this is a hack */ - g_object_set (options, - "tool-info", gimp_context_get_tool (GIMP_CONTEXT (options)), - NULL); + /* we need both tool and tool-info on the options */ + if (gimp_context_get_tool (GIMP_CONTEXT (options))) + { + g_object_set (options, + "tool-info", + gimp_context_get_tool (GIMP_CONTEXT (options)), + NULL); + } + else if (GIMP_TOOL_OPTIONS (options)->tool_info) + { + g_object_set (options, + "tool", GIMP_TOOL_OPTIONS (options)->tool_info, + NULL); + } + else + { + /* if we have none, the options set_property() logic will + * replace the NULL with its best guess + */ + g_object_set (options, + "tool", NULL, + "tool-info", NULL, + NULL); + } + + serialize_props = + gimp_context_get_serialize_properties (GIMP_CONTEXT (options)); + + gimp_context_set_serialize_properties (GIMP_CONTEXT (options), + serialize_props | + GIMP_CONTEXT_TOOL_MASK); g_value_take_object (value, options); } @@ -413,9 +441,39 @@ gimp_tool_preset_set_options (GimpToolPreset *preset, if (options) { + GimpContextPropMask serialize_props; + preset->tool_options = GIMP_TOOL_OPTIONS (gimp_config_duplicate (GIMP_CONFIG (options))); + serialize_props = + gimp_context_get_serialize_properties (GIMP_CONTEXT (preset->tool_options)); + + gimp_context_set_serialize_properties (GIMP_CONTEXT (preset->tool_options), + serialize_props | + GIMP_CONTEXT_TOOL_MASK); + + if (! (serialize_props & GIMP_CONTEXT_FOREGROUND_MASK)) + g_object_set (preset, "use-fg-bg", FALSE, NULL); + + if (! (serialize_props & GIMP_CONTEXT_BRUSH_MASK)) + g_object_set (preset, "use-brush", FALSE, NULL); + + if (! (serialize_props & GIMP_CONTEXT_DYNAMICS_MASK)) + g_object_set (preset, "use-dynamics", FALSE, NULL); + + if (! (serialize_props & GIMP_CONTEXT_GRADIENT_MASK)) + g_object_set (preset, "use-gradient", FALSE, NULL); + + if (! (serialize_props & GIMP_CONTEXT_PATTERN_MASK)) + g_object_set (preset, "use-pattern", FALSE, NULL); + + if (! (serialize_props & GIMP_CONTEXT_PALETTE_MASK)) + g_object_set (preset, "use-palette", FALSE, NULL); + + if (! (serialize_props & GIMP_CONTEXT_FONT_MASK)) + g_object_set (preset, "use-font", FALSE, NULL); + g_signal_connect (preset->tool_options, "notify", G_CALLBACK (gimp_tool_preset_options_notify), preset); @@ -461,27 +519,37 @@ gimp_tool_preset_new (GimpContext *context, GimpContextPropMask gimp_tool_preset_get_prop_mask (GimpToolPreset *preset) { - GimpContextPropMask use_props = 0; + GimpContextPropMask serialize_props; + GimpContextPropMask use_props = 0; g_return_val_if_fail (GIMP_IS_TOOL_PRESET (preset), 0); + serialize_props = + gimp_context_get_serialize_properties (GIMP_CONTEXT (preset->tool_options)); + if (preset->use_fg_bg) { - use_props |= GIMP_CONTEXT_FOREGROUND_MASK; - use_props |= GIMP_CONTEXT_BACKGROUND_MASK; + use_props |= (GIMP_CONTEXT_FOREGROUND_MASK & serialize_props); + use_props |= (GIMP_CONTEXT_BACKGROUND_MASK & serialize_props); } + if (preset->use_brush) - use_props |= GIMP_CONTEXT_BRUSH_MASK; + use_props |= (GIMP_CONTEXT_BRUSH_MASK & serialize_props); + if (preset->use_dynamics) - use_props |= GIMP_CONTEXT_DYNAMICS_MASK; + use_props |= (GIMP_CONTEXT_DYNAMICS_MASK & serialize_props); + if (preset->use_pattern) - use_props |= GIMP_CONTEXT_PATTERN_MASK; + use_props |= (GIMP_CONTEXT_PATTERN_MASK & serialize_props); + if (preset->use_palette) - use_props |= GIMP_CONTEXT_PALETTE_MASK; + use_props |= (GIMP_CONTEXT_PALETTE_MASK & serialize_props); + if (preset->use_gradient) - use_props |= GIMP_CONTEXT_GRADIENT_MASK; + use_props |= (GIMP_CONTEXT_GRADIENT_MASK & serialize_props); + if (preset->use_font) - use_props |= GIMP_CONTEXT_FONT_MASK; + use_props |= (GIMP_CONTEXT_FONT_MASK & serialize_props); return use_props; } diff --git a/app/widgets/gimptoolpreseteditor.c b/app/widgets/gimptoolpreseteditor.c index 867244c3b7..40ba34e356 100644 --- a/app/widgets/gimptoolpreseteditor.c +++ b/app/widgets/gimptoolpreseteditor.c @@ -43,6 +43,14 @@ struct _GimpToolPresetEditorPrivate GtkWidget *tool_icon; GtkWidget *tool_label; + + GtkWidget *fg_bg_toggle; + GtkWidget *brush_toggle; + GtkWidget *dynamics_toggle; + GtkWidget *gradient_toggle; + GtkWidget *pattern_toggle; + GtkWidget *palette_toggle; + GtkWidget *font_toggle; }; @@ -146,38 +154,45 @@ gimp_tool_preset_editor_constructed (GObject *object) gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); gtk_widget_show (button); - button = gimp_prop_check_button_new (G_OBJECT (preset), "use-fg-bg", - _("Apply stored FG/BG")); + button = editor->priv->fg_bg_toggle = + gimp_prop_check_button_new (G_OBJECT (preset), "use-fg-bg", + _("Apply stored FG/BG")); gtk_box_pack_start (GTK_BOX (data_editor), button, FALSE, FALSE, 0); gtk_widget_show (button); - button = gimp_prop_check_button_new (G_OBJECT (preset), "use-brush", - _("Apply stored brush")); + button = editor->priv->brush_toggle = + gimp_prop_check_button_new (G_OBJECT (preset), "use-brush", + _("Apply stored brush")); gtk_box_pack_start (GTK_BOX (data_editor), button, FALSE, FALSE, 0); gtk_widget_show (button); - button = gimp_prop_check_button_new (G_OBJECT (preset), "use-dynamics", - _("Apply stored dynamics")); + button = editor->priv->dynamics_toggle = + gimp_prop_check_button_new (G_OBJECT (preset), "use-dynamics", + _("Apply stored dynamics")); gtk_box_pack_start (GTK_BOX (data_editor), button, FALSE, FALSE, 0); gtk_widget_show (button); - button = gimp_prop_check_button_new (G_OBJECT (preset), "use-gradient", - _("Apply stored gradient")); + button = editor->priv->gradient_toggle = + gimp_prop_check_button_new (G_OBJECT (preset), "use-gradient", + _("Apply stored gradient")); gtk_box_pack_start (GTK_BOX (data_editor), button, FALSE, FALSE, 0); gtk_widget_show (button); - button = gimp_prop_check_button_new (G_OBJECT (preset), "use-pattern", - _("Apply stored pattern")); + button = editor->priv->pattern_toggle = + gimp_prop_check_button_new (G_OBJECT (preset), "use-pattern", + _("Apply stored pattern")); gtk_box_pack_start (GTK_BOX (data_editor), button, FALSE, FALSE, 0); gtk_widget_show (button); - button = gimp_prop_check_button_new (G_OBJECT (preset), "use-palette", - _("Apply stored palette")); + button = editor->priv->palette_toggle = + gimp_prop_check_button_new (G_OBJECT (preset), "use-palette", + _("Apply stored palette")); gtk_box_pack_start (GTK_BOX (data_editor), button, FALSE, FALSE, 0); gtk_widget_show (button); - button = gimp_prop_check_button_new (G_OBJECT (preset), "use-font", - _("Apply stored font")); + button = editor->priv->font_toggle = + gimp_prop_check_button_new (G_OBJECT (preset), "use-font", + _("Apply stored font")); gtk_box_pack_start (GTK_BOX (data_editor), button, FALSE, FALSE, 0); gtk_widget_show (button); @@ -249,33 +264,56 @@ gimp_tool_preset_editor_new (GimpContext *context, static void gimp_tool_preset_editor_sync_data (GimpToolPresetEditor *editor) { - GimpDataEditor *data_editor = GIMP_DATA_EDITOR (editor); - GimpToolInfo *tool_info; - const gchar *stock_id; - gchar *label; + GimpToolPresetEditorPrivate *priv = editor->priv; + GimpDataEditor *data_editor = GIMP_DATA_EDITOR (editor); + GimpToolPreset *preset; + GimpToolInfo *tool_info; + GimpContextPropMask serialize_props; + const gchar *stock_id; + gchar *label; - g_signal_handlers_block_by_func (editor->priv->tool_preset_model, + g_signal_handlers_block_by_func (priv->tool_preset_model, gimp_tool_preset_editor_notify_model, editor); gimp_config_copy (GIMP_CONFIG (data_editor->data), - GIMP_CONFIG (editor->priv->tool_preset_model), + GIMP_CONFIG (priv->tool_preset_model), GIMP_CONFIG_PARAM_SERIALIZE); - g_signal_handlers_unblock_by_func (editor->priv->tool_preset_model, + g_signal_handlers_unblock_by_func (priv->tool_preset_model, gimp_tool_preset_editor_notify_model, editor); - tool_info = editor->priv->tool_preset_model->tool_options->tool_info; + tool_info = priv->tool_preset_model->tool_options->tool_info; stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (tool_info)); label = g_strdup_printf (_("%s Preset"), tool_info->blurb); - gtk_image_set_from_stock (GTK_IMAGE (editor->priv->tool_icon), + gtk_image_set_from_stock (GTK_IMAGE (priv->tool_icon), stock_id, GTK_ICON_SIZE_MENU); - gtk_label_set_text (GTK_LABEL (editor->priv->tool_label), label); + gtk_label_set_text (GTK_LABEL (priv->tool_label), label); g_free (label); + + preset = GIMP_TOOL_PRESET (data_editor->data); + + serialize_props = + gimp_context_get_serialize_properties (GIMP_CONTEXT (preset->tool_options)); + + gtk_widget_set_sensitive (priv->fg_bg_toggle, + (serialize_props & GIMP_CONTEXT_FOREGROUND_MASK) != 0); + gtk_widget_set_sensitive (priv->brush_toggle, + (serialize_props & GIMP_CONTEXT_BRUSH_MASK) != 0); + gtk_widget_set_sensitive (priv->dynamics_toggle, + (serialize_props & GIMP_CONTEXT_DYNAMICS_MASK) != 0); + gtk_widget_set_sensitive (priv->gradient_toggle, + (serialize_props & GIMP_CONTEXT_GRADIENT_MASK) != 0); + gtk_widget_set_sensitive (priv->pattern_toggle, + (serialize_props & GIMP_CONTEXT_PATTERN_MASK) != 0); + gtk_widget_set_sensitive (priv->palette_toggle, + (serialize_props & GIMP_CONTEXT_PALETTE_MASK) != 0); + gtk_widget_set_sensitive (priv->font_toggle, + (serialize_props & GIMP_CONTEXT_FONT_MASK) != 0); } static void