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
This commit is contained in:
parent
8d609fc7e6
commit
3c6a16fcbe
Notes:
blender-bot
2023-02-14 19:01:06 +01:00
Referenced by issue #73905, Amaranth "Save&Reload" does not save texture changes [2.82]
|
@ -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",
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue