-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.js
executable file
·61 lines (44 loc) · 1.82 KB
/
config.js
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
const getFullConfigKey = (context, key) => {
return getPluginName(context) + '.' + key;
};
/**
* Per-installation config values
*/
const getConfigValue = (context, key) => {
const defaults = NSUserDefaults.standardUserDefaults();
return defaults.valueForKey(getFullConfigKey(context, key)) + '';
};
const hasConfigValue = (context, key) => getConfigValue(context, key) !== null;
const setConfigValue = (context, key, value) => {
const defaults = NSUserDefaults.standardUserDefaults();
defaults.setObject_forKey_(value, getFullConfigKey(context, key));
};
/**
* Per-layer config values
*/
const getLayerValue = (context, layer, key) => {
const store = context.command;
const fullKey = getFullConfigKey(context, key);
const value = store.valueForKey_onLayer_(fullKey, layer);
return value !== undefined && value !== null ? value + '' : undefined;
};
const hasLayerValue = (context, layer, key) => getLayerValue(context, layer, key) !== undefined;
const setLayerValue = (context, layer, key, value) => {
const store = context.command;
const fullKey = getFullConfigKey(context, key);
store.setValue_forKey_onLayer_(value, fullKey, layer);
};
/**
* Per-document config values
*/
const getDocumentValue = (context, key) => {
const value = context.api().selectedDocument.pages
.map(page => getLayerValue(context, page.sketchObject, key))
.reduce((value, current) => value !== undefined || current === null ? value : current, undefined);
return value !== undefined && value !== null ? value + '' : undefined;
};
const hasDocumentValue = (context, key) => getDocumentValue(context, key) !== undefined;
const setDocumentValue = (context, key, value) => {
const page = context.api().selectedDocument.pages[0];
setLayerValue(context, page.sketchObject, key, value);
};