Merge branch 'master' of git://repo.or.cz/alt-git
[git/mingw.git] / git-gui / lib / line.tcl
bloba026de954c3d9cbfd03d4dec9a73a74647bf74ba
1 # goto line number
2 # based on code from gitk, Copyright (C) Paul Mackerras
4 class linebar {
6 field w
7 field ctext
9 field linenum {}
11 constructor new {i_w i_text args} {
12 global use_ttk NS
13 set w $i_w
14 set ctext $i_text
16 ${NS}::frame $w
17 ${NS}::label $w.l -text [mc "Goto Line:"]
18 tentry $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 _goto]
25 pack $w.l -side left
26 pack $w.bn -side right
27 pack $w.ent -side left -expand 1 -fill x
29 eval grid conf $w -sticky we $args
30 grid remove $w
32 trace add variable linenum write [cb _goto_cb]
33 bind $w.ent <Return> [cb _goto]
34 bind $w.ent <Escape> [cb hide]
36 bind $w <Destroy> [list delete_this $this]
37 return $this
40 method show {} {
41 if {![visible $this]} {
42 grid $w
44 focus -force $w.ent
47 method hide {} {
48 if {[visible $this]} {
49 $w.ent delete 0 end
50 focus $ctext
51 grid remove $w
55 method visible {} {
56 return [winfo ismapped $w]
59 method editor {} {
60 return $w.ent
63 method _validate {P} {
64 # only accept numbers as input
65 string is integer $P
68 method _goto_cb {name ix op} {
69 after idle [cb _goto 1]
72 method _goto {{nohide {0}}} {
73 if {$linenum ne {}} {
74 $ctext see $linenum.0
75 if {!$nohide} {
76 hide $this