mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-12 01:07:57 -06:00
Merge remote-tracking branch 'remotes/origin/gui_translate_to_cpp'
This commit is contained in:
commit
69fc99edbb
26 changed files with 11863 additions and 6374 deletions
|
@ -28,7 +28,6 @@
|
|||
|
||||
#include <wx/app.h>
|
||||
#include <wx/button.h>
|
||||
#include <wx/config.h>
|
||||
#include <wx/dir.h>
|
||||
#include <wx/filename.h>
|
||||
#include <wx/frame.h>
|
||||
|
@ -45,6 +44,7 @@
|
|||
#include "TabIface.hpp"
|
||||
#include "AppConfig.hpp"
|
||||
#include "Utils.hpp"
|
||||
#include "Preferences.hpp"
|
||||
|
||||
namespace Slic3r { namespace GUI {
|
||||
|
||||
|
@ -171,6 +171,7 @@ void break_to_debugger()
|
|||
wxApp *g_wxApp = nullptr;
|
||||
wxFrame *g_wxMainFrame = nullptr;
|
||||
wxNotebook *g_wxTabPanel = nullptr;
|
||||
AppConfig *g_AppConfig = nullptr;
|
||||
|
||||
std::vector<Tab *> g_tabs_list;
|
||||
|
||||
|
@ -191,6 +192,11 @@ void set_tab_panel(wxNotebook *tab_panel)
|
|||
g_wxTabPanel = tab_panel;
|
||||
}
|
||||
|
||||
void set_app_config(AppConfig *app_config)
|
||||
{
|
||||
g_AppConfig = app_config;
|
||||
}
|
||||
|
||||
std::vector<Tab *>& get_tabs_list()
|
||||
{
|
||||
return g_tabs_list;
|
||||
|
@ -215,7 +221,7 @@ bool select_language(wxArrayString & names,
|
|||
wxArrayLong & identifiers)
|
||||
{
|
||||
wxCHECK_MSG(names.Count() == identifiers.Count(), false,
|
||||
_L("Array of language names and identifiers should have the same size."));
|
||||
_(L("Array of language names and identifiers should have the same size.")));
|
||||
int init_selection = 0;
|
||||
long current_language = g_wxLocale ? g_wxLocale->GetLanguage() : wxLANGUAGE_UNKNOWN;
|
||||
for (auto lang : identifiers){
|
||||
|
@ -226,7 +232,7 @@ bool select_language(wxArrayString & names,
|
|||
}
|
||||
if (init_selection == identifiers.size())
|
||||
init_selection = 0;
|
||||
long index = wxGetSingleChoiceIndex(_L("Select the language"), _L("Language"),
|
||||
long index = wxGetSingleChoiceIndex(_(L("Select the language")), _(L("Language")),
|
||||
names, init_selection);
|
||||
if (index != -1)
|
||||
{
|
||||
|
@ -241,13 +247,14 @@ bool select_language(wxArrayString & names,
|
|||
|
||||
bool load_language()
|
||||
{
|
||||
wxConfig config(g_wxApp->GetAppName());
|
||||
long language;
|
||||
if (!config.Read(wxT("wxTranslation_Language"),
|
||||
&language, wxLANGUAGE_UNKNOWN))
|
||||
{
|
||||
if (!g_AppConfig->has("translation_language"))
|
||||
language = wxLANGUAGE_UNKNOWN;
|
||||
else {
|
||||
auto str_language = g_AppConfig->get("translation_language");
|
||||
language = str_language != "" ? stol(str_language) : wxLANGUAGE_UNKNOWN;
|
||||
}
|
||||
|
||||
if (language == wxLANGUAGE_UNKNOWN)
|
||||
return false;
|
||||
wxArrayString names;
|
||||
|
@ -269,13 +276,13 @@ bool load_language()
|
|||
|
||||
void save_language()
|
||||
{
|
||||
wxConfig config(g_wxApp->GetAppName());
|
||||
long language = wxLANGUAGE_UNKNOWN;
|
||||
if (g_wxLocale) {
|
||||
language = g_wxLocale->GetLanguage();
|
||||
}
|
||||
config.Write(wxT("wxTranslation_Language"), language);
|
||||
config.Flush();
|
||||
std::string str_language = std::to_string(language);
|
||||
g_AppConfig->set("translation_language", str_language);
|
||||
g_AppConfig->save();
|
||||
}
|
||||
|
||||
void get_installed_languages(wxArrayString & names,
|
||||
|
@ -290,15 +297,12 @@ void get_installed_languages(wxArrayString & names,
|
|||
wxString name = wxLocale::GetLanguageName(wxLANGUAGE_DEFAULT);
|
||||
if (!name.IsEmpty())
|
||||
{
|
||||
names.Add(_L("Default"));
|
||||
names.Add(_(L("Default")));
|
||||
identifiers.Add(wxLANGUAGE_DEFAULT);
|
||||
}
|
||||
for (bool cont = dir.GetFirst(&filename, wxEmptyString, wxDIR_DIRS);
|
||||
cont; cont = dir.GetNext(&filename))
|
||||
{
|
||||
wxLogTrace(wxTraceMask(),
|
||||
"L10n: Directory found = \"%s\"",
|
||||
filename.GetData());
|
||||
langinfo = wxLocale::FindLanguageInfo(filename);
|
||||
if (langinfo != NULL)
|
||||
{
|
||||
|
@ -318,14 +322,14 @@ void add_debug_menu(wxMenuBar *menu, int event_language_change)
|
|||
{
|
||||
//#if 0
|
||||
auto local_menu = new wxMenu();
|
||||
local_menu->Append(wxWindow::NewControlId(1), _L("Change Application Language"));
|
||||
local_menu->Append(wxWindow::NewControlId(1), _(L("Change Application Language")));
|
||||
local_menu->Bind(wxEVT_MENU, [event_language_change](wxEvent&){
|
||||
wxArrayString names;
|
||||
wxArrayLong identifiers;
|
||||
get_installed_languages(names, identifiers);
|
||||
if (select_language(names, identifiers)){
|
||||
save_language();
|
||||
show_info(g_wxTabPanel, "Application will be restarted", "Attention!");
|
||||
show_info(g_wxTabPanel, _(L("Application will be restarted")), _(L("Attention!")));
|
||||
if (event_language_change > 0) {
|
||||
wxCommandEvent event(event_language_change);
|
||||
g_wxApp->ProcessEvent(event);
|
||||
|
@ -336,15 +340,21 @@ void add_debug_menu(wxMenuBar *menu, int event_language_change)
|
|||
//#endif
|
||||
}
|
||||
|
||||
void create_preset_tabs(PresetBundle *preset_bundle, AppConfig *app_config,
|
||||
void open_preferences_dialog(int event_preferences)
|
||||
{
|
||||
auto dlg = new PreferencesDialog(g_wxMainFrame, event_preferences);
|
||||
dlg->ShowModal();
|
||||
}
|
||||
|
||||
void create_preset_tabs(PresetBundle *preset_bundle,
|
||||
bool no_controller, bool is_disabled_button_browse, bool is_user_agent,
|
||||
int event_value_change, int event_presets_changed,
|
||||
int event_button_browse, int event_button_test)
|
||||
{
|
||||
add_created_tab(new TabPrint (g_wxTabPanel, no_controller), preset_bundle, app_config);
|
||||
add_created_tab(new TabFilament (g_wxTabPanel, no_controller), preset_bundle, app_config);
|
||||
add_created_tab(new TabPrint (g_wxTabPanel, no_controller), preset_bundle);
|
||||
add_created_tab(new TabFilament (g_wxTabPanel, no_controller), preset_bundle);
|
||||
add_created_tab(new TabPrinter (g_wxTabPanel, no_controller, is_disabled_button_browse, is_user_agent),
|
||||
preset_bundle, app_config);
|
||||
preset_bundle);
|
||||
for (size_t i = 0; i < g_wxTabPanel->GetPageCount(); ++ i) {
|
||||
Tab *tab = dynamic_cast<Tab*>(g_wxTabPanel->GetPage(i));
|
||||
if (! tab)
|
||||
|
@ -378,8 +388,14 @@ void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, b
|
|||
try{
|
||||
switch (config.def()->get(opt_key)->type){
|
||||
case coFloatOrPercent:{
|
||||
const auto &val = *config.option<ConfigOptionFloatOrPercent>(opt_key);
|
||||
config.set_key_value(opt_key, new ConfigOptionFloatOrPercent(boost::any_cast<double>(value), val.percent));
|
||||
std::string str = boost::any_cast<std::string>(value);
|
||||
bool percent = false;
|
||||
if (str.back() == '%'){
|
||||
str.pop_back();
|
||||
percent = true;
|
||||
}
|
||||
double val = stod(str);
|
||||
config.set_key_value(opt_key, new ConfigOptionFloatOrPercent(val, percent));
|
||||
break;}
|
||||
case coPercent:
|
||||
config.set_key_value(opt_key, new ConfigOptionPercent(boost::any_cast<double>(value)));
|
||||
|
@ -455,9 +471,9 @@ void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, b
|
|||
}
|
||||
}
|
||||
|
||||
void add_created_tab(Tab* panel, PresetBundle *preset_bundle, AppConfig *app_config)
|
||||
void add_created_tab(Tab* panel, PresetBundle *preset_bundle)
|
||||
{
|
||||
panel->m_show_btn_incompatible_presets = app_config->get("show_incompatible_presets").empty();
|
||||
panel->m_show_btn_incompatible_presets = g_AppConfig->get("show_incompatible_presets").empty();
|
||||
panel->create_preset_tab(preset_bundle);
|
||||
|
||||
// Load the currently selected preset into the GUI, update the preset selection box.
|
||||
|
@ -466,15 +482,22 @@ void add_created_tab(Tab* panel, PresetBundle *preset_bundle, AppConfig *app_con
|
|||
}
|
||||
|
||||
void show_error(wxWindow* parent, wxString message){
|
||||
auto msg_wingow = new wxMessageDialog(parent, message, _L("Error"), wxOK | wxICON_ERROR);
|
||||
auto msg_wingow = new wxMessageDialog(parent, message, _(L("Error")), wxOK | wxICON_ERROR);
|
||||
msg_wingow->ShowModal();
|
||||
}
|
||||
|
||||
void show_info(wxWindow* parent, wxString message, wxString title){
|
||||
auto msg_wingow = new wxMessageDialog(parent, message, title.empty() ? _L("Notice") : title, wxOK | wxICON_INFORMATION);
|
||||
auto msg_wingow = new wxMessageDialog(parent, message, title.empty() ? _(L("Notice")) : title, wxOK | wxICON_INFORMATION);
|
||||
msg_wingow->ShowModal();
|
||||
}
|
||||
|
||||
void warning_catcher(wxWindow* parent, wxString message){
|
||||
if (message == _(L("GLUquadricObjPtr | Attempt to free unreferenced scalar")) )
|
||||
return;
|
||||
auto msg = new wxMessageDialog(parent, message, _(L("Warning")), wxOK | wxICON_WARNING);
|
||||
msg->ShowModal();
|
||||
}
|
||||
|
||||
wxApp* get_app(){
|
||||
return g_wxApp;
|
||||
}
|
||||
|
@ -531,4 +554,20 @@ int combochecklist_get_flags(wxComboCtrl* comboCtrl)
|
|||
return flags;
|
||||
}
|
||||
|
||||
AppConfig* get_app_config()
|
||||
{
|
||||
return g_AppConfig;
|
||||
}
|
||||
|
||||
wxString L_str(std::string str)
|
||||
{
|
||||
//! Explicitly specify that the source string is already in UTF-8 encoding
|
||||
return wxGetTranslation(wxString(str.c_str(), wxConvUTF8));
|
||||
}
|
||||
|
||||
wxString from_u8(std::string str)
|
||||
{
|
||||
return wxString::FromUTF8(str.c_str());
|
||||
}
|
||||
|
||||
} }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue