Refactor editor shell host layers

This commit is contained in:
2026-03-26 23:52:05 +08:00
parent f87bc53875
commit 31675e00c8
18 changed files with 738 additions and 518 deletions

View File

@@ -1,5 +1,5 @@
#include "Actions/ActionRouting.h"
#include "Actions/EditorActions.h"
#include "Actions/ProjectActionRouter.h"
#include "Commands/ProjectCommands.h"
#include "ProjectPanel.h"
#include "Core/IEditorContext.h"
@@ -7,12 +7,13 @@
#include "Core/AssetItem.h"
#include "UI/UI.h"
#include <imgui.h>
#include <imgui_internal.h>
namespace XCEngine {
namespace Editor {
const char* DRAG_DROP_TYPE = "ASSET_ITEM";
namespace {
constexpr const char* kAssetDragDropType = "ASSET_ITEM";
}
ProjectPanel::ProjectPanel() : Panel("Project") {
}
@@ -23,7 +24,7 @@ void ProjectPanel::Initialize(const std::string& projectPath) {
void ProjectPanel::Render() {
const ImGuiPayload* payload = ImGui::GetDragDropPayload();
if (payload && payload->IsDataType(DRAG_DROP_TYPE)) {
if (payload && payload->IsDataType(kAssetDragDropType)) {
m_draggingPath = (const char*)payload->Data;
} else if (!ImGui::IsMouseDown(0)) {
m_draggingPath.clear();
@@ -101,52 +102,28 @@ void ProjectPanel::Render() {
if (ImGui::IsWindowHovered() && ImGui::IsMouseClicked(0) && !ImGui::IsAnyItemHovered()) {
manager.SetSelectedIndex(-1);
}
m_itemContextMenu.ConsumeOpenRequest("ItemContextMenu");
if (UI::BeginPopup("ItemContextMenu")) {
if (m_contextMenuIndex >= 0 && m_contextMenuIndex < (int)items.size()) {
auto& item = items[m_contextMenuIndex];
const bool canOpen = item->isFolder || item->type == "Scene";
Actions::DrawMenuAction(Actions::MakeOpenAssetAction(canOpen), [&]() {
Commands::OpenAsset(*m_context, item);
});
Actions::DrawMenuSeparator();
Actions::DrawMenuAction(Actions::MakeDeleteAssetAction(), [&]() {
Commands::DeleteAsset(manager, m_contextMenuIndex);
m_contextMenuIndex = -1;
});
if (m_itemContextMenu.HasTarget()) {
Actions::DrawProjectAssetContextActions(*m_context, m_itemContextMenu.TargetValue());
}
UI::EndPopup();
}
if (!ImGui::IsPopupOpen("ItemContextMenu") && !m_itemContextMenu.HasPendingOpenRequest()) {
m_itemContextMenu.Clear();
}
if (ImGui::IsWindowHovered() && ImGui::IsMouseClicked(1) && !ImGui::IsAnyItemHovered()) {
ImGui::OpenPopup("EmptyContextMenu");
}
if (UI::BeginPopup("EmptyContextMenu")) {
Actions::DrawMenuAction(Actions::MakeCreateFolderAction(), [&]() {
m_createFolderDialog.RequestOpen("NewFolder");
});
UI::EndPopup();
}
m_createFolderDialog.ConsumeOpenRequest("Create Folder");
if (UI::BeginModalPopup("Create Folder")) {
ImGui::InputText("Name", m_createFolderDialog.Buffer(), m_createFolderDialog.BufferSize());
ImGui::Separator();
const Actions::ActionBinding createAction = Actions::MakeConfirmCreateAction(!m_createFolderDialog.Empty());
const Actions::ActionBinding cancelAction = Actions::MakeCancelAction();
if (Actions::DrawButtonAction(createAction, UI::DialogActionButtonSize())) {
if (Commands::CreateFolder(manager, m_createFolderDialog.Buffer())) {
ImGui::CloseCurrentPopup();
}
}
ImGui::SameLine();
if (Actions::DrawButtonAction(cancelAction, UI::DialogActionButtonSize())) {
ImGui::CloseCurrentPopup();
}
Actions::DrawProjectEmptyContextActions(m_createFolderDialog);
UI::EndPopup();
}
Actions::DrawProjectCreateFolderDialog(*m_context, m_createFolderDialog);
}
void ProjectPanel::RenderAssetItem(const AssetItemPtr& item, int index) {
@@ -169,16 +146,14 @@ void ProjectPanel::RenderAssetItem(const AssetItemPtr& item, int index) {
manager.SetSelectedIndex(index);
}
bool openContextMenu = false;
if (tile.contextRequested) {
manager.SetSelectedIndex(index);
m_contextMenuIndex = index;
openContextMenu = true;
m_itemContextMenu.RequestOpen(item);
}
if (item->isFolder) {
if (ImGui::BeginDragDropTarget()) {
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload(DRAG_DROP_TYPE)) {
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload(kAssetDragDropType)) {
const char* draggedPath = (const char*)payload->Data;
Commands::MoveAssetToFolder(manager, draggedPath, item);
}
@@ -188,7 +163,7 @@ void ProjectPanel::RenderAssetItem(const AssetItemPtr& item, int index) {
if (!item->fullPath.empty()) {
if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_None)) {
ImGui::SetDragDropPayload(DRAG_DROP_TYPE, item->fullPath.c_str(), item->fullPath.length() + 1);
ImGui::SetDragDropPayload(kAssetDragDropType, item->fullPath.c_str(), item->fullPath.length() + 1);
ImVec2 previewMin = ImGui::GetMousePos();
const ImVec2 previewSize = UI::AssetDragPreviewSize();
@@ -204,10 +179,6 @@ void ProjectPanel::RenderAssetItem(const AssetItemPtr& item, int index) {
}
ImGui::PopID();
if (openContextMenu) {
ImGui::OpenPopup("ItemContextMenu");
}
}
}