fix: Workspaces not always loading layout correctly
This commit is contained in:
parent
690b0df932
commit
1b457dae7d
@ -25,11 +25,13 @@ namespace hex {
|
|||||||
|
|
||||||
static void reset();
|
static void reset();
|
||||||
|
|
||||||
|
static void process();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WorkspaceManager() = default;
|
WorkspaceManager() = default;
|
||||||
|
|
||||||
static std::map<std::string, WorkspaceManager::Workspace> s_workspaces;
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
@ -6,12 +6,14 @@
|
|||||||
#include <wolv/io/file.hpp>
|
#include <wolv/io/file.hpp>
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <nlohmann/json_fwd.hpp>
|
|
||||||
|
#include <imgui.h>
|
||||||
|
|
||||||
namespace hex {
|
namespace hex {
|
||||||
|
|
||||||
std::map<std::string, WorkspaceManager::Workspace> WorkspaceManager::s_workspaces;
|
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) {
|
void WorkspaceManager::createWorkspace(const std::string& name, const std::string &layout) {
|
||||||
s_workspaces[name] = Workspace {
|
s_workspaces[name] = Workspace {
|
||||||
@ -19,8 +21,6 @@ namespace hex {
|
|||||||
.path = {}
|
.path = {}
|
||||||
};
|
};
|
||||||
|
|
||||||
WorkspaceManager::switchWorkspace(name);
|
|
||||||
|
|
||||||
for (const auto &path : fs::getDefaultPaths(fs::ImHexPath::Workspaces)) {
|
for (const auto &path : fs::getDefaultPaths(fs::ImHexPath::Workspaces)) {
|
||||||
if (WorkspaceManager::exportToFile(path / (name + ".hexws")))
|
if (WorkspaceManager::exportToFile(path / (name + ".hexws")))
|
||||||
break;
|
break;
|
||||||
@ -28,22 +28,12 @@ namespace hex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WorkspaceManager::switchWorkspace(const std::string& name) {
|
void WorkspaceManager::switchWorkspace(const std::string& name) {
|
||||||
if (s_currentWorkspace != s_workspaces.end()) {
|
auto newWorkspace = s_workspaces.find(name);
|
||||||
auto &[name, workspace] = *s_currentWorkspace;
|
|
||||||
workspace.layout = LayoutManager::saveToString();
|
|
||||||
|
|
||||||
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) {
|
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() {
|
void WorkspaceManager::reset() {
|
||||||
s_workspaces.clear();
|
s_workspaces.clear();
|
||||||
s_currentWorkspace = WorkspaceManager::s_workspaces.end();
|
s_currentWorkspace = WorkspaceManager::s_workspaces.end();
|
||||||
|
s_previousWorkspace = WorkspaceManager::s_workspaces.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,8 +66,6 @@ namespace hex {
|
|||||||
bool m_frameRateTemporarilyUnlocked = false;
|
bool m_frameRateTemporarilyUnlocked = false;
|
||||||
double m_frameRateUnlockTime = 0;
|
double m_frameRateUnlockTime = 0;
|
||||||
|
|
||||||
bool m_anyViewsOpen = false;
|
|
||||||
|
|
||||||
ImGuiExt::ImHexCustomData m_imguiCustomData;
|
ImGuiExt::ImHexCustomData m_imguiCustomData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -760,8 +760,6 @@ namespace hex {
|
|||||||
void Window::frame() {
|
void Window::frame() {
|
||||||
auto &io = ImGui::GetIO();
|
auto &io = ImGui::GetIO();
|
||||||
|
|
||||||
this->m_anyViewsOpen = ImHexApi::Provider::isValid();
|
|
||||||
|
|
||||||
// Loop through all views and draw them
|
// Loop through all views and draw them
|
||||||
for (auto &[name, view] : ContentRegistry::Views::impl::getEntries()) {
|
for (auto &[name, view] : ContentRegistry::Views::impl::getEntries()) {
|
||||||
ImGui::GetCurrentContext()->NextWindowData.ClearFlags();
|
ImGui::GetCurrentContext()->NextWindowData.ClearFlags();
|
||||||
@ -854,8 +852,8 @@ namespace hex {
|
|||||||
|
|
||||||
// Process layout load requests
|
// Process layout load requests
|
||||||
// NOTE: This needs to be done before a new frame is started, otherwise ImGui won't handle docking correctly
|
// 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() {
|
void Window::initGLFW() {
|
||||||
|
@ -528,11 +528,6 @@ namespace hex::plugin::builtin {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
EventProviderCreated::subscribe([](auto) {
|
|
||||||
if (!isAnyViewOpen())
|
|
||||||
loadDefaultLayout();
|
|
||||||
});
|
|
||||||
|
|
||||||
EventWindowInitialized::subscribe([] {
|
EventWindowInitialized::subscribe([] {
|
||||||
// Documentation of the value above the setting definition
|
// Documentation of the value above the setting definition
|
||||||
auto allowServerContact = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.server_contact", 2);
|
auto allowServerContact = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.server_contact", 2);
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#include <hex/api/content_registry.hpp>
|
#include <hex/api/content_registry.hpp>
|
||||||
|
#include <hex/api/task_manager.hpp>
|
||||||
#include <hex/api/workspace_manager.hpp>
|
#include <hex/api/workspace_manager.hpp>
|
||||||
|
|
||||||
#include <hex/helpers/fs.hpp>
|
#include <hex/helpers/fs.hpp>
|
||||||
#include <wolv/utils/guards.hpp>
|
|
||||||
|
|
||||||
namespace hex::plugin::builtin {
|
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");
|
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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user