Import images: add file handler
[blender-addons.git] / space_view3d_pie_menus / pie_save_open_menu.py
blob1ec7b7773a7454bdec0c95ff1f293b2411c9c5b4
1 # SPDX-FileCopyrightText: 2016-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 bl_info = {
6 "name": "Hotkey: 'Ctrl S'",
7 "description": "Save/Open & File Menus",
8 "blender": (2, 80, 0),
9 "location": "All Editors",
10 "warning": "",
11 "doc_url": "",
12 "category": "Save Open Pie"
15 import bpy
16 from bpy.types import (
17 Menu,
18 Operator,
20 import os
23 # Pie Save/Open
24 class PIE_MT_SaveOpen(Menu):
25 bl_idname = "PIE_MT_saveopen"
26 bl_label = "Pie Save/Open"
28 @staticmethod
29 def _save_as_mainfile_calc_incremental_name():
30 import re
31 dirname, base_name = os.path.split(bpy.data.filepath)
32 base_name_no_ext, ext = os.path.splitext(base_name)
33 match = re.match(r"(.*)_([\d]+)$", base_name_no_ext)
34 if match:
35 prefix, number = match.groups()
36 number = int(number) + 1
37 else:
38 prefix, number = base_name_no_ext, 1
39 prefix = os.path.join(dirname, prefix)
40 while os.path.isfile(output := "%s_%03d%s" % (prefix, number, ext)):
41 number += 1
42 return output
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.menu("PIE_MT_openio", text="Open Menu", 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 if bpy.data.is_saved:
61 default_operator_contest = layout.operator_context
62 layout.operator_context = 'EXEC_DEFAULT'
63 pie.operator(
64 "wm.save_as_mainfile", text="Incremental Save", icon='NONE',
65 ).filepath = self._save_as_mainfile_calc_incremental_name()
66 layout.operator_context = default_operator_contest
67 else:
68 pie.box().label(text="Incremental Save (unsaved)")
70 # 3 - BOTTOM - RIGHT
71 pie.menu("PIE_MT_recover", text="Recovery Menu", icon='RECOVER_LAST')
74 class PIE_MT_link(Menu):
75 bl_idname = "PIE_MT_link"
76 bl_label = "Link"
78 def draw(self, context):
79 layout = self.layout
80 pie = layout.menu_pie()
81 box = pie.split().column()
82 box.operator("wm.link", text="Link", icon='LINK_BLEND')
83 box.operator("wm.append", text="Append", icon='APPEND_BLEND')
84 box.separator()
85 box.operator("file.autopack_toggle", text="Automatically Pack Into .blend")
86 box.operator("file.pack_all", text="Pack All Into .blend")
87 box.operator("file.unpack_all", text="Unpack All Into Files")
88 box.separator()
89 box.operator("file.make_paths_relative", text="Make All Paths Relative")
90 box.operator("file.make_paths_absolute", text="Make All Paths Absolute")
93 class PIE_MT_recover(Menu):
94 bl_idname = "PIE_MT_recover"
95 bl_label = "Recovery"
97 def draw(self, context):
98 layout = self.layout
99 pie = layout.menu_pie()
100 box = pie.split().column()
101 box.operator("wm.recover_auto_save", text="Recover Auto Save...", icon='NONE')
102 box.operator("wm.recover_last_session", text="Recover Last Session", icon='RECOVER_LAST')
103 box.operator("wm.revert_mainfile", text="Revert", icon='FILE_REFRESH')
104 box.separator()
105 box.operator("file.report_missing_files", text="Report Missing Files")
106 box.operator("file.find_missing_files", text="Find Missing Files")
109 class PIE_MT_fileio(Menu):
110 bl_idname = "PIE_MT_fileio"
111 bl_label = "Import/Export"
113 def draw(self, context):
114 layout = self.layout
115 pie = layout.menu_pie()
116 box = pie.split().column()
117 box.menu("TOPBAR_MT_file_import", icon='IMPORT')
118 box.separator()
119 box.menu("TOPBAR_MT_file_export", icon='EXPORT')
122 class PIE_MT_openio(Menu):
123 bl_idname = "PIE_MT_openio"
124 bl_label = "Open/Open Recent"
126 def draw(self, context):
127 layout = self.layout
128 pie = layout.menu_pie()
129 box = pie.split().column()
130 box.operator("wm.open_mainfile", text="Open File", icon='FILE_FOLDER')
131 box.separator()
132 box.menu("TOPBAR_MT_file_open_recent", icon='FILE_FOLDER')
135 classes = (
136 PIE_MT_SaveOpen,
137 PIE_MT_fileio,
138 PIE_MT_recover,
139 PIE_MT_link,
140 PIE_MT_openio,
143 addon_keymaps = []
146 def register():
147 for cls in classes:
148 bpy.utils.register_class(cls)
150 wm = bpy.context.window_manager
151 if wm.keyconfigs.addon:
152 # Save/Open/...
153 km = wm.keyconfigs.addon.keymaps.new(name='Window')
154 kmi = km.keymap_items.new('wm.call_menu_pie', 'S', 'PRESS', ctrl=True)
155 kmi.properties.name = "PIE_MT_saveopen"
156 addon_keymaps.append((km, kmi))
159 def unregister():
160 for cls in classes:
161 bpy.utils.unregister_class(cls)
163 wm = bpy.context.window_manager
164 kc = wm.keyconfigs.addon
165 if kc:
166 for km, kmi in addon_keymaps:
167 km.keymap_items.remove(kmi)
168 addon_keymaps.clear()
171 if __name__ == "__main__":
172 register()