refactor(editor): integrate EditorCardRegistry for improved card management
- Updated EditorManager and various editor components to utilize EditorCardRegistry for card registration and visibility management, enhancing dependency injection and modularity. - Refactored card registration logic across multiple editors, ensuring a consistent approach to managing editor cards. - Improved UI coordination by delegating visibility checks and card management to the new registry, streamlining the user experience. Benefits: - Simplifies card management, leading to a more organized and efficient user experience. - Enhances maintainability by clearly defining roles for card handling and editor operations, aligning with the overall architecture improvements.
This commit is contained in:
@@ -33,6 +33,7 @@ UICoordinator::UICoordinator(
|
||||
RomFileManager& rom_manager,
|
||||
ProjectManager& project_manager,
|
||||
EditorRegistry& editor_registry,
|
||||
EditorCardRegistry& card_registry,
|
||||
SessionCoordinator& session_coordinator,
|
||||
WindowDelegate& window_delegate,
|
||||
ToastManager& toast_manager,
|
||||
@@ -42,6 +43,7 @@ UICoordinator::UICoordinator(
|
||||
rom_manager_(rom_manager),
|
||||
project_manager_(project_manager),
|
||||
editor_registry_(editor_registry),
|
||||
card_registry_(card_registry),
|
||||
session_coordinator_(session_coordinator),
|
||||
window_delegate_(window_delegate),
|
||||
toast_manager_(toast_manager),
|
||||
@@ -191,14 +193,38 @@ void UICoordinator::DrawContextSensitiveCardControl() {
|
||||
if (!active_editor) return;
|
||||
|
||||
std::string category = editor_registry_.GetEditorCategory(active_editor->type());
|
||||
size_t session_id = editor_manager_->GetCurrentSessionId();
|
||||
|
||||
// Draw compact card control with session awareness
|
||||
auto& card_manager = gui::EditorCardManager::Get();
|
||||
if (session_coordinator_.HasMultipleSessions()) {
|
||||
std::string session_prefix = absl::StrFormat("s%zu", session_coordinator_.GetActiveSessionIndex());
|
||||
card_manager.DrawCompactCardControlWithSession(category, session_prefix);
|
||||
} else {
|
||||
card_manager.DrawCompactCardControl(category);
|
||||
// Draw compact card control in menu bar (mini dropdown for cards)
|
||||
ImGui::SameLine();
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, gui::GetSurfaceContainerHighVec4());
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, gui::GetSurfaceContainerHighestVec4());
|
||||
|
||||
if (ImGui::SmallButton(absl::StrFormat("%s %s", ICON_MD_LAYERS, category.c_str()).c_str())) {
|
||||
ImGui::OpenPopup("##CardQuickAccess");
|
||||
}
|
||||
|
||||
ImGui::PopStyleColor(2);
|
||||
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::SetTooltip("Quick access to %s cards", category.c_str());
|
||||
}
|
||||
|
||||
// Quick access popup for toggling cards
|
||||
if (ImGui::BeginPopup("##CardQuickAccess")) {
|
||||
auto cards = card_registry_.GetCardsInCategory(session_id, category);
|
||||
|
||||
for (const auto& card : cards) {
|
||||
bool visible = card.visibility_flag ? *card.visibility_flag : false;
|
||||
if (ImGui::MenuItem(card.display_name.c_str(), nullptr, visible)) {
|
||||
if (visible) {
|
||||
card_registry_.HideCard(session_id, card.card_id);
|
||||
} else {
|
||||
card_registry_.ShowCard(session_id, card.card_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ class UICoordinator {
|
||||
RomFileManager& rom_manager,
|
||||
ProjectManager& project_manager,
|
||||
EditorRegistry& editor_registry,
|
||||
EditorCardRegistry& card_registry,
|
||||
SessionCoordinator& session_coordinator,
|
||||
WindowDelegate& window_delegate,
|
||||
ToastManager& toast_manager,
|
||||
@@ -108,6 +109,8 @@ class UICoordinator {
|
||||
bool IsCardBrowserVisible() const { return show_card_browser_; }
|
||||
bool IsCommandPaletteVisible() const { return show_command_palette_; }
|
||||
bool IsCardSidebarVisible() const { return show_card_sidebar_; }
|
||||
bool IsImGuiDemoVisible() const { return show_imgui_demo_; }
|
||||
bool IsImGuiMetricsVisible() const { return show_imgui_metrics_; }
|
||||
|
||||
// UI state setters (for programmatic control)
|
||||
void SetEditorSelectionVisible(bool visible) { show_editor_selection_ = visible; }
|
||||
@@ -131,6 +134,7 @@ class UICoordinator {
|
||||
RomFileManager& rom_manager_;
|
||||
ProjectManager& project_manager_;
|
||||
EditorRegistry& editor_registry_;
|
||||
EditorCardRegistry& card_registry_;
|
||||
SessionCoordinator& session_coordinator_;
|
||||
WindowDelegate& window_delegate_;
|
||||
ToastManager& toast_manager_;
|
||||
@@ -155,7 +159,7 @@ class UICoordinator {
|
||||
bool show_asm_editor_ = false;
|
||||
bool show_palette_editor_ = false;
|
||||
bool show_resource_label_manager_ = false;
|
||||
bool show_card_sidebar_ = false;
|
||||
bool show_card_sidebar_ = true; // Show sidebar by default
|
||||
|
||||
// Command Palette state
|
||||
char command_palette_query_[256] = {};
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
|
||||
#include "app/editor/ui/workspace_manager.h"
|
||||
#include "app/editor/system/editor_card_registry.h"
|
||||
#include "app/editor/system/toast_manager.h"
|
||||
#include "app/gui/app/editor_card_manager.h"
|
||||
#include "app/rom.h"
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "util/file_util.h"
|
||||
@@ -125,14 +127,18 @@ void WorkspaceManager::LoadModderLayout() {
|
||||
}
|
||||
|
||||
void WorkspaceManager::ShowAllWindows() {
|
||||
gui::EditorCardManager::Get().ShowAll();
|
||||
if (card_registry_) {
|
||||
card_registry_->ShowAll();
|
||||
}
|
||||
if (toast_manager_) {
|
||||
toast_manager_->Show("All windows shown", ToastType::kInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void WorkspaceManager::HideAllWindows() {
|
||||
gui::EditorCardManager::Get().HideAll();
|
||||
if (card_registry_) {
|
||||
card_registry_->HideAll();
|
||||
}
|
||||
if (toast_manager_) {
|
||||
toast_manager_->Show("All windows hidden", ToastType::kInfo);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace editor {
|
||||
|
||||
class EditorSet;
|
||||
class ToastManager;
|
||||
class EditorCardRegistry;
|
||||
|
||||
/**
|
||||
* @brief Manages workspace layouts, sessions, and presets
|
||||
@@ -28,6 +29,9 @@ class WorkspaceManager {
|
||||
explicit WorkspaceManager(ToastManager* toast_manager)
|
||||
: toast_manager_(toast_manager) {}
|
||||
|
||||
// Set card registry for window visibility management
|
||||
void set_card_registry(EditorCardRegistry* registry) { card_registry_ = registry; }
|
||||
|
||||
// Layout management
|
||||
absl::Status SaveWorkspaceLayout(const std::string& name = "");
|
||||
absl::Status LoadWorkspaceLayout(const std::string& name = "");
|
||||
@@ -69,6 +73,7 @@ class WorkspaceManager {
|
||||
|
||||
private:
|
||||
ToastManager* toast_manager_;
|
||||
EditorCardRegistry* card_registry_ = nullptr;
|
||||
std::deque<SessionInfo>* sessions_ = nullptr;
|
||||
std::string last_workspace_preset_;
|
||||
std::vector<std::string> workspace_presets_;
|
||||
|
||||
Reference in New Issue
Block a user