Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
vecs
FIJI Public
Commits
f48588ee
Commit
f48588ee
authored
Jun 19, 2017
by
Stefan Tauner
Browse files
FIJISearchWidget: add support for case-insensitive search
parent
a448ee80
Changes
2
Hide whitespace changes
Inline
Side-by-side
bin/FIJI/TextGlob.pm
View file @
f48588ee
...
...
@@ -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
...
...
bin/Tk/FIJISearchWidget.pm
View file @
f48588ee
...
...
@@ -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
=>
'
e
w
');
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
');
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment