mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-13 09:29:01 +08:00
Use submenus for listing options in dropdown menu. #3905
This commit is contained in:
parent
1826517b04
commit
dff61d1018
@ -52,16 +52,23 @@ sub new {
|
|||||||
EVT_LEFT_DOWN($btn, sub {
|
EVT_LEFT_DOWN($btn, sub {
|
||||||
my $menu = Wx::Menu->new;
|
my $menu = Wx::Menu->new;
|
||||||
my $last_cat = '';
|
my $last_cat = '';
|
||||||
|
|
||||||
|
# create category submenus
|
||||||
|
my %categories = (); # category => submenu
|
||||||
foreach my $opt_key (@{$self->{options}}) {
|
foreach my $opt_key (@{$self->{options}}) {
|
||||||
# add icon, if we have one for this category
|
|
||||||
my $icon;
|
|
||||||
if (my $cat = $Slic3r::Config::Options->{$opt_key}{category}) {
|
if (my $cat = $Slic3r::Config::Options->{$opt_key}{category}) {
|
||||||
if ($last_cat && $cat ne $last_cat) {
|
$categories{$cat} //= Wx::Menu->new;
|
||||||
$menu->AppendSeparator;
|
|
||||||
}
|
|
||||||
$last_cat = $cat;
|
|
||||||
$icon = $icons{$cat};
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# append submenus to main menu
|
||||||
|
foreach my $cat (sort keys %categories) {
|
||||||
|
wxTheApp->append_submenu($menu, $cat, "", $categories{$cat}, undef, $icons{$cat});
|
||||||
|
}
|
||||||
|
|
||||||
|
# append options to submenus
|
||||||
|
foreach my $opt_key (@{$self->{options}}) {
|
||||||
|
my $cat = $Slic3r::Config::Options->{$opt_key}{category} or next;
|
||||||
|
|
||||||
my $cb = sub {
|
my $cb = sub {
|
||||||
$self->{config}->set($opt_key, $self->{default_config}->get($opt_key));
|
$self->{config}->set($opt_key, $self->{default_config}->get($opt_key));
|
||||||
@ -69,8 +76,8 @@ sub new {
|
|||||||
$self->{on_change}->($opt_key) if $self->{on_change};
|
$self->{on_change}->($opt_key) if $self->{on_change};
|
||||||
};
|
};
|
||||||
|
|
||||||
wxTheApp->append_menu_item($menu, $self->{option_labels}{$opt_key},
|
wxTheApp->append_menu_item($categories{$cat}, $self->{option_labels}{$opt_key},
|
||||||
$Slic3r::Config::Options->{$opt_key}{tooltip}, $cb, undef, $icon);
|
$Slic3r::Config::Options->{$opt_key}{tooltip}, $cb);
|
||||||
}
|
}
|
||||||
$self->PopupMenu($menu, $btn->GetPosition);
|
$self->PopupMenu($menu, $btn->GetPosition);
|
||||||
$menu->Destroy;
|
$menu->Destroy;
|
||||||
@ -107,17 +114,11 @@ sub set_config {
|
|||||||
sub set_opt_keys {
|
sub set_opt_keys {
|
||||||
my ($self, $opt_keys) = @_;
|
my ($self, $opt_keys) = @_;
|
||||||
|
|
||||||
# sort options by category+label
|
# sort options by label
|
||||||
$self->{option_labels} = {};
|
$self->{option_labels} = {};
|
||||||
foreach my $opt_key (@$opt_keys) {
|
foreach my $opt_key (@$opt_keys) {
|
||||||
my $def = $Slic3r::Config::Options->{$opt_key} or next;
|
my $def = $Slic3r::Config::Options->{$opt_key} or next;
|
||||||
if (!$def->{category}) {
|
$self->{option_labels}{$opt_key} = $def->{full_label} // $def->{label};
|
||||||
#printf "Skipping %s\n", $opt_key;
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
$self->{option_labels}{$opt_key} = sprintf '%s > %s',
|
|
||||||
$def->{category},
|
|
||||||
$def->{full_label} // $def->{label};
|
|
||||||
};
|
};
|
||||||
$self->{options} = [ sort { $self->{option_labels}{$a} cmp $self->{option_labels}{$b} } keys %{$self->{option_labels}} ];
|
$self->{options} = [ sort { $self->{option_labels}{$a} cmp $self->{option_labels}{$b} } keys %{$self->{option_labels}} ];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user