From 33e160c1ed404f5d2e70da0533711d4569d0bf1d Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 11 Nov 2013 21:45:58 +0100 Subject: [PATCH] Automatically save presets after running the wizard --- lib/Slic3r/GUI/SkeinPanel.pm | 5 ++++ lib/Slic3r/GUI/Tab.pm | 57 ++++++++++++++++++++---------------- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/lib/Slic3r/GUI/SkeinPanel.pm b/lib/Slic3r/GUI/SkeinPanel.pm index 9327dcd7b..2f3afed0a 100644 --- a/lib/Slic3r/GUI/SkeinPanel.pm +++ b/lib/Slic3r/GUI/SkeinPanel.pm @@ -313,6 +313,11 @@ sub config_wizard { } } $self->load_config($config); + if ($self->{mode} eq 'expert') { + for my $tab (values %{$self->{options_tabs}}) { + $tab->save_preset('My Settings'); + } + } } } diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index 5ac982915..e9c80ec74 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -84,32 +84,7 @@ sub new { $self->on_presets_changed; }); - EVT_BUTTON($self, $self->{btn_save_preset}, sub { - - # since buttons (and choices too) don't get focus on Mac, we set focus manually - # to the treectrl so that the EVT_* events are fired for the input field having - # focus currently. is there anything better than this? - $self->{treectrl}->SetFocus; - - my $preset = $self->current_preset; - my $default_name = $preset->{default} ? 'Untitled' : basename($preset->{name}); - $default_name =~ s/\.ini$//i; - - my $dlg = Slic3r::GUI::SavePresetWindow->new($self, - title => lc($self->title), - default => $default_name, - values => [ map { my $name = $_->{name}; $name =~ s/\.ini$//i; $name } @{$self->{presets}} ], - ); - return unless $dlg->ShowModal == wxID_OK; - - my $file = sprintf "$Slic3r::GUI::datadir/%s/%s.ini", $self->name, $dlg->get_name; - $self->config->save($file); - $self->set_dirty(0); - $self->load_presets; - $self->{presets_choice}->SetSelection(first { basename($self->{presets}[$_]{file}) eq $dlg->get_name . ".ini" } 1 .. $#{$self->{presets}}); - $self->on_select_preset; - $self->on_presets_changed; - }); + EVT_BUTTON($self, $self->{btn_save_preset}, sub { $self->save_preset }); EVT_BUTTON($self, $self->{btn_delete_preset}, sub { my $i = $self->{presets_choice}->GetSelection; @@ -148,6 +123,36 @@ sub get_preset { return $self->{presets}[ $_[0] ]; } +sub save_preset { + my ($self, $name) = @_; + + # since buttons (and choices too) don't get focus on Mac, we set focus manually + # to the treectrl so that the EVT_* events are fired for the input field having + # focus currently. is there anything better than this? + $self->{treectrl}->SetFocus; + + if (!defined $name) { + my $preset = $self->current_preset; + my $default_name = $preset->{default} ? 'Untitled' : basename($preset->{name}); + $default_name =~ s/\.ini$//i; + + my $dlg = Slic3r::GUI::SavePresetWindow->new($self, + title => lc($self->title), + default => $default_name, + values => [ map { my $name = $_->{name}; $name =~ s/\.ini$//i; $name } @{$self->{presets}} ], + ); + return unless $dlg->ShowModal == wxID_OK; + $name = $dlg->get_name; + } + + $self->config->save(sprintf "$Slic3r::GUI::datadir/%s/%s.ini", $self->name, $name); + $self->set_dirty(0); + $self->load_presets; + $self->{presets_choice}->SetSelection(first { basename($self->{presets}[$_]{file}) eq $name . ".ini" } 1 .. $#{$self->{presets}}); + $self->on_select_preset; + $self->on_presets_changed; +} + # propagate event to the parent sub on_value_change { my $self = shift;