mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-14 19:15: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,50 +766,54 @@ sub selected_presets {
|
||||
sub show_preset_editor {
|
||||
my ($self, $group, $i) = @_;
|
||||
|
||||
my @presets = $self->selected_presets($group);
|
||||
wxTheApp->CallAfter(sub {
|
||||
my @presets = $self->selected_presets($group);
|
||||
|
||||
my $preset_editor;
|
||||
my $dlg;
|
||||
my $mainframe = $self->GetFrame;
|
||||
my $tabpanel = $mainframe->{tabpanel};
|
||||
if (exists $mainframe->{preset_editor_tabs}{$group}) {
|
||||
# we already have an open editor
|
||||
$tabpanel->SetSelection($tabpanel->GetPageIndex($mainframe->{preset_editor_tabs}{$group}));
|
||||
return;
|
||||
} elsif ($Slic3r::GUI::Settings->{_}{tabbed_preset_editors}) {
|
||||
my $class = "Slic3r::GUI::PresetEditor::" . ucfirst($group);
|
||||
$mainframe->{preset_editor_tabs}{$group} = $preset_editor = $class->new($self->GetFrame);
|
||||
$tabpanel->AddPage($preset_editor, ucfirst($group) . " Settings", 1);
|
||||
} else {
|
||||
my $class = "Slic3r::GUI::PresetEditorDialog::" . ucfirst($group);
|
||||
$dlg = $class->new($self);
|
||||
$preset_editor = $dlg->preset_editor;
|
||||
}
|
||||
my $preset_editor;
|
||||
my $dlg;
|
||||
my $mainframe = $self->GetFrame;
|
||||
my $tabpanel = $mainframe->{tabpanel};
|
||||
if (exists $mainframe->{preset_editor_tabs}{$group}) {
|
||||
# we already have an open editor
|
||||
$tabpanel->SetSelection($tabpanel->GetPageIndex($mainframe->{preset_editor_tabs}{$group}));
|
||||
return;
|
||||
} elsif ($Slic3r::GUI::Settings->{_}{tabbed_preset_editors}) {
|
||||
my $class = "Slic3r::GUI::PresetEditor::" . ucfirst($group);
|
||||
$mainframe->{preset_editor_tabs}{$group} = $preset_editor = $class->new($self->GetFrame);
|
||||
$tabpanel->AddPage($preset_editor, ucfirst($group) . " Settings", 1);
|
||||
} else {
|
||||
my $class = "Slic3r::GUI::PresetEditorDialog::" . ucfirst($group);
|
||||
$dlg = $class->new($self);
|
||||
$preset_editor = $dlg->preset_editor;
|
||||
}
|
||||
|
||||
$preset_editor->select_preset_by_name($presets[$i // 0]->name);
|
||||
$preset_editor->on_value_change(sub {
|
||||
# Re-load the presets in order to toggle the (modified) suffix
|
||||
$self->load_presets;
|
||||
$preset_editor->select_preset_by_name($presets[$i // 0]->name);
|
||||
$preset_editor->on_value_change(sub {
|
||||
# Re-load the presets in order to toggle the (modified) suffix
|
||||
$self->load_presets;
|
||||
|
||||
# Update shortcuts
|
||||
$self->_on_select_preset($group);
|
||||
# Update shortcuts
|
||||
$self->_on_select_preset($group);
|
||||
|
||||
# Use the new config wherever we actually use its contents
|
||||
$self->config_changed;
|
||||
# Use the new config wherever we actually use its contents
|
||||
$self->config_changed;
|
||||
});
|
||||
my $cb = sub {
|
||||
my ($group, $preset) = @_;
|
||||
|
||||
# Re-load the presets as they might have changed.
|
||||
$self->load_presets;
|
||||
|
||||
# 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;
|
||||
}
|
||||
});
|
||||
$preset_editor->on_select_preset(sub {
|
||||
my ($group, $preset) = @_;
|
||||
|
||||
# Re-load the presets as they might have changed.
|
||||
$self->load_presets;
|
||||
|
||||
# Select the preset in plater too
|
||||
$self->select_preset_by_name($preset->name, $group, $i, 1);
|
||||
});
|
||||
|
||||
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) = @_;
|
||||
|
||||
$self->current_preset->_dirty_config->apply($self->config);
|
||||
$self->{on_value_change}->($opt_key) if $self->{on_value_change};
|
||||
$self->load_presets;
|
||||
$self->_update;
|
||||
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