Skip to content
GitLab
Menu
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
db166019
Commit
db166019
authored
Mar 17, 2015
by
Stefan Tauner
Browse files
fiji_scripts: allow value validation to include old value
parent
f6bec639
Changes
3
Hide whitespace changes
Inline
Side-by-side
FIJI.pm
View file @
db166019
...
...
@@ -17,7 +17,10 @@ use warnings;
# natural: values must be oct, hex, binary strings looking like a real number.
# hexadecimal: values must be hexadecimal numbers.
# boolean: will be convert to a truth value by Perl semantics
# - values = (optional) an array reference listing all valid values (emulates an enum)
# - values = (optional) used to restrict valid values. Can be...
# - an array reference listing all valid values (emulates an enum)
# - a code reference to a function that gets the new and old values and
# returns true if the new value is allowed, or false otherwise.
# - phases_opt = (optional) list of phases (subset of "setup", "instrument", "download")
# where no value must be present in input (e.g. ID is only necessary while downloading).
# - default = (optional) default value if not given in file and not determinable otherwise
...
...
FIJI/Settings.pm
View file @
db166019
...
...
@@ -292,10 +292,18 @@ sub validate_fiu_value {
return
validate_value
(
FIUMAP
,
$k
,
$v_ref
);
}
# Do validation (and conversation from external->internal representation)
sub
validate_value
($$$;$) {
## @function validate_value (%$map_ref, $k, $$v_ref, $old, $log_func)
# Do validation (and conversation from external->internal representation)
#
# \param map_ref reference to FIJI Settings mappings
# \param k key identifying the respective setting
# \param v_ref scalar reference to the proposed value (that may be modified)
# \param old (optional) previously valid value
# \param log_func (optional) the (log4perl) log function to use
# (defaul is \&Log::Log4perl::Logger::trace)
sub
validate_value
($$$;$$) {
my
$logger
=
get_logger
();
my
(
$map_ref
,
$k
,
$v_ref
,
$log_func
)
=
@_
;
my
(
$map_ref
,
$k
,
$v_ref
,
$old
,
$log_func
)
=
@_
;
$log_func
=
\
&
Log::Log4perl::Logger::
trace
if
!
defined
(
$log_func
);
if
(
defined
(
$map_ref
->
{
$k
}
->
{'
type
'}))
{
my
$orig
=
$
{
$v_ref
};
...
...
@@ -357,7 +365,7 @@ sub validate_value ($$$;$) {
return
0
;
}
}
elsif
(
ref
(
$values_ref
)
eq
'
CODE
')
{
if
(
!
$values_ref
->
(
$
{
$v_ref
}))
{
if
(
!
$values_ref
->
(
$
{
$v_ref
}
,
$old
))
{
$log_func
->
(
$logger
,
"
$k
:
${
$
v_ref}
is not allowed.
");
return
0
;
}
...
...
Tk/FIJISettingsViewer.pm
View file @
db166019
...
...
@@ -504,9 +504,10 @@ sub _validate_fiu_entry {
sub
_validate_entry
{
my
(
$map
,
$widget
,
$name
,
$new
,
$diff
,
$old
,
$char_idx
,
$type
)
=
@_
;
my
(
$map
,
$widget
,
$name
,
$new
,
$diff
,
$old
_str
,
$char_idx
,
$type
)
=
@_
;
my
$new_bak
=
$new
;
my
$ok
=
FIJI::Settings::
validate_value
(
$map
,
$name
,
\
$new
);
my
$old_val
=
$
{
$widget
->
{'
fiji_backend_ref
'}};
my
$ok
=
FIJI::Settings::
validate_value
(
$map
,
$name
,
\
$new
,
$old_val
);
_highlight_widget
(
$widget
,
(
!
$ok
));
if
(
$ok
)
{
$
{
$widget
->
{'
fiji_backend_ref
'}}
=
$new
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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