interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / git-gui / lib / line.tcl

80 lines · 1322 bytes Raw Blame History
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 set w $i_w
13 set ctext $i_text
14
15 ttk::frame $w
16 ttk::label $w.l -text [mc "Goto Line:"]
17 tentry $w.ent \
18 -textvariable ${__this}::linenum \
19 -background lightgreen \
20 -validate key \
21 -validatecommand [cb _validate %P]
22 ttk::button $w.bn -text [mc Go] -command [cb _goto]
23
24 pack $w.l -side left
25 pack $w.bn -side right
26 pack $w.ent -side left -expand 1 -fill x
27
28 eval grid conf $w -sticky we $args
29 grid remove $w
30
31 trace add variable linenum write [cb _goto_cb]
32 bind $w.ent <Return> [cb _goto]
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 $w.ent delete 0 end
49 focus $ctext
50 grid remove $w
51 }
52}
53
54method visible {} {
55 return [winfo ismapped $w]
56}
57
58method editor {} {
59 return $w.ent
60}
61
62method _validate {P} {
63 # only accept numbers as input
64 string is integer $P
65}
66
67method _goto_cb {name ix op} {
68 after idle [cb _goto 1]
69}
70
71method _goto {{nohide {0}}} {
72 if {$linenum ne {}} {
73 $ctext see $linenum.0
74 if {!$nohide} {
75 hide $this
76 }
77 }
78}
79
80}