git-gui: allow Ctrl+T to toggle multiple paths
[git/git.git] / lib / line.tcl
CommitLineData
9a483e5c
DF
1# goto line number
2# based on code from gitk, Copyright (C) Paul Mackerras
3
4class linebar {
5
6field w
7field ctext
8
9field linenum {}
10
11constructor new {i_w i_text args} {
12 global use_ttk NS
13 set w $i_w
14 set ctext $i_text
15
16 ${NS}::frame $w
17 ${NS}::label $w.l -text [mc "Goto Line:"]
35927672 18 tentry $w.ent \
59252107
BW
19 -textvariable ${__this}::linenum \
20 -background lightgreen \
21 -validate key \
22 -validatecommand [cb _validate %P]
843d6597 23 ${NS}::button $w.bn -text [mc Go] -command [cb _goto]
9a483e5c
DF
24
25 pack $w.l -side left
26 pack $w.bn -side right
27 pack $w.ent -side left -expand 1 -fill x
28
29 eval grid conf $w -sticky we $args
30 grid remove $w
31
843d6597
BW
32 trace add variable linenum write [cb _goto_cb]
33 bind $w.ent <Return> [cb _goto]
59252107 34 bind $w.ent <Escape> [cb hide]
9a483e5c
DF
35
36 bind $w <Destroy> [list delete_this $this]
37 return $this
38}
39
40method show {} {
41 if {![visible $this]} {
42 grid $w
43 }
44 focus -force $w.ent
45}
46
47method hide {} {
48 if {[visible $this]} {
81a92e52 49 $w.ent delete 0 end
9a483e5c
DF
50 focus $ctext
51 grid remove $w
52 }
53}
54
55method visible {} {
56 return [winfo ismapped $w]
57}
58
59method editor {} {
60 return $w.ent
61}
62
59252107
BW
63method _validate {P} {
64 # only accept numbers as input
65 string is integer $P
66}
67
843d6597
BW
68method _goto_cb {name ix op} {
69 after idle [cb _goto 1]
70}
71
72method _goto {{nohide {0}}} {
9a483e5c
DF
73 if {$linenum ne {}} {
74 $ctext see $linenum.0
843d6597
BW
75 if {!$nohide} {
76 hide $this
77 }
9a483e5c
DF
78 }
79}
80
81}