-
Notifications
You must be signed in to change notification settings - Fork 3
/
frlDragDropFilesIntoIDE.livecodescript
742 lines (545 loc) · 23 KB
/
frlDragDropFilesIntoIDE.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
script "com.ferruslogic.plugin.dragDropFilesIntoIDE"
/*
Copyright (c) 2020 FerrusLogic
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files the frlDragDropFilesIntoIDE, to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Summary
This small library is to aid in the application creation process by
allowing you to drag files into the development IDE. So it only runs
in development mode for the time being.
version 1.1.1
Made: 2020-07-09 15:20
Last Update: 2022-12-05 11:53
*/
# list of files being dragged.
local sFiles
# The window the mouse pointer is over.
local sMouseStack, sOldMouseStack
# The location of the mouse pointer.
local sMouseLoc
# Graph that is dynamically created in the background for the DragDrop event to be sent.
local sLongIdBackGraphic
# The object that is the object and its type.
local sDragDestination, sTypeDragDestination
# The last control that was imported. It is to select it at the end of everything.
local sLastControl
# Whether to import into the dragDestination or create a new object.
local sOptionShift
local sCtrlShift
constant kBynaryStack = "livecode,rev,mc", kScriptOnlyStack = "livecodescript"
constant kAudio = "mp3,mp4,mpg,mov,avi,m4a,midi,midi,snd,aac,wma,ogg,mpeg,m2v,mpeg2,qt,ram,rm"
constant kImage = "svg,png,jpeg,jpg,gif,bmp,pbm,pgm,ppm,xbm,xpm,xwd,pict,webp,jfif,tif,tiff,dib,vga,pict,pict2,pic"
constant kTextPlan = "json,html,htm,txt,lng,locale,log,mnu,nfo,inf,ini,inc,bar,cfg,sav,conf,manifest,lst,ion,rc,properties,mf,list,wbt,lic,css,hs,iss,js,nsi,nsh,java,php,php3,php4,php5,tct,xml,xsml,xsl,kml,adr,sfx,,sh,bsh,lua,pl,pm,py,as,las,mx,vb,f,for,f90,f95,f2k,tex,mak,tpl,asm,plx,lsp,lisp,scm,smd,ss,kix,au3,ml,mli,sml,thy,ada,ads,adb,v,lhs,cmake,twig,yml"
constant kLiveCodeExtension = "lce"
on extensionInitialize
if the target is not me then
pass extensionInitialize
end if
if the environment is "development" then
if $0 ends with ".lce" then
_installExtension $0
end if
insert the script of me into front
set the _ideoverride of me to true
end if
end extensionInitialize
on extensionFinalize
if the target is not me then pass extensionFinalize
remove the script of me from front
end extensionFinalize
on dragEnter
if the tool is "pointer tool" and the dragData["files"] is not empty then _acceptDrop
pass dragEnter
end dragEnter
on dragMove
if the tool is "pointer tool" and the dragData["files"] is not empty then _acceptDrop
pass dragMove
end dragMove
on dragLeave
if there is not a stack sMouseStack or within(stack sMouseStack, globalLoc(the mouseLoc)) is false then _deleteBackgroundGraphic
pass dragLeave
end dragLeave
on dragDrop
_deleteBackgroundGraphic
if the tool is no "pointer tool" or sFiles is empty then pass dragDrop
_setDefaultStack
if _ItIsIDEStack(sMouseStack) is true then
put the short name of the topStack into sMouseStack
set the defaultstack to sMouseStack
end if
put the mouseLoc into sMouseLoc
put the optionKey is down and the shiftKey is down and the number of lines of sFiles is 1 into sOptionShift
put the controlKey is down and the shiftKey is down into sCtrlShift
if sFiles is not empty then
lock messages;lock cursor
lock the clipboard
set the cursor to watch
repeat for each line tFile in sFiles
_importFile tFile
end repeat
delete variable sFiles
set the dragData["files"] to empty
set the clipboardData to empty
set the dragAction to "none"
set the fullDragData to empty
unlock messages
choose pointer tool
if there is a sLastControl then
focus on nothing
select empty
select sLastControl
end if
unlock screen; unlock messages; unlock cursor
unlock the clipboard
exit dragDrop
end if
pass dragDrop
end dragDrop
# remove data being dragged.
on dragEnd
_deleteBackgroundGraphic
pass dragEnd
end dragEnd
# remove data being dragged.
on suspendStack
if sFiles is not empty then
_deleteBackgroundGraphic
delete variable sMouseStack
end if
pass suspendStack
end suspendStack
private on ____________Core______________
-- Core of this extensions
end ____________Core______________
private command _acceptDrop
if the tool is not "pointer tool" then
_deleteBackgroundGraphic
unlock messages
exit _acceptDrop
end if
put the dragData["files"] into sFiles
_setDefaultStack
if _inMouseStack() and _filesTypeDragDrop(sFiles) is true and the cantModify of stack sMouseStack is not true then
set the dragAction to "copy"
else
set the dragAction to "none"
_deleteBackgroundGraphic
unlock messages
exit _acceptDrop
end if
if there is not graphic "frlDragDropBack" of this cd of stack sMouseStack then
lock messages
# I create this graph because the drag & drop message is not generated on the card
create invisible graphic "frlDragDropBack" in this cd
put it into sLongIdBackGraphic
set the rect of sLongIdBackGraphic to the rect of this cd of stack sMouseStack
try
set the opaque of sLongIdBackGraphic to true
set the blendlevel of sLongIdBackGraphic to 100
set the layer of sLongIdBackGraphic to bottom
set the lineSize of sLongIdBackGraphic to 0
set the backColor of sLongIdBackGraphic to revIDEColor("edition_color")
set the visible of sLongIdBackGraphic to true
end try
put empty into sDragDestination
put empty into sTypeDragDestination
put empty into sOptionShift
if _ItIsIDEStack(sMouseStack) is true then set the blendlevel of sLongIdBackGraphic to 100
else set the blendlevel of sLongIdBackGraphic to 0
unlock messages
end if
end _acceptDrop
private command _importFile pFilePath
local tExtension
set the itemdel to "."
try
lock messages
put _dragDestination() into sDragDestination
_deleteBackgroundGraphic
put word 1 of sDragDestination into sTypeDragDestination
put item - 1 of pFilePath into tExtension
set the itemdel to comma
if there is a file pFilePath then
switch
# SVG
case tExtension is "svg"
_importPathSVG pFilePath
break
# LiveCode, Revolution and MetaCard binary stack files
case tExtension is among the items of kBynaryStack
unlock messages
go to card 1 of stack pFilePath
break
# Script-only stack
case tExtension is kScriptOnlyStack
edit the script of stack pFilePath
break
# Images file
case tExtension is among the items of kImage
_importImage pFilePath, "file"
break
# Audio and Videos file
case tExtension is among the items of kAudio
_importPlayer pFilePath
break
# Text Plan
case tExtension is among the items of kTextPlan
_importTextPlan pFilePath
break
# LiveCode Extension
case tExtension is kLiveCodeExtension
_installExtension pFilePath
break
end switch
end if
unlock messages
end try
end _importFile
private command _importImage pPathOrData, pType
local tNameFile, tImageData, tNewImage
set the itemdel to slash
_setDefaultStack
if _ItIsIDEStack(sMouseStack) is true then
put the short name of the topStack into sMouseStack
set the defaultstack to sMouseStack
end if
if there is a stack sMouseStack and not _ItIsIDEStack(sMouseStack) then
if pType is "file" then
if there is a sDragDestination and sTypeDragDestination is "image" and sOptionShift is true then
local tLockLoc
put the lockLoc of sDragDestination into tLockLoc
set the lockLoc of sDragDestination to true
if the filename of sDragDestination is empty then
set the text of sDragDestination to URL ("binfile:" & pPathOrData)
else
set the filename of sDragDestination to _convertPathToRelativePath(pPathOrData)
end if
set the lockLoc of sDragDestination to tLockLoc
put sDragDestination into sLastControl
exit _importImage
end if
if sCtrlShift is false then set the text of templateImage to URL ("binfile:" & pPathOrData)
put item - 1 of pPathOrData into tNameFile
create image tNameFile in this cd
put it into tNewImage
if the text of tNewImage is empty then
set the filename of tNewImage to _convertPathToRelativePath(pPathOrData)
end if
if there is tNewImage then
_scaleImage tNewImage
if sMouseLoc is within the rect of card 1 of stack sMouseStack then
set the loc of tNewImage to sMouseLoc
else
set the loc of tNewImage to (the loc of cd 1 of stack sMouseStack)
end if
put tNewImage into sLastControl
end if
reset templateImage
else
local tOldText, tNewText
put drawingSvgCompileFile(pPathOrData) into tNewText
if tNewText is not empty then
if there is a sDragDestination and sTypeDragDestination is "image" then
put the text of sDragDestination into tOldText
set the text of sDragDestination to tNewText
_scaleImage tNewImage
if the text of sDragDestination is empty then
set the text of sDragDestination to tOldText
end if
else
put the mouseLoc into sMouseLoc
set the text of templateImage to tNewText
put item - 1 of pPathOrData into tNameFile
create image tNameFile in this cd
put it into tNewImage
if there is tNewImage then
_scaleImage tNewImage
if sMouseLoc is within the rect of card 1 of stack sMouseStack then
set the loc of tNewImage to sMouseLoc
else
set the loc of tNewImage to (the loc of cd 1 of stack sMouseStack)
end if
put tNewImage into sLastControl
end if
reset templateImage
end if
else
beep
end if
end if
end if
end _importImage
private command _importPlayer pPathOrData
local tNameFile, tNumPlayer
local tNewPlayer
set the itemdel to slash
_setDefaultStack
if _ItIsIDEStack(sMouseStack) is true then
put the short name of the topStack into sMouseStack
set the defaultstack to sMouseStack
end if
if there is a stack sMouseStack and not _ItIsIDEStack(sMouseStack) then
if there is a sDragDestination and sTypeDragDestination is "player" and sOptionShift is true then
set the filename of sDragDestination to _convertPathToRelativePath(pPathOrData)
put sDragDestination into sLastControl
else
set the filename of templatePlayer to _convertPathToRelativePath(pPathOrData)
set the showController of templatePlayer to true
put item - 1 of pPathOrData into tNameFile
create player tNameFile in this cd
put it into tNewPlayer
if sMouseLoc is within the rect of card 1 of stack sMouseStack then
set the loc of tNewPlayer to sMouseLoc
else
set the loc of tNewPlayer to (the loc of cd 1 of stack sMouseStack)
end if
put tNewPlayer into sLastControl
end if
reset templatePlayer
end if
end _importPlayer
private command _importPathSVG pFilePath
local tNewWidget, tPathSVG, tName
set the itemdel to slash
put last item of pFilePath into tName
_setDefaultStack
if _ItIsIDEStack(sMouseStack) is true then
put the short name of the topStack into sMouseStack
set the defaultstack to sMouseStack
end if
put _getPathSVG(pFilePath) into tPathSVG
if there is a stack sMouseStack and not _ItIsIDEStack(sMouseStack) then
if tPathSVG is not empty then
local tKind
try
put the kind of sDragDestination into tKind
end try
if there is a sDragDestination and sTypeDragDestination is "widget" and tKind is "com.livecode.widget.svgpath" and sOptionShift is true then
set the iconPath of sDragDestination to tPathSVG
put sDragDestination into sLastControl
else
create widget tName as "com.livecode.widget.svgpath" in this cd
put it into tNewWidget
set the iconPath of tNewWidget to tPathSVG
set the width of tNewWidget to 180
set the height of tNewWidget to 180
if sMouseLoc is within the rect of card 1 of stack sMouseStack then
set the loc of tNewWidget to sMouseLoc
else
set the loc of tNewWidget to (the loc of cd 1 of stack sMouseStack)
end if
put tNewWidget into sLastControl
end if
else
_importImage pFilePath, "SVG_Data"
end if
end if
end _importPathSVG
private command _importTextPlan pFilePath
local tText
_setDefaultStack
if _ItIsIDEStack(sMouseStack) is true then
put the short name of the topStack into sMouseStack
set the defaultstack to sMouseStack
end if
if there is a stack sMouseStack and not _ItIsIDEStack(sMouseStack) then
put URL("file:" & pFilePath) into tText
if there is a sDragDestination and sTypeDragDestination is "field" and sOptionShift is true then
set the text of sDragDestination to tText
else
create field ( the last item of pFilePath)
put it into sLastControl
set the text of sLastControl to tText
set the locktext of sLastControl to true
if sMouseLoc is within the rect of card 1 of stack sMouseStack then
set the loc of sLastControl to sMouseLoc
else
set the loc of sLastControl to (the loc of cd 1 of stack sMouseStack)
end if
end if
end if
end _importTextPlan
private command _installExtension pExtensionURL
local tKind
put _getKindExtensionFile( pExtensionURL ) into tKind
if tKind is empty then exit _installExtension
if tKind is among the lines of the loadedExtensions then
dispatch "revIDEExtensionUninstall" to stack "revExtensionBuilder" with tKind
end if
dispatch "revIDEExtensionInstall" to stack "revExtensionBuilder" with pExtensionURL
end _installExtension
private function _getKindExtensionFile pFilePath
try
local tItemData, tS, tE
revZipOpenArchive pFilePath, "read"
revZipExtractItemToVariable pFilePath, "manifest.xml", "tItemData"
revZipCloseArchive pFilePath
put offset ("<name>", tItemData, 0) into tS
put offset ("</name>", tItemData, tS) into tE
if tS is not 0 and tE is not 0 then
return the char (tS + 6) to ( tS + tE - 1) of tItemData
end if
catch e
return empty
end try
end _getKindExtensionFile
private command _setDefaultStack
if there is a the mouseStack then put the short name of the mouseStack into sMouseStack
if sOldMouseStack is not sMouseStack then
_deleteBackgroundGraphic
end if
put sMouseStack into sOldMouseStack
set the defaultStack to sMouseStack
end _setDefaultStack
private function _dragDestination
local tStack, tDragDestination
_setDefaultStack
put the dragDestination into tDragDestination
if there is an stack sMouseStack then
if there is tDragDestination then
put the long id of tDragDestination into tDragDestination
put ideStackOfObject(tDragDestination) into tStack
if there is a tDragDestination and tStack is the long name stack sMouseStack then
return tDragDestination
end if
end if
return the long id of this cd
end if
end _dragDestination
private command _deleteBackgroundGraphic
if sLongIdBackGraphic is not empty and there is sLongIdBackGraphic then
delete sLongIdBackGraphic
delete variable sLongIdBackGraphic
end if
set the dragAction to "none"
end _deleteBackgroundGraphic
private function _convertPathToRelativePath pPath
local tStackPath
set the itemdel to slash
if there is not a stack sMouseStack then return pPath
put item 1 to - 2 of the effective filename of stack sMouseStack into tStackPath
if there is not a folder tStackPath then return pPath
replace backslash with slash in pPath
replace tStackPath & slash with empty in pPath
return pPath
end _convertPathToRelativePath
private function _getPathSVG pFilePath
local tSVG, tPathOpen , tOpen = 0, tClose, tSVGPath, tNumChars, tNewPath, tName, tSvgColorToJPG = false
set the itemdel to slash
put the last item of pFilePath into tName
set the itemdel to quote
if there is a file pFilePath then
put URL( "file:" & pFilePath ) into tSVG
put length(tSVG) into tNumChars
put "#" is in tSVG and not (the controlKey is down and the shiftKey is down) into tSvgColorToJPG
if tSvgColorToJPG is false and "path" is in tSVG then
repeat for tNumChars
put offset("path", tSVG, tPathOpen) into tOpen
if tOpen is 0 then exit repeat
if tNumChars <= tOpen then exit repeat
put tOpen + tPathOpen into tPathOpen
if the char(tPathOpen - 1) of tSVG is not "<" and char (tPathOpen - 1) of tSVG is not space then
put tPathOpen + 3 into tPathOpen
next repeat
end if
put offset("d=" & quote, tSVG, tPathOpen) into tOpen
if tOpen is 0 then exit repeat
put tOpen + tPathOpen + 3 into tOpen
put offset(quote, tSVG, tOpen) into tClose
if tClose is 0 then exit repeat
put tOpen + tClose into tClose
put char tOpen to (tClose - 1) of tSVG into tNewPath
add 1 to tClose
put tClose into tPathOpen
get (the item 1 to 2 of ( the char tClose to - 1 of tSVG))
if the trueWord 1 of it is "fill" and the trueWord -1 of it is "none" then
next repeat
end if
put tNewPath && cr after tSVGPath
end repeat
end if
else
put tSVG into tSVGPath
end if
local tWidget, tOutPathSVG
create widget tName as "com.livecode.widget.svgpath"
put it into tWidget
try
set the iconPath of tWidget to tSVGPath
put tSVGPath into tOutPathSVG
end try
delete tWidget
return tOutPathSVG
end _getPathSVG
private function _filesTypeDragDrop pFiles
local tResult = true, tExtension
if pFiles is empty then return false
repeat for each line tFile in pFiles
set the itemdel to "."
put item - 1 of tFile into tExtension
set the itemdel to comma
if tExtension is not among the items of (kBynaryStack,kScriptOnlyStack,kAudio,kImage,kTextPlan,kLiveCodeExtension) then
put false into tResult
exit repeat
end if
end repeat
return tResult
end _filesTypeDragDrop
private command _scaleImage pLongId
local tFormattedWidth, tFormattedHeight, tWidthCard, tHeightCard, tAspectRatio
_setDefaultStack
if _ItIsIDEStack(sMouseStack) is true then
put the short name of the topStack into sMouseStack
set the defaultstack to sMouseStack
end if
put the formattedWidth of pLongId into tFormattedWidth
put the formattedHeight of pLongId into tFormattedHeight
put the width of this card into tWidthCard
put the height of this card into tHeightCard
if tFormattedWidth is 0 or tFormattedHeight is 0 or (tFormattedWidth < tWidthCard and tFormattedHeight < tHeightCard) then
exit _scaleImage
end if
put min(tWidthCard/tFormattedWidth, tHeightCard/tFormattedHeight) into tAspectRatio
set the width of pLongId to tFormattedWidth * tAspectRatio
set the height of pLongId to tFormattedHeight * tAspectRatio
end _scaleImage
private function _ItIsIDEStack pNameStack
if there is not a stack pNameStack then return false
return the mainstack of stack pNameStack is not among the lines of ideUserMainStacks()
end _ItIsIDEStack
private command _cancelPendingMessages pMessageName
local tPendingMessages
set the itemDelimiter to comma
put the pendingMessages into tPendingMessages
repeat for each line tMessage in tPendingMessages
if item 3 of tMessage is pMessageName then
cancel item 1 of tMessage
end if
end repeat
end _cancelPendingMessages
private function _inMouseStack
local tTarget, tStackOfControlLeave
put the target into tTarget
if tTarget is empty then return false
if word 1 of tTarget is in "card stack" then
put ideStackOfObject( the long id of tTarget) into tStackOfControlLeave
if there is a stack tStackOfControlLeave and globalLoc(the mouseLoc) is not within the rect of stack tStackOfControlLeave then
_deleteBackgroundGraphic
return false
end if
end if
return true
end _inMouseStack