mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 05:27:41 -05:00
feat: Allow jumping from hex editor to patterns and from patterns to source line
This commit is contained in:
@@ -31,10 +31,12 @@ namespace hex::ui {
|
||||
};
|
||||
|
||||
void setTreeStyle(TreeStyle style) { m_treeStyle = style; }
|
||||
void setSelectionCallback(std::function<void(Region)> callback) { m_selectionCallback = std::move(callback); }
|
||||
void setSelectionCallback(std::function<void(const pl::ptrn::Pattern *)> callback) { m_selectionCallback = std::move(callback); }
|
||||
void enableRowColoring(bool enabled) { m_rowColoring = enabled; }
|
||||
void reset();
|
||||
|
||||
void jumpToPattern(const pl::ptrn::Pattern *pattern) { m_jumpToPattern = pattern; }
|
||||
|
||||
private:
|
||||
void draw(pl::ptrn::Pattern& pattern);
|
||||
|
||||
@@ -100,6 +102,7 @@ namespace hex::ui {
|
||||
TreeStyle m_treeStyle = TreeStyle::Default;
|
||||
bool m_rowColoring = false;
|
||||
pl::ptrn::Pattern *m_currVisualizedPattern = nullptr;
|
||||
const pl::ptrn::Pattern *m_jumpToPattern = nullptr;
|
||||
|
||||
std::set<pl::ptrn::Pattern*> m_visualizedPatterns;
|
||||
std::string m_lastVisualizerError;
|
||||
@@ -115,7 +118,7 @@ namespace hex::ui {
|
||||
|
||||
TaskHolder m_favoritesUpdateTask;
|
||||
|
||||
std::function<void(Region)> m_selectionCallback = [](Region) { };
|
||||
std::function<void(const pl::ptrn::Pattern *)> m_selectionCallback = [](const pl::ptrn::Pattern *) { };
|
||||
|
||||
pl::gen::fmt::FormatterArray m_formatters;
|
||||
};
|
||||
|
||||
@@ -1032,7 +1032,7 @@ namespace hex::ui {
|
||||
this->setSelection(selectionStart.value_or(address), endAddress);
|
||||
this->scrollToSelection();
|
||||
}
|
||||
else if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
|
||||
else if (ImGui::IsMouseDown(ImGuiMouseButton_Left) || (ImGui::IsMouseDown(ImGuiMouseButton_Right) && (address < m_selectionStart || address > m_selectionEnd))) {
|
||||
if (ImGui::GetIO().KeyShift)
|
||||
this->setSelection(selectionStart.value_or(address), endAddress);
|
||||
else
|
||||
|
||||
@@ -342,6 +342,26 @@ namespace hex::ui {
|
||||
bool PatternDrawer::createTreeNode(const pl::ptrn::Pattern& pattern, bool leaf) {
|
||||
drawFavoriteColumn(pattern);
|
||||
|
||||
bool shouldOpen = false;
|
||||
if (m_jumpToPattern != nullptr) {
|
||||
if (m_jumpToPattern == &pattern) {
|
||||
ImGui::SetScrollHereY();
|
||||
m_jumpToPattern = nullptr;
|
||||
}
|
||||
else {
|
||||
auto parent = m_jumpToPattern->getParent();
|
||||
while (parent != nullptr) {
|
||||
if (&pattern == parent) {
|
||||
ImGui::SetScrollHereY();
|
||||
shouldOpen = true;
|
||||
break;
|
||||
}
|
||||
|
||||
parent = parent->getParent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pattern.isSealed() || leaf) {
|
||||
ImGui::Indent();
|
||||
highlightWhenSelected(pattern, [&]{ ImGui::TextUnformatted(this->getDisplayName(pattern).c_str()); });
|
||||
@@ -350,6 +370,9 @@ namespace hex::ui {
|
||||
}
|
||||
|
||||
return highlightWhenSelected(pattern, [&]{
|
||||
if (shouldOpen)
|
||||
ImGui::SetNextItemOpen(true, ImGuiCond_Always);
|
||||
|
||||
switch (m_treeStyle) {
|
||||
using enum TreeStyle;
|
||||
default:
|
||||
@@ -368,7 +391,7 @@ namespace hex::ui {
|
||||
ImGui::PushID(pattern.getVariableName().c_str());
|
||||
|
||||
if (ImGui::Selectable("##PatternLine", false, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowOverlap)) {
|
||||
m_selectionCallback(Region { pattern.getOffset(), pattern.getSize() });
|
||||
m_selectionCallback(&pattern);
|
||||
|
||||
if (m_editingPattern != &pattern) {
|
||||
this->resetEditing();
|
||||
|
||||
Reference in New Issue
Block a user