[Bf-extensions-cvs] [3c6a16fc] master: Amaranth: Add check for unsaved images in Save/Reload operator

Pablo Vazquez noreply at git.blender.org
Sun Jul 24 05:12:30 CEST 2022


Commit: 3c6a16fcbe5eeff525a83779a896b275bc410fbe
Author: Pablo Vazquez
Date:   Sun Jul 24 05:08:50 2022 +0200
Branches: master
https://developer.blender.org/rBA3c6a16fcbe5eeff525a83779a896b275bc410fbe

Amaranth: Add check for unsaved images in Save/Reload operator

The regular Save operator does not automatically save changes in images,
users become aware of this when quitting Blender or changing files.

This became a problem for the Save/Reload operator since you'd lose work
without noticing it. This commit adds a check and let the user now in the
terminal which image files have not been saved.

Fixes T73905

===================================================================

M	amaranth/__init__.py
M	amaranth/scene/save_reload.py

===================================================================

diff --git a/amaranth/__init__.py b/amaranth/__init__.py
index 70606999..b7e59e13 100644
--- a/amaranth/__init__.py
+++ b/amaranth/__init__.py
@@ -74,7 +74,7 @@ from amaranth.misc import (
 bl_info = {
     "name": "Amaranth Toolset",
     "author": "Pablo Vazquez, Bassam Kurdali, Sergey Sharybin, Lukas Tönne, Cesar Saez, CansecoGPC",
-    "version": (1, 0, 12,
+    "version": (1, 0, 13),
     "blender": (3, 2, 0),
     "location": "Everywhere!",
     "description": "A collection of tools and settings to improve productivity",
diff --git a/amaranth/scene/save_reload.py b/amaranth/scene/save_reload.py
index f3bedb5e..ece61246 100644
--- a/amaranth/scene/save_reload.py
+++ b/amaranth/scene/save_reload.py
@@ -13,6 +13,23 @@ import bpy
 
 KEYMAPS = list()
 
+def check_for_unsaved_images(self):
+    im_unsaved = []
+
+    for im in bpy.data.images:
+        if im.is_dirty:
+            im_unsaved.append(im.name)
+
+    if im_unsaved:
+        report_text = 'There are unsaved changes in {0} image(s), check console for details.'\
+                        .format(len(im_unsaved))
+        self.report({"WARNING"}, report_text)
+
+        print("\nAmaranth found unsaved images when trying to save and reload.")
+        for im in im_unsaved:
+            print('* Image: "' + im + '" has unsaved changes.')
+        return True
+    return
 
 class AMTH_WM_OT_save_reload(bpy.types.Operator):
     """Save and Reload the current blend file"""
@@ -23,6 +40,10 @@ class AMTH_WM_OT_save_reload(bpy.types.Operator):
         if not path:
             bpy.ops.wm.save_as_mainfile("INVOKE_AREA")
             return
+
+        if check_for_unsaved_images(self):
+            return
+
         bpy.ops.wm.save_mainfile()
         self.report({"INFO"}, "Saved & Reloaded")
         bpy.ops.wm.open_mainfile("EXEC_DEFAULT", filepath=path)



More information about the Bf-extensions-cvs mailing list