GUI::show_error() is now generalized for std::string and const char*

Fixed return type of std::string translate_utf8() with context
(incorrectly returned wxString, should return std::string).
Fixed double translation of BackgroundSlicingProcess::validate() in Plater.
This commit is contained in:
bubnikv 2020-02-21 13:38:06 +01:00
parent 0486e412f4
commit a7ffd2a6fe
8 changed files with 19 additions and 12 deletions

View file

@ -229,10 +229,15 @@ void show_error(wxWindow* parent, const wxString& message)
msg.ShowModal(); msg.ShowModal();
} }
void show_error(wxWindow* parent, const char* message)
{
show_error(parent, wxString::FromUTF8(message));
}
void show_error_id(int id, const std::string& message) void show_error_id(int id, const std::string& message)
{ {
auto *parent = id != 0 ? wxWindow::FindWindowById(id) : nullptr; auto *parent = id != 0 ? wxWindow::FindWindowById(id) : nullptr;
show_error(parent, from_u8(message)); show_error(parent, message);
} }
void show_info(wxWindow* parent, const wxString& message, const wxString& title) void show_info(wxWindow* parent, const wxString& message, const wxString& title)

View file

@ -39,6 +39,8 @@ extern void add_menus(wxMenuBar *menu, int event_preferences_changed, int event_
void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt_key, const boost::any& value, int opt_index = 0); void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt_key, const boost::any& value, int opt_index = 0);
void show_error(wxWindow* parent, const wxString& message); void show_error(wxWindow* parent, const wxString& message);
void show_error(wxWindow* parent, const char* message);
inline void show_error(wxWindow* parent, const std::string& message) { show_error(parent, message.c_str()); }
void show_error_id(int id, const std::string& message); // For Perl void show_error_id(int id, const std::string& message); // For Perl
void show_info(wxWindow* parent, const wxString& message, const wxString& title); void show_info(wxWindow* parent, const wxString& message, const wxString& title);
void warning_catcher(wxWindow* parent, const wxString& message); void warning_catcher(wxWindow* parent, const wxString& message);

View file

@ -244,7 +244,7 @@ bool GUI_App::on_init_inner()
try { try {
preset_bundle->load_presets(*app_config); preset_bundle->load_presets(*app_config);
} catch (const std::exception &ex) { } catch (const std::exception &ex) {
show_error(nullptr, from_u8(ex.what())); show_error(nullptr, ex.what());
} }
register_dpi_event(); register_dpi_event();
@ -1241,7 +1241,7 @@ void GUI_App::check_updates(const bool verbose)
} }
} }
catch (const std::exception & ex) { catch (const std::exception & ex) {
show_error(nullptr, from_u8(ex.what())); show_error(nullptr, ex.what());
} }

View file

@ -67,10 +67,10 @@ namespace I18N {
inline wxString translate(const std::string &s, const char* ctx) { return _wxGetTranslation_ctx(wxString(s.c_str(), wxConvUTF8), ctx); } inline wxString translate(const std::string &s, const char* ctx) { return _wxGetTranslation_ctx(wxString(s.c_str(), wxConvUTF8), ctx); }
inline wxString translate(const std::wstring &s, const char* ctx) { return _wxGetTranslation_ctx(s.c_str(), ctx); } inline wxString translate(const std::wstring &s, const char* ctx) { return _wxGetTranslation_ctx(s.c_str(), ctx); }
inline wxString translate_utf8(const char *s, const char* ctx) { return _wxGetTranslation_ctx(wxString(s, wxConvUTF8), ctx).ToUTF8().data(); } inline std::string translate_utf8(const char *s, const char* ctx) { return _wxGetTranslation_ctx(wxString(s, wxConvUTF8), ctx).ToUTF8().data(); }
inline wxString translate_utf8(const wchar_t *s, const char* ctx) { return _wxGetTranslation_ctx(s, ctx).ToUTF8().data(); } inline std::string translate_utf8(const wchar_t *s, const char* ctx) { return _wxGetTranslation_ctx(s, ctx).ToUTF8().data(); }
inline wxString translate_utf8(const std::string &s, const char* ctx) { return _wxGetTranslation_ctx(wxString(s.c_str(), wxConvUTF8), ctx).ToUTF8().data(); } inline std::string translate_utf8(const std::string &s, const char* ctx) { return _wxGetTranslation_ctx(wxString(s.c_str(), wxConvUTF8), ctx).ToUTF8().data(); }
inline wxString translate_utf8(const std::wstring &s, const char* ctx) { return _wxGetTranslation_ctx(s.c_str(), ctx).ToUTF8().data(); } inline std::string translate_utf8(const std::wstring &s, const char* ctx) { return _wxGetTranslation_ctx(s.c_str(), ctx).ToUTF8().data(); }
#undef _wxGetTranslation_ctx #undef _wxGetTranslation_ctx
} // namespace I18N } // namespace I18N

View file

@ -3074,10 +3074,10 @@ unsigned int Plater::priv::update_background_process(bool force_validation, bool
auto *top_level_wnd = dynamic_cast<wxTopLevelWindow*>(p); auto *top_level_wnd = dynamic_cast<wxTopLevelWindow*>(p);
if (! postpone_error_messages && top_level_wnd && top_level_wnd->IsActive()) { if (! postpone_error_messages && top_level_wnd && top_level_wnd->IsActive()) {
// The error returned from the Print needs to be translated into the local language. // The error returned from the Print needs to be translated into the local language.
GUI::show_error(this->q, _(err)); GUI::show_error(this->q, err);
} else { } else {
// Show the error message once the main window gets activated. // Show the error message once the main window gets activated.
this->delayed_error_message = _(err).ToUTF8(); this->delayed_error_message = err;
} }
return_state |= UPDATE_BACKGROUND_PROCESS_INVALID; return_state |= UPDATE_BACKGROUND_PROCESS_INVALID;
} }

View file

@ -275,7 +275,7 @@ void PrintHostQueueDialog::on_error(Event &evt)
on_list_select(); on_list_select();
GUI::show_error(nullptr, std::move(errormsg)); GUI::show_error(nullptr, errormsg);
} }
void PrintHostQueueDialog::on_cancel(Event &evt) void PrintHostQueueDialog::on_cancel(Event &evt)

View file

@ -3032,7 +3032,7 @@ void Tab::save_preset(std::string name /*= ""*/)
const Preset &preset = m_presets->get_selected_preset(); const Preset &preset = m_presets->get_selected_preset();
auto default_name = preset.is_default ? "Untitled" : auto default_name = preset.is_default ? "Untitled" :
// preset.is_system ? (boost::format(_utf8(L("%1% - Copy"))) % preset.name).str() : // preset.is_system ? (boost::format(_utf8(L("%1% - Copy"))) % preset.name).str() :
preset.is_system ? (boost::format(_CTX_utf8(L_CONTEXT("%1% - Copy", "PresetName"), "PresetName").ToUTF8()) % preset.name).str() : preset.is_system ? (boost::format(_CTX_utf8(L_CONTEXT("%1% - Copy", "PresetName"), "PresetName")) % preset.name).str() :
preset.name; preset.name;
bool have_extention = boost::iends_with(default_name, ".ini"); bool have_extention = boost::iends_with(default_name, ".ini");

View file

@ -423,7 +423,7 @@ Updates PresetUpdater::priv::get_config_updates(const Semver &old_slic3r_version
// Any published config shall be always found in the latest config index. // Any published config shall be always found in the latest config index.
auto message = (boost::format("Preset bundle `%1%` version not found in index: %2%") % idx.vendor() % vp.config_version.to_string()).str(); auto message = (boost::format("Preset bundle `%1%` version not found in index: %2%") % idx.vendor() % vp.config_version.to_string()).str();
BOOST_LOG_TRIVIAL(error) << message; BOOST_LOG_TRIVIAL(error) << message;
GUI::show_error(nullptr, GUI::from_u8(message)); GUI::show_error(nullptr, message);
continue; continue;
} }