提交 1159971b 编写于 作者: B Bert Wesarg 提交者: Pat Thoyts

git-gui: add search history to searchbar

Use the up/down keys to browse the history.
Signed-off-by: NBert Wesarg <bert.wesarg@googlemail.com>
Signed-off-by: NPat Thoyts <patthoyts@users.sourceforge.net>
上级 e9144d55
...@@ -13,6 +13,9 @@ field casesensitive ...@@ -13,6 +13,9 @@ field casesensitive
field default_casesensitive field default_casesensitive
field searchdirn -forwards field searchdirn -forwards
field history
field history_index
field smarktop field smarktop
field smarkbot field smarkbot
...@@ -28,6 +31,8 @@ constructor new {i_w i_text args} { ...@@ -28,6 +31,8 @@ constructor new {i_w i_text args} {
set default_casesensitive 1 set default_casesensitive 1
} }
set history [list]
${NS}::frame $w ${NS}::frame $w
${NS}::label $w.l -text [mc Find:] ${NS}::label $w.l -text [mc Find:]
entry $w.ent -textvariable ${__this}::searchstring -background lightgreen entry $w.ent -textvariable ${__this}::searchstring -background lightgreen
...@@ -50,6 +55,8 @@ constructor new {i_w i_text args} { ...@@ -50,6 +55,8 @@ constructor new {i_w i_text args} {
trace add variable searchstring write [cb _incrsearch_cb] trace add variable searchstring write [cb _incrsearch_cb]
bind $w.ent <Return> [cb find_next] bind $w.ent <Return> [cb find_next]
bind $w.ent <Shift-Return> [cb find_prev] bind $w.ent <Shift-Return> [cb find_prev]
bind $w.ent <Key-Up> [cb _prev_search]
bind $w.ent <Key-Down> [cb _next_search]
bind $w <Destroy> [list delete_this $this] bind $w <Destroy> [list delete_this $this]
return $this return $this
...@@ -58,8 +65,10 @@ constructor new {i_w i_text args} { ...@@ -58,8 +65,10 @@ constructor new {i_w i_text args} {
method show {} { method show {} {
if {![visible $this]} { if {![visible $this]} {
grid $w grid $w
$w.ent delete 0 end
set regexpsearch $default_regexpsearch set regexpsearch $default_regexpsearch
set casesensitive $default_casesensitive set casesensitive $default_casesensitive
set history_index [llength $history]
} }
focus -force $w.ent focus -force $w.ent
} }
...@@ -68,6 +77,7 @@ method hide {} { ...@@ -68,6 +77,7 @@ method hide {} {
if {[visible $this]} { if {[visible $this]} {
focus $ctext focus $ctext
grid remove $w grid remove $w
_save_search $this
} }
} }
...@@ -160,6 +170,55 @@ method _incrsearch {} { ...@@ -160,6 +170,55 @@ method _incrsearch {} {
} }
} }
method _save_search {} {
if {$searchstring eq {}} {
return
}
if {[llength $history] > 0} {
foreach {s_regexp s_case s_expr} [lindex $history end] break
} else {
set s_regexp $regexpsearch
set s_case $casesensitive
set s_expr ""
}
if {$searchstring eq $s_expr} {
# update modes
set history [lreplace $history end end \
[list $regexpsearch $casesensitive $searchstring]]
} else {
lappend history [list $regexpsearch $casesensitive $searchstring]
}
set history_index [llength $history]
}
method _prev_search {} {
if {$history_index > 0} {
incr history_index -1
foreach {s_regexp s_case s_expr} [lindex $history $history_index] break
$w.ent delete 0 end
$w.ent insert 0 $s_expr
set regexpsearch $s_regexp
set casesensitive $s_case
}
}
method _next_search {} {
if {$history_index < [llength $history]} {
incr history_index
}
if {$history_index < [llength $history]} {
foreach {s_regexp s_case s_expr} [lindex $history $history_index] break
} else {
set s_regexp $default_regexpsearch
set s_case $default_casesensitive
set s_expr ""
}
$w.ent delete 0 end
$w.ent insert 0 $s_expr
set regexpsearch $s_regexp
set casesensitive $s_case
}
method find_prev {} { method find_prev {} {
find_next $this -backwards find_next $this -backwards
} }
...@@ -170,6 +229,7 @@ method find_next {{dir -forwards}} { ...@@ -170,6 +229,7 @@ method find_next {{dir -forwards}} {
set searchdirn $dir set searchdirn $dir
$ctext mark unset anchor $ctext mark unset anchor
if {$searchstring ne {}} { if {$searchstring ne {}} {
_save_search $this
set start [_get_new_anchor $this] set start [_get_new_anchor $this]
if {$dir eq "-forwards"} { if {$dir eq "-forwards"} {
set start "$start + 1c" set start "$start + 1c"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册