Code cleaning
This commit is contained in:
parent
752083cbe6
commit
cd13356b6d
12
resources/icons/attention.svg
Normal file
12
resources/icons/attention.svg
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Generator: Adobe Illustrator 24.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||||
|
<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||||
|
viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
|
||||||
|
<g id="attention">
|
||||||
|
<path fill="#ED0000" d="M8,1.85l5.29,3.53V7v3.62L8,14.15l-5.29-3.53V7V5.38L8,1.85 M8,1L2,5v2v4l6,4l6-4V7V5L8,1L8,1z"/>
|
||||||
|
|
||||||
|
<path fill="none" stroke="#ED0000" stroke-linecap="round" stroke-width="3" d="M8 4 L8 8" />
|
||||||
|
|
||||||
|
<circle fill="#ED0000" cx="8" cy="12" r="1.5"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 641 B |
@ -57,7 +57,7 @@ void Field::PostInitialize()
|
|||||||
m_Undo_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { on_back_to_initial_value(); }));
|
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_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());
|
m_find_image = new wxStaticBitmap(m_parent, wxID_ANY, wxNullBitmap, wxDefaultPosition, m_attention_bmp.bmp().GetSize());
|
||||||
|
|
||||||
switch (m_opt.type)
|
switch (m_opt.type)
|
||||||
|
@ -193,6 +193,7 @@ public:
|
|||||||
|
|
||||||
void invalidate_attention_bmp() const {
|
void invalidate_attention_bmp() const {
|
||||||
m_find_image->SetBitmap(wxNullBitmap);
|
m_find_image->SetBitmap(wxNullBitmap);
|
||||||
|
m_find_image->Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void activate_attention_bmp() const {
|
void activate_attention_bmp() const {
|
||||||
|
@ -1093,7 +1093,7 @@ void Sidebar::msw_rescale()
|
|||||||
|
|
||||||
void Sidebar::apply_search_filter()
|
void Sidebar::apply_search_filter()
|
||||||
{
|
{
|
||||||
p->search_list.apply_filters(p->search_line);
|
if (p->search_list.apply_filters(p->search_line))
|
||||||
apply_search_line_on_tabs();
|
apply_search_line_on_tabs();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1387,7 +1387,7 @@ void Sidebar::apply_search_line_on_tabs()
|
|||||||
void Sidebar::update_search_list()
|
void Sidebar::update_search_list()
|
||||||
{
|
{
|
||||||
p->search_list.init(get_search_inputs(m_mode));
|
p->search_list.init(get_search_inputs(m_mode));
|
||||||
apply_search_line_on_tabs();
|
// apply_search_line_on_tabs();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sidebar::update_mode()
|
void Sidebar::update_mode()
|
||||||
|
@ -163,8 +163,11 @@ static void clear_marked_string(wxString& str)
|
|||||||
str.Replace(delete_string, wxEmptyString, true);
|
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();
|
clear_filters();
|
||||||
|
|
||||||
bool full_list = search.empty();
|
bool full_list = search.empty();
|
||||||
@ -189,6 +192,9 @@ void SearchOptions::apply_filters(const std::string& search)
|
|||||||
|
|
||||||
if (!full_list)
|
if (!full_list)
|
||||||
sort_filters();
|
sort_filters();
|
||||||
|
|
||||||
|
search_line = search;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchOptions::init(std::vector<SearchInput> input_values)
|
void SearchOptions::init(std::vector<SearchInput> input_values)
|
||||||
@ -198,7 +204,7 @@ void SearchOptions::init(std::vector<SearchInput> input_values)
|
|||||||
append_options(i.config, i.type, i.mode);
|
append_options(i.config, i.type, i.mode);
|
||||||
sort_options();
|
sort_options();
|
||||||
|
|
||||||
apply_filters("");
|
apply_filters("", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
const SearchOptions::Option& SearchOptions::get_option(size_t pos_in_filter) const
|
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");
|
wxBitmap bmp_hov = create_scaled_bitmap("search");
|
||||||
comboCtrl->SetButtonBitmaps(bmp_norm, true, bmp_hov, bmp_hov, bmp_norm);
|
comboCtrl->SetButtonBitmaps(bmp_norm, true, bmp_hov, bmp_hov, bmp_norm);
|
||||||
|
|
||||||
// popupListBox = new SearchComboPopup();
|
popupListBox = new SearchComboPopup();
|
||||||
popupListCtrl = new SearchComboPopup_();
|
|
||||||
|
|
||||||
// It is important to call SetPopupControl() as soon as possible
|
// It is important to call SetPopupControl() as soon as possible
|
||||||
// comboCtrl->SetPopupControl(popupListBox);
|
comboCtrl->SetPopupControl(popupListBox);
|
||||||
comboCtrl->SetPopupControl(popupListCtrl);
|
|
||||||
|
|
||||||
box_sizer->Add(comboCtrl, 0, wxALIGN_CENTER_VERTICAL);
|
box_sizer->Add(comboCtrl, 0, wxALIGN_CENTER_VERTICAL);
|
||||||
|
|
||||||
// popupListBox->Bind(wxEVT_LISTBOX, &SearchCtrl::OnSelect, this);
|
popupListBox->Bind(wxEVT_LISTBOX, &SearchCtrl::OnSelect, this);
|
||||||
// popupListCtrl->Bind(wxEVT_LIST_ITEM_SELECTED, &SearchCtrl::OnSelectCtrl, this);
|
popupListBox->Bind(wxEVT_LEFT_DOWN, &SearchCtrl::OnLeftDownInPopup, this);
|
||||||
popupListCtrl->Bind(wxEVT_LIST_ITEM_SELECTED, [](wxListEvent& event)
|
|
||||||
{
|
|
||||||
int i=0;
|
|
||||||
});
|
|
||||||
|
|
||||||
comboCtrl->Bind(wxEVT_TEXT, &SearchCtrl::OnInputText, this);
|
comboCtrl->Bind(wxEVT_TEXT, &SearchCtrl::OnInputText, this);
|
||||||
comboCtrl->Bind(wxEVT_TEXT_ENTER, &SearchCtrl::PopupList, this);
|
comboCtrl->Bind(wxEVT_TEXT_ENTER, &SearchCtrl::PopupList, this);
|
||||||
comboCtrl->Bind(wxEVT_COMBOBOX_DROPDOWN, &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()
|
SearchCtrl::~SearchCtrl()
|
||||||
@ -507,14 +507,21 @@ void SearchCtrl::OnInputText(wxCommandEvent& )
|
|||||||
if (prevent_update)
|
if (prevent_update)
|
||||||
return;
|
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();
|
std::string& search_str = wxGetApp().sidebar().get_search_line();
|
||||||
// search_str = into_u8(search_line->GetValue());
|
// 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();
|
wxGetApp().sidebar().apply_search_filter();
|
||||||
|
editing = false;
|
||||||
|
|
||||||
// popup_win->update_list(wxGetApp().sidebar().get_search_list().filters);
|
// popup_win->update_list(wxGetApp().sidebar().get_search_list().filters);
|
||||||
|
|
||||||
// update_list(wxGetApp().sidebar().get_search_list().filters);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchCtrl::PopupList(wxCommandEvent& e)
|
void SearchCtrl::PopupList(wxCommandEvent& e)
|
||||||
@ -536,7 +543,7 @@ void SearchCtrl::set_search_line(const std::string& line)
|
|||||||
{
|
{
|
||||||
prevent_update = true;
|
prevent_update = true;
|
||||||
// search_line->SetValue(line.empty() ? _L("Type here to search") : from_u8(line));
|
// 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;
|
prevent_update = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -549,7 +556,6 @@ void SearchCtrl::msw_rescale()
|
|||||||
// Set rescaled size
|
// Set rescaled size
|
||||||
search_btn->msw_rescale();
|
search_btn->msw_rescale();
|
||||||
|
|
||||||
|
|
||||||
comboCtrl->SetButtonBitmaps(create_scaled_bitmap("search"));
|
comboCtrl->SetButtonBitmaps(create_scaled_bitmap("search"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -567,37 +573,31 @@ void SearchCtrl::OnSelect(wxCommandEvent& event)
|
|||||||
comboCtrl->Dismiss();
|
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<SearchOptions::Filter>& filters)
|
void SearchCtrl::update_list(std::vector<SearchOptions::Filter>& 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)
|
for (const SearchOptions::Filter& item : filters)
|
||||||
popupListBox->Append(item.label);*/
|
popupListBox->Append(item.label);
|
||||||
popupListCtrl->DeleteAllItems();
|
|
||||||
for (const SearchOptions::Filter& item : filters)
|
|
||||||
popupListCtrl->InsertItem(popupListCtrl->GetItemCount(), item.label);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchCtrl::OnLeftDown(wxEvent &event)
|
void SearchCtrl::OnLeftUpInTextCtrl(wxEvent &event)
|
||||||
{
|
{
|
||||||
const wxString& str = comboCtrl->GetValue();
|
if (comboCtrl->GetValue() == default_string)
|
||||||
if (!str.IsEmpty() && str == default_string) {
|
|
||||||
prevent_update = true;
|
|
||||||
comboCtrl->SetValue("");
|
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();
|
event.Skip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ struct SearchInput
|
|||||||
|
|
||||||
class SearchOptions
|
class SearchOptions
|
||||||
{
|
{
|
||||||
|
std::string search_line;
|
||||||
public:
|
public:
|
||||||
struct Option {
|
struct Option {
|
||||||
bool operator<(const Option& other) const { return other.label > this->label; }
|
bool operator<(const Option& other) const { return other.label > this->label; }
|
||||||
@ -65,7 +66,7 @@ public:
|
|||||||
void init(std::vector<SearchInput> input_values);
|
void init(std::vector<SearchInput> input_values);
|
||||||
|
|
||||||
void append_options(DynamicPrintConfig* config, Preset::Type type, ConfigOptionMode mode);
|
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() {
|
void sort_options() {
|
||||||
std::sort(options.begin(), options.end(), [](const Option& o1, const Option& o2) {
|
std::sort(options.begin(), options.end(), [](const Option& o1, const Option& o2) {
|
||||||
@ -151,8 +152,6 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SearchComboPopup : public wxListBox, public wxComboPopup
|
class SearchComboPopup : public wxListBox, public wxComboPopup
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -197,53 +196,6 @@ protected:
|
|||||||
wxString m_input_string;
|
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
|
class SearchCtrl
|
||||||
{
|
{
|
||||||
wxBoxSizer* box_sizer {nullptr};
|
wxBoxSizer* box_sizer {nullptr};
|
||||||
@ -254,17 +206,17 @@ class SearchCtrl
|
|||||||
|
|
||||||
bool prevent_update{ false };
|
bool prevent_update{ false };
|
||||||
wxString default_string;
|
wxString default_string;
|
||||||
|
bool editing {false};
|
||||||
|
|
||||||
void PopupList(wxCommandEvent& event);
|
void PopupList(wxCommandEvent& event);
|
||||||
void OnInputText(wxCommandEvent& event);
|
void OnInputText(wxCommandEvent& event);
|
||||||
|
|
||||||
wxComboCtrl* comboCtrl {nullptr};
|
wxComboCtrl* comboCtrl {nullptr};
|
||||||
SearchComboPopup* popupListBox {nullptr};
|
SearchComboPopup* popupListBox {nullptr};
|
||||||
SearchComboPopup_* popupListCtrl {nullptr};
|
|
||||||
|
|
||||||
void OnSelect(wxCommandEvent& event);
|
void OnSelect(wxCommandEvent& event);
|
||||||
void OnLeftDown(wxEvent& event);
|
void OnLeftDownInPopup(wxEvent& event);
|
||||||
void OnSelectCtrl(wxListEvent& event);
|
void OnLeftUpInTextCtrl(wxEvent& event);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SearchCtrl(wxWindow* parent);
|
SearchCtrl(wxWindow* parent);
|
||||||
|
Loading…
Reference in New Issue
Block a user