mirror of https://github.com/odrling/Aegisub
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:
parent
a3ef701f17
commit
46254613c8
|
@ -147,6 +147,7 @@ DialogProgress::DialogProgress(wxWindow *parent, wxString const& title_text, wxS
|
||||||
|
|
||||||
Bind(wxEVT_SHOW, &DialogProgress::OnShow, this);
|
Bind(wxEVT_SHOW, &DialogProgress::OnShow, this);
|
||||||
Bind(wxEVT_TIMER, &DialogProgress::OnPulseTimer, this);
|
Bind(wxEVT_TIMER, &DialogProgress::OnPulseTimer, this);
|
||||||
|
Bind(wxEVT_IDLE, &DialogProgress::OnIdle, this);
|
||||||
|
|
||||||
Bind(EVT_TITLE, &DialogProgress::OnSetTitle, this);
|
Bind(EVT_TITLE, &DialogProgress::OnSetTitle, this);
|
||||||
Bind(EVT_MESSAGE, &DialogProgress::OnSetMessage, 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) {
|
void DialogProgress::OnSetTitle(wxThreadEvent &evt) {
|
||||||
title->SetLabelText(evt.GetPayload<wxString>());
|
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
|
// so the user can read the debug output and switch the cancel button to a
|
||||||
// close button
|
// close button
|
||||||
bool cancelled = ps->IsCancelled();
|
bool cancelled = ps->IsCancelled();
|
||||||
if (cancelled || log_output->IsEmpty())
|
if (cancelled || (log_output->IsEmpty() && !pending_log))
|
||||||
EndModal(!cancelled);
|
EndModal(!cancelled);
|
||||||
else
|
else
|
||||||
cancel_button->SetLabelText(_("Close"));
|
cancel_button->SetLabelText(_("Close"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogProgress::OnLog(wxThreadEvent &evt) {
|
void DialogProgress::OnLog(wxThreadEvent &evt) {
|
||||||
if (log_output->IsEmpty()) {
|
pending_log += evt.GetPayload<wxString>();
|
||||||
wxSizer *sizer = GetSizer();
|
|
||||||
sizer->Show(log_output);
|
|
||||||
Layout();
|
|
||||||
sizer->Fit(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
*log_output << evt.GetPayload<wxString>();
|
|
||||||
log_output->SetInsertionPointEnd();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogProgress::OnCancel(wxCommandEvent &) {
|
void DialogProgress::OnCancel(wxCommandEvent &) {
|
||||||
|
|
|
@ -33,7 +33,6 @@ class wxGauge;
|
||||||
class wxStaticText;
|
class wxStaticText;
|
||||||
class wxTextCtrl;
|
class wxTextCtrl;
|
||||||
|
|
||||||
/// DOCME
|
|
||||||
/// @class DialogProgress
|
/// @class DialogProgress
|
||||||
/// @brief Progress-bar dialog box for displaying during long operations
|
/// @brief Progress-bar dialog box for displaying during long operations
|
||||||
class DialogProgress : public wxDialog, public agi::BackgroundRunner {
|
class DialogProgress : public wxDialog, public agi::BackgroundRunner {
|
||||||
|
@ -47,6 +46,8 @@ class DialogProgress : public wxDialog, public agi::BackgroundRunner {
|
||||||
|
|
||||||
wxTimer pulse_timer;
|
wxTimer pulse_timer;
|
||||||
|
|
||||||
|
wxString pending_log;
|
||||||
|
|
||||||
void OnSetTitle(wxThreadEvent &evt);
|
void OnSetTitle(wxThreadEvent &evt);
|
||||||
void OnSetMessage(wxThreadEvent &evt);
|
void OnSetMessage(wxThreadEvent &evt);
|
||||||
void OnSetProgress(wxThreadEvent &evt);
|
void OnSetProgress(wxThreadEvent &evt);
|
||||||
|
@ -57,6 +58,7 @@ class DialogProgress : public wxDialog, public agi::BackgroundRunner {
|
||||||
void OnShow(wxShowEvent&);
|
void OnShow(wxShowEvent&);
|
||||||
void OnCancel(wxCommandEvent &);
|
void OnCancel(wxCommandEvent &);
|
||||||
void OnPulseTimer(wxTimerEvent&);
|
void OnPulseTimer(wxTimerEvent&);
|
||||||
|
void OnIdle(wxIdleEvent&);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// Constructor
|
||||||
|
|
Loading…
Reference in New Issue