diff --git a/resources/icons/attention.svg b/resources/icons/attention.svg new file mode 100644 index 000000000..934bd3b41 --- /dev/null +++ b/resources/icons/attention.svg @@ -0,0 +1,12 @@ + + + + + + + + + + + diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index d69fd6c06..dfe561caf 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -57,7 +57,7 @@ void Field::PostInitialize() m_Undo_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { on_back_to_initial_value(); })); m_Undo_to_sys_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { on_back_to_sys_value(); })); - m_attention_bmp = ScalableBitmap(m_parent, "error_tick_f"); + m_attention_bmp = ScalableBitmap(m_parent, "attention"); m_find_image = new wxStaticBitmap(m_parent, wxID_ANY, wxNullBitmap, wxDefaultPosition, m_attention_bmp.bmp().GetSize()); switch (m_opt.type) diff --git a/src/slic3r/GUI/Field.hpp b/src/slic3r/GUI/Field.hpp index 73529cf31..d716be25c 100644 --- a/src/slic3r/GUI/Field.hpp +++ b/src/slic3r/GUI/Field.hpp @@ -193,6 +193,7 @@ public: void invalidate_attention_bmp() const { m_find_image->SetBitmap(wxNullBitmap); + m_find_image->Show(); } void activate_attention_bmp() const { diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index acf762bfb..3d2f6052f 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1093,8 +1093,8 @@ void Sidebar::msw_rescale() void Sidebar::apply_search_filter() { - p->search_list.apply_filters(p->search_line); - apply_search_line_on_tabs(); + if (p->search_list.apply_filters(p->search_line)) + apply_search_line_on_tabs(); } void Sidebar::jump_to_option(size_t selected) @@ -1387,7 +1387,7 @@ void Sidebar::apply_search_line_on_tabs() void Sidebar::update_search_list() { p->search_list.init(get_search_inputs(m_mode)); - apply_search_line_on_tabs(); +// apply_search_line_on_tabs(); } void Sidebar::update_mode() diff --git a/src/slic3r/GUI/Search.cpp b/src/slic3r/GUI/Search.cpp index 4990b17ee..95bf2da3f 100644 --- a/src/slic3r/GUI/Search.cpp +++ b/src/slic3r/GUI/Search.cpp @@ -163,8 +163,11 @@ static void clear_marked_string(wxString& str) str.Replace(delete_string, wxEmptyString, true); } -void SearchOptions::apply_filters(const std::string& search) +bool SearchOptions::apply_filters(const std::string& search, bool force/* = false*/) { + if (search_line == search && !force) + return false; + clear_filters(); bool full_list = search.empty(); @@ -189,6 +192,9 @@ void SearchOptions::apply_filters(const std::string& search) if (!full_list) sort_filters(); + + search_line = search; + return true; } void SearchOptions::init(std::vector input_values) @@ -198,7 +204,7 @@ void SearchOptions::init(std::vector input_values) append_options(i.config, i.type, i.mode); sort_options(); - apply_filters(""); + apply_filters("", true); } const SearchOptions::Option& SearchOptions::get_option(size_t pos_in_filter) const @@ -469,27 +475,21 @@ SearchCtrl::SearchCtrl(wxWindow* parent) wxBitmap bmp_hov = create_scaled_bitmap("search"); comboCtrl->SetButtonBitmaps(bmp_norm, true, bmp_hov, bmp_hov, bmp_norm); -// popupListBox = new SearchComboPopup(); - popupListCtrl = new SearchComboPopup_(); + popupListBox = new SearchComboPopup(); // It is important to call SetPopupControl() as soon as possible -// comboCtrl->SetPopupControl(popupListBox); - comboCtrl->SetPopupControl(popupListCtrl); + comboCtrl->SetPopupControl(popupListBox); box_sizer->Add(comboCtrl, 0, wxALIGN_CENTER_VERTICAL); -// popupListBox->Bind(wxEVT_LISTBOX, &SearchCtrl::OnSelect, this); -// popupListCtrl->Bind(wxEVT_LIST_ITEM_SELECTED, &SearchCtrl::OnSelectCtrl, this); - popupListCtrl->Bind(wxEVT_LIST_ITEM_SELECTED, [](wxListEvent& event) - { - int i=0; - }); + popupListBox->Bind(wxEVT_LISTBOX, &SearchCtrl::OnSelect, this); + popupListBox->Bind(wxEVT_LEFT_DOWN, &SearchCtrl::OnLeftDownInPopup, this); comboCtrl->Bind(wxEVT_TEXT, &SearchCtrl::OnInputText, this); comboCtrl->Bind(wxEVT_TEXT_ENTER, &SearchCtrl::PopupList, this); comboCtrl->Bind(wxEVT_COMBOBOX_DROPDOWN, &SearchCtrl::PopupList, this); - comboCtrl->GetTextCtrl()->Bind(wxEVT_LEFT_DOWN, &SearchCtrl::OnLeftDown, this); + comboCtrl->GetTextCtrl()->Bind(wxEVT_LEFT_UP, &SearchCtrl::OnLeftUpInTextCtrl, this); } SearchCtrl::~SearchCtrl() @@ -507,14 +507,21 @@ void SearchCtrl::OnInputText(wxCommandEvent& ) if (prevent_update) return; + comboCtrl->GetTextCtrl()->SetInsertionPointEnd(); + + wxString input_string = comboCtrl->GetValue(); + if (input_string == default_string) + input_string.Clear(); + std::string& search_str = wxGetApp().sidebar().get_search_line(); // search_str = into_u8(search_line->GetValue()); - search_str = into_u8(comboCtrl->GetValue()); + wxGetApp().sidebar().get_search_line() = into_u8(input_string); + + editing = true; wxGetApp().sidebar().apply_search_filter(); + editing = false; // popup_win->update_list(wxGetApp().sidebar().get_search_list().filters); - -// update_list(wxGetApp().sidebar().get_search_list().filters); } void SearchCtrl::PopupList(wxCommandEvent& e) @@ -536,7 +543,7 @@ void SearchCtrl::set_search_line(const std::string& line) { prevent_update = true; // search_line->SetValue(line.empty() ? _L("Type here to search") : from_u8(line)); - comboCtrl->SetText(line.empty() ? default_string : from_u8(line)); + comboCtrl->SetValue(line.empty() && !editing ? default_string : from_u8(line)); prevent_update = false; } @@ -549,7 +556,6 @@ void SearchCtrl::msw_rescale() // Set rescaled size search_btn->msw_rescale(); - comboCtrl->SetButtonBitmaps(create_scaled_bitmap("search")); } @@ -567,37 +573,31 @@ void SearchCtrl::OnSelect(wxCommandEvent& event) comboCtrl->Dismiss(); } -void SearchCtrl::OnSelectCtrl(wxListEvent& event) -{ - prevent_update = true; - - int selection = event.GetIndex(); - if (selection >= 0) - wxGetApp().sidebar().jump_to_option(selection); - - prevent_update = false; - - comboCtrl->Dismiss(); -} - void SearchCtrl::update_list(std::vector& filters) { -/* popupListBox->Clear(); + if (popupListBox->GetCount() == filters.size() && + popupListBox->GetString(0) == filters[0].label && + popupListBox->GetString(popupListBox->GetCount()-1) == filters[filters.size()-1].label) + return; + + popupListBox->Clear(); for (const SearchOptions::Filter& item : filters) - popupListBox->Append(item.label);*/ - popupListCtrl->DeleteAllItems(); - for (const SearchOptions::Filter& item : filters) - popupListCtrl->InsertItem(popupListCtrl->GetItemCount(), item.label); + popupListBox->Append(item.label); } -void SearchCtrl::OnLeftDown(wxEvent &event) +void SearchCtrl::OnLeftUpInTextCtrl(wxEvent &event) { - const wxString& str = comboCtrl->GetValue(); - if (!str.IsEmpty() && str == default_string) { - prevent_update = true; + if (comboCtrl->GetValue() == default_string) comboCtrl->SetValue(""); - prevent_update = false; - } + + event.Skip(); +} + +void SearchCtrl::OnLeftDownInPopup(wxEvent &event) +{ + wxPoint pt = wxGetMousePosition() - popupListBox->GetScreenPosition(); + int selected_item = popupListBox->HitTest(pt); + event.Skip(); } diff --git a/src/slic3r/GUI/Search.hpp b/src/slic3r/GUI/Search.hpp index 720171018..a27a10380 100644 --- a/src/slic3r/GUI/Search.hpp +++ b/src/slic3r/GUI/Search.hpp @@ -28,6 +28,7 @@ struct SearchInput class SearchOptions { + std::string search_line; public: struct Option { bool operator<(const Option& other) const { return other.label > this->label; } @@ -65,7 +66,7 @@ public: void init(std::vector input_values); void append_options(DynamicPrintConfig* config, Preset::Type type, ConfigOptionMode mode); - void apply_filters(const std::string& search); + bool apply_filters(const std::string& search, bool force = false); void sort_options() { std::sort(options.begin(), options.end(), [](const Option& o1, const Option& o2) { @@ -151,8 +152,6 @@ private: - - class SearchComboPopup : public wxListBox, public wxComboPopup { public: @@ -197,53 +196,6 @@ protected: wxString m_input_string; }; - - -class SearchComboPopup_ : public wxListCtrl, public wxComboPopup -{ -public: - // Initialize member variables - virtual void Init() {} - - // Create popup control - virtual bool Create(wxWindow* parent) - { - return wxListCtrl::Create(parent, 1, wxPoint(0, 0), wxDefaultSize, wxLC_LIST | wxLC_NO_HEADER | wxLC_SINGLE_SEL); - } - // Return pointer to the created control - virtual wxWindow* GetControl() { return this; } - // Translate string into a list selection - virtual void SetStringValue(const wxString& s) - { - int n = wxListCtrl::FindItem(0, s); - if (n >= 0 && n < wxListCtrl::GetItemCount()) - wxListCtrl::SetItemState(n, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); - - // save a combo control's string - m_input_string = s; - } - // Get list selection as a string - virtual wxString GetStringValue() const - { - // we shouldn't change a combo control's string - return m_input_string; - } - // Do mouse hot-tracking (which is typical in list popups) - void OnMouseMove(wxMouseEvent& event) - { - // TODO: Move selection to cursor - } - // On mouse left up, set the value and close the popup - void OnMouseClick(wxMouseEvent& WXUNUSED(event)) - { - // TODO: Send event as well - Dismiss(); - } -protected: - wxString m_input_string; -}; - - class SearchCtrl { wxBoxSizer* box_sizer {nullptr}; @@ -254,17 +206,17 @@ class SearchCtrl bool prevent_update{ false }; wxString default_string; + bool editing {false}; void PopupList(wxCommandEvent& event); void OnInputText(wxCommandEvent& event); wxComboCtrl* comboCtrl {nullptr}; SearchComboPopup* popupListBox {nullptr}; - SearchComboPopup_* popupListCtrl {nullptr}; void OnSelect(wxCommandEvent& event); - void OnLeftDown(wxEvent& event); - void OnSelectCtrl(wxListEvent& event); + void OnLeftDownInPopup(wxEvent& event); + void OnLeftUpInTextCtrl(wxEvent& event); public: SearchCtrl(wxWindow* parent);