Implement Search for GCode DataView

This commit is contained in:
Ocraftyone
2024-01-08 18:00:32 -05:00
parent 43417b0f63
commit 068b888199
2 changed files with 145 additions and 19 deletions

View File

@@ -10,6 +10,7 @@
#include "wxExtensions.hpp"
#include "libslic3r/Preset.hpp"
#include "libslic3r/PrintConfig.hpp"
#include <wx/srchctrl.h>
class wxListBox;
class wxTextCtrl;
@@ -27,11 +28,12 @@ class ParamsViewCtrl;
class EditGCodeDialog : public DPIDialog
{
ParamsViewCtrl* m_params_list {nullptr};
ScalableButton* m_add_btn {nullptr};
wxTextCtrl* m_gcode_editor {nullptr};
wxStaticText* m_param_label {nullptr};
wxStaticText* m_param_description {nullptr};
ParamsViewCtrl* m_params_list {nullptr};
ScalableButton* m_add_btn {nullptr};
wxTextCtrl* m_gcode_editor {nullptr};
wxStaticText* m_param_label {nullptr};
wxStaticText* m_param_description {nullptr};
wxSearchCtrl* m_search_bar {nullptr};
ReadOnlySlicingStatesConfigDef cgp_ro_slicing_states_config_def;
ReadWriteSlicingStatesConfigDef cgp_rw_slicing_states_config_def;
@@ -48,6 +50,7 @@ public:
~EditGCodeDialog();
std::string get_edited_gcode() const;
void on_search_update();
void init_params_list(const std::string& custom_gcode_name);
wxDataViewItem add_presets_placeholders();
@@ -93,6 +96,7 @@ class ParamsNode
{
ParamsNode* m_parent{ nullptr };
ParamsNodePtrArray m_children;
wxDataViewCtrl* m_ctrl;
ParamType m_param_type{ ParamType::Undef };
@@ -106,6 +110,8 @@ class ParamsNode
// AND the classical node was removed (a new node temporary without children
// would be added to the control)
bool m_container{ true };
bool m_expanded_before_search{false};
bool m_enabled{true};
public:
@@ -119,25 +125,36 @@ public:
wxString text;
// Group params(root) node
ParamsNode(const wxString& group_name, const std::string& icon_name);
ParamsNode(const wxString& group_name, const std::string& icon_name, wxDataViewCtrl* ctrl);
// sub SlicingState node
ParamsNode(ParamsNode* parent,
const wxString& sub_group_name,
const std::string& icon_name);
const std::string& icon_name,
wxDataViewCtrl* ctrl);
// parametre node
ParamsNode( ParamsNode* parent,
ParamType param_type,
const std::string& param_key);
const std::string& param_key,
wxDataViewCtrl* ctrl);
bool IsContainer() const { return m_container; }
bool IsGroupNode() const { return m_parent == nullptr; }
bool IsParamNode() const { return m_param_type != ParamType::Undef; }
void SetContainer(bool is_container) { m_container = is_container; }
bool IsEnabled() { return m_enabled; }
void Enable(bool enable = true) { m_enabled = enable; }
void Disable() { Enable(false); }
void StartSearch();
void RefreshSearch(const wxString& search_text);
void FinishSearch();
ParamsNode* GetParent() { return m_parent; }
ParamsNodePtrArray& GetChildren() { return m_children; }
wxDataViewItemArray GetEnabledChildren();
void Append(std::unique_ptr<ParamsNode> child) { m_children.emplace_back(std::move(child)); }
};
@@ -149,8 +166,9 @@ public:
class ParamsModel : public wxDataViewModel
{
ParamsNodePtrArray m_group_nodes;
wxDataViewCtrl* m_ctrl{ nullptr };
ParamsNodePtrArray m_group_nodes;
wxDataViewCtrl* m_ctrl{ nullptr };
bool m_currently_searching{false};
public:
@@ -176,6 +194,9 @@ public:
std::string GetParamKey(wxDataViewItem item);
std::string GetTopLevelCategory(wxDataViewItem item);
void RefreshSearch(const wxString& search_text);
void FinishSearch();
void Clear();
wxDataViewItem GetParent(const wxDataViewItem& item) const override;