mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-14 20:35:54 +08:00
Fixed behavior of dirty settings not being correctly updated in the plater
This commit is contained in:
parent
a1b0246710
commit
4ab4831110
@ -766,6 +766,7 @@ sub selected_presets {
|
||||
sub show_preset_editor {
|
||||
my ($self, $group, $i) = @_;
|
||||
|
||||
wxTheApp->CallAfter(sub {
|
||||
my @presets = $self->selected_presets($group);
|
||||
|
||||
my $preset_editor;
|
||||
@ -797,7 +798,7 @@ sub show_preset_editor {
|
||||
# Use the new config wherever we actually use its contents
|
||||
$self->config_changed;
|
||||
});
|
||||
$preset_editor->on_select_preset(sub {
|
||||
my $cb = sub {
|
||||
my ($group, $preset) = @_;
|
||||
|
||||
# Re-load the presets as they might have changed.
|
||||
@ -805,11 +806,14 @@ sub show_preset_editor {
|
||||
|
||||
# Select the preset in plater too
|
||||
$self->select_preset_by_name($preset->name, $group, $i, 1);
|
||||
});
|
||||
};
|
||||
$preset_editor->on_select_preset($cb);
|
||||
$preset_editor->on_save_preset($cb);
|
||||
|
||||
if ($dlg) {
|
||||
$dlg->ShowModal;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
# Returns the current config by merging the selected presets and the overrides.
|
||||
|
@ -140,6 +140,9 @@ sub save_as {
|
||||
$self->_config->clear;
|
||||
$self->_config->apply($self->_dirty_config);
|
||||
}
|
||||
|
||||
# unlink the file first to avoid problems on case-insensitive file systems
|
||||
unlink Slic3r::encode_path($self->file);
|
||||
$self->_config->save($self->file);
|
||||
wxTheApp->load_presets;
|
||||
|
||||
|
@ -127,9 +127,16 @@ sub save_preset {
|
||||
$self->load_presets;
|
||||
$self->select_preset_by_name($preset->name);
|
||||
|
||||
$self->{on_save_preset}->($self->name, $preset) if $self->{on_save_preset};
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub on_save_preset {
|
||||
my ($self, $cb) = @_;
|
||||
$self->{on_save_preset} = $cb;
|
||||
}
|
||||
|
||||
sub on_value_change {
|
||||
my ($self, $cb) = @_;
|
||||
$self->{on_value_change} = $cb;
|
||||
@ -141,10 +148,12 @@ sub on_value_change {
|
||||
sub _on_value_change {
|
||||
my ($self, $opt_key) = @_;
|
||||
|
||||
wxTheApp->CallAfter(sub {
|
||||
$self->current_preset->_dirty_config->apply($self->config);
|
||||
$self->{on_value_change}->($opt_key) if $self->{on_value_change};
|
||||
$self->load_presets;
|
||||
$self->_update;
|
||||
});
|
||||
}
|
||||
|
||||
sub _update {}
|
||||
@ -163,6 +172,10 @@ sub select_preset_by_name {
|
||||
|
||||
my $presets = wxTheApp->presets->{$self->name};
|
||||
my $i = first { $presets->[$_]->name eq $name } 0..$#$presets;
|
||||
if (!defined $i) {
|
||||
warn "No preset named $name";
|
||||
return 0;
|
||||
}
|
||||
$self->{presets_choice}->SetSelection($i);
|
||||
$self->_on_select_preset($force);
|
||||
}
|
||||
@ -190,9 +203,6 @@ sub _on_select_preset {
|
||||
# Get the selected name.
|
||||
my $preset = wxTheApp->presets->{$self->name}->[$self->{presets_choice}->GetSelection];
|
||||
|
||||
# If selection didn't change, do nothing.
|
||||
return if defined $self->current_preset && $preset->name eq $self->current_preset->name;
|
||||
|
||||
# If we have unsaved changes, prompt user.
|
||||
if (!$force && !$self->prompt_unsaved_changes) {
|
||||
# User decided not to save the current changes, so we restore the previous selection.
|
||||
@ -204,6 +214,11 @@ sub _on_select_preset {
|
||||
|
||||
$self->current_preset($preset);
|
||||
|
||||
# If selection didn't change, do nothing.
|
||||
# Only after resetting current_preset because it might contain an older object of the
|
||||
# current preset.
|
||||
return if defined $self->current_preset && $preset->name eq $self->current_preset->name;
|
||||
|
||||
# We reload presets in order to remove the "(modified)" suffix in case user was
|
||||
# prompted and chose to discard changes.
|
||||
$self->load_presets;
|
||||
|
Loading…
x
Reference in New Issue
Block a user