app: create members of the Gimp instance earlier

Move fonts, data factories, document list, paint methods and user
context creation to gimp_init() or gimp_constructed() so that most
members are created when gimp_new() is done. This does not load any
data earlier, it just makes sure that all containers exist when
gimp_load_config() is called. It's also cleaner and less fragile,
This commit is contained in:
Michael Natterer 2016-09-13 09:47:27 +02:00
parent 631110e061
commit 314027f0c9
3 changed files with 41 additions and 19 deletions

View File

@ -252,6 +252,10 @@ gimp_init (Gimp *gimp)
gimp_object_set_static_name (GIMP_OBJECT (gimp->named_buffers),
"named buffers");
gimp_fonts_init (gimp);
gimp_data_factories_init (gimp);
gimp->tool_info_list = g_object_new (GIMP_TYPE_LIST,
"children-type", GIMP_TYPE_TOOL_INFO,
"append", TRUE,
@ -259,6 +263,8 @@ gimp_init (Gimp *gimp)
gimp_object_set_static_name (GIMP_OBJECT (gimp->tool_info_list),
"tool infos");
gimp->documents = gimp_document_list_new (gimp);
gimp->templates = gimp_list_new (GIMP_TYPE_TEMPLATE, TRUE);
gimp_object_set_static_name (GIMP_OBJECT (gimp->templates), "templates");
}
@ -272,12 +278,15 @@ gimp_constructed (GObject *object)
gimp_modules_init (gimp);
gimp_paint_init (gimp);
gimp->plug_in_manager = gimp_plug_in_manager_new (gimp);
gimp->pdb = gimp_pdb_new (gimp);
xcf_init (gimp);
gimp->documents = gimp_document_list_new (gimp);
/* create user and default context */
gimp_contexts_init (gimp);
}
static void
@ -397,11 +406,7 @@ gimp_finalize (GObject *object)
gimp_data_factories_exit (gimp);
if (gimp->fonts)
{
g_object_unref (gimp->fonts);
gimp->fonts = NULL;
}
gimp_fonts_exit (gimp);
if (gimp->named_buffers)
{
@ -563,20 +568,12 @@ gimp_real_initialize (Gimp *gimp,
status_callback (_("Initialization"), NULL, 0.0);
gimp_fonts_init (gimp);
/* create the data factories & tag cache */
gimp_data_factories_init (gimp);
gimp_paint_init (gimp);
gimp_fonts_set_config (gimp);
/* Set the last values used to default values. */
gimp->image_new_last_template =
gimp_config_duplicate (GIMP_CONFIG (gimp->config->default_image));
/* create user and default context */
gimp_contexts_init (gimp);
/* add data objects that need the user context */
gimp_data_factories_add_builtin (gimp);

View File

@ -53,11 +53,33 @@ gimp_fonts_init (Gimp *gimp)
gimp->fonts = gimp_font_list_new (72.0, 72.0);
gimp_object_set_name (GIMP_OBJECT (gimp->fonts), "fonts");
}
void
gimp_fonts_set_config (Gimp *gimp)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_signal_connect_swapped (gimp->config, "notify::font-path",
G_CALLBACK (gimp_fonts_load), gimp);
}
void
gimp_fonts_exit (Gimp *gimp)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
if (gimp->fonts)
{
g_signal_handlers_disconnect_by_func (gimp->config,
G_CALLBACK (gimp_fonts_load),
gimp);
g_object_unref (gimp->fonts);
gimp->fonts = NULL;
}
}
typedef struct
{
FcConfig *config;

View File

@ -19,10 +19,13 @@
#define __GIMP_FONTS_H__
void gimp_fonts_init (Gimp *gimp);
void gimp_fonts_load (Gimp *gimp,
GimpInitStatusFunc status_callback);
void gimp_fonts_reset (Gimp *gimp);
void gimp_fonts_init (Gimp *gimp);
void gimp_fonts_set_config (Gimp *gimp);
void gimp_fonts_exit (Gimp *gimp);
void gimp_fonts_load (Gimp *gimp,
GimpInitStatusFunc status_callback);
void gimp_fonts_reset (Gimp *gimp);
#endif /* __GIMP_FONTS_H__ */