84 lines
2.5 KiB
C
84 lines
2.5 KiB
C
|
|
#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
|