1
0
mirror of synced 2024-11-24 15:50:16 +01:00

feat: Added pattern data filter field

This commit is contained in:
WerWolv 2023-06-04 16:13:46 +02:00
parent 100b9e3bca
commit 244e34ab84
3 changed files with 53 additions and 2 deletions

View File

@ -645,7 +645,7 @@ namespace ImGui {
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + frame_size.x);
bool value_changed = ImGui::InputTextEx(label, nullptr, buffer.data(), buffer.size() + 1, ImVec2(CalcItemWidth() - frame_size.x, label_size.y + style.FramePadding.y * 2.0f), ImGuiInputTextFlags_CallbackResize | flags, ImGui::UpdateStringSizeCallback, &buffer);
bool value_changed = ImGui::InputTextEx(label, nullptr, buffer.data(), buffer.size() + 1, ImVec2(CalcItemWidth(), label_size.y + style.FramePadding.y * 2.0f), ImGuiInputTextFlags_CallbackResize | flags, ImGui::UpdateStringSizeCallback, &buffer);
if (value_changed)
MarkItemEdited(GImGui->LastItemData.ID);

View File

@ -63,6 +63,7 @@ namespace hex::plugin::builtin::ui {
bool isEditingPattern(const pl::ptrn::Pattern& pattern) const;
void resetEditing();
bool matchesFilter(const std::vector<std::string> &filterPath);
private:
std::map<const pl::ptrn::Pattern*, u64> m_displayEnd;
@ -77,6 +78,9 @@ namespace hex::plugin::builtin::ui {
std::set<pl::ptrn::Pattern*> m_visualizedPatterns;
std::string m_lastVisualizerError;
std::string m_filterText;
std::vector<std::string> m_filter;
std::vector<pl::ptrn::Pattern*> m_currPatternPath;
std::function<void(Region)> m_selectionCallback = [](Region) { };
};
}

View File

@ -164,6 +164,28 @@ namespace hex::plugin::builtin::ui {
}
}
std::vector<std::string> parseRValueFilter(const std::string &filter) {
std::vector<std::string> result;
if (!filter.empty()) {
result.emplace_back();
for (char c : filter) {
if (c == '.')
result.emplace_back();
else if (c == '[') {
result.emplace_back();
result.back() += c;
} else if (c == ']') {
result.back() += c;
result.emplace_back();
} else
result.back() += c;
}
}
return result;
}
}
bool PatternDrawer::isEditingPattern(const pl::ptrn::Pattern& pattern) const {
@ -175,6 +197,20 @@ namespace hex::plugin::builtin::ui {
this->m_editingPatternOffset = 0x00;
}
bool PatternDrawer::matchesFilter(const std::vector<std::string> &filterPath) {
if (this->m_currPatternPath.size() <= filterPath.size()) {
for (ssize_t i = this->m_currPatternPath.size() - 1; i >= 0; i--) {
const auto &filter = filterPath[i];
if (this->m_currPatternPath[i]->getVariableName() != filter && !filter.empty() && filter != "*") {
return false;
}
}
}
return true;
}
void PatternDrawer::drawVisualizer(const std::vector<pl::core::Token::Literal> &arguments, pl::ptrn::Pattern &pattern, pl::ptrn::IIterable &iteratable, bool reset) {
auto visualizerName = arguments.front().toString(true);
@ -732,7 +768,11 @@ namespace hex::plugin::builtin::ui {
if (pattern.getVisibility() == pl::ptrn::Visibility::Hidden)
return;
pattern.accept(*this);
this->m_currPatternPath.push_back(&pattern);
ON_SCOPE_EXIT { this->m_currPatternPath.pop_back(); };
if (matchesFilter(this->m_filter))
pattern.accept(*this);
}
void PatternDrawer::drawArray(pl::ptrn::Pattern& pattern, pl::ptrn::IIterable &iteratable, bool isInlined) {
@ -932,6 +972,12 @@ namespace hex::plugin::builtin::ui {
this->resetEditing();
}
ImGui::PushItemWidth(-1);
if (ImGui::InputTextIcon("##Search", ICON_VS_FILTER, this->m_filterText)) {
this->m_filter = parseRValueFilter(this->m_filterText);
}
ImGui::PopItemWidth();
if (beginPatternTable(patterns, this->m_sortedPatterns, height)) {
ImGui::TableHeadersRow();
@ -955,5 +1001,6 @@ namespace hex::plugin::builtin::ui {
this->m_currVisualizedPattern = nullptr;
this->m_sortedPatterns.clear();
this->m_lastVisualizerError.clear();
this->m_currPatternPath.clear();
}
}