diff --git a/plugins/ui/include/ui/pattern_drawer.hpp b/plugins/ui/include/ui/pattern_drawer.hpp index 9eae7ef6d..9dddd4442 100644 --- a/plugins/ui/include/ui/pattern_drawer.hpp +++ b/plugins/ui/include/ui/pattern_drawer.hpp @@ -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> &patterns, std::vector> &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> 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; diff --git a/plugins/ui/romfs/lang/en_US.json b/plugins/ui/romfs/lang/en_US.json index ebad11c37..b0ee75a2d 100644 --- a/plugins/ui/romfs/lang/en_US.json +++ b/plugins/ui/romfs/lang/en_US.json @@ -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" } diff --git a/plugins/ui/source/ui/pattern_drawer.cpp b/plugins/ui/source/ui/pattern_drawer.cpp index aa68589fc..75b3ab3cf 100644 --- a/plugins/ui/source/ui/pattern_drawer.cpp +++ b/plugins/ui/source/ui/pattern_drawer.cpp @@ -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(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);