关键节点
This commit is contained in:
123
editor/app/Features/Project/ProjectBrowserModel.h
Normal file
123
editor/app/Features/Project/ProjectBrowserModel.h
Normal file
@@ -0,0 +1,123 @@
|
||||
#pragma once
|
||||
|
||||
#include <XCEditor/Collections/UIEditorTreeView.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace XCEngine::UI::Editor::App {
|
||||
|
||||
class ProjectBrowserModel {
|
||||
public:
|
||||
enum class ItemKind : std::uint8_t {
|
||||
Folder = 0,
|
||||
Scene,
|
||||
Model,
|
||||
Material,
|
||||
Texture,
|
||||
Script,
|
||||
File
|
||||
};
|
||||
|
||||
struct BreadcrumbSegment {
|
||||
std::string label = {};
|
||||
std::string targetFolderId = {};
|
||||
bool current = false;
|
||||
};
|
||||
|
||||
struct FolderEntry {
|
||||
std::string itemId = {};
|
||||
std::filesystem::path absolutePath = {};
|
||||
std::string label = {};
|
||||
};
|
||||
|
||||
struct AssetEntry {
|
||||
std::string itemId = {};
|
||||
std::filesystem::path absolutePath = {};
|
||||
std::string displayName = {};
|
||||
std::string nameWithExtension = {};
|
||||
std::string extensionLower = {};
|
||||
ItemKind kind = ItemKind::File;
|
||||
bool directory = false;
|
||||
bool canOpen = false;
|
||||
bool canPreview = false;
|
||||
};
|
||||
|
||||
ProjectBrowserModel() = default;
|
||||
ProjectBrowserModel(const ProjectBrowserModel&) = default;
|
||||
ProjectBrowserModel& operator=(const ProjectBrowserModel&) = default;
|
||||
ProjectBrowserModel(ProjectBrowserModel&&) noexcept = default;
|
||||
ProjectBrowserModel& operator=(ProjectBrowserModel&&) noexcept = default;
|
||||
|
||||
void Reset();
|
||||
void Initialize(const std::filesystem::path& repoRoot);
|
||||
void Refresh();
|
||||
|
||||
bool Empty() const;
|
||||
std::filesystem::path GetProjectRootPath() const;
|
||||
const std::filesystem::path& GetAssetsRootPath() const;
|
||||
const std::vector<FolderEntry>& GetFolderEntries() const;
|
||||
const std::vector<Widgets::UIEditorTreeViewItem>& GetTreeItems() const;
|
||||
const std::vector<AssetEntry>& GetAssetEntries() const;
|
||||
const std::string& GetCurrentFolderId() const;
|
||||
bool IsAssetsRoot(std::string_view itemId) const;
|
||||
|
||||
const FolderEntry* FindFolderEntry(std::string_view itemId) const;
|
||||
const AssetEntry* FindAssetEntry(std::string_view itemId) const;
|
||||
std::optional<std::filesystem::path> ResolveItemAbsolutePath(
|
||||
std::string_view itemId) const;
|
||||
std::string BuildProjectRelativePath(std::string_view itemId) const;
|
||||
bool NavigateToFolder(std::string_view itemId);
|
||||
bool CreateFolder(
|
||||
std::string_view parentFolderId,
|
||||
std::string_view requestedName,
|
||||
std::string* createdFolderId = nullptr);
|
||||
bool CreateMaterial(
|
||||
std::string_view parentFolderId,
|
||||
std::string_view requestedName,
|
||||
std::string* createdItemId = nullptr);
|
||||
bool RenameItem(
|
||||
std::string_view itemId,
|
||||
std::string_view newName,
|
||||
std::string* renamedItemId = nullptr);
|
||||
bool DeleteItem(std::string_view itemId);
|
||||
bool CanMoveItemToFolder(
|
||||
std::string_view itemId,
|
||||
std::string_view targetFolderId) const;
|
||||
bool MoveItemToFolder(
|
||||
std::string_view itemId,
|
||||
std::string_view targetFolderId,
|
||||
std::string* movedItemId = nullptr);
|
||||
std::optional<std::string> GetParentFolderId(std::string_view itemId) const;
|
||||
bool CanReparentFolder(std::string_view sourceFolderId, std::string_view targetParentId) const;
|
||||
bool ReparentFolder(
|
||||
std::string_view sourceFolderId,
|
||||
std::string_view targetParentId,
|
||||
std::string* movedFolderId = nullptr);
|
||||
bool MoveFolderToRoot(
|
||||
std::string_view sourceFolderId,
|
||||
std::string* movedFolderId = nullptr);
|
||||
std::vector<BreadcrumbSegment> BuildBreadcrumbSegments() const;
|
||||
std::vector<std::string> CollectCurrentFolderAncestorIds() const;
|
||||
std::vector<std::string> BuildAncestorFolderIds(std::string_view itemId) const;
|
||||
|
||||
private:
|
||||
void RefreshBrowserState();
|
||||
void RefreshFolderTree();
|
||||
void RefreshAssetList();
|
||||
void EnsureValidCurrentFolder();
|
||||
|
||||
std::filesystem::path m_assetsRootPath = {};
|
||||
std::vector<FolderEntry> m_folderEntries = {};
|
||||
std::vector<Widgets::UIEditorTreeViewItem> m_treeItems = {};
|
||||
std::vector<AssetEntry> m_assetEntries = {};
|
||||
std::string m_currentFolderId = {};
|
||||
};
|
||||
|
||||
} // namespace XCEngine::UI::Editor::App
|
||||
|
||||
|
||||
Reference in New Issue
Block a user