1#define IMGUI_DEFINE_MATH_OPERATORS
5#include "absl/strings/str_format.h"
10#include "imgui/imgui.h"
11#include "imgui/imgui_internal.h"
22 const std::string layout_name = name.empty() ?
"workspace" : name;
28 return absl::OkStatus();
34 const std::string layout_name = name.empty() ?
"workspace" : name;
45 return absl::OkStatus();
49 if (ImGui::GetCurrentContext()) {
50 static const char kEmptyIni[] =
"\n";
51 ImGui::LoadIniSettingsFromMemory(kEmptyIni,
sizeof(kEmptyIni) - 1);
56 std::filesystem::remove(*ini_path, ec);
58 LOG_WARN(
"WorkspaceManager",
"Failed to remove ImGui ini: %s",
59 ec.message().c_str());
78 return absl::OkStatus();
85 std::filesystem::path workspace_dir = std::filesystem::current_path();
86 auto workspace_dir_status =
88 if (workspace_dir_status.ok()) {
89 workspace_dir = *workspace_dir_status;
95 std::filesystem::path ini_path =
96 workspace_dir / absl::StrFormat(
"workspace_%s.ini", name.c_str());
97 ImGui::SaveIniSettingsToDisk(ini_path.string().c_str());
108 std::ostringstream ss;
111 std::filesystem::path presets_path =
112 workspace_dir /
"workspace_presets.txt";
114 }
catch (
const std::exception& e) {
140 std::filesystem::path workspace_dir = std::filesystem::current_path();
141 auto workspace_dir_status =
143 if (workspace_dir_status.ok()) {
144 workspace_dir = *workspace_dir_status;
146 std::filesystem::path ini_path =
147 workspace_dir / absl::StrFormat(
"workspace_%s.ini", name.c_str());
148 ImGui::LoadIniSettingsFromDisk(ini_path.string().c_str());
158 std::vector<std::string> new_presets;
160 if (workspace_dir.ok()) {
161 std::filesystem::path presets_path =
162 *workspace_dir /
"workspace_presets.txt";
165 std::istringstream ss(data);
167 while (std::getline(ss, name)) {
168 name.erase(0, name.find_first_not_of(
" \t\r\n"));
169 name.erase(name.find_last_not_of(
" \t\r\n") + 1);
170 if (!name.empty() && name.length() < 256) {
171 new_presets.emplace_back(std::move(name));
178 }
catch (
const std::exception& e) {
229 ImGuiWindow* window = ImGui::GetCurrentWindowRead();
230 if (window && window->DockNode) {
231 ImGuiID central_node_id =
232 ImGui::DockBuilderGetCentralNode(ImGui::GetID(
"MainDockSpace"))->ID;
233 ImGui::DockBuilderDockWindow(window->Name, central_node_id);
242 ImGuiContext* ctx = ImGui::GetCurrentContext();
244 for (ImGuiWindow* window : ctx->Windows) {
245 if (window && !window->Collapsed) {
246 ImGui::SetWindowSize(window->Name, ImVec2(0, 0));
257 ImGuiContext* ctx = ImGui::GetCurrentContext();
259 for (ImGuiWindow* window : ctx->Windows) {
260 if (window && !window->DockNode && !window->Collapsed) {
261 window->Hidden =
true;
276 if (session.rom && session.rom->is_loaded()) {
288 if (session.filepath == filepath && session.rom &&
289 session.rom->is_loaded()) {
298 ImGuiContext* ctx = ImGui::GetCurrentContext();
299 if (ctx && ctx->NavWindow) {
300 ImGui::FocusWindow(ImGui::FindWindowByName(ctx->NavWindow->Name));
310 ImGuiWindow* window = ImGui::GetCurrentWindowRead();
311 if (window && window->DockNode) {
312 ImGuiID node_id = window->DockNode->ID;
313 ImGuiID out_id_at_dir = 0;
314 ImGuiID out_id_at_opposite_dir = 0;
315 ImGui::DockBuilderSplitNode(node_id, ImGuiDir_Down, 0.5f, &out_id_at_dir,
316 &out_id_at_opposite_dir);
321 ImGuiWindow* window = ImGui::GetCurrentWindowRead();
322 if (window && window->DockNode) {
323 ImGuiID node_id = window->DockNode->ID;
324 ImGuiID out_id_at_dir = 0;
325 ImGuiID out_id_at_opposite_dir = 0;
326 ImGui::DockBuilderSplitNode(node_id, ImGuiDir_Right, 0.5f, &out_id_at_dir,
327 &out_id_at_opposite_dir);
332 ImGuiWindow* window = ImGui::GetCurrentWindowRead();
334 window->Hidden =
true;
341 if (command_id ==
"w.s") {
343 }
else if (command_id ==
"w.h") {
345 }
else if (command_id ==
"w.m") {
347 }
else if (command_id ==
"w.r") {
349 }
else if (command_id ==
"w.c") {
351 }
else if (command_id ==
"w.f") {
353 }
else if (command_id ==
"w.v") {
355 }
else if (command_id ==
"w.H") {
360 else if (command_id ==
"l.s") {
362 }
else if (command_id ==
"l.l") {
364 }
else if (command_id ==
"l.r") {
366 }
else if (command_id ==
"l.d") {
368 }
else if (command_id ==
"l.g") {
370 }
else if (command_id ==
"l.m") {
static EditorType GetEditorTypeFromCategory(const std::string &category)
void LoadLayout(const std::string &name)
Load a saved layout by name.
void ClearInitializationFlags()
Clear all initialization flags (for testing)
void ResetToDefaultLayout(EditorType type)
Reset the layout for an editor to its default.
void SaveCurrentLayout(const std::string &name, bool persist=true)
Save the current layout with a custom name.
void RequestRebuild()
Request a layout rebuild on next frame.
bool HasLayout(const std::string &name) const
Check if a layout exists.
void HideAll(size_t session_id)
std::string GetActiveCategory() const
void ShowAll(size_t session_id)
void Show(const std::string &message, ToastType type=ToastType::kInfo, float ttl_seconds=3.0f)
absl::Status ResetWorkspaceLayout()
std::string last_workspace_preset_
void SaveWorkspacePreset(const std::string &name)
PanelManager * panel_manager_
bool HasDuplicateSession(const std::string &filepath) const
bool workspace_presets_loaded_
void FocusPreviousWindow()
void SplitWindowVertical()
std::function< void(const std::string &) apply_preset_callback_)
void MaximizeCurrentWindow()
std::vector< std::string > workspace_presets_
size_t GetActiveSessionCount() const
void LoadDeveloperLayout()
std::deque< SessionInfo > * sessions_
void LoadWorkspacePreset(const std::string &name)
absl::Status SaveWorkspaceLayout(const std::string &name="")
void CloseAllFloatingWindows()
LayoutManager * layout_manager_
void SplitWindowHorizontal()
void LoadDesignerLayout()
void CloseCurrentWindow()
absl::Status LoadWorkspaceLayout(const std::string &name="")
ToastManager * toast_manager_
void ExecuteWorkspaceCommand(const std::string &command_id)
#define LOG_WARN(category, format,...)
void SaveFile(const std::string &filename, const std::string &contents)
std::string LoadFile(const std::string &filename)
Loads the entire contents of a file into a string.