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 <functional>
6#include <memory>
7#include <optional>
8#include <string>
9#include <utility>
10#include <vector>
11
12#include "absl/status/status.h"
17#include "imgui/imgui.h"
18#include "rom/rom.h"
19
20// Forward declarations
21namespace yaze {
22class Rom;
23namespace editor {
24class ISessionConfigurator;
25class EditorRegistry;
26class EditorSet;
27class WorkspaceWindowManager;
28} // namespace editor
29} // namespace yaze
30
31namespace yaze {
32namespace editor {
33
34// Forward declarations
35class EditorSet;
36class ToastManager;
37
50 public:
51 explicit SessionCoordinator(WorkspaceWindowManager* window_manager,
52 ToastManager* toast_manager,
53 UserSettings* user_settings);
55
57 editor_manager_ = manager;
58 }
59 void SetBeforeSessionTransition(std::function<absl::Status()> callback) {
60 before_session_transition_ = std::move(callback);
61 }
63 editor_registry_ = registry;
64 }
65
68 void SetEventBus(EventBus* bus) { event_bus_ = bus; }
69
70 // Session lifecycle management
71 void CreateNewSession();
75 void CloseSession(size_t index);
76 // Closes `index` even when it is the only session, leaving the app with no
77 // ROM session (the welcome surface takes over). Used by File > Close ROM.
78 // Unsaved-work confirmation is the caller's responsibility.
79 void CloseSessionAllowingEmpty(size_t index);
80 void RemoveSession(size_t index);
81 void SwitchToSession(size_t index);
82 void UpdateSessions();
83
84 // Session activation and queries
85 void ActivateSession(size_t index);
87 size_t GetActiveSessionIndex() const;
89 size_t GetActiveSessionId() const;
91 size_t GetSessionId(size_t index) const;
92 void* GetActiveSession() const;
94 Rom* GetCurrentRom() const;
97 void* GetSession(size_t index) const;
98 bool HasMultipleSessions() const;
99 size_t GetActiveSessionCount() const;
103 absl::Status CheckBackingFileAvailable(
104 const std::string& filepath,
105 std::optional<size_t> excluded_session_id = std::nullopt) const;
109 static bool PathsReferToSameBackingFile(const std::string& lhs,
110 const std::string& rhs);
111 bool HasDuplicateSession(const std::string& filepath) const;
112
113 // Session UI components
114 void DrawSessionSwitcher();
115 void DrawSessionManager();
117 void DrawSessionTabs();
119
120 // Session information
121 std::string GetSessionDisplayName(size_t index) const;
122 std::string GetActiveSessionDisplayName() const;
123 void RenameSession(size_t index, const std::string& new_name);
124 std::string GenerateUniqueEditorTitle(const std::string& editor_name,
125 size_t session_index) const;
126
127 // Session state management
128 void SetActiveSessionIndex(size_t index);
129 void UpdateSessionCount();
130
131 // Panel coordination across sessions
134 void ShowPanelsInCategory(const std::string& category);
135 void HidePanelsInCategory(const std::string& category);
136
137 // Session validation
138 bool IsValidSessionIndex(size_t index) const;
139 bool IsSessionActive(size_t index) const;
140 bool IsSessionLoaded(size_t index) const;
141
142 // Session statistics
143 size_t GetTotalSessionCount() const;
144 size_t GetLoadedSessionCount() const;
145 size_t GetEmptySessionCount() const;
146
147 // Session operations with error handling
148 absl::Status LoadRomIntoSession(const std::string& filename,
149 size_t session_index = SIZE_MAX);
150 absl::Status SaveActiveSession(const std::string& filename = "");
151 absl::Status SaveSessionAs(size_t session_index, const std::string& filename);
152 absl::StatusOr<RomSession*> CreateSessionFromRom(Rom&& rom,
153 const std::string& filepath);
154 // Remove a just-created session after a failed open transaction. Unlike the
155 // user-facing close flow, this may return the coordinator to zero sessions.
156 absl::Status DiscardProvisionalSession(size_t session_id);
157
158 // Session cleanup
160 void ClearAllSessions();
161
162 // Session navigation
163 void FocusNextSession();
165 void FocusFirstSession();
166 void FocusLastSession();
167
168 // Session UI state
175
182
183 // Helper methods
184 void UpdateActiveSession();
185 void ValidateSessionIndex(size_t index) const;
186 std::string GenerateUniqueSessionName(const std::string& base_name) const;
188 void ShowSessionOperationResult(const std::string& operation, bool success);
189
190 // UI helper methods
191 void DrawSessionTab(size_t index, bool is_active);
192 void DrawSessionContextMenu(size_t index);
193 void DrawSessionBadge(size_t index);
194 ImVec4 GetSessionColor(size_t index) const;
195 std::string GetSessionIcon(size_t index) const;
196
197 // Session validation helpers
198 bool IsSessionEmpty(size_t index) const;
199 bool IsSessionClosed(size_t index) const;
200 bool IsSessionModified(size_t index) const;
201
202 private:
203 void ActivateCreatedSession(size_t index);
204 void SwitchToSessionInternal(size_t index, bool transient);
205 absl::Status PrepareActiveSessionTransition();
206 void ApplySessionActivation(size_t index, bool transient);
207 void CloseSessionInternal(size_t index, bool allow_closing_last);
208 void NotifySessionSwitched(size_t old_index, size_t new_index,
209 RomSession* session, bool transient);
210 void NotifySessionCreated(size_t index, RomSession* session);
211 void NotifySessionClosed(size_t index);
212 void NotifySessionRomLoaded(size_t index, RomSession* session);
213
214 // Core dependencies
217 EventBus* event_bus_ = nullptr; // For publishing session lifecycle events
218 std::vector<std::unique_ptr<RomSession>> sessions_;
222
223 // Session state
225 size_t session_count_ = 0;
227
228 // UI state
234
235 // Session limits
236 static constexpr size_t kMaxSessions = 8;
237 static constexpr size_t kMinSessions = 1;
238 std::function<absl::Status()> before_session_transition_;
239};
240
241} // namespace editor
242} // namespace yaze
243
244#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:52
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)
void ApplySessionActivation(size_t index, bool transient)
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)
std::function< absl::Status()> before_session_transition_
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
void SetBeforeSessionTransition(std::function< absl::Status()> callback)
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.