impr: Make sure all views are closed before loading new workspace or layout

This commit is contained in:
WerWolv
2023-12-24 14:51:47 +01:00
parent d2d244ebc7
commit 98bc89cb39
3 changed files with 17 additions and 0 deletions

View File

@@ -71,6 +71,11 @@ namespace hex {
*/
static void lockLayout(bool locked);
/**
* @brief Closes all views
*/
static void closeAllViews();
private:
LayoutManager() = default;
};

View File

@@ -7,6 +7,7 @@
#include <imgui.h>
#include <hex/api/content_registry.hpp>
#include <hex/api/imhex_api.hpp>
#include <hex/ui/view.hpp>
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");
}

View File

@@ -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;