diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-03-15 03:58:54 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-03-15 03:58:54 +0300 |
commit | ee2045bd9efdbf9691f4b4ae78b39873892a7dfc (patch) | |
tree | 999a6d1fb83db5c4d0c22acca6519b2eda20c016 | |
parent | 822a1da41c31537b1f864898d5ab901c321830d5 (diff) |
Fix T86569: Save incremental doesn't update recent list
-rw-r--r-- | space_view3d_pie_menus/pie_save_open_menu.py | 90 |
1 files changed, 37 insertions, 53 deletions
diff --git a/space_view3d_pie_menus/pie_save_open_menu.py b/space_view3d_pie_menus/pie_save_open_menu.py index ff253d2f..31714699 100644 --- a/space_view3d_pie_menus/pie_save_open_menu.py +++ b/space_view3d_pie_menus/pie_save_open_menu.py @@ -41,6 +41,33 @@ class PIE_MT_SaveOpen(Menu): bl_idname = "PIE_MT_saveopen" bl_label = "Pie Save/Open" + @staticmethod + def _save_as_mainfile_calc_incremental_name(): + f_path = bpy.data.filepath + b_name = bpy.path.basename(f_path) + + if b_name and b_name.find("_") != -1: + # except in cases when there is an underscore in the name like my_file.blend + try: + str_nb = b_name.rpartition("_")[-1].rpartition(".blend")[0] + int_nb = int(str(str_nb)) + new_nb = str_nb.replace(str(int_nb), str(int_nb + 1)) + output = f_path.replace(str_nb, new_nb) + + i = 1 + while os.path.isfile(output): + str_nb = b_name.rpartition("_")[-1].rpartition(".blend")[0] + i += 1 + new_nb = str_nb.replace(str(int_nb), str(int_nb + i)) + output = f_path.replace(str_nb, new_nb) + except ValueError: + output = f_path.rpartition(".blend")[0] + "_001" + ".blend" + else: + # no underscore in the name or saving a nameless (.blend) file + output = f_path.rpartition(".blend")[0] + "_001" + ".blend" + + return output + def draw(self, context): layout = self.layout pie = layout.menu_pie() @@ -57,7 +84,16 @@ class PIE_MT_SaveOpen(Menu): # 9 - TOP - RIGHT pie.operator("wm.save_as_mainfile", text="Save As...", icon='NONE') # 1 - BOTTOM - LEFT - pie.operator("file.save_incremental", text="Incremental Save", icon='NONE') + if bpy.data.is_saved: + default_operator_contest = layout.operator_context + layout.operator_context = 'EXEC_DEFAULT' + pie.operator( + "wm.save_as_mainfile", text="Incremental Save", icon='NONE', + ).filepath = self._save_as_mainfile_calc_incremental_name() + layout.operator_context = default_operator_contest + else: + pie.box().label(text="Incremental Save (unsaved)") + # 3 - BOTTOM - RIGHT pie.menu("PIE_MT_recover", text="Recovery Menu", icon='RECOVER_LAST') @@ -109,60 +145,8 @@ class PIE_MT_fileio(Menu): box.menu("TOPBAR_MT_file_export", icon='EXPORT') -# Save Incremental -class PIE_OT_FileIncrementalSave(Operator): - bl_idname = "file.save_incremental" - bl_label = "Save Incremental" - bl_description = "Save First! then Incremental, .blend will get _001 extension" - bl_options = {"REGISTER"} - - @classmethod - def poll(cls, context): - return (bpy.data.filepath != "") - - def execute(self, context): - f_path = bpy.data.filepath - b_name = bpy.path.basename(f_path) - - if b_name and b_name.find("_") != -1: - # except in cases when there is an underscore in the name like my_file.blend - try: - str_nb = b_name.rpartition("_")[-1].rpartition(".blend")[0] - int_nb = int(str(str_nb)) - new_nb = str_nb.replace(str(int_nb), str(int_nb + 1)) - output = f_path.replace(str_nb, new_nb) - - i = 1 - while os.path.isfile(output): - str_nb = b_name.rpartition("_")[-1].rpartition(".blend")[0] - i += 1 - new_nb = str_nb.replace(str(int_nb), str(int_nb + i)) - output = f_path.replace(str_nb, new_nb) - except ValueError: - output = f_path.rpartition(".blend")[0] + "_001" + ".blend" - else: - # no underscore in the name or saving a nameless (.blend) file - output = f_path.rpartition(".blend")[0] + "_001" + ".blend" - - # fix for saving in a directory without privileges - try: - bpy.ops.wm.save_as_mainfile(filepath=output) - except: - self.report({'WARNING'}, - "File could not be saved. Check the System Console for errors") - return {'CANCELLED'} - - self.report( - {'INFO'}, "File: {0} - Created at: {1}".format( - output[len(bpy.path.abspath("//")):], - output[:len(bpy.path.abspath("//"))]), - ) - return {'FINISHED'} - - classes = ( PIE_MT_SaveOpen, - PIE_OT_FileIncrementalSave, PIE_MT_fileio, PIE_MT_recover, PIE_MT_link, |