From 8e7bfb7f1a6b3537d24da5c22c20703f7adc1796 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 7 Feb 2021 14:29:13 +0100 Subject: [PATCH] Fixed some popups not appearing when no views are open --- include/views/view_hexeditor.hpp | 1 + include/views/view_pattern.hpp | 1 + plugins/libimhex/include/hex/views/view.hpp | 1 + source/views/view_hexeditor.cpp | 99 +++++++++++---------- source/views/view_pattern.cpp | 4 +- source/window.cpp | 4 +- 6 files changed, 59 insertions(+), 51 deletions(-) diff --git a/include/views/view_hexeditor.hpp b/include/views/view_hexeditor.hpp index d95aaec45..2f50ee126 100644 --- a/include/views/view_hexeditor.hpp +++ b/include/views/view_hexeditor.hpp @@ -25,6 +25,7 @@ namespace hex { ~ViewHexEditor() override; void drawContent() override; + void drawAlwaysVisible() override; void drawMenu() override; bool handleShortcut(int key, int mods) override; diff --git a/include/views/view_pattern.hpp b/include/views/view_pattern.hpp index 77cc38fd2..8331caef7 100644 --- a/include/views/view_pattern.hpp +++ b/include/views/view_pattern.hpp @@ -23,6 +23,7 @@ namespace hex { ~ViewPattern() override; void drawMenu() override; + void drawAlwaysVisible() override; void drawContent() override; private: diff --git a/plugins/libimhex/include/hex/views/view.hpp b/plugins/libimhex/include/hex/views/view.hpp index a9e859f19..60ded8641 100644 --- a/plugins/libimhex/include/hex/views/view.hpp +++ b/plugins/libimhex/include/hex/views/view.hpp @@ -21,6 +21,7 @@ namespace hex { virtual ~View() = default; virtual void drawContent() = 0; + virtual void drawAlwaysVisible() { } virtual void drawMenu(); virtual bool handleShortcut(int key, int mods); virtual bool isAvailable(); diff --git a/source/views/view_hexeditor.cpp b/source/views/view_hexeditor.cpp index 783115953..9b53aa531 100644 --- a/source/views/view_hexeditor.cpp +++ b/source/views/view_hexeditor.cpp @@ -206,7 +206,40 @@ namespace hex { this->drawSearchPopup(); this->drawGotoPopup(); } + } + static void save() { + auto provider = SharedData::currentProvider; + for (const auto &[address, value] : provider->getPatches()) + provider->writeRaw(address, &value, sizeof(u8)); + } + + static void saveAs() { + View::openFileBrowser("Save As", imgui_addons::ImGuiFileBrowser::DialogMode::SAVE, "*.*", [](auto path) { + FILE *file = fopen(path.c_str(), "wb"); + + if (file != nullptr) { + std::vector buffer(0xFF'FFFF, 0x00); + size_t bufferSize = buffer.size(); + + fseek(file, 0, SEEK_SET); + + auto provider = SharedData::currentProvider; + for (u64 offset = 0; offset < provider->getActualSize(); offset += bufferSize) { + if (bufferSize > provider->getActualSize() - offset) + bufferSize = provider->getActualSize() - offset; + + provider->read(offset, buffer.data(), bufferSize); + fwrite(buffer.data(), 1, bufferSize, file); + } + + fclose(file); + } + }); + } + + void ViewHexEditor::drawAlwaysVisible() { + auto provider = SharedData::currentProvider; if (ImGui::BeginPopupModal("Save Changes", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { constexpr auto Message = "You have unsaved changes made to your Project.\nAre you sure you want to exit?"; @@ -248,18 +281,18 @@ namespace hex { ImGui::NewLine(); confirmButtons("Load", "Cancel", - [this, &provider] { - if (!this->m_loaderScriptScriptPath.empty() && !this->m_loaderScriptFilePath.empty()) { - this->openFile(this->m_loaderScriptFilePath); - LoaderScript::setFilePath(this->m_loaderScriptFilePath); - LoaderScript::setDataProvider(provider); - LoaderScript::processFile(this->m_loaderScriptScriptPath); - ImGui::CloseCurrentPopup(); - } - }, - [] { - ImGui::CloseCurrentPopup(); - } + [this, &provider] { + if (!this->m_loaderScriptScriptPath.empty() && !this->m_loaderScriptFilePath.empty()) { + this->openFile(this->m_loaderScriptFilePath); + LoaderScript::setFilePath(this->m_loaderScriptFilePath); + LoaderScript::setDataProvider(provider); + LoaderScript::processFile(this->m_loaderScriptScriptPath); + ImGui::CloseCurrentPopup(); + } + }, + [] { + ImGui::CloseCurrentPopup(); + } ); ImGui::EndPopup(); @@ -271,12 +304,12 @@ namespace hex { ImGui::NewLine(); confirmButtons("Set", "Cancel", - [this, &provider]{ - provider->setBaseAddress(strtoull(this->m_baseAddressBuffer, nullptr, 16)); - ImGui::CloseCurrentPopup(); - }, []{ - ImGui::CloseCurrentPopup(); - }); + [this, &provider]{ + provider->setBaseAddress(strtoull(this->m_baseAddressBuffer, nullptr, 16)); + ImGui::CloseCurrentPopup(); + }, []{ + ImGui::CloseCurrentPopup(); + }); if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Escape))) ImGui::CloseCurrentPopup(); @@ -285,36 +318,6 @@ namespace hex { } } - static void save() { - auto provider = SharedData::currentProvider; - for (const auto &[address, value] : provider->getPatches()) - provider->writeRaw(address, &value, sizeof(u8)); - } - - static void saveAs() { - View::openFileBrowser("Save As", imgui_addons::ImGuiFileBrowser::DialogMode::SAVE, "*.*", [](auto path) { - FILE *file = fopen(path.c_str(), "wb"); - - if (file != nullptr) { - std::vector buffer(0xFF'FFFF, 0x00); - size_t bufferSize = buffer.size(); - - fseek(file, 0, SEEK_SET); - - auto provider = SharedData::currentProvider; - for (u64 offset = 0; offset < provider->getActualSize(); offset += bufferSize) { - if (bufferSize > provider->getActualSize() - offset) - bufferSize = provider->getActualSize() - offset; - - provider->read(offset, buffer.data(), bufferSize); - fwrite(buffer.data(), 1, bufferSize, file); - } - - fclose(file); - } - }); - }; - void ViewHexEditor::drawMenu() { auto provider = SharedData::currentProvider; diff --git a/source/views/view_pattern.cpp b/source/views/view_pattern.cpp index 49073d93d..25b5b02ce 100644 --- a/source/views/view_pattern.cpp +++ b/source/views/view_pattern.cpp @@ -257,9 +257,9 @@ namespace hex { View::discardNavigationRequests(); } ImGui::End(); + } - - + void ViewPattern::drawAlwaysVisible() { if (ImGui::BeginPopupModal("Accept Pattern", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { ImGui::TextWrapped("One or more patterns compatible with this data type has been found"); diff --git a/source/window.cpp b/source/window.cpp index 1878c8368..075f164e5 100644 --- a/source/window.cpp +++ b/source/window.cpp @@ -148,6 +148,8 @@ namespace hex { View::getDeferedCalls().clear(); for (auto &view : ContentRegistry::Views::getEntries()) { + view->drawAlwaysVisible(); + if (!view->isAvailable() || !view->getWindowOpenState()) continue; @@ -275,7 +277,7 @@ namespace hex { for (auto &view : ContentRegistry::Views::getEntries()) anyViewOpen = anyViewOpen || (view->getWindowOpenState() && view->isAvailable()); - if (!anyViewOpen) { + if (!anyViewOpen && SharedData::currentProvider == nullptr) { char title[256]; ImFormatString(title, IM_ARRAYSIZE(title), "%s/DockSpace_%08X", ImGui::GetCurrentWindow()->Name, ImGui::GetID("MainDock")); if (ImGui::Begin(title)) {