1
0
mirror of synced 2024-11-12 02:00:52 +01:00

fix: Workspaces not always loading layout correctly

This commit is contained in:
WerWolv 2023-12-12 00:16:21 +01:00
parent 690b0df932
commit 1b457dae7d
6 changed files with 32 additions and 33 deletions

View File

@ -25,11 +25,13 @@ namespace hex {
static void reset();
static void process();
private:
WorkspaceManager() = default;
static std::map<std::string, WorkspaceManager::Workspace> s_workspaces;
static decltype(s_workspaces)::iterator s_currentWorkspace;
static decltype(s_workspaces)::iterator s_currentWorkspace, s_previousWorkspace;
};
}

View File

@ -6,12 +6,14 @@
#include <wolv/io/file.hpp>
#include <nlohmann/json.hpp>
#include <nlohmann/json_fwd.hpp>
#include <imgui.h>
namespace hex {
std::map<std::string, WorkspaceManager::Workspace> WorkspaceManager::s_workspaces;
decltype(WorkspaceManager::s_workspaces)::iterator WorkspaceManager::s_currentWorkspace = WorkspaceManager::s_workspaces.end();
decltype(WorkspaceManager::s_workspaces)::iterator WorkspaceManager::s_currentWorkspace = WorkspaceManager::s_workspaces.end();
decltype(WorkspaceManager::s_workspaces)::iterator WorkspaceManager::s_previousWorkspace = WorkspaceManager::s_workspaces.end();
void WorkspaceManager::createWorkspace(const std::string& name, const std::string &layout) {
s_workspaces[name] = Workspace {
@ -19,8 +21,6 @@ namespace hex {
.path = {}
};
WorkspaceManager::switchWorkspace(name);
for (const auto &path : fs::getDefaultPaths(fs::ImHexPath::Workspaces)) {
if (WorkspaceManager::exportToFile(path / (name + ".hexws")))
break;
@ -28,22 +28,12 @@ namespace hex {
}
void WorkspaceManager::switchWorkspace(const std::string& name) {
if (s_currentWorkspace != s_workspaces.end()) {
auto &[name, workspace] = *s_currentWorkspace;
workspace.layout = LayoutManager::saveToString();
auto newWorkspace = s_workspaces.find(name);
WorkspaceManager::exportToFile(workspace.path);
if (newWorkspace != s_workspaces.end()) {
s_currentWorkspace = newWorkspace;
log::info("Switching to workspace '{}'", name);
}
auto it = s_workspaces.find(name);
if (it == s_workspaces.end()) {
log::error("Failed to switch workspace. Workspace '{}' does not exist", name);
return;
}
auto &[newName, newWorkspace] = *it;
s_currentWorkspace = it;
LayoutManager::loadFromString(newWorkspace.layout);
}
void WorkspaceManager::importFromFile(const std::fs::path& path) {
@ -92,9 +82,22 @@ namespace hex {
}
void WorkspaceManager::process() {
if (s_previousWorkspace != s_currentWorkspace) {
if (s_previousWorkspace != s_workspaces.end())
WorkspaceManager::exportToFile(s_previousWorkspace->second.path);
ImGui::LoadIniSettingsFromMemory(s_currentWorkspace->second.layout.c_str());
s_previousWorkspace = s_currentWorkspace;
}
}
void WorkspaceManager::reset() {
s_workspaces.clear();
s_currentWorkspace = WorkspaceManager::s_workspaces.end();
s_currentWorkspace = WorkspaceManager::s_workspaces.end();
s_previousWorkspace = WorkspaceManager::s_workspaces.end();
}

View File

@ -66,8 +66,6 @@ namespace hex {
bool m_frameRateTemporarilyUnlocked = false;
double m_frameRateUnlockTime = 0;
bool m_anyViewsOpen = false;
ImGuiExt::ImHexCustomData m_imguiCustomData;
};

View File

@ -760,8 +760,6 @@ namespace hex {
void Window::frame() {
auto &io = ImGui::GetIO();
this->m_anyViewsOpen = ImHexApi::Provider::isValid();
// Loop through all views and draw them
for (auto &[name, view] : ContentRegistry::Views::impl::getEntries()) {
ImGui::GetCurrentContext()->NextWindowData.ClearFlags();
@ -854,8 +852,8 @@ namespace hex {
// Process layout load requests
// NOTE: This needs to be done before a new frame is started, otherwise ImGui won't handle docking correctly
if (this->m_anyViewsOpen)
LayoutManager::process();
LayoutManager::process();
WorkspaceManager::process();
}
void Window::initGLFW() {

View File

@ -528,11 +528,6 @@ namespace hex::plugin::builtin {
}
});
EventProviderCreated::subscribe([](auto) {
if (!isAnyViewOpen())
loadDefaultLayout();
});
EventWindowInitialized::subscribe([] {
// Documentation of the value above the setting definition
auto allowServerContact = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.server_contact", 2);

View File

@ -1,8 +1,8 @@
#include <hex/api/content_registry.hpp>
#include <hex/api/task_manager.hpp>
#include <hex/api/workspace_manager.hpp>
#include <hex/helpers/fs.hpp>
#include <wolv/utils/guards.hpp>
namespace hex::plugin::builtin {
@ -21,7 +21,10 @@ namespace hex::plugin::builtin {
}
std::string currentWorkspace = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.curr_workspace", "Default");
WorkspaceManager::switchWorkspace(currentWorkspace);
TaskManager::doLater([currentWorkspace] {
WorkspaceManager::switchWorkspace(currentWorkspace);
});
}
}