-
Notifications
You must be signed in to change notification settings - Fork 2
/
keymap.py
107 lines (88 loc) · 3.1 KB
/
keymap.py
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
import bpy
addon_keymaps = []
def register_keymaps(force=False):
if bpy.app.background:
return
addon = bpy.context.window_manager.keyconfigs.addon
km = addon.keymaps.new(name = "Window", space_type = "EMPTY")
## Pop up search in history
idn = 'path.open_from_history'
kmi = km.keymap_items.get(idn)
# refresh here
# if kmi:
# km.keymap_items.remove(idn)
# kmi = km.keymap_items.new(idn,
# type = "O", value = "PRESS", shift = True, ctrl = True, alt = True)
# addon_keymaps.append((km, kmi))
## Menu open with search
if not kmi or force:
kmi = km.keymap_items.new(idn,
type = "O", value = "PRESS", shift = True, ctrl = True, alt = True)
addon_keymaps.append((km, kmi))
# else:
# print(f'Found kmi {idn}')
## Open last blend in one go
# idn = 'path.open_last_file'
# kmi = km.keymap_items.get(idn)
# if not kmi or force:
# kmi = km.keymap_items.new(idn,
# type = "P", value = "PRESS", shift = True, ctrl = True, alt = True)
# addon_keymaps.append((km, kmi))
def unregister_keymaps():
if bpy.app.background:
return
for km, kmi in addon_keymaps:
if km.keymap_items.get(kmi.idname):
km.keymap_items.remove(kmi)
addon_keymaps.clear()
"""
# /old
class PATH_OT_re_register_keymap(bpy.types.Operator):
bl_idname = "path.re_register_keymaps"
bl_label = "Register Addon Keymaps"
bl_options = {'REGISTER', 'INTERNAL'}
def execute(self, context):
register_keymaps()
return {'FINISHED'}
# old/
# unregistered not exposed anymore
class PATH_OT_re_register_keymap(bpy.types.Operator):
bl_idname = "path.re_register_keymaps"
bl_label = "Register Addon Keymaps"
bl_options = {'REGISTER', 'INTERNAL'}
idname: bpy.props.StringProperty()
def execute(self, context):
# Clean addon_keymap list
# wm = bpy.context.window_manager
# kc = wm.keyconfigs.user
# print('addon_keymaps: ', len(addon_keymaps))
to_pop = []
for i, kmp in enumerate(addon_keymaps):
km, kmi = kmp
idn = kmi.idname
if self.idname == kmi.idname:
print('idname found', self.idname)
if km.keymap_items.get(kmi.idname):
## try removing in user...
# kmu = kc.keymaps[km.name]
# kmui = kmu.keymap_items.get(idn)
# if kmui:
# print('found kmui')
# kmu.keymap_items.remove(kmui)
km.keymap_items.remove(kmi)
to_pop.append(i)
print('to_pop: ', to_pop)
for i in reversed(to_pop):
del addon_keymaps[i]
# addon_keymaps.pop(i)
# register again
register_keymaps() # force=True
return {'FINISHED'}
"""
### ---
def register():
register_keymaps()
# bpy.utils.register_class(PATH_OT_re_register_keymap)
def unregister():
# bpy.utils.unregister_class(PATH_OT_re_register_keymap)
unregister_keymaps()