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 <memory>
6#include <optional>
7#include <string>
8#include <vector>
9
10#include "absl/status/status.h"
15#include "imgui/imgui.h"
16#include "rom/rom.h"
17
18// Forward declarations
19namespace yaze {
20class Rom;
21namespace editor {
22class ISessionConfigurator;
23class EditorRegistry;
24class EditorSet;
25class WorkspaceWindowManager;
26} // namespace editor
27} // namespace yaze
28
29namespace yaze {
30namespace editor {
31
32// Forward declarations
33class EditorSet;
34class ToastManager;
35
48 public:
49 explicit SessionCoordinator(WorkspaceWindowManager* window_manager,
50 ToastManager* toast_manager,
51 UserSettings* user_settings);
53
55 editor_manager_ = manager;
56 }
58 editor_registry_ = registry;
59 }
60
63 void SetEventBus(EventBus* bus) { event_bus_ = bus; }
64
65 // Session lifecycle management
66 void CreateNewSession();
70 void CloseSession(size_t index);
71 void RemoveSession(size_t index);
72 void SwitchToSession(size_t index);
73 void UpdateSessions();
74
75 // Session activation and queries
76 void ActivateSession(size_t index);
78 size_t GetActiveSessionIndex() const;
80 size_t GetActiveSessionId() const;
82 size_t GetSessionId(size_t index) const;
83 void* GetActiveSession() const;
85 Rom* GetCurrentRom() const;
88 void* GetSession(size_t index) const;
89 bool HasMultipleSessions() const;
90 size_t GetActiveSessionCount() const;
94 absl::Status CheckBackingFileAvailable(
95 const std::string& filepath,
96 std::optional<size_t> excluded_session_id = std::nullopt) const;
100 static bool PathsReferToSameBackingFile(const std::string& lhs,
101 const std::string& rhs);
102 bool HasDuplicateSession(const std::string& filepath) const;
103
104 // Session UI components
105 void DrawSessionSwitcher();
106 void DrawSessionManager();
108 void DrawSessionTabs();
110
111 // Session information
112 std::string GetSessionDisplayName(size_t index) const;
113 std::string GetActiveSessionDisplayName() const;
114 void RenameSession(size_t index, const std::string& new_name);
115 std::string GenerateUniqueEditorTitle(const std::string& editor_name,
116 size_t session_index) const;
117
118 // Session state management
119 void SetActiveSessionIndex(size_t index);
120 void UpdateSessionCount();
121
122 // Panel coordination across sessions
125 void ShowPanelsInCategory(const std::string& category);
126 void HidePanelsInCategory(const std::string& category);
127
128 // Session validation
129 bool IsValidSessionIndex(size_t index) const;
130 bool IsSessionActive(size_t index) const;
131 bool IsSessionLoaded(size_t index) const;
132
133 // Session statistics
134 size_t GetTotalSessionCount() const;
135 size_t GetLoadedSessionCount() const;
136 size_t GetEmptySessionCount() const;
137
138 // Session operations with error handling
139 absl::Status LoadRomIntoSession(const std::string& filename,
140 size_t session_index = SIZE_MAX);
141 absl::Status SaveActiveSession(const std::string& filename = "");
142 absl::Status SaveSessionAs(size_t session_index, const std::string& filename);
143 absl::StatusOr<RomSession*> CreateSessionFromRom(Rom&& rom,
144 const std::string& filepath);
145 // Remove a just-created session after a failed open transaction. Unlike the
146 // user-facing close flow, this may return the coordinator to zero sessions.
147 absl::Status DiscardProvisionalSession(size_t session_id);
148
149 // Session cleanup
151 void ClearAllSessions();
152
153 // Session navigation
154 void FocusNextSession();
156 void FocusFirstSession();
157 void FocusLastSession();
158
159 // Session UI state
166
173
174 // Helper methods
175 void UpdateActiveSession();
176 void ValidateSessionIndex(size_t index) const;
177 std::string GenerateUniqueSessionName(const std::string& base_name) const;
179 void ShowSessionOperationResult(const std::string& operation, bool success);
180
181 // UI helper methods
182 void DrawSessionTab(size_t index, bool is_active);
183 void DrawSessionContextMenu(size_t index);
184 void DrawSessionBadge(size_t index);
185 ImVec4 GetSessionColor(size_t index) const;
186 std::string GetSessionIcon(size_t index) const;
187
188 // Session validation helpers
189 bool IsSessionEmpty(size_t index) const;
190 bool IsSessionClosed(size_t index) const;
191 bool IsSessionModified(size_t index) const;
192
193 private:
194 void ActivateCreatedSession(size_t index);
195 void SwitchToSessionInternal(size_t index, bool transient);
196 void NotifySessionSwitched(size_t old_index, size_t new_index,
197 RomSession* session, bool transient);
198 void NotifySessionCreated(size_t index, RomSession* session);
199 void NotifySessionClosed(size_t index);
200 void NotifySessionRomLoaded(size_t index, RomSession* session);
201
202 // Core dependencies
205 EventBus* event_bus_ = nullptr; // For publishing session lifecycle events
206 std::vector<std::unique_ptr<RomSession>> sessions_;
210
211 // Session state
213 size_t session_count_ = 0;
215
216 // UI state
222
223 // Session limits
224 static constexpr size_t kMaxSessions = 8;
225 static constexpr size_t kMinSessions = 1;
226};
227
228} // namespace editor
229} // namespace yaze
230
231#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.
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
size_t GetActiveSessionIndex() const
Compact zero-based UI position in sessions_.
void NotifySessionSwitched(size_t old_index, size_t new_index, RomSession *session, bool transient)
void NotifySessionRomLoaded(size_t index, RomSession *session)
absl::StatusOr< RomSession * > CreateSessionFromRom(Rom &&rom, const std::string &filepath)
SessionCoordinator(WorkspaceWindowManager *window_manager, ToastManager *toast_manager, UserSettings *user_settings)
absl::Status SaveSessionAs(size_t session_index, const std::string &filename)
void SetEditorManager(ISessionConfigurator *manager)
size_t GetSessionId(size_t index) const
Resolve a compact UI index to its stable workspace identity.
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)
absl::Status CheckBackingFileAvailable(const std::string &filepath, std::optional< size_t > excluded_session_id=std::nullopt) const
std::string GetSessionDisplayName(size_t index) const
void RenameSession(size_t index, const std::string &new_name)
bool IsSessionModified(size_t index) const
absl::Status DiscardProvisionalSession(size_t session_id)
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
size_t GetActiveSessionId() const
Stable workspace identity that is never reused while this coordinator lives.
WorkspaceWindowManager * window_manager_
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 SwitchToSessionInternal(size_t index, bool transient)
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
bool IsSessionLoaded(size_t index) const
std::string GenerateUniqueSessionName(const std::string &base_name) const
static bool PathsReferToSameBackingFile(const std::string &lhs, const std::string &rhs)
Manages user preferences and settings persistence.
Central registry for all editor cards with session awareness and dependency injection.
Represents a single session, containing a ROM and its associated editors.