Sun position: remove unused prop in HDRI mode
[blender-addons.git] / space_view3d_pie_menus / pie_save_open_menu.py
blobff253d2f3db852cff5f03b287dd64307582b1191
1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
19 # <pep8 compliant>
21 bl_info = {
22 "name": "Hotkey: 'Ctrl S'",
23 "description": "Save/Open & File Menus",
24 "blender": (2, 80, 0),
25 "location": "All Editors",
26 "warning": "",
27 "doc_url": "",
28 "category": "Save Open Pie"
31 import bpy
32 from bpy.types import (
33 Menu,
34 Operator,
36 import os
39 # Pie Save/Open
40 class PIE_MT_SaveOpen(Menu):
41 bl_idname = "PIE_MT_saveopen"
42 bl_label = "Pie Save/Open"
44 def draw(self, context):
45 layout = self.layout
46 pie = layout.menu_pie()
47 # 4 - LEFT
48 pie.operator("wm.read_homefile", text="New", icon='FILE_NEW')
49 # 6 - RIGHT
50 pie.menu("PIE_MT_link", text="Link Menu", icon='LINK_BLEND')
51 # 2 - BOTTOM
52 pie.menu("PIE_MT_fileio", text="Import/Export Menu", icon='IMPORT')
53 # 8 - TOP
54 pie.operator("wm.open_mainfile", text="Open File", icon='FILE_FOLDER')
55 # 7 - TOP - LEFT
56 pie.operator("wm.save_mainfile", text="Save", icon='FILE_TICK')
57 # 9 - TOP - RIGHT
58 pie.operator("wm.save_as_mainfile", text="Save As...", icon='NONE')
59 # 1 - BOTTOM - LEFT
60 pie.operator("file.save_incremental", text="Incremental Save", icon='NONE')
61 # 3 - BOTTOM - RIGHT
62 pie.menu("PIE_MT_recover", text="Recovery Menu", icon='RECOVER_LAST')
65 class PIE_MT_link(Menu):
66 bl_idname = "PIE_MT_link"
67 bl_label = "Link"
69 def draw(self, context):
70 layout = self.layout
71 pie = layout.menu_pie()
72 box = pie.split().column()
73 box.operator("wm.link", text="Link", icon='LINK_BLEND')
74 box.operator("wm.append", text="Append", icon='APPEND_BLEND')
75 box.separator()
76 box.operator("file.autopack_toggle", text="Automatically Pack Into .blend")
77 box.operator("file.pack_all", text="Pack All Into .blend")
78 box.operator("file.unpack_all", text="Unpack All Into Files")
79 box.separator()
80 box.operator("file.make_paths_relative", text="Make All Paths Relative")
81 box.operator("file.make_paths_absolute", text="Make All Paths Absolute")
84 class PIE_MT_recover(Menu):
85 bl_idname = "PIE_MT_recover"
86 bl_label = "Recovery"
88 def draw(self, context):
89 layout = self.layout
90 pie = layout.menu_pie()
91 box = pie.split().column()
92 box.operator("wm.recover_auto_save", text="Recover Auto Save...", icon='NONE')
93 box.operator("wm.recover_last_session", text="Recover Last Session", icon='RECOVER_LAST')
94 box.operator("wm.revert_mainfile", text="Revert", icon='FILE_REFRESH')
95 box.separator()
96 box.operator("file.report_missing_files", text="Report Missing Files")
97 box.operator("file.find_missing_files", text="Find Missing Files")
99 class PIE_MT_fileio(Menu):
100 bl_idname = "PIE_MT_fileio"
101 bl_label = "Import/Export"
103 def draw(self, context):
104 layout = self.layout
105 pie = layout.menu_pie()
106 box = pie.split().column()
107 box.menu("TOPBAR_MT_file_import", icon='IMPORT')
108 box.separator()
109 box.menu("TOPBAR_MT_file_export", icon='EXPORT')
112 # Save Incremental
113 class PIE_OT_FileIncrementalSave(Operator):
114 bl_idname = "file.save_incremental"
115 bl_label = "Save Incremental"
116 bl_description = "Save First! then Incremental, .blend will get _001 extension"
117 bl_options = {"REGISTER"}
119 @classmethod
120 def poll(cls, context):
121 return (bpy.data.filepath != "")
123 def execute(self, context):
124 f_path = bpy.data.filepath
125 b_name = bpy.path.basename(f_path)
127 if b_name and b_name.find("_") != -1:
128 # except in cases when there is an underscore in the name like my_file.blend
129 try:
130 str_nb = b_name.rpartition("_")[-1].rpartition(".blend")[0]
131 int_nb = int(str(str_nb))
132 new_nb = str_nb.replace(str(int_nb), str(int_nb + 1))
133 output = f_path.replace(str_nb, new_nb)
135 i = 1
136 while os.path.isfile(output):
137 str_nb = b_name.rpartition("_")[-1].rpartition(".blend")[0]
138 i += 1
139 new_nb = str_nb.replace(str(int_nb), str(int_nb + i))
140 output = f_path.replace(str_nb, new_nb)
141 except ValueError:
142 output = f_path.rpartition(".blend")[0] + "_001" + ".blend"
143 else:
144 # no underscore in the name or saving a nameless (.blend) file
145 output = f_path.rpartition(".blend")[0] + "_001" + ".blend"
147 # fix for saving in a directory without privileges
148 try:
149 bpy.ops.wm.save_as_mainfile(filepath=output)
150 except:
151 self.report({'WARNING'},
152 "File could not be saved. Check the System Console for errors")
153 return {'CANCELLED'}
155 self.report(
156 {'INFO'}, "File: {0} - Created at: {1}".format(
157 output[len(bpy.path.abspath("//")):],
158 output[:len(bpy.path.abspath("//"))]),
160 return {'FINISHED'}
163 classes = (
164 PIE_MT_SaveOpen,
165 PIE_OT_FileIncrementalSave,
166 PIE_MT_fileio,
167 PIE_MT_recover,
168 PIE_MT_link,
171 addon_keymaps = []
174 def register():
175 for cls in classes:
176 bpy.utils.register_class(cls)
178 wm = bpy.context.window_manager
179 if wm.keyconfigs.addon:
180 # Save/Open/...
181 km = wm.keyconfigs.addon.keymaps.new(name='Window')
182 kmi = km.keymap_items.new('wm.call_menu_pie', 'S', 'PRESS', ctrl=True)
183 kmi.properties.name = "PIE_MT_saveopen"
184 addon_keymaps.append((km, kmi))
187 def unregister():
188 for cls in classes:
189 bpy.utils.unregister_class(cls)
191 wm = bpy.context.window_manager
192 kc = wm.keyconfigs.addon
193 if kc:
194 for km, kmi in addon_keymaps:
195 km.keymap_items.remove(kmi)
196 addon_keymaps.clear()
199 if __name__ == "__main__":
200 register()