Skip to content

Commit

Permalink
Search: 1.Select first item in the search list by default
Browse files Browse the repository at this point in the history
2. Show "Search in English" checkbox only, when Slicer is localized
3. Suppress search window hiding when leave the 3D-scene
  • Loading branch information
YuSanka committed May 7, 2020
1 parent 2daa12d commit 9189758
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 22 deletions.
11 changes: 5 additions & 6 deletions src/slic3r/GUI/GLCanvas3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3567,7 +3567,6 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
else if (evt.Leaving())
{
_deactivate_undo_redo_toolbar_items();
_deactivate_search_toolbar_item();

// to remove hover on objects when the mouse goes out of this canvas
m_mouse.position = Vec2d(-1.0, -1.0);
Expand Down Expand Up @@ -4386,7 +4385,6 @@ bool GLCanvas3D::_render_search_list(float pos_x) const

int selected = -1;
bool edited = false;
bool check_changed = false;
float em = static_cast<float>(wxGetApp().em_unit());
#if ENABLE_RETINA_GL
em *= m_retina_helper->get_scale_factor();
Expand All @@ -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,
sidebar.get_searcher().view_params,
selected, edited, m_mouse_wheel);
selected, edited, m_mouse_wheel, wxGetApp().is_localized());

search_line = s;
delete [] s;
Expand All @@ -4410,11 +4408,12 @@ bool GLCanvas3D::_render_search_list(float pos_x) const
if (edited)
sidebar.search();

if (selected != size_t(-1)) {
if (selected >= 0) {
// selected == 9999 means that Esc kye was pressed
if (selected != 9999)
if (selected == 9999)
action_taken = true;
else
sidebar.jump_to_option(selected);
action_taken = true;
}

imgui->end();
Expand Down
1 change: 1 addition & 0 deletions src/slic3r/GUI/GUI_App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class GUI_App : public wxApp
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".
wxString current_language_code_safe() const;
bool is_localized() const { return m_wxLocale->GetLocale() != "English"; }

virtual bool OnExceptionInMainLoop() override;

Expand Down
19 changes: 9 additions & 10 deletions src/slic3r/GUI/ImGuiWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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);
{
// rewrote part of function to add a TextInput instead of label Text
Expand Down Expand Up @@ -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);
edited = ImGui::IsItemEdited();
if (edited)
view_params.hovered_id = -1;
hovered_id = 0;

process_key_down(ImGuiKey_Escape, [&selected, search_str, str]() {
// use 9999 to mark selection as a Esc key
Expand All @@ -684,15 +685,14 @@ void ImGuiWrapper::search_list(const ImVec2& size_, bool (*items_getter)(int, co
const char* item_text;
const char* tooltip;
int mouse_hovered = -1;
int& hovered_id = view_params.hovered_id;

while (items_getter(i, &item_text, &tooltip))
{
selectable(item_text, i == hovered_id);

if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("%s", /*item_text*/tooltip);
view_params.hovered_id = -1;
hovered_id = -1;
mouse_hovered = i;
}

Expand All @@ -701,8 +701,6 @@ void ImGuiWrapper::search_list(const ImVec2& size_, bool (*items_getter)(int, co
i++;
}

scroll_y(mouse_hovered);

// Process mouse wheel
if (mouse_hovered > 0)
process_mouse_wheel(mouse_wheel);
Expand All @@ -712,7 +710,7 @@ void ImGuiWrapper::search_list(const ImVec2& size_, bool (*items_getter)(int, co
if (mouse_hovered > 0)
scroll_up();
else {
if (hovered_id > 0 && hovered_id != size_t(-1))
if (hovered_id > 0)
--hovered_id;
scroll_y(hovered_id);
}
Expand All @@ -722,9 +720,9 @@ void ImGuiWrapper::search_list(const ImVec2& size_, bool (*items_getter)(int, co
if (mouse_hovered > 0)
scroll_down();
else {
if (hovered_id == size_t(-1))
if (hovered_id < 0)
hovered_id = 0;
else if (hovered_id < size_t(i - 1))
else if (hovered_id < i - 1)
++hovered_id;
scroll_y(hovered_id);
}
Expand All @@ -750,7 +748,8 @@ void ImGuiWrapper::search_list(const ImVec2& size_, bool (*items_getter)(int, co
text(_L("Use for search")+":");
check_box(_L("Category"), view_params.category);
check_box(_L("Group"), view_params.group);
check_box(_L("Search in English"), view_params.english);
if (is_localized)
check_box(_L("Search in English"), view_params.english);
}

void ImGuiWrapper::disabled_begin(bool disabled)
Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/GUI/ImGuiWrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ImGuiWrapper
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);
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_end();
Expand Down
5 changes: 5 additions & 0 deletions src/slic3r/GUI/MainFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,12 @@ void MainFrame::select_tab(size_t tab/* = size_t(-1)*/)
}
// Show/Activate Settings Dialog
if (m_settings_dialog->IsShown())
#ifdef __WXOSX__ // Don't call SetFont under OSX to avoid name cutting in ObjectList
m_settings_dialog->Hide();
#else
m_settings_dialog->SetFocus();
else
#endif
m_settings_dialog->Show();
}
else if (m_layout == slNew) {
Expand Down
11 changes: 7 additions & 4 deletions src/slic3r/GUI/Search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,15 @@ SearchDialog::SearchDialog(OptionsSearcher* searcher)

check_category = new wxCheckBox(this, wxID_ANY, _L("Category"));
check_group = new wxCheckBox(this, wxID_ANY, _L("Group"));
check_english = new wxCheckBox(this, wxID_ANY, _L("Search in English"));
if (GUI::wxGetApp().is_localized())
check_english = new wxCheckBox(this, wxID_ANY, _L("Search in English"));

wxStdDialogButtonSizer* cancel_btn = this->CreateStdDialogButtonSizer(wxCANCEL);

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_english, 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->AddStretchSpacer(border);
check_sizer->Add(cancel_btn, 0, wxALIGN_CENTER_VERTICAL);

Expand All @@ -459,7 +461,8 @@ SearchDialog::SearchDialog(OptionsSearcher* searcher)
search_list->Bind(wxEVT_LEFT_UP, &SearchDialog::OnMouseClick, this);
search_list->Bind(wxEVT_KEY_DOWN,&SearchDialog::OnKeyDown, this);

check_english ->Bind(wxEVT_CHECKBOX, &SearchDialog::OnCheck, this);
if (GUI::wxGetApp().is_localized())
check_english ->Bind(wxEVT_CHECKBOX, &SearchDialog::OnCheck, this);
check_category->Bind(wxEVT_CHECKBOX, &SearchDialog::OnCheck, this);
check_group ->Bind(wxEVT_CHECKBOX, &SearchDialog::OnCheck, this);

Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/GUI/Search.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct OptionViewParameters
bool group {true };
bool english {false};

int hovered_id {-1};
int hovered_id {0};
};

class OptionsSearcher
Expand Down

0 comments on commit 9189758

Please sign in to comment.