904722e6772ee20ef28619db3bd6fd56aff6f89f
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:"]
18 entry $w.ent \
19 -textvariable ${__this}::linenum \
20 -background lightgreen \
21 -validate key \
22 -validatecommand [cb _validate %P]
23 ${NS}::button $w.bn -text [mc Go] -command [cb _incrgoto]
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
32 bind $w.ent <Return> [cb _incrgoto]
33 bind $w.ent <Escape> [cb hide]
34
35 bind $w <Destroy> [list delete_this $this]
36 return $this
37}
38
39method show {} {
40 if {![visible $this]} {
41 grid $w
42 }
43 focus -force $w.ent
44}
45
46method hide {} {
47 if {[visible $this]} {
48 focus $ctext
49 grid remove $w
50 }
51}
52
53method visible {} {
54 return [winfo ismapped $w]
55}
56
57method editor {} {
58 return $w.ent
59}
60
61method _validate {P} {
62 # only accept numbers as input
63 string is integer $P
64}
65
66method _incrgoto {} {
67 if {$linenum ne {}} {
68 $ctext see $linenum.0
69 hide $this
70 }
71}
72
73}