Remember last presets
This commit is contained in:
parent
0ef8da42a6
commit
a664709b31
@ -169,6 +169,7 @@ our $extruder_clearance_radius = 20; # mm
|
|||||||
our $extruder_clearance_height = 20; # mm
|
our $extruder_clearance_height = 20; # mm
|
||||||
|
|
||||||
our $Defaults = Slic3r::Config->current;
|
our $Defaults = Slic3r::Config->current;
|
||||||
|
our $Settings = { presets => {} }; # application settings
|
||||||
|
|
||||||
sub parallelize {
|
sub parallelize {
|
||||||
my %params = @_;
|
my %params = @_;
|
||||||
|
@ -655,20 +655,41 @@ sub deserialize {
|
|||||||
: set($opt_key, $value);
|
: set($opt_key, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub write_ini {
|
||||||
|
my $class = shift;
|
||||||
|
my ($file, $ini) = @_;
|
||||||
|
|
||||||
|
open my $fh, '>', $file;
|
||||||
|
binmode $fh, ':utf8';
|
||||||
|
foreach my $category (sort keys %$ini) {
|
||||||
|
printf $fh "\n[%s]\n", $category if $category ne '_';
|
||||||
|
foreach my $key (sort keys %{$ini->{$category}}) {
|
||||||
|
printf $fh "%s = %s\n", $key, $ini->{$category}{$key};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close $fh;
|
||||||
|
}
|
||||||
|
|
||||||
sub save {
|
sub save {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
my ($file, $group) = @_;
|
my ($file, $group) = @_;
|
||||||
|
|
||||||
open my $fh, '>', $file;
|
my $ini = { _ => {} };
|
||||||
binmode $fh, ':utf8';
|
|
||||||
foreach my $opt (sort keys %$Options) {
|
foreach my $opt (sort keys %$Options) {
|
||||||
next if defined $group && not ($opt ~~ @{$Groups{$group}});
|
next if defined $group && not ($opt ~~ @{$Groups{$group}});
|
||||||
next if $Options->{$opt}{gui_only};
|
next if $Options->{$opt}{gui_only};
|
||||||
my $value = get($opt);
|
my $value = get($opt);
|
||||||
$value = $Options->{$opt}{serialize}->($value) if $Options->{$opt}{serialize};
|
$value = $Options->{$opt}{serialize}->($value) if $Options->{$opt}{serialize};
|
||||||
printf $fh "%s = %s\n", $opt, $value;
|
$ini->{_}{$opt} = $value;
|
||||||
}
|
}
|
||||||
close $fh;
|
$class->write_ini($file, $ini);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub save_settings {
|
||||||
|
my $class = shift;
|
||||||
|
my ($file) = @_;
|
||||||
|
|
||||||
|
$class->write_ini($file, $Slic3r::Settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub setenv {
|
sub setenv {
|
||||||
@ -701,6 +722,10 @@ sub read_ini {
|
|||||||
next if /^\s+/;
|
next if /^\s+/;
|
||||||
next if /^$/;
|
next if /^$/;
|
||||||
next if /^\s*#/;
|
next if /^\s*#/;
|
||||||
|
if (/^\[(\w+)\]$/) {
|
||||||
|
$category = $1;
|
||||||
|
next;
|
||||||
|
}
|
||||||
/^(\w+) = (.*)/ or die "Unreadable configuration file (invalid data at line $.)\n";
|
/^(\w+) = (.*)/ or die "Unreadable configuration file (invalid data at line $.)\n";
|
||||||
$ini->{$category}{$1} = $2;
|
$ini->{$category}{$1} = $2;
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,12 @@ sub OnInit {
|
|||||||
unless -d $_;
|
unless -d $_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# load settings
|
||||||
|
if (-f "$datadir/slic3r.ini") {
|
||||||
|
my $ini = eval { Slic3r::Config->read_ini("$datadir/slic3r.ini") };
|
||||||
|
$Slic3r::Settings = $ini if $ini;
|
||||||
|
}
|
||||||
|
|
||||||
# application frame
|
# application frame
|
||||||
Wx::Image::AddHandler(Wx::PNGHandler->new);
|
Wx::Image::AddHandler(Wx::PNGHandler->new);
|
||||||
my $frame = Wx::Frame->new(undef, -1, 'Slic3r', [-1, -1], [760,500], wxDEFAULT_FRAME_STYLE);
|
my $frame = Wx::Frame->new(undef, -1, 'Slic3r', [-1, -1], [760,500], wxDEFAULT_FRAME_STYLE);
|
||||||
|
@ -94,6 +94,7 @@ sub new {
|
|||||||
$self->set_dirty(0);
|
$self->set_dirty(0);
|
||||||
$self->load_presets;
|
$self->load_presets;
|
||||||
$self->{presets_choice}->SetSelection(1 + first { basename($self->{presets}[$_]) eq $dlg->get_name . ".ini" } 0 .. $#{$self->{presets}});
|
$self->{presets_choice}->SetSelection(1 + first { basename($self->{presets}[$_]) eq $dlg->get_name . ".ini" } 0 .. $#{$self->{presets}});
|
||||||
|
$self->on_select_preset;
|
||||||
$self->sync_presets;
|
$self->sync_presets;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -124,11 +125,12 @@ sub on_select_preset {
|
|||||||
}
|
}
|
||||||
|
|
||||||
my $i = $self->{presets_choice}->GetSelection;
|
my $i = $self->{presets_choice}->GetSelection;
|
||||||
|
my $file;
|
||||||
if ($i == 0) {
|
if ($i == 0) {
|
||||||
Slic3r::Config->load_hash($Slic3r::Defaults, $self->{presets_group}, 1);
|
Slic3r::Config->load_hash($Slic3r::Defaults, $self->{presets_group}, 1);
|
||||||
$self->{btn_delete_preset}->Disable;
|
$self->{btn_delete_preset}->Disable;
|
||||||
} else {
|
} else {
|
||||||
my $file = $self->{presets}[$i-1];
|
$file = $self->{presets}[$i-1];
|
||||||
if (!-e $file) {
|
if (!-e $file) {
|
||||||
Slic3r::GUI::show_error($self, "The selected preset does not exist anymore ($file).");
|
Slic3r::GUI::show_error($self, "The selected preset does not exist anymore ($file).");
|
||||||
return;
|
return;
|
||||||
@ -138,6 +140,8 @@ sub on_select_preset {
|
|||||||
}
|
}
|
||||||
$_->() for @Slic3r::GUI::OptionsGroup::reload_callbacks{@{$Slic3r::Config::Groups{$self->{presets_group}}}};
|
$_->() for @Slic3r::GUI::OptionsGroup::reload_callbacks{@{$Slic3r::Config::Groups{$self->{presets_group}}}};
|
||||||
$self->set_dirty(0);
|
$self->set_dirty(0);
|
||||||
|
$Slic3r::Settings->{presets}{$self->{presets_group}} = $file ? basename($file) : '';
|
||||||
|
Slic3r::Config->save_settings("$Slic3r::GUI::datadir/slic3r.ini");
|
||||||
}
|
}
|
||||||
|
|
||||||
sub add_options_page {
|
sub add_options_page {
|
||||||
@ -204,6 +208,13 @@ sub load_presets {
|
|||||||
$preset =~ s/\.ini$//i;
|
$preset =~ s/\.ini$//i;
|
||||||
$self->{presets_choice}->Append($preset);
|
$self->{presets_choice}->Append($preset);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
my $i = first { basename($self->{presets}[$_]) eq ($Slic3r::Settings->{presets}{$self->{presets_group}} || '') } 0 .. $#{$self->{presets}};
|
||||||
|
if (defined $i) {
|
||||||
|
$self->{presets_choice}->SetSelection($i + 1);
|
||||||
|
$self->on_select_preset;
|
||||||
|
}
|
||||||
|
}
|
||||||
$self->sync_presets;
|
$self->sync_presets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user