From 98bc89cb39176f5e65c4cbe83e7105573ed6122e Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 24 Dec 2023 14:51:47 +0100 Subject: [PATCH] impr: Make sure all views are closed before loading new workspace or layout --- lib/libimhex/include/hex/api/layout_manager.hpp | 5 +++++ lib/libimhex/source/api/layout_manager.cpp | 11 +++++++++++ lib/libimhex/source/api/workspace_manager.cpp | 1 + 3 files changed, 17 insertions(+) diff --git a/lib/libimhex/include/hex/api/layout_manager.hpp b/lib/libimhex/include/hex/api/layout_manager.hpp index 650f7cb4d..78e761a80 100644 --- a/lib/libimhex/include/hex/api/layout_manager.hpp +++ b/lib/libimhex/include/hex/api/layout_manager.hpp @@ -71,6 +71,11 @@ namespace hex { */ static void lockLayout(bool locked); + /** + * @brief Closes all views + */ + static void closeAllViews(); + private: LayoutManager() = default; }; diff --git a/lib/libimhex/source/api/layout_manager.cpp b/lib/libimhex/source/api/layout_manager.cpp index 2c065b2a4..d48473065 100644 --- a/lib/libimhex/source/api/layout_manager.cpp +++ b/lib/libimhex/source/api/layout_manager.cpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace hex { @@ -64,16 +65,26 @@ namespace hex { return s_layouts; } + void LayoutManager::closeAllViews() { + for (const auto &[name, view] : ContentRegistry::Views::impl::getEntries()) + view->getWindowOpenState() = false; + } + void LayoutManager::process() { if (s_layoutPathToLoad.has_value()) { const auto pathString = wolv::util::toUTF8String(*s_layoutPathToLoad); + + LayoutManager::closeAllViews(); ImGui::LoadIniSettingsFromDisk(pathString.c_str()); + s_layoutPathToLoad = std::nullopt; log::info("Loaded layout from {}", pathString); } if (s_layoutStringToLoad.has_value()) { + LayoutManager::closeAllViews(); ImGui::LoadIniSettingsFromMemory(s_layoutStringToLoad->c_str()); + s_layoutStringToLoad = std::nullopt; log::info("Loaded layout from string"); } diff --git a/lib/libimhex/source/api/workspace_manager.cpp b/lib/libimhex/source/api/workspace_manager.cpp index 59e9a1d6c..edf1087a3 100644 --- a/lib/libimhex/source/api/workspace_manager.cpp +++ b/lib/libimhex/source/api/workspace_manager.cpp @@ -89,6 +89,7 @@ namespace hex { if (s_previousWorkspace != s_workspaces.end()) exportToFile(s_previousWorkspace->second.path, s_previousWorkspace->first); + LayoutManager::closeAllViews(); ImGui::LoadIniSettingsFromMemory(s_currentWorkspace->second.layout.c_str()); s_previousWorkspace = s_currentWorkspace;