diff options
Diffstat (limited to 'src/slic3r/GUI/MainFrame.cpp')
-rw-r--r-- | src/slic3r/GUI/MainFrame.cpp | 77 |
1 files changed, 67 insertions, 10 deletions
diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 941841f6f..3165b625b 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -595,7 +595,7 @@ void MainFrame::init_tabpanel() m_last_selected_tab = m_tabpanel->GetSelection(); } else - select_tab(0); // select Plater + select_tab(size_t(0)); // select Plater }); m_plater = new Plater(this, this); @@ -650,6 +650,24 @@ void MainFrame::add_created_tab(Tab* panel) m_tabpanel->AddPage(panel, panel->title()); } +bool MainFrame::is_active_and_shown_tab(Tab* tab) +{ + if (!this) + return false; + int page_id = m_tabpanel->FindPage(tab); + + if (m_tabpanel->GetSelection() != page_id) + return false; + + if (m_layout == ESettingsLayout::Dlg) + return m_settings_dialog.IsShown(); + + if (m_layout == ESettingsLayout::New) + return m_main_sizer->IsShown(m_tabpanel); + + return true; +} + bool MainFrame::can_start_new_project() const { return (m_plater != nullptr) && !m_plater->model().objects.empty(); @@ -1167,7 +1185,7 @@ void MainFrame::init_menubar() { if (m_plater) { append_menu_item(windowMenu, wxID_HIGHEST + 1, _L("&Plater Tab") + "\tCtrl+1", _L("Show the plater"), - [this](wxCommandEvent&) { select_tab(0); }, "plater", nullptr, + [this](wxCommandEvent&) { select_tab(size_t(0)); }, "plater", nullptr, [this]() {return true; }, this); windowMenu->AppendSeparator(); } @@ -1723,9 +1741,35 @@ void MainFrame::load_config(const DynamicPrintConfig& config) #endif } +void MainFrame::select_tab(Tab* tab) +{ + if (!tab) + return; + int page_idx = m_tabpanel->FindPage(tab); + if (page_idx != wxNOT_FOUND && m_layout == ESettingsLayout::Dlg) + page_idx++; + select_tab(size_t(page_idx)); +} + void MainFrame::select_tab(size_t tab/* = size_t(-1)*/) { bool tabpanel_was_hidden = false; + + // Controls on page are created on active page of active tab now. + // We should select/activate tab before its showing to avoid an UI-flickering + auto select = [this, tab](bool was_hidden) { + // when tab == -1, it means we should show the last selected tab + size_t new_selection = tab == (size_t)(-1) ? m_last_selected_tab : (m_layout == ESettingsLayout::Dlg && tab != 0) ? tab - 1 : tab; + + if (m_tabpanel->GetSelection() != new_selection) + m_tabpanel->SetSelection(new_selection); + else if (was_hidden) { + Tab* cur_tab = dynamic_cast<Tab*>(m_tabpanel->GetPage(new_selection)); + if (cur_tab) + cur_tab->OnActivate(); + } + }; + if (m_layout == ESettingsLayout::Dlg) { if (tab==0) { if (m_settings_dialog.IsShown()) @@ -1739,14 +1783,20 @@ void MainFrame::select_tab(size_t tab/* = size_t(-1)*/) #ifdef __WXOSX__ // Don't call SetFont under OSX to avoid name cutting in ObjectList if (m_settings_dialog.IsShown()) m_settings_dialog.Hide(); - + else + tabpanel_was_hidden = true; + + select(tabpanel_was_hidden); m_tabpanel->Show(); m_settings_dialog.Show(); #else - if (m_settings_dialog.IsShown()) + if (m_settings_dialog.IsShown()) { + select(false); m_settings_dialog.SetFocus(); + } else { tabpanel_was_hidden = true; + select(tabpanel_was_hidden); m_tabpanel->Show(); m_settings_dialog.Show(); } @@ -1755,6 +1805,7 @@ void MainFrame::select_tab(size_t tab/* = size_t(-1)*/) else if (m_layout == ESettingsLayout::New) { m_main_sizer->Show(m_plater, tab == 0); tabpanel_was_hidden = !m_main_sizer->IsShown(m_tabpanel); + select(tabpanel_was_hidden); m_main_sizer->Show(m_tabpanel, tab != 0); // plater should be focused for correct navigation inside search window @@ -1762,17 +1813,23 @@ void MainFrame::select_tab(size_t tab/* = size_t(-1)*/) m_plater->SetFocus(); Layout(); } + else + select(false); // When we run application in ESettingsLayout::New or ESettingsLayout::Dlg mode, tabpanel is hidden from the very beginning // and as a result Tab::update_changed_tree_ui() function couldn't update m_is_nonsys_values values, // which are used for update TreeCtrl and "revert_buttons". // So, force the call of this function for Tabs, if tab panel was hidden if (tabpanel_was_hidden) - for (auto tab : wxGetApp().tabs_list) - tab->update_changed_tree_ui(); - - // when tab == -1, it means we should show the last selected tab - m_tabpanel->SetSelection(tab == (size_t)(-1) ? m_last_selected_tab : (m_layout == ESettingsLayout::Dlg && tab != 0) ? tab - 1 : tab); + for (auto cur_tab : wxGetApp().tabs_list) + cur_tab->update_changed_tree_ui(); + + //// when tab == -1, it means we should show the last selected tab + //size_t new_selection = tab == (size_t)(-1) ? m_last_selected_tab : (m_layout == ESettingsLayout::Dlg && tab != 0) ? tab - 1 : tab; + //if (m_tabpanel->GetSelection() != new_selection) + // m_tabpanel->SetSelection(new_selection); + //if (tabpanel_was_hidden) + // static_cast<Tab*>(m_tabpanel->GetPage(new_selection))->OnActivate(); } // Set a camera direction, zoom to all objects. @@ -1919,7 +1976,7 @@ SettingsDialog::SettingsDialog(MainFrame* mainframe) auto key_up_handker = [this](wxKeyEvent& evt) { if ((evt.GetModifiers() & wxMOD_CONTROL) != 0) { switch (evt.GetKeyCode()) { - case '1': { m_main_frame->select_tab(0); break; } + case '1': { m_main_frame->select_tab(size_t(0)); break; } case '2': { m_main_frame->select_tab(1); break; } case '3': { m_main_frame->select_tab(2); break; } case '4': { m_main_frame->select_tab(3); break; } |