mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-07-30 23:02:02 +08:00
TopBar: Search improvements to respect to the ESettingsLayout::Dlg
This commit is contained in:
parent
9beef5e847
commit
0848fecb02
@ -1112,11 +1112,16 @@ void GUI_App::jump_to_option(const std::string& composite_key)
|
||||
}
|
||||
}
|
||||
|
||||
void GUI_App::update_search_lines()
|
||||
{
|
||||
mainframe->update_search_lines(m_searcher->search_string());
|
||||
}
|
||||
|
||||
void GUI_App::show_search_dialog()
|
||||
{
|
||||
// To avoid endless loop caused by mutual lose focuses from serch_input and search_dialog
|
||||
// invoke killFocus for serch_input by set focus to tab_panel
|
||||
GUI::wxGetApp().tab_panel()->SetFocus();
|
||||
m_searcher->set_focus_to_parent();
|
||||
|
||||
check_and_update_searcher(get_mode());
|
||||
m_searcher->show_dialog();
|
||||
|
@ -203,6 +203,7 @@ public:
|
||||
void jump_to_option(const std::string& opt_key, Preset::Type type, const std::wstring& category);
|
||||
// jump to option which is represented by composite key : "opt_key;tab_name"
|
||||
void jump_to_option(const std::string& composite_key);
|
||||
void update_search_lines();
|
||||
void show_search_dialog();
|
||||
|
||||
// To be called after the GUI is fully built up.
|
||||
|
@ -286,17 +286,18 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S
|
||||
});
|
||||
#endif //WIN32
|
||||
|
||||
Bind(wxEVT_MOVE, [](wxMoveEvent& event) {
|
||||
// OSX specific issue:
|
||||
// When we move application between Retina and non-Retina displays, The legend on a canvas doesn't redraw
|
||||
// So, redraw explicitly canvas, when application is moved
|
||||
//FIXME maybe this is useful for __WXGTK3__ as well?
|
||||
#if __APPLE__
|
||||
Bind(wxEVT_MOVE, [](wxMoveEvent& event) {
|
||||
wxGetApp().plater()->get_current_canvas3D()->set_as_dirty();
|
||||
wxGetApp().plater()->get_current_canvas3D()->request_extra_frame();
|
||||
#endif
|
||||
wxGetApp().searcher().update_dialog_position();
|
||||
event.Skip();
|
||||
});
|
||||
#endif
|
||||
|
||||
wxGetApp().persist_window_geometry(this, true);
|
||||
wxGetApp().persist_window_geometry(&m_settings_dialog, true);
|
||||
@ -1947,6 +1948,13 @@ void MainFrame::load_config(const DynamicPrintConfig& config)
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainFrame::update_search_lines(const std::string search_line)
|
||||
{
|
||||
wxString search = from_u8(search_line);
|
||||
m_tabpanel ->UpdateSearch(search);
|
||||
m_tmp_top_bar->UpdateSearch(search);
|
||||
}
|
||||
|
||||
void MainFrame::select_tab(Tab* tab)
|
||||
{
|
||||
if (!tab)
|
||||
@ -2174,6 +2182,8 @@ SettingsDialog::SettingsDialog(MainFrame* mainframe)
|
||||
default:break;
|
||||
}
|
||||
}
|
||||
|
||||
evt.Skip();
|
||||
};
|
||||
|
||||
if (evt.IsShown()) {
|
||||
@ -2205,6 +2215,11 @@ SettingsDialog::SettingsDialog(MainFrame* mainframe)
|
||||
SetSize(GetMinSize());
|
||||
#endif
|
||||
Layout();
|
||||
|
||||
Bind(wxEVT_MOVE, [](wxMoveEvent& event) {
|
||||
wxGetApp().searcher().update_dialog_position();
|
||||
event.Skip();
|
||||
});
|
||||
}
|
||||
|
||||
void SettingsDialog::on_dpi_changed(const wxRect& suggested_rect)
|
||||
|
@ -198,6 +198,7 @@ public:
|
||||
void export_configbundle(bool export_physical_printers = false);
|
||||
void load_configbundle(wxString file = wxEmptyString);
|
||||
void load_config(const DynamicPrintConfig& config);
|
||||
void update_search_lines(const std::string search_line);
|
||||
// Select tab in m_tabpanel
|
||||
// When tab == -1, will be selected last selected tab
|
||||
void select_tab(Tab* tab);
|
||||
|
@ -441,11 +441,25 @@ static bool has_focus(wxWindow* win)
|
||||
void OptionsSearcher::update_dialog_position()
|
||||
{
|
||||
if (search_dialog) {
|
||||
search_dialog->CenterOnParent(wxHORIZONTAL);
|
||||
search_dialog->SetPosition({ search_dialog->GetPosition().x, search_input->GetScreenPosition().y + search_input->GetSize().y });
|
||||
wxPoint old_pos = search_dialog->GetPosition();
|
||||
wxPoint pos = search_input->GetScreenPosition() + wxPoint(-5, search_input->GetSize().y);
|
||||
if (old_pos != pos)
|
||||
search_dialog->SetPosition(pos);
|
||||
}
|
||||
}
|
||||
|
||||
void OptionsSearcher::check_and_hide_dialog()
|
||||
{
|
||||
if (search_dialog && search_dialog->IsShown() && !has_focus(search_dialog))
|
||||
show_dialog(false);
|
||||
}
|
||||
|
||||
void OptionsSearcher::set_focus_to_parent()
|
||||
{
|
||||
if (search_input)
|
||||
search_input->GetParent()->SetFocus();
|
||||
}
|
||||
|
||||
void OptionsSearcher::show_dialog(bool show /*= true*/)
|
||||
{
|
||||
if (search_dialog && !show) {
|
||||
@ -455,7 +469,6 @@ void OptionsSearcher::show_dialog(bool show /*= true*/)
|
||||
|
||||
if (!search_dialog) {
|
||||
search_dialog = new SearchDialog(this, search_input);
|
||||
update_dialog_position();
|
||||
|
||||
search_dialog->Bind(wxEVT_KILL_FOCUS, [this](wxFocusEvent& e)
|
||||
{
|
||||
@ -463,14 +476,8 @@ void OptionsSearcher::show_dialog(bool show /*= true*/)
|
||||
show_dialog(false);
|
||||
e.Skip();
|
||||
});
|
||||
|
||||
search_input->Bind(wxEVT_KILL_FOCUS, [this](wxFocusEvent& e)
|
||||
{
|
||||
e.Skip();
|
||||
if (search_dialog->IsShown() && !has_focus(search_dialog))
|
||||
show_dialog(false);
|
||||
});
|
||||
}
|
||||
update_dialog_position();
|
||||
|
||||
search_string();
|
||||
search_input->SetSelection(-1,-1);
|
||||
@ -492,55 +499,33 @@ void OptionsSearcher::dlg_msw_rescale()
|
||||
search_dialog->msw_rescale();
|
||||
}
|
||||
|
||||
void OptionsSearcher::edit_search_input()
|
||||
{
|
||||
if (!search_input)
|
||||
return;
|
||||
|
||||
if (search_dialog) {
|
||||
search_dialog->input_text(search_input->GetValue());
|
||||
if (!search_dialog->IsShown())
|
||||
search_dialog->Popup();
|
||||
}
|
||||
else
|
||||
GUI::wxGetApp().show_search_dialog();
|
||||
}
|
||||
|
||||
void OptionsSearcher::process_key_down_from_input(wxKeyEvent& e)
|
||||
{
|
||||
int key = e.GetKeyCode();
|
||||
if (key == WXK_ESCAPE)
|
||||
search_dialog->EndModal(wxID_CLOSE);
|
||||
else if (search_dialog && (key == WXK_UP || key == WXK_DOWN || key == WXK_NUMPAD_ENTER || key == WXK_RETURN))
|
||||
search_dialog->KeyDown(e);
|
||||
}
|
||||
|
||||
void OptionsSearcher::set_search_input(TextInput* input_ctrl)
|
||||
{
|
||||
search_input = input_ctrl;
|
||||
|
||||
search_input->Bind(wxEVT_TEXT, [this](wxEvent& e)
|
||||
{
|
||||
if (search_dialog) {
|
||||
search_dialog->input_text(search_input->GetValue());
|
||||
if (!search_dialog->IsShown())
|
||||
search_dialog->Popup();
|
||||
}
|
||||
else
|
||||
GUI::wxGetApp().show_search_dialog();
|
||||
});
|
||||
|
||||
wxTextCtrl* ctrl = search_input->GetTextCtrl();
|
||||
ctrl->SetToolTip(GUI::format_wxstr(_L("Search in settings [%1%]"), "Ctrl+F"));
|
||||
|
||||
ctrl->Bind(wxEVT_KEY_DOWN, [this](wxKeyEvent& e)
|
||||
{
|
||||
int key = e.GetKeyCode();
|
||||
if (key == WXK_TAB)
|
||||
search_input->Navigate(e.ShiftDown() ? wxNavigationKeyEvent::IsBackward : wxNavigationKeyEvent::IsForward);
|
||||
else if (key == WXK_ESCAPE)
|
||||
search_dialog->EndModal(wxID_CLOSE);
|
||||
else if (search_dialog && (key == WXK_UP || key == WXK_DOWN || key == WXK_NUMPAD_ENTER || key == WXK_RETURN))
|
||||
search_dialog->KeyDown(e);
|
||||
e.Skip();
|
||||
});
|
||||
|
||||
ctrl->Bind(wxEVT_LEFT_UP, [this](wxMouseEvent& event)
|
||||
{
|
||||
if (search_input->GetValue() == default_string)
|
||||
search_input->SetValue("");
|
||||
event.Skip();
|
||||
});
|
||||
|
||||
ctrl->Bind(wxEVT_LEFT_DOWN, [](wxMouseEvent& event) {
|
||||
GUI::wxGetApp().show_search_dialog();
|
||||
event.Skip();
|
||||
});
|
||||
|
||||
search_input->Bind(wxEVT_MOVE, [this](wxMoveEvent& event)
|
||||
{
|
||||
event.Skip();
|
||||
update_dialog_position();
|
||||
});
|
||||
|
||||
search_input->SetOnDropDownIcon([](){ GUI::wxGetApp().show_search_dialog(); });
|
||||
update_dialog_position();
|
||||
}
|
||||
|
||||
void OptionsSearcher::add_key(const std::string& opt_key, Preset::Type type, const wxString& group, const wxString& category)
|
||||
@ -707,7 +692,7 @@ void SearchDialog::OnKeyDown(wxKeyEvent& event)
|
||||
if (key == WXK_UP || key == WXK_DOWN)
|
||||
{
|
||||
// So, for the next correct navigation, set focus on the search_list
|
||||
search_list->SetFocus();
|
||||
// search_list->SetFocus(); // #ys_delete_after_test -> Looks like no need anymore
|
||||
|
||||
auto item = search_list->GetSelection();
|
||||
|
||||
|
@ -148,6 +148,10 @@ public:
|
||||
void sort_options_by_label() { sort_options(); }
|
||||
|
||||
void update_dialog_position();
|
||||
void edit_search_input();
|
||||
void process_key_down_from_input(wxKeyEvent& e);
|
||||
void check_and_hide_dialog();
|
||||
void set_focus_to_parent();
|
||||
void show_dialog(bool show = true);
|
||||
void dlg_sys_color_changed();
|
||||
void dlg_msw_rescale();
|
||||
|
@ -259,7 +259,63 @@ void TopBarItemsCtrl::CreateSearch()
|
||||
m_search = new ::TextInput(this, wxGetApp().searcher().default_string, "", "search", wxDefaultPosition, wxSize(2 * em_unit(this), -1), wxTE_PROCESS_ENTER);
|
||||
m_search->SetMaxSize(wxSize(42*em_unit(this), -1));
|
||||
wxGetApp().UpdateDarkUI(m_search);
|
||||
wxGetApp().searcher().set_search_input(m_search);
|
||||
|
||||
m_search->Bind(wxEVT_TEXT, [](wxEvent& e)
|
||||
{
|
||||
wxGetApp().searcher().edit_search_input();
|
||||
wxGetApp().update_search_lines();
|
||||
});
|
||||
|
||||
m_search->Bind(wxEVT_MOVE, [](wxMoveEvent& event)
|
||||
{
|
||||
event.Skip();
|
||||
wxGetApp().searcher().update_dialog_position();
|
||||
});
|
||||
|
||||
m_search->SetOnDropDownIcon([this]()
|
||||
{
|
||||
wxGetApp().searcher().set_search_input(m_search);
|
||||
wxGetApp().show_search_dialog();
|
||||
});
|
||||
|
||||
m_search->Bind(wxEVT_KILL_FOCUS, [](wxFocusEvent& e)
|
||||
{
|
||||
e.Skip();
|
||||
wxGetApp().searcher().check_and_hide_dialog();
|
||||
});
|
||||
|
||||
wxTextCtrl* ctrl = m_search->GetTextCtrl();
|
||||
ctrl->SetToolTip(format_wxstr(_L("Search in settings [%1%]"), "Ctrl+F"));
|
||||
|
||||
ctrl->Bind(wxEVT_KEY_DOWN, [this](wxKeyEvent& e)
|
||||
{
|
||||
wxGetApp().searcher().set_search_input(m_search);
|
||||
if (e.GetKeyCode() == WXK_TAB)
|
||||
m_search->Navigate(e.ShiftDown() ? wxNavigationKeyEvent::IsBackward : wxNavigationKeyEvent::IsForward);
|
||||
else
|
||||
wxGetApp().searcher().process_key_down_from_input(e);
|
||||
e.Skip();
|
||||
});
|
||||
|
||||
ctrl->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& event)
|
||||
{
|
||||
wxGetApp().searcher().set_search_input(m_search);
|
||||
wxGetApp().show_search_dialog();
|
||||
event.Skip();
|
||||
});
|
||||
|
||||
ctrl->Bind(wxEVT_LEFT_UP, [this](wxMouseEvent& event)
|
||||
{
|
||||
if (m_search->GetValue() == wxGetApp().searcher().default_string)
|
||||
m_search->SetValue("");
|
||||
event.Skip();
|
||||
});
|
||||
}
|
||||
|
||||
void TopBarItemsCtrl::UpdateSearch(const wxString& search)
|
||||
{
|
||||
if (search != m_search->GetValue())
|
||||
m_search->SetValue(search);
|
||||
}
|
||||
|
||||
void TopBarItemsCtrl::update_margins()
|
||||
@ -317,6 +373,8 @@ TopBarItemsCtrl::TopBarItemsCtrl(wxWindow *parent, TopBarMenus* menus/* = nullpt
|
||||
left_sizer->Add(m_buttons_sizer, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, m_btn_margin);
|
||||
|
||||
CreateSearch();
|
||||
if (!is_main)
|
||||
wxGetApp().searcher().set_search_input(m_search);
|
||||
|
||||
wxBoxSizer* search_sizer = new wxBoxSizer(wxVERTICAL);
|
||||
search_sizer->Add(m_search, 1, wxEXPAND | wxALIGN_RIGHT);
|
||||
@ -495,6 +553,7 @@ void TopBarItemsCtrl::ShowFull()
|
||||
m_account_btn->set_selected(true);
|
||||
m_menus->Popup(this, &m_menus->account, m_account_btn->get_popup_pos());
|
||||
});
|
||||
m_sizer->SetItemMinSize(1, wxSize(42 * em_unit(this), -1));
|
||||
}
|
||||
|
||||
void TopBarItemsCtrl::ShowJustMode()
|
||||
@ -505,6 +564,7 @@ void TopBarItemsCtrl::ShowJustMode()
|
||||
m_settings_btn->Hide();
|
||||
m_account_btn->Hide();
|
||||
m_menus->set_cb_on_user_item(nullptr);
|
||||
m_sizer->SetItemMinSize(1, wxSize(20, -1));
|
||||
}
|
||||
|
||||
void TopBarItemsCtrl::SetSettingsButtonTooltip(const wxString& tooltip)
|
||||
|
@ -86,6 +86,7 @@ public:
|
||||
void ShowFull();
|
||||
void ShowJustMode();
|
||||
void SetSettingsButtonTooltip(const wxString& tooltip);
|
||||
void UpdateSearch(const wxString& search);
|
||||
|
||||
wxWindow* GetSearchCtrl() { return m_search->GetTextCtrl(); }
|
||||
|
||||
@ -440,6 +441,10 @@ public:
|
||||
GetTopBarItemsCtrl()->SetSettingsButtonTooltip(tooltip);
|
||||
}
|
||||
|
||||
void UpdateSearch(const wxString& search) {
|
||||
GetTopBarItemsCtrl()->UpdateSearch(search);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void UpdateSelectedPage(size_t WXUNUSED(newsel)) override
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user