feat: Added pattern context menu for copy and edit

This commit is contained in:
WerWolv 2025-12-01 21:25:57 +01:00
parent d610f787b9
commit da755ec75b
3 changed files with 34 additions and 7 deletions

View File

@ -77,17 +77,17 @@ namespace hex::ui {
void drawArray(pl::ptrn::Pattern& pattern, pl::ptrn::IIterable &iterable, bool isInlined);
u64& getDisplayEnd(const pl::ptrn::Pattern& pattern);
void makeSelectable(const pl::ptrn::Pattern &pattern);
void makeSelectable(pl::ptrn::Pattern &pattern);
void drawValueColumn(pl::ptrn::Pattern& pattern);
void drawFavoriteColumn(const pl::ptrn::Pattern& pattern);
bool drawNameColumn(const pl::ptrn::Pattern &pattern, bool leaf = false);
bool drawNameColumn(pl::ptrn::Pattern &pattern, bool leaf = false);
void drawColorColumn(const pl::ptrn::Pattern& pattern);
void drawCommentColumn(const pl::ptrn::Pattern& pattern);
bool beginPatternTable(const std::vector<std::shared_ptr<pl::ptrn::Pattern>> &patterns, std::vector<std::shared_ptr<pl::ptrn::Pattern>> &sortedPatterns, float height) const;
bool createTreeNode(const pl::ptrn::Pattern& pattern, bool leaf = false);
void createDefaultEntry(const pl::ptrn::Pattern &pattern);
void createDefaultEntry(pl::ptrn::Pattern &pattern);
void closeTreeNode(bool inlined) const;
bool sortPatterns(const ImGuiTableSortSpecs* sortSpecs, const pl::ptrn::Pattern * left, const pl::ptrn::Pattern * right) const;
@ -117,6 +117,7 @@ namespace hex::ui {
std::vector<std::shared_ptr<pl::ptrn::Pattern>> m_sortedPatterns;
const pl::ptrn::Pattern *m_editingPattern = nullptr;
const pl::ptrn::Pattern *m_contextMenuPattern = nullptr;
u64 m_editingPatternOffset = 0;
hex::ui::VisualizerDrawer m_visualizerDrawer;
hex::ui::PatternValueEditor m_valueEditor;

View File

@ -123,5 +123,10 @@
"hex.ui.diagram.byte_type_distribution.plain_text": "Plain Text",
"hex.ui.diagram.byte_type_distribution.similar_bytes": "Similar Bytes",
"hex.ui.diagram.entropy_analysis.entropy_drop": "Large Entropy Drop",
"hex.ui.diagram.entropy_analysis.entropy_spike": "Large Entropy Spike"
"hex.ui.diagram.entropy_analysis.entropy_spike": "Large Entropy Spike",
"hex.ui.pattern_drawer.context.copy_name": "Copy Name",
"hex.ui.pattern_drawer.context.copy_value": "Copy Value",
"hex.ui.pattern_drawer.context.copy_address": "Copy Address",
"hex.ui.pattern_drawer.context.copy_comment": "Copy Comment",
"hex.ui.pattern_drawer.context.edit_value": "Edit Value"
}

View File

@ -393,7 +393,7 @@ namespace hex::ui {
ImGui::PopStyleVar();
}
bool PatternDrawer::drawNameColumn(const pl::ptrn::Pattern &pattern, bool leaf) {
bool PatternDrawer::drawNameColumn(pl::ptrn::Pattern &pattern, bool leaf) {
bool open = createTreeNode(pattern, leaf);
ImGui::SameLine(0, 0);
makeSelectable(pattern);
@ -550,7 +550,7 @@ namespace hex::ui {
});
}
void PatternDrawer::makeSelectable(const pl::ptrn::Pattern &pattern) {
void PatternDrawer::makeSelectable(pl::ptrn::Pattern &pattern) {
ImGui::PushID(static_cast<int>(pattern.getOffset()));
ImGui::PushID(pattern.getVariableName().c_str());
@ -572,13 +572,34 @@ namespace hex::ui {
}
}
if (ImGui::BeginPopupContextItem(nullptr)) {
if (ImGui::MenuItemEx("hex.ui.pattern_drawer.context.copy_name"_lang, ICON_VS_COPY, nullptr, false, true))
ImGui::SetClipboardText(pattern.getDisplayName().c_str());
if (ImGui::MenuItem("hex.ui.pattern_drawer.context.copy_address"_lang, nullptr, false, true))
ImGui::SetClipboardText(fmt::format("0x{:02X}", pattern.getOffset()).c_str());
if (ImGui::MenuItem("hex.ui.pattern_drawer.context.copy_value"_lang, nullptr, false, true))
ImGui::SetClipboardText(pattern.toString().c_str());
if (ImGui::MenuItem("hex.ui.pattern_drawer.context.copy_comment"_lang, nullptr, false, !pattern.getComment().empty()))
ImGui::SetClipboardText(pattern.getComment().c_str());
ImGui::Separator();
if (ImGui::MenuItemEx("hex.ui.pattern_drawer.context.edit_value"_lang, ICON_VS_EDIT)) {
m_editingPattern = &pattern;
m_editingPatternOffset = pattern.getOffset();
AchievementManager::unlockAchievement("hex.builtin.achievement.patterns", "hex.builtin.achievement.patterns.modify_data.name");
}
ImGui::EndPopup();
}
ImGui::SameLine(0, 0);
ImGui::PopID();
ImGui::PopID();
}
void PatternDrawer::createDefaultEntry(const pl::ptrn::Pattern &pattern) {
void PatternDrawer::createDefaultEntry(pl::ptrn::Pattern &pattern) {
// Draw Name column
drawNameColumn(pattern, true);