Skip to content

Commit

Permalink
GUI::show_error() is now generalized for std::string and const char*
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bubnikv committed Feb 21, 2020
1 parent 0486e41 commit a7ffd2a
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 12 deletions.
7 changes: 6 additions & 1 deletion src/slic3r/GUI/GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,15 @@ void show_error(wxWindow* parent, const wxString& message)
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)
{
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)
Expand Down
2 changes: 2 additions & 0 deletions src/slic3r/GUI/GUI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 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_info(wxWindow* parent, const wxString& message, const wxString& title);
void warning_catcher(wxWindow* parent, const wxString& message);
Expand Down
4 changes: 2 additions & 2 deletions src/slic3r/GUI/GUI_App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ bool GUI_App::on_init_inner()
try {
preset_bundle->load_presets(*app_config);
} catch (const std::exception &ex) {
show_error(nullptr, from_u8(ex.what()));
show_error(nullptr, ex.what());
}

register_dpi_event();
Expand Down Expand Up @@ -1241,7 +1241,7 @@ void GUI_App::check_updates(const bool verbose)
}
}
catch (const std::exception & ex) {
show_error(nullptr, from_u8(ex.what()));
show_error(nullptr, ex.what());
}


Expand Down
8 changes: 4 additions & 4 deletions src/slic3r/GUI/I18N.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::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 wxString 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 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 char *s, const char* ctx) { return _wxGetTranslation_ctx(wxString(s, wxConvUTF8), ctx).ToUTF8().data(); }
inline std::string translate_utf8(const wchar_t *s, const char* ctx) { return _wxGetTranslation_ctx(s, 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 std::string translate_utf8(const std::wstring &s, const char* ctx) { return _wxGetTranslation_ctx(s.c_str(), ctx).ToUTF8().data(); }

#undef _wxGetTranslation_ctx
} // namespace I18N
Expand Down
4 changes: 2 additions & 2 deletions src/slic3r/GUI/Plater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3074,10 +3074,10 @@ unsigned int Plater::priv::update_background_process(bool force_validation, bool
auto *top_level_wnd = dynamic_cast<wxTopLevelWindow*>(p);
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.
GUI::show_error(this->q, _(err));
GUI::show_error(this->q, err);
} else {
// 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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/GUI/PrintHostDialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ void PrintHostQueueDialog::on_error(Event &evt)

on_list_select();

GUI::show_error(nullptr, std::move(errormsg));
GUI::show_error(nullptr, errormsg);
}

void PrintHostQueueDialog::on_cancel(Event &evt)
Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/GUI/Tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3032,7 +3032,7 @@ void Tab::save_preset(std::string name /*= ""*/)
const Preset &preset = m_presets->get_selected_preset();
auto default_name = preset.is_default ? "Untitled" :
// 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;

bool have_extention = boost::iends_with(default_name, ".ini");
Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/Utils/PresetUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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;
GUI::show_error(nullptr, GUI::from_u8(message));
GUI::show_error(nullptr, message);
continue;
}

Expand Down

0 comments on commit a7ffd2a

Please sign in to comment.