[gimp] app: add GimpFilterTool::set_config()
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: add GimpFilterTool::set_config()
- Date: Thu, 30 Mar 2017 21:23:52 +0000 (UTC)
commit 3c0cffe53d053ce179966bd09d3bc98ba2ad988f
Author: Michael Natterer <mitch gimp org>
Date: Thu Mar 30 23:21:46 2017 +0200
app: add GimpFilterTool::set_config()
and use it to set saved settings on the tool. In GimpOperationTool's
implementation, re-sync the config's output-extent properties with the
drawable.
app/actions/gimpgeglprocedure.c | 11 +------
app/tools/gimpfiltertool-settings.c | 4 +++
app/tools/gimpfiltertool.c | 28 +++++++++++++++++++
app/tools/gimpfiltertool.h | 5 +++
app/tools/gimpoperationtool.c | 50 ++++++++++++++++++++++++----------
app/widgets/gimpsettingsbox.c | 29 ++++++++++----------
app/widgets/gimpsettingsbox.h | 2 +
7 files changed, 90 insertions(+), 39 deletions(-)
---
diff --git a/app/actions/gimpgeglprocedure.c b/app/actions/gimpgeglprocedure.c
index 237bd88..0494417 100644
--- a/app/actions/gimpgeglprocedure.c
+++ b/app/actions/gimpgeglprocedure.c
@@ -356,15 +356,8 @@ gimp_gegl_procedure_execute_async (GimpProcedure *procedure,
tool_manager_initialize_active (gimp, GIMP_DISPLAY (display));
if (settings)
- {
- GObject *tool_config = GIMP_FILTER_TOOL (active_tool)->config;
-
- gimp_config_copy (GIMP_CONFIG (settings),
- GIMP_CONFIG (tool_config), 0);
-
- /* see comment in gimp_settings_box_setting_selected() */
- g_object_set (tool_config, "time", 0, NULL);
- }
+ gimp_filter_tool_set_config (GIMP_FILTER_TOOL (active_tool),
+ GIMP_CONFIG (settings));
}
}
diff --git a/app/tools/gimpfiltertool-settings.c b/app/tools/gimpfiltertool-settings.c
index ddb999b..d6eb91a 100644
--- a/app/tools/gimpfiltertool-settings.c
+++ b/app/tools/gimpfiltertool-settings.c
@@ -87,6 +87,10 @@ gimp_filter_tool_get_settings_box (GimpFilterTool *filter_tool)
G_CALLBACK (gimp_filter_tool_settings_export),
filter_tool);
+ g_signal_connect_swapped (box, "selected",
+ G_CALLBACK (gimp_filter_tool_set_config),
+ filter_tool);
+
label = gtk_label_new_with_mnemonic (_("Pre_sets:"));
gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
gtk_box_reorder_child (GTK_BOX (box), label, 0);
diff --git a/app/tools/gimpfiltertool.c b/app/tools/gimpfiltertool.c
index 0c17a2a..014a9d5 100644
--- a/app/tools/gimpfiltertool.c
+++ b/app/tools/gimpfiltertool.c
@@ -123,6 +123,8 @@ static void gimp_filter_tool_color_picked (GimpColorTool *color_too
const GimpRGB *color);
static void gimp_filter_tool_real_reset (GimpFilterTool *filter_tool);
+static void gimp_filter_tool_real_set_config (GimpFilterTool *filter_tool,
+ GimpConfig *config);
static void gimp_filter_tool_halt (GimpFilterTool *filter_tool);
static void gimp_filter_tool_commit (GimpFilterTool *filter_tool);
@@ -183,6 +185,7 @@ gimp_filter_tool_class_init (GimpFilterToolClass *klass)
klass->get_operation = NULL;
klass->dialog = NULL;
klass->reset = gimp_filter_tool_real_reset;
+ klass->set_config = gimp_filter_tool_real_set_config;
klass->settings_import = gimp_filter_tool_real_settings_import;
klass->settings_export = gimp_filter_tool_real_settings_export;
}
@@ -849,6 +852,21 @@ gimp_filter_tool_real_reset (GimpFilterTool *filter_tool)
}
static void
+gimp_filter_tool_real_set_config (GimpFilterTool *filter_tool,
+ GimpConfig *config)
+{
+ gimp_config_copy (GIMP_CONFIG (config),
+ GIMP_CONFIG (filter_tool->config), 0);
+
+ /* reset the "time" property, otherwise explicitly storing the
+ * config as setting will also copy the time, and the stored object
+ * will be considered to be among the automatically stored recently
+ * used settings
+ */
+ g_object_set (filter_tool->config, "time", 0, NULL);
+}
+
+static void
gimp_filter_tool_halt (GimpFilterTool *filter_tool)
{
GimpTool *tool = GIMP_TOOL (filter_tool);
@@ -1414,6 +1432,16 @@ gimp_filter_tool_set_has_settings (GimpFilterTool *filter_tool,
}
void
+gimp_filter_tool_set_config (GimpFilterTool *filter_tool,
+ GimpConfig *config)
+{
+ g_return_if_fail (GIMP_IS_FILTER_TOOL (filter_tool));
+ g_return_if_fail (GIMP_IS_SETTINGS (config));
+
+ GIMP_FILTER_TOOL_GET_CLASS (filter_tool)->set_config (filter_tool, config);
+}
+
+void
gimp_filter_tool_edit_as (GimpFilterTool *filter_tool,
const gchar *new_tool_id,
GimpConfig *config)
diff --git a/app/tools/gimpfiltertool.h b/app/tools/gimpfiltertool.h
index a4302d1..a1b6eb0 100644
--- a/app/tools/gimpfiltertool.h
+++ b/app/tools/gimpfiltertool.h
@@ -85,6 +85,8 @@ struct _GimpFilterToolClass
gchar **export_dialog_title);
void (* dialog) (GimpFilterTool *filter_tool);
void (* reset) (GimpFilterTool *filter_tool);
+ void (* set_config) (GimpFilterTool *filter_tool,
+ GimpConfig *config);
gboolean (* settings_import) (GimpFilterTool *filter_tool,
GInputStream *input,
@@ -109,6 +111,9 @@ void gimp_filter_tool_get_operation (GimpFilterTool *filter_tool);
void gimp_filter_tool_set_has_settings (GimpFilterTool *filter_tool,
gboolean has_settings);
+void gimp_filter_tool_set_config (GimpFilterTool *filter_tool,
+ GimpConfig *config);
+
void gimp_filter_tool_edit_as (GimpFilterTool *filter_tool,
const gchar *new_tool_id,
GimpConfig *config);
diff --git a/app/tools/gimpoperationtool.c b/app/tools/gimpoperationtool.c
index e087028..3ed8100 100644
--- a/app/tools/gimpoperationtool.c
+++ b/app/tools/gimpoperationtool.c
@@ -90,6 +90,8 @@ static gchar * gimp_operation_tool_get_operation (GimpFilterTool *filte
gchar **export_dialog_title);
static void gimp_operation_tool_dialog (GimpFilterTool *filter_tool);
static void gimp_operation_tool_reset (GimpFilterTool *filter_tool);
+static void gimp_operation_tool_set_config (GimpFilterTool *filter_tool,
+ GimpConfig *config);
static void gimp_operation_tool_color_picked (GimpFilterTool *filter_tool,
gpointer identifier,
gdouble x,
@@ -98,7 +100,8 @@ static void gimp_operation_tool_color_picked (GimpFilterTool *filte
const GimpRGB *color);
static void gimp_operation_tool_sync_op (GimpOperationTool *op_tool,
- GimpDrawable *drawable);
+ GimpDrawable *drawable,
+ gboolean sync_colors);
static AuxInput * gimp_operation_tool_aux_input_new (GimpOperationTool *tool,
GeglNode *operation,
@@ -147,6 +150,7 @@ gimp_operation_tool_class_init (GimpOperationToolClass *klass)
filter_tool_class->get_operation = gimp_operation_tool_get_operation;
filter_tool_class->dialog = gimp_operation_tool_dialog;
filter_tool_class->reset = gimp_operation_tool_reset;
+ filter_tool_class->set_config = gimp_operation_tool_set_config;
filter_tool_class->color_picked = gimp_operation_tool_color_picked;
}
@@ -216,7 +220,7 @@ gimp_operation_tool_initialize (GimpTool *tool,
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
if (filter_tool->config)
- gimp_operation_tool_sync_op (op_tool, drawable);
+ gimp_operation_tool_sync_op (op_tool, drawable, TRUE);
return TRUE;
}
@@ -317,7 +321,19 @@ gimp_operation_tool_reset (GimpFilterTool *filter_tool)
GIMP_FILTER_TOOL_CLASS (parent_class)->reset (filter_tool);
if (filter_tool->config && GIMP_TOOL (tool)->drawable)
- gimp_operation_tool_sync_op (tool, GIMP_TOOL (tool)->drawable);
+ gimp_operation_tool_sync_op (tool, GIMP_TOOL (tool)->drawable, TRUE);
+}
+
+static void
+gimp_operation_tool_set_config (GimpFilterTool *filter_tool,
+ GimpConfig *config)
+{
+ GimpOperationTool *tool = GIMP_OPERATION_TOOL (filter_tool);
+
+ GIMP_FILTER_TOOL_CLASS (parent_class)->set_config (filter_tool, config);
+
+ if (filter_tool->config && GIMP_TOOL (tool)->drawable)
+ gimp_operation_tool_sync_op (tool, GIMP_TOOL (tool)->drawable, FALSE);
}
static void
@@ -439,7 +455,8 @@ gimp_operation_tool_color_picked (GimpFilterTool *filter_tool,
static void
gimp_operation_tool_sync_op (GimpOperationTool *op_tool,
- GimpDrawable *drawable)
+ GimpDrawable *drawable,
+ gboolean sync_colors)
{
GimpFilterTool *filter_tool = GIMP_FILTER_TOOL (op_tool);
GimpToolOptions *options = GIMP_TOOL_GET_OPTIONS (op_tool);
@@ -487,19 +504,22 @@ gimp_operation_tool_sync_op (GimpOperationTool *op_tool,
g_object_set (filter_tool->config, pspec->name, bounds_height, NULL);
}
}
- else if (HAS_KEY (pspec, "role", "color-primary"))
+ else if (sync_colors)
{
- GimpRGB color;
+ if (HAS_KEY (pspec, "role", "color-primary"))
+ {
+ GimpRGB color;
- gimp_context_get_foreground (GIMP_CONTEXT (options), &color);
- g_object_set (filter_tool->config, pspec->name, &color, NULL);
- }
- else if (HAS_KEY (pspec, "role", "color-secondary"))
- {
- GimpRGB color;
+ gimp_context_get_foreground (GIMP_CONTEXT (options), &color);
+ g_object_set (filter_tool->config, pspec->name, &color, NULL);
+ }
+ else if (sync_colors && HAS_KEY (pspec, "role", "color-secondary"))
+ {
+ GimpRGB color;
- gimp_context_get_background (GIMP_CONTEXT (options), &color);
- g_object_set (filter_tool->config, pspec->name, &color, NULL);
+ gimp_context_get_background (GIMP_CONTEXT (options), &color);
+ g_object_set (filter_tool->config, pspec->name, &color, NULL);
+ }
}
}
@@ -724,5 +744,5 @@ gimp_operation_tool_set_operation (GimpOperationTool *tool,
}
if (GIMP_TOOL (tool)->drawable)
- gimp_operation_tool_sync_op (tool, GIMP_TOOL (tool)->drawable);
+ gimp_operation_tool_sync_op (tool, GIMP_TOOL (tool)->drawable, TRUE);
}
diff --git a/app/widgets/gimpsettingsbox.c b/app/widgets/gimpsettingsbox.c
index 657395a..9ebba75 100644
--- a/app/widgets/gimpsettingsbox.c
+++ b/app/widgets/gimpsettingsbox.c
@@ -49,6 +49,7 @@ enum
FILE_DIALOG_SETUP,
IMPORT,
EXPORT,
+ SELECTED,
LAST_SIGNAL
};
@@ -187,6 +188,16 @@ gimp_settings_box_class_init (GimpSettingsBoxClass *klass)
G_TYPE_BOOLEAN, 1,
G_TYPE_FILE);
+ settings_box_signals[SELECTED] =
+ g_signal_new ("selected",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GimpSettingsBoxClass, selected),
+ NULL, NULL,
+ gimp_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1,
+ GIMP_TYPE_CONFIG);
+
object_class->constructed = gimp_settings_box_constructed;
object_class->finalize = gimp_settings_box_finalize;
object_class->set_property = gimp_settings_box_set_property;
@@ -195,6 +206,7 @@ gimp_settings_box_class_init (GimpSettingsBoxClass *klass)
klass->file_dialog_setup = NULL;
klass->import = NULL;
klass->export = NULL;
+ klass->selected = NULL;
g_object_class_install_property (object_class, PROP_GIMP,
g_param_spec_object ("gimp",
@@ -569,23 +581,10 @@ gimp_settings_box_setting_selected (GimpContainerView *view,
gpointer insert_data,
GimpSettingsBox *box)
{
- GimpSettingsBoxPrivate *private = GET_PRIVATE (box);
-
if (object)
{
- gimp_config_copy (GIMP_CONFIG (object),
- GIMP_CONFIG (private->config), 0);
-
- /* reset the "time" property, otherwise explicitly storing the
- * config as setting will also copy the time, and the stored
- * object will be considered to be among the automatically
- * stored recently used settings
- */
- if (g_object_class_find_property (G_OBJECT_GET_CLASS (private->config),
- "time"))
- {
- g_object_set (private->config, "time", 0, NULL);
- }
+ g_signal_emit (box, settings_box_signals[SELECTED], 0,
+ object);
gimp_container_view_select_item (view, NULL);
}
diff --git a/app/widgets/gimpsettingsbox.h b/app/widgets/gimpsettingsbox.h
index c6a39d6..a1860cd 100644
--- a/app/widgets/gimpsettingsbox.h
+++ b/app/widgets/gimpsettingsbox.h
@@ -49,6 +49,8 @@ struct _GimpSettingsBoxClass
GFile *file);
void (* export) (GimpSettingsBox *box,
GFile *file);
+ void (* selected) (GimpSettingsBox *box,
+ GObject *config);
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]