From 46d281931253448cd973b376ca712bd13ba7ac99 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sat, 22 Dec 2012 11:51:08 -0800 Subject: [PATCH] Use lambdas for some of DialogProgress's stuff --- aegisub/src/dialog_progress.cpp | 42 +++++++-------------------------- aegisub/src/dialog_progress.h | 6 ----- 2 files changed, 9 insertions(+), 39 deletions(-) diff --git a/aegisub/src/dialog_progress.cpp b/aegisub/src/dialog_progress.cpp index 4a63f3108..67c733483 100644 --- a/aegisub/src/dialog_progress.cpp +++ b/aegisub/src/dialog_progress.cpp @@ -59,11 +59,11 @@ public: } void SetTitle(std::string const& title) { - SafeQueue(EVT_TITLE, lagi_wxString(title)); + SafeQueue(EVT_TITLE, to_wx(title)); } void SetMessage(std::string const& msg) { - SafeQueue(EVT_MESSAGE, lagi_wxString(msg)); + SafeQueue(EVT_MESSAGE, to_wx(msg)); } void SetProgress(int64_t cur, int64_t max) { @@ -71,7 +71,7 @@ public: } void Log(std::string const& str) { - SafeQueue(EVT_LOG, lagi_wxString(str)); + SafeQueue(EVT_LOG, to_wx(str)); } bool IsCancelled() { @@ -147,15 +147,15 @@ DialogProgress::DialogProgress(wxWindow *parent, wxString const& title_text, wxS CenterOnParent(); Bind(wxEVT_SHOW, &DialogProgress::OnShow, this); - Bind(wxEVT_TIMER, &DialogProgress::OnPulseTimer, this); + Bind(wxEVT_TIMER, [=](wxTimerEvent&) { gauge->Pulse(); }); Bind(wxEVT_IDLE, &DialogProgress::OnIdle, this); - Bind(EVT_TITLE, &DialogProgress::OnSetTitle, this); - Bind(EVT_MESSAGE, &DialogProgress::OnSetMessage, this); - Bind(EVT_PROGRESS, &DialogProgress::OnSetProgress, this); - Bind(EVT_INDETERMINATE, &DialogProgress::OnSetIndeterminate, this); + Bind(EVT_TITLE, [=](wxThreadEvent& e) { title->SetLabelText(e.GetPayload()); }); + Bind(EVT_MESSAGE, [=](wxThreadEvent& e) { text->SetLabelText(e.GetPayload()); }); + Bind(EVT_PROGRESS, [=](wxThreadEvent& e) { gauge->SetValue(mid(0, e.GetPayload(), 100)); }); + Bind(EVT_INDETERMINATE, [=](wxThreadEvent &) { pulse_timer.Start(1000); }); Bind(EVT_COMPLETE, &DialogProgress::OnComplete, this); - Bind(EVT_LOG, &DialogProgress::OnLog, this); + Bind(EVT_LOG, [=](wxThreadEvent& e) { pending_log += e.GetPayload(); }); } void DialogProgress::Run(std::function task, int priority) { @@ -197,22 +197,6 @@ void DialogProgress::OnIdle(wxIdleEvent&) { pending_log.clear(); } -void DialogProgress::OnSetTitle(wxThreadEvent &evt) { - title->SetLabelText(evt.GetPayload()); -} - -void DialogProgress::OnSetMessage(wxThreadEvent &evt) { - text->SetLabelText(evt.GetPayload()); -} - -void DialogProgress::OnSetProgress(wxThreadEvent &evt) { - gauge->SetValue(mid(0, evt.GetPayload(), 100)); -} - -void DialogProgress::OnSetIndeterminate(wxThreadEvent &) { - pulse_timer.Start(1000); -} - void DialogProgress::OnComplete(wxThreadEvent &) { pulse_timer.Stop(); @@ -230,16 +214,8 @@ void DialogProgress::OnComplete(wxThreadEvent &) { cancel_button->SetLabelText(_("Close")); } -void DialogProgress::OnLog(wxThreadEvent &evt) { - pending_log += evt.GetPayload(); -} - void DialogProgress::OnCancel(wxCommandEvent &) { ps->Cancel(); cancel_button->Enable(false); cancel_button->SetLabelText(_("Cancelling...")); } - -void DialogProgress::OnPulseTimer(wxTimerEvent&) { - gauge->Pulse(); -} diff --git a/aegisub/src/dialog_progress.h b/aegisub/src/dialog_progress.h index 5ad17bdeb..9ea462564 100644 --- a/aegisub/src/dialog_progress.h +++ b/aegisub/src/dialog_progress.h @@ -44,16 +44,10 @@ class DialogProgress : public wxDialog, public agi::BackgroundRunner { wxString pending_log; - void OnSetTitle(wxThreadEvent &evt); - void OnSetMessage(wxThreadEvent &evt); - void OnSetProgress(wxThreadEvent &evt); - void OnSetIndeterminate(wxThreadEvent &evt); - void OnLog(wxThreadEvent &evt); void OnComplete(wxThreadEvent &evt); void OnShow(wxShowEvent&); void OnCancel(wxCommandEvent &); - void OnPulseTimer(wxTimerEvent&); void OnIdle(wxIdleEvent&); public: