forked from fuzzball-muck/trebuchet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrebuchet.tcl
executable file
·2383 lines (2160 loc) · 81.7 KB
/
Trebuchet.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
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
#!/bin/sh
# the next line restarts using wish \
exec wish "$0" "$@"
#############################################################################
#
# Trebuchet Tk
# copyright 1997-2016 by Fuzzball Software
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#############################################################################
package require opt
catch { package require Img }
catch { package require sound }
catch { package require griffin }
#################################
# GLOBAL VARIABLES
#
global treb_revision; set treb_revision 1082
global treb_version; set treb_version "1.[format %03d [expr {$treb_revision - 1000}]]"
global treb_name; set treb_name "Trebuchet Tk"
global wordchars; set wordchars {-A-Za-z0-9_\'\\.}
global wordchar; set wordchar "\[$wordchars\]"
global nonwordchar; set nonwordchar "\[^$wordchars\]"
set domain_chars {[a-z0-9_.-]}
set domain_start "\[a-z0-9_-\]$domain_chars*\[a-z0-9_-\]"
set domain_end {\.[a-z][a-z]+}
set url_end {[^() ]*[a-z0-9_/]}
set ftp_regexp "ftp://$url_end|ftp\\.$url_end"
set web_regexp "http://$url_end"
append web_regexp "|$domain_start\\.$domain_start$domain_end"
append web_regexp "|$domain_start\\.$domain_start$domain_end$url_end"
append web_regexp "|$domain_start\\.$domain_start$domain_end\[\[:>:\]\]"
append web_regexp "|$domain_start\\.$domain_start$domain_end\[\[:>:\]\]$url_end"
append web_regexp "|\[\\d\]+\\.\[\\d\]+\\.\[\\d\]+\\.\[\\d\]+"
append web_regexp "|\[\\d\]+\\.\[\\d\]+\\.\[\\d\]+\\.\[\\d\]+$url_end"
append web_regexp "|\[\\d\]+\\.\[\\d\]+\\.\[\\d\]+\\.\[\\d\]+\[\[:>:\]\]"
append web_regexp "|\[\\d\]+\\.\[\\d\]+\\.\[\\d\]+\\.\[\\d\]+\[\[:>:\]\]$url_end"
set web2_regexp "https://$url_end"
set rtsp_regexp "rtsp://$url_end"
set mail_regexp "mailto:\[a-z0-9_+.-\]*\[a-z0-9\]@\[a-z0-9\]$domain_chars*$domain_end\[^ \"\]*"
set mail_regexp2 "\[a-z0-9_+.-\]*\[a-z0-9\]@$domain_start$domain_end"
global url_regexp
set url_regexp "$ftp_regexp|$web_regexp|$web2_regexp|$mail_regexp|$mail_regexp2|$rtsp_regexp"
global errors_nonfatal; set errors_nonfatal 0
global cmdhist; set cmdhist {}
global cmdhistnum; set cmdhistnum -1
global defpri; set defpri {10}
global mpid; set mpid 1
global dirty_preferences; set dirty_preferences 0
global styleslist; set styleslist {}
global forcedelete; set forcedelete 0
global widget;
set widget(bars) {.mw.bars}
set widget(compass) {.mw.bars.compass}
set widget(qbuttons) {.mw.bars.qbuttons}
set widget(disp) {.mw.top.disp}
set widget(backdrop) {.mw.top.disp.backdrop}
set widget(worldsbar) {.mw.top.worlds}
set widget(inbuf) {.mw.bot.inbuf}
set widget(statbar) {.mw.top.status}
set widget(loglight) {.mw.statusbar.log}
global treb_colors
#################################
proc find_windows_prefsfile {} {
global treb_prefs_dir treb_root_dir treb_save_file
set treb_save_file {}
package require registry 1.0
set key "HKEY_CURRENT_USER\\Software\\Fuzzball Software\\Trebuchet Tk\\1.0"
if {![catch {registry get $key "prefsfile"} file]} {
if {[file isfile $file]} {
if {[file readable $file]} {
set treb_save_file $file
return ""
} else {
tk_messageBox -type "ok" -title "Preferences File Unreadable" \
-message "The file '$file' isn't readable. Please specify a different file, or fix the permissions."
}
}
} else {
# No registry entry. Probably first time run on this machine.
return ""
}
# Prefs file was moved or is now unreadable.
set filetypes {
{{Trebuchet Preferences Files} {.trc} TEXT}
}
set initdir $treb_prefs_dir
set initfile "trebprefs.trc"
if {$file != "" && [file isfile $file]} {
set initdir [file dirname $file]
set initfile [file tail $file]
} elseif {[file isfile [file join $treb_root_dir "trebpref.trc"]]} {
set initdir $treb_root_dir
}
while (1) {
set dofind [tk_messageBox -title {Trebuchet Preferences File} \
-message "Unable to open Trebuchet's preferences file. Would you like to specify its location?" \
-type yesno -icon warning -default "no"]
if {$dofind == "no"} {
catch {registry delete $key "prefsfile"}
set treb_save_file {}
return ""
}
set treb_save_file [tk_getOpenFile -defaultextension .trc \
-initialdir $initdir \
-initialfile "trebpref.trc" \
-title {Specify Trebuchet Preferences File} \
-filetypes $filetypes]
if {$treb_save_file != ""} {
set dir [file dirname $treb_save_file]
if {![file isdirectory $dir]} {
tk_messageBox -type "ok" -title "Preferences File Unwritable" \
-message "The directory '$dir' does not exist."
} elseif {![file writable $dir]} {
tk_messageBox -type "ok" -title "Preferences File Unwritable" \
-message "You do not have permission to write to the directory '$dir'. You will need to save your prefs to a different directory or, fix the directory permissions."
} elseif {![file readable $treb_save_file]} {
tk_messageBox -type "ok" -title "Preferences File Unreadable" \
-message "The file '$file' isn't readable. Please specify a different file, or fix the permissions."
} elseif {![file writable $treb_save_file]} {
tk_messageBox -type "ok" -title "Preferences File Unwritable" \
-message "You do not have permission to write to the file '$file'. You will need to save your prefs to a different file, later, or fix the file permissions."
} else {
registry set $key "prefsfile" $treb_save_file
return ""
}
}
}
}
proc /clock_clicks {} {
if {![catch {clock clicks -milliseconds} millis]} {
return $millis
} else {
return [clock clicks]
}
}
proc calculate_clicks_per_second {} {
global clicks_per_second
if {![catch {clock clicks -milliseconds}]} {
set clicks_per_second 1000
} else {
set now [clock seconds]
while {$now == [clock seconds]} {
set sclick [clock clicks]
}
set now [clock seconds]
while {$now == [clock seconds]} {
set eclick [clock clicks]
}
set clicks_per_second [expr {$eclick - $sclick}]
}
}
proc timetest {args} {
global clicks_per_second
set st [/clock_clicks]
set result [uplevel 1 $args]
set en [/clock_clicks]
set secs [expr {int((($en-$st)*1000.0)/($clicks_per_second*1.0))}]
/echo -style results [format "%5d ms: %s" $secs $args]
return $result
}
proc init {argc argv} {
global tcl_platform tcl_version
global treb_colors treb_save_file
global treb_root_dir treb_lib_dir
global treb_docs_dir treb_document_dir
global treb_tool_dir treb_temp_dir
global treb_cacerts_dir treb_prefs_dir
global argv0 env treb_fonts
set tclpatchlevel [info patchlevel]
set pattern {^([0-9][0-9]*)[^0-9]([0-9][0-9]*)([^0-9])([0-9][0-9]*)}
regexp $pattern $tclpatchlevel dummy vermajor verminor separ patchlevel
if {$separ != "."} {
set patchlevel 0
}
set tcl_platform(vermajor) $vermajor
set tcl_platform(verminor) $verminor
set tcl_platform(patchlevel) $patchlevel
if {[catch {tk windowingsystem} winsys]} {
if {$tcl_platform(os) == "Darwin"} {
set winsys "aqua"
} elseif {$tcl_platform(platform) == "windows"} {
set winsys "win32"
} elseif {$tcl_platform(platform) == "macintosh"} {
set winsys "classic"
} else {
set winsys "x11"
}
}
set tcl_platform(winsys) $winsys
if {[info exists env(TREB_ROOT_DIR)]} {
set treb_root_dir $env(TREB_ROOT_DIR)
} elseif {$argv0 != {}} {
set myexec $argv0
# Make sure we find the REAL Trebuchet.tcl, and not a softlink.
while {![catch {file readlink $myexec}]} {
set myexec [file join \
[file dirname $myexec] \
[file readlink $myexec]]
}
# The root trebuchet dir is the dir that Trebuchet.tcl is in.
set treb_root_dir [file dirname $myexec]
if {$myexec == "Trebuchet.tcl"} {
set treb_root_dir ""
} elseif {$tcl_platform(winsys) == "aqua"} {
set treb_root_dir [file join $treb_root_dir .. .. .. trebuchet]
}
} else {
tk_messageBox -default ok -type ok -icon error \
-title {Trebuchet error} -message "Trebuchet was unable to find its libraries.\nYou may need to set your TREB_ROOT_DIR environment variable."
exit
}
if {$tcl_platform(os) == "Darwin"} {
# The "correct" place for document files on the mac (OS X)
# is in ~/Library/Preferences folder
set treb_document_dir [file join $env(HOME) Documents]
} elseif {$tcl_platform(platform) == "macintosh"} {
# The "correct" place for document files on the mac (OS 9)
# is in the application's directory.
set treb_document_dir $env(HOME)
} elseif {[info exists env(HOME)]} {
# For Windows and Unix, use the user's home dir.
set treb_document_dir $env(HOME)
if {![file exists $treb_document_dir]} {
set treb_document_dir $treb_root_dir
}
} else {
set treb_document_dir $treb_root_dir
}
if {$tcl_platform(os) == "Darwin"} {
# The "correct" place for preferences files on the mac (OS X)
# is in ~/Library/Preferences folder
set treb_prefs_dir [file join $env(HOME) Library Preferences]
} elseif {$tcl_platform(platform) == "macintosh"} {
# The "correct" place for preferences files on the mac (OS 9)
# is in the preferences folder
set treb_prefs_dir $env(PREF_FOLDER)
} elseif {[info exists env(HOME)]} {
set treb_prefs_dir $env(HOME)
if {$tcl_platform(platform) == "windows"} {
if {![file exists $treb_prefs_dir]} {
set treb_prefs_dir $treb_root_dir
}
}
} else {
set treb_prefs_dir $treb_root_dir
}
set treb_lib_dir [file join $treb_root_dir lib]
set treb_docs_dir [file join $treb_root_dir docs]
set treb_tool_dir [file join $treb_root_dir pkgs]
# Windows Tk (8.3.3) generally gets 96 DPI.
# Linux Tk (8.3.3) uses the DPI the X server tells it, usually misconfigured.
# OS X Aqua Tk (8.4.4) is hardcoded to 72 DPI, regardless of what the OS says.
# Grrr.
if {$tcl_platform(winsys) == "aqua"} {
# Because OS X assumes 72 DPI, and windows usually assumes 96,
# Lets scale OS X fonts to match the Windows size, so folks
# can swap between machines using the same prefs.
tk scaling 1.3333333333333
}
# Under Linux (and probably MacOS-X), newer Tk versions may use the Xft fonts,
# which causes a havoc in Trebuchet fonts (some anti-aliased fonts not being
# available for all attributes, causing different font sizes to be used
# depending whether the font is bold and/or italic, which in turn causes
# missaligned columns in formatted text using the monospacing font...
# With this code, we try and use the default Helvetica and Courier bitmap
# fonts that older Tk versions always used...
# Helvetica is then also being used for the GUI (preventing ugly blury text in
# the menus).
# Note that the actual availability of the Helvetica and Courier bitmap fonts
# still depend on your system's fontconfig configuration: you may have to remove
# some configuration file(s) in /etc/fonts/conf.d/ to get rid of the aliases of
# bitmap fonts to anti-aliased fonts.
# You still may use --sysfonts to force the use of system fonts with Xft-enabled
# Tk, and you may use --stdfonts to force the use of Helvetica/Courier fonts
# with non-Xft-enabled Tk.
if {[catch {::tk::pkgconfig get fontsystem} xft]} {set xft no-xft}
if {$tcl_platform(platform) == "unix" && $tcl_platform(os) != "Darwin" && $xft == "xft"} {
set standard_fonts 1
} else {
set standard_fonts 0
}
set standard_fonts [expr {($standard_fonts == 1 && [lsearch -exact $argv "--sysfonts"] == -1) || [lsearch -exact $argv "--stdfonts"] != -1}]
if {$standard_fonts} {
array set tmp_font [font actual Helvetica]]
} else {
label .fontcheck
array set tmp_font [font actual [lrange [.fontcheck cget -font] 0 1]]
destroy .fontcheck
}
set sansfont [list $tmp_font(-family) $tmp_font(-size)]
set sansh [font metrics $sansfont -linespace]
if {[font metrics $sansfont -fixed]} {
array set tmp_font [font actual [list Helvetica -$sansh]]
set sansfont [list $tmp_font(-family) $tmp_font(-size)]
}
set treb_fonts(sansserif) $sansfont
font create default_system_font -family $tmp_font(-family) -size $tmp_font(-size)
option add *font default_system_font
set small_size [expr {int(0.8*$tmp_font(-size))}]
if {$small_size < 8} {
set small_size 8
}
array set tmp_font [font actual [list $tmp_font(-family) $small_size]]
set bbarfont [list $tmp_font(-family) $tmp_font(-size)]
set treb_fonts(bbar) $bbarfont
unset tmp_font
if {$standard_fonts} {
array set tmp_font [font actual Courier]]
} else {
text .fontcheck
array set tmp_font [font actual [lrange [.fontcheck cget -font] 0 1]]
destroy .fontcheck
}
set fixedfont [list $tmp_font(-family) $tmp_font(-size)]
# set fixedh [font metrics $fixedfont -linespace]
set fixedh $tmp_font(-size)
if {![font metrics $fixedfont -fixed]} {
array set tmp_font [font actual [list Courier $fixedh]]
set fixedfont [list $tmp_font(-family) $tmp_font(-size)]
}
set treb_fonts(fixed) $fixedfont
unset tmp_font
array set tmp_font [font actual [list Times -$sansh]]
set treb_fonts(serif) [list $tmp_font(-family) $tmp_font(-size)]
unset tmp_font
array set tmp_font [font actual [concat $treb_fonts(sansserif) bold underline]]
set treb_fonts(url) [list $tmp_font(-family) $tmp_font(-size) bold underline]
unset tmp_font
set treb_fonts(worldbar) $treb_fonts(sansserif)
if {$tcl_platform(winsys) == "aqua"} {
set treb_fonts(worldbar) $treb_fonts(bbar)
}
if {[lsearch -exact $argv "--tkshell"] != -1} {
return
}
source [file join $treb_lib_dir webview.tcl]
if {($vermajor != 8 || $verminor < 3)} {
set mesg "Trebuchet Tk requires TCL/Tk version 8.3 or later to run."
if {$tcl_platform(winsys) == "x11"} {
append mesg "\nPlease fetch and install the latest TCL/Tk 8 interpreter for your operating system."
} else {
append mesg "\nPlease fetch and install the latest version of Trebuchet from:"
}
set tclurl "https://sourceforge.net/projects/trebuchet/"
label .icon -bitmap error -foreground red
label .text -text $mesg -anchor sw -justify left -font $treb_fonts(sansserif)
label .url -text $tclurl -anchor nw -justify left -foreground blue -font $treb_fonts(url) -cursor hand2
button .btn -text Okay -command exit
bind .url <ButtonPress-1> "
.url config -foreground red
/web_view [list $tclurl]
after 250 .url config -foreground blue
"
pack .btn -side bottom -anchor s -padx 10 -pady 10
pack .icon -side left -anchor w -padx 10 -pady 10
pack .text -side top -anchor w -expand 1 -fill x -padx 10 -pady 5
if {$tcl_platform(winsys) != "x11"} {
pack .url -side top -anchor nw -expand 1 -fill both -padx 10 -pady 0
}
wm title . "TCL Version Error"
bell
vwait tcl_version
exit
}
wm withdraw .
global treb_web_cache_dir
global treb_web_cache_map
if {$tcl_platform(platform) == "unix"} {
set treb_web_cache_dir [file join $treb_prefs_dir .trebtk-web-cache]
} else {
set treb_web_cache_dir [file join $treb_prefs_dir trebcache]
}
if {![file exists $treb_web_cache_dir]} {
file mkdir $treb_web_cache_dir
}
global treb_web_cache_index
set treb_web_cache_index [file join $treb_web_cache_dir index]
if {[file exists $treb_web_cache_index]} {
set f [open $treb_web_cache_index "r"]
set map_version [gets $f]
switch -exact $map_version {
"1" { array set treb_web_cache_map [read $f] }
}
close $f
}
switch -exact -- $tcl_platform(winsys) {
win32 {
set treb_colors(buttonface) systemButtonFace
set treb_colors(window) systemWindow
set treb_colors(windowtext) systemWindowText
if {[catch {event add <<ContextMenu>> <Button-3> <Key-App>}]} {
event add <<ContextMenu>> <Button-3>
}
bind Text <ButtonRelease-1> {+
if {[/prefs:get copy_on_select]} {
event generate %W <<Copy>>
}
}
bind Text <ButtonPress-2> {+
if {[/prefs:get button2_paste]} {
catch {event delete <<PasteSelection>>}
event generate %W <<PasteAt>> -x %x -y %y
break
}
}
event add <<Cut>> <Control-Key-x> <Shift-Key-Delete>
event add <<Copy>> <Control-Key-c> <Control-Key-Insert>
event add <<Paste>> <Control-Key-v> <Shift-Key-Insert>
event add <<SelectAll>> <Control-Shift-Key-A>
}
aqua {
set treb_colors(buttonface) systemButtonFace
set treb_colors(window) systemWindowBody
set treb_colors(windowtext) #000000
event add <<Cut>> <Command-Key-x>
event add <<Copy>> <Command-Key-c>
event add <<Paste>> <Command-Key-v>
event add <<SelectAll>> <Command-Key-a>
bind Text <Button-2> {}
bind Text <Control-Button-1> {}
event add <<ContextMenu>> <Control-Button-1> <Button-2>
if {![info exists env(TREB_MAC_THEME_FIX)]} {
tk_setPalette $treb_colors(window)
option add "*Text*background" "white" 60
option add "*Entry*background" "white" 60
option add "*Listbox*background" "white" 60
option add "*Listbox*selectBackground" "#cfcfff" 60
option add "*Checkbutton*highlightColor" "#cfcfff" 60
option add "*Text*relief" "sunken" widgetDefault
option add "*Entry*relief" "sunken" widgetDefault
option add "*Text*borderWidth" 2 widgetDefault
option add "*Text*highlightThickness" 1 widgetDefault
option add "*Entry*highlightThickness" 1 widgetDefault
option add "*Checkbutton*highlightThickness" 1 widgetDefault
}
catch {event delete <<PasteSelection>>}
# Workaround for a Tk8.4a4 bug on mac.
catch {namespace eval tk set Priv(repeated) 0}
}
default {
set treb_colors(buttonface) [. cget -bg]
option add *HighlightBackground [. cget -bg]
entry .flee
set treb_colors(window) [.flee cget -bg]
set treb_colors(windowtext) [.flee cget -fg]
destroy .flee
if {[catch {event add <<ContextMenu>> <Button-3> <Key-App>}]} {
event add <<ContextMenu>> <Button-3>
}
bind Text <ButtonRelease-1> {+
if {[/prefs:get copy_on_select]} {
event generate %W <<Copy>>
}
}
bind Text <ButtonPress-2> {+
if {[/prefs:get button2_paste]} {
catch {event delete <<PasteSelection>>}
event generate %W <<PasteAt>> -x %x -y %y
break
} else {
catch {event add <<PasteSelection>> <ButtonRelease-2>}
}
}
bind Text <Control-Key-v> {}
event add <<Cut>> <Control-Key-x>
event add <<Copy>> <Control-Key-c>
event add <<Paste>> <Control-Key-v>
event add <<SelectAll>> <Control-Shift-Key-A>
bind Text <Button-4> {%W yview scroll -4 units}
bind Text <Button-5> {%W yview scroll 4 units}
bind Listbox <Button-4> {%W yview scroll -4 units}
bind Listbox <Button-5> {%W yview scroll 4 units}
bind Canvas <Button-4> {%W yview scroll -4 units}
bind Canvas <Button-5> {%W yview scroll 4 units}
}
}
switch -glob -- $tcl_platform(os) {
Win* {
find_windows_prefsfile
if {[info exists env(TEMP)]} {
set treb_temp_dir $env(TEMP)
} else {
set treb_temp_dir $treb_root_dir
}
}
Darwin* -
Mac* {
set treb_save_file [file join $treb_prefs_dir "Trebuchet Data"]
set treb_temp_dir $treb_root_dir
}
default {
set treb_save_file [file join $treb_prefs_dir ".trebtkrc"]
set treb_temp_dir "/tmp"
}
}
catch {
bind Text <MouseWheel> {
if {%D > 0} {
%W yview scroll -4 units
} else {
%W yview scroll 4 units
}
}
bind Listbox <MouseWheel> {
if {%D > 0} {
%W yview scroll -4 units
} else {
%W yview scroll 4 units
}
}
bind Canvas <MouseWheel> {
if {%D > 0} {
%W yview scroll -4 units
} else {
%W yview scroll 4 units
}
}
}
bind Listbox <Key> {gdm:ListBox:Keypress %W %K %A ; break}
bind Listbox <Key-Shift_L> {continue}
bind Listbox <Key-Shift_R> {continue}
bind Listbox <Key-Control_L> {continue}
bind Listbox <Key-Control_R> {continue}
bind Listbox <Key-Alt_L> {continue}
bind Listbox <Key-Alt_R> {continue}
bind Listbox <Alt-Key> {continue}
bind Listbox <Key-Tab> {continue}
bind Listbox <Shift-Key-Tab> {continue}
bind Listbox <Control-Key-Tab> {continue}
bind Listbox <Control-Shift-Key-Tab> {continue}
bind Text <<Beep>> {/bell ; break}
event add <<Beep>> <Control-Key-g>
bind Text <<Cut>> {editCut %W ; break}
bind Text <<Copy>> {editCopy %W ; break}
bind Text <<Paste>> {editPaste %W ; break}
bind Text <<PasteAt>> {editPasteAt %W %x %y ; break}
bind Text <<SelectAll>> {editSelectAll %W ; break}
bind Entry <<Cut>> {editCut %W ; break}
bind Entry <<Copy>> {editCopy %W ; break}
bind Entry <<Paste>> {editPaste %W ; break}
bind Entry <<PasteAt>> {editPasteAt %W %x %y ; break}
bind Entry <<SelectAll>> {editSelectAll %W ; break}
set treb_lib_dir [file join $treb_root_dir lib]
set treb_docs_dir [file join $treb_root_dir docs]
set treb_tool_dir [file join $treb_root_dir pkgs]
set treb_cacerts_dir [file join $treb_root_dir cacerts]
image create photo ssl_icon_secure -file [file join $treb_lib_dir images locked.gif]
image create photo ssl_icon_insecure -file [file join $treb_lib_dir images unlocked.gif]
source [file join $treb_lib_dir bitmaps.tcl]
source [file join $treb_lib_dir errors.tcl]
source [file join $treb_lib_dir spinner.tcl]
source [file join $treb_lib_dir groupbox.tcl]
source [file join $treb_lib_dir combobox.tcl]
source [file join $treb_lib_dir notebook.tcl]
source [file join $treb_lib_dir tree.tcl]
source [file join $treb_lib_dir colorwheel.tcl]
source [file join $treb_lib_dir btnbar.tcl]
source [file join $treb_lib_dir compass.tcl]
source [file join $treb_lib_dir textpups.tcl]
source [file join $treb_lib_dir selector.tcl]
source [file join $treb_lib_dir editdlog.tcl]
source [file join $treb_lib_dir textmods.tcl]
source [file join $treb_lib_dir textdlog.tcl]
source [file join $treb_lib_dir finddlog.tcl]
source [file join $treb_lib_dir prefs.tcl]
source [file join $treb_lib_dir commands.tcl]
source [file join $treb_lib_dir telnet.tcl]
source [file join $treb_lib_dir secsupp.tcl]
source [file join $treb_lib_dir menus.tcl]
source [file join $treb_lib_dir mcpmgr.tcl]
source [file join $treb_lib_dir displays.tcl]
source [file join $treb_lib_dir worldbtn.tcl]
source [file join $treb_lib_dir spellchk.tcl]
source [file join $treb_lib_dir remote.tcl]
source [file join $treb_lib_dir socks.tcl]
if {![info exists treb_version_c] || $treb_version != $treb_version_c} {
source [file join $treb_lib_dir compat.tcl]
}
calculate_clicks_per_second
mcp_initialize /socket:sendln_raw
textmods:init
display:init
prefs:init
remote:init $argc $argv
}
if {[catch {init $argc $argv} mesg]} {
global errorInfo
set savedInfo $errorInfo
set top [toplevel .tle]
wm title $top "Trebuchet Error"
text $top.t -font {Courier 10} -yscrollcommand {$top.sb set}
scrollbar $top.sb -command {$top.t yview} -orient vert
button $top.b -text "Ok" -width 6 -command {exit} -default active
grid columnconfigure $top 0 -weight 1
grid rowconfigure $top 0 -weight 1
grid rowconfigure $top 1 -minsize 5
grid $top.t -sticky nsew
grid $top.sb -row 0 -column 1 -sticky ns
grid $top.b -row 2 -column 0
$top.t insert end $savedInfo
focus $top.b
tkwait window $top
exit
}
proc bgerror {mesg} {
global errorInfo
set savedInfo $errorInfo
if {[string match "SSL channel \"*\": *" $mesg]} {
return ""
}
/error [/socket:current] $mesg $savedInfo
/socket:setforeground
return ""
}
proc gdm:ListBox:Keypress {wname keycode key} {
global gdmListBox
set mylist [$wname get 0 end]
set lastpos [$wname index anchor]
if {$keycode == "Up"} {
set newpos $lastpos
incr newpos -1
if {$newpos < 0} {
set newpos 0
}
if {[info exists gdmListBox($wname,typedchars)]} {
unset gdmListBox($wname,typedchars)
}
if {[info exists gdmListBox($wname,keytimer)]} {
after cancel $gdmListBox($wname,keytimer)
unset gdmListBox($wname,keytimer)
}
} elseif {$keycode == "Down"} {
set newpos $lastpos
incr newpos
if {$newpos > [$wname index end]} {
set newpos [$wname index end]
}
if {[info exists gdmListBox($wname,typedchars)]} {
unset gdmListBox($wname,typedchars)
}
if {[info exists gdmListBox($wname,keytimer)]} {
after cancel $gdmListBox($wname,keytimer)
unset gdmListBox($wname,keytimer)
}
} else {
if {![regexp -nocase -- {[ -~]} $key]} {
if {[info exists gdmListBox($wname,typedchars)]} {
unset gdmListBox($wname,typedchars)
}
if {[info exists gdmListBox($wname,keytimer)]} {
after cancel $gdmListBox($wname,keytimer)
unset gdmListBox($wname,keytimer)
}
return
}
if {[info exists gdmListBox($wname,keytimer)]} {
after cancel $gdmListBox($wname,keytimer)
}
set gdmListBox($wname,keytimer) [
after 750 "
if {\[info exists gdmListBox($wname,typedchars)\]} {
unset gdmListBox($wname,typedchars)
}
"
]
set chars {}
if {[info exists gdmListBox($wname,typedchars)]} {
set chars $gdmListBox($wname,typedchars)
}
if {$lastpos == {}} {
set lastpos 0
}
append chars $key
set chars [string tolower $chars]
set llen [llength $mylist]
set slen [string length $chars]
incr slen -1
for {set newpos 0} {$newpos < $llen} {incr newpos} {
set item [lindex $mylist $newpos]
set posstr [string tolower [string range $item 0 $slen]]
set test [string compare $posstr $chars]
if {$test == 0} {
break
}
}
if {$newpos >= $llen} {
set newpos $lastpos
}
set gdmListBox($wname,typedchars) $chars
}
if {$newpos != $lastpos} {
$wname selection clear 0 end
$wname selection set $newpos
$wname activate $newpos
$wname see $newpos
}
}
proc getColorVals {color} {
return [winfo rgb . $color]
}
proc setvars {variables values} {
foreach var $variables val $values {
if {$var == ""} {
break
}
upvar $var tmp
set tmp $val
}
return $values
}
proc dispatcher {root opt argset} {
if {[info procs $root:$opt] != {}} {
set cmd "$root:$opt"
foreach arg $argset {
append cmd " [list $arg]"
}
return [eval "$cmd"]
} else {
set opts ""
set rootlen [string length $root]
incr rootlen
foreach item [lsort -dictionary [info procs $root:*]] {
if {$opts != ""} {
append opts ", "
}
append opts [string range $item $rootlen end]
}
error "$root: Unknown option \"$opt\" should be one of $opts"
}
}
proc lrotate {list first last count} {
if {$first == "end"} {set first [expr {[llength $list] - 1}]}
if {$last == "end"} {set last [expr {[llength $list] - 1}]}
if {$first > $last} {
set tmp $first
set first $last
set last $tmp
set count [expr {-1 * $count}]
}
if {(abs($last - $first) + 1) > $count} {
set count [expr {$count % (abs($last - $first) + 1)}]
}
if {$count > 0} {
set endfirst [expr {$last - $count}]
set startlast [expr {$last - ($count - 1)}]
} elseif {$count < 0} {
set endfirst [expr {$first - ($count + 1)}]
set startlast [expr {$first - $count}]
} else {
return $list
}
set tmprng [lrange $list $startlast $last]
set tmplist [lreplace $list $startlast $last]
foreach item $tmprng {
set tmplist [linsert $tmplist $first $item]
incr first
}
return $tmplist
}
proc lrottostart {list pos} {
set item [lindex $list $pos]
return [linsert [lreplace $list $pos $pos] 0 $item]
}
proc chooseColor {args} {
set results [eval tk_chooseColor $args]
if {[string match "after#*" $results]} {
regexp {after#[0-9]+([^0-9].*$)} "$results" {} results
}
return $results
}
proc editSelectAll {w} {
if {[winfo class $w] == "Text"} {
catch {$w tag add sel 1.0 end}
} elseif {[winfo class $w] == "Entry"} {
catch {$w selection range 0 end}
}
}
proc editCopy {w} {
if {[winfo class $w] == "Text"} {
if {[$w tag ranges sel] != "[$w index end-1c] [$w index end]"} {
if {![catch {set data [$w get sel.first sel.last]}]} {
if {$data != {}} {
clipboard clear -displayof $w
clipboard append -displayof $w -- $data
}
}
}
} elseif {[winfo class $w] == "Entry"} {
if {![catch {set data [selection get -displayof $w -selection PRIMARY]}]} {
if {$data != {}} {
clipboard clear -displayof $w
clipboard append -displayof $w -- $data
}
}
}
}
proc editCut {w} {
if {[winfo class $w] == "Text" || $w == [/display]} {
if {[$w tag ranges sel] != "[$w index end-1c] [$w index end]"} {
if {![catch {set data [$w get sel.first sel.last]}]} {
if {$data != {}} {
clipboard clear -displayof $w
clipboard append -displayof $w -- $data
$w delete sel.first sel.last
}
}
}
} elseif {[winfo class $w] == "Entry"} {
if {![catch {set data [selection get -displayof $w -selection PRIMARY]}]} {
if {$data != {}} {
clipboard clear -displayof $w
clipboard append -displayof $w -- $data
$w delete sel.first sel.last
}
}
}
}
proc editPaste {w} {
if {$w == [/display]} {
set w [/inbuf]
#/statbar 5 "You can't paste into the output display."
#/bell
#return
}
catch {
catch {
$w delete sel.first sel.last
}
set data [selection get -displayof $w -selection CLIPBOARD]
$w insert insert $data
}
}
proc editPasteAt {w x y} {
if {$w == [/display]} {
/statbar 5 "You can't paste into the output display."
/bell
return
}
catch {
if {[winfo class $w] == "Text"} {
catch { $w tag remove sel.first sel.last }
} elseif {[winfo class $w] == "Entry"} {
catch { $w selection clear }
}
$w insert @$x,$y [selection get -displayof $w -selection CLIPBOARD]
if {[winfo class $w] == "Text"} {
$w mark set insert @%x,%y
} elseif {[winfo class $w] == "Entry"} {
$w icursor @%x,%y
}
}
}
proc match_text_word {wname pos {end {}}} {
global nonwordchar
set first [$wname search -backwards -regexp -nocase -- "$nonwordchar|^" "$pos + 1 chars"]
if {[$wname compare $first != "$first linestart"]} {
set first "$first + 1 chars"
}
if {$end != {}} {
set last $end
} else {
set last [$wname search -forwards -regexp -nocase -- "$nonwordchar|$" $pos]
}
return [$wname get $first "$last"]
}
proc complete_word {wname word} {
global nonwordchar wordchar
regsub -all {[]\$.*()|?+^; []} $word {\\&} word
set limindex "end - [/prefs:get completion_lines] lines"
set lastindex "end"
# FIXME: we need $oldindex else, sometimes, the routine would enter an
# infinite loop... This behaviour was encountered on a Talker, with
# completion on ANSIfied text.
set oldindex ""
set shortword ""
set shortlen 0
set wordslist {}
set wordlen [string length $word]
while {$lastindex != "" && $lastindex != $oldindex} {
set oldindex $lastindex
set lastindex [$wname search -backwards -regexp -nocase -- \
"$nonwordchar$word|^$word" $lastindex $limindex]
if {$lastindex != "" && $lastindex != $oldindex} {
if {[$wname compare $lastindex != "$lastindex linestart"]} {
set wordstart "$lastindex + 1 chars"
} else {
set wordstart "$lastindex"
}
set foundword [match_text_word $wname "$wordstart"]
if {$shortword == ""} {
set shortword $foundword
set shortlen [string length $shortword]
lappend wordslist [string tolower "$foundword"]
} else {
if {[lsearch -exact "$wordslist" [string tolower "$foundword"]] == -1} {
lappend wordslist [string tolower "$foundword"]
}
set tmpword [string range $foundword 0 [expr {$shortlen - 1}]]
while {[string tolower $shortword] != [string tolower $tmpword]} {