Commit 81226f33 authored by Stefan Tauner's avatar Stefan Tauner
Browse files

FIJITestsViewer: towards unified handling of activated_by_settings

This patch automatically disables dropdown menus in addition to boolean
checkboxes and adds a text label to inform the user about the reason.
parent 9bee9338
......@@ -592,21 +592,29 @@ sub _populate_widget {
# entry
my $type = TESTCONSTMAP->{$k}->{'type'};
if (defined($type) && $type eq 'boolean') {
my $state = "normal";
my $t = "";
if (defined(TESTCONSTMAP->{$k}->{'activated_by_settings'})
&& ref(TESTCONSTMAP->{$k}->{'activated_by_settings'}) eq "CODE")
{
$state = TESTCONSTMAP->{$k}->{'activated_by_settings'}->($self->{'settings'}) ? "normal" : "disabled";
$t = "(disabled in FIJI configuration file)" if $state eq "disabled";
my $state = "normal";
my $activation_text = "";
my $activation_values = "";
my $activation_func = TESTCONSTMAP->{$k}->{'activated_by_settings'};
if (defined($activation_func) && ref($activation_func) eq "CODE")
{
$activation_values = $activation_func->($self->{'settings'});
if (ref($activation_values) eq "ARRAY") {
$state = (scalar(@{$activation_values}) > 1) ? "normal" : "disabled";
} elsif (ref(\$activation_values) eq "SCALAR") {
$state = ($activation_values ne "") ? "normal" : "disabled";
}
$activation_text = "(disabled due to current FIJI configuration)" if ($state eq "disabled");
$logger->trace("$k: activation_values=$activation_values");
}
if (defined($type) && $type eq 'boolean') {
$state = "disabled" if (TESTCONSTMAP->{$k}->{'noedit'});
$entry = $page->Checkbutton(
'-state' => $state,
'-variable' => \$self->{'tests'}->{'design'}->{$k},
'-justify' => 'left',
'-text' => $t,
'-text' => $activation_text,
);
$entry->grid(
-row => $row,
......@@ -629,20 +637,52 @@ sub _populate_widget {
} elsif (defined($type) && $type eq 'dropdown') {
my $options = TESTCONSTMAP->{$k}->{'values'};
if (defined(TESTCONSTMAP->{$k}->{'activated_by_settings'})
&& ref(TESTCONSTMAP->{$k}->{'activated_by_settings'}) eq "CODE")
{
$options = TESTCONSTMAP->{$k}->{'activated_by_settings'}->($self->{'settings'});
}
$options = $activation_values if defined($activation_func);
if (defined $options && ref($options) eq "CODE") {
$options = $options->();
}
$entry = $page->Optionmenu(
# If we are disabled we want to add a label next to the dropdown.
# To that end we create an intermediate frame here if need be.
my $base;
if ($state eq "disabled") {
$base = $page->Frame();
} else {
$base = $page;
}
my $opts = $base->Optionmenu(
'-state' => $state,
'-options' => $options,
'-textvariable' => \$self->{'tests'}->{'design'}->{$k},
'-anchor' => 'w',
'-justify' => 'left'
'-justify' => 'left',
);
if ($state eq "disabled") {
$opts->grid(
-row => 0,
-column => 0,
-sticky => "w"
);
$base->gridColumnconfigure(1, -weight => 1);
$base->Label(
-text => $activation_text,
-state => "disabled",
)->pack(
-side => "left",
-padx => 5
)->grid(
-row => 0,
-column => 1,
'-sticky' => 'w'
);
$entry = $base;
} else {
$entry = $opts;
}
# Whatever our entry is, we want it in the 2nd column on the left
$entry->grid(
-row => $row,
-column => 2,
......
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