From 81795bfb9f93e6f4962f47188e3e311404ff4ada Mon Sep 17 00:00:00 2001 From: Jehan Date: Fri, 24 Oct 2025 03:25:15 +0200 Subject: [PATCH] =?UTF-8?q?app,=20libgimp,=20pdb:=20also=20mark=20images?= =?UTF-8?q?=20returned=20by=20a=20GimpLoadProcedure=20as=20clean=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … and reset their undo stack. This is a followup to #14463 as I realized that images opened directly by a load procedure may still be dirty, first if the plug-in developers didn't think of cleaning themselves the image at the end, but even as we add some metadata which adds an undo step too. So even if the plug-in developer made a perfect job, the image would still end up dirty if it has metadata! Let's just make so that GimpLoadProcedure clean the image explicitly. Note that other types of plug-ins creating images won't have such code as we cannot anticipate every case. In fact, in some use case, maybe someone may want a plug-in to return a dirty image with undo steps! At least for load procedures, we can consider these pretty standardized, knowing we want them clean upon loading. --- app/pdb/image-cmds.c | 2 +- libgimp/gimpimage_pdb.c | 7 ++++--- libgimp/gimploadprocedure.c | 7 +++++++ pdb/groups/image.pdb | 7 ++++--- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/pdb/image-cmds.c b/app/pdb/image-cmds.c index 4270b2d4a2..9dcd1e0b48 100644 --- a/app/pdb/image-cmds.c +++ b/app/pdb/image-cmds.c @@ -4660,7 +4660,7 @@ register_image_procs (GimpPDB *pdb) "Checks if the image has unsaved changes.", "This procedure checks the specified image's dirty count to see if it needs to be saved. Note that saving the image does not automatically set the dirty count to 0, you need to call [method@Gimp.Image.clean_all] after calling a save procedure to make the image clean.\n" "\n" - "When loading an image using e.g. [func@Gimp.file_load] the image will be marked as clean, but loading an image calling directly the accurate file format procedure may return a dirty image.", + "When loading an image using e.g. [func@Gimp.file_load], or when created by a [class@Gimp.LoadProcedure], the image will be marked as clean. In other cases, it may sometimes be useful to clean programmatically created image yourself.", NULL); gimp_procedure_set_static_attribution (procedure, "Spencer Kimball & Peter Mattis", diff --git a/libgimp/gimpimage_pdb.c b/libgimp/gimpimage_pdb.c index 486a97a81a..54c5d7bfe1 100644 --- a/libgimp/gimpimage_pdb.c +++ b/libgimp/gimpimage_pdb.c @@ -2086,9 +2086,10 @@ gimp_image_clean_all (GimpImage *image) * [method@Gimp.Image.clean_all] after calling a save procedure to make * the image clean. * - * When loading an image using e.g. [func@Gimp.file_load] the image - * will be marked as clean, but loading an image calling directly the - * accurate file format procedure may return a dirty image. + * When loading an image using e.g. [func@Gimp.file_load], or when + * created by a [class@Gimp.LoadProcedure], the image will be marked as + * clean. In other cases, it may sometimes be useful to clean + * programmatically created image yourself. * * Returns: TRUE if the image has unsaved changes. **/ diff --git a/libgimp/gimploadprocedure.c b/libgimp/gimploadprocedure.c index 86bfc700ae..faf338322c 100644 --- a/libgimp/gimploadprocedure.c +++ b/libgimp/gimploadprocedure.c @@ -284,6 +284,13 @@ gimp_load_procedure_run (GimpProcedure *procedure, if (image != NULL && metadata != NULL && flags != GIMP_METADATA_LOAD_NONE) _gimp_image_metadata_load_finish (image, NULL, metadata, flags); + if (image) + { + gimp_image_clean_all (image); + gimp_image_undo_disable (image); + gimp_image_undo_enable (image); + } + /* This is debug printing to help plug-in developers figure out best * practices. */ diff --git a/pdb/groups/image.pdb b/pdb/groups/image.pdb index d5bdc02f98..3cfb564aa7 100644 --- a/pdb/groups/image.pdb +++ b/pdb/groups/image.pdb @@ -1799,9 +1799,10 @@ set the dirty count to 0, you need to call [method@Gimp.Image.clean_all] after calling a save procedure to make the image clean. -When loading an image using e.g. [func@Gimp.file_load] the image will be -marked as clean, but loading an image calling directly the accurate file -format procedure may return a dirty image. +When loading an image using e.g. [func@Gimp.file_load], or when created +by a [class@Gimp.LoadProcedure], the image will be marked as clean. +In other cases, it may sometimes be useful to clean programmatically +created image yourself. HELP &std_pdb_misc;