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"
13#include "rom/rom.h"
14#include "imgui/imgui.h"
15
16// Forward declarations
17namespace yaze {
18class Rom;
19namespace editor {
20class EditorManager;
21class EditorSet;
22class PanelManager;
23} // namespace editor
24} // namespace yaze
25
26namespace yaze {
27namespace editor {
28
29// Forward declarations
30class EditorSet;
31class ToastManager;
32
41 public:
42 virtual ~SessionObserver() = default;
43
45 virtual void OnSessionSwitched(size_t new_index, RomSession* session) = 0;
46
48 virtual void OnSessionCreated(size_t index, RomSession* session) = 0;
49
51 virtual void OnSessionClosed(size_t index) = 0;
52
54 virtual void OnSessionRomLoaded(size_t index, RomSession* session) {}
55};
56
69 public:
70 explicit SessionCoordinator(PanelManager* panel_manager,
71 ToastManager* toast_manager,
72 UserSettings* user_settings);
74
75 void SetEditorManager(EditorManager* manager) { editor_manager_ = manager; }
76
77 // Observer management
78 void AddObserver(SessionObserver* observer);
79 void RemoveObserver(SessionObserver* observer);
80
81 // Session lifecycle management
82 void CreateNewSession();
85 void CloseSession(size_t index);
86 void RemoveSession(size_t index);
87 void SwitchToSession(size_t index);
88 void UpdateSessions();
89
90 // Session activation and queries
91 void ActivateSession(size_t index);
92 size_t GetActiveSessionIndex() const;
93 void* GetActiveSession() const;
95 Rom* GetCurrentRom() const;
98 void* GetSession(size_t index) const;
99 bool HasMultipleSessions() const;
100 size_t GetActiveSessionCount() const;
101 bool HasDuplicateSession(const std::string& filepath) const;
102
103 // Session UI components
104 void DrawSessionSwitcher();
105 void DrawSessionManager();
107 void DrawSessionTabs();
109
110 // Session information
111 std::string GetSessionDisplayName(size_t index) const;
112 std::string GetActiveSessionDisplayName() const;
113 void RenameSession(size_t index, const std::string& new_name);
114 std::string GenerateUniqueEditorTitle(const std::string& editor_name,
115 size_t session_index) const;
116
117 // Session state management
118 void SetActiveSessionIndex(size_t index);
119 void UpdateSessionCount();
120
121 // Panel coordination across sessions
124 void ShowPanelsInCategory(const std::string& category);
125 void HidePanelsInCategory(const std::string& category);
126
127 // Session validation
128 bool IsValidSessionIndex(size_t index) const;
129 bool IsSessionActive(size_t index) const;
130 bool IsSessionLoaded(size_t index) const;
131
132 // Session statistics
133 size_t GetTotalSessionCount() const;
134 size_t GetLoadedSessionCount() const;
135 size_t GetEmptySessionCount() const;
136
137 // Session operations with error handling
138 absl::Status LoadRomIntoSession(const std::string& filename,
139 size_t session_index = SIZE_MAX);
140 absl::Status SaveActiveSession(const std::string& filename = "");
141 absl::Status SaveSessionAs(size_t session_index, const std::string& filename);
142 absl::StatusOr<RomSession*> CreateSessionFromRom(Rom&& rom,
143 const std::string& filepath);
144
145 // Session cleanup
147 void ClearAllSessions();
148
149 // Session navigation
150 void FocusNextSession();
152 void FocusFirstSession();
153 void FocusLastSession();
154
155 // Session UI state
162
169
170 // Helper methods
171 void UpdateActiveSession();
172 void ValidateSessionIndex(size_t index) const;
173 std::string GenerateUniqueSessionName(const std::string& base_name) const;
175 void ShowSessionOperationResult(const std::string& operation, bool success);
176
177 // UI helper methods
178 void DrawSessionTab(size_t index, bool is_active);
179 void DrawSessionContextMenu(size_t index);
180 void DrawSessionBadge(size_t index);
181 ImVec4 GetSessionColor(size_t index) const;
182 std::string GetSessionIcon(size_t index) const;
183
184 // Session validation helpers
185 bool IsSessionEmpty(size_t index) const;
186 bool IsSessionClosed(size_t index) const;
187 bool IsSessionModified(size_t index) const;
188
189 private:
190 // Observer notification helpers
191 void NotifySessionSwitched(size_t index, RomSession* session);
192 void NotifySessionCreated(size_t index, RomSession* session);
193 void NotifySessionClosed(size_t index);
194 void NotifySessionRomLoaded(size_t index, RomSession* session);
195
196 // Core dependencies
198 std::vector<std::unique_ptr<RomSession>> sessions_;
199 std::vector<SessionObserver*> observers_;
203
204 // Session state
206 size_t session_count_ = 0;
207
208 // UI state
214
215 // Session limits
216 static constexpr size_t kMaxSessions = 8;
217 static constexpr size_t kMinSessions = 1;
218};
219
220} // namespace editor
221} // namespace yaze
222
223#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:24
The EditorManager controls the main editor window and manages the various editor classes.
Contains a complete set of editors for a single ROM instance.
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
void RemoveObserver(SessionObserver *observer)
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)
absl::Status SaveActiveSession(const std::string &filename="")
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
void SetEditorManager(EditorManager *manager)
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
std::vector< SessionObserver * > observers_
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 AddObserver(SessionObserver *observer)
void NotifySessionSwitched(size_t index, RomSession *session)
bool IsSessionLoaded(size_t index) const
std::string GenerateUniqueSessionName(const std::string &base_name) const
Observer interface for session state changes.
virtual void OnSessionSwitched(size_t new_index, RomSession *session)=0
Called when the active session changes.
virtual void OnSessionClosed(size_t index)=0
Called when a session is closed.
virtual void OnSessionCreated(size_t index, RomSession *session)=0
Called when a new session is created.
virtual void OnSessionRomLoaded(size_t index, RomSession *session)
Called when a ROM is loaded into a session.
virtual ~SessionObserver()=default
Manages user preferences and settings persistence.
Represents a single session, containing a ROM and its associated editors.