mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 05:27:41 -05:00
impr: Added clip library to improve clipboard situation
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include <wolv/utils/string.hpp>
|
||||
|
||||
#include <ranges>
|
||||
#include <hex/helpers/clipboard.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
@@ -279,7 +280,7 @@ namespace hex::plugin::builtin {
|
||||
const auto providerSize = m_selectedProvider->getActualSize();
|
||||
const auto providerEndAddress = baseAddress + providerSize;
|
||||
|
||||
ImGui::BeginDisabled(providerSize < requiredSize || selection->getStartAddress() < baseAddress + requiredSize);
|
||||
ImGui::BeginDisabled(providerSize < requiredSize || (selection.has_value() && selection->getStartAddress() < baseAddress + requiredSize));
|
||||
if (ImGuiExt::DimmedIconButton(ICON_VS_ARROW_LEFT, ImGui::GetStyleColorVec4(ImGuiCol_Text), buttonSize)) {
|
||||
ImHexApi::HexEditor::setSelection(Region { selection->getStartAddress() - requiredSize, requiredSize });
|
||||
}
|
||||
@@ -287,7 +288,7 @@ namespace hex::plugin::builtin {
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::BeginDisabled(providerSize < requiredSize || selection->getEndAddress() > providerEndAddress - requiredSize);
|
||||
ImGui::BeginDisabled(providerSize < requiredSize || (selection.has_value() && selection->getEndAddress() > providerEndAddress - requiredSize));
|
||||
if (ImGuiExt::DimmedIconButton(ICON_VS_ARROW_RIGHT, ImGui::GetStyleColorVec4(ImGuiCol_Text), buttonSize)) {
|
||||
ImHexApi::HexEditor::setSelection(Region { selection->getStartAddress() + requiredSize, requiredSize });
|
||||
}
|
||||
@@ -436,7 +437,7 @@ namespace hex::plugin::builtin {
|
||||
|
||||
if (ImGui::BeginPopup("##DataInspectorRowContextMenu")) {
|
||||
if (ImGui::MenuItemEx("hex.builtin.view.data_inspector.menu.copy"_lang, ICON_VS_COPY)) {
|
||||
ImGui::SetClipboardText(copyValue.c_str());
|
||||
clipboard::setTextData(copyValue);
|
||||
}
|
||||
if (ImGui::MenuItemEx("hex.builtin.view.data_inspector.menu.edit"_lang, ICON_VS_EDIT, nullptr, false, editable)) {
|
||||
entry.editing = true;
|
||||
@@ -593,4 +594,4 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include <content/helpers/demangle.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
#include <hex/helpers/clipboard.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
@@ -648,9 +649,9 @@ namespace hex::plugin::builtin {
|
||||
|
||||
if (ImGui::BeginPopup("FindContextMenu")) {
|
||||
if (ImGui::MenuItemEx("hex.builtin.view.find.context.copy"_lang, ICON_VS_COPY))
|
||||
ImGui::SetClipboardText(value.c_str());
|
||||
clipboard::setTextData(value);
|
||||
if (ImGui::MenuItemEx("hex.builtin.view.find.context.copy_demangle"_lang, ICON_VS_FILES))
|
||||
ImGui::SetClipboardText(hex::plugin::builtin::demangle(value).c_str());
|
||||
clipboard::setTextData(hex::plugin::builtin::demangle(value));
|
||||
if (ImGui::BeginMenuEx("hex.builtin.view.find.context.replace"_lang, ICON_VS_REPLACE)) {
|
||||
if (ImGui::BeginTabBar("##replace_tabs")) {
|
||||
if (ImGui::BeginTabItem("hex.builtin.view.find.context.replace.hex"_lang)) {
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <popups/popup_file_chooser.hpp>
|
||||
#include <content/popups/popup_blocking_task.hpp>
|
||||
#include <content/popups/hex_editor/popup_hex_editor_find.hpp>
|
||||
#include <hex/helpers/clipboard.hpp>
|
||||
#include <pl/patterns/pattern.hpp>
|
||||
#include <hex/helpers/menu_items.hpp>
|
||||
#include <wolv/literals.hpp>
|
||||
@@ -744,7 +745,7 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
static void copyBytes(const Region &selection) {
|
||||
constexpr static auto Format = "{0:02X} ";
|
||||
//constexpr static auto Format = "{0:02X} ";
|
||||
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
if (provider == nullptr)
|
||||
@@ -754,33 +755,16 @@ namespace hex::plugin::builtin {
|
||||
reader.seek(selection.getStartAddress());
|
||||
reader.setEndAddress(selection.getEndAddress());
|
||||
|
||||
std::string result;
|
||||
result.reserve(fmt::format(Format, 0x00).size() * selection.getSize());
|
||||
|
||||
for (const auto &byte : reader)
|
||||
result += fmt::format(Format, byte);
|
||||
result.pop_back();
|
||||
|
||||
ImGui::SetClipboardText(result.c_str());
|
||||
auto bytes = std::vector(reader.begin(), reader.end());
|
||||
clipboard::setBinaryData(bytes);
|
||||
}
|
||||
|
||||
static void pasteBytes(const Region &selection, bool selectionCheck, bool asPlainText) {
|
||||
static void pasteBytes(const Region &selection, bool selectionCheck, bool) {
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
if (provider == nullptr)
|
||||
return;
|
||||
|
||||
auto clipboard = ImGui::GetClipboardText();
|
||||
if (clipboard == nullptr)
|
||||
return;
|
||||
|
||||
std::vector<u8> buffer;
|
||||
if (asPlainText) {
|
||||
// Directly reinterpret clipboard as an array of bytes
|
||||
std::string cp = clipboard;
|
||||
buffer = std::vector<u8>(cp.begin(), cp.end());
|
||||
}
|
||||
else
|
||||
buffer = parseHexString(clipboard);
|
||||
auto buffer = clipboard::getBinaryData();
|
||||
|
||||
if (!selectionCheck) {
|
||||
if (selection.getStartAddress() + buffer.size() >= provider->getActualSize())
|
||||
@@ -831,7 +815,7 @@ namespace hex::plugin::builtin {
|
||||
buffer.reserve(selection.size);
|
||||
provider->read(selection.getStartAddress(), buffer.data(), selection.size);
|
||||
|
||||
ImGui::SetClipboardText(buffer.c_str());
|
||||
clipboard::setTextData(buffer);
|
||||
}
|
||||
|
||||
static void copyCustomEncoding(const EncodingFile &customEncoding, const Region &selection) {
|
||||
@@ -851,7 +835,7 @@ namespace hex::plugin::builtin {
|
||||
offset += size;
|
||||
}
|
||||
|
||||
ImGui::SetClipboardText(string.c_str());
|
||||
clipboard::setTextData(string);
|
||||
}
|
||||
|
||||
void ViewHexEditor::registerShortcuts() {
|
||||
@@ -1264,7 +1248,7 @@ namespace hex::plugin::builtin {
|
||||
[] {
|
||||
auto selection = ImHexApi::HexEditor::getSelection();
|
||||
if (selection.has_value() && selection != Region::Invalid())
|
||||
ImGui::SetClipboardText(hex::format("0x{:08X}", selection->getStartAddress()).c_str());
|
||||
clipboard::setTextData(hex::format("0x{:08X}", selection->getStartAddress()));
|
||||
},
|
||||
ImHexApi::HexEditor::isSelectionValid);
|
||||
|
||||
@@ -1291,7 +1275,7 @@ namespace hex::plugin::builtin {
|
||||
bool enabled = ImHexApi::HexEditor::isSelectionValid();
|
||||
for (const auto &[unlocalizedName, callback] : ContentRegistry::DataFormatter::impl::getExportMenuEntries()) {
|
||||
if (menu::menuItem(Lang(unlocalizedName), Shortcut::None, false, enabled)) {
|
||||
ImGui::SetClipboardText(
|
||||
clipboard::setTextData(
|
||||
callback(
|
||||
provider,
|
||||
selection->getStartAddress(),
|
||||
|
||||
Reference in New Issue
Block a user