mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-21 15:51:10 -06:00
Implemented Application recreate after changing of language.
* Implementation of C++ to Perl callbacks from menu item Localization. * Added global variable g_tabs_list to control existing Tabs.
This commit is contained in:
parent
143f9d7d84
commit
abcfd5bad9
8 changed files with 115 additions and 30 deletions
|
@ -166,6 +166,8 @@ wxApp *g_wxApp = nullptr;
|
|||
wxFrame *g_wxMainFrame = nullptr;
|
||||
wxNotebook *g_wxTabPanel = nullptr;
|
||||
|
||||
std::vector<Tab *> g_tabs_list;
|
||||
|
||||
wxLocale* m_Locale;
|
||||
std::string m_local_dir;
|
||||
|
||||
|
@ -184,6 +186,26 @@ void set_tab_panel(wxNotebook *tab_panel)
|
|||
g_wxTabPanel = tab_panel;
|
||||
}
|
||||
|
||||
std::vector<Tab *>& get_tabs_list()
|
||||
{
|
||||
return g_tabs_list;
|
||||
}
|
||||
|
||||
bool checked_tab(Tab* tab)
|
||||
{
|
||||
bool ret = true;
|
||||
if (find(g_tabs_list.begin(), g_tabs_list.end(), tab) == g_tabs_list.end())
|
||||
ret = false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void delete_tab_from_list(Tab* tab)
|
||||
{
|
||||
std::vector<Tab *>::iterator itr = find(g_tabs_list.begin(), g_tabs_list.end(), tab);
|
||||
if (itr != g_tabs_list.end())
|
||||
g_tabs_list.erase(itr);
|
||||
}
|
||||
|
||||
bool select_language(wxArrayString & names,
|
||||
wxArrayLong & identifiers)
|
||||
{
|
||||
|
@ -214,10 +236,10 @@ bool load_language()
|
|||
long language;
|
||||
// if (!config.Read(wxT("wxTranslation_Language"),
|
||||
// &language, wxLANGUAGE_UNKNOWN))
|
||||
// {
|
||||
language = wxLANGUAGE_UKRAINIAN;// wxLANGUAGE_UNKNOWN;
|
||||
// }
|
||||
// if (language == wxLANGUAGE_UNKNOWN) return false;
|
||||
{
|
||||
language = wxLANGUAGE_ENGLISH_US;// wxLANGUAGE_UKRAINIAN;// wxLANGUAGE_UNKNOWN;
|
||||
}
|
||||
if (language == wxLANGUAGE_UNKNOWN) return false;
|
||||
wxArrayString names;
|
||||
wxArrayLong identifiers;
|
||||
get_installed_languages(names, identifiers);
|
||||
|
@ -287,16 +309,22 @@ void get_installed_languages(wxArrayString & names,
|
|||
}
|
||||
}
|
||||
|
||||
void add_debug_menu(wxMenuBar *menu)
|
||||
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->Bind(wxEVT_MENU, [](wxEvent&){
|
||||
local_menu->Bind(wxEVT_MENU, [event_language_change](wxEvent&){
|
||||
wxArrayString names;
|
||||
wxArrayLong identifiers;
|
||||
get_installed_languages(names, identifiers);
|
||||
select_language(names, identifiers);
|
||||
if (select_language(names, identifiers)){
|
||||
show_info(g_wxTabPanel, "Application will be restarted", "Attention!");
|
||||
if (event_language_change > 0) {
|
||||
wxCommandEvent event(event_language_change);
|
||||
g_wxApp->ProcessEvent(event);
|
||||
}
|
||||
}
|
||||
});
|
||||
menu->Append(local_menu, _T("&Localization"));
|
||||
//#endif
|
||||
|
|
|
@ -58,7 +58,7 @@ void set_wxapp(wxApp *app);
|
|||
void set_main_frame(wxFrame *main_frame);
|
||||
void set_tab_panel(wxNotebook *tab_panel);
|
||||
|
||||
void add_debug_menu(wxMenuBar *menu);
|
||||
void add_debug_menu(wxMenuBar *menu, int event_language_change);
|
||||
// Create a new preset tab (print, filament and printer),
|
||||
void create_preset_tabs(PresetBundle *preset_bundle, AppConfig *app_config,
|
||||
bool no_controller, bool is_disabled_button_browse, bool is_user_agent,
|
||||
|
@ -83,6 +83,10 @@ void get_installed_languages(wxArrayString & names, wxArrayLong & identifiers);
|
|||
// select language from the list of installed languages
|
||||
bool select_language(wxArrayString & names, wxArrayLong & identifiers);
|
||||
|
||||
std::vector<Tab *>& get_tabs_list();
|
||||
bool checked_tab(Tab* tab);
|
||||
void delete_tab_from_list(Tab* tab);
|
||||
|
||||
} }
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1238,7 +1238,7 @@ void TabPrinter::build_extruder_pages(){
|
|||
// # rebuild page list
|
||||
PageShp page_note = m_pages.back();
|
||||
m_pages.pop_back();
|
||||
while (m_pages.back()->title().find("Extruder") != std::string::npos)
|
||||
while (m_pages.back()->title().find(_L("Extruder")) != std::string::npos)
|
||||
m_pages.pop_back();
|
||||
for (auto page_extruder : m_extruder_pages)
|
||||
m_pages.push_back(page_extruder);
|
||||
|
@ -1361,6 +1361,9 @@ void Tab::load_current_preset()
|
|||
// preset dirty again
|
||||
// (not sure this is true anymore now that update_dirty is idempotent)
|
||||
wxTheApp->CallAfter([this]{
|
||||
// checking out if this Tab exists till this moment
|
||||
if (!checked_tab(this))
|
||||
return;
|
||||
update_tab_ui();
|
||||
on_presets_changed();
|
||||
});
|
||||
|
|
|
@ -112,11 +112,12 @@ public:
|
|||
|
||||
public:
|
||||
Tab() {}
|
||||
Tab(wxNotebook* parent, const char *title, const char* name, bool no_controller) :
|
||||
Tab(wxNotebook* parent, wxString title, const char* name, bool no_controller) :
|
||||
m_parent(parent), m_title(title), m_name(name), m_no_controller(no_controller) {
|
||||
Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL);
|
||||
get_tabs_list().push_back(this);
|
||||
}
|
||||
~Tab(){}
|
||||
~Tab() { delete_tab_from_list(this); }
|
||||
|
||||
wxWindow* parent() const { return m_parent; }
|
||||
wxString title() const { return m_title; }
|
||||
|
@ -160,7 +161,10 @@ public:
|
|||
wxSizer* description_line_widget(wxWindow* parent, ogStaticText** StaticText);
|
||||
bool current_preset_is_dirty();
|
||||
DynamicPrintConfig* get_config() { return m_config; }
|
||||
PresetCollection* get_presets() { return m_presets; }
|
||||
PresetCollection* get_presets()
|
||||
{
|
||||
return m_presets;
|
||||
}
|
||||
std::vector<std::string> get_dependent_tabs() { return m_reload_dependent_tabs; }
|
||||
|
||||
void on_value_change(std::string opt_key, boost::any value);
|
||||
|
|
|
@ -13,7 +13,7 @@ bool TabIface::current_preset_is_dirty() { return m_tab->current_preset_is_d
|
|||
void TabIface::OnActivate() { return m_tab->OnActivate();}
|
||||
std::string TabIface::title() { return m_tab->title().ToStdString();}
|
||||
DynamicPrintConfig* TabIface::get_config() { return m_tab->get_config(); }
|
||||
PresetCollection* TabIface::get_presets() { return m_tab->get_presets(); }
|
||||
PresetCollection* TabIface::get_presets() { return m_tab!=nullptr ? m_tab->get_presets() : nullptr; }
|
||||
std::vector<std::string> TabIface::get_dependent_tabs() { return m_tab->get_dependent_tabs(); }
|
||||
|
||||
}; // namespace Slic3r
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue