7#include "absl/strings/str_format.h"
8#include "imgui/imgui.h"
17 printf(
"[WindowDelegate] ShowAllWindows() - %zu windows registered\n",
24 printf(
"[WindowDelegate] HideAllWindows() - %zu windows registered\n",
30 printf(
"[WindowDelegate] ShowWindow: %s\n", window_id.c_str());
37 printf(
"[WindowDelegate] HideWindow: %s\n", window_id.c_str());
44 printf(
"[WindowDelegate] ToggleWindow: %s\n", window_id.c_str());
59 printf(
"[WindowDelegate] FocusWindow: %s\n", window_id.c_str());
66 printf(
"[WindowDelegate] MaximizeWindow: %s\n", window_id.c_str());
73 printf(
"[WindowDelegate] RestoreWindow: %s\n", window_id.c_str());
80 printf(
"[WindowDelegate] CenterWindow: %s\n", window_id.c_str());
86 ImGuiDir dock_direction) {
88 printf(
"[WindowDelegate] DockWindow: %s to direction %d\n",
89 window_id.c_str(),
static_cast<int>(dock_direction));
96 printf(
"[WindowDelegate] UndockWindow: %s\n", window_id.c_str());
102 const ImVec2& size) {
103 printf(
"[WindowDelegate] SetDockSpace: %s (%.1f x %.1f)\n",
104 dock_space_id.c_str(), size.x, size.y);
109 if (preset_name.empty()) {
110 return absl::InvalidArgumentError(
"Layout preset name cannot be empty");
117 std::filesystem::path dir = std::filesystem::path(file_path).parent_path();
118 if (!std::filesystem::exists(dir)) {
119 std::filesystem::create_directories(dir);
123 std::ofstream file(file_path);
124 if (!file.is_open()) {
125 return absl::InternalError(
126 absl::StrFormat(
"Failed to open layout file: %s", file_path));
129 file <<
"# YAZE Layout Preset: " << preset_name <<
"\n";
130 file <<
"# Generated by WindowDelegate\n";
131 file <<
"# TODO: Implement actual layout serialization\n";
135 printf(
"[WindowDelegate] Saved layout: %s\n", preset_name.c_str());
136 return absl::OkStatus();
138 }
catch (
const std::exception& e) {
139 return absl::InternalError(
140 absl::StrFormat(
"Failed to save layout: %s", e.what()));
145 if (preset_name.empty()) {
146 return absl::InvalidArgumentError(
"Layout preset name cannot be empty");
152 if (!std::filesystem::exists(file_path)) {
153 return absl::NotFoundError(
154 absl::StrFormat(
"Layout file not found: %s", file_path));
157 std::ifstream file(file_path);
158 if (!file.is_open()) {
159 return absl::InternalError(
160 absl::StrFormat(
"Failed to open layout file: %s", file_path));
165 while (std::getline(file, line)) {
171 printf(
"[WindowDelegate] Loaded layout: %s\n", preset_name.c_str());
172 return absl::OkStatus();
174 }
catch (
const std::exception& e) {
175 return absl::InternalError(
176 absl::StrFormat(
"Failed to load layout: %s", e.what()));
181 printf(
"[WindowDelegate] ResetLayout()\n");
182 if (ImGui::GetCurrentContext()) {
183 static const char kEmptyIni[] =
"\n";
184 ImGui::LoadIniSettingsFromMemory(kEmptyIni,
sizeof(kEmptyIni) - 1);
190 std::filesystem::remove(*ini_path, ec);
192 printf(
"[WindowDelegate] Failed to remove ImGui ini: %s\n",
193 ec.message().c_str());
196 return absl::OkStatus();
200 std::vector<std::string> layouts;
204 if (!layouts_dir.ok()) {
207 for (
const auto& entry :
208 std::filesystem::directory_iterator(*layouts_dir)) {
209 if (entry.is_regular_file() && entry.path().extension() ==
".ini") {
210 layouts.push_back(entry.path().stem().string());
213 }
catch (
const std::exception& e) {
214 printf(
"[WindowDelegate] Error scanning layouts: %s\n", e.what());
221 std::vector<std::string> visible;
227 std::vector<std::string> hidden;
237 return ImVec2(400, 300);
245 return ImVec2(100, 100);
249 printf(
"[WindowDelegate] ShowWindowsInCategory: %s\n", category.c_str());
254 printf(
"[WindowDelegate] HideWindowsInCategory: %s\n", category.c_str());
259 printf(
"[WindowDelegate] ShowOnlyWindow: %s\n", window_id.c_str());
264 const std::string& category) {
271 printf(
"[WindowDelegate] Registered window: %s (category: %s)\n",
272 window_id.c_str(), category.c_str());
279 printf(
"[WindowDelegate] Unregistered window: %s\n", window_id.c_str());
313 const std::string& preset_name)
const {
315 if (layouts_dir.ok()) {
316 return (*layouts_dir / absl::StrFormat(
"%s.ini", preset_name.c_str()))
319 return absl::StrFormat(
"yaze_layout_%s.ini", preset_name);
323 const std::string& layout_data) {
325 printf(
"[WindowDelegate] ApplyLayoutToWindow: %s\n", window_id.c_str());
331 std::filesystem::path layout_path =
"yaze_workspace.ini";
333 if (workspace_dir.ok()) {
334 layout_path = *workspace_dir /
"yaze_workspace.ini";
336 ImGui::SaveIniSettingsToDisk(layout_path.string().c_str());
337 printf(
"[WindowDelegate] Workspace layout saved to %s\n",
338 layout_path.string().c_str());
342 std::filesystem::path layout_path =
"yaze_workspace.ini";
344 if (workspace_dir.ok()) {
345 layout_path = *workspace_dir /
"yaze_workspace.ini";
347 ImGui::LoadIniSettingsFromDisk(layout_path.string().c_str());
348 printf(
"[WindowDelegate] Workspace layout loaded from %s\n",
349 layout_path.string().c_str());
355 printf(
"[WindowDelegate] Workspace layout reset requested\n");
void LoadDesignerLayout()
void LoadWorkspaceLayout()
void SaveWorkspaceLayout()
std::vector< std::string > GetVisibleWindows() const
void SetDockSpace(const std::string &dock_space_id, const ImVec2 &size=ImVec2(0, 0))
absl::Status ResetLayout()
bool IsWindowVisible(const std::string &window_id) const
void UnregisterWindow(const std::string &window_id)
std::function< void(const std::string &) apply_preset_callback_)
void RegisterWindow(const std::string &window_id, const std::string &category="")
std::unordered_map< std::string, WindowInfo > registered_windows_
void RestoreWindow(const std::string &window_id)
void MaximizeWindow(const std::string &window_id)
std::string GetLayoutFilePath(const std::string &preset_name) const
void ShowWindow(const std::string &window_id)
void HideWindow(const std::string &window_id)
std::vector< std::string > GetAvailableLayouts() const
ImVec2 GetWindowSize(const std::string &window_id) const
void ToggleWindow(const std::string &window_id)
void UndockWindow(const std::string &window_id)
absl::Status SaveLayout(const std::string &preset_name)
void ShowOnlyWindow(const std::string &window_id)
void ShowWindowsInCategory(const std::string &category)
bool IsWindowRegistered(const std::string &window_id) const
void HideWindowsInCategory(const std::string &category)
void CenterWindow(const std::string &window_id)
void ResetWorkspaceLayout()
ImVec2 GetWindowPosition(const std::string &window_id) const
void ApplyLayoutToWindow(const std::string &window_id, const std::string &layout_data)
absl::Status LoadLayout(const std::string &preset_name)
void DockWindow(const std::string &window_id, ImGuiDir dock_direction)
std::vector< std::string > GetHiddenWindows() const
void FocusWindow(const std::string &window_id)
void LoadDeveloperLayout()