yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
session_coordinator.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_SYSTEM_SESSION_COORDINATOR_H_
2#define YAZE_APP_EDITOR_SYSTEM_SESSION_COORDINATOR_H_
3
4#include <deque>
5#include <string>
6#include <vector>
7#include <memory>
8
9#include "absl/status/status.h"
14#include "rom/rom.h"
15#include "imgui/imgui.h"
16
17// Forward declarations
18namespace yaze {
19class Rom;
20namespace editor {
21class ISessionConfigurator;
22class EditorRegistry;
23class EditorSet;
24class PanelManager;
25} // namespace editor
26} // namespace yaze
27
28namespace yaze {
29namespace editor {
30
31// Forward declarations
32class EditorSet;
33class ToastManager;
34
47 public:
48 explicit SessionCoordinator(PanelManager* panel_manager,
49 ToastManager* toast_manager,
50 UserSettings* user_settings);
52
54 editor_manager_ = manager;
55 }
57 editor_registry_ = registry;
58 }
59
62 void SetEventBus(EventBus* bus) { event_bus_ = bus; }
63
64 // Session lifecycle management
65 void CreateNewSession();
68 void CloseSession(size_t index);
69 void RemoveSession(size_t index);
70 void SwitchToSession(size_t index);
71 void UpdateSessions();
72
73 // Session activation and queries
74 void ActivateSession(size_t index);
75 size_t GetActiveSessionIndex() const;
76 void* GetActiveSession() const;
78 Rom* GetCurrentRom() const;
81 void* GetSession(size_t index) const;
82 bool HasMultipleSessions() const;
83 size_t GetActiveSessionCount() const;
84 bool HasDuplicateSession(const std::string& filepath) const;
85
86 // Session UI components
88 void DrawSessionManager();
90 void DrawSessionTabs();
92
93 // Session information
94 std::string GetSessionDisplayName(size_t index) const;
95 std::string GetActiveSessionDisplayName() const;
96 void RenameSession(size_t index, const std::string& new_name);
97 std::string GenerateUniqueEditorTitle(const std::string& editor_name,
98 size_t session_index) const;
99
100 // Session state management
101 void SetActiveSessionIndex(size_t index);
102 void UpdateSessionCount();
103
104 // Panel coordination across sessions
107 void ShowPanelsInCategory(const std::string& category);
108 void HidePanelsInCategory(const std::string& category);
109
110 // Session validation
111 bool IsValidSessionIndex(size_t index) const;
112 bool IsSessionActive(size_t index) const;
113 bool IsSessionLoaded(size_t index) const;
114
115 // Session statistics
116 size_t GetTotalSessionCount() const;
117 size_t GetLoadedSessionCount() const;
118 size_t GetEmptySessionCount() const;
119
120 // Session operations with error handling
121 absl::Status LoadRomIntoSession(const std::string& filename,
122 size_t session_index = SIZE_MAX);
123 absl::Status SaveActiveSession(const std::string& filename = "");
124 absl::Status SaveSessionAs(size_t session_index, const std::string& filename);
125 absl::StatusOr<RomSession*> CreateSessionFromRom(Rom&& rom,
126 const std::string& filepath);
127
128 // Session cleanup
130 void ClearAllSessions();
131
132 // Session navigation
133 void FocusNextSession();
135 void FocusFirstSession();
136 void FocusLastSession();
137
138 // Session UI state
145
152
153 // Helper methods
154 void UpdateActiveSession();
155 void ValidateSessionIndex(size_t index) const;
156 std::string GenerateUniqueSessionName(const std::string& base_name) const;
158 void ShowSessionOperationResult(const std::string& operation, bool success);
159
160 // UI helper methods
161 void DrawSessionTab(size_t index, bool is_active);
162 void DrawSessionContextMenu(size_t index);
163 void DrawSessionBadge(size_t index);
164 ImVec4 GetSessionColor(size_t index) const;
165 std::string GetSessionIcon(size_t index) const;
166
167 // Session validation helpers
168 bool IsSessionEmpty(size_t index) const;
169 bool IsSessionClosed(size_t index) const;
170 bool IsSessionModified(size_t index) const;
171
172 private:
173 void NotifySessionSwitched(size_t index, RomSession* session);
174 void NotifySessionCreated(size_t index, RomSession* session);
175 void NotifySessionClosed(size_t index);
176 void NotifySessionRomLoaded(size_t index, RomSession* session);
177
178 // Core dependencies
181 EventBus* event_bus_ = nullptr; // For publishing session lifecycle events
182 std::vector<std::unique_ptr<RomSession>> sessions_;
186
187 // Session state
189 size_t session_count_ = 0;
190
191 // UI state
197
198 // Session limits
199 static constexpr size_t kMaxSessions = 8;
200 static constexpr size_t kMinSessions = 1;
201};
202
203} // namespace editor
204} // namespace yaze
205
206#endif // YAZE_APP_EDITOR_SYSTEM_SESSION_COORDINATOR_H_
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:28
Manages editor types, categories, and lifecycle.
Contains a complete set of editors for a single ROM instance.
Interface for session configuration.
Central registry for all editor cards with session awareness and dependency injection.
High-level orchestrator for multi-session UI.
void NotifySessionCreated(size_t index, RomSession *session)
void * GetSession(size_t index) const
std::string GenerateUniqueEditorTitle(const std::string &editor_name, size_t session_index) const
zelda3::GameData * GetCurrentGameData() const
void NotifySessionRomLoaded(size_t index, RomSession *session)
absl::StatusOr< RomSession * > CreateSessionFromRom(Rom &&rom, const std::string &filepath)
absl::Status SaveSessionAs(size_t session_index, const std::string &filename)
void SetEditorManager(ISessionConfigurator *manager)
absl::Status SaveActiveSession(const std::string &filename="")
void SetEditorRegistry(EditorRegistry *registry)
ImVec4 GetSessionColor(size_t index) const
absl::Status LoadRomIntoSession(const std::string &filename, size_t session_index=SIZE_MAX)
std::string GetSessionDisplayName(size_t index) const
void RenameSession(size_t index, const std::string &new_name)
bool IsSessionModified(size_t index) const
SessionCoordinator(PanelManager *panel_manager, ToastManager *toast_manager, UserSettings *user_settings)
bool HasDuplicateSession(const std::string &filepath) const
void ShowPanelsInCategory(const std::string &category)
void HidePanelsInCategory(const std::string &category)
bool IsSessionClosed(size_t index) const
std::string GetSessionIcon(size_t index) const
std::string GetActiveSessionDisplayName() const
void ShowSessionOperationResult(const std::string &operation, bool success)
bool IsValidSessionIndex(size_t index) const
bool IsSessionEmpty(size_t index) const
void DrawSessionTab(size_t index, bool is_active)
bool IsSessionActive(size_t index) const
std::vector< std::unique_ptr< RomSession > > sessions_
void ValidateSessionIndex(size_t index) const
void NotifySessionSwitched(size_t index, RomSession *session)
bool IsSessionLoaded(size_t index) const
std::string GenerateUniqueSessionName(const std::string &base_name) const
Manages user preferences and settings persistence.
Represents a single session, containing a ROM and its associated editors.