-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlist_menu_bindings.py
57 lines (47 loc) · 1.8 KB
/
list_menu_bindings.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
#coding: utf8
#################################### IMPORTS ###################################
# Std Libs
import re
from pprint import pprint
# Sublime Libs
from .quick_panel_cols import format_for_display
from .jsonix import dumps as dumpsj
from .commands_base import EditJSONPreferenceBase
class ListMenuBindings(EditJSONPreferenceBase):
format_cols = (1,3)
extra_rows = (-2, -1, )
settings_pattern = "sublime-menu"
def on_settings_json(self, pkg, name, f, text, menu, completions):
pkg_display = "%s - %s" % (pkg, name) if name != pkg else pkg
completions.update(re.findall(r'\w+', text))
menus = []
def walk(menu, parent=''):
for item in menu:
if item.get('children'):
walk(item['children'],
parent=item.get('caption', ''))
else:
try:
row1 = item.get('caption') or item.get('command')
row2 = dumpsj (item.get('args', {}))
cmd = item.get('command') or ''
except Exception as e:
pprint(locals())
print(e)
raise
menus.append (
(f,
pkg_display + ((' - %s' % parent)
if parent else '' ),
parent,
row1,
cmd,
row2, ) )
walk(menu)
return menus
def on_selection(self, setting):
ident = setting[-2]
fn = setting[0]
try: regions = [list(ident.__inner__())]
except: regions = [list(ident.__outer__())]
return fn, None, regions