-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent.r
2489 lines (2059 loc) · 62.1 KB
/
event.r
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
REBOL [
; -- Core Header attributes --
title: "Glass Event stream handler"
file: %event.r
version: 1.0.7
date: 2013-9-17
author: "Maxim Olivier-Adlhoch"
purpose: {Complete rewrite of view input stream management. Specifically tailored to GLASS.}
web: http://www.revault.org/modules/event.rmrk
source-encoding: "Windows-1252"
note: {slim Library Manager is Required to use this module.}
; -- slim - Library Manager --
slim-name: 'event
slim-version: 1.2.1
slim-prefix: none
slim-update: http://www.revault.org/downloads/modules/event.r
; -- Licensing details --
copyright: "Copyright © 2013 Maxim Olivier-Adlhoch"
license-type: "Apache License v2.0"
license: {Copyright © 2013 Maxim Olivier-Adlhoch
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.}
;- / history
history: {
v1.0.7 - 2013-09-17
-License changed to Apache v2
}
;- \ history
;- / documentation
documentation: {
--------------------
DANGER: the hold() function was patched (see comment there) but current side-effects are unknown (if any)
if you are using any modal dialogs on application start, it may cause your app to start handling
events early. while this usually shouldn't be cause for concern, it may break some apps.
if you have this issue, uncomment the line in the hold function, but know that you then can't have
early modal dialogs(before calling do-events), since the app needs to have started handling
events for it to work.
---------------------
This library implements the event stream system as used by GLASS. It allows many advanced event
manipulations including event stream recording, queuing custom events and stream transformations.
There are several levels of handlers, each of which may have several handlers.
All handlers are linked dynamically, so the stream can be expanded on the fly.
The stream is also responsible for handling non-view events like GUI refreshes
and focus events, generated by marbles themselves.
Because several handlers may process the same event, we have great flexibility in how
events may be manipulated, especially since the same event can now trigger several
callbacks, and even generate several new events.
Also note that an event may be consumed by any handler, so some care must be taken in
how handlers are implemented (its easy to corrupt display when expected events
are missing downstream).
This library is still undergoing some upgrades and not all features are enabled or even
implemented yet.
Expect a good deal of overhaul in some areas, so future releases might break current code.
Don't use this library directly, unless you are prepared for some maintenance down the road.
Generally, the event queuing is not expected to change in the future, so that is safe to use.
}
;- \ documentation
]
;--------------------------------------
; unit testing setup
;--------------------------------------
;
; test-enter-slim 'event
;
;--------------------------------------
slim/register [
view*: system/view
;- LIBS
;
liquid-lib: slim/open/expose 'liquid none [
!plug
retrieve-plug
liquify*: liquify
content*: content
fill*: fill
link*: link
unlink*: unlink
detach*: detach
]
slim/open/expose 'glass-core-utils none [ search-parent-frames ]
glob-lib: slim/open 'glob none
;-
;- GLOBALS
;- last-move-position
; remember last move coordinates so we can trigger it on time events.
last-move-position: 0x0
;- last-down-event
; remember the mouse down event which switches moves to swipe/drop?
last-down-event: none
;- last-move-event:
; when mouse throttling is enabled, this is where we store mouse events until they are handled at
; a time event.
last-move-event: none
;- hold-count:
; each time hold is called, this is incremented,
; each time resume is called, its decremented.
;
; resume will do nothing, if this is 0. preventing the initial wait from terminating
hold-count: 0
;- resume?:
; if this is set to true, the wake event will kill the current wait loop.
; note: will be ignored if hold-count < 1
resume?: none
;- last-wake-event:
; this event (object! or none!) is used to keep track of the CURRENT cloned event which triggered a dispatch.
;
; the reason we need this is to be able to refer to it when implementing dispatch-event
; directives.
;
; that function will inspect the event/action to determine if its been directed to do
; something very low-level... like interrupt current event with a new wait,
; or release of that interruption by returning none from itself.
last-wake-event: none
;- immobile-start:
; this is used to determine how many times the timer-based move event occured
; its usefull to create an 'immobile action.
immobile-start: none
;- GLASS-THROTTLE-MOUSE:
; a global which tells this wake-event to postpone mouse events so they only occur just before time events.
;
; be VERY carefull:
; -if you don't have any window with a rate, mouse handling is effectively nullified
; -key events might occur out-of order.
;
; its set as a global, since control of this must be application wide.
set 'GLASS-THROTTLE-MOUSE true
;- focused-marble:
; link any marble here so it receives focused keyboard events.
;
; focused keyboard events are triggered by the 'focus' input filter.
focused-marble: liquify* !plug
hot-keys: []
;- !event[]
!event: context [
;- action:
; current event type (it may evolve!)
action: none
;- marble:
; stores the destination for the event, changes as streaming progresses.
marble: none
;- view-window:
; what window face originated this event.
view-window: none
;- viewport:
; stores the !viewport face which is responsible for this event.
; note that in some setups, there may be several !viewports -> (<TO DO>: delayed feature)
viewport: none
;- coordinates:
; where was the pointer when the event occured? (may evolve as we go from event->windows->marble)
coordinates: none
;- offset:
; above coordinates, converted to local offset, relative to position and
; frame transformations (translation/scale, if any)
;
; marble handlers will usually use this value instead of coordinates.
;
; note that windows/viewports are responsible for setting this value
offset: none
;- key:
; was the keyboard involved in the event?
key: none
;- control?:
; was the control key pressed?
control?: none
;- shift?:
; was the shift key pressed?
shift?: none
;- tick:
; the event/time integer in milliseconds
; when the mouse is immobile over the active window,
; move events are generated by view... we use this value
; directly to create an 'immobile action (ticks usually happen twice a second)
tick: none
]
;- event-queue:
;
; use the queue-event() function to add events here.
;
; used by the streaming engine to store created events while another event is being processed.
; usually the queue will be empty.
;
; when an event is finished dispatching, the engine will see if there are new events in the queue
; and start the process again.
;
; you can use the event-queue to re-order events...
;
; example:, a mouse click occurs.. you detect that the marble can be focused.
; instead of managing the focus within the mouse handler... you generate new
; unfocus & focus events.
;
; the stream engine will then start a new dispatch with the unfocus, and another with the focus.
; this makes it possible for each part of glass to react to events, without requiring you to
; know how other systems manage events.
;
; when an event simply changes to another event type, just return the new (or modified) event
; from the handler... no need to create a new event in this case.
;
; when the GLASS-THROTTLE-MOUSE is enabled, time events will use this system to stream the last stored
; mouse event before the time event.
event-queue: []
;- automation-queue:
;
; only used when playback? is true
;
; just like the event queue, but can be stalled by setting paused-playback? to true
;
; also, the queue is handled in a different way. we progress through the list one event
; at a time and set the list to the next item (without removing anything)
;
; this way it can be paused and progress can resume at any time.
;
automation-queue: []
;- stream:
; stores event processing functions.
; the event library stream will be responsible for shooting off events to the window stream
;
; streaming allows us to implement various event manipulations in a decoupled manner.
;
; we can implement special features like hotkeys, add or even remove input events on the fly.
;
; the fact that windows have their own stream allows a good degree of flexibility.
;
; things like modality are handled within the stream.
;
; the stream handlers are labeled, for easy manipulation and reference.
;
; you must use the various handler functions to manipulate this.
stream: []
;- recording?:
;
; tells the core-glass-handler to start recording events.
;
; only root level (view) events are recorded, so any marble-generated events get processed normally.
; and will stream as they should.
;
; recording is very handy to reproduce user interaction and allows developpers to automate testing
; of new GUI features, to see if they perform as desired using a recorded event stream.
;
; a file storage/retrieval api is also provided, making it very easy to create a complete
; solution for application macro, unit testing purposes, automated document generation and more
;
; you must not change window titles between recording and playback, nor should you modify
; the layout between tests, cause things like mouse clicks will affect new marbles.
recording?: false
;- record-events:
;
; tells the recording system what it should log.
; true, means log everything.
; it can also be a block of event/action names to match
record-events: true
;- event-log:
; when recording is enabled, view events are stored here. we can run automate on the list after
;
; 'activate events are stored as activate-window events instead, which allow the engine to
; CAUSE a window activation instead.
event-log: []
;- playback?:
; enables automation playback, prevents new event recording, and post-pones normal event processing.
;
; causes the wake-even() to call do-automation() instead of real events.
;
; normally queued events cannot be interrupted (events triggered by marbles which end up in event-queue) but once all
; queued-events are done, the next automation event may be stalled, see paused-playback?: below.
;
playback?: false
;- paused-playback?:
;
; interrupts the automation playback when set to true.
;
; because time events occur normally, the queue will be verified periodically.
;
; note that to set the value of paused-playback? you need to have an external control
; over the GLASS application. this is commonly done using a normal view window
; or tcp port as a trigger.
paused-playback?: false
;- play-delay:
; when dispatching an automation, wait this time period before continuing.
;
play-delay: 0.2
;-
;- FUNCTIONS
;-----------------
;- clone-event()
;
; note: /with block! only works with object! events
;-----------------
clone-event: func [
event [object! event!]
/with e [event! block!] "when cloning !event objects, transfer event! type values into it"
][
if event? event [
; this is an internal view event!
e: event
event: !event
]
; clone the glass event.
either block? e [
event: make event e
][
event: make event []
]
; carry over any view event properties into glass
if event? e [
event/coordinates: e/offset
event/key: e/key
event/action: e/type
; be carefull because at different stages, this face can change, especially
; if there are multiple !VIEWPORTs in a single window.
event/view-window: e/face
event/control?: e/control
event/shift?: e/shift
event/tick: e/time
; if e/type = 'down [
; print ["event/ticks: " e/time]
; print ["event/ticks: " event/tick]
; ]
]
event
]
;-----------------
;- queue-event()
;
; add specified event on the queue.
;-----------------
queue-event: func [
event [object! block!]
/automated "add to automation queue instead, used by recording and direct call to automated"
][
vin [{queue-event()}]
;print "QUEUING EVENT!"
if block? event [
event: clone-event/with !event event
]
either in event 'action [
append either automated [automation-queue][event-queue] event
][
to-error "GLASS/Event.r/queue-event() ATTEMPT TO QUEUE INVALID OBJECT!"
]
vout
]
;-----------------
;- make-event()
;-----------------
make-event: func [
spec [block!]
][
;vin [{make-event()}]
make !event spec
]
;-----------------
;- flush-queue()
;-----------------
flush-queue: func [
][
vin [{flush-queue()}]
clear event-queue
vout
]
;-----------------
;- do-queue()
;-----------------
do-queue: func [
/local gl-event trigger trigger-action done?
][
;vin [{do-queue()}]
; process normal queue
until [
if gl-event: pick event-queue 1 [
either trigger: get in gl-event 'trigger-event [
;vin "trigger-event()"
switch/default type?/word :trigger [
date! [
;print "timed trigger"
either now/precise > trigger [
;print "event-triggered event!"
;print trigger
remove event-queue
if function? trigger-action: get in gl-event 'trigger-action [
event: trigger-action gl-event
if object? event [
;vprint "trigger()"
;vprobe event/trigger-repeat-delay
if event/trigger-repeat-delay [
event/trigger-event: now/precise + event/trigger-repeat-delay
]
append event-queue event
]
]
][
;---
; skip the event, its not ready.
event-queue: next event-queue
]
]
][
;---
; if the trigger-event is invalid, we just dispatch it
; like, a normal event
remove event-queue
dispatch gl-event
]
;vout
][
remove event-queue
dispatch gl-event
]
]
empty? event-queue
]
; in case we skipped some un-triggered events
event-queue: head event-queue
;vout
]
;--------------------------
;- queue-delayed-trigger()
;--------------------------
; purpose:
;
; inputs:
;
; returns:
;
; notes:
; to build repeating events, the action() determines if the event is
; requeued by returning an event (usually the event it received).
; in such a case, make sure to add a delay to the trigger-next, if you need it.
;
; if the trigger action returns none, the event is NOT requeued, and the
; repeat action is pointeless.
;
; tests:
;--------------------------
queue-delayed-trigger: funcl [
delay [time! date! integer! decimal! none!] ; number values are in seconds, functions are executed at each
action [function! block!] "what to do when delay is passed, when given a block, 'EVENT is set to the trigger event"
/repeat-delay "when used, the trigger delay is automatically calculated after the action returns an event."
/label lname [word!] "give this trigger a label in order to recognize it later."
/data user-data
][
vin "queue-delayed-trigger()"
default lname 'time-trigger
switch (type?/word :delay) [
integer! decimal! [
delay: ( 0:0:1 * delay )
if repeat-delay [
repeat-delay: delay
]
]
none! [
delay: 0:00
]
date! [
if repeat-delay [
to-error "queue-trigger(): cannot use /repeat-delay on date delayed events"
]
; when given a date and repeat, we figure out the difference from date and now.
delay: difference delay now/precise
]
]
if block? :action [
action: func [event] :action
]
--action--: :action
;vprint "====>"
event: make-event compose/only [
event-label: lname
trigger-event: now/precise + delay
trigger-data: user-data
trigger-action: :--action--
trigger-repeat-delay: either repeat-delay [ delay ][ none ]
]
;vprint "<===="
queue-event event
vout
event
]
;--------------------------
;- search-event-queue()
;--------------------------
; purpose: retrieve an event based on a variety of criteria
;
; inputs:
;
; returns:
;
; notes: requires a labeled event
;--------------------------
search-event-queue: funcl [
/label lname [word!]
][
vin "search-event-queue()"
case [
label [
foreach event event-queue [
all [
in event 'event-label
word? get/any in event 'event-label
return event ; found it don't
]
]
]
]
vout
]
;-----------------
;- handle-stream()
;
; adds/replaces a handler in an event stream
;
; be carefull, given function is called for EVERY event
;
; if your handler needs any persistent values, wrap the function within
; a context, and call handle-stream from within the context.
;
; be careful, if the named handler already exists, it WILL be replaced.
;-----------------
handle-stream: func [
name [word!]
handler [function!]
/before bhdlr [word!] "add before handler"
/after ahdlr [word!] "add after handler"
/within strm [block! object!] "add a handler to a marble or viewport"
][
vin [{handle-stream()}]
either (copy/part third :handler 2) = compose/deep [event [(object!)]] [
vprint "HANDLER COMFORMS!"
; use glass stream or marble's own stream
strm: any [strm stream]
; reuse or create a new stream for a specified marble
if object? strm [
; object MUST be a marble
strm: strm/stream: any [strm/stream copy []]
]
;vprint length? strm
append strm name
append strm :handler
][
vprobe (copy/part third :handler 2)
to-error "GLASS/Event.r/handle-stream() requires first argument specification of given handler function to be 'event [object!]'"
]
vout
]
;-----------------
;- bypass-stream()
; removes a handler from an event stream
;-----------------
bypass-stream: func [
name [word!]
/from strm [block!]
][
vin [{bypass-stream()}]
strm: any [strm stream]
vout
]
;-----------------
;- do-automation()
;-----------------
do-automation: func [
/local gl-event
][
vin [{do-automation()}]
unless paused-playback? [
until [
; get automation event
if gl-event: pick automation-queue 1 [
;print ["^/---------------^/automation events left: " length? automation-queue]
;probe gl-event/action
;print ["^/---------------^/event log: " length? event-log]
remove automation-queue
wait play-delay
dispatch clone-event gl-event
; trigger wake-event... smoother for view?
wait 0
; the automated event might have generated queued events.
;print ["^/---------------^/queue: " length? event-queue]
do-queue
]
; are we done?
any [
paused-playback? ; automation was interrupted
empty? automation-queue ; all done
]
]
; disable automation and reset automation-queue to its head.
if empty? automation-queue [
; we're done!
reset-automation
]
]
vout
]
;-----------------
;- automate()
;
; given a block of events or event block specs, perform each event using specified delay
;
; any events triggered by wake-event will be ignored, exception of time events.
;
; when automate is called, playback? is set to true and wake-event will start to ignore
; its own events.
;
; setting paused-playback? will stop do-automation from processing its queue,
; giving wake-event the chance to re-trigger it on time events.
;-----------------
automate: func [
events [block!]
delay [integer! decimal!]
/paused
/local event
][
vin [{automate()}]
reset-automation
foreach event events [
queue-event/automated event ; /automated will add the event to automation-queue
]
playback?: true
paused-playback?: paused ; make sure we don't start paused by default, but allow as an option.
play-delay: delay
do-automation
vout
]
;-----------------
;- reset-automation()
;
; quits playback, clears automation-queue to its head and exits pause mode.
;
; doesn't touch event-log, since that is specifically recording related.
;-----------------
reset-automation: func [
][
vin [{reset-automation()}]
playback?: false
paused-playback?: false
automation-queue: head clear head automation-queue
vout
]
;-----------------
;- start-recording()
;
; enables event logging, also resets the log, if already recording
;
; note that we do not record time events, since they will only
; generate noise. normal time ticks will occur as usuall once
; playback is started, so any time sensitive events will still
; occur, but have current time instead of original time.
;
; refresh rate is also independent of recording, so you can record at
; high-rate, slow down refresh, then playback.
;
; this ultimately allows you to run the playback at cpu speed, if its not
; dependent on time information.
;
; /only allows you to specify a list of event/action types you wish to remember
; note that the block is NOT copied and may be modified at runtime
;-----------------
start-recording: func [
/only events [block! word!]
][
vin [{start-recording()}]
; flush event log
event-log: copy []
; pause play
stop-playback
; set recording stat to true
recording?: true
if only [
if word? events [
events: compose [(events)]
]
record-events: events
]
vout
]
;-----------------
;- record-event()
;
; depending on event types, we record event or not.
;
; only events generated by view whould be submitted here.
;-----------------
record-event: func [
event [object!] "This must be a COPY of original !event object"
][
vin [{record-event()}]
; we ignore useless time events.
either event/action = 'time [
;prin "."
][
switch/default event/action [
move key down up [
append event-log event
]
; these events CAUSE activation to change. we use different action names, to make sure
; no activate cycle is caused. (just like resizing "feedback")
active [
event/action: 'ACTIVATE-WINDOW!
append event-log event
]
inactive [
event/action: 'DEACTIVATE-WINDOW!
append event-log event
]
resize [
event/action: 'RESIZE-WINDOW!
; the coordinates are the actual mouse position while resizing window,
; so we change the value for the window's new size
event/coordinates: event/view-window/size
append event-log event
]
offset [
event/action: 'MOVE-WINDOW!
; the coordinate is the actual mouse position while dragging window
; we substitute the value for new offset
event/coordinates: event/view-window/offset
append event-log event
]
][
;print "Not recording:"
;print event/action
;print event/coordinates
]
]
vout
]
;-----------------
;- stop-recording()
;-----------------
stop-recording: func [
][
vin [{stop-recording()}]
recording?: false
vout
]
;-----------------
;- pause-recording()
;-----------------
pause-recording: func [
][
vin [{pause-recording()}]
vout
]
;-----------------
;- store-recording()
;
; allows you to store a recording for later retrieval using the restore-recording.
;
; note that the view-window property must be wiped out when an automation is stored.
; we replace it with the window's title.
;
; when the recording is later restored, we try to match the Title with any opened window,
; if any are opened.
;
; if none matched (usually cause they are not yet opened), we delay the process, and
; let do-automation map it out a run-time.
;
; note: event/ticks are not cleared at this time. its possible that this could be a
; slight privacy risk since someone could determine time of event by scanning file.
;
; in a further release, we could anonymise this by calculating an offset from first
; tick wrt every other, and then restore current tick time when do-automation is performed.
;-----------------
store-recording: func [
/name filename [word! file! url!]
/safe "do not overwrite previous recording!"
/local file event
][
vin [{store-recording()}]
;print "STORE RECORDING!"
if word? filename [
filename: to-file join to-string filename ".gler" ; gler = glass event recording.
]
filename: any [filename %glass-event-recording.gler]
if all [
safe
exists? filename
][
; <TO DO> pop up a requestor instead?
; error is meant to make it easier to trap when debugging.
to-error "GLASS tried to overwrite event recording, but application asked not to!"
]
; make sure we have access to disk or url
if file: attempt [write filename "" copy ""] [
foreach event event-log [
; replace window by its title
event/view-window: event/view-window/text
; clear fields which will be filled out by core handler (if they are filled for some reason)
event/viewport: none
; event
append file mold/all event
]
write filename file
]
vout
]
;-----------------
;- restore-recording()
;-----------------
restore-recording: func [
/name filename [word! file! url!]
/local window windows item
][
vin [{restore-recording()}]
filename: any [filename %glass-event-recording.gler]