]> rtime.felk.cvut.cz Git - sojka/git-gui.git/blob - lib/line.tcl
git-gui: Enable jumping to a specific line number in blame view.
[sojka/git-gui.git] / lib / line.tcl
1 # goto line number
2 # based on code from gitk, Copyright (C) Paul Mackerras
3
4 class linebar {
5
6 field w
7 field ctext
8
9 field linenum   {}
10
11 constructor 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 -textvariable ${__this}::linenum -background lightgreen
19         ${NS}::button $w.bn      -text [mc Go] -command [cb _incrgoto]
20
21         pack   $w.l   -side left
22         pack   $w.bn  -side right
23         pack   $w.ent -side left -expand 1 -fill x
24
25         eval grid conf $w -sticky we $args
26         grid remove $w
27
28         bind $w.ent <Return> [cb _incrgoto]
29         bind $w.ent <Escape> [list linebar::hide $this]
30
31         bind $w <Destroy> [list delete_this $this]
32         return $this
33 }
34
35 method show {} {
36         if {![visible $this]} {
37                 grid $w
38         }
39         focus -force $w.ent
40 }
41
42 method hide {} {
43         if {[visible $this]} {
44                 focus $ctext
45                 grid remove $w
46         }
47 }
48
49 method visible {} {
50         return [winfo ismapped $w]
51 }
52
53 method editor {} {
54         return $w.ent
55 }
56
57 method _incrgoto {} {
58         if {$linenum ne {}} {
59                 $ctext see $linenum.0
60                 hide $this
61         }
62 }
63
64 }