yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
window_delegate.cc
Go to the documentation of this file.
2
3#include <filesystem>
4#include <fstream>
5#include <sstream>
6
7#include "absl/strings/str_format.h"
8#include "imgui/imgui.h"
10
11namespace yaze {
12namespace editor {
13
15 // This is a placeholder - actual implementation would need to track
16 // all registered windows and set their visibility flags
17 printf("[WindowDelegate] ShowAllWindows() - %zu windows registered\n",
18 registered_windows_.size());
19}
20
22 // This is a placeholder - actual implementation would need to track
23 // all registered windows and set their visibility flags
24 printf("[WindowDelegate] HideAllWindows() - %zu windows registered\n",
25 registered_windows_.size());
26}
27
28void WindowDelegate::ShowWindow(const std::string& window_id) {
29 if (IsWindowRegistered(window_id)) {
30 printf("[WindowDelegate] ShowWindow: %s\n", window_id.c_str());
31 // Actual implementation would set window visibility flag
32 }
33}
34
35void WindowDelegate::HideWindow(const std::string& window_id) {
36 if (IsWindowRegistered(window_id)) {
37 printf("[WindowDelegate] HideWindow: %s\n", window_id.c_str());
38 // Actual implementation would set window visibility flag
39 }
40}
41
42void WindowDelegate::ToggleWindow(const std::string& window_id) {
43 if (IsWindowRegistered(window_id)) {
44 printf("[WindowDelegate] ToggleWindow: %s\n", window_id.c_str());
45 // Actual implementation would toggle window visibility flag
46 }
47}
48
49bool WindowDelegate::IsWindowVisible(const std::string& window_id) const {
50 if (!IsWindowRegistered(window_id)) {
51 return false;
52 }
53 // Actual implementation would check window visibility flag
54 return true; // Placeholder
55}
56
57void WindowDelegate::FocusWindow(const std::string& window_id) {
58 if (IsWindowRegistered(window_id)) {
59 printf("[WindowDelegate] FocusWindow: %s\n", window_id.c_str());
60 // Actual implementation would bring window to front and focus it
61 }
62}
63
64void WindowDelegate::MaximizeWindow(const std::string& window_id) {
65 if (IsWindowRegistered(window_id)) {
66 printf("[WindowDelegate] MaximizeWindow: %s\n", window_id.c_str());
67 // Actual implementation would maximize the window
68 }
69}
70
71void WindowDelegate::RestoreWindow(const std::string& window_id) {
72 if (IsWindowRegistered(window_id)) {
73 printf("[WindowDelegate] RestoreWindow: %s\n", window_id.c_str());
74 // Actual implementation would restore the window from maximized state
75 }
76}
77
78void WindowDelegate::CenterWindow(const std::string& window_id) {
79 if (IsWindowRegistered(window_id)) {
80 printf("[WindowDelegate] CenterWindow: %s\n", window_id.c_str());
81 // Actual implementation would center the window on screen
82 }
83}
84
85void WindowDelegate::DockWindow(const std::string& window_id,
86 ImGuiDir dock_direction) {
87 if (IsWindowRegistered(window_id)) {
88 printf("[WindowDelegate] DockWindow: %s to direction %d\n",
89 window_id.c_str(), static_cast<int>(dock_direction));
90 // Actual implementation would dock the window
91 }
92}
93
94void WindowDelegate::UndockWindow(const std::string& window_id) {
95 if (IsWindowRegistered(window_id)) {
96 printf("[WindowDelegate] UndockWindow: %s\n", window_id.c_str());
97 // Actual implementation would undock the window
98 }
99}
100
101void WindowDelegate::SetDockSpace(const std::string& dock_space_id,
102 const ImVec2& size) {
103 printf("[WindowDelegate] SetDockSpace: %s (%.1f x %.1f)\n",
104 dock_space_id.c_str(), size.x, size.y);
105 // Actual implementation would create/configure dock space
106}
107
108absl::Status WindowDelegate::SaveLayout(const std::string& preset_name) {
109 if (preset_name.empty()) {
110 return absl::InvalidArgumentError("Layout preset name cannot be empty");
111 }
112
113 std::string file_path = GetLayoutFilePath(preset_name);
114
115 try {
116 // Create directory if it doesn't exist
117 std::filesystem::path dir = std::filesystem::path(file_path).parent_path();
118 if (!std::filesystem::exists(dir)) {
119 std::filesystem::create_directories(dir);
120 }
121
122 // Save layout data (placeholder implementation)
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));
127 }
128
129 file << "# YAZE Layout Preset: " << preset_name << "\n";
130 file << "# Generated by WindowDelegate\n";
131 file << "# TODO: Implement actual layout serialization\n";
132
133 file.close();
134
135 printf("[WindowDelegate] Saved layout: %s\n", preset_name.c_str());
136 return absl::OkStatus();
137
138 } catch (const std::exception& e) {
139 return absl::InternalError(
140 absl::StrFormat("Failed to save layout: %s", e.what()));
141 }
142}
143
144absl::Status WindowDelegate::LoadLayout(const std::string& preset_name) {
145 if (preset_name.empty()) {
146 return absl::InvalidArgumentError("Layout preset name cannot be empty");
147 }
148
149 std::string file_path = GetLayoutFilePath(preset_name);
150
151 try {
152 if (!std::filesystem::exists(file_path)) {
153 return absl::NotFoundError(
154 absl::StrFormat("Layout file not found: %s", file_path));
155 }
156
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));
161 }
162
163 // Load layout data (placeholder implementation)
164 std::string line;
165 while (std::getline(file, line)) {
166 // TODO: Parse and apply layout data
167 }
168
169 file.close();
170
171 printf("[WindowDelegate] Loaded layout: %s\n", preset_name.c_str());
172 return absl::OkStatus();
173
174 } catch (const std::exception& e) {
175 return absl::InternalError(
176 absl::StrFormat("Failed to load layout: %s", e.what()));
177 }
178}
179
181 printf("[WindowDelegate] ResetLayout()\n");
182 if (ImGui::GetCurrentContext()) {
183 static const char kEmptyIni[] = "\n";
184 ImGui::LoadIniSettingsFromMemory(kEmptyIni, sizeof(kEmptyIni) - 1);
185 }
186
187 auto ini_path = util::PlatformPaths::GetImGuiIniPath();
188 if (ini_path.ok()) {
189 std::error_code ec;
190 std::filesystem::remove(*ini_path, ec);
191 if (ec) {
192 printf("[WindowDelegate] Failed to remove ImGui ini: %s\n",
193 ec.message().c_str());
194 }
195 }
196 return absl::OkStatus();
197}
198
199std::vector<std::string> WindowDelegate::GetAvailableLayouts() const {
200 std::vector<std::string> layouts;
201
202 try {
203 auto layouts_dir = util::PlatformPaths::GetAppDataSubdirectory("layouts");
204 if (!layouts_dir.ok()) {
205 return layouts;
206 }
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());
211 }
212 }
213 } catch (const std::exception& e) {
214 printf("[WindowDelegate] Error scanning layouts: %s\n", e.what());
215 }
216
217 return layouts;
218}
219
220std::vector<std::string> WindowDelegate::GetVisibleWindows() const {
221 std::vector<std::string> visible;
222 // TODO: Implement actual visibility checking
223 return visible;
224}
225
226std::vector<std::string> WindowDelegate::GetHiddenWindows() const {
227 std::vector<std::string> hidden;
228 // TODO: Implement actual visibility checking
229 return hidden;
230}
231
232ImVec2 WindowDelegate::GetWindowSize(const std::string& window_id) const {
233 if (!IsWindowRegistered(window_id)) {
234 return ImVec2(0, 0);
235 }
236 // TODO: Implement actual size retrieval
237 return ImVec2(400, 300); // Placeholder
238}
239
240ImVec2 WindowDelegate::GetWindowPosition(const std::string& window_id) const {
241 if (!IsWindowRegistered(window_id)) {
242 return ImVec2(0, 0);
243 }
244 // TODO: Implement actual position retrieval
245 return ImVec2(100, 100); // Placeholder
246}
247
248void WindowDelegate::ShowWindowsInCategory(const std::string& category) {
249 printf("[WindowDelegate] ShowWindowsInCategory: %s\n", category.c_str());
250 // TODO: Implement category-based window showing
251}
252
253void WindowDelegate::HideWindowsInCategory(const std::string& category) {
254 printf("[WindowDelegate] HideWindowsInCategory: %s\n", category.c_str());
255 // TODO: Implement category-based window hiding
256}
257
258void WindowDelegate::ShowOnlyWindow(const std::string& window_id) {
259 printf("[WindowDelegate] ShowOnlyWindow: %s\n", window_id.c_str());
260 // TODO: Implement show-only functionality
261}
262
263void WindowDelegate::RegisterWindow(const std::string& window_id,
264 const std::string& category) {
265 WindowInfo info;
266 info.id = window_id;
267 info.category = category;
268 info.is_registered = true;
269
270 registered_windows_[window_id] = info;
271 printf("[WindowDelegate] Registered window: %s (category: %s)\n",
272 window_id.c_str(), category.c_str());
273}
274
275void WindowDelegate::UnregisterWindow(const std::string& window_id) {
276 auto it = registered_windows_.find(window_id);
277 if (it != registered_windows_.end()) {
278 registered_windows_.erase(it);
279 printf("[WindowDelegate] Unregistered window: %s\n", window_id.c_str());
280 }
281}
282
288
294
300
306
307bool WindowDelegate::IsWindowRegistered(const std::string& window_id) const {
308 auto it = registered_windows_.find(window_id);
309 return it != registered_windows_.end() && it->second.is_registered;
310}
311
313 const std::string& preset_name) const {
314 auto layouts_dir = util::PlatformPaths::GetAppDataSubdirectory("layouts");
315 if (layouts_dir.ok()) {
316 return (*layouts_dir / absl::StrFormat("%s.ini", preset_name.c_str()))
317 .string();
318 }
319 return absl::StrFormat("yaze_layout_%s.ini", preset_name);
320}
321
322void WindowDelegate::ApplyLayoutToWindow(const std::string& window_id,
323 const std::string& layout_data) {
324 if (IsWindowRegistered(window_id)) {
325 printf("[WindowDelegate] ApplyLayoutToWindow: %s\n", window_id.c_str());
326 // TODO: Implement layout application
327 }
328}
329
331 std::filesystem::path layout_path = "yaze_workspace.ini";
332 auto workspace_dir = util::PlatformPaths::GetAppDataSubdirectory("workspaces");
333 if (workspace_dir.ok()) {
334 layout_path = *workspace_dir / "yaze_workspace.ini";
335 }
336 ImGui::SaveIniSettingsToDisk(layout_path.string().c_str());
337 printf("[WindowDelegate] Workspace layout saved to %s\n",
338 layout_path.string().c_str());
339}
340
342 std::filesystem::path layout_path = "yaze_workspace.ini";
343 auto workspace_dir = util::PlatformPaths::GetAppDataSubdirectory("workspaces");
344 if (workspace_dir.ok()) {
345 layout_path = *workspace_dir / "yaze_workspace.ini";
346 }
347 ImGui::LoadIniSettingsFromDisk(layout_path.string().c_str());
348 printf("[WindowDelegate] Workspace layout loaded from %s\n",
349 layout_path.string().c_str());
350}
351
353 // Request layout rebuild - the actual reset is handled by LayoutManager
354 // Do NOT use LoadIniSettingsFromMemory(nullptr) as it causes crashes
355 printf("[WindowDelegate] Workspace layout reset requested\n");
356}
357
358} // namespace editor
359} // namespace yaze
std::vector< std::string > GetVisibleWindows() const
void SetDockSpace(const std::string &dock_space_id, const ImVec2 &size=ImVec2(0, 0))
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)
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)
static absl::StatusOr< std::filesystem::path > GetImGuiIniPath()
Get the ImGui ini path for YAZE.
static absl::StatusOr< std::filesystem::path > GetAppDataSubdirectory(const std::string &subdir)
Get a subdirectory within the app data folder.