[gimp] app: make GimpFilterTool always have a container of recent settings
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: make GimpFilterTool always have a container of recent settings
- Date: Tue, 28 Mar 2017 22:00:49 +0000 (UTC)
commit da70cc74464b9bcc3b2f89b6be3b9b9ecfaa0603
Author: Michael Natterer <mitch gimp org>
Date: Tue Mar 28 23:58:52 2017 +0200
app: make GimpFilterTool always have a container of recent settings
and a GimpSettingsBox. This brings savable settings to all ops, also
the automatic ones in the GEGL tool. It also makes the code cleaner
and more general.
app/tools/gimpfilteroptions.c | 2 +-
app/tools/gimpfiltertool-settings.c | 34 +++++-------
app/tools/gimpfiltertool.c | 103 ++++++++++++++++++++++++++++-------
app/tools/gimpfiltertool.h | 6 ++-
app/tools/gimpoperationtool.c | 4 +-
5 files changed, 105 insertions(+), 44 deletions(-)
---
diff --git a/app/tools/gimpfilteroptions.c b/app/tools/gimpfilteroptions.c
index 95e025f..b0bca5b 100644
--- a/app/tools/gimpfilteroptions.c
+++ b/app/tools/gimpfilteroptions.c
@@ -78,7 +78,7 @@ gimp_filter_options_class_init (GimpFilterOptionsClass *klass)
g_object_class_install_property (object_class, PROP_PREVIEW_SPLIT,
g_param_spec_boolean ("preview-split",
- _("_Split view"),
+ _("Split _view"),
NULL,
FALSE,
GIMP_PARAM_READWRITE |
diff --git a/app/tools/gimpfiltertool-settings.c b/app/tools/gimpfiltertool-settings.c
index 39556f3..ddb999b 100644
--- a/app/tools/gimpfiltertool-settings.c
+++ b/app/tools/gimpfiltertool-settings.c
@@ -65,34 +65,20 @@ static gboolean gimp_filter_tool_settings_export (GimpSettingsBox *box,
GtkWidget *
gimp_filter_tool_get_settings_box (GimpFilterTool *filter_tool)
{
- GimpToolInfo *tool_info = GIMP_TOOL (filter_tool)->tool_info;
- GType type = G_TYPE_FROM_INSTANCE (filter_tool->config);
- GimpContainer *settings;
- GFile *default_folder;
- GtkWidget *box;
-
- settings =
- gimp_operation_config_get_container (tool_info->gimp,
- type,
- (GCompareFunc) gimp_settings_compare);
-
- if (filter_tool->settings_folder)
- default_folder = gimp_directory_file (filter_tool->settings_folder, NULL);
- else
- default_folder = NULL;
+ GimpToolInfo *tool_info = GIMP_TOOL (filter_tool)->tool_info;
+ GtkWidget *box;
+ GtkWidget *label;
+ GtkWidget *combo;
box = gimp_settings_box_new (tool_info->gimp,
filter_tool->config,
- settings,
+ filter_tool->settings,
filter_tool->import_dialog_title,
filter_tool->export_dialog_title,
filter_tool->help_id,
- default_folder,
+ filter_tool->settings_folder,
NULL);
- if (default_folder)
- g_object_unref (default_folder);
-
g_signal_connect (box, "import",
G_CALLBACK (gimp_filter_tool_settings_import),
filter_tool);
@@ -101,6 +87,14 @@ gimp_filter_tool_get_settings_box (GimpFilterTool *filter_tool)
G_CALLBACK (gimp_filter_tool_settings_export),
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);
+ gtk_widget_show (label);
+
+ combo = gimp_settings_box_get_combo (GIMP_SETTINGS_BOX (box));
+ gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
+
return box;
}
diff --git a/app/tools/gimpfiltertool.c b/app/tools/gimpfiltertool.c
index 422c43e..0c17a2a 100644
--- a/app/tools/gimpfiltertool.c
+++ b/app/tools/gimpfiltertool.c
@@ -234,6 +234,12 @@ gimp_filter_tool_finalize (GObject *object)
filter_tool->default_config = NULL;
}
+ if (filter_tool->settings)
+ {
+ g_object_unref (filter_tool->settings);
+ filter_tool->settings = NULL;
+ }
+
if (filter_tool->title)
{
g_free (filter_tool->title);
@@ -266,7 +272,7 @@ gimp_filter_tool_finalize (GObject *object)
if (filter_tool->settings_folder)
{
- g_free (filter_tool->settings_folder);
+ g_object_unref (filter_tool->settings_folder);
filter_tool->settings_folder = NULL;
}
@@ -384,27 +390,15 @@ gimp_filter_tool_initialize (GimpTool *tool,
G_CALLBACK (gimp_filter_tool_response),
G_OBJECT (filter_tool), 0);
- if (filter_tool->config && filter_tool->has_settings)
+ if (filter_tool->config)
{
- GtkWidget *label;
- GtkWidget *combo;
-
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
- gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
- gtk_widget_show (hbox);
-
- label = gtk_label_new_with_mnemonic (_("Pre_sets:"));
- gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
- gtk_widget_show (label);
-
filter_tool->settings_box =
gimp_filter_tool_get_settings_box (filter_tool);
- gtk_box_pack_start (GTK_BOX (hbox), filter_tool->settings_box,
- TRUE, TRUE, 0);
- gtk_widget_show (filter_tool->settings_box);
+ gtk_box_pack_start (GTK_BOX (vbox), filter_tool->settings_box,
+ FALSE, FALSE, 0);
- combo = gimp_settings_box_get_combo (GIMP_SETTINGS_BOX (filter_tool->settings_box));
- gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
+ if (filter_tool->has_settings)
+ gtk_widget_show (filter_tool->settings_box);
}
/* The preview and split view toggles */
@@ -902,7 +896,7 @@ gimp_filter_tool_commit (GimpFilterTool *filter_tool)
gimp_image_flush (gimp_display_get_image (tool->display));
- if (filter_tool->config && filter_tool->settings_box)
+ if (filter_tool->config && filter_tool->has_settings)
{
GimpGuiConfig *config = GIMP_GUI_CONFIG (tool->tool_info->gimp->config);
@@ -1186,6 +1180,7 @@ gimp_filter_tool_get_operation (GimpFilterTool *filter_tool)
GimpFilterToolClass *klass;
GimpToolInfo *tool_info;
gchar *operation_name;
+ gchar *settings_folder = NULL;
g_return_if_fail (GIMP_IS_FILTER_TOOL (filter_tool));
@@ -1222,6 +1217,12 @@ gimp_filter_tool_get_operation (GimpFilterTool *filter_tool)
filter_tool->default_config = NULL;
}
+ if (filter_tool->settings)
+ {
+ g_object_unref (filter_tool->settings);
+ filter_tool->settings = NULL;
+ }
+
if (filter_tool->title)
{
g_free (filter_tool->title);
@@ -1254,7 +1255,7 @@ gimp_filter_tool_get_operation (GimpFilterTool *filter_tool)
if (filter_tool->settings_folder)
{
- g_free (filter_tool->settings_folder);
+ g_object_unref (filter_tool->settings_folder);
filter_tool->settings_folder = NULL;
}
@@ -1277,7 +1278,7 @@ gimp_filter_tool_get_operation (GimpFilterTool *filter_tool)
&filter_tool->icon_name,
&filter_tool->help_id,
&filter_tool->has_settings,
- &filter_tool->settings_folder,
+ &settings_folder,
&filter_tool->import_dialog_title,
&filter_tool->export_dialog_title);
@@ -1300,9 +1301,17 @@ gimp_filter_tool_get_operation (GimpFilterTool *filter_tool)
if (! filter_tool->help_id)
filter_tool->help_id = g_strdup (tool_info->help_id);
+ if (settings_folder)
+ {
+ filter_tool->settings_folder = gimp_directory_file (settings_folder,
+ NULL);
+ g_free (settings_folder);
+ }
+
filter_tool->operation = gegl_node_new_child (NULL,
"operation", operation_name,
NULL);
+
filter_tool->config =
G_OBJECT (gimp_operation_config_new (tool_info->gimp,
operation_name,
@@ -1314,6 +1323,12 @@ gimp_filter_tool_get_operation (GimpFilterTool *filter_tool)
gimp_operation_config_connect_node (GIMP_OBJECT (filter_tool->config),
filter_tool->operation);
+ filter_tool->settings =
+ gimp_operation_config_get_container (tool_info->gimp,
+ G_TYPE_FROM_INSTANCE (filter_tool->config),
+ (GCompareFunc) gimp_settings_compare);
+ g_object_ref (filter_tool->settings);
+
if (filter_tool->gui)
{
gimp_tool_gui_set_title (filter_tool->gui, filter_tool->title);
@@ -1322,6 +1337,9 @@ gimp_filter_tool_get_operation (GimpFilterTool *filter_tool)
gimp_tool_gui_set_help_id (filter_tool->gui, filter_tool->help_id);
}
+ gimp_filter_tool_set_has_settings (filter_tool,
+ filter_tool->has_settings);
+
if (gegl_operation_get_key (operation_name, "position-dependent"))
{
if (filter_tool->gui)
@@ -1352,6 +1370,49 @@ gimp_filter_tool_get_operation (GimpFilterTool *filter_tool)
gimp_filter_tool_create_filter (filter_tool);
}
+/* this function should better not exist, but we determine whether an
+ * op has settings by checking if gimp_prop_gui_new() returns a
+ * GtkLabel, which happens after get_operation() is called.
+ */
+void
+gimp_filter_tool_set_has_settings (GimpFilterTool *filter_tool,
+ gboolean has_settings)
+{
+ g_return_if_fail (GIMP_IS_FILTER_TOOL (filter_tool));
+
+ filter_tool->has_settings = has_settings;
+
+ if (filter_tool->settings_box)
+ {
+ if (filter_tool->has_settings)
+ {
+ g_object_set (filter_tool->settings_box,
+ "visible", TRUE,
+ "config", filter_tool->config,
+ "container", filter_tool->settings,
+ "help-id", filter_tool->help_id,
+ "import-title", filter_tool->import_dialog_title,
+ "export-title", filter_tool->export_dialog_title,
+ "default-folder", filter_tool->settings_folder,
+ "last-file", NULL,
+ NULL);
+ }
+ else
+ {
+ g_object_set (filter_tool->settings_box,
+ "visible", FALSE,
+ "config", NULL,
+ "container", NULL,
+ "help-id", NULL,
+ "import-title", NULL,
+ "export-title", NULL,
+ "default-folder", NULL,
+ "last-file", NULL,
+ NULL);
+ }
+ }
+}
+
void
gimp_filter_tool_edit_as (GimpFilterTool *filter_tool,
const gchar *new_tool_id,
diff --git a/app/tools/gimpfiltertool.h b/app/tools/gimpfiltertool.h
index 239e134..a4302d1 100644
--- a/app/tools/gimpfiltertool.h
+++ b/app/tools/gimpfiltertool.h
@@ -43,6 +43,7 @@ struct _GimpFilterTool
GeglNode *operation;
GObject *config;
GObject *default_config;
+ GimpContainer *settings;
gchar *title;
gchar *description;
@@ -51,7 +52,7 @@ struct _GimpFilterTool
gchar *help_id;
gboolean has_settings;
- gchar *settings_folder;
+ GFile *settings_folder;
gchar *import_dialog_title;
gchar *export_dialog_title;
@@ -105,6 +106,9 @@ GType gimp_filter_tool_get_type (void) G_GNUC_CONST;
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_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 690e739..e087028 100644
--- a/app/tools/gimpoperationtool.c
+++ b/app/tools/gimpoperationtool.c
@@ -711,7 +711,9 @@ gimp_operation_tool_set_operation (GimpOperationTool *tool,
(GimpCreatePickerFunc) gimp_filter_tool_add_color_picker,
tool);
- filter_tool->has_settings = ! GTK_IS_LABEL (tool->options_gui); /* HACK */
+ /* ugly, see comment in the function */
+ gimp_filter_tool_set_has_settings (filter_tool,
+ ! GTK_IS_LABEL (tool->options_gui));
if (tool->options_box)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]