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 pathrevcommonlibrary.livecodescript
More file actions
1581 lines (1367 loc) · 57.7 KB
/
revcommonlibrary.livecodescript
File metadata and controls
1581 lines (1367 loc) · 57.7 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 "revcommonlibrary"
on extensionInitialize
if the target is me then
insert the script of me into back
end if
end extensionInitialize
on extensionFinalize
if the target is me then
remove the script of me from back
end if
end extensionFinalize
function revTargetStack pWhich
local tParse
if pWhich is not empty and there is a pWhich and word 1 of pWhich is not "the"
then put the long id of pWhich into tParse
else put the long id of the target into tParse
get wordOffset("stack",tParse)
local tStackName
put word (it) to (it+1) of tParse into tStackName
put the short name of tStackName into tStackName
return tStackName
end revTargetstack
# OK-2008-03-24 : Bug 6186
on revGoURL pUrl
global gREVWebBrowser
revSetWindowsShellCommand
local tNT
put revRunningWindowsNT() into tNT
if "file://" is not in pUrl then
replace "file:/" with "file:///" in pUrl
end if
if char 1 to 4 of pUrl is not "file" \
and char 1 to 4 of pUrl is not "http" \
and char 1 to 7 of pUrl is not "mailto:" \
and char 1 to 3 of pUrl is not "ftp" \
and char 1 to 4 of pUrl is not "feed" then
put "http://" before pUrl
end if
launch url pUrl
end revGoURL
on revGoPDF pFilename
launch document pFilename
end revGoPDF
# TH-2008-06-27 :: Bug 6521/6432, have seperated revMail into two alternative handlers. revMailUnicode
# should be ussed by people sending unicode characters, the original revMail can be used otherwise
command revMail pTo, pCC, pSubject, pBody
if the environment is "mobile" then
mobileComposeMail pSubject, pTo, pCC, , pBody
else
revMailUnicode pTo, pCC, uniEncode(pSubject), uniEncode(pBody)
end if
end revMail
command revMailUnicode pTo, pCC, pSubject, pBody
put uniDecode(pSubject, "UTF8") into pSubject
put uniDecode(pBody, "UTF8") into pBody
put urlEncode(pSubject) into pSubject
put urlEncode(pBody) into pBody
replace "+" with "%20" in pSubject
replace "+" with "%20" in pBody
local tURL
if the paramcount is 1 then
put "mailto:" & pTo into tURL
else
local tCC, tSubject, tBody
if pCC is not empty then put true into tCC
if pSubject is not empty then put true into tSubject
if pBody is not empty then put true into tBody
put "mailto:" & pTo into tURL
if tCC then
if (tURL contains "?Subject=") or (tURL contains "?Body=") then
put "&" & "CC=" & pCC after tURL
else
put "?" & "CC=" & pCC after tURL
end if
end if
if tSubject then
if (tURL contains "?CC=") or (tURL contains "?Body=") then
put "&" & "Subject=" & pSubject after tURL
else
put "?" & "Subject=" & pSubject after tURL
end if
end if
if tBody then
if (tURL contains "?CC=") or (tURL contains "?Subject=") then
put "&" & "Body=" & pBody after tURL
else
put "?" & "Body=" & pBody after tURL
end if
end if
# TH-2008-08-05 :: Bug fix added if statement 6865
if tCC or tBody or tSubject then
put "&Content-Type:text/plain;"&"charset=utf-8" after tURL
end if
end if
if the platform is not "win32" then
launch url tURL
else
local tMailApp
put queryRegistry("HKEY_CLASSES_ROOT\mailto\shell\open\command\") into tMailApp
replace quote & "%1" & quote with tURL in tMailApp
replace "%1" with tURL in tMailApp
replace "%ProgramFiles%" with $ProgramFiles in tMailApp
if the length of tMailApp > 32767 then
return "message too long"
end if
open process tMailApp for neither
end if
end revMailUnicode
function revRunningWindowsNT
if the platform is not "Win32" then return false
if word 1 of the systemVersion is "Windows"
then return false
else return true
end revRunningWindowsNT
on revSetWindowsShellCommand
if the platform is not "Win32" then exit revSetWindowsShellCommand
set the hideConsoleWindows to true
if $COMSPEC is not empty then set the shellCommand to $COMSPEC
else
--just in case some windows versions don't use $COMSPEC
if revRunningWindowsNT() then set the shellCommand to "cmd.exe"
else set the shellCommand to "command.com"
end if
end revSetWindowsShellCommand
getProp revProfile
return the cREVGeneral["profile"] of the target
end revProfile
getProp cREVGeneral[pWhichProp]
if pWhichProp is "revUniqueID" then
lock messages
local tRevUniqueID
put the cREVGeneral["revUniqueID"] of the target into tRevUniqueID
unlock messages
if tRevUniqueID is empty then
put the milliseconds into tRevUniqueID
set the cREVGeneral["revUniqueID"] of the target to tRevUniqueID
end if
return tRevUniqueID
end if
# OK-2009-02-11 : Global not declared...
global gREVSuppressMessages
if pWhichProp is not "profile" then if not gREVSuppressMessages or (gREVSuppressMessages and revOKTarget()) then pass cREVGeneral
lock messages
local tProfile
put the cREVGeneral["profile"] of the target into tProfile
if tProfile is empty or tProfile is the cREVGeneral["masterName"] of the target then put "Master" into tProfile
unlock messages
return tProfile
end cREVGeneral
setProp revProfile pWhich
set the cREVGeneral["profile"] of the target to pWhich
end revProfile
setProp cREVGeneral[pWhichProp] pWhichProfile
local tTarget
put the long id of the target into tTarget
if pWhichProp is not "profile" and pWhichProp is not "inLineImages" and \
pWhichProp is not "virtualWidth" and pWhichProp is not "virtualHeight" \
then pass cREVGeneral
if pWhichProp is "virtualWidth" then
lock messages
local tOriginalWidth
put the cREVGeneral["virtualWidth"] of tTarget into tOriginalWidth
set the cREVGeneral["virtualWidth"] of tTarget to pWhichProfile
local tDifference
put tOriginalWidth - pWhichProfile into tDifference
local tRect
put the rect of stack revTargetStack() into tRect
put item 3 of tRect + tDifference into item 3 of tRect
set the rect of stack revtargetStack() to tRect
unlock messages
exit cREVGeneral
end if
if pWhichProp is "virtualHeight" then
lock messages
local tOriginalHeight
put the cREVGeneral["virtualHeight"] of tTarget into tOriginalHeight
set the cREVGeneral["virtualHeight"] of tTarget to pWhichProfile
put tOriginalHeight - pWhichProfile into tDifference
put the rect of stack revTargetStack() into tRect
put item 4 of tRect + tDifference into item 4 of tRect
set the rect of stack revtargetStack() to tRect
unlock messages
exit cREVGeneral
end if
if pWhichProp is "inLineImages" then
if pWhichProfile is true then
lock messages
lock screen
set the lockLocation of the templateGroup to true
set the rect of the templateGroup to item 1 to 2 of the rect of tTarget,item 3 of the rect of tTarget-the scrollbarWidth of tTarget,item 4 of the rect of tTarget
set the name of the templateGroup to the short name of tTarget&"images"&the number of this cd
create group
reset the templateGroup
local tGroupName
put the short name of tTarget & "images"&the number of this cd into tGroupName
--now pad the group so it can scroll
reset the templateGraphic
set the style of the templateGraphic to "line"
set the lineSize of the templateGraphic to 0
set the topLeft of the templateGraphic to the topLeft of tTarget
create grc in group tGroupName
reset the templateGraphic
set the scroll of group tGroupName to 0
set the scroll of tTarget to 0
set the cREVGeneral["preInlineText"&the number of this cd] of tTarget to the text of tTarget
set the itemDel to "/"
local tSubtract
put 0 into tSubtract
local tFinalExit
repeat
if tFinalExit then exit repeat
local tLineCount
put 0 into tLineCount
set the scroll of group tGroupName to 0
set the scroll of tTarget to 0
repeat for each line l in the text of tTarget
put true into tFinalExit
add 1 to tLineCount
if item 2 of l is "*IMAGEFILE*" then
do "put empty into line tLineCount of" && tTarget
reset the templateImage
set the fileName of the templateImage to item 3 to -1 of l
local tFieldName
put the short name of tTarget into tFieldName
local tTop
put (the formattedHeight of line 1 to tLineCount of fld tFieldName + the top of tTarget) into tTop
set the width of the templateImage to the formattedWidth of the templateImage
local tImageHeight
put the formattedHeight of the templateImage into tImageHeight
set the height of the templateImage to tImageHeight
set the lockLoc of the templateImage to true
set the topLeft of the templateImage to the left of tTarget+8,tTop-tSubtract
create image in group tGroupName
local tNewLines
put 0 into tNewLines
repeat
add 1 to tNewLines
put cr after line tLineCount of the target
if the formattedHeight of line tLineCount to tLineCount+tNewLines of fld tFieldName >= tImageHeight then exit repeat
end repeat
put cr after line tLineCount of the target
put false into tFinalExit
exit repeat
end if
if item 2 of l is "*IMAGEID*" then
do "put empty into line tLineCount of" && tTarget
reset the templateButton
set the showName of the templateButton to false
set the showBorder of the templateButton to false
set the traversalOn of the templateButton to false
set the autoHilite of the templateButton to false
set icon of the templateButton to item 3 to -1 of l
put the short name of tTarget into tFieldName
put (the formattedHeight of line 1 to tLineCount of fld tFieldName + the top of tTarget) into tTop
set the width of the templateButton to the formattedWidth of the templateButton
put the formattedHeight of the templateButton into tImageHeight
set the height of the templateButton to tImageHeight
set the lockLoc of the templateButton to true
set the topLeft of the templateButton to the left of tTarget+8,tTop-tSubtract
create button in group tGroupName
put 0 into tNewLines
repeat
add 1 to tNewLines
put cr after line tLineCount of the target
if the formattedHeight of line tLineCount to tLineCount+tNewLines of fld tFieldName >= tImageHeight then exit repeat
end repeat
put cr after line tLineCount of the target
put false into tFinalExit
exit repeat
end if
end repeat
put 30 into tSubtract
end repeat
reset the templateButton
reset the templateImage
--now pad the group so it can scroll
local tFieldHeight
put the formattedHeight of fld tFieldName into tFieldHeight
reset the templateGraphic
set the style of the templateGraphic to "line"
set the lineSize of the templateGraphic to 0
set the topLeft of the templateGraphic to the left of tTarget,tFieldHeight+the top of tTarget
create grc in group tGroupName
reset the templateGraphic
set the scroll of group tGroupName to 0
set the scroll of the target to 0
unlock screen
unlock messages
else
delete group (the short name of tTarget&"images"&the number of this cd)
set the text of tTarget to the cREVGeneral["preInlineText"&the number of this cd] of tTarget
set the cREVGeneral["preInlineText"&the number of this cd] of tTarget to empty
end if
set the cREVGEneral["inLineImages"&the number of this cd] of tTarget to pWhichProfile
exit cREVGeneral
end if --inLineImages
-- pWhichProp is "profile"
global gREVProfileReadOnly, gREVAutoCreateProfiles
lock screen
lock messages
local tReturnSet
put the customPropertySet of tTarget into tReturnSet
set the cREVGeometryCache["order"] of this card to empty
if the customkeys["cRevGeometry"] of tTarget is not empty then
if "revUpdateGeometry" is in the pendingMessages then
cancel item 1 of line (lineOffset("revUpdateGeometry",the pendingMessages)) of the pendingMessages
end if
send "revUpdateGeometry" to stack revTargetStack(tTarget) in 250 milliseconds -- update geometry
end if
if pWhichProfile is not empty and pWhichprofile is not "master" and pWhichProfile is not the cREVGeneral["masterName"] of tTarget and pWhichProfile is not among the lines of the cREVGeneral["profileList"] of tTarget then
if gREVAutoCreateProfiles then revNewProfile pWhichProfile, tTarget
unlock screen
unlock messages
exit cREVGeneral
end if
if the cREVGeneral["profile"] of tTarget is "Master" or the cREVGeneral["profile"] of tTarget is empty or the cREVGeneral["profile"] of tTarget is the cREVGeneral["masterName"] of tTarget then
--its in master, going out
if not gREVProfileReadOnly then
set the customPropertySet of tTarget to "cREVTempMaster"
local tTempArray
put the properties of tTarget into tTempArray
set the customProperties of tTarget to tTempArray
end if
else
--its another profile, going into or through master
set the customPropertySet of tTarget to "cREVMaster"
local tCurrentMasterArray
if the customKeys["cREVMaster"] of tTarget is not empty then put the customProperties of tTarget into tCurrentMasterArray
if not gREVProfileReadOnly then
set the customPropertySet of tTarget to "cREVTempMaster"
local tTempMasterArray
put the customProperties of tTarget into tTempMasterArray
local tCurrentPropertiesArray
put the properties of tTarget into tCurrentPropertiesArray
--compare the temporary master with the current properties
--any changes:
--the original tempMaster value gets added to the current master array
--and the new value gets created in the current profile array
local tCurrentPropertyKeys
put keys(tCurrentPropertiesArray) into tCurrentPropertyKeys
set the caseSensitive to true
repeat for each line l in tCurrentPropertyKeys
if tTempMasterArray[l] is not tCurrentPropertiesArray[l] then
put tTempMasterArray[l] into tCurrentMasterArray[l]
local tProfileArray
put tCurrentPropertiesArray[l] into tProfileArray[l]
end if
end repeat
--transfer the current profile array to the object
set the customPropertySet of tTarget to "cREVDiverged" & the cREVGeneral["profile"] of tTarget
set the customProperties of tTarget to tProfileArray
--now transfer the current master array to the master profile
set the customPropertySet of tTarget to "cREVMaster"
set the customProperties of tTarget to tCurrentMasterArray
end if
# MW-2010-10-14: [[ Bug 9060 ]] In 4.5 the 'id' property of objects became mutable - we never
# want to set this property as part of a profile, so make sure its never in the array.
delete variable tCurrentMasterArray["id"]
set the properties of tTarget to tCurrentMasterArray
set the cREVGeneral["profile"] of tTarget to "Master"
end if
if pWhichProfile is not empty and pWhichProfile is not "master" and pWhichProfile is not the cREVGeneral["masterName"] of tTarget then
set the cREVGeneral["profile"] of tTarget to pWhichProfile
set the customPropertySet of tTarget to "cREVDiverged"&pWhichProfile
local tTempArray1
if the customKeys of tTarget is not empty then put the customProperties of tTarget into tTempArray1
# MW-2010-10-14: [[ Bug 9060 ]] In 4.5 the 'id' property of objects became mutable - we never
# want to set this property as part of a profile, so make sure its never in the array.
delete variable tTempArray1["id"]
set the properties of tTarget to tTempArray1
end if
set the customPropertySet of tTarget to tReturnSet
unlock screen
unlock messages
end cREVGeneral
function revAppVersion
return the version
end revAppVersion
function revLoadedStacks pWhich
global gREVShowStacks
local tMainstacks
put the mainStacks into tMainStacks
switch pWhich
case "all"
break
case "preference"
if not gREVShowStacks
then put revFilterStacksList(tMainStacks) into tMainStacks --filters LiveCode stacks
break
default
put revFilterStacksList(tMainStacks) into tMainStacks
end switch
local tStacksInMemory
put empty into tStacksInMemory
repeat for each line l in tMainStacks
if the substacks of stack l is empty
then put l & cr after tStacksInMemory
else put l & cr & the substacks of stack l & cr after tStacksInMemory
end repeat
delete last char of tStacksInMemory
return tStacksInMemory
end revLoadedStacks
function revStackNameIsIDEStack pStackName
if there is a stack pStackName and the _ideoverride of stack pStackName then
return true
else if pStackName is among the items of "message box,answer dialog,ask dialog,home" then
return true
else if pStackName begins with "com.livecode." then
return true
else
return pStackName begins with "rev"
end if
end revStackNameIsIDEStack
-- MW-2010-09-29: Slight tweak to this so that IDE stacks never appear in lists - regardless of mode.
function revFilterStacksList pStacks
local tReturnValue
repeat for each line l in pStacks
if revStackNameIsIDEStack(l) then
next repeat
end if
-- This allows a hook function somewhere in the message path to do extra filtering on stacks.
dispatch function "revHookIsUserStack" to me with the long id of stack l
if it is not "handled" or the result then
put l & cr after tReturnValue
end if
end repeat
delete last char of tReturnValue
return tReturnValue
end revFilterStacksList
# OK-2007-07-05: Rewrote revRotatePoly and revPoints to fix bug 4882
# Parameters
# pGraphic : A reference to a graphic
# pAngle : The angle to rotate the graphic by
# Description
# Performs a rotation transformation whose origin is the loc of the graphic and
# whose magnitude is pAngle degrees. Preserves the topLeft of the graphic, but may
# cause distortion due to rounding errors.
command revRotatePoly pGraphic, pAngle
local tPoints, tFinalPoints
local tLoc
local tSinAngle, tCosAngle
local tCurrentH, tCurrentV, tTransformedH, tTransformedV
local tOrigLeft, tOrigTop
lock screen
lock messages
if the realPoints of pGraphic is empty then
put the effective points of pGraphic into tPoints
else
put the realPoints of pGraphic into tPoints
end if
put the loc of pGraphic into tLoc
put item 1 of tLoc into tOrigLeft
put item 2 of tLoc into tOrigTop
put sin(pi*pAngle/180) into tSinAngle
put cos(pi*pAngle/180) into tCosAngle
repeat for each line tPoint in tPoints
if tPoint is not empty then
put item 1 of tPoint into tCurrentH
put item 2 of tPoint into tCurrentV
put (tOrigLeft+(tCosAngle*tCurrentH)-(tSinAngle*tCurrentV), tOrigTop+(tCosAngle*tCurrentV)+(tSinAngle*tCurrentH) ) after tFinalPoints
end if
put cr after tFinalPoints
end repeat
delete char -1 of tFinalPoints -- is CR
if the style of pGraphic is among the items of "oval,rectangle,roundrect,regular" then
set the style of pGraphic to "polygon"
end if
set points of pGraphic to tFinalPoints
set the realPoints of pGraphic to tFinalPoints
set loc of pGraphic to tLoc
unlock messages
unlock screen
end revRotatePoly
command revRotatePolygonOld pGraphic, pAngle
local tTopLeft
put the topLeft of pGraphic into tTopLeft
local tPoints
put revPoints(pGraphic) into tPoints
local tLoc
put the loc of pGraphic into tLoc
local tSinAngle
put sin(pAngle * (pi / 180)) into tSinAngle
local tCosAngle
put cos(pAngle * (pi / 180)) into tCosAngle
local tLineCount
put (the number of lines of tPoints) into tLineCount
local tCurrentH, tCurrentV, tTransformedH, tTransformedV, tFinalPoints
repeat for each line tPoint in tPoints
if tPoint is empty then
put empty & return after tFinalPoints
next repeat
end if
put item 1 of tPoint into tCurrentH
put item 2 of tPoint into tCurrentV
put trunc((tCosAngle * tCurrentH) - (tSinAngle * tCurrentV)) into tTransformedH
put trunc((tSinAngle * tCurrentH) + (tCosAngle * tCurrentV)) into tTransformedV
put tTransformedH + (item 1 of line 1 of tPoints) into tCurrentH
put tTransformedV + (item 2 of line 1 of tPoints) into tCurrentV
put tCurrentH,tCurrentV & return after tFinalPoints
end repeat
delete the last char of tFinalPoints
set the points of pGraphic to tFinalPoints
set the topLeft of pGraphic to tTopLeft
end revRotatePolygonOld
# Parameters
# pGraphic : A reference to a graphic
# Returns
# A return delimited list of points in the same format as the points property.
# Description
# Note that the return format is different to the old behavior (changed in 2.9-0-dp-1). The
# points returned by this function are relative to the centre of the graphic,
# unlike the points returned by the engine which are absolute.
function revPoints pGraphic
local tNumPoints
put the number of lines in the points of pGraphic into tNumPoints
local tCentreH
put item 1 of loc of pGraphic into tCentreH
local tCentreV
put item 2 of loc of pGraphic into tCentreV
local tPoints
put the points of pGraphic into tPoints
local tResult
repeat for each line tPoint in tPoints
if tPoint is empty then
put empty & return after tResult
next repeat
end if
local tAbsolutePointH
put item 1 of tPoint into tAbsolutePointH
local tAbsolutePointV
put item 2 of tPoint into tAbsolutePointV
put tAbsolutePointH - tCentreH & comma & tAbsolutePointV - tCentreV & return after tResult
end repeat
delete the last char of tResult
return tResult
end revPoints
--Path Conversion Functions
function revUnixFromMacPath thePath
local numberOfLevels
if char 1 of thePath is colon then -- relative path
repeat while char 1 of thePath is colon
delete char 1 of thePath
add 1 to numberOfLevels -- keep track
end repeat
if numberOfLevels is 1 then
put ".:" before thePath
else -- more than one level
repeat for (numberOfLevels - 1) times
put "..:" before thePath
end repeat
end if
else -- colon is not char 1 - therefore it's an absolute path
set the itemDelimiter to colon
if line 1 of the drives is item 1 of thePath then delete item 1 of thePath -- startup drive
else put "Volumes:" before thePath -- non-startup drives are rooted in the Volumes dir on OS X
put colon before thePath -- will be transformed to slash
end if
replace colon with linefeed in thePath
replace "/" with colon in thePath
replace linefeed with "/" in thePath
return thePath
end revUnixFromMacPath
function revMacFromUnixPath thePath
local numberOfLevels
-- MW-2008-02-28: [[ Bug 5678 ]] Make sure we resolve the UNIX ~ component as MacOS
-- paths don't support this
if char 1 of thePath is "~" then
local tOldFolder
put the folder into tOldFolder
set the itemDelimiter to "/"
set the folder to item 1 of thePath
put the folder & slash & item 2 to -1 of thePath into thePath
set the folder to tOldFolder
end if
replace colon with linefeed in thePath
if char 1 of thePath is "/" then delete char 1 of thePath
replace "/" with colon in thePath
replace linefeed with "/" in thePath
if char 1 to 2 of thePath is ".:" then delete char 1 of thePath
else if char 1 to 3 of thePath is "..:" then -- relative path
repeat while char 1 to 3 of thePath is "..:"
delete char 1 to 3 of thePath
add 1 to numberOfLevels
end repeat
repeat for numberOfLevels + 1 times
put ":" before thePath
end repeat
end if
if char 1 of thePath is not ":" then
-- it's an absolute path, so adjust for OS X if necessary
set the itemDelimiter to ":"
if item 1 of thePath is "Volumes" then delete item 1 of thePath -- non-startup disk
else put line 1 of the drives & ":" before thePath -- need to prepend startup disk name
end if
return thePath
end revMacFromUnixPath
--File transfer functions
function revWindowsFromUnixPath pUnixPath
replace "/" with "\" in pUnixPath
return pUnixPath
end revWindowsFromUnixPath
on revCopyFile pSrcFile, pDestFile
replace "//" with "/" in pSrcFile
replace "//" with "/" in pDestFile
# If the two paths are identical, this is a no-op as we are replacing the file with itself
if pSrcFile is pDestFile then
return empty
end if
# If the destination is a folder, and its the same folder as the file already resides in, this is also a no-op.
set the itemDelimiter to slash
if item 1 to -2 of pSrcFile is pDestFile and there is a folder pDestFile then
return empty
end if
if the platform is "MacOS" then
if "applescript" is in the alternateLanguages then
if there is a file pDestFile then delete file pDestfile -- overwrite before copying
do revAppleScriptFull("copyFile",pSrcFile,pDestFile) as "applescript"
if word 1 to 2 of the result is "document file" then
#Copy successful so don't return anything
return empty
else if the result is not "compile error" and the result is not "execution error" then
return createCopyFileResult(the result, pDestFile)
else
return the result
end if
else return "Error: AppleScript not installed"
else if the platform is "Win32" then
revSetWindowsShellCommand
# OK-2008-03-24 : Bug 6180, standardise the paths so that we can refer to items in them,
# The paths will get converted back into Windows paths by revWindowsFromUnixPath.
replace "\" with "/" in pDestFile
replace "\" with "/" in pSrcFile
if there is a directory pDestFile then
set the itemDel to "/"
if char -1 of pDestFile is "/" then
delete char -1 of pDestFile
end if
local tDestFileName
put item -1 of pSrcFile into tDestFileName
set the itemDel to comma
put "/" & tDestFileName after pDestFile
end if
get shell ("copy" && revWindowsFromUnixPath(quote&pSrcFile"e) && revWindowsFromUnixPath(quote&pDestFile"e))
else
get shell ("cp -f" && quote&pSrcFile"e && quote&pDestFile"e)
end if
return the result
end revCopyFile
private command log pMessage
put pMessage & return after msg
end log
on mouseDoubleUp pButtonNo, pTarget
--not been handled
--pTarget set in suppress messages frontscript
if pTarget is empty
then put the long id of the target into pTarget
local tStack
put revTargetStack(pTarget) into tStack
local tDefaultStack
put the defaultStack into tDefaultStack
set the defaultStack to tStack
if the mode of stack tStack is not 0 then
# OK-2008-11-28 : Bug 6455 - Must pass the correct mouse button here or button 1 will be assumed.
click button pButtonNo at the clickLoc
end if
set the defaultStack to tDefaultStack
end mouseDoubleUp
on revCopyFolder pSrcFolder, pDestFolder
if the last char of pSrcFolder is "/" then delete the last char of pSrcFolder
if the platform is "MacOS" then
if "applescript" is in the alternateLanguages then
if there is not a folder pDestFolder then
create folder pDestFolder
end if
do revAppleScriptFull("copyFolder",pSrcFolder,pDestFolder) as "applescript"
if word 1 of the result is "folder" then
#Copy successful so don't return anything
return empty
else
return the result
end if
else return "Error: AppleScript not installed"
else if the platform is "Win32" then
revSetWindowsShellCommand
if there is a directory pDestFolder then
set the itemDel to "/"
if char -1 of pDestFolder is "/" then delete char -1 of pDestFolder
local tLastItemOfSrcFolder
put item -1 of pSrcFolder into tLastItemofSrcFolder
put "/" & tLastItemofSrcFolder after pDestFolder
create directory pDestFolder
end if
# TH-2008-03-11 : Fix for 5465, should remedy problem with copy sometimes crashing on vista
# now use robocopy instead of xcopy if operating under vista.
if the systemVersion is "NT 6.0" then
get shell ("robocopy" && revWindowsFromUnixPath(quote&pSrcFolder"e) && revWindowsFromUnixPath(quote&pDestFolder"e) && "/E /NFL /NDL /NS /NC /NJH /NJS")
else
get shell ("xcopy /I /E /Y /R" && revWindowsFromUnixPath(quote&pSrcFolder"e) && revWindowsFromUnixPath(quote&pDestFolder"e))
end if
else
get shell ("cp -rf" && quote&pSrcFolder"e && quote&pDestFolder"e)
end if
return the result
end revCopyFolder
on revCopyFolder__Standalone pSrcFolder, pDestFolder
if the last char of pSrcFolder is "/" then delete the last char of pSrcFolder
if the platform is "MacOS" then
if "applescript" is in the alternateLanguages then
if there is not a folder pDestFolder then
create folder pDestFolder
end if
do revAppleScriptFull("copyFolder",pSrcFolder,pDestFolder) as "applescript"
if word 1 of the result is "folder" then
#Copy successful so don't return anything
return empty
else
return the result
end if
else return "Error: AppleScript not installed"
else if the platform is "Win32" then
revSetWindowsShellCommand
if there is a directory pDestFolder then
set the itemDel to "/"
if char -1 of pDestFolder is "/" then delete char -1 of pDestFolder
local tLastItemOfSrcFolder
put item -1 of pSrcFolder into tLastItemofSrcFolder
put "/" & tLastItemofSrcFolder after pDestFolder
create directory pDestFolder
end if
# TH-2008-03-11 : Fix for 5465, should remedy problem with copy sometimes crashing on vista
# now use robocopy instead of xcopy if operating under vista.
if the systemVersion is "NT 6.0" then
get shell ("robocopy" && revWindowsFromUnixPath(quote&pSrcFolder"e) && revWindowsFromUnixPath(quote&pDestFolder"e) && "/E /NFL /NDL /NS /NC /NJH /NJS")
else
get shell ("xcopy /I /E /Y /R" && revWindowsFromUnixPath(quote&pSrcFolder"e) && revWindowsFromUnixPath(quote&pDestFolder"e))
end if
else
get shell ("cp -rf" && quote&pSrcFolder"e && quote&pDestFolder"e)
end if
return the result
end revCopyFolder__Standalone
on revCopyPackage pSrcFolder, pDestFolder
if the platform is "MacOS" then
if "applescript" is in the alternateLanguages then
if there is not a folder pDestFolder then
create folder pDestFolder
end if
do revAppleScriptFull("copyPackage",pSrcFolder,pDestFolder) as "applescript"
else return "Error: AppleScript not installed"
else if the platform is "Win32" then
revSetWindowsShellCommand
if there is a directory pDestFolder then
set the itemDel to "/"
if char -1 of pDestFolder is "/" then delete char -1 of pDestFolder
local tLastItemOfSrcFolder
put item -1 of pSrcFolder into tLastItemofSrcFolder
put "/" & tLastItemofSrcFolder after pDestFolder
create directory pDestFolder
end if
# TH-2008-03-11 : Fix for 5465, should remedy problem with copy sometimes crashing on vista
# now use robocopy instead of xcopy if operating under vista.
if the systemVersion is "NT 6.0" then
get shell ("robocopy" && revWindowsFromUnixPath(quote&pSrcFolder"e) && revWindowsFromUnixPath(quote&pDestFolder"e) && "/E /NFL /NDL /NS /NC /NJH /NJS")
else
get shell ("xcopy /I /E /Y /R" && revWindowsFromUnixPath(quote&pSrcFolder"e) && revWindowsFromUnixPath(quote&pDestFolder"e))
end if
else
get shell ("cp -rf" && quote&pSrcFolder"e && quote&pDestFolder"e)
end if
return the result
end revCopyPackage
on revDeleteFolder pSrcFolder
set the itemdelimiter to "."
if the platform is "Win32" then
revSetWindowsShellCommand
-- check for Win 2000, XP, Vista
if item 1 of (word 2 of the systemVersion) >= "5" then
get shell ("rmdir /s /q" && revWindowsFromUnixPath(quote&pSrcFolder"e))
else
get shell ("deltree /Y" && revWindowsFromUnixPath(quote&pSrcFolder"e))
end if
else
get shell ("rm -rf" && quote&pSrcFolder"e)
end if
return the result
end revDeleteFolder
on revDeleteFile pWhich
close file pWhich
if the platform is "MacOS" then put empty into URL ("resfile:"&pWhich)
put empty into URL ("binfile:"&pWhich)
delete file pWHich
end revDeleteFile
on revMoveFolder pSrcFolder, pDestFolder
if the platform is "Win32" then
revSetWindowsShellCommand
get shell ("move /Y" && revWindowsFromUnixPath(quote&pSrcFolder"e) && revWindowsFromUnixPath(quote&pDestFolder"e))
else
get shell ("mv -f" && quote&pSrcFolder"e && quote&pDestFolder"e)
end if
return the result
end revMoveFolder
function revPathtoApplescript pPath
local tApplescript
put empty into tApplescript
replace "\" with "\\" in pPath
replace quote with "\" & quote in pPath
put quote & revMacFromUnixPath(pPath) & quote into tApplescript
return tApplescript
end revPathtoApplescript
# OK-2009-02-11 : Bug 7580 - Added to allow revCopyFile to return something useful
# Currently, it just returns empty. However the disabled branch of code will convert
# the parameters into an absolute file path in case we want to use this in the future.
private function createCopyFileResult pPath, pDestination
return empty
local tPath
put pPath into tPath
if char 1 of tPath is quote and char -1 of tPath is quote then
delete char 1 of tPath
delete char -1 of tPath
end if
local tIsFilename
if tPath contains ":" then
put false into tIsFilename
else
put true into tIsFilename
end if
if not tIsFilename then
# Assume absolute path and convert
local tUnixPath
put revUnixFromMacPath(tPath) into tUnixPath
replace ("\" & quote) with quote in tUnixPath
replace "\\" with "\" in tUnixPath
return tUnixPath
else
# Turn it into an absolute path for consistent return values
local tFolder
if there is a folder pDestination then
put pDestination into tFolder
else
set the itemDelimiter to slash
put item 1 to -2 of pDestination into tFolder
set the itemDelimiter to comma
end if
return tFolder & slash & tPath
end if
end createCopyFileResult
function revApplescriptFull pFunction, pSrc, pDest
local tScript
switch pFunction
case "deleteFolder"
put "tell application" && quote & "Finder" & quote & cr & tab & "delete folder" && revPathtoApplescript(pSrc) && cr & "end tell" into tScript
break
case "copyFile"
# OK-2009-02-11 : Bug 7580 - Rewritten to take some extra cases into account
put buildCopyFileApplescript(pSrc, pDest, false) into tScript
break
case "copyPackage"
put "tell application" && quote & "Finder" & quote & cr & tab & "copy package" && revPathtoApplescript(pSrc) && "to folder" && revPathtoApplescript(pDest) && cr & "end tell" into tScript
break
case "copyFolder"
put "tell application" && quote & "Finder" & quote & cr & tab & "copy folder" && revPathtoApplescript(pSrc) && "to folder" && revPathtoApplescript(pDest) && cr & "end tell" into tScript
break
case "moveFolder"
put "tell application" && quote & "Finder" & quote & cr & tab & "move folder" && revPathtoApplescript(pSrc) && "to folder" && revPathtoApplescript(pDest) && cr & "end tell" into tScript
break
end switch