forked from montegoulding/scriptonlyui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptOnlyUI.livecodescript
More file actions
405 lines (356 loc) · 14.9 KB
/
ScriptOnlyUI.livecodescript
File metadata and controls
405 lines (356 loc) · 14.9 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
script "ScriptOnlyUI"
constant kObjectSeparator = "------------------------------------------------------------------------"
constant kPropertySeparator = ";"
constant kPropertyNameSeparator = " : "
constant kPropertyValueKeySeparator = " - "
constant kPropertyValueElementSeparator = " -> "
on libraryStack
if the target is me and there is not a button "ScriptOnlyUIFront" of me then
set the defaultStack to me
create button "ScriptOnlyUIFront"
set the script of button "ScriptOnlyUIFront" to \
"on preOpenStack" & return & \
" get the short name of the owner of the target" & return & \
" if it is not " & quote & "ScriptOnlyUI" & quote & " and \" & return & \
" the scriptOnly of stack it and \" & return & \
" the number of controls of stack it is 0 and \" & return & \
" the filename of stack it is not empty then" & return & \
" GenerateScriptOnlyUI it" & return & \
" end if" & return & \
" pass preOpenStack" & return & \
"end preOpenStack" & return
insert the script of btn "ScriptOnlyUIFront" of me into front
create button "ScriptOnlyUIBack"
set the script of button "ScriptOnlyUIBack" to \
"on saveStackRequest" & return & \
" get the short name of the owner of the target" & return & \
" if it is not " & quote & "ScriptOnlyUI" & quote & " and the scriptOnly of stack it then" & return & \
" SaveScriptOnlyUI it" & return & \
" end if" & return & \
" pass saveStackRequest" & return & \
"end saveStackRequest" & return
insert the script of btn "ScriptOnlyUIBack" of me into back
end if
pass libraryStack
end libraryStack
on releaseStack
if the target is me then
if there is a button "ScriptOnlyUIFront" then
remove the script of btn "ScriptOnlyUIFront" from front
end if
if there is a button "ScriptOnlyUIBack" then
remove the script of btn "ScriptOnlyUIBack" from front
end if
end if
pass releaseStack
end releaseStack
private function EnsureScriptOnlyUI pStack
dispatch "ScriptOnlyUI" to stack pStack
return the result
end EnsureScriptOnlyUI
private function UIFile pStack
local tFile
put the filename of stack pStack into tFile
set the itemDelimiter to "."
put "livecodescriptui" into the last item of tFile
return tFile
end UIFile
on GenerateScriptOnlyUI pStack
if EnsureScriptOnlyUI(pStack) then
set the defaultStack to pStack
local tScreenRect
put line (the screen of stack pStack) of the screenRects into tScreenRect
set the location of stack pStack to item 1 of tScreenRect + (item 3 of tScreenRect - item 1 of tScreenRect) div 2, item 2 of tScreenRect + (item 4 of tScreenRect - item 2 of tScreenRect) div 2
local tFile
put UIFile(pStack) into tFile
if there is a file tFile then
local tObjects
open file tFile for "utf-8" text read
read from file tFile until "eof"
put it into tObjects
close file tFile
--put textDecode(url ("binfile:" & tFile)) into tObjects
split tObjects by (kObjectSeparator & return)
local tUnlockUpdates
repeat with tIndex = 1 to the number of elements of tObjects
split tObjects[tIndex] by (kPropertySeparator & return) and kPropertyNameSeparator
local tObject
switch tObjects[tIndex]["type"]
case "" -- stack
get the name of stack pStack
break
case "card"
if the number of cards of stack pStack is 1 and \
the short name of card 1 of stack pStack is the abbreviated id of card 1 of stack pStack then
get the long id of card 1 of stack pStack
else
create card tObjects[tIndex]["name"]
end if
break
case "group"
if word 1 of tObjects[tIndex]["owner"] is "group" then
create group tObjects[tIndex]["name"] in tObjects[tIndex]["owner"]
else
create group tObjects[tIndex]["name"]
end if
set the lockUpdates of it to true
put it into tUnlockUpdates[the number of elements of tUnlockUpdates + 1]
break
case "button"
if word 1 of tObjects[tIndex]["owner"] is "group" then
create button tObjects[tIndex]["name"] in tObjects[tIndex]["owner"]
else
create button tObjects[tIndex]["name"]
end if
break
case "field"
if word 1 of tObjects[tIndex]["owner"] is "group" then
create field tObjects[tIndex]["name"] in tObjects[tIndex]["owner"]
else
create field tObjects[tIndex]["name"]
end if
break
case "graphic"
if word 1 of tObjects[tIndex]["owner"] is "group" then
create graphic tObjects[tIndex]["name"] in tObjects[tIndex]["owner"]
else
create graphic tObjects[tIndex]["name"]
end if
break
case "image"
if word 1 of tObjects[tIndex]["owner"] is "group" then
create image tObjects[tIndex]["name"] in tObjects[tIndex]["owner"]
else
create image tObjects[tIndex]["name"]
end if
break
case "player"
if word 1 of tObjects[tIndex]["owner"] is "group" then
create player tObjects[tIndex]["name"] in tObjects[tIndex]["owner"]
else
create player tObjects[tIndex]["name"]
end if
break
case "scrollbar"
if word 1 of tObjects[tIndex]["owner"] is "group" then
create scrollbar tObjects[tIndex]["name"] in tObjects[tIndex]["owner"]
else
create scrollbar tObjects[tIndex]["name"]
end if
break
case "widget"
CreateWidget tObjects[tIndex]
get the result
break
end switch
put it into tObject
local tProperty
repeat for each key tProperty in tObjects[tIndex]
if tObjects[tIndex][tProperty] begins with return then
delete char 1 of tObjects[tIndex][tProperty]
end if
if tObjects[tIndex][tProperty] begins with kPropertyValueKeySeparator then
delete char 1 to the length of kPropertyValueKeySeparator of tObjects[tIndex][tProperty]
-- array property
split tObjects[tIndex][tProperty] by (return & kPropertyValueKeySeparator) and kPropertyValueElementSeparator
repeat for each key tKey in tObjects[tIndex][tProperty]
if tObjects[tIndex][tProperty][tKey] begins with return then
delete char 1 of tObjects[tIndex][tProperty][tKey]
end if
end repeat
end if
set the tProperty of tObject to tObjects[tIndex][tProperty]
end repeat
end repeat
repeat with tIndex = the number of elements of tUnlockUpdates down to 1
set the lockUpdates of tUnlockUpdates[tIndex] to false
end repeat
end if
end if
end GenerateScriptOnlyUI
on SaveScriptOnlyUI pStack
if EnsureScriptOnlyUI(pStack) then
ResetTemplateProperties
local tFile
put UIFile(pStack) into tFile
open file tFile for "utf-8" text write
if the result is empty then
try
SaveObject the long id of stack pStack, tFile
catch tError
answer error tError
finally
close file tFile
end try
end if
end if
end SaveScriptOnlyUI
private command SaveObject pObject, pFile
local tProperties, tType
put word 1 of pObject into tType
if tType is "widget" then
put GetWidgetProperties(pObject) into tProperties
else
put the properties of pObject into tProperties
end if
if tProperties["name"] is empty then
set the name of pObject to uuid()
put the short name of pObject into tProperties["name"]
end if
if tType is not "stack" then
write "name" & kPropertyNameSeparator & tProperties["name"] & kPropertySeparator & return to file pFile
write "type" & kPropertyNameSeparator & tType & kPropertySeparator & return to file pFile
if tType is not "card" then
write "owner" & kPropertyNameSeparator & the abbreviated name of the owner of pObject & kPropertySeparator & return to file pFile
end if
if the script of pObject is not empty then
put the script of pObject into tProperties["script"]
end if
else
put the width of pObject into tProperties["width"]
put the height of pObject into tProperties["height"]
end if
local tKeys
put the keys of tProperties into tKeys
sort tKeys
local tTemplateProperties
put GetTemplateProperties(tType) into tTemplateProperties
repeat for each line tKey in tKeys
switch
case tProperties[tKey] is tTemplateProperties[tKey]
case tKey is among the words of "name id altId layer defaultButton mark"
case tKey contains "icon"
case tKey contains "pattern"
case tKey is among the words of "rect fileName" and tType is "stack"
case tKey is "text" and tType is "image"
next repeat
break
end switch
write tKey & kPropertyNameSeparator to file pFile
if tProperties[tKey] is an array then
local tArrayKeys
put the keys of tProperties[tKey] into tArrayKeys
sort tArrayKeys
repeat for each line tArrayKey in tArrayKeys
if tProperties[tKey][tArrayKey] is tTemplateProperties[tKey][tArrayKey] then
next repeat
end if
write return & kPropertyValueKeySeparator & tArrayKey & kPropertyValueElementSeparator to file pFile
if the number of lines of tProperties[tKey][tArrayKey] > 1 then
write return to file pFile
end if
write tProperties[tKey][tArrayKey] to file pFile
end repeat
else
if the number of lines of tProperties[tKey] > 1 then
write return to file pFile
end if
write tProperties[tKey] to file pFile
end if
write kPropertySeparator & return to file pFile
end repeat
local tChildID
switch tType
case "stack"
repeat for each line tChildID in the cardIDs of pObject
write kObjectSeparator & return to file pFile
SaveObject the long id of card id tChildID of pObject, pFile
end repeat
break
case "card"
repeat for each line tChildID in the childControlIDs of pObject
write kObjectSeparator & return to file pFile
SaveObject the long id of control id tChildID of pObject, pFile
end repeat
break
case "group"
repeat for each line tChildID in the childControlIDs of pObject
write kObjectSeparator & return to file pFile
SaveObject the long id of control id tChildID of pObject, pFile
end repeat
break
end switch
end SaveObject
constant kWidgetProps = "rect toolTip visible topColor textStyle bottomColor dropShadow backColor lockLoc foreColor cantSelect layerMode shadowColor opaque innerGlow ink showBorder textSize textFont disabled colorOverlay hiliteColor behavior borderColor innerShadow hiliteBorder outerGlow blendLevel hiliteFill traversalOn focusColor textAlign layer"
function GetTemplateProperties pType
switch pType
case "stack"
return the properties of the templateStack
case "card"
return the properties of the templateStack
case "group"
return the properties of the templateStack
case "image"
return the properties of the templateStack
case "graphic"
case "widget" -- !dirty hack!
return the properties of the templateStack
case "button"
return the properties of the templateStack
case "field"
return the properties of the templateStack
case "player"
return the properties of the templateStack
case "scrollbar"
return the properties of the templateStack
end switch
end GetTemplateProperties
private command ResetTemplateProperties
reset the templateStack
reset the templateCard
reset the templateGroup
reset the templateImage
reset the templateGraphic
reset the templateButton
reset the templateField
reset the templatePlayer
reset the templateScrollbar
end ResetTemplateProperties
function GetWidgetProperties pObject
local theObjectA
# default properties
put the short name of pObject into theObjectA["name"]
repeat for each word theProperty in kWidgetProps
put the theProperty of pObject into theObjectA[theProperty]
end repeat
# widget properties
local tWidgetProps
export pObject to array tWidgetProps
put tWidgetProps["$kind"] into theObjectA["kind"]
put tWidgetProps["$state"] into theObjectA["state"]
return theObjectA
end GetWidgetProperties
command CreateWidget pPropertiesA
local tObject
local tWidgetProps
put pPropertiesA["state"] into tWidgetProps["$state"]
put pPropertiesA["kind"] into tWidgetProps["$kind"]
FixWidgetState tWidgetProps["$state"]
import widget from array tWidgetProps
put the long id of the last widget into tObject
-- this won't work if the card isn't open!
set the name of tObject to pPropertiesA["name"]
if word 1 of tObjects[tIndex]["owner"] is "group" then
relayer tObject to front of tObjects[tIndex]["owner"]
end if
return tObject
end CreateWidget
private command FixWidgetState @pState
if pState is an array then
repeat for each key tKey in pState
FixWidgetState pState[tKey]
end repeat
else
switch
case pState is "true"
put pState is "true" into pState
break
case pState is "false"
put pState is "true" into pState
break
case pState is a number
put pState * 1 into pState
break
end switch
end if
end FixWidgetState