-
Notifications
You must be signed in to change notification settings - Fork 8
/
stdlib.js
135 lines (123 loc) · 3.85 KB
/
stdlib.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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*<javascriptresource><menu>hide</menu></javascriptresource>*/
//@include 'resources/base.js'
//@include 'resources/plurals.js'
//@include 'resources/strings.js'
//@include 'enums.js'
//@include 'internals.js'
//@include 'collections/base.js'
//@include 'collections/predicate.js'
//@include 'collections/transform.js'
//@include 'controls/about.js'
//@include 'controls/anchor.js'
//@include 'controls/multi-toggles.js'
//@include 'io/console.js'
//@include 'io/file.js'
//@include 'io/picker.js'
//@include 'sui/child-button.js'
//@include 'sui/child-dropdownlist.js'
//@include 'sui/child-edittext.js'
//@include 'sui/child-iconbutton.js'
//@include 'sui/child-image.js'
//@include 'sui/child-listbox.js'
//@include 'sui/child-progressbar.js'
//@include 'sui/child-slider.js'
//@include 'sui/child-statictext.js'
//@include 'sui/child-toggles.js'
//@include 'sui/parent-group.js'
//@include 'sui/parent-panel.js'
//@include 'sui/parent-tab.js'
//@include 'sui/parent-tabbedpanel.js'
//@include 'sui/window-builtin.js'
//@include 'sui/window-dialog.js'
//@include 'sui/window-palette.js'
//@include 'geometry.js'
//@include 'math.js'
//@include 'objects.js'
//@include 'preconditions.js'
//@include 'range.js'
//@include 'standard.js'
//@include 'text.js'
//@include 'time.js'
//@include 'units.js'
var Theme =
new Enum({
DARK: {text: R.string.dark},
LIGHT: {text: R.string.light},
})
var Language =
new Enum({
EN: {text: 'English', code: 'en'},
ID: {text: 'Indonesia', code: 'id'},
valueOfCode: function(code) {
return Collections.first(Language.values(), function(it) {
return it.code == code
})
},
/**
* Change scripts' localization.
* @param {!Object} language enum Language.
*/
set: function(language) {
checkNotNull(language)
$.localize = true
$.locale = language.code
},
})
var Scripts = {
PATH_STDLIB: new File($.fileName).path,
PATH_LIB: undefined,
PATH_STDRES: undefined,
PATH_RES: undefined,
RES_DARK: undefined,
RES_LANG: undefined,
OS_MAC: $.os.toLowerCase().indexOf('mac') >= 0,
APP_AI: app.name === 'Adobe Illustrator',
URL_GITHUB: 'https://github.com/hanggrian/prepress-adobe-scripts/',
URL_WEBSITE: 'https://hanggrian.github.io/prepress-adobe-scripts/',
/**
* Refer to a file from preferably local resources, or fallback standard resources if local resource is not found.
* @param {string} fullName
* @return {!File}
*/
getResource: function(fullName) {
checkNotNull(fullName)
if (Scripts.PATH_STDRES === undefined) {
Scripts.PATH_STDRES = new File(Scripts.PATH_STDLIB + '/../.stdres')
Scripts.PATH_RES = new File(Scripts.PATH_LIB + '/../.res')
}
var file = new File(Scripts.PATH_RES + '/' + fullName)
if (file.exists) {
return file
}
file = new File(Scripts.PATH_STDRES + '/' + fullName)
if (file.exists) {
return file
}
return undefined
},
/**
* Open URL with default browser, by writing a temporary HTML file which redirects to the URL.
* @param {string} url
* @see https://community.adobe.com/t5/indesign/js-scriptui-url-links-in-dialogues/td-p/4572773?page=1
*/
openUrl: function(url) {
checkNotNull(url)
var html =
'<!doctype html>\n' +
'<html lang="en">\n' +
' <head>\n' +
' <meta charset="UTF-8">\n' +
' <title>Redirecting...</title>\n' +
' <meta HTTP-EQUIV=refresh CONTENT="0; URL=%s">\n'.format(url) +
' </head>\n' +
' <body>\n' +
' <h1>Redirecting...</h1>\n' +
' <p>You\'re being redirected to</p>\n' +
' <a href="%s">%s</a>\n'.format(url, url) +
' </body>\n' +
'</html>'
var tempFile = new File(Folder.temp + '/prepress-adobe-scripts.html')
tempFile.writeText(html)
tempFile.execute()
},
}