Preserve saved editor dock layouts

This commit is contained in:
2026-04-01 16:43:46 +08:00
parent 3f18530396
commit 6e2711f9e8
3 changed files with 67 additions and 4 deletions

View File

@@ -5,6 +5,7 @@
#include <imgui.h>
#include <filesystem>
#include <fstream>
#include <string>
namespace XCEngine {
@@ -48,15 +49,17 @@ public:
return m_iniPath;
}
void SetProjectPath(const std::string& projectPath) {
bool SetProjectPath(const std::string& projectPath) {
if (ImGui::GetCurrentContext() == nullptr) {
return;
return false;
}
SaveSettings();
ImGuiIO& io = ImGui::GetIO();
ConfigureIniFile(projectPath, io);
const bool hasSavedLayout = HasSavedDockLayoutOnDisk(m_iniPath);
ImGui::LoadIniSettingsFromDisk(m_iniPath.c_str());
return hasSavedLayout;
}
private:
@@ -64,6 +67,27 @@ private:
static constexpr const char* kPrimaryUiFontPath = "C:/Windows/Fonts/segoeui.ttf";
static constexpr const char* kChineseFallbackFontPath = "C:/Windows/Fonts/msyh.ttc";
static bool HasSavedDockLayoutOnDisk(const std::filesystem::path& iniPath) {
std::error_code ec;
if (!std::filesystem::is_regular_file(iniPath, ec) || ec) {
return false;
}
std::ifstream input(iniPath, std::ios::in);
if (!input.is_open()) {
return false;
}
std::string line;
while (std::getline(input, line)) {
if (line == "[Docking][Data]") {
return true;
}
}
return false;
}
void ConfigureIniFile(const std::string& projectPath, ImGuiIO& io) {
const std::filesystem::path configDir = std::filesystem::path(projectPath) / ".xceditor";
std::error_code ec;