Welcome to mirror list, hosted at ThFree Co, Russian Federation.

pie_save_open_menu.py « space_view3d_pie_menus - git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a3243fd24b0f9b9f2e38b54c31556cd743c88ab9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# SPDX-License-Identifier: GPL-2.0-or-later

bl_info = {
    "name": "Hotkey: 'Ctrl S'",
    "description": "Save/Open & File Menus",
    "blender": (2, 80, 0),
    "location": "All Editors",
    "warning": "",
    "doc_url": "",
    "category": "Save Open Pie"
    }

import bpy
from bpy.types import (
        Menu,
        Operator,
        )
import os


# Pie Save/Open
class PIE_MT_SaveOpen(Menu):
    bl_idname = "PIE_MT_saveopen"
    bl_label = "Pie Save/Open"

    @staticmethod
    def _save_as_mainfile_calc_incremental_name():
        import re
        dirname, base_name = os.path.split(bpy.data.filepath)
        base_name_no_ext, ext = os.path.splitext(base_name)
        match = re.match(r"(.*)_([\d]+)$", base_name_no_ext)
        if match:
            prefix, number = match.groups()
            number = int(number) + 1
        else:
            prefix, number = base_name_no_ext, 1
        prefix = os.path.join(dirname, prefix)
        while os.path.isfile(output := "%s_%03d%s" % (prefix, number, ext)):
            number += 1
        return output

    def draw(self, context):
        layout = self.layout
        pie = layout.menu_pie()
        # 4 - LEFT
        pie.operator("wm.read_homefile", text="New", icon='FILE_NEW')
        # 6 - RIGHT
        pie.menu("PIE_MT_link", text="Link Menu", icon='LINK_BLEND')
        # 2 - BOTTOM
        pie.menu("PIE_MT_fileio", text="Import/Export Menu", icon='IMPORT')
        # 8 - TOP
        pie.operator("wm.open_mainfile", text="Open File", icon='FILE_FOLDER')
        # 7 - TOP - LEFT
        pie.operator("wm.save_mainfile", text="Save", icon='FILE_TICK')
        # 9 - TOP - RIGHT
        pie.operator("wm.save_as_mainfile", text="Save As...", icon='NONE')
        # 1 - BOTTOM - LEFT
        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')


class PIE_MT_link(Menu):
    bl_idname = "PIE_MT_link"
    bl_label = "Link"

    def draw(self, context):
        layout = self.layout
        pie = layout.menu_pie()
        box = pie.split().column()
        box.operator("wm.link", text="Link", icon='LINK_BLEND')
        box.operator("wm.append", text="Append", icon='APPEND_BLEND')
        box.separator()
        box.operator("file.autopack_toggle", text="Automatically Pack Into .blend")
        box.operator("file.pack_all", text="Pack All Into .blend")
        box.operator("file.unpack_all", text="Unpack All Into Files")
        box.separator()
        box.operator("file.make_paths_relative", text="Make All Paths Relative")
        box.operator("file.make_paths_absolute", text="Make All Paths Absolute")


class PIE_MT_recover(Menu):
    bl_idname = "PIE_MT_recover"
    bl_label = "Recovery"

    def draw(self, context):
        layout = self.layout
        pie = layout.menu_pie()
        box = pie.split().column()
        box.operator("wm.recover_auto_save", text="Recover Auto Save...", icon='NONE')
        box.operator("wm.recover_last_session", text="Recover Last Session", icon='RECOVER_LAST')
        box.operator("wm.revert_mainfile", text="Revert", icon='FILE_REFRESH')
        box.separator()
        box.operator("file.report_missing_files", text="Report Missing Files")
        box.operator("file.find_missing_files", text="Find Missing Files")

class PIE_MT_fileio(Menu):
    bl_idname = "PIE_MT_fileio"
    bl_label = "Import/Export"

    def draw(self, context):
        layout = self.layout
        pie = layout.menu_pie()
        box = pie.split().column()
        box.menu("TOPBAR_MT_file_import", icon='IMPORT')
        box.separator()
        box.menu("TOPBAR_MT_file_export", icon='EXPORT')


classes = (
    PIE_MT_SaveOpen,
    PIE_MT_fileio,
    PIE_MT_recover,
    PIE_MT_link,
    )

addon_keymaps = []


def register():
    for cls in classes:
        bpy.utils.register_class(cls)

    wm = bpy.context.window_manager
    if wm.keyconfigs.addon:
        # Save/Open/...
        km = wm.keyconfigs.addon.keymaps.new(name='Window')
        kmi = km.keymap_items.new('wm.call_menu_pie', 'S', 'PRESS', ctrl=True)
        kmi.properties.name = "PIE_MT_saveopen"
        addon_keymaps.append((km, kmi))


def unregister():
    for cls in classes:
        bpy.utils.unregister_class(cls)

    wm = bpy.context.window_manager
    kc = wm.keyconfigs.addon
    if kc:
        for km, kmi in addon_keymaps:
            km.keymap_items.remove(kmi)
    addon_keymaps.clear()


if __name__ == "__main__":
    register()