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 // Closes `index` even when it is the only session, leaving the app with no
72 // ROM session (the welcome surface takes over). Used by File > Close ROM.
73 // Unsaved-work confirmation is the caller's responsibility.
74 void CloseSessionAllowingEmpty(size_t index);
75 void RemoveSession(size_t index);
76 void SwitchToSession(size_t index);
77 void UpdateSessions();
78
79 // Session activation and queries
80 void ActivateSession(size_t index);
82 size_t GetActiveSessionIndex() const;
84 size_t GetActiveSessionId() const;
86 size_t GetSessionId(size_t index) const;
87 void* GetActiveSession() const;
89 Rom* GetCurrentRom() const;
92 void* GetSession(size_t index) const;
93 bool HasMultipleSessions() const;
94 size_t GetActiveSessionCount() const;
98 absl::Status CheckBackingFileAvailable(
99 const std::string& filepath,
100 std::optional<size_t> excluded_session_id = std::nullopt) const;
104 static bool PathsReferToSameBackingFile(const std::string& lhs,
105 const std::string& rhs);
106 bool HasDuplicateSession(const std::string& filepath) const;
107
108 // Session UI components
109 void DrawSessionSwitcher();
110 void DrawSessionManager();
112 void DrawSessionTabs();
114
115 // Session information
116 std::string GetSessionDisplayName(size_t index) const;
117 std::string GetActiveSessionDisplayName() const;
118 void RenameSession(size_t index, const std::string& new_name);
119 std::string GenerateUniqueEditorTitle(const std::string& editor_name,
120 size_t session_index) const;
121
122 // Session state management
123 void SetActiveSessionIndex(size_t index);
124 void UpdateSessionCount();
125
126 // Panel coordination across sessions
129 void ShowPanelsInCategory(const std::string& category);
130 void HidePanelsInCategory(const std::string& category);
131
132 // Session validation
133 bool IsValidSessionIndex(size_t index) const;
134 bool IsSessionActive(size_t index) const;
135 bool IsSessionLoaded(size_t index) const;
136
137 // Session statistics
138 size_t GetTotalSessionCount() const;
139 size_t GetLoadedSessionCount() const;
140 size_t GetEmptySessionCount() const;
141
142 // Session operations with error handling
143 absl::Status LoadRomIntoSession(const std::string& filename,
144 size_t session_index = SIZE_MAX);
145 absl::Status SaveActiveSession(const std::string& filename = "");
146 absl::Status SaveSessionAs(size_t session_index, const std::string& filename);
147 absl::StatusOr<RomSession*> CreateSessionFromRom(Rom&& rom,
148 const std::string& filepath);
149 // Remove a just-created session after a failed open transaction. Unlike the
150 // user-facing close flow, this may return the coordinator to zero sessions.
151 absl::Status DiscardProvisionalSession(size_t session_id);
152
153 // Session cleanup
155 void ClearAllSessions();
156
157 // Session navigation
158 void FocusNextSession();
160 void FocusFirstSession();
161 void FocusLastSession();
162
163 // Session UI state
170
177
178 // Helper methods
179 void UpdateActiveSession();
180 void ValidateSessionIndex(size_t index) const;
181 std::string GenerateUniqueSessionName(const std::string& base_name) const;
183 void ShowSessionOperationResult(const std::string& operation, bool success);
184
185 // UI helper methods
186 void DrawSessionTab(size_t index, bool is_active);
187 void DrawSessionContextMenu(size_t index);
188 void DrawSessionBadge(size_t index);
189 ImVec4 GetSessionColor(size_t index) const;
190 std::string GetSessionIcon(size_t index) const;
191
192 // Session validation helpers
193 bool IsSessionEmpty(size_t index) const;
194 bool IsSessionClosed(size_t index) const;
195 bool IsSessionModified(size_t index) const;
196
197 private:
198 void ActivateCreatedSession(size_t index);
199 void SwitchToSessionInternal(size_t index, bool transient);
200 void CloseSessionInternal(size_t index, bool allow_closing_last);
201 void NotifySessionSwitched(size_t old_index, size_t new_index,
202 RomSession* session, bool transient);
203 void NotifySessionCreated(size_t index, RomSession* session);
204 void NotifySessionClosed(size_t index);
205 void NotifySessionRomLoaded(size_t index, RomSession* session);
206
207 // Core dependencies
210 EventBus* event_bus_ = nullptr; // For publishing session lifecycle events
211 std::vector<std::unique_ptr<RomSession>> sessions_;
215
216 // Session state
218 size_t session_count_ = 0;
220
221 // UI state
227
228 // Session limits
229 static constexpr size_t kMaxSessions = 8;
230 static constexpr size_t kMinSessions = 1;
231};
232
233} // namespace editor
234} // namespace yaze
235
236#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:49
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 CloseSessionInternal(size_t index, bool allow_closing_last)
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.