-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathPageRangeTester.jsx
More file actions
143 lines (129 loc) · 4.03 KB
/
PageRangeTester.jsx
File metadata and controls
143 lines (129 loc) · 4.03 KB
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
136
137
138
139
140
141
142
143
// Path to IdExtenso entry point.
// ---
#include '../$$.jsxinc'
// PageRange module.
// ---
#include '../etc/$$.PageRange.jsxlib'
// Load the framework.
// ---
$$.load();
// =============================================================================
// PageRangeTester [210817] [230109]
// Parse, format and normalize page ranges.
// ---
// Demonstrates:
// - Using the `PageRange` module.
// - Simple modal dialog interface generated by `ScriptUI.builder`.
// =============================================================================
try
{
const prefElision = 'Chicago'; // [ADD230109]
const prefMinRange = 1; // [ADD230109]
ScriptUI.builder
({
properties: { type:'dialog', text:"PageRange Tester", },
margins: 22,
spacing: 22,
orientation: 'column',
alignChildren: ScriptUI.LT,
Panel$1:
{
properties: { text:'', },
margins: 22,
spacing: 10,
orientation: 'column',
alignChildren: ScriptUI.LT,
StaticText$0: { properties:{text:"Enter a numeric sequence, e.g. `7, 10-15, 17, 25`"} },
EditText$Input:
{
properties: { text:'' },
optimalSize: { width:400 },
onChanging: function onChanging( w)
{
w = this.window;
w.Info.text = '';
w.Count.enabled = w.Format.enabled = w.Display.enabled = !!this.text;
},
},
StaticText$Note:
{
properties: { text:"\u2022 Supports overlaps and/or dups: `7, 7, 5-8, 3-6`\r\u2022 Supports unordered data: `8, 2-3, 12, 5`\r\u2022 Interprets elided ranges: `210-8` means `210-218`.", multiline:true },
optimalSize: { width:400,height:60 },
},
StaticText$Info:
{
properties: { text:'', multiline:true },
optimalSize: { width:400,height:120 },
},
},
Group$2:
{
margins: 22,
spacing: 20,
orientation: 'row',
alignment: ScriptUI.CT,
Button$Count:
{
properties: { text:'Count' },
helpTip: "Tells how many page numbers are targetted...",
enabled: false,
onClick: function onCount( w,n)
{
w = this.window;
n = $$.PageRange.count(w.Input.text);
w.Info.text = n ? (n + " element(s).") : "No element.";
},
},
Button$Format:
{
properties: { text:'Format' },
helpTip: "Reformat the sequence, both in normalized form and custom format...",
enabled: false,
onClick: function onFormat( w,r)
{
const PR = $$.PageRange;
w = this.window;
r = PR.normalize(w.Input.text);
if( !r ){ w.Info.text = "No result."; return; }
w.Info.text = "Normalized form:\r" + r
+ "\r\r\rCustom reformat (minRange:"+prefMinRange+", "+prefElision+" elision, etc):\r"
+ PR.format(PR.parse(r),
{
separator: ' ; ',
joiner: '\u2014',
minRange: prefMinRange,
elision: prefElision, // None|FinalThreeDigits|FinalTwoDigits|Chicago|Oxford|FewestFigures
});
},
},
Button$Display:
{
properties: { text:'Display' },
helpTip: "Show the array of page numbers that match the input...",
enabled: false,
onClick: function onDisplay( w,r,n)
{
w = this.window;
r = $$.PageRange.parse(w.Input.text);
1000 < (n=r.length) && (r.length=1000);
w.Info.text = n ? (n + " element(s):\r\r" + r.join(', ')) : "No element.";
},
},
Button$Quit:
{
properties: { text:'Quit', name:'cancel' },
}
},
})
.show();
}
catch(e)
{
// Should something go wrong.
// ---
$$.receiveError(e);
}
// =============================================================================
// Unload the framework to cleanup memory.
// ---
$$.unload();