Merge remote-tracking branch 'remotes/origin/vk-bugfixes'

This commit is contained in:
bubnikv 2019-05-10 12:09:39 +02:00
commit 95b8d80a83
3 changed files with 75 additions and 59 deletions

View file

@ -104,6 +104,7 @@ const std::string& shortkey_alt_prefix()
bool config_wizard_startup(bool app_config_exists) bool config_wizard_startup(bool app_config_exists)
{ {
if (!app_config_exists || wxGetApp().preset_bundle->printers.size() <= 1) { if (!app_config_exists || wxGetApp().preset_bundle->printers.size() <= 1) {
wxGetApp().switch_language();
config_wizard(ConfigWizard::RR_DATA_EMPTY); config_wizard(ConfigWizard::RR_DATA_EMPTY);
return true; return true;
} else if (get_app_config()->legacy_datadir()) { } else if (get_app_config()->legacy_datadir()) {

View file

@ -3,6 +3,8 @@
#include "GUI_ObjectManipulation.hpp" #include "GUI_ObjectManipulation.hpp"
#include "I18N.hpp" #include "I18N.hpp"
#include <algorithm>
#include <iterator>
#include <exception> #include <exception>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
@ -21,6 +23,7 @@
#include <wx/sysopt.h> #include <wx/sysopt.h>
#include <wx/msgdlg.h> #include <wx/msgdlg.h>
#include <wx/log.h> #include <wx/log.h>
#include <wx/intl.h>
#include "libslic3r/Utils.hpp" #include "libslic3r/Utils.hpp"
#include "libslic3r/Model.hpp" #include "libslic3r/Model.hpp"
@ -255,7 +258,7 @@ bool GUI_App::on_init_inner()
CallAfter([this] { CallAfter([this] {
if (!config_wizard_startup(app_conf_exists)) { if (!config_wizard_startup(app_conf_exists)) {
// Only notify if there was not wizard so as not to bother too much ... // Only notify if there was no wizard so as not to bother too much ...
preset_updater->slic3r_update_notify(); preset_updater->slic3r_update_notify();
} }
preset_updater->sync(preset_bundle); preset_updater->sync(preset_bundle);
@ -518,35 +521,61 @@ void GUI_App::import_model(wxWindow *parent, wxArrayString& input_files)
dialog.GetPaths(input_files); dialog.GetPaths(input_files);
} }
// select language from the list of installed languages bool GUI_App::switch_language()
bool GUI_App::select_language( wxArrayString & names,
wxArrayLong & identifiers)
{ {
wxCHECK_MSG(names.Count() == identifiers.Count(), false, if (select_language()) {
_(L("Array of language names and identifiers should have the same size."))); save_language();
int init_selection = 0; _3DScene::remove_all_canvases();
long current_language = m_wxLocale ? m_wxLocale->GetLanguage() : wxLANGUAGE_UNKNOWN; recreate_GUI();
for (auto lang : identifiers) { return true;
if (lang == current_language) } else {
break; return false;
++init_selection;
} }
if (init_selection == identifiers.size()) }
init_selection = 0;
long index = wxGetSingleChoiceIndex(_(L("Select the language")), _(L("Language")), // select language from the list of installed languages
names, init_selection); bool GUI_App::select_language()
if (index != -1) {
{ const auto langs = get_installed_languages();
m_wxLocale = new wxLocale; wxArrayString names;
m_wxLocale->Init(identifiers[index]); names.Alloc(langs.size());
int init_selection = -1;
const auto current_language = m_wxLocale ? m_wxLocale->GetLanguage() : wxLocale::GetSystemLanguage();
for (size_t i = 0; i < langs.size(); i++) {
const auto lang = langs[i]->Language;
const bool is_english = lang >= wxLANGUAGE_ENGLISH && lang <= wxLANGUAGE_ENGLISH_ZIMBABWE;
if (lang == current_language || (current_language == wxLANGUAGE_UNKNOWN && is_english)) {
init_selection = i;
}
names.Add(langs[i]->Description);
}
const long index = wxGetSingleChoiceIndex(
_(L("Select the language")),
_(L("Language")), names, init_selection >= 0 ? init_selection : 0);
if (index != -1) {
const wxLanguageInfo *lang = langs[index];
if (lang->Language == current_language) {
// There was no change
return false;
}
m_wxLocale = new wxLocale; // FIXME: leak?
m_wxLocale->Init(lang->Language);
m_wxLocale->AddCatalogLookupPathPrefix(from_u8(localization_dir())); m_wxLocale->AddCatalogLookupPathPrefix(from_u8(localization_dir()));
m_wxLocale->AddCatalog("Slic3rPE"); m_wxLocale->AddCatalog("Slic3rPE");
//FIXME This is a temporary workaround, the correct solution is to switch to "C" locale during file import / export only. //FIXME This is a temporary workaround, the correct solution is to switch to "C" locale during file import / export only.
wxSetlocale(LC_NUMERIC, "C"); wxSetlocale(LC_NUMERIC, "C");
Preset::update_suffix_modified(); Preset::update_suffix_modified();
m_imgui->set_language(m_wxLocale->GetCanonicalName().ToUTF8().data()); m_imgui->set_language(into_u8(lang->CanonicalName));
return true; return true;
} }
return false; return false;
} }
@ -559,21 +588,20 @@ bool GUI_App::load_language()
if (language.IsEmpty()) if (language.IsEmpty())
return false; return false;
wxArrayString names;
wxArrayLong identifiers; const auto langs = get_installed_languages();
get_installed_languages(names, identifiers); for (const wxLanguageInfo *info : langs)
for (size_t i = 0; i < identifiers.Count(); i++)
{ {
if (wxLocale::GetLanguageCanonicalName(identifiers[i]) == language) if (info->CanonicalName == language)
{ {
m_wxLocale = new wxLocale; m_wxLocale = new wxLocale;
m_wxLocale->Init(identifiers[i]); m_wxLocale->Init(info->Language);
m_wxLocale->AddCatalogLookupPathPrefix(from_u8(localization_dir())); m_wxLocale->AddCatalogLookupPathPrefix(from_u8(localization_dir()));
m_wxLocale->AddCatalog("Slic3rPE"); m_wxLocale->AddCatalog("Slic3rPE");
//FIXME This is a temporary workaround, the correct solution is to switch to "C" locale during file import / export only. //FIXME This is a temporary workaround, the correct solution is to switch to "C" locale during file import / export only.
wxSetlocale(LC_NUMERIC, "C"); wxSetlocale(LC_NUMERIC, "C");
Preset::update_suffix_modified(); Preset::update_suffix_modified();
m_imgui->set_language(m_wxLocale->GetCanonicalName().ToUTF8().data()); m_imgui->set_language(into_u8(info->CanonicalName));
return true; return true;
} }
} }
@ -591,36 +619,31 @@ void GUI_App::save_language()
app_config->save(); app_config->save();
} }
// get list of installed languages // Get a list of installed languages
void GUI_App::get_installed_languages(wxArrayString & names, wxArrayLong & identifiers) std::vector<const wxLanguageInfo*> GUI_App::get_installed_languages()
{ {
names.Clear(); std::vector<const wxLanguageInfo*> res;
identifiers.Clear();
wxDir dir(from_u8(localization_dir())); wxDir dir(from_u8(localization_dir()));
wxString filename; wxString filename;
const wxLanguageInfo * langinfo; const wxLanguageInfo * langinfo;
wxString name = wxLocale::GetLanguageName(wxLANGUAGE_DEFAULT); wxString name = wxLocale::GetLanguageName(wxLANGUAGE_DEFAULT);
if (!name.IsEmpty()) if (!name.IsEmpty()) {
{ res.push_back(wxLocale::GetLanguageInfo(wxLANGUAGE_DEFAULT));
names.Add(_(L("Default")));
identifiers.Add(wxLANGUAGE_DEFAULT);
} }
for (bool cont = dir.GetFirst(&filename, wxEmptyString, wxDIR_DIRS);
cont; cont = dir.GetNext(&filename)) for (bool cont = dir.GetFirst(&filename, wxEmptyString, wxDIR_DIRS); cont; cont = dir.GetNext(&filename)) {
{
langinfo = wxLocale::FindLanguageInfo(filename); langinfo = wxLocale::FindLanguageInfo(filename);
if (langinfo != NULL) if (langinfo != NULL) {
{
auto full_file_name = dir.GetName() + wxFileName::GetPathSeparator() + auto full_file_name = dir.GetName() + wxFileName::GetPathSeparator() +
filename + wxFileName::GetPathSeparator() + "Slic3rPE" + wxT(".mo"); filename + wxFileName::GetPathSeparator() + "Slic3rPE" + wxT(".mo");
if (wxFileExists(full_file_name)) if (wxFileExists(full_file_name)) {
{ res.push_back(langinfo);
names.Add(langinfo->Description);
identifiers.Add(langinfo->Language);
} }
} }
} }
return res;
} }
Tab* GUI_App::get_tab(Preset::Type type) Tab* GUI_App::get_tab(Preset::Type type)
@ -757,14 +780,7 @@ void GUI_App::add_config_menu(wxMenuBar *menu)
if ( dialog.ShowModal() == wxID_CANCEL) if ( dialog.ShowModal() == wxID_CANCEL)
return; return;
wxArrayString names; switch_language();
wxArrayLong identifiers;
get_installed_languages(names, identifiers);
if (select_language(names, identifiers)) {
save_language();
_3DScene::remove_all_canvases();// remove all canvas before recreate GUI
recreate_GUI();
}
break; break;
} }
case ConfigMenuFlashFirmware: case ConfigMenuFlashFirmware:

View file

@ -19,6 +19,7 @@ class wxMenuItem;
class wxMenuBar; class wxMenuBar;
class wxTopLevelWindow; class wxTopLevelWindow;
class wxNotebook; class wxNotebook;
class wxLanguageInfo;
namespace Slic3r { namespace Slic3r {
class AppConfig; class AppConfig;
@ -119,18 +120,16 @@ public:
void keyboard_shortcuts(); void keyboard_shortcuts();
void load_project(wxWindow *parent, wxString& input_file); void load_project(wxWindow *parent, wxString& input_file);
void import_model(wxWindow *parent, wxArrayString& input_files); void import_model(wxWindow *parent, wxArrayString& input_files);
static bool catch_error(std::function<void()> cb, static bool catch_error(std::function<void()> cb, const std::string& err);
// wxMessageDialog* message_dialog,
const std::string& err);
// void notify(/*message*/);
void persist_window_geometry(wxTopLevelWindow *window, bool default_maximized = false); void persist_window_geometry(wxTopLevelWindow *window, bool default_maximized = false);
void update_ui_from_settings(); void update_ui_from_settings();
bool select_language(wxArrayString & names, wxArrayLong & identifiers); bool switch_language();
bool select_language();
bool load_language(); bool load_language();
void save_language(); void save_language();
void get_installed_languages(wxArrayString & names, wxArrayLong & identifiers); std::vector<const wxLanguageInfo*> get_installed_languages();
Tab* get_tab(Preset::Type type); Tab* get_tab(Preset::Type type);
ConfigOptionMode get_mode(); ConfigOptionMode get_mode();