From e58c32bee87cd7b4286f46d1a897f06d9f24f871 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 28 May 2015 18:31:53 +0200 Subject: [PATCH] Ask for confirmation before stopping prints --- lib/Slic3r/GUI/Controller.pm | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/Slic3r/GUI/Controller.pm b/lib/Slic3r/GUI/Controller.pm index 329efba89..be96b5fc0 100644 --- a/lib/Slic3r/GUI/Controller.pm +++ b/lib/Slic3r/GUI/Controller.pm @@ -3,7 +3,7 @@ use strict; use warnings; use utf8; -use Wx qw(wxTheApp :frame :id :misc :sizer :bitmap :button); +use Wx qw(wxTheApp :frame :id :misc :sizer :bitmap :button :icon :dialog); use Wx::Event qw(EVT_CLOSE EVT_LEFT_DOWN EVT_MENU); use base 'Wx::ScrolledWindow'; @@ -46,6 +46,20 @@ sub new { EVT_CLOSE($self, sub { my (undef, $event) = @_; + if ($event->CanVeto) { + foreach my $panel ($self->print_panels) { + if ($panel->printing) { + my $confirm = Wx::MessageDialog->new( + $self, "Printer '" . $panel->printer_name . "' is printing.\n\nDo you want to stop printing?", + 'Unfinished Print', wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION, + ); + if ($confirm->ShowModal == wxID_NO) { + $event->Veto; + return; + } + } + } + } foreach my $panel ($self->print_panels) { $panel->disconnect; } @@ -54,12 +68,13 @@ sub new { $event->Skip; }); - # if only one preset exists, load it { my %presets = wxTheApp->presets('printer'); my %configs = map { my $name = $_; $name => Slic3r::Config->load($presets{$name}) } keys %presets; my @presets_with_printer = grep $configs{$_}->serial_port, keys %presets; + if (@presets_with_printer == 1) { + # if only one preset exists, load it my $name = $presets_with_printer[0]; $self->add_printer($name, $configs{$name}); }