Skip to content

Commit

Permalink
BuildChoiceMenu: smarter check argument and use it
Browse files Browse the repository at this point in the history
  • Loading branch information
squentin committed Sep 19, 2015
1 parent b54d9a2 commit f2b44c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
5 changes: 4 additions & 1 deletion gmusicbrowser.pl
Original file line number Diff line number Diff line change
Expand Up @@ -4595,7 +4595,10 @@ sub BuildChoiceMenu
$sub->($args, $selected);
};
my ($check,$radio);
$check= $options{check}($args) if $options{check};
if ($check=$options{check})
{ if (ref $check) { $check= $check->($args) }
else { my ($not,$ref)=ParseKeyPath($args,$check); $check= $$ref }
}
if (defined $check)
{ $selection={};
if (ref $check) { $selection->{$_}=1 for @$check; }
Expand Down
14 changes: 7 additions & 7 deletions gmusicbrowser_list.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1660,20 +1660,20 @@ my @MenuSubGroup=
check => sub { $_[0]{self}{lmarkup}[$_[0]{depth}]}, istrue => 'aa', mode => 'LS', },
{ label => _"text mode", code => sub { $_[0]{self}->SetOption(mmarkup=>$_[1]); },
submenu => [ 0 => _"None", below => _"Below", right => _"Right side", ], submenu_ordered_hash => 1, submenu_reverse => 1,
check => sub { $_[0]{self}{mmarkup} }, mode => 'M', },
check => 'self/mmarkup', mode => 'M', },
{ label => _"picture size", code => sub { $_[0]{self}->SetOption(mpicsize=>$_[1]); },
mode => 'M',
submenu => \@mpicsize_menu, submenu_ordered_hash => 1, check => sub {$_[0]{self}{mpicsize}}, istrue => 'aa' },
submenu => \@mpicsize_menu, submenu_ordered_hash => 1, check => 'self/mpicsize', istrue => 'aa' },

{ label => _"font size depends on", code => sub { $_[0]{self}->SetOption(cloud_stat=>$_[1]); },
mode => 'C',
submenu => \@cloudstats_menu, submenu_ordered_hash => 1, check => sub {$_[0]{self}{cloud_stat}}, },
submenu => \@cloudstats_menu, submenu_ordered_hash => 1, check => 'self/cloud_stat', },
{ label => _"minimum font size", code => sub { $_[0]{self}->SetOption(cloud_min=>$_[1]); },
mode => 'C',
submenu => sub { [2..::min(20,$_[0]{self}{cloud_max}-1)] }, check => sub {$_[0]{self}{cloud_min}}, },
submenu => sub { [2..::min(20,$_[0]{self}{cloud_max}-1)] }, check => 'self/cloud_min', },
{ label => _"maximum font size", code => sub { $_[0]{self}->SetOption(cloud_max=>$_[1]); },
mode => 'C',
submenu => sub { [::max(10,$_[0]{self}{cloud_min}+1)..40] }, check => sub {$_[0]{self}{cloud_max}}, },
submenu => sub { [::max(10,$_[0]{self}{cloud_min}+1)..40] }, check => 'self/cloud_max', },

{ label => _"sort by", code => sub { my $self=$_[0]{self}; $self->{'sort'}[$_[0]{depth}]=$_[1]; $self->SetOption; },
check => sub {$_[0]{self}{sort}[$_[0]{depth}]}, submenu => sub { $_[0]{field} eq 'album' ? \%sort_menu_album : \%sort_menu; },
Expand Down Expand Up @@ -5370,7 +5370,7 @@ our @OptionsMenu=
{ label => _"Words that begin with", toggleoption => 'self/onlyword',code => sub { $_[0]{self}{onlybegin}=0; $_[0]{self}->changed;}, },
{ label => _"Hide non-matching",toggleoption=> 'self/hidenomatch', code => sub { $_[0]{self}{close_button}->set_visible($_[0]{self}{hidenomatch}); $_[0]{self}->changed;}, test=> sub { $_[0]{self}{type} } },
{ label => _"Fields", submenu => sub { return {map { $_=>Songs::FieldName($_) } Songs::StringFields}; }, submenu_reverse => 1,
check => sub { $_[0]{self}{fields}; }, test => sub { !$_[0]{self}{type} },
check => 'self/fields', test => sub { !$_[0]{self}{type} },
code => sub { my $toggle=$_[1]; my $l=$_[0]{self}{fields}; my $n=@$l; @$l=grep $toggle ne $_, @$l; push @$l,$toggle if @$l==$n; @$l=('title') unless @$l; $_[0]{self}->changed; }, #toggle selected field
},
);
Expand Down Expand Up @@ -6843,7 +6843,7 @@ use constant TREE_VIEW_DRAG_WIDTH => 6;
our @ColumnMenu=
( { label => _"_Sort by", submenu => sub { Browser::make_sort_menu($_[0]{songtree}); }
},
{ label => _"Set grouping", submenu => sub {$::Options{SavedSTGroupings}}, check =>sub { $_[0]{songtree}{grouping} },
{ label => _"Set grouping", submenu => sub {$::Options{SavedSTGroupings}}, check => 'songtree/grouping',
code => sub { $_[0]{songtree}->set_head_columns($_[1]); },
},
{ label => _"Edit grouping ...", code => sub { my $songtree=$_[0]{songtree}; ::EditSTGroupings($songtree,$songtree->{grouping},undef,sub{ $songtree->set_head_columns($_[0]) if defined $_[0]; }); },
Expand Down

0 comments on commit f2b44c8

Please sign in to comment.