Unbind the progress dialog's idle handler when it's unneeded

This commit is contained in:
Thomas Goyne 2014-04-05 07:51:31 -07:00
parent 2ea9c4c2c5
commit ec3d8e4f2e

View file

@ -142,7 +142,6 @@ DialogProgress::DialogProgress(wxWindow *parent, wxString const& title_text, wxS
Bind(wxEVT_SHOW, &DialogProgress::OnShow, this); Bind(wxEVT_SHOW, &DialogProgress::OnShow, this);
Bind(wxEVT_TIMER, [=](wxTimerEvent&) { gauge->Pulse(); }); Bind(wxEVT_TIMER, [=](wxTimerEvent&) { gauge->Pulse(); });
Bind(wxEVT_IDLE, &DialogProgress::OnIdle, this);
} }
void DialogProgress::Run(std::function<void(agi::ProgressSink*)> task, int priority) { void DialogProgress::Run(std::function<void(agi::ProgressSink*)> task, int priority) {
@ -161,6 +160,7 @@ void DialogProgress::Run(std::function<void(agi::ProgressSink*)> task, int prior
Main().Async([this]{ Main().Async([this]{
pulse_timer.Stop(); pulse_timer.Stop();
Unbind(wxEVT_IDLE, &DialogProgress::OnIdle, this);
// Unbind the cancel handler so that the default behavior happens (i.e. the // Unbind the cancel handler so that the default behavior happens (i.e. the
// dialog is closed) as there's no longer a task to cancel // dialog is closed) as there's no longer a task to cancel
@ -170,14 +170,13 @@ void DialogProgress::Run(std::function<void(agi::ProgressSink*)> task, int prior
// so the user can read the debug output and switch the cancel button to a // so the user can read the debug output and switch the cancel button to a
// close button // close button
bool cancelled = this->ps->IsCancelled(); bool cancelled = this->ps->IsCancelled();
if (cancelled || (log_output->IsEmpty() && !pending_log)) { if (cancelled || (log_output->IsEmpty() && !pending_log))
set_taskbar_progress(0);
EndModal(!cancelled); EndModal(!cancelled);
}
else { else {
cancel_button->SetLabelText(_("Close")); cancel_button->SetLabelText(_("Close"));
SetProgress(300); gauge->SetValue(300);
} }
set_taskbar_progress(0);
}); });
}); });
@ -185,10 +184,13 @@ void DialogProgress::Run(std::function<void(agi::ProgressSink*)> task, int prior
throw agi::UserCancelException("Cancelled by user"); throw agi::UserCancelException("Cancelled by user");
} }
void DialogProgress::OnShow(wxShowEvent&) { void DialogProgress::OnShow(wxShowEvent& evt) {
if (!evt.IsShown()) return;
// Restore the cancel button in case it was previously switched to a close // Restore the cancel button in case it was previously switched to a close
// button // button
Bind(wxEVT_BUTTON, &DialogProgress::OnCancel, this, wxID_CANCEL); Bind(wxEVT_BUTTON, &DialogProgress::OnCancel, this, wxID_CANCEL);
Bind(wxEVT_IDLE, &DialogProgress::OnIdle, this);
cancel_button->SetLabelText(_("Cancel")); cancel_button->SetLabelText(_("Cancel"));
cancel_button->Enable(); cancel_button->Enable();