Search: 1.Select first item in the search list by default

2. Show "Search in English" checkbox only, when Slicer is localized
3. Suppress search window hiding when leave the 3D-scene
This commit is contained in:
YuSanka 2020-05-07 18:39:38 +02:00
parent 2daa12d467
commit 9189758992
7 changed files with 29 additions and 22 deletions

View file

@ -3567,7 +3567,6 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
else if (evt.Leaving()) else if (evt.Leaving())
{ {
_deactivate_undo_redo_toolbar_items(); _deactivate_undo_redo_toolbar_items();
_deactivate_search_toolbar_item();
// to remove hover on objects when the mouse goes out of this canvas // to remove hover on objects when the mouse goes out of this canvas
m_mouse.position = Vec2d(-1.0, -1.0); m_mouse.position = Vec2d(-1.0, -1.0);
@ -4386,7 +4385,6 @@ bool GLCanvas3D::_render_search_list(float pos_x) const
int selected = -1; int selected = -1;
bool edited = false; bool edited = false;
bool check_changed = false;
float em = static_cast<float>(wxGetApp().em_unit()); float em = static_cast<float>(wxGetApp().em_unit());
#if ENABLE_RETINA_GL #if ENABLE_RETINA_GL
em *= m_retina_helper->get_scale_factor(); em *= m_retina_helper->get_scale_factor();
@ -4400,7 +4398,7 @@ bool GLCanvas3D::_render_search_list(float pos_x) const
imgui->search_list(ImVec2(45 * em, 30 * em), &search_string_getter, s, imgui->search_list(ImVec2(45 * em, 30 * em), &search_string_getter, s,
sidebar.get_searcher().view_params, sidebar.get_searcher().view_params,
selected, edited, m_mouse_wheel); selected, edited, m_mouse_wheel, wxGetApp().is_localized());
search_line = s; search_line = s;
delete [] s; delete [] s;
@ -4410,11 +4408,12 @@ bool GLCanvas3D::_render_search_list(float pos_x) const
if (edited) if (edited)
sidebar.search(); sidebar.search();
if (selected != size_t(-1)) { if (selected >= 0) {
// selected == 9999 means that Esc kye was pressed // selected == 9999 means that Esc kye was pressed
if (selected != 9999) if (selected == 9999)
sidebar.jump_to_option(selected);
action_taken = true; action_taken = true;
else
sidebar.jump_to_option(selected);
} }
imgui->end(); imgui->end();

View file

@ -162,6 +162,7 @@ public:
wxString current_language_code() const { return m_wxLocale->GetCanonicalName(); } wxString current_language_code() const { return m_wxLocale->GetCanonicalName(); }
// Translate the language code to a code, for which Prusa Research maintains translations. Defaults to "en_US". // Translate the language code to a code, for which Prusa Research maintains translations. Defaults to "en_US".
wxString current_language_code_safe() const; wxString current_language_code_safe() const;
bool is_localized() const { return m_wxLocale->GetLocale() != "English"; }
virtual bool OnExceptionInMainLoop() override; virtual bool OnExceptionInMainLoop() override;

View file

@ -627,8 +627,9 @@ static void process_key_down(ImGuiKey imgui_key, std::function<void()> f)
} }
void ImGuiWrapper::search_list(const ImVec2& size_, bool (*items_getter)(int, const char** label, const char** tooltip), char* search_str, void ImGuiWrapper::search_list(const ImVec2& size_, bool (*items_getter)(int, const char** label, const char** tooltip), char* search_str,
Search::OptionViewParameters& view_params, int& selected, bool& edited, int& mouse_wheel) Search::OptionViewParameters& view_params, int& selected, bool& edited, int& mouse_wheel, bool is_localized)
{ {
int& hovered_id = view_params.hovered_id;
// ImGui::ListBoxHeader("", size); // ImGui::ListBoxHeader("", size);
{ {
// rewrote part of function to add a TextInput instead of label Text // rewrote part of function to add a TextInput instead of label Text
@ -668,7 +669,7 @@ void ImGuiWrapper::search_list(const ImVec2& size_, bool (*items_getter)(int, co
ImGui::InputTextEx("", NULL, search_str, 20, search_size, ImGuiInputTextFlags_AutoSelectAll, NULL, NULL); ImGui::InputTextEx("", NULL, search_str, 20, search_size, ImGuiInputTextFlags_AutoSelectAll, NULL, NULL);
edited = ImGui::IsItemEdited(); edited = ImGui::IsItemEdited();
if (edited) if (edited)
view_params.hovered_id = -1; hovered_id = 0;
process_key_down(ImGuiKey_Escape, [&selected, search_str, str]() { process_key_down(ImGuiKey_Escape, [&selected, search_str, str]() {
// use 9999 to mark selection as a Esc key // use 9999 to mark selection as a Esc key
@ -684,7 +685,6 @@ void ImGuiWrapper::search_list(const ImVec2& size_, bool (*items_getter)(int, co
const char* item_text; const char* item_text;
const char* tooltip; const char* tooltip;
int mouse_hovered = -1; int mouse_hovered = -1;
int& hovered_id = view_params.hovered_id;
while (items_getter(i, &item_text, &tooltip)) while (items_getter(i, &item_text, &tooltip))
{ {
@ -692,7 +692,7 @@ void ImGuiWrapper::search_list(const ImVec2& size_, bool (*items_getter)(int, co
if (ImGui::IsItemHovered()) { if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("%s", /*item_text*/tooltip); ImGui::SetTooltip("%s", /*item_text*/tooltip);
view_params.hovered_id = -1; hovered_id = -1;
mouse_hovered = i; mouse_hovered = i;
} }
@ -701,8 +701,6 @@ void ImGuiWrapper::search_list(const ImVec2& size_, bool (*items_getter)(int, co
i++; i++;
} }
scroll_y(mouse_hovered);
// Process mouse wheel // Process mouse wheel
if (mouse_hovered > 0) if (mouse_hovered > 0)
process_mouse_wheel(mouse_wheel); process_mouse_wheel(mouse_wheel);
@ -712,7 +710,7 @@ void ImGuiWrapper::search_list(const ImVec2& size_, bool (*items_getter)(int, co
if (mouse_hovered > 0) if (mouse_hovered > 0)
scroll_up(); scroll_up();
else { else {
if (hovered_id > 0 && hovered_id != size_t(-1)) if (hovered_id > 0)
--hovered_id; --hovered_id;
scroll_y(hovered_id); scroll_y(hovered_id);
} }
@ -722,9 +720,9 @@ void ImGuiWrapper::search_list(const ImVec2& size_, bool (*items_getter)(int, co
if (mouse_hovered > 0) if (mouse_hovered > 0)
scroll_down(); scroll_down();
else { else {
if (hovered_id == size_t(-1)) if (hovered_id < 0)
hovered_id = 0; hovered_id = 0;
else if (hovered_id < size_t(i - 1)) else if (hovered_id < i - 1)
++hovered_id; ++hovered_id;
scroll_y(hovered_id); scroll_y(hovered_id);
} }
@ -750,6 +748,7 @@ void ImGuiWrapper::search_list(const ImVec2& size_, bool (*items_getter)(int, co
text(_L("Use for search")+":"); text(_L("Use for search")+":");
check_box(_L("Category"), view_params.category); check_box(_L("Category"), view_params.category);
check_box(_L("Group"), view_params.group); check_box(_L("Group"), view_params.group);
if (is_localized)
check_box(_L("Search in English"), view_params.english); check_box(_L("Search in English"), view_params.english);
} }

View file

@ -79,7 +79,7 @@ public:
bool combo(const wxString& label, const std::vector<std::string>& options, int& selection); // Use -1 to not mark any option as selected bool combo(const wxString& label, const std::vector<std::string>& options, int& selection); // Use -1 to not mark any option as selected
bool undo_redo_list(const ImVec2& size, const bool is_undo, bool (*items_getter)(const bool, int, const char**), int& hovered, int& selected, int& mouse_wheel); bool undo_redo_list(const ImVec2& size, const bool is_undo, bool (*items_getter)(const bool, int, const char**), int& hovered, int& selected, int& mouse_wheel);
void search_list(const ImVec2& size, bool (*items_getter)(int, const char** label, const char** tooltip), char* search_str, void search_list(const ImVec2& size, bool (*items_getter)(int, const char** label, const char** tooltip), char* search_str,
Search::OptionViewParameters& view_params, int& selected, bool& edited, int& mouse_wheel); Search::OptionViewParameters& view_params, int& selected, bool& edited, int& mouse_wheel, bool is_localized);
void disabled_begin(bool disabled); void disabled_begin(bool disabled);
void disabled_end(); void disabled_end();

View file

@ -1267,7 +1267,12 @@ void MainFrame::select_tab(size_t tab/* = size_t(-1)*/)
} }
// Show/Activate Settings Dialog // Show/Activate Settings Dialog
if (m_settings_dialog->IsShown()) if (m_settings_dialog->IsShown())
#ifdef __WXOSX__ // Don't call SetFont under OSX to avoid name cutting in ObjectList
m_settings_dialog->Hide(); m_settings_dialog->Hide();
#else
m_settings_dialog->SetFocus();
else
#endif
m_settings_dialog->Show(); m_settings_dialog->Show();
} }
else if (m_layout == slNew) { else if (m_layout == slNew) {

View file

@ -434,12 +434,14 @@ SearchDialog::SearchDialog(OptionsSearcher* searcher)
check_category = new wxCheckBox(this, wxID_ANY, _L("Category")); check_category = new wxCheckBox(this, wxID_ANY, _L("Category"));
check_group = new wxCheckBox(this, wxID_ANY, _L("Group")); check_group = new wxCheckBox(this, wxID_ANY, _L("Group"));
if (GUI::wxGetApp().is_localized())
check_english = new wxCheckBox(this, wxID_ANY, _L("Search in English")); check_english = new wxCheckBox(this, wxID_ANY, _L("Search in English"));
wxStdDialogButtonSizer* cancel_btn = this->CreateStdDialogButtonSizer(wxCANCEL); wxStdDialogButtonSizer* cancel_btn = this->CreateStdDialogButtonSizer(wxCANCEL);
check_sizer->Add(check_category, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, border); check_sizer->Add(check_category, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, border);
check_sizer->Add(check_group, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, border); check_sizer->Add(check_group, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, border);
if (GUI::wxGetApp().is_localized())
check_sizer->Add(check_english, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, border); check_sizer->Add(check_english, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, border);
check_sizer->AddStretchSpacer(border); check_sizer->AddStretchSpacer(border);
check_sizer->Add(cancel_btn, 0, wxALIGN_CENTER_VERTICAL); check_sizer->Add(cancel_btn, 0, wxALIGN_CENTER_VERTICAL);
@ -459,6 +461,7 @@ SearchDialog::SearchDialog(OptionsSearcher* searcher)
search_list->Bind(wxEVT_LEFT_UP, &SearchDialog::OnMouseClick, this); search_list->Bind(wxEVT_LEFT_UP, &SearchDialog::OnMouseClick, this);
search_list->Bind(wxEVT_KEY_DOWN,&SearchDialog::OnKeyDown, this); search_list->Bind(wxEVT_KEY_DOWN,&SearchDialog::OnKeyDown, this);
if (GUI::wxGetApp().is_localized())
check_english ->Bind(wxEVT_CHECKBOX, &SearchDialog::OnCheck, this); check_english ->Bind(wxEVT_CHECKBOX, &SearchDialog::OnCheck, this);
check_category->Bind(wxEVT_CHECKBOX, &SearchDialog::OnCheck, this); check_category->Bind(wxEVT_CHECKBOX, &SearchDialog::OnCheck, this);
check_group ->Bind(wxEVT_CHECKBOX, &SearchDialog::OnCheck, this); check_group ->Bind(wxEVT_CHECKBOX, &SearchDialog::OnCheck, this);

View file

@ -70,7 +70,7 @@ struct OptionViewParameters
bool group {true }; bool group {true };
bool english {false}; bool english {false};
int hovered_id {-1}; int hovered_id {0};
}; };
class OptionsSearcher class OptionsSearcher