yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
workspace_manager.cc
Go to the documentation of this file.
1#define IMGUI_DEFINE_MATH_OPERATORS
2
6#include "app/rom.h"
7#include "absl/strings/str_format.h"
8#include "util/file_util.h"
10#include "imgui/imgui.h"
11#include "imgui/imgui_internal.h"
12
13namespace yaze {
14namespace editor {
15
16absl::Status WorkspaceManager::SaveWorkspaceLayout(const std::string& name) {
17 // TODO: Serialize ImGui docking layout
18 if (toast_manager_) {
19 toast_manager_->Show("Layout saved", ToastType::kSuccess);
20 }
21 return absl::OkStatus();
22}
23
24absl::Status WorkspaceManager::LoadWorkspaceLayout(const std::string& name) {
25 // TODO: Deserialize ImGui docking layout
26 if (toast_manager_) {
27 toast_manager_->Show("Layout loaded", ToastType::kSuccess);
28 }
29 return absl::OkStatus();
30}
31
33 // TODO: Reset to default layout
34 if (toast_manager_) {
35 toast_manager_->Show("Layout reset to default", ToastType::kInfo);
36 }
37 return absl::OkStatus();
38}
39
40void WorkspaceManager::SaveWorkspacePreset(const std::string& name) {
41 if (name.empty()) return;
42 std::string ini_name = absl::StrFormat("yaze_workspace_%s.ini", name.c_str());
43 ImGui::SaveIniSettingsToDisk(ini_name.c_str());
44
46 // RefreshWorkspacePresets(); // This will be implemented next
47 }
48
49 if (std::find(workspace_presets_.begin(), workspace_presets_.end(), name) ==
50 workspace_presets_.end()) {
51 workspace_presets_.emplace_back(name);
52 try {
53 std::ostringstream ss;
54 for (const auto& n : workspace_presets_)
55 ss << n << "\n";
56 // This should use a platform-agnostic path
57 util::SaveFile("workspace_presets.txt", ss.str());
58 } catch (const std::exception& e) {
59 // LOG_WARN("WorkspaceManager", "Failed to save presets: %s", e.what());
60 }
61 }
63 if (toast_manager_) {
64 toast_manager_->Show(absl::StrFormat("Preset '%s' saved", name),
66 }
67}
68
69void WorkspaceManager::LoadWorkspacePreset(const std::string& name) {
70 if (name.empty()) return;
71 std::string ini_name = absl::StrFormat("yaze_workspace_%s.ini", name.c_str());
72 ImGui::LoadIniSettingsFromDisk(ini_name.c_str());
74 if (toast_manager_) {
75 toast_manager_->Show(absl::StrFormat("Preset '%s' loaded", name),
77 }
78}
79
81 try {
82 std::vector<std::string> new_presets;
84 if (config_dir.ok()) {
85 std::string presets_path = (*config_dir / "workspace_presets.txt").string();
86 auto data = util::LoadFile(presets_path);
87 if (!data.empty()) {
88 std::istringstream ss(data);
89 std::string name;
90 while (std::getline(ss, name)) {
91 name.erase(0, name.find_first_not_of(" \t\r\n"));
92 name.erase(name.find_last_not_of(" \t\r\n") + 1);
93 if (!name.empty() && name.length() < 256) {
94 new_presets.emplace_back(std::move(name));
95 }
96 }
97 }
98 }
99 workspace_presets_ = std::move(new_presets);
101 } catch (const std::exception& e) {
102 // LOG_ERROR("WorkspaceManager", "Error refreshing presets: %s", e.what());
103 workspace_presets_.clear();
105 }
106}
107
109 // TODO: Load preset with all debug tools
110 if (toast_manager_) {
111 toast_manager_->Show("Developer layout loaded", ToastType::kInfo);
112 }
113}
114
116 // TODO: Load preset focused on graphics
117 if (toast_manager_) {
118 toast_manager_->Show("Designer layout loaded", ToastType::kInfo);
119 }
120}
121
123 // TODO: Load preset for ROM hacking
124 if (toast_manager_) {
125 toast_manager_->Show("Modder layout loaded", ToastType::kInfo);
126 }
127}
128
130 if (card_registry_) {
132 }
133 if (toast_manager_) {
134 toast_manager_->Show("All windows shown", ToastType::kInfo);
135 }
136}
137
139 if (card_registry_) {
141 }
142 if (toast_manager_) {
143 toast_manager_->Show("All windows hidden", ToastType::kInfo);
144 }
145}
146
148 // Use ImGui internal API to maximize current window
149 ImGuiWindow* window = ImGui::GetCurrentWindowRead();
150 if (window && window->DockNode) {
151 ImGuiID central_node_id = ImGui::DockBuilderGetCentralNode(
152 ImGui::GetID("MainDockSpace"))->ID;
153 ImGui::DockBuilderDockWindow(window->Name, central_node_id);
154 }
155 if (toast_manager_) {
156 toast_manager_->Show("Window maximized", ToastType::kInfo);
157 }
158}
159
161 // Reset all window sizes - ImGui will auto-restore based on docking
162 ImGuiContext* ctx = ImGui::GetCurrentContext();
163 if (ctx) {
164 for (ImGuiWindow* window : ctx->Windows) {
165 if (window && !window->Collapsed) {
166 ImGui::SetWindowSize(window->Name, ImVec2(0, 0)); // Auto-size
167 }
168 }
169 }
170 if (toast_manager_) {
171 toast_manager_->Show("All windows restored", ToastType::kInfo);
172 }
173}
174
176 // Close all windows that are not docked
177 ImGuiContext* ctx = ImGui::GetCurrentContext();
178 if (ctx) {
179 for (ImGuiWindow* window : ctx->Windows) {
180 if (window && !window->DockNode && !window->Collapsed) {
181 window->Hidden = true;
182 }
183 }
184 }
185 if (toast_manager_) {
186 toast_manager_->Show("Floating windows closed", ToastType::kInfo);
187 }
188}
189
191 if (!sessions_) return 0;
192
193 size_t count = 0;
194 for (const auto& session : *sessions_) {
195 if (session.rom && session.rom->is_loaded()) {
196 count++;
197 }
198 }
199 return count;
200}
201
202bool WorkspaceManager::HasDuplicateSession(const std::string& filepath) const {
203 if (!sessions_) return false;
204
205 for (const auto& session : *sessions_) {
206 if (session.filepath == filepath && session.rom && session.rom->is_loaded()) {
207 return true;
208 }
209 }
210 return false;
211}
212
213// Window navigation operations
215 ImGuiContext* ctx = ImGui::GetCurrentContext();
216 if (ctx && ctx->NavWindow) {
217 ImGui::FocusWindow(ImGui::FindWindowByName(ctx->NavWindow->Name));
218 }
219 // TODO: Implement proper window cycling
220}
221
223 // TODO: Implement window cycling backward
224}
225
227 ImGuiWindow* window = ImGui::GetCurrentWindowRead();
228 if (window && window->DockNode) {
229 ImGuiID node_id = window->DockNode->ID;
230 ImGuiID out_id_at_dir = 0;
231 ImGuiID out_id_at_opposite_dir = 0;
232 ImGui::DockBuilderSplitNode(node_id, ImGuiDir_Down, 0.5f,
233 &out_id_at_dir, &out_id_at_opposite_dir);
234 }
235}
236
238 ImGuiWindow* window = ImGui::GetCurrentWindowRead();
239 if (window && window->DockNode) {
240 ImGuiID node_id = window->DockNode->ID;
241 ImGuiID out_id_at_dir = 0;
242 ImGuiID out_id_at_opposite_dir = 0;
243 ImGui::DockBuilderSplitNode(node_id, ImGuiDir_Right, 0.5f,
244 &out_id_at_dir, &out_id_at_opposite_dir);
245 }
246}
247
249 ImGuiWindow* window = ImGui::GetCurrentWindowRead();
250 if (window) {
251 window->Hidden = true;
252 }
253}
254
255// Command execution for WhichKey integration
256void WorkspaceManager::ExecuteWorkspaceCommand(const std::string& command_id) {
257 // Window commands (Space + w)
258 if (command_id == "w.s") { ShowAllWindows(); }
259 else if (command_id == "w.h") { HideAllWindows(); }
260 else if (command_id == "w.m") { MaximizeCurrentWindow(); }
261 else if (command_id == "w.r") { RestoreAllWindows(); }
262 else if (command_id == "w.c") { CloseCurrentWindow(); }
263 else if (command_id == "w.f") { CloseAllFloatingWindows(); }
264 else if (command_id == "w.v") { SplitWindowVertical(); }
265 else if (command_id == "w.H") { SplitWindowHorizontal(); }
266
267 // Layout commands (Space + l)
268 else if (command_id == "l.s") { SaveWorkspaceLayout(); }
269 else if (command_id == "l.l") { LoadWorkspaceLayout(); }
270 else if (command_id == "l.r") { ResetWorkspaceLayout(); }
271 else if (command_id == "l.d") { LoadDeveloperLayout(); }
272 else if (command_id == "l.g") { LoadDesignerLayout(); }
273 else if (command_id == "l.m") { LoadModderLayout(); }
274
275 // Unknown command
276 else if (toast_manager_) {
277 toast_manager_->Show(absl::StrFormat("Unknown command: %s", command_id),
279 }
280}
281
282} // namespace editor
283} // namespace yaze
void Show(const std::string &message, ToastType type=ToastType::kInfo, float ttl_seconds=3.0f)
void SaveWorkspacePreset(const std::string &name)
bool HasDuplicateSession(const std::string &filepath) const
std::vector< std::string > workspace_presets_
std::deque< SessionInfo > * sessions_
void LoadWorkspacePreset(const std::string &name)
absl::Status SaveWorkspaceLayout(const std::string &name="")
absl::Status LoadWorkspaceLayout(const std::string &name="")
EditorCardRegistry * card_registry_
void ExecuteWorkspaceCommand(const std::string &command_id)
static absl::StatusOr< std::filesystem::path > GetConfigDirectory()
Get the user-specific configuration directory for YAZE.
void SaveFile(const std::string &filename, const std::string &contents)
Definition file_util.cc:56
std::string LoadFile(const std::string &filename)
Loads the entire contents of a file into a string.
Definition file_util.cc:23
Main namespace for the application.
Definition controller.cc:20