-
Notifications
You must be signed in to change notification settings - Fork 0
/
macmoose.tcl
941 lines (777 loc) · 27.9 KB
/
macmoose.tcl
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
client.register macmoose start
client.register macmoose client_connected
client.register macmoose incoming
proc macmoose.start {} {
global macmoose_use macmoose_log
.output tag configure macmoose_feedback -foreground [colourdb.get darkgreen]
.output tag configure macmoose_error -foreground [colourdb.get red]
set macmoose_use 1
set macmoose_log 0
set macmenu [menu .macmoosemenu]
$macmenu configure -tearoff 0
$macmenu add command -label "Browser" -command "macmoose.create_browser"
$macmenu add command -label "Help" -command macmoose.help
$macmenu add command -label "Send Mail" -command macmoose.mail
window.menu_tools_add_cascade "MacMOOSE" .macmoosemenu
preferences.register macmoose {Out of Band} {
{ {directive MacMOOSELogging}
{type boolean}
{default On}
{display "Log MacMOOSE\nmessages"} }
}
}
proc macmoose.client_connected {} {
global macmoose_use macmoose_log
set default_usage 1
set macmoose_use $default_usage
set use ""
catch {
set use [string tolower [worlds.get [worlds.get_current] UseModuleMacMOOSE]]
}
if { $use == "on" } {
set macmoose_use 1
} elseif { $use == "off" } {
set macmoose_use 0
}
set macmoose_log 0
set log [string tolower [worlds.get_generic On {} {} MacMOOSELogging]]
if { $log == "on" } {
set macmoose_log 1
} elseif { $log == "off" } {
set macmoose_log 0
}
return [modules.module_deferred]
}
proc macmoose.stop {} {}
proc macmoose.incoming event {
global macmoose_fake_args macmoose_use macmoose_log
if { $macmoose_use == 0 } { return [modules.module_deferred] }
set line [db.get $event line]
if { [regexp {^_&_MacMOOSE_(.*)} $line] == 0 } { return [modules.module_deferred] }
if { $macmoose_log == 0 } { db.set $event logging_ignore_incoming 1 }
set space [string first " " $line]
if { $space == -1 } {
set lhs $line
set rhs ""
} else {
set lhs [string range $line 0 [expr $space-1]]
set rhs [string range $line [expr $space+1] end]
}
if { [regexp {^_&_MacMOOSE_([^\(]+)\((.*)\)$} $lhs _ type the_args] } {
} {
set type ""
set the_args ""
}
catch { unset macmoose_fake_args }
macmoose.cgi_populate_array macmoose_fake_args $the_args
macmoose.do_$type $rhs
return [modules.module_ok]
}
proc macmoose.cgi_populate_array { array text } {
upvar $array a
foreach element [split $text "&"] {
set keyval [split $element "="]
set a([lindex $keyval 0]) [lindex $keyval 1]
}
}
proc macmoose.do_set_code data {
macmoose.populate_array keyvals $data
set feedback_tag "macmoose_feedback"
catch {
if { $keyvals(TEXT_COLOR_) == "RED" } {
set feedback_tag "macmoose_error"
}
}
catch {
window.displayCR $keyvals(FEEDBACK_) $feedback_tag
}
}
proc macmoose.do_list_code data {
global macmoose_keyvals macmoose_lines
if { $data == "CODE_END" } {
macmoose.invoke_verb_editor
catch { unset macmoose_keyvals }
catch { unset macmoose_lines }
return
}
if { [regexp {^CODE_LINE_: (.*)} $data null text] } {
lappend macmoose_lines $text
return
}
set macmoose_lines ""
macmoose.populate_array macmoose_keyvals $data
}
proc macmoose.invoke_verb_editor {} {
global macmoose_editordb macmoose_keyvals macmoose_lines macmoose_fake_args
set e [edit.create "Verb Editor" "Verb Editor"]
edit.set_type $e moo-code
edit.SCedit "" $macmoose_lines "" "Verb Editor" "Verb Editor" $e
edit.configure_send $e Send "macmoose.editor_verb_send $e" 1
edit.configure_send_and_close $e "Send and Close" "macmoose.editor_verb_send_and_close $e" 10
edit.configure_close $e Close "macmoose.editor_close $e" 0
foreach key [array names macmoose_keyvals] {
set macmoose_editordb($e:$key) $macmoose_keyvals($key)
}
foreach key [array names macmoose_fake_args] {
set macmoose_editordb($e:$key) $macmoose_fake_args($key)
}
edit.add_toolbar $e info
ttk::frame $e.info
set msg ""
set msg "$msg$macmoose_editordb($e:OBJ_)"
set msg "$msg:"
set msg "$msg$macmoose_editordb($e:CODE_NAME_)"
ttk::label $e.info.l1 -text "$msg"
ttk::label $e.info.la -text " args:"
ttk::entry $e.info.args -width 15 \
-background [colourdb.get pink] \
-font [fonts.fixedwidth]
$e.info.args insert 0 "$macmoose_editordb($e:VERB_DOBJ_) $macmoose_editordb($e:VERB_PREP_) $macmoose_editordb($e:VERB_IOBJ_)"
ttk::label $e.info.lp -text " perms:"
ttk::entry $e.info.perms -width 4 \
-background [colourdb.get pink] \
-font [fonts.fixedwidth]
$e.info.perms insert 0 $macmoose_editordb($e:VERB_PERMS_)
ttk::label $e.info.lo -text " owner: $macmoose_editordb($e:VERB_OWNER_)"
pack $e.info.l1 -side left
pack $e.info.la -side left
pack $e.info.args -side left
pack $e.info.lp -side left
pack $e.info.perms -side left
pack $e.info.lo -side left
edit.repack $e
}
proc macmoose.do_prop_info data {
macmoose.populate_array info $data
set error ""
catch { set error $info(ERROR_) }
if { $error != "" } {
window.displayCR "$info(OBJ_NAME_) ($info(OBJ_)).$info(PROP_NAME_) $error" macmoose_error
return [modules.module_ok]
}
global macmoose_editordb
set e [edit.SCedit "" "" "" "Property Editor" "Property Editor"]
$e.t insert insert "$info(PROP_VALUE_)"
edit.configure_send $e Send "macmoose.editor_property_send $e" 1
edit.configure_send_and_close $e "Send and Close" "macmoose.editor_property_send_and_close $e" 10
edit.configure_close $e Close "macmoose.editor_close $e" 0
foreach key [array names info] { set macmoose_editordb($e:$key) $info($key) }
edit.add_toolbar $e info
ttk::frame $e.info
set msg ""
set msg "$msg$macmoose_editordb($e:OBJ_)"
set msg "$msg."
set msg "$msg$macmoose_editordb($e:PROP_NAME_)"
label $e.info.l -text "$msg"
ttk::label $e.info.lp -text " perms:"
ttk::entry $e.info.perms -width 4 \
-background [colourdb.get pink] \
-font [fonts.fixedwidth]
$e.info.perms insert 0 "$macmoose_editordb($e:PROP_PERMS_)"
ttk::label $e.info.lo -text " owner: $macmoose_editordb($e:PROP_OWNER_)"
pack $e.info.l -side left
pack $e.info.lp -side left
pack $e.info.perms -side left
pack $e.info.lo -side left
edit.repack $e
return [modules.module_ok]
}
proc macmoose.editor_property_send_and_close editor {
macmoose.editor_property_send $editor
edit.destroy $editor
}
proc macmoose.editor_property_send editor {
global macmoose_editordb
set line "#$#MacMOOSE"
set line "$line set_prop"
set line "$line PREFIX_: _&_MacMOOSE_set_prop()"
set line "$line OBJ_: $macmoose_editordb($editor:OBJ_)"
set line "$line PROP_NAME_: $macmoose_editordb($editor:PROP_NAME_)"
set perms [$editor.info.perms get]
if { ($perms != "") &&
($perms != $macmoose_editordb($editor:PROP_PERMS_)) } {
set line "$line PERMS_: $perms"
}
set value [$editor.t get 1.0 end]
set line "$line VALUE_: $value"
io.outgoing $line
}
proc macmoose.do_set_prop data {
macmoose.populate_array keyvals $data
catch { window.displayCR $keyvals(ERROR_) macmoose_error }
set feedback_tag macmoose_feedback
catch {
if { $keyvals(TEXT_COLOR_) == "RED" } {
set feedback_tag macmoose_error
}
}
catch { window.displayCR $keyvals(FEEDBACK_) $feedback_tag }
}
proc macmoose.editor_verb_send_and_close editor {
macmoose.editor_verb_send $editor
edit.destroy $editor
}
proc macmoose.editor_verb_send editor {
global macmoose_editordb
set line "#$#MacMOOSE"
set line "$line set_code"
set line "$line PREFIX_: _&_MacMOOSE_set_code()"
set line "$line CODE_NAME_: $macmoose_editordb($editor:CODE_NAME_)"
set line "$line OBJ_: $macmoose_editordb($editor:OBJ_)"
set args [$editor.info.args get]
set old_args "$macmoose_editordb($editor:VERB_DOBJ_) $macmoose_editordb($editor:VERB_PREP_) $macmoose_editordb($editor:VERB_IOBJ_)"
if { ($args != "") && ($args != $old_args) && ([llength $args] == 3)} {
set line "$line VERB_DOBJ_: [lindex $args 0]"
set line "$line VERB_PREP_: [lindex $args 1]"
set line "$line VERB_IOBJ_: [lindex $args 2]"
}
set perms [$editor.info.perms get]
if { ($perms != "") && ($perms != $macmoose_editordb($editor:VERB_PERMS_)) } {
set line "$line PERMS_: $perms"
}
set value ""
foreach thing [edit.get_text $editor] {
regsub -all "/" $thing "\\/" thing
if { $value == "" } {
set value $thing
} {
set value "$value/$thing"
}
}
set line "$line VALUE_: $value"
io.outgoing $line
}
proc macmoose.editor_close editor {
global macmoose_editordb
foreach {key val} [array get macmoose_editordb "$editor:*"] {
unset macmoose_editordb($key)
}
edit.destroy $editor
}
proc macmoose.do_object_parents data {
global macmoose_keyvals macmoose_current_object \
macmoose_fake_args
catch { unset macmoose_keyvals }
macmoose.populate_array macmoose_keyvals $data
set browser ""
catch { set browser $macmoose_fake_args(_BROWSER_) }
if { $browser == "" } { set browser [macmoose.create_browser] }
set error ""
catch { set error $macmoose_keyvals(ERROR_) }
if { $error != "" } {
window.displayCR "$error" macmoose_error
return [modules.module_ok]
}
set object_menu {}
set names [split $macmoose_keyvals(PARENT_NAMES_) "/"]
foreach item [split $macmoose_keyvals(PARENT_OBJS_) "/"] {
if { $item != "" } {
set obj $item
set name [lindex $names 0]
regsub { *\(#.*\)$} $name {} name
lappend object_menu [list "$obj" "$name"]
}
set names [lrange $names 1 end]
}
db.set $browser object_menu $object_menu
macmoose.post_object_menu $browser
macmoose.object_info $browser $obj
}
proc macmoose.do_object_info data {
global macmoose_keyvals
catch { unset macmoose_keyvals }
macmoose.populate_array macmoose_keyvals $data
macmoose.invoke_browser
}
proc macmoose.invoke_browser {} {
global macmoose_keyvals macmoose_current_object \
macmoose_fake_args
set browser ""
catch { set browser $macmoose_fake_args(_BROWSER_) }
if { $browser == "" } { set browser [macmoose.create_browser] }
$browser.lists.v.verbs.l delete 0 end
foreach verb [lsort [split $macmoose_keyvals(VERBS_) "/"]] {
if { $verb == "" } { continue }
$browser.lists.v.verbs.l insert end $verb
}
$browser.lists.p.props.l delete 0 end
foreach prop [lsort [split $macmoose_keyvals(PROPS_) "/"]] {
if { $prop == "" } { continue }
$browser.lists.p.props.l insert end $prop
}
wm title $browser "Browser on $macmoose_keyvals(OBJ_NAME_)"
set macmoose_current_object $macmoose_keyvals(OBJ_)
db.set $browser current_object $macmoose_keyvals(OBJ_)
set found 0
set object_menu [db.get $browser object_menu]
foreach object_name $object_menu {
set object [lindex $object_name 0]
set name [lindex $object_name 1]
if { ($object == $macmoose_keyvals(OBJ_)) &&
($name == $macmoose_keyvals(OBJ_NAME_)) } {
set found 1
break;
}
}
if { $found != 1 } {
lappend object_menu [list "$macmoose_keyvals(OBJ_)" "$macmoose_keyvals(OBJ_NAME_)"]
db.set $browser object_menu $object_menu
macmoose.post_object_menu $browser
}
}
proc macmoose.object_info { browser object } {
set line "#$#MacMOOSE object_info"
set line "$line OBJ_: $object"
set special "_BROWSER_=$browser"
set line "$line PREFIX_: _&_MacMOOSE_object_info($special)"
io.outgoing $line
}
proc macmoose.object_parents { browser object } {
set line "#$#MacMOOSE object_parents"
set line "$line OBJ_: $object"
set special "_BROWSER_=$browser"
set line "$line PREFIX_: _&_MacMOOSE_object_parents($special)"
io.outgoing $line
}
proc macmoose.list_code { browser code_name } {
set current_object [db.get $browser current_object]
if { $current_object == "" } { return }
set line "#$#MacMOOSE list_code"
set line "$line OBJ_: $current_object"
regsub -all {\*} $code_name {} code_name
set code_name [lindex $code_name 0]
set line "$line CODE_NAME_: $code_name"
set line "$line PREFIX_: _&_MacMOOSE_list_code(CODE_NAME_=$code_name&OBJ_=$current_object)"
io.outgoing $line
}
proc macmoose.prop_info { browser prop_name } {
set current_object [db.get $browser current_object]
if { $current_object == "" } { return }
set line "#$#MacMOOSE prop_info"
set line "$line OBJ_: $current_object"
set line "$line PROP_NAME_: $prop_name"
set line "$line PREFIX_: _&_MacMOOSE_prop_info()"
io.outgoing $line
}
proc macmoose.do_declare_code data {
macmoose.populate_array info $data
set error ""
catch { set error $info(ERROR_) }
if { $error != "" } {
window.displayCR "Whoops!: $error" macmoose_error
return [modules.module_ok]
}
set ok 0
catch { set ok $info(DECLARE_CODE_) }
if { $ok == 1 } { window.displayCR "Code Added." macmoose_feedback } { }
return [modules.module_ok]
}
proc macmoose.do_declare_prop data {
macmoose.populate_array info $data
set error ""
catch { set error $info(ERROR_) }
if { $error != "" } {
window.displayCR "Whoops!: $error" macmoose_error
return [modules.module_ok]
}
set ok 0
catch { set ok $info(DECLARE_PROP_) }
if { $ok == 1 } { window.displayCR "Property Added." macmoose_feedback } { }
return [modules.module_ok]
}
proc macmoose.add_dialog w {
global macmoose_add macmoose_current_object
switch $macmoose_add {
script {
set name [$w.s.name get]
set perms [$w.s.perms get]
set args [$w.s.args get]
set dobj [lindex $args 0]
set prep [lindex $args 1]
set iobj [lindex $args 2]
if { $name == "" } { return }
set obj $macmoose_current_object
set obj [db.get $w browser current_object]
set line "#$#MacMOOSE declare_code"
set line "$line CODE_NAME_: $name"
set line "$line OBJ_: $obj"
set line "$line VERB_DOBJ_: $dobj"
set line "$line VERB_PREP_: $prep"
set line "$line VERB_IOBJ_: $iobj"
set line "$line PERMS_: $perms"
set line "$line PREFIX_: _&_MacMOOSE_declare_code()"
}
property {
set name [$w.p.name get]
set perms [$w.p.perms get]
if { $name == "" } { return }
set obj $macmoose_current_object
set obj [db.get $w browser current_object]
set line "#$#MacMOOSE declare_prop"
set line "$line PROP_NAME_: $name"
set line "$line OBJ_: $obj"
set line "$line PERMS_: $perms"
set line "$line PREFIX_: _&_MacMOOSE_declare_prop()"
}
}
io.outgoing $line
macmoose.object_info [db.get $w browser] $obj
}
proc macmoose.add_script_or_property browser {
global macmoose_add
set macmoose_add script
set w .[util.unique_id "macmoose_add"]
catch { destroy $w; db.drop $w }
toplevel $w
window.place_nice $w
wm iconname $w "Add script or property"
wm title $w "Add script or property"
db.set $w browser $browser
label $w.l -text "add a script or property"
ttk::frame $w.s
ttk::radiobutton $w.s.r -text "script" \
-variable macmoose_add -value script \
-width 10
ttk::label $w.s.lname -text "name:"
ttk::entry $w.s.name \
-width 15 \
-background [colourdb.get pink] \
-font [fonts.fixedwidth]
ttk::label $w.s.lperms -text "perms:"
ttk::entry $w.s.perms \
-width 4 \
-background [colourdb.get pink] \
-font [fonts.fixedwidth]
$w.s.perms insert 0 "rd"
ttk::label $w.s.largs -text "args:"
ttk::entry $w.s.args \
-width 15 \
-background [colourdb.get pink] \
-font [fonts.fixedwidth]
$w.s.args insert 0 "none none none"
pack $w.s.r -side left
pack $w.s.lname -side left
pack $w.s.name -side left
pack $w.s.lperms -side left
pack $w.s.perms -side left
pack $w.s.largs -side left
pack $w.s.args -side left
ttk::frame $w.p
ttk::radiobutton $w.p.r -text "property" \
-variable macmoose_add -value property \
-width 10
ttk::label $w.p.lname -text "name:"
ttk::entry $w.p.name \
-width 15 \
-background [colourdb.get pink] \
-font [fonts.fixedwidth]
ttk::label $w.p.lperms -text "perms:"
ttk::entry $w.p.perms \
-width 4 \
-background [colourdb.get pink] \
-font [fonts.fixedwidth]
$w.p.perms insert 0 "rc"
pack $w.p.r -side left
pack $w.p.lname -side left
pack $w.p.name -side left
pack $w.p.lperms -side left
pack $w.p.perms -side left
pack $w.l -side top
pack $w.s -side top -expand 1 -fill x
pack $w.p -side top -expand 1 -fill x
ttk::frame $w.controls
ttk::button $w.controls.a -text "Add" -command "macmoose.add_dialog $w"
ttk::button $w.controls.c -text "Close" -command "destroy $w; db.drop $w"
pack $w.controls.a $w.controls.c -side left \
-padx 5 -pady 5
pack $w.controls -side bottom
window.focus $w
}
proc macmoose.toplevel w { return [winfo toplevel $w] }
proc macmoose.post_object_menu browser {
$browser.cmenu.object delete 0 end
set object_menu [db.get $browser object_menu]
if { $object_menu != {} } {
foreach object_name $object_menu {
set object [lindex $object_name 0]
set name [lindex $object_name 1]
$browser.cmenu.object add command \
-label "$name ($object)" \
-command "macmoose.object_info $browser $object"
}
} {
$browser.cmenu.object add command \
-label "No object selected" \
-state disabled
}
$browser.cmenu.object add separator
$browser.cmenu.object add command -label "Close" \
-underline 0 \
-command "macmoose.destroy_browser $browser"
}
proc macmoose.destroy_browser browser {
destroy $browser
db.drop $browser
}
proc macmoose.create_browser {} {
set browser .[util.unique_id "macmoose_browser"]
catch { destroy $browser; db.drop $browser }
toplevel $browser
window.place_nice $browser
menu $browser.cmenu
$browser configure -menu $browser.cmenu
wm iconname $browser "Macmoose"
wm title $browser "Macmoose"
db.set $browser current_object ""
db.set $browser object_menu {}
$browser.cmenu add cascade -label "Object" -menu $browser.cmenu.object \
-underline 0
menu $browser.cmenu.object -tearoff 0
$browser.cmenu add cascade -label "Tools" -menu $browser.cmenu.tools \
-underline 0
menu $browser.cmenu.tools -tearoff 0
$browser.cmenu.tools add command -label "Add Script/Property" \
-underline 0 \
-command "macmoose.add_script_or_property $browser"
$browser.cmenu.tools add command -label "New Browser" \
-underline 0 \
-command macmoose.create_browser
ttk::frame $browser.toolbar
ttk::label $browser.toolbar.l -text "Browse:" -width 7 -anchor e
ttk::entry $browser.toolbar.e \
-font [fonts.fixedwidth] \
-background [colourdb.get pink]
bind $browser.toolbar.e <Return> {
set object [%W get]
if { $object != "" } {
macmoose.object_parents [macmoose.toplevel %W] $object
}
%W delete 0 end
}
pack $browser.toolbar.l -side left
pack $browser.toolbar.e -side left
pack $browser.toolbar -side top \
-fill x
ttk::frame $browser.lists
ttk::frame $browser.lists.v
ttk::label $browser.lists.v.l -text "Scripts / Verbs"
ttk::frame $browser.lists.v.verbs
listbox $browser.lists.v.verbs.l \
-highlightthickness 0 \
-background #ffffff \
-yscrollcommand "$browser.lists.v.verbs.s set"
bind $browser.lists.v.verbs.l <Double-ButtonRelease-1> {
macmoose.list_code [macmoose.toplevel %W] [%W get @%x,%y]
}
bind $browser.lists.v.verbs.l <Triple-ButtonRelease-1> {
}
ttk::scrollbar $browser.lists.v.verbs.s \
-command "$browser.lists.v.verbs.l yview"
pack $browser.lists.v.verbs.l -side left -fill both -expand 1
pack $browser.lists.v.verbs.s -side right -fill y
pack $browser.lists.v.l -side top
pack $browser.lists.v.verbs -side bottom -fill both -expand 1
ttk::frame $browser.lists.p
ttk::label $browser.lists.p.l -text "Properties"
ttk::frame $browser.lists.p.props
listbox $browser.lists.p.props.l \
-highlightthickness 0 \
-background #ffffff \
-yscrollcommand "$browser.lists.p.props.s set"
bind $browser.lists.p.props.l <Double-ButtonRelease-1> {
macmoose.prop_info [macmoose.toplevel %W] [%W get @%x,%y]
}
bind $browser.lists.p.props.l <Triple-ButtonRelease-1> {
}
ttk::scrollbar $browser.lists.p.props.s \
-command "$browser.lists.p.props.l yview"
pack $browser.lists.p.props.l -side left -fill both -expand 1
pack $browser.lists.p.props.s -side right -fill y
pack $browser.lists.p.l -side top
pack $browser.lists.p.props -side bottom -fill both -expand 1
pack $browser.lists.v -side left -fill both -expand 1
pack $browser.lists.p -side right -fill both -expand 1
pack $browser.lists -side bottom -fill both -expand 1
macmoose.post_object_menu $browser
window.focus $browser.toolbar.e
return $browser
}
proc macmoose.populate_array {array string} {
upvar $array a
set key ""
set value ""
regsub -all {\\} $string {\\\\} string
while { $string != "" } {
set space [string first " " $string]
if { $space != -1 } {
set left [string range $string 0 [expr $space - 1]]
set string [string range $string [expr $space + 1] end]
if { [regexp {^[A-Z_]+_:$} $left] } {
if { $key != "" } {
if { ($value == "") || ([string first " " $value] != -1) } {
append correct " $key \"$value\""
} else {
append correct " $key $value"
}
}
set key $left
set value ""
} else {
regsub -all {\"} $left {\\"} left
if { $value == "" } {
set value $left
} else {
append value " $left"
}
}
} else {
regsub -all {\"} $string {\\"} string
if { $value == "" } {
set value $string
} else {
append value " $string"
}
break
}
}
if { $key != "" } {
if { ($value == "") || ([string first " " $value] != -1) } {
append correct " $key \"$value\""
} else {
append correct " $key $value"
}
}
set correct [string trimleft $correct]
util.populate_array a $correct
}
proc macmoose.help {} {
global win
set win .[util.unique_id help]
toplevel $win
wm title $win "MacMOOSE Help"
ttk::frame $win.entry
ttk::label $win.entry.text -text "Enter help query: "
ttk::entry $win.entry.entry
ttk::button $win.entry.button -text "Search" -command {macmoose.search $win}
bind $win.entry.entry <Return> {macmoose.search $win}
ttk::frame $win.msg
text $win.msg.text -yscrollcommand "$win.msg.sby set" -state disabled
ttk::scrollbar $win.msg.sby -orient vert -command "$win.msg.text yview"
ttk::button $win.close -text "Close" -command {destroy $win}
pack $win.entry
pack $win.entry.text -side left
pack $win.entry.entry -side left
pack $win.entry.button -side right
pack $win.msg
pack $win.msg.text -side left
pack $win.msg.sby -expand yes -fill both -side right
pack $win.close
}
proc macmoose.search win {
set topic [$win.entry.entry get]
set msg $win.msg.text
set line "#$#MacMOOSE"
set line "$line help"
set line "$line PREFIX_: _&_MacMOOSE_help(win_=$win)"
set line "$line TOPIC_: $topic"
io.outgoing $line
$msg conf -state normal
$msg insert end "$topic\n"
$msg conf -state disabled
}
proc macmoose.do_help data {
global macmoose_fake_args
set win $macmoose_fake_args(win_)
set msg $win.msg.text
$msg tag configure machelp_error -foreground [colourdb.get red]
if {$data == "HELP_START"} {
$msg conf -state normal
$msg insert end "-----\n"
$msg conf -state disabled
}
if { [string range $data 0 8] == "HELP_LINE"} {
macmoose.populate_array keyvals $data
$msg conf -state normal
$msg insert end "\n$keyvals(HELP_LINE_)\n"
$msg conf -state disabled
}
if {$data == "HELP_END"} {
$msg conf -state normal
$msg insert end "\n-----\n"
$msg conf -state disabled
}
if {[string range $data 0 5] == "ERROR_"} {
macmoose.populate_array keyvals $data
$msg conf -state normal
$msg insert end "\n$keyvals(ERROR_) machelp_error\n-----\n"
$msg conf -state disabled
}
}
proc macmoose.mail {} {
global win
set win .[util.unique_id mail]
toplevel $win
wm title $win "MacMOOSE Send Mail"
ttk::frame $win.to
ttk::label $win.to.text -text "To:" -width 8
ttk::entry $win.to.entry
ttk::frame $win.subject
ttk::label $win.subject.text -text "Subject:" -width 8
ttk::entry $win.subject.entry
ttk::frame $win.msg
ttk::label $win.msg.text -text "Message:"
text $win.msg.msg
ttk::scrollbar $win.msg.sby -orient vert
ttk::frame $win.buttons
ttk::button $win.buttons.send -text "Send" -command {macmoose.verify_mail_recipients $win [$win.to.entry get]}
ttk::button $win.buttons.cancel -text "Cancel" -command {destroy $win}
pack $win.to -anchor w
pack $win.to.text -side left
pack $win.to.entry -side right
pack $win.subject -anchor w
pack $win.subject.text -side left
pack $win.subject.entry -side right
pack $win.msg
pack $win.msg.text -anchor w
pack $win.msg.sby -side right -fill both -expand yes
pack $win.msg.msg
pack $win.buttons
pack $win.buttons.send -side left
pack $win.buttons.cancel -side left
$win.msg.msg conf -yscrollcommand {$win.msg.sby set}
$win.msg.sby conf -command {$win.msg.msg yview}
}
proc macmoose.verify_mail_recipients {win to} {
set to [string map {" " /} $to]
set line "#$#MacMOOSE"
set line "$line verify_mail_recipients"
set line "$line PREFIX_: _&_MacMOOSE_send_mail(win_=$win)"
set line "$line RECIPIENTS_: $to"
io.outgoing $line
}
proc macmoose.do_send_mail data {
global macmoose_fake_args
macmoose.populate_array keyvals $data
set to $keyvals(VALID_RECIPIENTS_)
set win $macmoose_fake_args(win_)
set subject [$win.subject.entry get]
set msg [$win.msg.msg get 1.0 end-1c]
set msg [string map {/ "\\/" \n /} $msg]
set line "#$#MacMOOSE"
set line "$line send_mail"
set line "$line PREFIX_: _&_MacMOOSE_recieved(win_=$win)"
set line "$line RECIPIENTS_: $to"
set line "$line SUBJECT_: $subject"
set line "$line BODY_: $msg"
io.outgoing $line
}
proc macmoose.do_recieved data {
global macmoose_fake_args
macmoose.populate_array keyvals $data
if {$keyvals(SEND_MAIL_) == 1} {
tk_dialog .[util.unique_id popup] "Mail Sent" "Mail Sent Successfully" "" 0 OK
destroy $macmoose_fake_args(win_)
} else {
tk_dialog .[util.unique_id popup] "Mail failed" "Sending Failed" "" 0 OK
}
}