diff options
author | Pablo Vazquez <pablo@blender.org> | 2022-07-24 06:08:50 +0300 |
---|---|---|
committer | Pablo Vazquez <pablo@blender.org> | 2022-07-24 06:12:26 +0300 |
commit | 3c6a16fcbe5eeff525a83779a896b275bc410fbe (patch) | |
tree | f28004a151dcd12d42b881bc400db74877590e68 | |
parent | 8d609fc7e68def4f9c43bada22d930d4b257c7e6 (diff) |
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
-rw-r--r-- | amaranth/__init__.py | 2 | ||||
-rw-r--r-- | amaranth/scene/save_reload.py | 21 |
2 files changed, 22 insertions, 1 deletions
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) |