-
Notifications
You must be signed in to change notification settings - Fork 19
/
add_action.py
62 lines (53 loc) · 2.14 KB
/
add_action.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
# coding: utf-8
'''
Manipulate action (wrench) menu
example:
add_action('/stash/launch_stash.py','monitor')
save_defaults() # so it is stored for next launch
'''
from objc_util import *
NSUserDefaults = ObjCClass('NSUserDefaults')
def add_action(scriptName,iconName='python',iconColor='',title='',arguments=''):
'''adds an editor action. scriptName should start with /
(e.g /stash/stash.py)
iconName should be an icon without leading prefix, or trailing size. i.e alert instead of iob:alert_256
iconColor should be a web style hex string, eg aa00ff
title is the alternative title
Call save_defaults() to store defaults
')'''
defaults=NSUserDefaults.standardUserDefaults()
kwargs=locals()
entry={ key:kwargs[key]
for key in
('scriptName','iconName','iconColor','title','arguments')
if key in kwargs and kwargs[key] }
editoractions=get_actions()
editoractions.append(ns(entry))
defaults.setObject_forKey_(editoractions,'EditorActionInfos')
def remove_action(scriptName):
''' remove all instances of a given scriptname.
Call save_defaults() to store for next session
'''
defaults=NSUserDefaults.standardUserDefaults()
editoractions=get_actions()
[editoractions.remove(x) for x in editoractions if str(x['scriptName'])==scriptName]
defaults.setObject_forKey_(editoractions,'EditorActionInfos')
def remove_action_at_index(index):
''' remove action at index. Call save_defaults() to save result.
'''
defaults=NSUserDefaults.standardUserDefaults()
editoractions = get_actions()
del editoractions[index]
defaults.setObject_forKey_(editoractions,'EditorActionInfos')
def get_defaults_dict():
'''return NSdictionary of defaults'''
defaults=NSUserDefaults.standardUserDefaults()
return defaults.dictionaryRepresentation()
def get_actions():
'''return action list'''
defaults=NSUserDefaults.standardUserDefaults()
return list(defaults.arrayForKey_('EditorActionInfos'))
def save_defaults():
'''save current set of defaults'''
defaults=NSUserDefaults.standardUserDefaults()
NSUserDefaults.setStandardUserDefaults_(defaults)