Batch up log messages in DialogProgress and append them in OnIdle

This signficantly improves performance with spammy automation macros
(karaoke templater with the log level set to Trace is 10-15x faster),
and helps ensure that clicks on the Cancel button are actually processed
in a timely manner.

Originally committed to SVN as r6481.
This commit is contained in:
Thomas Goyne 2012-02-16 21:22:04 +00:00
parent a3ef701f17
commit 46254613c8
2 changed files with 21 additions and 11 deletions

View File

@ -147,6 +147,7 @@ DialogProgress::DialogProgress(wxWindow *parent, wxString const& title_text, wxS
Bind(wxEVT_SHOW, &DialogProgress::OnShow, this);
Bind(wxEVT_TIMER, &DialogProgress::OnPulseTimer, this);
Bind(wxEVT_IDLE, &DialogProgress::OnIdle, this);
Bind(EVT_TITLE, &DialogProgress::OnSetTitle, this);
Bind(EVT_MESSAGE, &DialogProgress::OnSetMessage, this);
@ -180,6 +181,21 @@ void DialogProgress::OnShow(wxShowEvent&) {
}
}
void DialogProgress::OnIdle(wxIdleEvent&) {
if (!pending_log) return;
if (log_output->IsEmpty()) {
wxSizer *sizer = GetSizer();
sizer->Show(log_output);
Layout();
sizer->Fit(this);
}
*log_output << pending_log;
log_output->SetInsertionPointEnd();
pending_log.clear();
}
void DialogProgress::OnSetTitle(wxThreadEvent &evt) {
title->SetLabelText(evt.GetPayload<wxString>());
}
@ -207,22 +223,14 @@ void DialogProgress::OnComplete(wxThreadEvent &) {
// so the user can read the debug output and switch the cancel button to a
// close button
bool cancelled = ps->IsCancelled();
if (cancelled || log_output->IsEmpty())
if (cancelled || (log_output->IsEmpty() && !pending_log))
EndModal(!cancelled);
else
cancel_button->SetLabelText(_("Close"));
}
void DialogProgress::OnLog(wxThreadEvent &evt) {
if (log_output->IsEmpty()) {
wxSizer *sizer = GetSizer();
sizer->Show(log_output);
Layout();
sizer->Fit(this);
}
*log_output << evt.GetPayload<wxString>();
log_output->SetInsertionPointEnd();
pending_log += evt.GetPayload<wxString>();
}
void DialogProgress::OnCancel(wxCommandEvent &) {

View File

@ -33,7 +33,6 @@ class wxGauge;
class wxStaticText;
class wxTextCtrl;
/// DOCME
/// @class DialogProgress
/// @brief Progress-bar dialog box for displaying during long operations
class DialogProgress : public wxDialog, public agi::BackgroundRunner {
@ -47,6 +46,8 @@ class DialogProgress : public wxDialog, public agi::BackgroundRunner {
wxTimer pulse_timer;
wxString pending_log;
void OnSetTitle(wxThreadEvent &evt);
void OnSetMessage(wxThreadEvent &evt);
void OnSetProgress(wxThreadEvent &evt);
@ -57,6 +58,7 @@ class DialogProgress : public wxDialog, public agi::BackgroundRunner {
void OnShow(wxShowEvent&);
void OnCancel(wxCommandEvent &);
void OnPulseTimer(wxTimerEvent&);
void OnIdle(wxIdleEvent&);
public:
/// Constructor