[gimp/gimp-2-10] app: construct tool-options GUI lazily
- From: Ell <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gimp-2-10] app: construct tool-options GUI lazily
- Date: Thu, 27 Sep 2018 06:45:32 +0000 (UTC)
commit c9510721c52069d97b08712aa74c15f0aaf4e619
Author: Ell <ell_se yahoo com>
Date: Thu Sep 27 02:31:39 2018 -0400
app: construct tool-options GUI lazily
We currently construct the tool-options GUI for all the tools at
startup, which takes a significant amount of time. Instead,
only register the GUI construction function with the tool-options
object, using the new gimp_tools_set_tool_options_gui_func()
function, and use the registered function to construct the GUI when
actually needed.
(cherry picked from commit c1347a7f267839554e648da09dc045d5082103cb)
app/tools/gimp-tools.c | 30 ++++--------------------
app/tools/gimptooloptions-gui.c | 19 +++++++++++++++
app/tools/gimptooloptions-gui.h | 3 ++-
app/tools/tools-types.h | 2 --
app/widgets/gimpwidgets-utils.c | 52 ++++++++++++++++++++++++++++++++++++-----
app/widgets/gimpwidgets-utils.h | 3 +++
app/widgets/widgets-types.h | 2 ++
po/POTFILES.in | 2 +-
8 files changed, 77 insertions(+), 36 deletions(-)
---
diff --git a/app/tools/gimp-tools.c b/app/tools/gimp-tools.c
index 17b8d8822d..16d41de588 100644
--- a/app/tools/gimp-tools.c
+++ b/app/tools/gimp-tools.c
@@ -87,8 +87,6 @@
#include "gimpvectortool.h"
#include "gimpwarptool.h"
-#include "gimp-intl.h"
-
/* local function prototypes */
@@ -244,10 +242,7 @@ gimp_tools_exit (Gimp *gimp)
list = g_list_next (list))
{
GimpToolInfo *tool_info = list->data;
- GtkWidget *options_gui;
- options_gui = gimp_tools_get_tool_options_gui (tool_info->tool_options);
- gtk_widget_destroy (options_gui);
gimp_tools_set_tool_options_gui (tool_info->tool_options, NULL);
}
}
@@ -353,7 +348,6 @@ gimp_tools_restore (Gimp *gimp)
{
GimpToolInfo *tool_info = GIMP_TOOL_INFO (list->data);
GimpToolOptionsGUIFunc options_gui_func;
- GtkWidget *options_gui;
/* copy all context properties except those the tool actually
* uses, because the subsequent deserialize() on the tool
@@ -374,27 +368,11 @@ gimp_tools_restore (Gimp *gimp)
options_gui_func = g_object_get_data (G_OBJECT (tool_info),
"gimp-tool-options-gui-func");
- if (options_gui_func)
- {
- options_gui = (* options_gui_func) (tool_info->tool_options);
- }
- else
- {
- GtkWidget *label;
-
- options_gui = gimp_tool_options_gui (tool_info->tool_options);
-
- label = gtk_label_new (_("This tool has\nno options."));
- gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
- gimp_label_set_attributes (GTK_LABEL (label),
- PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
- -1);
- gtk_box_pack_start (GTK_BOX (options_gui), label, FALSE, FALSE, 6);
- gtk_widget_show (label);
- }
+ if (! options_gui_func)
+ options_gui_func = gimp_tool_options_empty_gui;
- gimp_tools_set_tool_options_gui (tool_info->tool_options,
- g_object_ref_sink (options_gui));
+ gimp_tools_set_tool_options_gui_func (tool_info->tool_options,
+ options_gui_func);
}
}
diff --git a/app/tools/gimptooloptions-gui.c b/app/tools/gimptooloptions-gui.c
index 3776cf22c1..7e0ef3ebd0 100644
--- a/app/tools/gimptooloptions-gui.c
+++ b/app/tools/gimptooloptions-gui.c
@@ -28,6 +28,8 @@
#include "gimptooloptions-gui.h"
+#include "gimp-intl.h"
+
/* public functions */
@@ -42,3 +44,20 @@ gimp_tool_options_gui (GimpToolOptions *tool_options)
return vbox;
}
+
+GtkWidget *
+gimp_tool_options_empty_gui (GimpToolOptions *tool_options)
+{
+ GtkWidget *vbox = gimp_tool_options_gui (tool_options);
+ GtkWidget *label;
+
+ label = gtk_label_new (_("This tool has\nno options."));
+ gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
+ gimp_label_set_attributes (GTK_LABEL (label),
+ PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
+ -1);
+ gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 6);
+ gtk_widget_show (label);
+
+ return vbox;
+}
diff --git a/app/tools/gimptooloptions-gui.h b/app/tools/gimptooloptions-gui.h
index 0867c28444..5847e92739 100644
--- a/app/tools/gimptooloptions-gui.h
+++ b/app/tools/gimptooloptions-gui.h
@@ -19,7 +19,8 @@
#define __GIMP_TOOL_OPTIONS_GUI_H__
-GtkWidget * gimp_tool_options_gui (GimpToolOptions *tool_options);
+GtkWidget * gimp_tool_options_gui (GimpToolOptions *tool_options);
+GtkWidget * gimp_tool_options_empty_gui (GimpToolOptions *tool_options);
#endif /* __GIMP_TOOL_OPTIONS_GUI_H__ */
diff --git a/app/tools/tools-types.h b/app/tools/tools-types.h
index 0e32b4b7a3..ea115ba88b 100644
--- a/app/tools/tools-types.h
+++ b/app/tools/tools-types.h
@@ -45,8 +45,6 @@ typedef struct _GimpFilterOptions GimpFilterOptions;
/* functions */
-typedef GtkWidget * (* GimpToolOptionsGUIFunc) (GimpToolOptions *tool_options);
-
typedef void (* GimpToolRegisterCallback) (GType tool_type,
GType tool_option_type,
GimpToolOptionsGUIFunc options_gui_func,
diff --git a/app/widgets/gimpwidgets-utils.c b/app/widgets/gimpwidgets-utils.c
index b7b6d296b6..53725d10e5 100644
--- a/app/widgets/gimpwidgets-utils.c
+++ b/app/widgets/gimpwidgets-utils.c
@@ -58,7 +58,8 @@
#include "gimp-intl.h"
-#define GIMP_TOOL_OPTIONS_GUI_KEY "gimp-tool-options-gui"
+#define GIMP_TOOL_OPTIONS_GUI_KEY "gimp-tool-options-gui"
+#define GIMP_TOOL_OPTIONS_GUI_FUNC_KEY "gimp-tool-options-gui-func"
/**
@@ -1565,20 +1566,59 @@ gimp_dock_with_window_new (GimpDialogFactory *factory,
GtkWidget *
gimp_tools_get_tool_options_gui (GimpToolOptions *tool_options)
{
- return g_object_get_data (G_OBJECT (tool_options),
- GIMP_TOOL_OPTIONS_GUI_KEY);
+ GtkWidget *widget;
+
+ widget = g_object_get_data (G_OBJECT (tool_options),
+ GIMP_TOOL_OPTIONS_GUI_KEY);
+
+ if (! widget)
+ {
+ GimpToolOptionsGUIFunc func;
+
+ func = g_object_get_data (G_OBJECT (tool_options),
+ GIMP_TOOL_OPTIONS_GUI_FUNC_KEY);
+
+ if (func)
+ {
+ widget = func (tool_options);
+
+ gimp_tools_set_tool_options_gui (tool_options, widget);
+ }
+ }
+
+ return widget;
}
void
-gimp_tools_set_tool_options_gui (GimpToolOptions *tool_options,
- GtkWidget *widget)
+gimp_tools_set_tool_options_gui (GimpToolOptions *tool_options,
+ GtkWidget *widget)
{
+ GtkWidget *prev_widget;
+
+ prev_widget = g_object_get_data (G_OBJECT (tool_options),
+ GIMP_TOOL_OPTIONS_GUI_KEY);
+
+ if (widget == prev_widget)
+ return;
+
+ if (prev_widget)
+ gtk_widget_destroy (prev_widget);
+
g_object_set_data_full (G_OBJECT (tool_options),
GIMP_TOOL_OPTIONS_GUI_KEY,
- widget,
+ widget ? g_object_ref_sink (widget) : NULL,
widget ? (GDestroyNotify) g_object_unref : NULL);
}
+void
+gimp_tools_set_tool_options_gui_func (GimpToolOptions *tool_options,
+ GimpToolOptionsGUIFunc func)
+{
+ g_object_set_data (G_OBJECT (tool_options),
+ GIMP_TOOL_OPTIONS_GUI_FUNC_KEY,
+ func);
+}
+
void
gimp_widget_flush_expose (GtkWidget *widget)
{
diff --git a/app/widgets/gimpwidgets-utils.h b/app/widgets/gimpwidgets-utils.h
index 157d0d5ce4..1e5c1ff221 100644
--- a/app/widgets/gimpwidgets-utils.h
+++ b/app/widgets/gimpwidgets-utils.h
@@ -105,6 +105,9 @@ GtkWidget * gimp_dock_with_window_new (GimpDialogFactory *factor
GtkWidget * gimp_tools_get_tool_options_gui (GimpToolOptions *tool_options);
void gimp_tools_set_tool_options_gui (GimpToolOptions *tool_options,
GtkWidget *widget);
+void gimp_tools_set_tool_options_gui_func
+ (GimpToolOptions *tool_options,
+ GimpToolOptionsGUIFunc func);
void gimp_widget_flush_expose (GtkWidget *widget);
diff --git a/app/widgets/widgets-types.h b/app/widgets/widgets-types.h
index 5b186ee953..fba239800d 100644
--- a/app/widgets/widgets-types.h
+++ b/app/widgets/widgets-types.h
@@ -309,5 +309,7 @@ typedef gboolean (* GimpPanedBoxDroppedFunc) (GtkWidget *source,
gint insert_index,
gpointer data);
+typedef GtkWidget * (* GimpToolOptionsGUIFunc) (GimpToolOptions *tool_options);
+
#endif /* __WIDGETS_TYPES_H__ */
diff --git a/po/POTFILES.in b/po/POTFILES.in
index b19e2083b5..1989192616 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -405,7 +405,6 @@ app/text/gimptextlayer-xcf.c
app/text/gimptextlayout.c
app/text/text-enums.c
-app/tools/gimp-tools.c
app/tools/gimpairbrushtool.c
app/tools/gimpalignoptions.c
app/tools/gimpaligntool.c
@@ -489,6 +488,7 @@ app/tools/gimptexttool.c
app/tools/gimptexttool-editor.c
app/tools/gimpthresholdtool.c
app/tools/gimptool.c
+app/tools/gimptooloptions-gui.c
app/tools/gimptransformgridoptions.c
app/tools/gimptransformgridtool.c
app/tools/gimptransformoptions.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]