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
4
5#include "absl/strings/str_format.h"
8#include "rom/rom.h"
9#include "imgui/imgui.h"
10#include "imgui/imgui_internal.h"
11#include "util/file_util.h"
12#include "util/platform_paths.h"
13
14namespace yaze {
15namespace editor {
16
17absl::Status WorkspaceManager::SaveWorkspaceLayout(const std::string& name) {
18 // TODO: Serialize ImGui docking layout
19 if (toast_manager_) {
20 toast_manager_->Show("Layout saved", ToastType::kSuccess);
21 }
22 return absl::OkStatus();
23}
24
25absl::Status WorkspaceManager::LoadWorkspaceLayout(const std::string& name) {
26 // TODO: Deserialize ImGui docking layout
27 if (toast_manager_) {
28 toast_manager_->Show("Layout loaded", ToastType::kSuccess);
29 }
30 return absl::OkStatus();
31}
32
34 // TODO: Reset to default layout
35 if (toast_manager_) {
36 toast_manager_->Show("Layout reset to default", ToastType::kInfo);
37 }
38 return absl::OkStatus();
39}
40
41void WorkspaceManager::SaveWorkspacePreset(const std::string& name) {
42 if (name.empty())
43 return;
44 std::string ini_name = absl::StrFormat("yaze_workspace_%s.ini", name.c_str());
45 ImGui::SaveIniSettingsToDisk(ini_name.c_str());
46
48 // RefreshWorkspacePresets(); // This will be implemented next
49 }
50
51 if (std::find(workspace_presets_.begin(), workspace_presets_.end(), name) ==
52 workspace_presets_.end()) {
53 workspace_presets_.emplace_back(name);
54 try {
55 std::ostringstream ss;
56 for (const auto& n : workspace_presets_)
57 ss << n << "\n";
58 // This should use a platform-agnostic path
59 util::SaveFile("workspace_presets.txt", ss.str());
60 } catch (const std::exception& e) {
61 // LOG_WARN("WorkspaceManager", "Failed to save presets: %s", e.what());
62 }
63 }
65 if (toast_manager_) {
66 toast_manager_->Show(absl::StrFormat("Preset '%s' saved", name),
68 }
69}
70
71void WorkspaceManager::LoadWorkspacePreset(const std::string& name) {
72 if (name.empty())
73 return;
74 std::string ini_name = absl::StrFormat("yaze_workspace_%s.ini", name.c_str());
75 ImGui::LoadIniSettingsFromDisk(ini_name.c_str());
77 if (toast_manager_) {
78 toast_manager_->Show(absl::StrFormat("Preset '%s' loaded", name),
80 }
81}
82
84 try {
85 std::vector<std::string> new_presets;
87 if (config_dir.ok()) {
88 std::string presets_path =
89 (*config_dir / "workspace_presets.txt").string();
90 auto data = util::LoadFile(presets_path);
91 if (!data.empty()) {
92 std::istringstream ss(data);
93 std::string name;
94 while (std::getline(ss, name)) {
95 name.erase(0, name.find_first_not_of(" \t\r\n"));
96 name.erase(name.find_last_not_of(" \t\r\n") + 1);
97 if (!name.empty() && name.length() < 256) {
98 new_presets.emplace_back(std::move(name));
99 }
100 }
101 }
102 }
103 workspace_presets_ = std::move(new_presets);
105 } catch (const std::exception& e) {
106 // LOG_ERROR("WorkspaceManager", "Error refreshing presets: %s", e.what());
107 workspace_presets_.clear();
109 }
110}
111
113 // TODO: Load preset with all debug tools
114 if (toast_manager_) {
115 toast_manager_->Show("Developer layout loaded", ToastType::kInfo);
116 }
117}
118
120 // TODO: Load preset focused on graphics
121 if (toast_manager_) {
122 toast_manager_->Show("Designer layout loaded", ToastType::kInfo);
123 }
124}
125
127 // TODO: Load preset for ROM hacking
128 if (toast_manager_) {
129 toast_manager_->Show("Modder layout loaded", ToastType::kInfo);
130 }
131}
132
134 if (panel_manager_) {
136 }
137 if (toast_manager_) {
138 toast_manager_->Show("All windows shown", ToastType::kInfo);
139 }
140}
141
143 if (panel_manager_) {
145 }
146 if (toast_manager_) {
147 toast_manager_->Show("All windows hidden", ToastType::kInfo);
148 }
149}
150
152 // Use ImGui internal API to maximize current window
153 ImGuiWindow* window = ImGui::GetCurrentWindowRead();
154 if (window && window->DockNode) {
155 ImGuiID central_node_id =
156 ImGui::DockBuilderGetCentralNode(ImGui::GetID("MainDockSpace"))->ID;
157 ImGui::DockBuilderDockWindow(window->Name, central_node_id);
158 }
159 if (toast_manager_) {
160 toast_manager_->Show("Window maximized", ToastType::kInfo);
161 }
162}
163
165 // Reset all window sizes - ImGui will auto-restore based on docking
166 ImGuiContext* ctx = ImGui::GetCurrentContext();
167 if (ctx) {
168 for (ImGuiWindow* window : ctx->Windows) {
169 if (window && !window->Collapsed) {
170 ImGui::SetWindowSize(window->Name, ImVec2(0, 0)); // Auto-size
171 }
172 }
173 }
174 if (toast_manager_) {
175 toast_manager_->Show("All windows restored", ToastType::kInfo);
176 }
177}
178
180 // Close all windows that are not docked
181 ImGuiContext* ctx = ImGui::GetCurrentContext();
182 if (ctx) {
183 for (ImGuiWindow* window : ctx->Windows) {
184 if (window && !window->DockNode && !window->Collapsed) {
185 window->Hidden = true;
186 }
187 }
188 }
189 if (toast_manager_) {
190 toast_manager_->Show("Floating windows closed", ToastType::kInfo);
191 }
192}
193
195 if (!sessions_)
196 return 0;
197
198 size_t count = 0;
199 for (const auto& session : *sessions_) {
200 if (session.rom && session.rom->is_loaded()) {
201 count++;
202 }
203 }
204 return count;
205}
206
207bool WorkspaceManager::HasDuplicateSession(const std::string& filepath) const {
208 if (!sessions_)
209 return false;
210
211 for (const auto& session : *sessions_) {
212 if (session.filepath == filepath && session.rom &&
213 session.rom->is_loaded()) {
214 return true;
215 }
216 }
217 return false;
218}
219
220// Window navigation operations
222 ImGuiContext* ctx = ImGui::GetCurrentContext();
223 if (ctx && ctx->NavWindow) {
224 ImGui::FocusWindow(ImGui::FindWindowByName(ctx->NavWindow->Name));
225 }
226 // TODO: Implement proper window cycling
227}
228
230 // TODO: Implement window cycling backward
231}
232
234 ImGuiWindow* window = ImGui::GetCurrentWindowRead();
235 if (window && window->DockNode) {
236 ImGuiID node_id = window->DockNode->ID;
237 ImGuiID out_id_at_dir = 0;
238 ImGuiID out_id_at_opposite_dir = 0;
239 ImGui::DockBuilderSplitNode(node_id, ImGuiDir_Down, 0.5f, &out_id_at_dir,
240 &out_id_at_opposite_dir);
241 }
242}
243
245 ImGuiWindow* window = ImGui::GetCurrentWindowRead();
246 if (window && window->DockNode) {
247 ImGuiID node_id = window->DockNode->ID;
248 ImGuiID out_id_at_dir = 0;
249 ImGuiID out_id_at_opposite_dir = 0;
250 ImGui::DockBuilderSplitNode(node_id, ImGuiDir_Right, 0.5f, &out_id_at_dir,
251 &out_id_at_opposite_dir);
252 }
253}
254
256 ImGuiWindow* window = ImGui::GetCurrentWindowRead();
257 if (window) {
258 window->Hidden = true;
259 }
260}
261
262// Command execution for WhichKey integration
263void WorkspaceManager::ExecuteWorkspaceCommand(const std::string& command_id) {
264 // Window commands (Space + w)
265 if (command_id == "w.s") {
267 } else if (command_id == "w.h") {
269 } else if (command_id == "w.m") {
271 } else if (command_id == "w.r") {
273 } else if (command_id == "w.c") {
275 } else if (command_id == "w.f") {
277 } else if (command_id == "w.v") {
279 } else if (command_id == "w.H") {
281 }
282
283 // Layout commands (Space + l)
284 else if (command_id == "l.s") {
286 } else if (command_id == "l.l") {
288 } else if (command_id == "l.r") {
290 } else if (command_id == "l.d") {
292 } else if (command_id == "l.g") {
294 } else if (command_id == "l.m") {
296 }
297
298 // Unknown command
299 else if (toast_manager_) {
300 toast_manager_->Show(absl::StrFormat("Unknown command: %s", command_id),
302 }
303}
304
305} // namespace editor
306} // namespace yaze
void HideAll(size_t session_id)
void ShowAll(size_t session_id)
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="")
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