Preserve saved editor dock layouts
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user