Files
XCEngine/new_editor/app/Project/EditorProjectRuntime.h

113 lines
3.9 KiB
C++

#pragma once
#include "Features/Project/ProjectBrowserModel.h"
#include <XCEditor/App/EditorSession.h>
#include <XCEngine/UI/Types.h>
#include <filesystem>
#include <optional>
#include <string>
#include <string_view>
namespace XCEngine::UI::Editor::App {
class EditorProjectRuntime {
public:
struct EditCommandTarget {
std::string itemId = {};
std::filesystem::path absolutePath = {};
std::string displayName = {};
ProjectBrowserModel::ItemKind itemKind =
ProjectBrowserModel::ItemKind::File;
bool directory = false;
bool assetsRoot = false;
};
struct AssetCommandTarget {
const ProjectBrowserModel::FolderEntry* currentFolder = nullptr;
const ProjectBrowserModel::FolderEntry* containerFolder = nullptr;
const ProjectBrowserModel::FolderEntry* subjectFolder = nullptr;
const ProjectBrowserModel::AssetEntry* subjectAsset = nullptr;
std::string subjectItemId = {};
std::filesystem::path subjectPath = {};
std::string subjectDisplayName = {};
std::string subjectRelativePath = {};
bool showInExplorerSelectTarget = false;
};
bool Initialize(const std::filesystem::path& repoRoot);
void SetFolderIcon(const ::XCEngine::UI::UITextureHandle& icon);
void Refresh();
const ProjectBrowserModel& GetBrowserModel() const;
ProjectBrowserModel& GetBrowserModel();
bool HasSelection() const;
const EditorSelectionState& GetSelection() const;
std::uint64_t GetSelectionStamp() const;
bool SetSelection(std::string_view itemId);
void ClearSelection();
bool NavigateToFolder(std::string_view itemId);
bool OpenItem(std::string_view itemId);
std::optional<std::filesystem::path> ConsumePendingSceneOpenPath();
const ProjectBrowserModel::FolderEntry* FindFolderEntry(
std::string_view itemId) const;
const ProjectBrowserModel::AssetEntry* FindAssetEntry(
std::string_view itemId) const;
AssetCommandTarget ResolveAssetCommandTarget(
std::string_view explicitItemId = {},
bool forceCurrentFolder = false) const;
std::optional<EditCommandTarget> ResolveEditCommandTarget(
std::string_view explicitItemId = {},
bool forceCurrentFolder = false) const;
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);
private:
void ApplySelection(
const ProjectBrowserModel::AssetEntry& asset,
bool preserveStamp);
void RevalidateSelection();
bool SelectionTargetsItem(std::string_view itemId) const;
ProjectBrowserModel m_browserModel = {};
EditorSelectionState m_selection = {};
std::optional<std::filesystem::path> m_pendingSceneOpenPath = std::nullopt;
};
} // namespace XCEngine::UI::Editor::App