From 57ee6e13ab573c5835e050daecf121884e643efc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ny=C3=A1ri-Kov=C3=A1cs=2C=20D=C3=A1vid=20Tam=C3=A1s?= Date: Wed, 26 Oct 2022 23:30:23 +0200 Subject: [PATCH] Fix file extension issue when "Saving As..." for guillotine Original issue: #8581 1. When an image with a non-xcf format is loaded, within GIMP core it qualifies as an imported file. (See gimp_image_get_imported_file function) 2. But the guillotine plugin cannot propagate this information. It can only set the file path on the new image it creates, and it uses the file extension of the original imported file. 3. But since the filename is set by the plugin is the actual filename not imported filename, the gimpsavedialog.c module cannot differentiate it. This results in the incorrect file extension being set in the "gimp_save_dialog_set_image" function. This issue can actually be present in other plugins as well that generate new images which has to be checked. --- plug-ins/common/guillotine.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plug-ins/common/guillotine.c b/plug-ins/common/guillotine.c index fd12599fdb..ad3ad3fba6 100644 --- a/plug-ins/common/guillotine.c +++ b/plug-ins/common/guillotine.c @@ -237,6 +237,7 @@ guillotine (gint32 image_ID, GString *new_filename; gchar *fileextension; gchar *fileindex; + gchar *fileindex_with_xcf_extension; gint pos; if (new_image == -1) @@ -263,13 +264,19 @@ guillotine (gint32 image_ID, /* show the rough coordinates of the image in the title */ fileindex = g_strdup_printf (format, x, y); + /* preparation to replace original image extension with GIMP default + see issue #8581 for details */ + fileindex_with_xcf_extension = g_strdup_printf ("%s.xcf", fileindex); + g_free (fileindex); + /* get the position of the file extension - last . in filename */ fileextension = strrchr (new_filename->str, '.'); pos = fileextension - new_filename->str; /* insert the coordinates before the extension */ - g_string_insert (new_filename, pos, fileindex); - g_free (fileindex); + g_string_truncate (new_filename, pos); + g_string_insert (new_filename, pos, fileindex_with_xcf_extension); + g_free (fileindex_with_xcf_extension); gimp_image_set_filename (new_image, new_filename->str); g_string_free (new_filename, TRUE);