You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
1.3 KiB
82 lines
1.3 KiB
14 years ago
|
# goto line number
|
||
|
# based on code from gitk, Copyright (C) Paul Mackerras
|
||
|
|
||
|
class linebar {
|
||
|
|
||
|
field w
|
||
|
field ctext
|
||
|
|
||
|
field linenum {}
|
||
|
|
||
|
constructor new {i_w i_text args} {
|
||
|
global use_ttk NS
|
||
|
set w $i_w
|
||
|
set ctext $i_text
|
||
|
|
||
|
${NS}::frame $w
|
||
|
${NS}::label $w.l -text [mc "Goto Line:"]
|
||
13 years ago
|
tentry $w.ent \
|
||
13 years ago
|
-textvariable ${__this}::linenum \
|
||
|
-background lightgreen \
|
||
|
-validate key \
|
||
|
-validatecommand [cb _validate %P]
|
||
13 years ago
|
${NS}::button $w.bn -text [mc Go] -command [cb _goto]
|
||
14 years ago
|
|
||
|
pack $w.l -side left
|
||
|
pack $w.bn -side right
|
||
|
pack $w.ent -side left -expand 1 -fill x
|
||
|
|
||
|
eval grid conf $w -sticky we $args
|
||
|
grid remove $w
|
||
|
|
||
13 years ago
|
trace add variable linenum write [cb _goto_cb]
|
||
|
bind $w.ent <Return> [cb _goto]
|
||
13 years ago
|
bind $w.ent <Escape> [cb hide]
|
||
14 years ago
|
|
||
|
bind $w <Destroy> [list delete_this $this]
|
||
|
return $this
|
||
|
}
|
||
|
|
||
|
method show {} {
|
||
|
if {![visible $this]} {
|
||
|
grid $w
|
||
|
}
|
||
|
focus -force $w.ent
|
||
|
}
|
||
|
|
||
|
method hide {} {
|
||
|
if {[visible $this]} {
|
||
13 years ago
|
$w.ent delete 0 end
|
||
14 years ago
|
focus $ctext
|
||
|
grid remove $w
|
||
|
}
|
||
|
}
|
||
|
|
||
|
method visible {} {
|
||
|
return [winfo ismapped $w]
|
||
|
}
|
||
|
|
||
|
method editor {} {
|
||
|
return $w.ent
|
||
|
}
|
||
|
|
||
13 years ago
|
method _validate {P} {
|
||
|
# only accept numbers as input
|
||
|
string is integer $P
|
||
|
}
|
||
|
|
||
13 years ago
|
method _goto_cb {name ix op} {
|
||
|
after idle [cb _goto 1]
|
||
|
}
|
||
|
|
||
|
method _goto {{nohide {0}}} {
|
||
14 years ago
|
if {$linenum ne {}} {
|
||
|
$ctext see $linenum.0
|
||
13 years ago
|
if {!$nohide} {
|
||
|
hide $this
|
||
|
}
|
||
14 years ago
|
}
|
||
|
}
|
||
|
|
||
|
}
|