refactor(editor): integrate EditorCardRegistry for card management

- Introduced EditorCardRegistry class to centralize card registration and management, enhancing session awareness and visibility control.
- Refactored EditorManager to delegate card-related operations to EditorCardRegistry, improving separation of concerns and maintainability.
- Updated CMake configuration to include new source files for the EditorCardRegistry component.

Benefits:
- Streamlines card management within the editor, leading to a more organized and efficient user experience.
- Enhances the overall architecture by clearly defining roles for card handling and editor operations.
This commit is contained in:
scawful
2025-10-14 23:35:19 -04:00
parent 9f41f8c2b8
commit 2250f03f7d
10 changed files with 1668 additions and 154 deletions

View File

@@ -41,8 +41,54 @@ UICoordinator::UICoordinator(
toast_manager_(toast_manager),
popup_manager_(popup_manager) {
// Initialize welcome screen
// Initialize welcome screen with proper callbacks
welcome_screen_ = std::make_unique<WelcomeScreen>();
// Wire welcome screen callbacks to EditorManager
welcome_screen_->SetOpenRomCallback([this]() {
if (editor_manager_) {
auto status = editor_manager_->LoadRom();
if (!status.ok()) {
toast_manager_.Show(
absl::StrFormat("Failed to load ROM: %s", status.message()),
ToastType::kError);
} else {
// Hide welcome screen on successful ROM load
show_welcome_screen_ = false;
welcome_screen_manually_closed_ = true;
}
}
});
welcome_screen_->SetNewProjectCallback([this]() {
if (editor_manager_) {
auto status = editor_manager_->CreateNewProject();
if (!status.ok()) {
toast_manager_.Show(
absl::StrFormat("Failed to create project: %s", status.message()),
ToastType::kError);
} else {
// Hide welcome screen on successful project creation
show_welcome_screen_ = false;
welcome_screen_manually_closed_ = true;
}
}
});
welcome_screen_->SetOpenProjectCallback([this](const std::string& filepath) {
if (editor_manager_) {
auto status = editor_manager_->OpenRomOrProject(filepath);
if (!status.ok()) {
toast_manager_.Show(
absl::StrFormat("Failed to open project: %s", status.message()),
ToastType::kError);
} else {
// Hide welcome screen on successful project open
show_welcome_screen_ = false;
welcome_screen_manually_closed_ = true;
}
}
});
}
void UICoordinator::DrawAllUI() {
@@ -217,10 +263,28 @@ void UICoordinator::DrawLayoutPresets() {
}
void UICoordinator::DrawWelcomeScreen() {
// Auto-show welcome screen when no ROM is loaded (unless manually closed)
if (!show_welcome_screen_ && !welcome_screen_manually_closed_) {
// Check with EditorManager if we should show welcome screen
if (editor_manager_ && editor_manager_->GetActiveSessionCount() == 0) {
show_welcome_screen_ = true;
}
}
if (!show_welcome_screen_) return;
if (welcome_screen_) {
// Update recent projects before showing
welcome_screen_->RefreshRecentProjects();
bool was_open = show_welcome_screen_;
welcome_screen_->Show(&show_welcome_screen_);
// Check if the welcome screen was manually closed via the close button
if (was_open && !show_welcome_screen_) {
welcome_screen_manually_closed_ = true;
welcome_screen_->MarkManuallyClosed();
}
}
}
@@ -247,19 +311,11 @@ void UICoordinator::HidePopup(const std::string& popup_name) {
popup_manager_.Hide(popup_name.c_str());
}
void UICoordinator::ShowEditorSelection() {
show_editor_selection_ = true;
}
void UICoordinator::ShowDisplaySettings() {
show_display_settings_ = true;
ShowPopup("Display Settings");
}
void UICoordinator::ShowSessionSwitcher() {
show_session_switcher_ = true;
}
void UICoordinator::HideCurrentEditorCards() {
// TODO: Implement card hiding logic
// This would hide cards for the current editor

View File

@@ -78,26 +78,44 @@ class UICoordinator {
void HidePopup(const std::string& popup_name);
// UI state management
void ShowEditorSelection();
void ShowEditorSelection() { show_editor_selection_ = true; }
void ShowDisplaySettings();
void ShowSessionSwitcher();
void ShowSessionSwitcher() { show_session_switcher_ = true; }
void HideCurrentEditorCards();
void ToggleCardSidebar() { show_card_sidebar_ = !show_card_sidebar_; }
void ShowGlobalSearch() { show_global_search_ = true; }
void ShowCommandPalette() { show_command_palette_ = true; }
void ShowCardBrowser() { show_card_browser_ = true; }
// Window visibility management
void ShowAllWindows();
void HideAllWindows();
// UI state queries
// UI state queries (EditorManager can check these)
bool IsEditorSelectionVisible() const { return show_editor_selection_; }
bool IsDisplaySettingsVisible() const { return show_display_settings_; }
bool IsSessionSwitcherVisible() const { return show_session_switcher_; }
bool IsWelcomeScreenVisible() const { return show_welcome_screen_; }
bool IsWelcomeScreenManuallyClosed() const { return welcome_screen_manually_closed_; }
bool IsGlobalSearchVisible() const { return show_global_search_; }
bool IsPerformanceDashboardVisible() const { return show_performance_dashboard_; }
bool IsCardBrowserVisible() const { return show_card_browser_; }
bool IsCommandPaletteVisible() const { return show_command_palette_; }
bool IsCardSidebarVisible() const { return show_card_sidebar_; }
// UI state setters
// UI state setters (for programmatic control)
void SetEditorSelectionVisible(bool visible) { show_editor_selection_ = visible; }
void SetDisplaySettingsVisible(bool visible) { show_display_settings_ = visible; }
void SetSessionSwitcherVisible(bool visible) { show_session_switcher_ = visible; }
void SetWelcomeScreenVisible(bool visible) { show_welcome_screen_ = visible; }
void SetWelcomeScreenManuallyClosed(bool closed) { welcome_screen_manually_closed_ = closed; }
void SetGlobalSearchVisible(bool visible) { show_global_search_ = visible; }
void SetPerformanceDashboardVisible(bool visible) { show_performance_dashboard_ = visible; }
void SetCardBrowserVisible(bool visible) { show_card_browser_ = visible; }
void SetCommandPaletteVisible(bool visible) { show_command_palette_ = visible; }
void SetCardSidebarVisible(bool visible) { show_card_sidebar_ = visible; }
void SetImGuiDemoVisible(bool visible) { show_imgui_demo_ = visible; }
void SetImGuiMetricsVisible(bool visible) { show_imgui_metrics_ = visible; }
// Theme and styling helpers
void ApplyMaterialDesignStyling();
@@ -115,16 +133,25 @@ class UICoordinator {
ToastManager& toast_manager_;
PopupManager& popup_manager_;
// UI state flags
// UI state flags (UICoordinator owns all UI visibility state)
bool show_editor_selection_ = false;
bool show_display_settings_ = false;
bool show_session_switcher_ = false;
bool show_welcome_screen_ = true;
bool welcome_screen_manually_closed_ = false;
bool show_global_search_ = false;
bool show_performance_dashboard_ = false;
bool show_imgui_demo_ = false;
bool show_imgui_metrics_ = false;
bool show_test_dashboard_ = false;
bool show_card_browser_ = false;
bool show_command_palette_ = false;
bool show_emulator_ = false;
bool show_memory_editor_ = false;
bool show_asm_editor_ = false;
bool show_palette_editor_ = false;
bool show_resource_label_manager_ = false;
bool show_card_sidebar_ = false;
// Welcome screen component
std::unique_ptr<WelcomeScreen> welcome_screen_;