mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-15 02:26:12 +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 {
|
sub show_preset_editor {
|
||||||
my ($self, $group, $i) = @_;
|
my ($self, $group, $i) = @_;
|
||||||
|
|
||||||
my @presets = $self->selected_presets($group);
|
wxTheApp->CallAfter(sub {
|
||||||
|
my @presets = $self->selected_presets($group);
|
||||||
|
|
||||||
my $preset_editor;
|
my $preset_editor;
|
||||||
my $dlg;
|
my $dlg;
|
||||||
my $mainframe = $self->GetFrame;
|
my $mainframe = $self->GetFrame;
|
||||||
my $tabpanel = $mainframe->{tabpanel};
|
my $tabpanel = $mainframe->{tabpanel};
|
||||||
if (exists $mainframe->{preset_editor_tabs}{$group}) {
|
if (exists $mainframe->{preset_editor_tabs}{$group}) {
|
||||||
# we already have an open editor
|
# we already have an open editor
|
||||||
$tabpanel->SetSelection($tabpanel->GetPageIndex($mainframe->{preset_editor_tabs}{$group}));
|
$tabpanel->SetSelection($tabpanel->GetPageIndex($mainframe->{preset_editor_tabs}{$group}));
|
||||||
return;
|
return;
|
||||||
} elsif ($Slic3r::GUI::Settings->{_}{tabbed_preset_editors}) {
|
} elsif ($Slic3r::GUI::Settings->{_}{tabbed_preset_editors}) {
|
||||||
my $class = "Slic3r::GUI::PresetEditor::" . ucfirst($group);
|
my $class = "Slic3r::GUI::PresetEditor::" . ucfirst($group);
|
||||||
$mainframe->{preset_editor_tabs}{$group} = $preset_editor = $class->new($self->GetFrame);
|
$mainframe->{preset_editor_tabs}{$group} = $preset_editor = $class->new($self->GetFrame);
|
||||||
$tabpanel->AddPage($preset_editor, ucfirst($group) . " Settings", 1);
|
$tabpanel->AddPage($preset_editor, ucfirst($group) . " Settings", 1);
|
||||||
} else {
|
} else {
|
||||||
my $class = "Slic3r::GUI::PresetEditorDialog::" . ucfirst($group);
|
my $class = "Slic3r::GUI::PresetEditorDialog::" . ucfirst($group);
|
||||||
$dlg = $class->new($self);
|
$dlg = $class->new($self);
|
||||||
$preset_editor = $dlg->preset_editor;
|
$preset_editor = $dlg->preset_editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
$preset_editor->select_preset_by_name($presets[$i // 0]->name);
|
$preset_editor->select_preset_by_name($presets[$i // 0]->name);
|
||||||
$preset_editor->on_value_change(sub {
|
$preset_editor->on_value_change(sub {
|
||||||
# Re-load the presets in order to toggle the (modified) suffix
|
# Re-load the presets in order to toggle the (modified) suffix
|
||||||
$self->load_presets;
|
$self->load_presets;
|
||||||
|
|
||||||
# Update shortcuts
|
# Update shortcuts
|
||||||
$self->_on_select_preset($group);
|
$self->_on_select_preset($group);
|
||||||
|
|
||||||
# Use the new config wherever we actually use its contents
|
# Use the new config wherever we actually use its contents
|
||||||
$self->config_changed;
|
$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.
|
# Returns the current config by merging the selected presets and the overrides.
|
||||||
|
@ -140,6 +140,9 @@ sub save_as {
|
|||||||
$self->_config->clear;
|
$self->_config->clear;
|
||||||
$self->_config->apply($self->_dirty_config);
|
$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);
|
$self->_config->save($self->file);
|
||||||
wxTheApp->load_presets;
|
wxTheApp->load_presets;
|
||||||
|
|
||||||
|
@ -127,9 +127,16 @@ sub save_preset {
|
|||||||
$self->load_presets;
|
$self->load_presets;
|
||||||
$self->select_preset_by_name($preset->name);
|
$self->select_preset_by_name($preset->name);
|
||||||
|
|
||||||
|
$self->{on_save_preset}->($self->name, $preset) if $self->{on_save_preset};
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub on_save_preset {
|
||||||
|
my ($self, $cb) = @_;
|
||||||
|
$self->{on_save_preset} = $cb;
|
||||||
|
}
|
||||||
|
|
||||||
sub on_value_change {
|
sub on_value_change {
|
||||||
my ($self, $cb) = @_;
|
my ($self, $cb) = @_;
|
||||||
$self->{on_value_change} = $cb;
|
$self->{on_value_change} = $cb;
|
||||||
@ -141,10 +148,12 @@ sub on_value_change {
|
|||||||
sub _on_value_change {
|
sub _on_value_change {
|
||||||
my ($self, $opt_key) = @_;
|
my ($self, $opt_key) = @_;
|
||||||
|
|
||||||
$self->current_preset->_dirty_config->apply($self->config);
|
wxTheApp->CallAfter(sub {
|
||||||
$self->{on_value_change}->($opt_key) if $self->{on_value_change};
|
$self->current_preset->_dirty_config->apply($self->config);
|
||||||
$self->load_presets;
|
$self->{on_value_change}->($opt_key) if $self->{on_value_change};
|
||||||
$self->_update;
|
$self->load_presets;
|
||||||
|
$self->_update;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
sub _update {}
|
sub _update {}
|
||||||
@ -163,6 +172,10 @@ sub select_preset_by_name {
|
|||||||
|
|
||||||
my $presets = wxTheApp->presets->{$self->name};
|
my $presets = wxTheApp->presets->{$self->name};
|
||||||
my $i = first { $presets->[$_]->name eq $name } 0..$#$presets;
|
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->{presets_choice}->SetSelection($i);
|
||||||
$self->_on_select_preset($force);
|
$self->_on_select_preset($force);
|
||||||
}
|
}
|
||||||
@ -190,9 +203,6 @@ sub _on_select_preset {
|
|||||||
# Get the selected name.
|
# Get the selected name.
|
||||||
my $preset = wxTheApp->presets->{$self->name}->[$self->{presets_choice}->GetSelection];
|
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 we have unsaved changes, prompt user.
|
||||||
if (!$force && !$self->prompt_unsaved_changes) {
|
if (!$force && !$self->prompt_unsaved_changes) {
|
||||||
# User decided not to save the current changes, so we restore the previous selection.
|
# 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);
|
$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
|
# We reload presets in order to remove the "(modified)" suffix in case user was
|
||||||
# prompted and chose to discard changes.
|
# prompted and chose to discard changes.
|
||||||
$self->load_presets;
|
$self->load_presets;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user