Cleaning up and fixing localization issues with AppController.

This commit is contained in:
tamasmeszaros 2018-09-07 10:24:05 +02:00
parent ae2b4dd01c
commit ec3e1403b6
7 changed files with 72 additions and 313 deletions

View file

@ -32,11 +32,11 @@ void AppControllerBoilerplate::process_events()
AppControllerBoilerplate::PathList
AppControllerBoilerplate::query_destination_paths(
const string &title,
const std::string &title,
const std::string &extensions) const
{
wxFileDialog dlg(wxTheApp->GetTopWindow(), title );
wxFileDialog dlg(wxTheApp->GetTopWindow(), _(title) );
dlg.SetWildcard(extensions);
dlg.ShowModal();
@ -52,11 +52,11 @@ AppControllerBoilerplate::query_destination_paths(
AppControllerBoilerplate::Path
AppControllerBoilerplate::query_destination_path(
const string &title,
const std::string &title,
const std::string &extensions,
const std::string& hint) const
{
wxFileDialog dlg(wxTheApp->GetTopWindow(), title );
wxFileDialog dlg(wxTheApp->GetTopWindow(), _(title) );
dlg.SetWildcard(extensions);
dlg.SetFilename(hint);
@ -71,8 +71,8 @@ AppControllerBoilerplate::query_destination_path(
}
bool AppControllerBoilerplate::report_issue(IssueType issuetype,
const string &description,
const string &brief)
const std::string &description,
const std::string &brief)
{
auto icon = wxICON_INFORMATION;
auto style = wxOK|wxCENTRE;
@ -84,15 +84,15 @@ bool AppControllerBoilerplate::report_issue(IssueType issuetype,
case IssueType::FATAL: icon = wxICON_ERROR;
}
auto ret = wxMessageBox(description, brief, icon | style);
auto ret = wxMessageBox(_(description), _(brief), icon | style);
return ret != wxCANCEL;
}
bool AppControllerBoilerplate::report_issue(
AppControllerBoilerplate::IssueType issuetype,
const string &description)
const std::string &description)
{
return report_issue(issuetype, description, string());
return report_issue(issuetype, description, std::string());
}
wxDEFINE_EVENT(PROGRESS_STATUS_UPDATE_EVENT, wxCommandEvent);
@ -104,10 +104,10 @@ namespace {
* the main thread as well.
*/
class GuiProgressIndicator:
public IProgressIndicator, public wxEvtHandler {
public ProgressIndicator, public wxEvtHandler {
wxProgressDialog gauge_;
using Base = IProgressIndicator;
using Base = ProgressIndicator;
wxString message_;
int range_; wxString title_;
bool is_asynch_ = false;
@ -136,8 +136,8 @@ public:
/// Get the mode of parallel operation.
inline bool asynch() const { return is_asynch_; }
inline GuiProgressIndicator(int range, const string& title,
const string& firstmsg) :
inline GuiProgressIndicator(int range, const wxString& title,
const wxString& firstmsg) :
gauge_(title, firstmsg, range, wxTheApp->GetTopWindow(),
wxPD_APP_MODAL | wxPD_AUTO_HIDE),
message_(firstmsg),
@ -151,11 +151,6 @@ public:
this, id_);
}
virtual void cancel() override {
update(max(), "Abort");
IProgressIndicator::cancel();
}
virtual void state(float val) override {
state(static_cast<unsigned>(val));
}
@ -170,26 +165,28 @@ public:
} else _state(st);
}
virtual void message(const string & msg) override {
message_ = msg;
virtual void message(const std::string & msg) override {
message_ = _(msg);
}
virtual void messageFmt(const string& fmt, ...) {
virtual void messageFmt(const std::string& fmt, ...) {
va_list arglist;
va_start(arglist, fmt);
message_ = wxString::Format(wxString(fmt), arglist);
message_ = wxString::Format(_(fmt), arglist);
va_end(arglist);
}
virtual void title(const string & title) override {
title_ = title;
virtual void title(const std::string & title) override {
title_ = _(title);
}
};
}
AppControllerBoilerplate::ProgresIndicatorPtr
AppControllerBoilerplate::create_progress_indicator(
unsigned statenum, const string& title, const string& firstmsg) const
unsigned statenum,
const std::string& title,
const std::string& firstmsg) const
{
auto pri =
std::make_shared<GuiProgressIndicator>(statenum, title, firstmsg);
@ -202,20 +199,20 @@ AppControllerBoilerplate::create_progress_indicator(
}
AppControllerBoilerplate::ProgresIndicatorPtr
AppControllerBoilerplate::create_progress_indicator(unsigned statenum,
const string &title) const
AppControllerBoilerplate::create_progress_indicator(
unsigned statenum, const std::string &title) const
{
return create_progress_indicator(statenum, title, string());
return create_progress_indicator(statenum, title, std::string());
}
namespace {
// A wrapper progress indicator class around the statusbar created in perl.
class Wrapper: public IProgressIndicator, public wxEvtHandler {
class Wrapper: public ProgressIndicator, public wxEvtHandler {
wxGauge *gauge_;
wxStatusBar *stbar_;
using Base = IProgressIndicator;
std::string message_;
using Base = ProgressIndicator;
wxString message_;
AppControllerBoilerplate& ctl_;
void showProgress(bool show = true) {
@ -223,7 +220,7 @@ class Wrapper: public IProgressIndicator, public wxEvtHandler {
}
void _state(unsigned st) {
if( st <= IProgressIndicator::max() ) {
if( st <= ProgressIndicator::max() ) {
Base::state(st);
if(!gauge_->IsShown()) showProgress(true);
@ -266,7 +263,7 @@ public:
virtual void max(float val) override {
if(val > 1.0) {
gauge_->SetRange(static_cast<int>(val));
IProgressIndicator::max(val);
ProgressIndicator::max(val);
}
}
@ -280,18 +277,18 @@ public:
}
}
virtual void message(const string & msg) override {
message_ = msg;
virtual void message(const std::string & msg) override {
message_ = _(msg);
}
virtual void message_fmt(const string& fmt, ...) override {
virtual void message_fmt(const std::string& fmt, ...) override {
va_list arglist;
va_start(arglist, fmt);
message_ = wxString::Format(fmt, arglist);
message_ = wxString::Format(_(fmt), arglist);
va_end(arglist);
}
virtual void title(const string & /*title*/) override {}
virtual void title(const std::string & /*title*/) override {}
};
}