From 55e24b5e23458e2e50224cf7349b7a32b75adb3c Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 9 Jun 2024 10:28:58 +0200 Subject: [PATCH] fix: Bookmarks not being correctly reorderable anymore Fixes #1745 --- .../source/content/views/view_bookmarks.cpp | 71 ++++++++++--------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/plugins/builtin/source/content/views/view_bookmarks.cpp b/plugins/builtin/source/content/views/view_bookmarks.cpp index 83f279d17..2410ba8d0 100644 --- a/plugins/builtin/source/content/views/view_bookmarks.cpp +++ b/plugins/builtin/source/content/views/view_bookmarks.cpp @@ -35,7 +35,7 @@ namespace hex::plugin::builtin { if (id != nullptr) *id = bookmarkId; - auto bookmark = ImHexApi::Bookmarks::Entry{ + auto bookmark = ImHexApi::Bookmarks::Entry { region, name, std::move(comment), @@ -286,38 +286,6 @@ namespace hex::plugin::builtin { bool notDeleted = true; auto expanded = ImGui::CollapsingHeader(hex::format("{}###bookmark", name).c_str(), ¬Deleted); - auto nextPos = ImGui::GetCursorPos(); - - ImGui::SameLine(); - ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 70_scaled); - - { - // Draw jump to region button - if (ImGuiExt::DimmedIconButton(ICON_VS_DEBUG_STEP_BACK, ImGui::GetStyleColorVec4(ImGuiCol_Text))) - ImHexApi::HexEditor::setSelection(region); - ImGuiExt::InfoTooltip("hex.builtin.view.bookmarks.tooltip.jump_to"_lang); - - ImGui::SameLine(0, 1_scaled); - - // Draw open in new view button - if (ImGuiExt::DimmedIconButton(ICON_VS_GO_TO_FILE, ImGui::GetStyleColorVec4(ImGuiCol_Text))) { - TaskManager::doLater([region, provider]{ - auto newProvider = ImHexApi::Provider::createProvider("hex.builtin.provider.view", true); - if (auto *viewProvider = dynamic_cast(newProvider); viewProvider != nullptr) { - viewProvider->setProvider(region.getStartAddress(), region.getSize(), provider); - if (viewProvider->open()) { - EventProviderOpened::post(viewProvider); - AchievementManager::unlockAchievement("hex.builtin.achievement.hex_editor", "hex.builtin.achievement.hex_editor.open_new_view.name"); - } - } - }); - } - ImGuiExt::InfoTooltip("hex.builtin.view.bookmarks.tooltip.open_in_view"_lang); - } - - ImGui::SetCursorPos(nextPos); - ImGui::Dummy({}); - if (!expanded) { // Handle dragging bookmarks up and down when they're collapsed @@ -354,12 +322,47 @@ namespace hex::plugin::builtin { // Swap the two bookmarks if (droppedIter != m_bookmarks->end()) { std::iter_swap(it, droppedIter); + EventHighlightingChanged::post(); } } ImGui::EndDragDropTarget(); } - } else { + } + + auto nextPos = ImGui::GetCursorPos(); + + ImGui::SameLine(); + ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 70_scaled); + + { + // Draw jump to region button + if (ImGuiExt::DimmedIconButton(ICON_VS_DEBUG_STEP_BACK, ImGui::GetStyleColorVec4(ImGuiCol_Text))) + ImHexApi::HexEditor::setSelection(region); + ImGuiExt::InfoTooltip("hex.builtin.view.bookmarks.tooltip.jump_to"_lang); + + ImGui::SameLine(0, 1_scaled); + + // Draw open in new view button + if (ImGuiExt::DimmedIconButton(ICON_VS_GO_TO_FILE, ImGui::GetStyleColorVec4(ImGuiCol_Text))) { + TaskManager::doLater([region, provider]{ + auto newProvider = ImHexApi::Provider::createProvider("hex.builtin.provider.view", true); + if (auto *viewProvider = dynamic_cast(newProvider); viewProvider != nullptr) { + viewProvider->setProvider(region.getStartAddress(), region.getSize(), provider); + if (viewProvider->open()) { + EventProviderOpened::post(viewProvider); + AchievementManager::unlockAchievement("hex.builtin.achievement.hex_editor", "hex.builtin.achievement.hex_editor.open_new_view.name"); + } + } + }); + } + ImGuiExt::InfoTooltip("hex.builtin.view.bookmarks.tooltip.open_in_view"_lang); + } + + ImGui::SetCursorPos(nextPos); + ImGui::Dummy({}); + + if (expanded) { const auto rowHeight = ImGui::GetTextLineHeightWithSpacing() + 2 * ImGui::GetStyle().FramePadding.y; if (ImGui::BeginTable("##bookmark_table", 3, ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit)) { ImGui::TableSetupColumn("##name");