mirror of https://github.com/GNOME/gimp.git
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.
This commit is contained in:
parent
d33fb0e7b8
commit
c1347a7f26
|
@ -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;
|
||||
if (! options_gui_func)
|
||||
options_gui_func = gimp_tool_options_empty_gui;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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__ */
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
||||
GtkWidget *
|
||||
|
@ -1426,20 +1427,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);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_widget_get_fully_opaque (GtkWidget *widget)
|
||||
{
|
||||
|
|
|
@ -95,6 +95,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);
|
||||
|
||||
gboolean gimp_widget_get_fully_opaque (GtkWidget *widget);
|
||||
void gimp_widget_set_fully_opaque (GtkWidget *widget,
|
||||
|
|
|
@ -310,5 +310,7 @@ typedef gboolean (* GimpPanedBoxDroppedFunc) (GtkWidget *noteboo
|
|||
gint insert_index,
|
||||
gpointer data);
|
||||
|
||||
typedef GtkWidget * (* GimpToolOptionsGUIFunc) (GimpToolOptions *tool_options);
|
||||
|
||||
|
||||
#endif /* __WIDGETS_TYPES_H__ */
|
||||
|
|
|
@ -403,7 +403,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
|
||||
|
@ -487,6 +486,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
|
||||
|
|
Loading…
Reference in New Issue