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

@@ -0,0 +1,83 @@
#pragma once
#include "EditorActions.h"
#include "Commands/ProjectCommands.h"
#include "Core/IEditorContext.h"
#include "Core/IProjectManager.h"
#include "UI/PopupState.h"
namespace XCEngine {
namespace Editor {
namespace Actions {
inline int FindProjectItemIndex(IProjectManager& projectManager, const AssetItemPtr& item) {
if (!item) {
return -1;
}
const auto& items = projectManager.GetCurrentItems();
for (size_t i = 0; i < items.size(); ++i) {
if (items[i] == item) {
return static_cast<int>(i);
}
if (items[i] && items[i]->fullPath == item->fullPath) {
return static_cast<int>(i);
}
}
return -1;
}
inline void DrawProjectAssetContextActions(IEditorContext& context, const AssetItemPtr& item) {
auto& projectManager = context.GetProjectManager();
const int itemIndex = FindProjectItemIndex(projectManager, item);
DrawMenuAction(MakeOpenAssetAction(Commands::CanOpenAsset(item)), [&]() {
Commands::OpenAsset(context, item);
});
DrawMenuSeparator();
DrawMenuAction(MakeDeleteAssetAction(itemIndex >= 0), [&]() {
Commands::DeleteAsset(projectManager, itemIndex);
});
}
template <size_t BufferCapacity>
inline void DrawProjectEmptyContextActions(UI::TextInputPopupState<BufferCapacity>& createFolderDialog) {
DrawMenuAction(MakeCreateFolderAction(), [&]() {
createFolderDialog.RequestOpen("NewFolder");
});
}
template <size_t BufferCapacity>
inline void DrawProjectCreateFolderDialog(IEditorContext& context, UI::TextInputPopupState<BufferCapacity>& createFolderDialog) {
createFolderDialog.ConsumeOpenRequest("Create Folder");
if (!UI::BeginModalPopup("Create Folder")) {
return;
}
ImGui::InputText("Name", createFolderDialog.Buffer(), createFolderDialog.BufferSize());
ImGui::Separator();
switch (UI::DrawDialogActionRow("Create", "Cancel", !createFolderDialog.Empty())) {
case UI::DialogActionResult::Primary:
if (Commands::CreateFolder(context.GetProjectManager(), createFolderDialog.Buffer())) {
createFolderDialog.Clear();
ImGui::CloseCurrentPopup();
}
break;
case UI::DialogActionResult::Secondary:
createFolderDialog.Clear();
ImGui::CloseCurrentPopup();
break;
case UI::DialogActionResult::None:
break;
}
UI::EndPopup();
}
} // namespace Actions
} // namespace Editor
} // namespace XCEngine