app: add gimp_set,get_last_template() and use is from gimpimage-new.c

instead of using gimp->image_new_last_template directly.
The first call to gimp_get_last_template() will create
gimp->image_new_last_template on demand and thus make sure the first
new image is always matching what is set in preferences. All later
images will still default to the last image created in this
session. Fixes #14378.
This commit is contained in:
Michael Natterer 2025-07-05 12:42:14 +02:00
parent 2c767fdb51
commit 7eac33fba3
3 changed files with 41 additions and 7 deletions

View file

@ -540,10 +540,6 @@ gimp_real_initialize (Gimp *gimp,
status_callback (_("Initialization"), NULL, 0.0);
/* set the last values used to default values */
gimp->image_new_last_template =
gimp_config_duplicate (GIMP_CONFIG (gimp->config->default_image));
/* add data objects that need the user context */
gimp_data_factories_add_builtin (gimp);
@ -1118,6 +1114,37 @@ gimp_get_tool_info (Gimp *gimp,
return (GimpToolInfo *) info;
}
void
gimp_set_last_template (Gimp *gimp,
GimpTemplate *template)
{
GimpTemplate *last_template;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (GIMP_IS_TEMPLATE (template));
last_template = gimp_get_last_template (gimp);
gimp_config_sync (G_OBJECT (template),
G_OBJECT (last_template), 0);
}
GimpTemplate *
gimp_get_last_template (Gimp *gimp)
{
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
if (! gimp->image_new_last_template)
{
/* set the last values used to default values */
gimp->image_new_last_template =
gimp_config_duplicate (GIMP_CONFIG (gimp->config->default_image));
}
return gimp->image_new_last_template;
}
/**
* gimp_message:
* @gimp: a pointer to the %Gimp object

View file

@ -225,6 +225,10 @@ GimpContext * gimp_get_user_context (Gimp *gimp);
GimpToolInfo * gimp_get_tool_info (Gimp *gimp,
const gchar *tool_name);
void gimp_set_last_template (Gimp *gimp,
GimpTemplate *_template);
GimpTemplate * gimp_get_last_template (Gimp *gimp);
void gimp_message (Gimp *gimp,
GObject *handler,
GimpMessageSeverity severity,

View file

@ -87,7 +87,11 @@ gimp_image_new_get_last_template (Gimp *gimp,
}
else
{
gimp_config_sync (G_OBJECT (gimp->image_new_last_template),
GimpTemplate *last_template;
last_template = gimp_get_last_template (gimp);
gimp_config_sync (G_OBJECT (last_template),
G_OBJECT (template), 0);
}
@ -101,8 +105,7 @@ gimp_image_new_set_last_template (Gimp *gimp,
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (GIMP_IS_TEMPLATE (template));
gimp_config_sync (G_OBJECT (template),
G_OBJECT (gimp->image_new_last_template), 0);
gimp_set_last_template (gimp, template);
}
GimpImage *