1#define IMGUI_DEFINE_MATH_OPERATORS
10#include "imgui/imgui.h"
11#include "imgui/imgui_internal.h"
21 if (!config_dir_result.ok()) {
22 LOG_ERROR(
"WorkspaceWindowManager",
"Failed to get config directory: %s",
23 config_dir_result.status().ToString().c_str());
27 std::filesystem::path presets_file =
28 *config_dir_result /
"layout_presets.json";
35 for (
const auto& [name, preset] :
presets_) {
37 preset_json[
"name"] = preset.name;
38 preset_json[
"description"] = preset.description;
39 preset_json[
"visible_cards"] = preset.visible_cards;
40 j[
"presets"][name] = preset_json;
43 std::ofstream file(presets_file);
44 if (!file.is_open()) {
45 LOG_ERROR(
"WorkspaceWindowManager",
"Failed to open file for writing: %s",
46 presets_file.string().c_str());
53 LOG_INFO(
"WorkspaceWindowManager",
"Saved %zu presets to %s",
54 presets_.size(), presets_file.string().c_str());
55 }
catch (
const std::exception& e) {
56 LOG_ERROR(
"WorkspaceWindowManager",
"Error saving presets: %s", e.what());
62 if (!config_dir_result.ok()) {
63 LOG_WARN(
"WorkspaceWindowManager",
"Failed to get config directory: %s",
64 config_dir_result.status().ToString().c_str());
68 std::filesystem::path presets_file =
69 *config_dir_result /
"layout_presets.json";
72 LOG_INFO(
"WorkspaceWindowManager",
"No presets file found at %s",
73 presets_file.string().c_str());
78 std::ifstream file(presets_file);
79 if (!file.is_open()) {
80 LOG_WARN(
"WorkspaceWindowManager",
"Failed to open presets file: %s",
81 presets_file.string().c_str());
90 LOG_WARN(
"WorkspaceWindowManager",
"Invalid presets file format");
94 size_t loaded_count = 0;
95 for (
auto& [name, preset_json] : j[
"presets"].
items()) {
97 preset.
name = preset_json.value(
"name", name);
98 preset.
description = preset_json.value(
"description",
"");
100 if (preset_json.contains(
"visible_cards")) {
101 yaze::Json visible_cards = preset_json[
"visible_cards"];
103 for (
const auto& card : visible_cards) {
104 if (card.is_string()) {
115 LOG_INFO(
"WorkspaceWindowManager",
"Loaded %zu presets from %s",
116 loaded_count, presets_file.string().c_str());
117 }
catch (
const std::exception& e) {
118 LOG_ERROR(
"WorkspaceWindowManager",
"Error loading presets: %s", e.what());
123 const std::string& category) {
126 return it->second.get();
132 const std::string& root_path) {
135 auto browser = std::make_unique<FileBrowser>();
137 browser->SetFileClickedCallback([
this, category](
const std::string& path) {
146 if (!root_path.empty()) {
147 browser->SetRootPath(root_path);
150 if (category ==
"Assembly") {
151 browser->SetFileFilter({
".asm",
".s",
".65c816",
".inc",
".h"});
155 LOG_INFO(
"WorkspaceWindowManager",
"Enabled file browser for category: %s",
170 const std::string& path) {
173 it->second->SetRootPath(path);
178 size_t session_id,
const std::string& base_card_id,
bool pinned) {
181 if (prefixed_id.empty()) {
182 prefixed_id =
MakeWindowId(session_id, canonical_base_id);
188 size_t session_id,
const std::string& base_card_id)
const {
191 if (prefixed_id.empty()) {
192 prefixed_id =
MakeWindowId(session_id, canonical_base_id);
199 size_t session_id)
const {
200 std::vector<std::string> result;
202 if (!session_panels) {
209 if (std::find(session_panels->begin(), session_panels->end(), panel_id) !=
210 session_panels->end()) {
212 result.push_back(base_id.empty() ? panel_id : base_id);
219 size_t session_id,
const std::string& base_card_id,
220 const std::string& prefixed_id) {
226 bool has_other_live_instance =
false;
228 (void)mapped_session;
229 auto mapping_it = mapping.find(base_card_id);
230 if (mapping_it == mapping.end()) {
233 if (mapping_it->second == prefixed_id) {
237 has_other_live_instance =
true;
242 if (!has_other_live_instance) {
248 const std::string& base_card_id,
bool pinned) {
253 const std::string& base_card_id)
const {
266 auto it =
cards_.find(card_id);
270 result.
message =
"Panel not registered";
279 result.
message =
"FAIL - Missing window name";
283 ImGuiWindow* window = ImGui::FindWindowByName(result.
expected_title.c_str());
287 result.
message =
"OK - Window found";
295std::vector<WorkspaceWindowManager::WindowValidationResult>
297 std::vector<WindowValidationResult> results;
298 results.reserve(
cards_.size());
300 for (
const auto& [card_id, info] :
cards_) {
std::string dump(int=-1, char=' ', bool=false, int=0) const
bool contains(const std::string &) const
File system browser for the sidebar.
void EnableFileBrowser(const std::string &category, const std::string &root_path="")
bool IsWindowPinnedImpl(size_t session_id, const std::string &base_card_id) const
std::string ResolveBaseWindowId(const std::string &panel_id) const
std::unordered_map< std::string, WindowDescriptor > & cards_
WindowBrowserState browser_state_
std::string GetPrefixedWindowId(size_t session_id, const std::string &base_id) const
std::vector< std::string > * FindSessionWindowIds(size_t session_id)
void RememberPinnedStateForRemovedWindow(size_t session_id, const std::string &base_card_id, const std::string &prefixed_id)
std::string GetBaseIdForPrefixedId(size_t session_id, const std::string &prefixed_id) const
FileBrowser * GetFileBrowser(const std::string &category)
std::unordered_map< size_t, std::unordered_map< std::string, std::string > > & session_card_mapping_
std::unordered_map< std::string, bool > & pending_pinned_base_ids_
void DisableFileBrowser(const std::string &category)
std::function< void(const std::string &, const std::string &) on_file_clicked_)
std::vector< std::string > GetPinnedWindowsImpl() const
std::unordered_map< std::string, WorkspacePreset > presets_
bool HasFileBrowser(const std::string &category) const
void SetWindowPinnedImpl(size_t session_id, const std::string &base_card_id, bool pinned)
std::string GetWindowNameImpl(size_t session_id, const std::string &base_card_id) const
void SetFileBrowserPath(const std::string &category, const std::string &path)
std::string MakeWindowId(size_t session_id, const std::string &base_id) const
std::vector< WindowValidationResult > ValidateWindows() const
std::unordered_map< std::string, bool > & pinned_panels_
void LoadPresetsFromFile()
WindowValidationResult ValidateWindow(const std::string &card_id) const
#define LOG_ERROR(category, format,...)
#define LOG_WARN(category, format,...)
#define LOG_INFO(category, format,...)
Metadata for a dockable editor window (formerly PanelInfo)
std::function< void(const std::string &) on_window_clicked)
std::unordered_map< std::string, std::unique_ptr< FileBrowser > > category_file_browsers
std::string expected_title
std::vector< std::string > visible_cards