From a10a554e2a69227cc3e5bdb8179970c6fdf8a822 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 25 Jan 2015 11:43:34 +0100 Subject: [PATCH] Remember last selected settings page in Printer Settings too, like in Print Settings and Filament Settings. #2568 --- lib/Slic3r/GUI/Tab.pm | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index b1eb2bcd3..a60425025 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -292,16 +292,24 @@ sub reload_config { } sub update_tree { - my $self = shift; - my ($select) = @_; + my ($self) = @_; - $select //= 0; #/ + # get label of the currently selected item + my $selected = $self->{treectrl}->GetItemText($self->{treectrl}->GetSelection); my $rootItem = $self->{treectrl}->GetRootItem; $self->{treectrl}->DeleteChildren($rootItem); + my $have_selection = 0; foreach my $page (@{$self->{pages}}) { my $itemId = $self->{treectrl}->AppendItem($rootItem, $page->{title}, $page->{iconID}); - $self->{treectrl}->SelectItem($itemId) if $self->{treectrl}->GetChildrenCount($rootItem) == $select + 1; + if ($page->{title} eq $selected) { + $self->{treectrl}->SelectItem($itemId); + $have_selection = 1; + } + } + + if (!$have_selection) { + $self->{treectrl}->SelectItem($self->{treectrl}->GetFirstChild($rootItem)); } } @@ -1182,6 +1190,7 @@ sub _build_extruder_pages { # remove extra pages if ($self->{extruders_count} <= $#{$self->{extruder_pages}}) { + $_->Destroy for @{$self->{extruder_pages}}[$self->{extruders_count}..$#{$self->{extruder_pages}}]; splice @{$self->{extruder_pages}}, $self->{extruders_count}; } @@ -1198,7 +1207,7 @@ sub _build_extruder_pages { (grep $_->{title} !~ /^Extruder \d+/, @{$self->{pages}}), @{$self->{extruder_pages}}[ 0 .. $self->{extruders_count}-1 ], ); - $self->update_tree(0); + $self->update_tree; } sub _update {