mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-20 13:17:54 -06:00
Add search term highlighting to EditGCodeDialog
Now leaves text stored in ParamsNode un-formatted and uses flags to determine the formatting. The GetFormattedText function now returns the markup text.
This commit is contained in:
parent
22302a0f10
commit
8de9d97cd8
2 changed files with 41 additions and 14 deletions
|
@ -338,7 +338,7 @@ void EditGCodeDialog::selection_changed(wxDataViewEvent& evt)
|
|||
// Orca: move below checking for def in custom defined gcode placeholders
|
||||
// This allows custom placeholders to override the default ones for this dialog
|
||||
// Override custom def if selection is within the preset category
|
||||
if (!def || unbold(m_params_list->GetSelectedTopLevelCategory()) == "Presets") {
|
||||
if (!def || m_params_list->GetSelectedTopLevelCategory() == "Presets") {
|
||||
const auto& full_config = wxGetApp().preset_bundle->full_config();
|
||||
if (const ConfigDef* config_def = full_config.def(); config_def && config_def->has(opt_key)) {
|
||||
def = config_def->get(opt_key);
|
||||
|
@ -510,6 +510,13 @@ static void make_bold(wxString& str)
|
|||
#endif
|
||||
}
|
||||
|
||||
static void highlight(wxString& str)
|
||||
{
|
||||
#if defined(SUPPORTS_MARKUP) && !defined(__APPLE__)
|
||||
str = format_wxstr("<span bgcolor=\"#009688\">%1%</span>", str);
|
||||
#endif
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ParamsModelNode: a node inside ParamsModel
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -518,8 +525,8 @@ ParamsNode::ParamsNode(const wxString& group_name, const std::string& icon_name,
|
|||
: icon_name(icon_name)
|
||||
, text(group_name)
|
||||
, m_ctrl(ctrl)
|
||||
, m_bold(true)
|
||||
{
|
||||
make_bold(text);
|
||||
}
|
||||
|
||||
ParamsNode::ParamsNode( ParamsNode * parent,
|
||||
|
@ -530,8 +537,8 @@ ParamsNode::ParamsNode( ParamsNode * parent,
|
|||
, icon_name(icon_name)
|
||||
, text(sub_group_name)
|
||||
, m_ctrl(ctrl)
|
||||
, m_bold(true)
|
||||
{
|
||||
make_bold(text);
|
||||
}
|
||||
|
||||
ParamsNode::ParamsNode( ParamsNode* parent,
|
||||
|
@ -553,6 +560,22 @@ ParamsNode::ParamsNode( ParamsNode* parent,
|
|||
icon_name = ParamsInfo.at(param_type);
|
||||
}
|
||||
|
||||
wxString ParamsNode::GetFormattedText()
|
||||
{
|
||||
wxString formatted_text(text);
|
||||
if (m_highlight_index) {
|
||||
wxString substr = formatted_text.substr(m_highlight_index->first, m_highlight_index->second);
|
||||
formatted_text = formatted_text.Remove(m_highlight_index->first, m_highlight_index->second);
|
||||
highlight(substr);
|
||||
formatted_text.insert(m_highlight_index->first, substr);
|
||||
}
|
||||
|
||||
if (m_bold)
|
||||
make_bold(formatted_text);
|
||||
|
||||
return formatted_text;
|
||||
}
|
||||
|
||||
void ParamsNode::StartSearch()
|
||||
{
|
||||
const wxDataViewItem item(this);
|
||||
|
@ -569,10 +592,12 @@ void ParamsNode::RefreshSearch(const wxString& search_text)
|
|||
child->RefreshSearch(search_text);
|
||||
|
||||
if (GetEnabledChildren().empty())
|
||||
if (IsParamNode() && text.find(search_text) != wxString::npos)
|
||||
if (auto pos = text.find(search_text); IsParamNode() && pos != wxString::npos) {
|
||||
m_highlight_index = make_unique<pair<int, int>>(pos, search_text.Len());
|
||||
Enable();
|
||||
else
|
||||
} else {
|
||||
Disable();
|
||||
}
|
||||
else
|
||||
Enable();
|
||||
}
|
||||
|
@ -580,6 +605,7 @@ void ParamsNode::RefreshSearch(const wxString& search_text)
|
|||
void ParamsNode::FinishSearch()
|
||||
{
|
||||
Enable();
|
||||
m_highlight_index.reset();
|
||||
const wxDataViewItem item(this);
|
||||
if (!GetChildren().empty())
|
||||
for (const auto& child : GetChildren())
|
||||
|
@ -760,15 +786,15 @@ void ParamsModel::GetValue(wxVariant& variant, const wxDataViewItem& item, unsig
|
|||
ParamsNode* node = static_cast<ParamsNode*>(item.GetID());
|
||||
if (col == (unsigned int)0)
|
||||
#ifdef __linux__
|
||||
// variant << wxDataViewIconText(node->text, get_bmp_bundle(node->icon_name)->GetIconFor(m_ctrl->GetParent())); //TODO: update to bundle with wx update
|
||||
// variant << wxDataViewIconText(node->GetFormattedText(), get_bmp_bundle(node->icon_name)->GetIconFor(m_ctrl->GetParent())); //TODO: update to bundle with wx update
|
||||
{
|
||||
wxIcon icon;
|
||||
icon.CopyFromBitmap(create_scaled_bitmap(node->icon_name, m_ctrl->GetParent()));
|
||||
wxDataViewIconText(node->text, icon);
|
||||
wxDataViewIconText(node->GetFormattedText(), icon);
|
||||
}
|
||||
#else
|
||||
// variant << DataViewBitmapText(node->text, get_bmp_bundle(node->icon_name)->GetBitmapFor(m_ctrl->GetParent())); //TODO: update to bundle with wx update
|
||||
variant << DataViewBitmapText(node->text, create_scaled_bitmap(node->icon_name, m_ctrl->GetParent()));
|
||||
// variant << DataViewBitmapText(node->GetFormattedText(), get_bmp_bundle(node->icon_name)->GetBitmapFor(m_ctrl->GetParent())); //TODO: update to bundle with wx update
|
||||
variant << DataViewBitmapText(node->GetFormattedText(), create_scaled_bitmap(node->icon_name, m_ctrl->GetParent()));
|
||||
#endif //__linux__
|
||||
else
|
||||
wxLogError("DiffModel::GetValue: wrong column %d", col);
|
||||
|
|
|
@ -113,6 +113,10 @@ class ParamsNode
|
|||
bool m_expanded_before_search{false};
|
||||
bool m_enabled{true};
|
||||
|
||||
bool m_bold{false};
|
||||
// first is pos, second is length
|
||||
std::unique_ptr<std::pair<int, int>> m_highlight_index{nullptr};
|
||||
|
||||
public:
|
||||
|
||||
#ifdef __linux__
|
||||
|
@ -139,6 +143,8 @@ public:
|
|||
const std::string& param_key,
|
||||
wxDataViewCtrl* ctrl);
|
||||
|
||||
wxString GetFormattedText();
|
||||
|
||||
bool IsContainer() const { return m_container; }
|
||||
bool IsGroupNode() const { return m_parent == nullptr; }
|
||||
bool IsParamNode() const { return m_param_type != ParamType::Undef; }
|
||||
|
@ -257,11 +263,6 @@ public:
|
|||
void set_em_unit(int em) { m_em_unit = em; }
|
||||
};
|
||||
|
||||
static std::string unbold(const std::string& text) {
|
||||
return text.substr(text.find("<b>")+3, text.find("</b>")-3);
|
||||
}
|
||||
|
||||
|
||||
} // namespace GUI
|
||||
} // namespace Slic3r
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue