Migrate ProjectManager to dependency injection
- Created IProjectManager interface - ProjectManager now implements IProjectManager - Removed ProjectManager::Get() singleton - Added IEditorContext::GetProjectManager() - ProjectPanel now uses m_context->GetProjectManager() instead of singleton - EditorContext owns ProjectManager instance
This commit is contained in:
@@ -3,7 +3,9 @@
|
||||
#include "IEditorContext.h"
|
||||
#include "EventBus.h"
|
||||
#include "SelectionManager.h"
|
||||
#include "IProjectManager.h"
|
||||
#include "Managers/SceneManager.h"
|
||||
#include "Managers/ProjectManager.h"
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
@@ -15,7 +17,8 @@ public:
|
||||
EditorContext()
|
||||
: m_eventBus(std::make_unique<EventBus>())
|
||||
, m_selectionManager(std::make_unique<SelectionManager>(*m_eventBus))
|
||||
, m_sceneManager(std::make_unique<SceneManager>()) {
|
||||
, m_sceneManager(std::make_unique<SceneManager>())
|
||||
, m_projectManager(std::make_unique<ProjectManager>()) {
|
||||
m_sceneManager->SetSelectionManager(m_selectionManager.get());
|
||||
}
|
||||
|
||||
@@ -35,6 +38,10 @@ public:
|
||||
return *m_sceneManager;
|
||||
}
|
||||
|
||||
IProjectManager& GetProjectManager() override {
|
||||
return *m_projectManager;
|
||||
}
|
||||
|
||||
void SetProjectPath(const std::string& path) override {
|
||||
m_projectPath = path;
|
||||
}
|
||||
@@ -47,8 +54,9 @@ private:
|
||||
std::unique_ptr<EventBus> m_eventBus;
|
||||
std::unique_ptr<SelectionManager> m_selectionManager;
|
||||
std::unique_ptr<SceneManager> m_sceneManager;
|
||||
std::unique_ptr<ProjectManager> m_projectManager;
|
||||
std::string m_projectPath;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ namespace Editor {
|
||||
|
||||
class EventBus;
|
||||
class ISelectionManager;
|
||||
class IProjectManager;
|
||||
|
||||
class IEditorContext {
|
||||
public:
|
||||
@@ -16,6 +17,7 @@ public:
|
||||
virtual EventBus& GetEventBus() = 0;
|
||||
virtual ISelectionManager& GetSelectionManager() = 0;
|
||||
virtual void* GetSceneManager() = 0;
|
||||
virtual IProjectManager& GetProjectManager() = 0;
|
||||
|
||||
virtual void SetProjectPath(const std::string& path) = 0;
|
||||
virtual const std::string& GetProjectPath() const = 0;
|
||||
|
||||
39
editor/src/Core/IProjectManager.h
Normal file
39
editor/src/Core/IProjectManager.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include "Core/AssetItem.h"
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Editor {
|
||||
|
||||
class IProjectManager {
|
||||
public:
|
||||
virtual ~IProjectManager() = default;
|
||||
|
||||
virtual std::vector<AssetItemPtr>& GetCurrentItems() = 0;
|
||||
virtual int GetSelectedIndex() const = 0;
|
||||
virtual void SetSelectedIndex(int index) = 0;
|
||||
|
||||
virtual void NavigateToFolder(const AssetItemPtr& folder) = 0;
|
||||
virtual void NavigateBack() = 0;
|
||||
virtual void NavigateToIndex(size_t index) = 0;
|
||||
virtual bool CanNavigateBack() const = 0;
|
||||
|
||||
virtual std::string GetCurrentPath() const = 0;
|
||||
virtual size_t GetPathDepth() const = 0;
|
||||
virtual std::string GetPathName(size_t index) const = 0;
|
||||
|
||||
virtual void Initialize(const std::string& projectPath) = 0;
|
||||
virtual void RefreshCurrentFolder() = 0;
|
||||
|
||||
virtual void CreateFolder(const std::string& name) = 0;
|
||||
virtual void DeleteItem(int index) = 0;
|
||||
virtual bool MoveItem(const std::string& sourceFullPath, const std::string& destFolderFullPath) = 0;
|
||||
|
||||
virtual const std::string& GetProjectPath() const = 0;
|
||||
};
|
||||
|
||||
} // namespace Editor
|
||||
} // namespace XCEngine
|
||||
@@ -9,11 +9,6 @@ namespace fs = std::filesystem;
|
||||
namespace XCEngine {
|
||||
namespace Editor {
|
||||
|
||||
ProjectManager& ProjectManager::Get() {
|
||||
static ProjectManager instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
std::vector<AssetItemPtr>& ProjectManager::GetCurrentItems() {
|
||||
if (m_path.empty()) {
|
||||
static std::vector<AssetItemPtr> empty;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Core/AssetItem.h"
|
||||
#include "Core/IProjectManager.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
@@ -8,35 +9,31 @@
|
||||
namespace XCEngine {
|
||||
namespace Editor {
|
||||
|
||||
class ProjectManager {
|
||||
class ProjectManager : public IProjectManager {
|
||||
public:
|
||||
static ProjectManager& Get();
|
||||
std::vector<AssetItemPtr>& GetCurrentItems() override;
|
||||
int GetSelectedIndex() const override { return m_selectedIndex; }
|
||||
void SetSelectedIndex(int index) override { m_selectedIndex = index; }
|
||||
|
||||
std::vector<AssetItemPtr>& GetCurrentItems();
|
||||
int GetSelectedIndex() const { return m_selectedIndex; }
|
||||
void SetSelectedIndex(int index) { m_selectedIndex = index; }
|
||||
void NavigateToFolder(const AssetItemPtr& folder) override;
|
||||
void NavigateBack() override;
|
||||
void NavigateToIndex(size_t index) override;
|
||||
bool CanNavigateBack() const override { return m_path.size() > 1; }
|
||||
|
||||
void NavigateToFolder(const AssetItemPtr& folder);
|
||||
void NavigateBack();
|
||||
void NavigateToIndex(size_t index);
|
||||
bool CanNavigateBack() const { return m_path.size() > 1; }
|
||||
std::string GetCurrentPath() const override;
|
||||
size_t GetPathDepth() const override { return m_path.size(); }
|
||||
std::string GetPathName(size_t index) const override;
|
||||
|
||||
std::string GetCurrentPath() const;
|
||||
size_t GetPathDepth() const { return m_path.size(); }
|
||||
std::string GetPathName(size_t index) const;
|
||||
void Initialize(const std::string& projectPath) override;
|
||||
void RefreshCurrentFolder() override;
|
||||
|
||||
void Initialize(const std::string& projectPath);
|
||||
void RefreshCurrentFolder();
|
||||
void CreateFolder(const std::string& name) override;
|
||||
void DeleteItem(int index) override;
|
||||
bool MoveItem(const std::string& sourceFullPath, const std::string& destFolderFullPath) override;
|
||||
|
||||
void CreateFolder(const std::string& name);
|
||||
void DeleteItem(int index);
|
||||
bool MoveItem(const std::string& sourceFullPath, const std::string& destFolderFullPath);
|
||||
|
||||
const std::string& GetProjectPath() const { return m_projectPath; }
|
||||
const std::string& GetProjectPath() const override { return m_projectPath; }
|
||||
|
||||
private:
|
||||
ProjectManager() = default;
|
||||
|
||||
AssetItemPtr ScanDirectory(const std::wstring& path);
|
||||
AssetItemPtr CreateAssetItem(const std::wstring& path, const std::wstring& nameW, bool isFolder);
|
||||
std::wstring GetCurrentFullPathW() const;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "ProjectPanel.h"
|
||||
#include "Managers/ProjectManager.h"
|
||||
#include "Core/IEditorContext.h"
|
||||
#include "Core/IProjectManager.h"
|
||||
#include "Core/AssetItem.h"
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
@@ -13,7 +14,7 @@ ProjectPanel::ProjectPanel() : Panel("Project") {
|
||||
}
|
||||
|
||||
void ProjectPanel::Initialize(const std::string& projectPath) {
|
||||
ProjectManager::Get().Initialize(projectPath);
|
||||
m_context->GetProjectManager().Initialize(projectPath);
|
||||
}
|
||||
|
||||
void ProjectPanel::Render() {
|
||||
@@ -26,7 +27,7 @@ void ProjectPanel::Render() {
|
||||
|
||||
ImGui::Begin(m_name.c_str(), nullptr, ImGuiWindowFlags_None);
|
||||
|
||||
auto& manager = ProjectManager::Get();
|
||||
auto& manager = m_context->GetProjectManager();
|
||||
|
||||
bool canGoBack = manager.CanNavigateBack();
|
||||
ImGui::BeginDisabled(!canGoBack);
|
||||
@@ -160,7 +161,7 @@ void ProjectPanel::Render() {
|
||||
}
|
||||
|
||||
void ProjectPanel::RenderAssetItem(const AssetItemPtr& item, int index) {
|
||||
auto& manager = ProjectManager::Get();
|
||||
auto& manager = m_context->GetProjectManager();
|
||||
bool isSelected = (manager.GetSelectedIndex() == index);
|
||||
|
||||
ImGui::PushID(index);
|
||||
@@ -287,7 +288,7 @@ void ProjectPanel::RenderAssetItem(const AssetItemPtr& item, int index) {
|
||||
}
|
||||
|
||||
void ProjectPanel::CreateNewFolder(const std::string& name) {
|
||||
auto& manager = ProjectManager::Get();
|
||||
auto& manager = m_context->GetProjectManager();
|
||||
manager.CreateFolder(name);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user