Commit f48588ee authored by Stefan Tauner's avatar Stefan Tauner
Browse files

FIJISearchWidget: add support for case-insensitive search

parent a448ee80
......@@ -31,7 +31,7 @@ use constant debug => 0;
sub glob_to_regex {
my $glob = shift;
my $regex = glob_to_regex_string($glob);
return qr/^$regex$/;
return "^$regex\$";
}
sub glob_to_regex_string
......
......@@ -24,7 +24,7 @@ use warnings;
use utf8;
use Tk;
use Tk::widgets qw(Entry Button Frame Radiobutton Balloon);
use Tk::widgets qw(Entry Button Frame Checkbutton Radiobutton Balloon);
use Tk::FIJIModalDialog;
use FIJI::TextGlob;
$FIJI::TextGlob::strict_wildcard_slash = 0;
......@@ -50,16 +50,15 @@ sub callback {
if ($self->{'search_mode'} eq 'Glob') {
$regex = FIJI::TextGlob::glob_to_regex($string);
} elsif ($self->{'search_mode'} eq 'Regex') {
# check if regex is valid:
eval { "" =~ qr($string) };
if ($@) {
$msg = "Error in regular expression: $@";
} else {
$regex = qr/$string/;
$regex = "$string";
}
} elsif ($self->{'search_mode'} eq 'Substring') {
$regex = qr/\Q$string\E/;
$regex = "\Q$string\E";
} else {
$msg = "Invalid search mode. Please report a bug in module '" . $self->class() . "'!";
}
......@@ -74,6 +73,8 @@ sub callback {
# $self->Unbusy; needed?
} else {
my $ci_str = ($self->{'case_insensitive'}) ? "(?i)" : "";
$regex = qr/$ci_str$regex/;
$self->cget('-callback')->($regex, $self->cget('-userdata'));
}
}
......@@ -98,7 +99,7 @@ sub Populate {
$search_entry->focus();
$self->{'search_mode'} = 'Substring'; # Default to substring
my $search_mode_frame = $self->Frame()->grid(-row => 1, -column => 0, -padx => 5, -pady => 0, -sticky => 'w');
my $search_mode_frame = $self->Frame()->grid(-row => 1, -column => 0, -padx => 5, -pady => 0, -sticky => 'ew');
my $search_modes = [
{text => 'Substring', tooltip => 'Search for a substring anywhere within the given string(s)'},
{text => 'Glob', tooltip => 'Search using standard globbing symbols ("*" and "?")'},
......@@ -108,4 +109,7 @@ sub Populate {
my $rb = $search_mode_frame->Radiobutton(-text => $_->{text}, -value => $_->{text}, -variable => \$self->{'search_mode'})->pack(-side => 'left');
$balloon_widget->attach($rb, -msg => $_->{tooltip});
}
my $insensitive_cb = $search_mode_frame->Checkbutton(-text => 'Case-insensitive', -variable => \$self->{'case_insensitive'})->pack(-side => 'right');
$balloon_widget->attach($insensitive_cb, -msg => 'Use case-insensitive search if enabled');
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment