Extract hierarchy and project drag semantics

This commit is contained in:
2026-03-27 00:30:11 +08:00
parent 6ec5f05601
commit c97510ed5b
7 changed files with 119 additions and 72 deletions

View File

@@ -11,10 +11,6 @@
namespace XCEngine {
namespace Editor {
namespace {
constexpr const char* kAssetDragDropType = "ASSET_ITEM";
}
ProjectPanel::ProjectPanel() : Panel("Project") {
}
@@ -23,13 +19,6 @@ void ProjectPanel::Initialize(const std::string& projectPath) {
}
void ProjectPanel::Render() {
const ImGuiPayload* payload = ImGui::GetDragDropPayload();
if (payload && payload->IsDataType(kAssetDragDropType)) {
m_draggingPath = (const char*)payload->Data;
} else if (!ImGui::IsMouseDown(0)) {
m_draggingPath.clear();
}
UI::PanelWindowScope panel(m_name.c_str());
if (!panel.IsOpen()) {
return;
@@ -131,7 +120,7 @@ void ProjectPanel::RenderAssetItem(const AssetItemPtr& item, int index) {
bool isSelected = (manager.GetSelectedIndex() == index);
ImGui::PushID(index);
const bool isDraggingThisItem = !m_draggingPath.empty() && item->fullPath == m_draggingPath;
const bool isDraggingThisItem = Actions::IsProjectAssetBeingDragged(item);
const UI::AssetIconKind iconKind = item->isFolder ? UI::AssetIconKind::Folder : UI::AssetIconKind::File;
const UI::AssetTileResult tile = UI::DrawAssetTile(
@@ -151,28 +140,8 @@ void ProjectPanel::RenderAssetItem(const AssetItemPtr& item, int index) {
m_itemContextMenu.RequestOpen(item);
}
if (item->isFolder) {
if (ImGui::BeginDragDropTarget()) {
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload(kAssetDragDropType)) {
const char* draggedPath = (const char*)payload->Data;
Commands::MoveAssetToFolder(manager, draggedPath, item);
}
ImGui::EndDragDropTarget();
}
}
if (!item->fullPath.empty()) {
if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_None)) {
ImGui::SetDragDropPayload(kAssetDragDropType, item->fullPath.c_str(), item->fullPath.length() + 1);
ImVec2 previewMin = ImGui::GetMousePos();
const ImVec2 previewSize = UI::AssetDragPreviewSize();
ImVec2 previewMax = ImVec2(previewMin.x + previewSize.x, previewMin.y + previewSize.y);
UI::DrawAssetIcon(ImGui::GetForegroundDrawList(), previewMin, previewMax, iconKind);
ImGui::EndDragDropSource();
}
}
Actions::AcceptProjectAssetDrop(manager, item);
Actions::BeginProjectAssetDrag(item, iconKind);
if (tile.openRequested) {
Commands::OpenAsset(*m_context, item);