yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
workspace_manager.cc
Go to the documentation of this file.
3#include "app/rom.h"
4#include "absl/strings/str_format.h"
5#include "util/file_util.h"
7
8namespace yaze {
9namespace editor {
10
11absl::Status WorkspaceManager::SaveWorkspaceLayout(const std::string& name) {
12 // TODO: Serialize ImGui docking layout
13 if (toast_manager_) {
14 toast_manager_->Show("Layout saved", ToastType::kSuccess);
15 }
16 return absl::OkStatus();
17}
18
19absl::Status WorkspaceManager::LoadWorkspaceLayout(const std::string& name) {
20 // TODO: Deserialize ImGui docking layout
21 if (toast_manager_) {
22 toast_manager_->Show("Layout loaded", ToastType::kSuccess);
23 }
24 return absl::OkStatus();
25}
26
28 // TODO: Reset to default layout
29 if (toast_manager_) {
30 toast_manager_->Show("Layout reset to default", ToastType::kInfo);
31 }
32 return absl::OkStatus();
33}
34
35void WorkspaceManager::SaveWorkspacePreset(const std::string& name) {
36 if (name.empty()) return;
37 std::string ini_name = absl::StrFormat("yaze_workspace_%s.ini", name.c_str());
38 ImGui::SaveIniSettingsToDisk(ini_name.c_str());
39
41 // RefreshWorkspacePresets(); // This will be implemented next
42 }
43
44 if (std::find(workspace_presets_.begin(), workspace_presets_.end(), name) ==
45 workspace_presets_.end()) {
46 workspace_presets_.emplace_back(name);
47 try {
48 std::ostringstream ss;
49 for (const auto& n : workspace_presets_)
50 ss << n << "\n";
51 // This should use a platform-agnostic path
52 util::SaveFile("workspace_presets.txt", ss.str());
53 } catch (const std::exception& e) {
54 // LOG_WARN("WorkspaceManager", "Failed to save presets: %s", e.what());
55 }
56 }
58 if (toast_manager_) {
59 toast_manager_->Show(absl::StrFormat("Preset '%s' saved", name),
61 }
62}
63
64void WorkspaceManager::LoadWorkspacePreset(const std::string& name) {
65 if (name.empty()) return;
66 std::string ini_name = absl::StrFormat("yaze_workspace_%s.ini", name.c_str());
67 ImGui::LoadIniSettingsFromDisk(ini_name.c_str());
69 if (toast_manager_) {
70 toast_manager_->Show(absl::StrFormat("Preset '%s' loaded", name),
72 }
73}
74
76 try {
77 std::vector<std::string> new_presets;
79 if (config_dir.ok()) {
80 std::string presets_path = (*config_dir / "workspace_presets.txt").string();
81 auto data = util::LoadFile(presets_path);
82 if (!data.empty()) {
83 std::istringstream ss(data);
84 std::string name;
85 while (std::getline(ss, name)) {
86 name.erase(0, name.find_first_not_of(" \t\r\n"));
87 name.erase(name.find_last_not_of(" \t\r\n") + 1);
88 if (!name.empty() && name.length() < 256) {
89 new_presets.emplace_back(std::move(name));
90 }
91 }
92 }
93 }
94 workspace_presets_ = std::move(new_presets);
96 } catch (const std::exception& e) {
97 // LOG_ERROR("WorkspaceManager", "Error refreshing presets: %s", e.what());
98 workspace_presets_.clear();
100 }
101}
102
104 // TODO: Load preset with all debug tools
105 if (toast_manager_) {
106 toast_manager_->Show("Developer layout loaded", ToastType::kInfo);
107 }
108}
109
111 // TODO: Load preset focused on graphics
112 if (toast_manager_) {
113 toast_manager_->Show("Designer layout loaded", ToastType::kInfo);
114 }
115}
116
118 // TODO: Load preset for ROM hacking
119 if (toast_manager_) {
120 toast_manager_->Show("Modder layout loaded", ToastType::kInfo);
121 }
122}
123
125 // TODO: Set all editor windows to visible
126}
127
129 // TODO: Hide all editor windows
130}
131
133 // TODO: Maximize focused window
134}
135
137 // TODO: Restore all windows to default size
138}
139
141 // TODO: Close undocked windows
142}
143
145 if (!sessions_) return 0;
146
147 size_t count = 0;
148 for (const auto& session : *sessions_) {
149 if (session.rom && session.rom->is_loaded()) {
150 count++;
151 }
152 }
153 return count;
154}
155
156bool WorkspaceManager::HasDuplicateSession(const std::string& filepath) const {
157 if (!sessions_) return false;
158
159 for (const auto& session : *sessions_) {
160 if (session.filepath == filepath && session.rom && session.rom->is_loaded()) {
161 return true;
162 }
163 }
164 return false;
165}
166
167} // namespace editor
168} // 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="")
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.