git-gui: add regexp search mode to the searchbar
[gitweb.git] / lib / search.tcl
index 32c8656fc9b15498073a09e516777f71827dc3b1..9268ec325bb4dd639f7dcc7f0e68c7301b7786a8 100644 (file)
@@ -7,25 +7,39 @@ field w
 field ctext
 
 field searchstring   {}
-field casesensitive  1
+field regexpsearch
+field default_regexpsearch
+field casesensitive
+field default_casesensitive
 field searchdirn     -forwards
 
 field smarktop
 field smarkbot
 
 constructor new {i_w i_text args} {
+       global use_ttk NS
        set w      $i_w
        set ctext  $i_text
 
-       frame  $w
-       label  $w.l       -text [mc Find:]
+       set default_regexpsearch [is_config_true gui.search.regexp]
+       if {[is_config_true gui.search.smartcase]} {
+               set default_casesensitive 0
+       } else {
+               set default_casesensitive 1
+       }
+
+       ${NS}::frame  $w
+       ${NS}::label  $w.l       -text [mc Find:]
        entry  $w.ent -textvariable ${__this}::searchstring -background lightgreen
-       button $w.bn      -text [mc Next] -command [cb find_next]
-       button $w.bp      -text [mc Prev] -command [cb find_prev]
-       checkbutton $w.cs -text [mc Case-Sensitive] \
+       ${NS}::button $w.bn      -text [mc Next] -command [cb find_next]
+       ${NS}::button $w.bp      -text [mc Prev] -command [cb find_prev]
+       ${NS}::checkbutton $w.re -text [mc RegExp] \
+               -variable ${__this}::regexpsearch -command [cb _incrsearch]
+       ${NS}::checkbutton $w.cs -text [mc Case] \
                -variable ${__this}::casesensitive -command [cb _incrsearch]
        pack   $w.l   -side left
        pack   $w.cs  -side right
+       pack   $w.re  -side right
        pack   $w.bp  -side right
        pack   $w.bn  -side right
        pack   $w.ent -side left -expand 1 -fill x
@@ -34,14 +48,18 @@ constructor new {i_w i_text args} {
        grid remove $w
 
        trace add variable searchstring write [cb _incrsearch_cb]
+       bind $w.ent <Return> [cb find_next]
+       bind $w.ent <Shift-Return> [cb find_prev]
        
-       bind $w <Destroy> [cb delete_this]
+       bind $w <Destroy> [list delete_this $this]
        return $this
 }
 
 method show {} {
        if {![visible $this]} {
                grid $w
+               set regexpsearch  $default_regexpsearch
+               set casesensitive $default_casesensitive
        }
        focus -force $w.ent
 }
@@ -95,6 +113,9 @@ method _do_search {start {mlenvar {}} {dir {}} {endbound {}}} {
                upvar $mlenvar mlen
                lappend cmd -count mlen
        }
+       if {$regexpsearch} {
+               lappend cmd -regexp
+       }
        if {!$casesensitive} {
                lappend cmd -nocase
        }
@@ -122,6 +143,9 @@ method _incrsearch {} {
        if {[catch {$ctext index anchor}]} {
                $ctext mark set anchor [_get_new_anchor $this]
        }
+       if {[regexp {[[:upper:]]} $searchstring]} {
+               set casesensitive 1
+       }
        if {$searchstring ne {}} {
                set here [_do_search $this anchor mlen]
                if {$here ne {}} {
@@ -195,4 +219,4 @@ method scrolled {} {
        }
 }
 
-}
\ No newline at end of file
+}