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
Expand file tree
/
Copy pathrevseeditorbehavior.livecodescript
More file actions
2930 lines (2438 loc) · 106 KB
/
revseeditorbehavior.livecodescript
File metadata and controls
2930 lines (2438 loc) · 106 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
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 "revSEEditorBehavior"
# Stores the following mapping
# <handler name>,type => string representing the handler type eg PF for private function
# <handler name>,start => line offset to start of handler
# <handler name>,end => line offset to end of handler
# The map is updated whenever scriptCompile is called.
local sHandlerMap
# These two variables store which object the current search was started on, and which#
# object the most recent result was found in respectively.
local sFirstFindObject
local sLastFindObject
constant kMinGutterWidth = 16
# Description
# Sent by the parent when the rect of this group may have changed. Resizes / positions all the controls in this group
# according to the group's current rect.
command resize
local tControls
put the long id of group "Interactive Find" of me into tControls["find"]
put the long id of group "Enter Password" of me into tControls["password"]
put the long id of group "Gutter" of me into tControls["gutter"]
put the long id of field "Script" of me into tControls["script"]
local tMyRect, tMyWidth, tMyHeight
put the rect of me into tMyRect
split tMyRect by comma
put tMyRect[3] - tMyRect[1] into tMyWidth
put tMyRect[4] - tMyRect[2] into tMyHeight
local tGutterWidth
if sePrefGet("gutter,linenumbers") then
put max(formattedWidth of field "Numbers" of tControls["gutter"], \
kMinGutterWidth) into tGutterWidth
else
put kMinGutterWidth into tGutterWidth
end if
local tFindHeight
if sePrefGet("editor,findvisible") then
put the formattedheight of tControls["find"] into tFindHeight
else
put 0 into tFindHeight
end if
local tNewRect, tScriptScrollSize
-- Position the main code editing field
put tMyRect[1] + tGutterWidth, tMyRect[2], \
tMyRect[3], tMyRect[4] - tFindHeight into tNewRect
if the rect of tControls["script"] is not tNewRect then
set the rect of tControls["script"] to tNewRect
end if
if the hScrollbar of tControls["script"] then
put the scrollBarWidth of tControls["script"] into tScriptScrollSize
else
put 0 into tScriptScrollSize
end if
-- Position the "find" interface
put tMyRect[1] + tGutterWidth, tMyRect[4] - tFindHeight, \
tMyRect[3], tMyRect[4] into tNewRect
if the rect of tControls["find"] is not tNewRect then
set the topLeft of tControls["find"] to tMyRect[1] + tGutterWidth, tMyRect[4] - tFindHeight
end if
-- Position the gutter
put tMyRect[1], tMyRect[2], tMyRect[1] + tGutterWidth, \
tMyRect[4] - tFindHeight - tScriptScrollSize into tNewRect
if the rect of tControls["gutter"] is not tNewRect then
set the rect of tControls["gutter"] to tNewRect
send "resize" to tControls["gutter"]
end if
-- If the script is encrypted, display the password layer over the
-- top.
if scriptProtected() then
set the loc of tControls["password"] to (item 1 of the loc of me), (item 2 of the loc of tControls["password"])
set the top of tControls["password"] to the top of me + (the height of me div 3)
send "openControl" to tControls["password"]
else
set the right of tControls["password"] to the left of me - 20
end if
-- Ensure that various bits of infrastructure that the user
-- shouldn't see are hidden.
set the right of button "Context Menu" of me to the left of me - 500
set the right of button "revCompileObject" of me to the left of me - 500
end resize
local sUniqueId
# Description
# Sent by the parent when editor group is about to be used for the first time
# Initializes the group. Note that this is also called when there are no more
# objects to edit, this may happen when the user has removed the last object
# from the script editor. This is the reason why this command saves the previous
# context before putting empty into getObjectID().
command initialize
if getObjectID() is not empty then
contextSave
end if
lock screen
textInitialize
call "initialize" to group "Gutter" of me
set the backgroundColor of field "Script" of me to sePrefGet("editor,backgroundcolor")
setHandlersFieldBackColor
set the hScrollbar of field "Script" of me to (sePrefGet("editor,hscrollbar") is "true")
-- See bug 16773. Mac likes an odd scrollbarwidth,
-- Windows requires a scrollbarwidth > 16
set the scrollbarWidth of field "Script" of me to 17
# OK-2009-03-11 : Bug 7499 - The hilite color was previously not being reset to empty on OS X.
# At the same time as fixing this issue, I've made the hilite color a preference in case we decide
# to allow users to configure it in the future.
set the hiliteColor of field "Script" of me to sePrefGet("editor,hilitecolor")
# OK-2008-07-07 : Bug 6748 - Interactive find not remembering last search
if sePrefGet("editor,findvisible") then
call "openControl" to group "Interactive Find" of me
end if
setObjectID empty
put 0 into sUniqueId
unlock screen
end initialize
private command setHandlersFieldBackColor
if there is a field "Handlers" of group "Left Handler List" of group "Left Bar" \
of card "Main" of this stack then
set the backgroundColor of field "Handlers" of group "Left Handler List" of group "Left Bar" \
of card "Main" of this stack to sePrefGet("editor,backgroundcolor")
end if
end setHandlersFieldBackColor
private command initializeFonts
local tFont, tFontSize
put sePrefGet("editor,font") into tFont
put sePrefGet("editor,fontsize") into tFontSize
if the textFont of field "Script" of me is not tFont or \
the textSize of field "Script" of me is not tFontSize then
set the textFont of field "Script" of me to tFont
set the textSize of field "Script" of me to tFontSize
# It is not possible to set the textSize and textFont of styled text that has already
# had its textSize / textFont set once. Therefore to allow textSize / textFont changes
# we have to remove all styling from the script field. Although it seems rather weird, this
# does have to be done *after* the properties have been set to the value required..
set the text of field "Script" of me to the text of field "Script" of me
end if
# Note that the textSize and textFont properties are set on the group overall. The gutter has a
# numbers field and a template numbers field both of which should inherit this value. Other controls
# must have their textFont / textSize explicitly set if they need specific values.
if the textSize of group "Gutter" of me is not tFontSize or \
the textHeight of group "Gutter" of me is not the effective textHeight of field "Script" of me then
set the textSize of group "Gutter" of me to tFontSize
set the textHeight of group "Gutter" of me to the effective textHeight of field "Script" of me
end if
end initializeFonts
# Description
# Sent by the parent when the script editor preferences have been changed.
# Causes the script editor to reread preferences such as font, text size
# and colorization scheme, and update itself according to these.
command reapplyPreferences
lock screen
initializeFonts
textFormatInitialize
colorizationUpdate
scriptColorize "script"
set the backgroundColor of field "Script" of me to sePrefGet("editor,backgroundcolor")
setHandlersFieldBackColor
set the hScrollbar of field "Script" of me to (sePrefGet("editor,hscrollbar") is "true")
updateGutterRequest empty, empty, empty, empty, false, false, true
resize
unlock screen
end reapplyPreferences
local sLastSelections
# Description
# Saves the script editor context of the current object as metadata on that object.
# The context includes such information as vscroll and selected chunk. For selections,
# we save the last char of the selection as metadata on the object, and the full selection
# in memory as a script local. Thus full selections are remembered when switching tabs, but only
# the location of the selection is remembered when opening a new tab or after restarting rev.
private command contextSave
revMetadataSet getObjectID(), "general", "scripteditorvscroll", the vScroll of field "Script" of me
if the long id of the focusedObject is the long id of field "Script" of me then
get the selectedChunk
put word 2 of it & comma & word 4 of it into sLastSelections[getObjectID()]
revMetadataSet getObjectID(), "general", "scripteditorselection", word 4 of it
end if
end contextSave
# Description
# Loads the previously saved context for for current object if one was saved.
private command contextLoad
local tSelection
if sLastSelections[getObjectID()] is not empty then
# If there is a last selection stored in memory, this means the user has previously opened this object
# and is just changing tabs. In this case we remember the entire selection.
put sLastSelections[getObjectID()] into tSelection
else
# If there is no last selection in memory, this means either the user didnt select anything, or they
# have not opened the object yet. In this case we only remember the location of the selection, not what was selected.
# This information is stored as object metadata. In previous versions of the script editor, both the selection start and end
# were stored, but this was changed to store only the selection end. This change is what warrants the extra check.
put revMetadataGet(getObjectID(), "general", "scripteditorselection") into tSelection
# In case the object was last edited with an older version, get rid of any excess selection info.
if the number of items of tSelection > 1 then
put item 2 of tSelection into tSelection
end if
# Form the full selection from what is stored
put (tSelection + 1) & comma & tSelection into tSelection
end if
if tSelection is not empty then
# Try is used here to allow the IDE to add objects to a script editor before opening it
try
select char (item 1 of tSelection) to (item 2 of tSelection) of field "Script" of me
# OK-2009-01-17 : Bug 7601 - Update sLastSelectedChunk here as it will be incorrect until the first selectionChanged message is triggered
setLastSelectedChunk tSelection
end try
end if
local tScroll
put revMetadataGet(getObjectID(), "general", "scripteditorvscroll") into tScroll
if tScroll is not empty then
set the vScroll of field "Script" of me to tScroll
else
set the vScroll of field "Script" of me to 0
end if
end contextLoad
local sHandlerList
local sLastSelectedHandler
command loadScript
# When changing object, the gutter should update its compilation errors. The gutter is updated
# in the call to textSetScriptRaw, however this does not update these errors for efficiency reasons
# so an extra call is made here to make sure the errors are updated.
send "updateCompilationErrors" to group "Gutter" of me
# OK-2008-07-07 : Bug 6746 - When loading a new script, we clear the handler list, this means that if the newly
# loaded script cannot be compiled, a empty handler list will be shown instead of the one from the previous object.
put empty into sHandlerList
put empty into sLastSelectedHandler
# If the current object is password protected, show dialog and disable script field.
if scriptProtected() then
textSetScriptRaw empty
scriptLock
exit loadScript
end if
# If the mode is edit then make sure the script is unlocked.
local tMode
revSEGetMode
put the result into tMode
if tMode is "edit" then
scriptUnlock
end if
local tCachedScript
scriptGetCache getObjectID()
put the result into tCachedScript
lock screen
if tCachedScript is not empty then
# If there is a cached script, this means that the user is coming back to this object from another tab.
textSetScriptRaw tCachedScript
else
local tScript
put the script of getObjectID() into tScript
textSetScriptRaw tScript
# OK-2008-07-07 : Bug 6746
seUpdateCheckSum getObjectID(), tScript
if tScript is empty then
select before field "Script" of me
end if
end if
# The lock messages is required, because otherwise an exitField is received before the contextLoad
# can execute, causing the context to be overwritten just before we load it. Not currently sure why
# this happens...
lock messages
contextLoad
unlock messages
# As we have changed the selection, update the rest of the script editor to reflect this
--selectionUpdateRequest
# OK-2008-08-14 : In this case, do the selection update immediately, not in time.
selectionUpdate
end loadScript
command selectionUpdate
lock screen
findClearResults
if the lockText of field "Script" of me is false then
deSelectLastGoneToLine
end if
# Tell the script editor to update its panes. This is called here in particular
# for the documentation pane to update itself when the user selects a new term.
paneUpdateRequest
# Update the variables that store the last selected line and handler list
updateHandlerList
updateSelectedHandler
contextSave
# Update the toolbar so that the handlers list can reflect the new selection. For efficiency we pass
# a parameter to the update command which tells it that the selected handler can be assumed to be
# up to date, so it doesn't need to evaluate it again (as we just updated it).
local tTrueString
put "true" into tTrueString
# OK-2009-10-05: Optimized this a little. The previous call to update was doing quite a bit of stuff
# that is not required here. I factored out the stuff that we actually need into a new method, which
# is now called instead.
-- send "update tTrueString" to group "Toolbar" of stack (revTargetStack(the long id of me))
send "updateSelectedHandler tTrueString" to group "Toolbar" of stack (revTargetStack(the long id of me))
# Update the left bar in the same way as the toolbar is updated
# OK-2009-10-05: Some more optimization here, the update method was doing a lot of stuff that is not
# needed, so I added a more specific method to handle this situation.
send "updateSelectedHandler" to group "Left Bar" of stack (revTargetStack(the long id of me))
unlock screen
pass selectionUpdate
end selectionUpdate
# Parameters
# pObjectId : reference to the object to set the script to. Must be one of the target objects of the script editor.
# Description
# Sets the current target object of the editor group.
command setObject pObjectId, pDontSendCallbacks
local tRuggedObjectId
put seGetRuggedId(pObjectId) into tRuggedObjectId
if getObjectID() is not empty and tRuggedObjectId is getObjectID() then
if not pDontSendCallbacks then
seSendCallbacks getObjectID(), the name of stack (revTargetStack(the long id of me))
end if
exit setObject
end if
# If we are closing a previous object and the script has not been applied,
# cache the script of the previous object internally, and save the context
if getObjectID() is not empty then
cacheScript getObjectID(), textGetScript()
if there is a getObjectID() then
contextSave
end if
end if
lock screen
# It appears that changing the text of the field does not remove all styles,
# so it is necessary to reset the fonts here, otherwise when changing tabs after the textSize has
# been changed, the the textSize will appear to revert back to what it was previously.
initializeFonts
findClearResults
EditorFieldCacheSwap getObjectID(), tRuggedObjectId
setObjectID tRuggedObjectId
loadScript
resize
unlock screen
if not pDontSendCallbacks then
seSendCallbacks getObjectID(), the name of stack (revTargetStack(the long id of me))
end if
end setObject
# Description
# Reverts the script of the current object to the last applied version
command revertObject
loadScript
seSetObjectState getObjectID(), "applied"
end revertObject
# Parameters
# pObjectId : reference to the object to set the script to. Must be the same object as is currently set.
# Description
# Sets the object being edited to the specified object *without* changing the script. This should be called
# when the object being edited has changed ids, been moved to a new stack etc, anything that might change
# its rugged id. It should not be called outside this situation as stuff will break.
command setObjectRaw pObjectId
local tOldObjectId
put getObjectID() into tOldObjectId
setObjectID pObjectId
if tOldObjectId is empty then
exit setObjectRaw
end if
updateObjectID tOldObjectID, getObjectID()
# Find results
if sLastFindObject is tOldObjectId then
put getObjectID() into sLastFindObject
end if
if sFirstFindObject is tOldObjectId then
put getObjectID() into sFirstFindObject
end if
end setObjectRaw
# Description
# Returns a reference to the current object being edited.
command getObject
return getObjectID()
end getObject
# Parameters
# pDontUpdate : if true, the selected handler is assumed to be up to date and the stored one is just returned.
# Description
# Returns the last selected handler of the current object
command getSelectedHandler pDontUpdate
if pDontUpdate is not "true" then
updateSelectedHandler
end if
return sLastSelectedHandler
end getSelectedHandler
# Parameters
# pLineNumber : a line number in the current script
# Returns
# Either the name and type of the handler if pLineNumber falls inside a handler
# or empty. Uses revAvailableHandlers so only works with compiled scripts. Note that this function
# assumes that the handler list has been updated before its called. This is for efficiency purposes.
private function handlerContainingLine pLineNumber
# If we have no available handlers empty must be the correct result.
if sHandlerList is empty then
return empty
end if
local tHandlers
put sHandlerList into tHandlers
# Otherwise, calculate the selected handler, and return it.
local tMatchingHandlerName, tMatchingHandlerType
repeat for each line tHandler in tHandlers
if word 3 of tHandler > pLineNumber then
next repeat
end if
if word 4 of tHandler < pLineNumber then
next repeat
end if
put word 2 of tHandler into tMatchingHandlerName
put word 1 of tHandler into tMatchingHandlerType
exit repeat
end repeat
if tMatchingHandlerName is empty then
return empty
end if
if char 1 of tMatchingHandlerType is "P" then
delete char 1 of tMatchingHandlerType
end if
return (tMatchingHandlerType & comma & tMatchingHandlerName)
end handlerContainingLine
# Description
# Updates the sLastSelectedHandler variable to contain the details of the handler that was last
# selected by the user. NOTE: this command assumes that the handler list is up to date at the time of calling.
# If the handler list may not be up to date, use updateHandlerList to ensure it is first. The reason this is the case
# is so that this command and updateHandlerList can both be called without needing to update the handler list twice.
private command updateSelectedHandler
# If we have no selected line in the script field, then don't update the variable, leave the last value intact
local tLine
put word 2 of the selectedLine into tLine
if tLine is empty or the long id of the focusedObject() is not the long id of getScriptField() then
exit updateSelectedHandler
end if
local tMatchingHandler
put item 2 of handlerContainingLine(tLine) into tMatchingHandler
# For now, if the selection is outside any handler, we don't update the variable.
if tMatchingHandler is empty then
exit updateSelectedHandler
end if
put tMatchingHandler into sLastSelectedHandler
end updateSelectedHandler
# Description
# Returns the handler list of the current object
command getHandlerList
updateHandlerList
return sHandlerList
end getHandlerList
private command updateHandlerList
scriptCompile getObjectID()
end updateHandlerList
# Parameters
# pObjectId : reference to the object to set the script to. Must be one of the target objects of the script editor.
# Description
# Clears the script cache for the specified object. This should be called when the object is being closed. The cache also
# includes selection information.
command clearCache pObject, pDontCheckId
local tObject
if pDontCheckId then
put pObject into tObject
else
put seGetRuggedId(pObject) into tObject
end if
delete variable sLastSelections[tObject]
pass clearCache
end clearCache
# Description
# Locks the script to prevent the uesr from editing it. Used by the debugger.
command scriptLock
set the lockText of field "Script" of me to true
set the backgroundColor of field "Script" of me to sePrefGet("editor,debugBackgroundcolor")
set the backgroundColor of field "Handlers" of group "Left Handler List" of group "Left Bar" \
of card "Main" of this stack to sePrefGet("editor,debugBackgroundcolor")
end scriptLock
# Description
# Unlocks the script, allowing the user to edit it.
command scriptUnlock
set the lockText of field "Script" of me to false
set the backgroundColor of field "Script" of me to sePrefGet("editor,backgroundColor")
setHandlersFieldBackColor
end scriptUnlock
# Returns
# Whether or not the current object script is password protected.
private function scriptProtected
# Prevent errors when editing the script editor.
if getObjectID() is empty then
return false
end if
local tStack
put revTargetStack(getObjectID()) into tStack
# think this may be wrong...
-- if the passKey of stack tStack is not the password of stack tStack then
-- return true
-- else
-- return false
-- end if
try
get the script of stack tStack
return false
catch tError
return true
end try
end scriptProtected
# Description
# Shows error indicators for the specified compilation errors
command setCompilationErrors pErrors, pObject
send "setCompilationErrors pErrors, pObject" to group "Gutter" of me
if seGetRuggedId(pObject) is getObjectID() then
updateGutterRequest empty, empty, empty, empty, false, true
end if
end setCompilationErrors
# OK-2009-03-03 : Bug 7450
# Parameters
# pName : the name of a handler
# pProposedPosition : the suggested start line of the handler (i.e was returned by the revAvailableHandlers)
# pType : the handler type code (e.g "F", "PM" etc)
# Returns
# The line number that the handler was located at, or empty if it could not be found.
command locateHandler pName, pProposedPosition, pType
local tScript
put the text of field "Script" of me into tScript
local tStartLine
put line pProposedPosition of tScript into tStartLine
local tSyntaxOptions
put convertTypeCodeToSyntax(pType, pName) into tSyntaxOptions
# Unknown handler type, this is a bug in whatever called this command.
if tSyntaxOptions is empty then
return empty
end if
repeat for each line tSyntax in tSyntaxOptions
if word 1 to (the number of words of tSyntax) of tStartLine is tSyntax and word (the number of words of tSyntax + 1) of tStartLine is pName then
return pProposedPosition
end if
end repeat
# If we got here, it means the handler was no longer at the location proposed. This is probably because the handler
# was moved and at the same time the script was made invalid. We search for the handler manually instead.
# As this case will not happen too often, it is not optimized for now.
local tLineNumber
put 1 into tLineNumber
repeat for each line tLine in tScript
repeat for each line tSyntax in tSyntaxOptions
if word 1 to (the number of words of tSyntax) of tLine is tSyntax and word (the number of words of tSyntax + 1) of tLine is pName then
return tLineNumber
end if
end repeat
add 1 to tLineNumber
end repeat
# Could not be found, in this case the script editor will get the wrong line...
return pProposedPosition
end locateHandler
private function convertTypeCodeToSyntax pTypeCode
local tSyntax
switch pTypeCode
case "F"
return "function"
break
case "PF"
return "private function"
break
case "M"
return "on" & return & "command"
break
case "PM"
return "private on" & return & "private command"
break
case "G"
return "getprop"
break
case "S"
return "setprop"
break
case "B"
return "before"
break
case "A"
return "after"
break
default
return empty
end switch
end convertTypeCodeToSyntax
# Parameters
# pObject : reference to the object to compile the script of. Must be one of the target objects.
# Description
# Attempts to compile the specified script. Does not apply it to the target object, instead
# creates a temporary object and attemps to set the script of that. If compilation is successful
# stores a map of handler names to line numbers for later use.
# Returns
# Empty if compilation suceeded, otherwise a list of errors.
command scriptCompile pObject
lock screen
lock messages
local tOldPreserveVariables, tOldExplicitVariables
put the preserveVariables into tOldPreserveVariables
put the explicitVariables into tOldExplicitVariables
set the preserveVariables to sePrefGet("preserveVariables")
set the explicitVariables to sePrefGet("explicitVariables")
local tScript
scriptGet pObject
put the result into tScript
local tResult
local tDoUpdateDescription
set the script of button "revCompileObject" of me to tScript
put the result into tResult
-- if setting the script failed with explicit vars try without
if tResult is not empty and the explicitVariables then
set the explicitVariables to false
set the script of button "revCompileObject" of me to tScript
put the result is empty into tDoUpdateDescription
else
put tResult is empty into tDoUpdateDescription
end if
if tDoUpdateDescription then
--! TODO remove use of revAvailableHandlers here (quite invasive)
put the revAvailableHandlers of button "revCompileObject" of me into sHandlerList
get getObjectID()
if exists(it) and revEnvironmentEditionProperty("autocomplete") then
ideAutocompleteUpdateScriptDescription it, the revScriptDescription of button "revCompileObject" of me
end if
end if
local tLiveErrors
put sePrefGet("editor,liveerrors") into tLiveErrors
put tLiveErrors and not the lockText of field "script" of me into tLiveErrors
local tState
getDirty pObject
if the result then
put "edited" into tState
else
put "applied" into tState
end if
if tLiveErrors then
send "clearErrors" to group "Errors" of the owner of me
if tResult is empty then
setCompilationErrors empty, pObject
else
send "addError compilation, line 1 of tResult, pObject" to group "Errors" of the owner of me
setCompilationErrors line 1 of tResult, pObject
put "error" into tState
end if
else
send "clearErrors" to group "Errors" of the owner of me
if tResult is empty then
setCompilationErrors empty, pObject
else
send "addError compilation, line 1 of tResult, pObject" to group "Errors" of the owner of me
setCompilationErrors line 1 of tResult, pObject
put "error" into tState
end if
end if
seSetObjectState pObject, tState
set the preserveVariables to tOldPreserveVariables
set the explicitVariables to tOldExplicitVariables
# The script should be unset because it could cause issues with idle handlers
set the script of button "revCompileObject" of me to empty
unlock messages
unlock screen
return tResult
end scriptCompile
# Description
# Shows the interactive find dialog and focuses the appropriate control for the user to enter text.
# The dialog remains visible until the user closes it.
command goInteractiveFind
sePrefSet "editor,findvisible", "true"
resize
send "openControl" to group "Interactive Find" of me
end goInteractiveFind
command hideInteractiveFind
sePrefSet "editor,findvisible", "false"
resize
send "closeControl" to group "Interactive Find" of me
end hideInteractiveFind
################################################################################
#
# End of editor object interface. Code below here is part of the object's internal
# workings and should not be accessed from outside.
#
################################################################################
--local sMetricGutterSize
--local sMetricGutterNumbersMargin
--local sMetricGutterOverlayMargin
# Parameters
# pLineNumber : the number of a line in the current script
# Returns
# The number of line with next available for a breakpoint from pLineNumber
# Description
# If line pLineNumber can have a breakpoint, then pLineNumber is returned.
# Otherwise the function iterates down until it finds a line that is not in
# a comment or a variable declaration. This does not take multi-line comments
# into account at the moment. Returns empty if no line can be found.
function nextAvailableBreakpoint pLineNumber
local tMatchingLineNumber
local tCurrentLineNumber
put pLineNumber - 1 into tCurrentLineNumber
local tText
put line pLineNumber to -1 of textGetScript() into tText
repeat for each line tCurrentLine in tText
add 1 to tCurrentLineNumber
# Detect if the line is a comment or the line is whitespace
if token 1 of tCurrentLine is empty then
next repeat
end if
# Detect if the line is a variable declaration
if token 1 of tCurrentLine is among the words of "local global" then
next repeat
end if
put tCurrentLineNumber into tMatchingLineNumber
exit repeat
end repeat
return tMatchingLineNumber
end nextAvailableBreakpoint
private function getUniqueId
add 1 to sUniqueId
return sUniqueId
end getUniqueId
private command gutterResize pRect
set the rect of group "Gutter" of me to pRect
send "resize" to group "Gutter" of me
end gutterResize
private command colorizationUpdate
local tClasses, tKeywords
put seColorizationConfigClasses() into tClasses
put seColorizationConfigKeywords() into tKeywords
_internal script configure classes tClasses
_internal script configure keywords tKeywords
end colorizationupdate
# For debugging only, remove at some point
private function arrayShow pArray
local tKeys
put the keys of pArray into tKeys
sort tKeys
local tText
repeat for each line tKey in tKeys
put tKey & tab & pArray[tKey] & return after tText
end repeat
delete the last char of tText
return tText
end arrayShow
command textInitialize
initializeFonts
seColorizationInit
colorizationUpdate
EditorFieldCacheFlushAll
pass textInitialize
end textInitialize
# Description
# Updates the gutter according to the specified parameters.
command updateGutterDo
local tOffset, tSelectedLine, tOldLines, tNewLines, tTextChanged
local tDetails
put getUpdateGutterRequestDetails() into tDetails
put tDetails["offset"] into tOffset
put tDetails["selectedLine"] into tSelectedLine
put tDetails["oldLines"] into tOldLines
put tDetails["newLines"] into tNewLines
put tDetails["textChanged"] into tTextChanged
local tUpdateCompilationErrors
put tDetails["updateCompilationErrors"] into tUpdateCompilationErrors
local tForceBreakpointRedraw
put tDetails["forceBreakpointRedraw"] into tForceBreakpointRedraw
send "update tOffset, tSelectedLine, tOldLines, tNewLines, tTextChanged, tUpdateCompilationErrors, tForceBreakpointRedraw" to group "Gutter" of me
# Once an update has been carried out, we reset the sGutterUpdateRequestDetails array
deleteUpdateGutterRequestDetails
end updateGutterDo
################################################################################
# Description
# Called when the script editor is about to be closed.
command finalize
cancelPendingMessages
if there is a getObjectID() then
contextSave
end if
_internal script flush field "Script" of me
end finalize
# Description
# Sets some state variables that may be needed to update the script editor panes
# and calls the sePanesUpdate command to do the update.
command paneUpdate
sePanesUpdate
end paneUpdate
local sLastSelectedGoneToChunk
local sLastGoneToLine
# Parameters
# pLine : a line number to go to, from 1 up to the number of lines in the current script.
# pHighlightMode : How to highlight the specified line. If this is false or not specified, the line is not highlighted.
# Description
# Goes to the specified line and highlights if required. The highlight mode is either false / empty for no highlight
# or "select" to select the line or "color" to set the line's background color. A value of "true" is treated the same
# as "select".
command goLine pLine, pHighlightMode, pPosition
local tScroll
put the vScroll of field "Script" of me into tScroll
# OK-2008-08-25 : Bug 7013 - Preserve horizontal scroll
local tHScroll
put the hScroll of field "Script" of me into tHScroll
# Select the line according to the value of pHighlight
lock messages
if pHighlightMode is "true" or pHighlightMode is "select" then
select line pLine of field "Script" of me
get the selectedChunk
put word 2 of it & comma & word 4 of it into sLastSelectedGoneToChunk
else if pHighlightMode is "color" then
set the backgroundColor of line pLine of field "Script" of me to sePrefGet("editor,selectbackgroundcolor")
local tStart
put the number of chars of line 1 to (pLine - 1) of field "Script" of me + 1 into tStart
put tStart & comma & tStart + the number of chars of line pLine of field "Script" of me into sLastSelectedGoneToChunk
else if pHighlightMode is "position" then
# OK-2009-03-03 : Bug 7550 - Allow for particular chars to be highlighted for better error display
local tEnd
put item 1 of pPosition into tStart
put item 2 of pPosition into tEnd
# As typically Revolution errors only have a start char, and every after that gets ignored,
# if no end is specified, we highlight from the start char to the end of the line.
if tEnd is empty then
put the number of chars of line pLine of field "Script" of me into tEnd
end if
select char tStart to tEnd of line pLine of field "Script" of me
get the selectedChunk
put word 2 of it & comma & word 4 of it into sLastSelectedGoneToChunk
else if pHighlightMode is "after" then
put empty into sLastSelectedGoneToChunk
select after line pLine of field "Script" of me
else
put empty into sLastSelectedGoneToChunk
select before line pLine of field "Script" of me
end if
unlock messages
# Scroll until the line is centred (assumes fixed line height)
if the vScroll of field "Script" of me > tScroll then
# The field has scrolled down in order to show the selection, therefore
# we need to make it scroll down again to centre it.
set the vScroll of field "Script" of me to the vScroll of field "Script" of me + round(the height of field "Script" of me / 2)
else if the vScroll of field "Script" of me < tScroll then
# The field has scrolled up in order to show the selection, therefore
# we need to make it scroll up again to centre it.
set the vScroll of field "Script" of me to the vScroll of field "Script" of me - round(the height of field "Script" of me / 2)
end if
set the hScroll of field "Script" of me to tHScroll
put pLine into sLastGoneToLine
updateGutterRequest empty, empty, empty, empty, false, false
end goLine
function getLastGoneToLine
return sLastGoneToLine
end getLastGoneToLine