# TH bindings (created by makebeth) for Listbox widgets

set TH(Pipe,Enabled) 1
set TH(File,Pad) 0
set TH(Binding,Search_Forward) <Control-s>
set TH(Menuentry,Search_Forward) {Forward 0}
set TH(Binding,Search_Backward) <Control-r>
set TH(Menuentry,Search_Backward) {Reverse 0}
set TH(Binding,Toggle_Case_Sensitivity) <Meta-Control-c>
set TH(Menuentry,Toggle_Case_Sensitivity) {"Case Inensitive" 0}
set TH(Binding,Toggle_Incremental_Search) <Meta-C>
set TH(Menuentry,Toggle_Incremental_Search) {"Incremental Search" 0}
set TH(Search,Select,Listbox) sel
set TH(Search,Case,Implicit) 1
set TH(Binding,Highlight_Searches) <Meta-Control-l>
set TH(Menuentry,Highlight_Searches) {Highlight 4}
bind Listbox <Button-3> {th_toggle_menus %W}
bind Listbox <Control-a> {th_scroll %W xview moveto 0}
bind Listbox <Control-e> {th_scroll %W xview moveto 1}
bind Listbox <Meta-less> {th_Listbox_goto %W 0}
bind Listbox <Meta-greater> {th_Listbox_goto %W end}
bind Listbox <Control-l> {%W xview moveto 0 ; th_scroll %W yview [expr [%W index active] - ([%W index "@0,[winfo height %W]"] - [%W index "@0,0"]) / 2]}
bind Listbox <Control-p> {th_Listbox_goto %W [expr [%W index active] - 1]}
bind Listbox <Control-n> {th_Listbox_goto %W [expr [%W index active] + 1]}
bind Listbox <Control-L> {%W activate "@0,[expr [winfo height %W] / 2]"}
bind Listbox <Control-K> {if {[selection own -displayof %W] == "%W"} {
	tkListboxBeginSelect %W active} else {tkListboxBeginExtend %W active}
	th_Listbox_goto %W [expr [%W index active] + 1]}
bind Listbox <Control-Shift-space> {th_Listbox_select_region %W}
bind Listbox <Control-slash> {tkListboxSelectAll %W}
bind Listbox <Control-space> {%W selection anchor active}
bind Listbox <Control-x> {th_[winfo class %W]_exchange_mark %W}
bind Listbox <Meta-g> {th_goto %W}
bind Listbox <Control-backslash> {selection clear -displayof %W}
bind Listbox <Meta-w> {if {[selection own -displayof %W] == "%W"} {
	    clipboard clear -displayof %W
	    clipboard append -displayof %W -- [selection get -displayof %W]}}
bind Listbox <Meta-Z> {th_scroll %W xview scroll -1 units}
bind Listbox <Control-Z> {th_scroll %W xview scroll  1 units}
bind Listbox <Meta-asciitilde> {th_scroll %W xview scroll -1 pages}
bind Listbox <Control-asciitilde> {th_scroll %W xview scroll  1 pages}
bind Listbox <Meta-z> {th_scroll %W yview scroll -1 units}
bind Listbox <Control-z> {th_scroll %W yview scroll  1 units}
bind Listbox <Meta-quoteleft> {th_scroll %W yview scroll -1 pages}
bind Listbox <Control-quoteleft> {th_scroll %W yview scroll  1 pages}
bind Listbox <Control-g> {th_cancel_all %W}
bind Listbox <Meta-s> {th_save_file %W}
bind Listbox <Meta-S> {th_save_file_prompt %W}
bind Listbox <Enter> {th_check_mtime %W}
bind Listbox <Meta-x> {th_[winfo class %W]_toggle_grid_x %W bottom}
bind Listbox <Meta-y> {th_[winfo class %W]_toggle_grid_y %W left}
bind Listbox <Control-s> {th_Misc_search %W forward string}
bind Listbox <Control-r> {th_Misc_search %W backward string}
bind Listbox <Control-S> {th_Misc_search %W forward regexp}
bind Listbox <Control-R> {th_Misc_search %W backward regexp}
bind Listbox <Meta-C> {th_toggle_incremental_search %W}
bind Listbox <Meta-X> {th_toggle_scrollbar %W x bottom}
bind Listbox <Meta-Y> {th_toggle_scrollbar %W y left}



proc th_Listbox_menus {w} {
  th_Misc_menus $w
set code {

menubutton %W_mb.mb_browse -m %W_mb.mb_browse.m -text Browse -u 0
pack %W_mb.mb_browse -in %W_mb -side left
menu %W_mb.mb_browse.m
%W_mb.mb_browse.m add cascade -l Goto -u 0 -m %W_mb.mb_browse.m.goto
menu %W_mb.mb_browse.m.goto
%W_mb.mb_browse.m.goto add cascade -l Edge -u 0 -m %W_mb.mb_browse.m.goto.edge
menu %W_mb.mb_browse.m.goto.edge
%W_mb.mb_browse.m.goto.edge add command -l {Left} -u 0 -acc {<Control-a>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_scroll %W xview moveto 0}}
%W_mb.mb_browse.m.goto.edge add command -l {Right} -u 0 -acc {<Control-e>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_scroll %W xview moveto 1}}
%W_mb.mb_browse.m.goto.edge add command -l {Up} -u 0 -acc {<Meta-less>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_Listbox_goto %W 0}}
%W_mb.mb_browse.m.goto.edge add command -l {Down} -u 0 -acc {<Meta-greater>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_Listbox_goto %W end}}
%W_mb.mb_browse.m add cascade -l Scroll -u 0 -m %W_mb.mb_browse.m.scroll
menu %W_mb.mb_browse.m.scroll
%W_mb.mb_browse.m.scroll add command -l {Center Cursor} -u 0 -acc {<Control-l>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  %W xview moveto 0 ; th_scroll %W yview [expr [%W index active] - ([%W index "@0,[winfo height %W]"] - [%W index "@0,0"]) / 2]}}
%W_mb.mb_browse.m.goto add cascade -l Character -u 0 -m %W_mb.mb_browse.m.goto.character
menu %W_mb.mb_browse.m.goto.character
%W_mb.mb_browse.m.goto.character add command -l {Previous} -u 0 -acc {<Control-p>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_Listbox_goto %W [expr [%W index active] - 1]}}
%W_mb.mb_browse.m.goto.character add command -l {Next} -u 0 -acc {<Control-n>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_Listbox_goto %W [expr [%W index active] + 1]}}
%W_mb.mb_browse.m.goto add command -l {Center of Screen} -u 5 -acc {<Control-L>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  %W activate "@0,[expr [winfo height %W] / 2]"}}
%W_mb.mb_browse.m add cascade -l Select -u 1 -m %W_mb.mb_browse.m.select
menu %W_mb.mb_browse.m.select
%W_mb.mb_browse.m.select add command -l {Line} -u 0 -acc {<Control-K>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  if {[selection own -displayof %W] == "%W"} {
	tkListboxBeginSelect %W active} else {tkListboxBeginExtend %W active}
	th_Listbox_goto %W [expr [%W index active] + 1]}}
%W_mb.mb_browse.m.select add command -l {Region} -u 0 -acc {<Control-Shift-space>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_Listbox_select_region %W}}
%W_mb.mb_browse.m.select add command -l {All} -u 0 -acc {<Control-slash>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  tkListboxSelectAll %W}}
%W_mb.mb_browse.m add command -l {Anchor} -u 0 -acc {<Control-space>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  %W selection anchor active}}
%W_mb.mb_browse.m.goto add command -l {Anchor} -u 0 -acc {<Control-x>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_[winfo class %W]_exchange_mark %W}}
%W_mb.mb_browse.m.goto add command -l {Specify an Index} -u 11 -acc {<Meta-g>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_goto %W}}
%W_mb.mb_browse.m.select add command -l {Clear} -u 0 -acc {<Control-backslash>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  selection clear -displayof %W}}
%W_mb.mb_browse.m.select add command -l {Copy} -u 1 -acc {<Meta-w>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  if {[selection own -displayof %W] == "%W"} {
	    clipboard clear -displayof %W
	    clipboard append -displayof %W -- [selection get -displayof %W]}}}
%W_mb.mb_browse.m.scroll add cascade -l Line -u 0 -m %W_mb.mb_browse.m.scroll.line
menu %W_mb.mb_browse.m.scroll.line
%W_mb.mb_browse.m.scroll.line add command -l {Left} -u 0 -acc {<Meta-Z>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_scroll %W xview scroll -1 units}}
%W_mb.mb_browse.m.scroll.line add command -l {Right} -u 0 -acc {<Control-Z>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_scroll %W xview scroll  1 units}}
%W_mb.mb_browse.m.scroll add cascade -l Page -u 0 -m %W_mb.mb_browse.m.scroll.page
menu %W_mb.mb_browse.m.scroll.page
%W_mb.mb_browse.m.scroll.page add command -l {Left} -u 0 -acc {<Meta-asciitilde>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_scroll %W xview scroll -1 pages}}
%W_mb.mb_browse.m.scroll.page add command -l {Right} -u 0 -acc {<Control-asciitilde>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_scroll %W xview scroll  1 pages}}
%W_mb.mb_browse.m.scroll.line add command -l {Up} -u 0 -acc {<Meta-z>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_scroll %W yview scroll -1 units}}
%W_mb.mb_browse.m.scroll.line add command -l {Down} -u 0 -acc {<Control-z>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_scroll %W yview scroll  1 units}}
%W_mb.mb_browse.m.scroll.page add command -l {Up} -u 0 -acc {<Meta-quoteleft>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_scroll %W yview scroll -1 pages}}
%W_mb.mb_browse.m.scroll.page add command -l {Down} -u 0 -acc {<Control-quoteleft>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_scroll %W yview scroll  1 pages}}

menubutton %W_mb.mb_file -m %W_mb.mb_file.m -text File -u 0
pack %W_mb.mb_file -in %W_mb -side left
menu %W_mb.mb_file.m
%W_mb.mb_file.m add command -l {Save} -u 0 -acc {<Meta-s>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_save_file %W}}
%W_mb.mb_file.m add command -l {Save As} -u 5 -acc {<Meta-S>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_save_file_prompt %W}}
%W_mb.mb_file.m add checkbutton -variable TH(Pipe)\
  -onvalue 1 -offvalue 0 -l {Use a Pipe} -u 6 -acc {} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_checkbutton_variable Pipe}}
%W_mb.mb_window.m add checkbutton -variable TH(Grid_X,%W)\
  -onvalue 1 -offvalue 0 -l {Horizontal Grid} -u 0 -acc {<Meta-x>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_[winfo class %W]_toggle_grid_x %W bottom}}
%W_mb.mb_window.m add checkbutton -variable TH(Grid_Y,%W)\
  -onvalue 1 -offvalue 0 -l {Vertical Grid} -u 0 -acc {<Meta-y>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_[winfo class %W]_toggle_grid_y %W left}}

menubutton %W_mb.mb_search -m %W_mb.mb_search.m -text Search -u 0
pack %W_mb.mb_search -in %W_mb -side left
menu %W_mb.mb_search.m
%W_mb.mb_search.m add cascade -l String -u 0 -m %W_mb.mb_search.m.string
menu %W_mb.mb_search.m.string
%W_mb.mb_search.m.string add command -l {Forward} -u 0 -acc {<Control-s>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_Misc_search %W forward string}}
%W_mb.mb_search.m.string add command -l {Reverse} -u 0 -acc {<Control-r>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_Misc_search %W backward string}}
%W_mb.mb_search.m add cascade -l Regexp -u 0 -m %W_mb.mb_search.m.regexp
menu %W_mb.mb_search.m.regexp
%W_mb.mb_search.m.regexp add command -l {Forward} -u 0 -acc {<Control-S>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_Misc_search %W forward regexp}}
%W_mb.mb_search.m.regexp add command -l {Reverse} -u 0 -acc {<Control-R>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_Misc_search %W backward regexp}}
%W_mb.mb_search.m add checkbutton -variable TH(Search,Incremental,%W)\
  -onvalue 1 -offvalue 0 -l {Incremental Search} -u 0 -acc {<Meta-C>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_toggle_incremental_search %W}}
%W_mb.mb_window.m add checkbutton -variable TH(Scrollbar,X,%W)\
  -onvalue 1 -offvalue 0 -l {X Scrollbar} -u 0 -acc {<Meta-X>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_toggle_scrollbar %W x bottom}}
%W_mb.mb_window.m add checkbutton -variable TH(Scrollbar,Y,%W)\
  -onvalue 1 -offvalue 0 -l {Y Scrollbar} -u 0 -acc {<Meta-Y>} -co {if {![winfo exists %W]} {destroy %W_mb} else {
  th_toggle_scrollbar %W y left}}


}

global TH
regsub -all "%W_mb" $code $TH(Menubar,$w) new_code
regsub -all %W $new_code $w code
eval $code
}


