-
Notifications
You must be signed in to change notification settings - Fork 10
/
ulysses_view.py
62 lines (45 loc) · 1.45 KB
/
ulysses_view.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
import sys
import os.path
import workflow.workflow3
import parse_ulysses
"""
"""
logger = None
# Views match entries in Ulysses' View menu
views = ['Default', 'Library', 'Sheets', 'Editor Only']
def main(wf):
sheet_or_group = wf.args[0]
assert sheet_or_group in ['sheet', 'group']
configured_view = get_view_setting(sheet_or_group)
for view in views:
if view is 'Default':
subtitle = 'Let Ulysses decide how to open items'
else:
subtitle = "Switch to '%s' view after opening" % view
title = view + (' (selected)' if configured_view==view else '')
wf.add_item(
title,
subtitle=subtitle,
arg=view,
valid=True,
autocomplete=view,
)
wf.send_feedback()
def get_view_setting(sheet_or_group):
assert sheet_or_group in ['sheet', 'group']
wf = workflow.workflow3.Workflow3()
view = wf.settings.get('open_%s_with_view' % sheet_or_group, None)
if view not in views:
if sheet_or_group == 'sheet':
view = 'Editor Only'
else: # group
view = 'Sheets'
return view
def set_view_setting(sheet_or_group, view):
assert sheet_or_group in ['sheet', 'group']
wf = workflow.workflow3.Workflow3()
wf.settings['open_%s_with_view' % sheet_or_group] = view
if __name__ == "__main__":
wf = workflow.workflow3.Workflow3()
logger = wf.logger
sys.exit(wf.run(main))