Preserve selection order in TUI.pm (e.g. when comparing results)
This commit is contained in:
@ -33,11 +33,13 @@ sub select_from_list {
|
|||||||
: map { $_ => $_ } @items;
|
: map { $_ => $_ } @items;
|
||||||
|
|
||||||
my @selection;
|
my @selection;
|
||||||
|
my @selection_order; # multiselect only: items in toggle order
|
||||||
|
|
||||||
my $cui = init_cui();
|
my $cui = init_cui();
|
||||||
my $win = $cui->add( 'root', 'Window', );
|
my $win = $cui->add( 'root', 'Window', );
|
||||||
|
|
||||||
my $listbox = $win->add(
|
my $listbox;
|
||||||
|
$listbox = $win->add(
|
||||||
'item_list',
|
'item_list',
|
||||||
'Listbox',
|
'Listbox',
|
||||||
-title => $title,
|
-title => $title,
|
||||||
@ -47,7 +49,20 @@ sub select_from_list {
|
|||||||
-multi => $multiselect == 1,
|
-multi => $multiselect == 1,
|
||||||
-radio => $multiselect == 0,
|
-radio => $multiselect == 0,
|
||||||
-padbottom => 1,
|
-padbottom => 1,
|
||||||
|
-onchange => sub {
|
||||||
|
return unless $multiselect;
|
||||||
|
my %now = map { $_ => 1 } $listbox->get();
|
||||||
|
|
||||||
|
# Append newly selected items in toggle order
|
||||||
|
for my $item (@items) {
|
||||||
|
if ( $now{$item} && !grep { $_ eq $item } @selection_order ) {
|
||||||
|
push @selection_order, $item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Drop deselected items
|
||||||
|
@selection_order = grep { $now{$_} } @selection_order;
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
$win->add(
|
$win->add(
|
||||||
@ -64,6 +79,9 @@ sub select_from_list {
|
|||||||
if ( $multiselect && grep { $_ eq '__ALL__' } @picked ) {
|
if ( $multiselect && grep { $_ eq '__ALL__' } @picked ) {
|
||||||
@selection = @items;
|
@selection = @items;
|
||||||
}
|
}
|
||||||
|
elsif ($multiselect) {
|
||||||
|
@selection = @selection_order;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
@selection = @picked;
|
@selection = @picked;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user