This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathrevprojectbrowserbehavior.livecodescript
2542 lines (2115 loc) · 96.3 KB
/
revprojectbrowserbehavior.livecodescript
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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
script "revProjectBrowserBehavior"
local sDisplayArray, sLongIDToRow, sObjectToParent
on arrowKey pDirection
local tHilitedRow
put the dvHilitedRows of group "objectList" of me into tHilitedRow
-- up and down are handled by the data view
if the number of items of tHilitedRow is 1 and not (the dvIsFieldEditor of the target) then
switch pDirection
case "left"
if getRowExpanded(getAbsoluteRow(tHilitedRow)) then
toggleGroup tHilitedRow, false
end if
break
case "right"
if not getRowExpanded(getAbsoluteRow(tHilitedRow)) then
toggleGroup tHilitedRow, true
end if
break
end switch
end if
pass arrowKey
end arrowKey
on returnKey
local tHilitedRow
put the dvHilitedRows of group "objectList" of me into tHilitedRow
-- up and down are handled by the data view
if the number of items of tHilitedRow is 1 then
local tDataA, tTemplateStyle
DataForRow tHilitedRow, tDataA, tTemplateStyle
if exists(tDataA["behavior"]) and the shiftKey is down and the optionKey is down then
edit the script of tDataA["behavior"]
else if exists(tDataA["long id"]) then
if the shiftKey is down then
edit the script of tDataA["long id"]
else if the commandKey is down then
revIDEInspectObjects tDataA["long id"]
else
goToObject tDataA["long id"]
end if
end if
end if
pass returnKey
end returnKey
on preOpenStack
dispatch "setAsBehavior" to revIDEFrameBehavior() with the long id of this me
set the zoomBox of this stack to false
clearFrameData
revIDEUpdatePBPreferences
# Navigation
# Footer Actions
addFrameItem "alignLeft","footer", "action", "Align left", "object align left", "","alignControls", the long id of me, "left"
addFrameItem "alignTop","footer", "action", "Align top", "object align top", "","alignControls", the long id of me, "top"
addFrameItem "alignRight","footer", "action", "Align right", "object align right", "","alignControls", the long id of me, "right"
addFrameItem "alignBottom","footer", "action", "Align bottom", "object align bottom", "","alignControls", the long id of me, "bottom"
addFrameItem "centerX","footer", "action", "Center horizontally", "object align horizontal center", "","centerControls", the long id of me, "horizontal"
addFrameItem "centerY","footer", "action", "Center vertically", "object align vertical center", "","centerControls", the long id of me, "vertical"
addFrameItem "equalizeWidth","footer", "action", "Equalize width", "object justify horizontal", "","equalizeControls", the long id of me, "width"
addFrameItem "equalizeHeight","footer", "action", "Equalize height", "object justify vertical", "","equalizeControls", the long id of me, "height"
addFrameItem "equalizeRect","footer", "action", "Equalize rect", "object justify both", "","equalizeControls", the long id of me, "rect"
addFrameItem "distributeVertically","footer", "action", "Layout vertically", "resize vertical", "","distributeControls", the long id of me, "vertical"
addFrameItem "distributeHorizontally","footer", "action", "Layout horizontally", "resize horizontal", "","distributeControls", the long id of me, "horizontal"
addFrameItem "newControl","footer", "action", "New control", "file alt", "","newControls", the long id of me
addFrameItem "groupControl","footer", "action", "Group controls", "folder open alt", "","groupControls", the long id of me
addFrameItem "cloneControl","footer", "action", "Clone control", "files alt", "","cloneControls", the long id of me
addFrameItem "deleteControl","footer", "action", "Delete control", "trash", "","deleteControls", the long id of me
# Preferences
addFrameItem "pb_indicator", "header", "preference", "Object type indicator", "enum","Text,Icon", "preferenceChanged", the long id of me
addFrameItem "pb_sections", "header", "preference", "Show Sections", "set","Front Scripts,Stacks,Back Scripts,Stacks in use", "preferenceChanged", the long id of me
addFrameItem "pb_stackSort","header","preference","Order stacks by","enum","Name - ascending,Name - descending,Layer - ascending,Layer - descending","preferenceChanged",the long id of me
addFrameItem "pb_cardSort","header","preference","Order cards by","enum","Name - ascending,Name - descending,Layer - ascending,Layer - descending","preferenceChanged",the long id of me
addFrameItem "pb_controlSort","header","preference","Order controls by","enum","Name - ascending,Name - descending,Layer - ascending,Layer - descending","preferenceChanged",the long id of me
addFrameItem "pb_textSize","header","preference","Text size","enum","default,8,10,12,14,18,24","preferenceChanged",the long id of me
revIDESubscribe "ideSelectedObjectChanged"
revIDESubscribe "ideNewControl"
revIDESubscribe "ideNewCard"
revIDESubscribe "ideNewStack"
revIDESubscribe "ideOpenStack"
revIDESubscribe "ideResumeStack"
revIDESubscribe "ideDestroyStack"
revIDESubscribe "ideControlDeleted"
revIDESubscribe "ideCardDeleted"
revIDESubscribe "ideStackDeleted"
revIDESubscribe "ideLibraryStack"
revIDESubscribe "ideReleaseStack"
revIDESubscribe "ideNameChanged"
revIDESubscribe "ideMainstackChanged"
revIDESubscribe "idePreferenceChanged:cShowRevolutionStacks"
revIDESubscribe "idePreferenceChanged:pb_indicator"
revIDESubscribe "idePreferenceChanged:pb_sections"
revIDESubscribe "idePreferenceChanged:pb_stackSort"
revIDESubscribe "idePreferenceChanged:pb_cardSort"
revIDESubscribe "idePreferenceChanged:pb_controlSort"
revIDESubscribe "idePreferenceChanged:pb_textSize"
revIDESubscribe "ideShowInProjectBrowser"
local tTextSize
put revIDEGetPreference("pb_textSize") into tTextSize
if tTextSize is "default" then
set the textSize of me to empty
else
set the textSize of me to tTextSize
end if
put empty into sDisplayArray
loadImages
setUpProjectView
buildProjectView
set the rect of group "content" of card 1 of me to the contentRect of me
ideSelectedObjectChanged
end preOpenStack
on resizeStack
lock screen
set the rect of group "content" of card 1 of me to the contentRect of me
unlock screen
end resizeStack
on closeStack
local tExpanded
## Unsubscribe
-- revIDEUnsubscribe "ideSelectedObjectChanged"
-- revIDEUnsubscribe "ideNewControl"
-- revIDEUnsubscribe "ideNewCard"
-- revIDEUnsubscribe "ideNewStack"
-- revIDEUnsubscribe "ideControlDeleted"
-- revIDEUnsubscribe "ideCardDeleted"
-- revIDEUnsubscribe "ideStackDeleted"
-- revIDEUnsubscribe "ideLibraryStack"
-- revIDEUnsubscribe "ideReleaseStack"
## Store the expanded controls
lock screen
repeat for each key tRow in sDisplayArray["objects"]
if sDisplayArray["objects"][tRow]["expanded"] then put sDisplayArray["objects"][tRow]["long id"] & return before tExpanded
end repeat
set the cExpandedControls of me to tExpanded
put empty into sDisplayArray
refreshProjectView
unlock screen
end closeStack
####### Subscribed IDE messages #######
###################################
on ideSelectedObjectChanged
highlightObjects revIDESelectedObjects()
end ideSelectedObjectChanged
on ideNewControl pTarget
if not exists(pTarget) then
exit ideNewControl
end if
put the long id of pTarget into pTarget
if word 1 of pTarget is "stack" or word 1 of pTarget is "card" then
exit ideNewControl
end if
local tSortType,tSortOrder
revIDEGetPBSortPreferences "pb_controlSort", tSortType, tSortOrder
if word 1 of pTarget is "group" and tSortType is "number" then
addGroupToProjectBrowser pTarget
else
addControlToProjectBrowser pTarget
end if
end ideNewControl
on ideNewCard pTarget
if not exists(pTarget) then
exit ideNewCard
end if
addCardToProjectBrowser pTarget
end ideNewCard
on ideNewStack pTarget
if not exists(pTarget) then
exit ideNewStack
end if
addStackToProjectBrowser pTarget
end ideNewStack
on ideControlDeleted pTarget
deleteControlFromProjectBrowser pTarget
end ideControlDeleted
on ideCardDeleted pTarget
deleteCardFromProjectBrowser pTarget
end ideCardDeleted
on ideStackDeleted pTarget
deleteStackFromProjectBrowser pTarget
end ideStackDeleted
on ideLibraryStack pTarget
buildProjectView true
end ideLibraryStack
on ideReleaseStack pTarget
buildProjectView true
end ideReleaseStack
on ideOpenStack pTarget
local tStack
if not exists(pTarget) then
exit ideOpenStack
end if
if word 1 of pTarget is "card" then
put ideStackOfObject(pTarget) into tStack
else if word 1 of pTarget is "stack" then
put pTarget into tStack
end if
addStackToProjectBrowser tStack
end ideOpenStack
on ideDestroyStack pTarget
deleteStackFromProjectBrowser pTarget
end ideDestroyStack
on ideResumeStack pTarget
ideSelectedObjectChanged
end ideResumeStack
on ideNameChanged pOldName, pNewName, pTarget
# if the target is a stack, we need to deal with the name change
# separately, as the long id is changed.
if word 1 of pTarget is "stack" then
local tOldTarget
put pTarget into tOldTarget
put quote & pOldName & quote into word 2 of tOldTarget
deleteStackFromProjectBrowser tOldTarget
addStackToProjectBrowser pTarget
exit ideNameChanged
end if
updateObjectRows pTarget, "name", pNewName
# If we're sorting by name, we might need to re-order
local tSortType,tSortOrder
if word 1 of pTarget is "card" then
revIDEGetPBSortPreferences "pb_cardSort", tSortType, tSortOrder
else
revIDEGetPBSortPreferences "pb_controlSort", tSortType, tSortOrder
end if
if tSortType is "name" then
buildProjectView true
end if
end ideNameChanged
on ideMainstackChanged pOldName, pNewName, pTarget
# The long id of the target will have changed.
# Try and find the old stack which will have been added to the pb
local tOldTarget
# First check if the target was previously the substack of another stack
local tDeleted
put pTarget into tOldTarget
put quote & pOldName & quote into word 5 of tOldTarget
deleteStackFromProjectBrowser tOldTarget
put the result into tDeleted
# Otherwise the target was previously a mainstack
if not tDeleted then
put word 1 to 2 of pTarget into tOldTarget
deleteStackFromProjectBrowser tOldTarget
put the result into tDeleted
end if
addStackToProjectBrowser pTarget
end ideMainstackChanged
on preferenceChanged pPreference, pValue
local tOldValue, tSortType, tSortOrder
switch pPreference
case "pb_sections"
local tCurrentPreferenceValue, tPreferencePosition
put revIDEGetPreference("pb_sections") into tCurrentPreferenceValue
put itemoffset(pValue, tCurrentPreferenceValue) into tPreferencePosition
if tPreferencePosition > 0 then
delete item tPreferencePosition of tCurrentPreferenceValue
else
put "," & pValue after tCurrentPreferenceValue
end if
revIDESetPreference "pb_sections", tCurrentPreferenceValue
break
case "pb_stackSort"
case "pb_cardSort"
case "pb_controlSort"
case "pb_textSize"
case "pb_indicator"
revIDESetPreference pPreference,pValue
break
end switch
end preferenceChanged
on idePreferenceChanged pPreference, pValue
local tTextSize
switch pPreference
case "pb_indicator"
case "pb_sections"
case "pb_stackSort"
case "pb_cardSort"
case "pb_controlSort"
buildProjectView true
break
case "pb_textSize"
put revIDEGetPreference("pb_textSize") into tTextSize
if tTextSize is "default" then
set the textSize of me to empty
else
set the textSize of me to tTextSize
end if
setUpProjectView
buildProjectView true
break
default
buildProjectView true
end switch
end idePreferenceChanged
on ideShowInProjectBrowser pTarget
lock screen
repeat for each line tObj in pTarget
showObjects tObj
end repeat
scrollToObject line 1 of pTarget
unlock screen
end ideShowInProjectBrowser
######## Project View Handlers ########
###################################
function pbSelectedObjects
local tHilitedRows
put the dvHilitedRows of group "objectList" of me into tHilitedRows
local tObjectList, tAbsoluteRow, tObject
repeat for each item tRow in tHilitedRows
put getAbsoluteRow(tRow) into tAbsoluteRow
put sDisplayArray["objects"][tAbsoluteRow]["long id"] into tObject
if tObjectList is empty then
put tObject into tObjectList
else
put return & tObject after tObjectList
end if
end repeat
return tObjectList
end pbSelectedObjects
command setUpProjectView
local theStylesA, tBehaviorsFolder, tStackID, tTemplatesFolder
put revIDEPaletteResourcePath("behaviors") into tBehaviorsFolder
put revIDEPaletteResourcePath("templates") into tTemplatesFolder
set the behavior of group "objectList" of me to revIDEDataViewBehavior()
send "ResetView" to group "objectList" of me
put the long id of group "containerRow" of card 1 of stack (tTemplatesFolder & slash & "revideprojectbrowsercontainerrowtemplate.livecode") into theStylesA["container"]
put the long id of stack (tBehaviorsFolder & slash & "revideprojectbrowsercontainerrowbehavior.livecodescript") into tStackID
set the behavior of theStylesA["container"] to tStackID
put the long id of group "controlRow" of card 1 of stack (tTemplatesFolder & slash & "revideprojectbrowsercontrolrowtemplate.livecode") into theStylesA["control"]
put the long id of stack (tBehaviorsFolder & slash & "revideprojectbrowsercontrolrowbehavior.livecodescript") into tStackID
set the behavior of theStylesA["control"] to tStackID
put the long id of group "libraryRow" of card 1 of stack (tTemplatesFolder & slash & "revideprojectbrowserlibraryrowtemplate.livecode") into theStylesA["library"]
put the long id of stack (tBehaviorsFolder & slash & "revideprojectbrowserlibraryrowbehavior.livecodescript") into tStackID
set the behavior of theStylesA["library"] to tStackID
put the long id of group "sectionRow" of card 1 of stack (tTemplatesFolder & slash & "revideprojectbrowsersectionrowtemplate.livecode") into theStylesA["section"]
put the long id of stack (tBehaviorsFolder & slash & "revideprojectbrowsersectionrowbehavior.livecodescript") into tStackID
set the behavior of theStylesA["section"] to tStackID
put the long id of group "groupRow" of card 1 of stack (tTemplatesFolder & slash & "revideprojectbrowsergrouprowtemplate.livecode") into theStylesA["group"]
put the long id of stack (tBehaviorsFolder & slash & "revideprojectbrowsergrouprowbehavior.livecodescript") into tStackID
set the behavior of theStylesA["group"] to tStackID
set the viewProp["row style templates"] of group "objectList" of me to theStylesA
set the viewProp["hilite color"] of group "objectList" of me to revIDEColor("dataView_HiliteColor")
set the viewProp["row color"] of group "objectList" of me to revIDEColor("dataView_rowColor")
set the viewProp["alternate row color"] of group "objectList" of me to revIDEColor("dataView_rowAlternateColor")
set the viewProp["fixed row height"] of group "objectList" of me to "true"
set the viewProp["row height"] of group "objectList" of me to the effective textSize of me + 14
set the viewProp["cache"] of group "objectList" of me to "none"
set the viewProp["background color"] of group "objectList" of me to empty
set the viewProp["drop indicator template"] of group "objectList" of me to the long id of group "pbDragIndicator" of card "templates" of this stack
set the foregroundColor of graphic "indicator" of group "pbDragIndicator" of card "templates" of this stack to revIDEColor("edition_color")
end setUpProjectView
command buildProjectView pRememberExpansion
local tStacks, tFrontScripts, tBackScripts,tRow, tVisibleROws, tChildren
local tLibraryStacks, tOldArray,tOldExpandedControls, tOldExpandedRows
local tSections
local tIndex
lock screen
put revIDEGetPreference("pb_sections") into tSections
if pRememberExpansion then
repeat for each key tKey in sDisplayArray["objects"]
if sDisplayArray["objects"][tKey]["expanded"] is true then
if sDisplayArray["objects"][tKey]["type"] is "stack" or sDisplayArray["objects"][tKey]["type"] is "substack" then
put sDisplayArray["objects"][tKey]["long id"] & comma & 1 & return after tOldExpandedControls
else if sDisplayArray["objects"][tKey]["type"] is "card" then
put sDisplayArray["objects"][tKey]["long id"] & comma & 2 & return after tOldExpandedControls
else if sDisplayArray["objects"][tKey]["type"] is "group" then
put sDisplayArray["objects"][tKey]["long id"] & comma & 3 & return after tOldExpandedControls
else
put sDisplayArray["objects"][tKey]["long id"] & comma & 4 & return after tOldExpandedControls
end if
end if
end repeat
end if
sort lines of tOldExpandedControls by item 2 of each
repeat with x = 1 to the number of items in tSections
if item x of tSections is not among the items of "Front Scripts,Stacks,Back Scripts,Stacks in use" then
delete item x of tSections
end if
end repeat
## If all are switched off the show stacks
if tSections is empty then
put "stacks" into tSections
revIDESetPreference "ideProjectBrowser_show",tSections
exit buildProjectView
end if
if "Front Scripts" is among the items of tSections then
put revIDEFrontScripts() into tFrontScripts
if tFrontScripts is not empty then
put the number of elements in tFrontScripts + 1 into tIndex
end if
end if
if "Stacks" is among the items of tSections then
put revIDEStacksForDataView(tIndex) into tStacks
end if
if "Back Scripts" is among the items of tSections then
put revIDEBackScripts() into tBackScripts
end if
if "Stacks in use" is among the items of tSections then
put revIDEStacksInUse() into tLibraryStacks
end if
put itemise(tStacks,tFrontScripts,tBackScripts,tLibraryStacks) into sDisplayArray
put topLevelRows(sDisplayArray["objects"]) into tVisibleRows
put tVisibleRows into sDisplayArray["visible object keys"]
## Expanded all previously expanded controls
local tChildRow, tVisibleRowNumber
repeat for each line tExpandedControl in tOldExpandedControls
delete item 2 of tExpandedControl
put sDisplayArray["visible object keys"] into tVisibleRows
if exists(tExpandedControl) then
put getRow(tExpandedControl) into tChildRow
put itemOffset(tChildRow, tVisibleRows) into tVisibleRowNumber
if sDisplayArray["objects"][tChildRow]["childCount"] is not 0 then
addChildren tExpandedControl, tChildRow, false
end if
put "false" into sDisplayArray["objects"][tChildRow]["expanded"]
dispatch "TreeToggleRow" to group "objectList" with sDisplayArray, tVisibleRowNumber, 0, true
end if
end repeat
refreshProjectView
unlock screen
end buildProjectView
on refreshProjectView
updateListeners
--revPutArray sDisplayArray
lock messages
send "RenderView" to group "objectList" of me
unlock messages
ideSelectedObjectChanged
end refreshProjectView
on updateListeners
local tOldTargets, tOldTargetsSet
put the revObjectListeners into tOldTargets
repeat for each line tTarget in tOldTargets
put true into tOldTargetsSet[tTarget]
end repeat
repeat for each key tKey in sDisplayArray["objects"]
get sDisplayArray["objects"][tKey]["long id"]
if it is not empty then
if tOldTargetsSet[it] then
delete variable tOldTargetsSet[it]
else
if exists(it) then
_internal listen to it
end if
end if
end if
end repeat
repeat for each key tKey in tOldTargetsSet
_internal cancel listener for tKey
end repeat
end updateListeners
--on redrawProjectList
-- local tStacks, tFrontScripts, tBackScripts,tRow, tVisibleROws, tChildren
-- local tLibraryStacks, tOldArray,tOldExpandedControls, tOldExpandedRows
-- local tSections
-- put sDisplayArray into tOldArray
-- put tOldArray["visible object keys"] into tVisibleRows
-- repeat with x = 1 to the number of lines in the keys of tOldArray["objects"]
-- if tOldArray["objects"][x]["expanded"] is true then
-- put tOldArray["objects"][x]["long id"] & return after tOldExpandedControls
-- end if
-- end repeat
-- repeat for each line tControl in tOldExpandedControls
-- put getRow(tControl) into tRow
-- put sDisplayArray["objects"][tRow]["children"] & comma after tVisibleRows
-- put true into sDisplayArray["objects"][tRow]["expanded"]
-- end repeat
-- delete the last char of tVisibleRows
-- sort items of tVisibleRows ascending numeric
-- put tVisibleRows into sDisplayArray["visible object keys"]
-- lock messages
-- send "RenderView" to group "objectList" of me
-- unlock messages
--end redrawProjectList
## Returns the stacks and header rows
function topLevelRows pArray
local tTopLevelRows, tLongID
put empty into sLongIDToRow
put empty into sObjectToParent
repeat with x = 1 to the number of elements in pArray
## Mainstacks
if pArray[x]["type"] is "stack" and pArray[x]["level"] is "1" then
put x & comma after tTopLevelRows
end if
## Titles
if pArray[x]["type"] is "section" then
put x & comma after tTopLevelRows
end if
if pArray[x]["style"] is not among the items of "section,library" then
put pArray[x]["long id"] into tLongID
put x into sLongIDToRow[tLongID]
try
put the long id of the owner of tLongID into sObjectToParent[tLongID]
catch pError
end try
else
end if
end repeat
if the last char of tTopLevelRows is comma then delete the last char of tTopLevelRows
return tTopLevelRows
end topLevelRows
########## Selection handlers ##########
####################################
# Indicate that pObjects are selected
command highlightObjects pObjects, pForceScroll
local tVisibleRows,tRow,tRows
put sDisplayArray["visible object keys"] into tVisibleRows
repeat for each line tObject in pObjects
put getRow(tObject) into tRow
if tRow is among the items of tVisibleRows then
put itemOffset(tRow,tVisibleRows) & comma after tRows
end if
end repeat
delete the last char of tRows
if pForceScroll and pObjects is not empty then
scrollToRow(getRow(line 1 of pObjects))
end if
updateSelection tRows
end highlightObjects
## Expands stacks, cards and groups as necessary to show object
command showObjects pObject
local tRow, tRows, tOwners, tOwnerRow, tVisibleRows, tVisibleRowNumber
### Highlight the parent trail
put getOwners(pObject,tOwners) into tOwners
set the cOwners of group "objectList" of me to tOwners
lock screen
repeat for each line tObject in tOwners
## Expand if necessary
put sDisplayArray["visible object keys"] into tVisibleRows
put getRow(tObject) into tRow
if sDisplayArray["objects"][tRow]["expanded"] is not true then
put false into sDisplayArray["objects"][tRow]["expanded"]
addChildren tObject, tRow
put itemOffset(tRow, tVisibleRows) into tVisibleRowNumber
dispatch "TreeToggleRow" to group "objectList" with sDisplayArray, tVisibleRowNumber, 0, true
end if
end repeat
updateActions
unlock screen
end showObjects
on selectObjects pObjectList
// AL-2015-12-17: Don't select objects anymore when they are selected
// in the PB
/*
local tSelectedRows, tObjectList, tVisibleRows
local tCards
put sDisplayArray["visible object keys"] into tVisibleRows
if pObjectList is empty then
put the dvHilitedRows["true"] of group "objectList" of this stack into tSelectedRows
repeat for each item tRow in tSelectedRows
put sDisplayArray["objects"][item tRow of tVisibleRows]["long id"] & return after tObjectList
end repeat
delete the last char of tObjectList
else
put pObjectList into tObjectList
end if
if the last char of tObjectList is return then delete the last char of tObjectList
## If a card or stack is selected we don't want to go to the card
## The user should be able to highlight or expand a card or stack without going to it
if word 1 of tObjectList is "stack" or word 1 of tObjectList is "card" then
exit selectObjects
end if
## Don't go to card if it is part of the project browser
If ideStackOfObject(line 1 of tObjectList) is the long id of me then
exit selectObjects
end if
## Go to correct card as required
lock messages
repeat for each line tObject in tObjectList
if revIDECardOfObject(tObject) is not among the lines of tCards then
put revIDECardOfObject(tObject) & return after tCards
end if
if the last char of tCards is return then delete the last char of tCards
end repeat
if exists(tCards) then
if tCards is not the long id of this card of the topStack then
go tCards
end if
end if
unlock messages
## Select objects
revIDESelectObjects tObjectList
*/
end selectObjects
on selectionChanged pHilitedRows, pPreviouslyHilitedRows
lock screen
local tObjectList, tAbsoluteRow, tStyle, tSelectedTypes
local tContainer, tControl
local tMostRecentRow
repeat for each item tRow in pHilitedRows
if tRow is not among the items of pPreviouslyHilitedRows then
put tRow into tMostRecentRow
end if
end repeat
if the number of items of pHilitedRows <2 then
## If only one item is highlighted then no checks are needed
put getAbsoluteRow(pHilitedRows) into tAbsoluteRow
put sDisplayArray["objects"][tAbsoluteRow]["long id"] into tObjectList
else
put 0 into tContainer
put 0 into tControl
repeat for each item tRow in pHilitedRows
put getAbsoluteRow(tRow) into tAbsoluteRow
put getRowStyle(tAbsoluteRow) into tStyle
if tStyle is "container" then add 1 to tContainer
if tStyle is "control" or tStyle is "group" then
add 1 to tControl
put getAbsoluteRow(tRow) into tAbsoluteRow
put sDisplayArray["objects"][tAbsoluteRow]["long id"] & return after tObjectList
end if
end repeat
end if
## If there is more that one stack or more than one card
if tContainer > 1 then
set the dvHilitedRows of group "objectList" of card 1 of this stack to tMostRecentRow
else
if tObjectList is not empty then
selectObjects tObjectList
end if
end if
unlock screen
end selectionChanged
on goToObject pObjectID
## Don't go to object if it is part of the project browser
If ideStackOfObject(pObjectID) is the long id of me then
exit goToObject
end if
if word 1 of pObjectID is "stack" then
if not the visible of pObjectID then show pObjectID
go pObjectID
else if word 1 of pObjectID is "card" then
if not the visible of the owner of pObjectID then show the owner of pObjectID
go pObjectID
else
go ideStackOfObject(pObjectID)
revIDESelectObjects pObjectID
end if
end goToObject
########### Footer actions ############
####################################
command updateActions
local tSelectedObjects
put pbSelectedObjects() into tSelectedObjects
lock screen
if the number of lines in tSelectedObjects > 1 then
enableFrameItem "alignLeft"
enableFrameItem "alignTop"
enableFrameItem "alignRight"
enableFrameItem "alignBottom"
enableFrameItem "centerX"
enableFrameItem "centerY"
enableFrameItem "equalizeWidth"
enableFrameItem "equalizeHeight"
enableFrameItem "equalizeRect"
enableFrameItem "distributeHorizontally"
enableFrameItem "distributeVertically"
enableFrameItem "newControl"
enableFrameItem "groupControl"
enableFrameItem "cloneControl"
enableFrameItem "deleteControl"
else if the number of lines in tSelectedObjects = 1 then
disableFrameItem "alignLeft"
disableFrameItem "alignTop"
disableFrameItem "alignRight"
disableFrameItem "alignBottom"
disableFrameItem "centerX"
disableFrameItem "centerY"
disableFrameItem "equalizeWidth"
disableFrameItem "equalizeHeight"
disableFrameItem "equalizeRect"
disableFrameItem "distributeHorizontally"
disableFrameItem "distributeVertically"
enableFrameItem "newControl"
enableFrameItem "groupControl"
enableFrameItem "cloneControl"
enableFrameItem "deleteControl"
else if tSelectedObjects is empty then
disableFrameItem "alignLeft"
disableFrameItem "alignTop"
disableFrameItem "alignRight"
disableFrameItem "alignBottom"
disableFrameItem "centerX"
disableFrameItem "centerY"
disableFrameItem "equalizeWidth"
disableFrameItem "equalizeHeight"
disableFrameItem "equalizeRect"
disableFrameItem "distributeHorizontally"
disableFrameItem "distributeVertically"
disableFrameItem "newControl"
disableFrameItem "groupControl"
disableFrameItem "cloneControl"
disableFrameItem "deleteControl"
end if
unlock screen
end updateActions
on alignControls pPosition
local tSelectedObjects
put pbSelectedObjects() into tSelectedObjects
revIDEAlignControls tSelectedObjects, pPosition
end alignControls
on centerControls pPosition
local tSelectedObjects
put pbSelectedObjects() into tSelectedObjects
revIDECenterControls tSelectedObjects,pPosition
end centerControls
on equalizeControls pPosition
local tSelectedObjects
put pbSelectedObjects() into tSelectedObjects
revIDEEqualizeControls tSelectedObjects,pPosition
end equalizeControls
on distributeControls pPosition
local tSelectedObjects
put pbSelectedObjects() into tSelectedObjects
revIDEDistributeControls tSelectedObjects,pPosition, "First To Last selected"
end distributeControls
on newControls
local tControls
put pbSelectedObjects() into tControls
lock screen
repeat for each line tControlID in tControls
revIDECloneObjectWithDefaults tControlID
end repeat
unlock screen
end newControls
on groupControls
local tName, tLayer, tList, tGroupID, tControlList
put pbSelectedObjects() into tControlList
revIDEGroupObjects tControlList
if the result is empty and exists(it) then
select it
else
beep
end if
unlock screen
end groupControls
on cloneControls
local tClonedIDs, tControlList
put pbSelectedObjects() into tControlList
lock screen
local tOldDefaultStack
put the defaultStack into tOldDefaultStack
set the defaultStack to revIDEStackOfObject(line 1 of tControlList)
repeat for each line tControlID in tControlList
revIDECloneObject tControlID
put the result & return after tClonedIDs
end repeat
selectObjects tClonedIDs
set the defaultStack to tOldDefaultStack
unlock screen
end cloneControls
on backspaceKey
if the dvIsFieldEditor of the target then
pass backspaceKey
else
deleteControls
end if
end backspaceKey
on deleteControls
local tControlID, tGroupID, tControlList
put pbSelectedObjects() into tControlList
local tAnswerString
put "Are you sure you want to delete these objects?" into tAnswerString
put return & tControlList after tAnswerString
answer tAnswerString with "Cancel" and "OK"
if it is "ok" then
lock screen
revIDEDeleteObjects tControlList
unlock screen
end if
end deleteControls
on lockControls
local tControlList, tUnlocked
put pbSelectedObjects() into tControlList
lock screen
put true into tUnlocked
repeat for each line tControl in tControlList
if the cantSelect of tControl then put false into tUnlocked
exit repeat
end repeat
revIDESetPropertyOfObject tControlList, "cantSelect", not(tUnlocked)
updateObjectRows tControlList, "cantSelect", not(tUnlocked)
unlock screen
end lockControls
on showControls
local tControlList, tVisible
put pbSelectedObjects() into tControlList
lock screen
put true into tVisible
repeat for each line tControl in tControlList
if not the visible of tControl then put false into tVisible
exit repeat
end repeat
revIDESetPropertyOfObject tControlList, "visible", not(tVisible)
updateObjectRows tControlList, "visible", not(tVisible)
unlock screen
end showControls
####### DataView handlers #######
##############################
function NumberOfRows
# return the number of rows in the data view
return the number of items in sDisplayArray["visible object keys"]
end NumberOfRows
command DataForRow pRow, @pDataA, @pTemplateStyle
local theID
# Fill in pDataA with the values for this pRow and specify the row style.
put item pRow of sDisplayArray["visible object keys"] into theId
put sDisplayArray["objects"][theId] into pDataA
switch pDataA["style"]
case "section"
put "section" into pTemplateStyle
break
case "container"
put "container" into pTemplateStyle
break
case "group"
put "group" into pTemplateStyle
break
case "library"
put "library" into pTemplateStyle
break
case "control"
put "control" into pTemplateStyle
break
default
put "control" into pTemplateStyle
end switch
end DataForRow
function CacheKeyForRow pRow
# [OPTIONAL unless data is a tree] Specify a unique key for pRow.
# Only define if you will be reordering rows in the dataview
# By default the row number is used to cache the control for a row.
# If you will be reordering rows in your dataview then you need to provide
# a unique value for the cache key by defining this function and returning a value.
# A database id can work nicely.
local theID
put item pRow of sDisplayArray["visible object keys"] into theId
return (sDisplayArray["objects"][theId]["long id"] && sDisplayArray["objects"][theId]["type"])