From 3f493520556ad4d2bc4168d3197c43154b530081 Mon Sep 17 00:00:00 2001 From: ducphamhong Date: Wed, 10 Mar 2021 12:56:40 +0700 Subject: [PATCH] #119 Implement shell command on context menu --- .../Source/AssetManager/CAssetManager.cpp | 5 +++++ .../Source/AssetManager/CAssetManager.h | 4 ++++ .../Editor/Space/Assets/CContextMenuFS.cpp | 18 +++++++++++++++-- .../Editor/Space/Assets/CContextMenuFS.h | 6 ++++-- .../Editor/Space/Assets/CListFSController.cpp | 20 +++++++++++++++++++ .../Editor/Space/Assets/CListFSController.h | 4 ++++ 6 files changed, 53 insertions(+), 4 deletions(-) diff --git a/Projects/Editor/Source/AssetManager/CAssetManager.cpp b/Projects/Editor/Source/AssetManager/CAssetManager.cpp index ca95d5c7a..c21b4cfa6 100644 --- a/Projects/Editor/Source/AssetManager/CAssetManager.cpp +++ b/Projects/Editor/Source/AssetManager/CAssetManager.cpp @@ -295,5 +295,10 @@ namespace Skylicht sortPath.replace(sortPath.find(assetPath.c_str()), assetPath.size(), ""); return sortPath; } + + bool CAssetManager::deleteAsset(const char* path) + { + return true; + } } } \ No newline at end of file diff --git a/Projects/Editor/Source/AssetManager/CAssetManager.h b/Projects/Editor/Source/AssetManager/CAssetManager.h index 738a3eae5..a81ca683d 100644 --- a/Projects/Editor/Source/AssetManager/CAssetManager.h +++ b/Projects/Editor/Source/AssetManager/CAssetManager.h @@ -131,6 +131,10 @@ namespace Skylicht std::string getShortPath(const char* folder); + public: + + bool deleteAsset(const char* path); + protected: void discovery(const std::string& bundle, const std::string& folder); diff --git a/Projects/Editor/Source/Editor/Space/Assets/CContextMenuFS.cpp b/Projects/Editor/Source/Editor/Space/Assets/CContextMenuFS.cpp index aad1708f9..b5f418117 100644 --- a/Projects/Editor/Source/Editor/Space/Assets/CContextMenuFS.cpp +++ b/Projects/Editor/Source/Editor/Space/Assets/CContextMenuFS.cpp @@ -54,6 +54,8 @@ namespace Skylicht m_treeFS->OnItemContextMenu = BIND_LISTENER(&CContextMenuFS::OnTreeContextMenu, this); m_listFS->OnItemContextMenu = BIND_LISTENER(&CContextMenuFS::OnListContextMenu, this); + + m_assetManager = CAssetManager::getInstance(); } CContextMenuFS::~CContextMenuFS() @@ -102,11 +104,23 @@ namespace Skylicht } else if (label == L"Show in Explorer") { - +#if defined(WIN32) + char path[512] = { 0 }; + CStringImp::replaceText(path, m_selectedPath.c_str(), "/", "\\"); + ShellExecuteA(NULL, "open", path, NULL, NULL, SW_SHOWDEFAULT); +#elif defined(__APPLE__) + // QProcess::execute("/usr/bin/osascript", { "-e", "tell application \"Finder\" to reveal POSIX file \"" + path + "\"" }); + // QProcess::execute("/usr/bin/osascript", { "-e", "tell application \"Finder\" to activate" }); + + char cmd[1024] = { 0 }; + sprintf(cmd, "osascript -e 'tell app \"Finder\" to open POSIX file \"%s\"'", m_selectedPath.c_str()); + system(cmd); +#endif } else if (label == L"Delete") { - + if (m_assetManager->deleteAsset(m_selectedPath.c_str())) + m_listFSController->refresh(); } else if (label == L"Rename") { diff --git a/Projects/Editor/Source/Editor/Space/Assets/CContextMenuFS.h b/Projects/Editor/Source/Editor/Space/Assets/CContextMenuFS.h index 3770a5f37..c41172ab7 100644 --- a/Projects/Editor/Source/Editor/Space/Assets/CContextMenuFS.h +++ b/Projects/Editor/Source/Editor/Space/Assets/CContextMenuFS.h @@ -36,9 +36,9 @@ namespace Skylicht { protected: GUI::CTreeControl* m_treeFS; - + GUI::CListBox* m_listFS; - + CListFSController* m_listFSController; GUI::CMenu* m_contextMenu; @@ -49,6 +49,8 @@ namespace Skylicht GUI::CBase* m_selected; + CAssetManager* m_assetManager; + std::string m_selectedPath; public: diff --git a/Projects/Editor/Source/Editor/Space/Assets/CListFSController.cpp b/Projects/Editor/Source/Editor/Space/Assets/CListFSController.cpp index 7a4da96b5..51975f363 100644 --- a/Projects/Editor/Source/Editor/Space/Assets/CListFSController.cpp +++ b/Projects/Editor/Source/Editor/Space/Assets/CListFSController.cpp @@ -25,6 +25,7 @@ This file is part of the "Skylicht Engine". #include "pch.h" #include "CListFSController.h" #include "Utils/CPath.h" +#include "Utils/CStringImp.h" namespace Skylicht { @@ -116,6 +117,8 @@ namespace Skylicht } m_listFS->setScrollVertical(0.0f); + + m_currentFolder = currentFolder; } void CListFSController::OnFileOpen(GUI::CBase* node) @@ -139,8 +142,25 @@ namespace Skylicht else { // shell open the file +#if WIN32 + char path[512] = { 0 }; + CStringImp::replaceText(path, fullPath.c_str(), "/", "\\"); + ShellExecuteA(NULL, "open", path, NULL, NULL, SW_SHOWDEFAULT); +#endif } } } + + void CListFSController::refresh() + { + std::vector files; + + if (m_currentFolder.empty()) + m_assetManager->getRoot(files); + else + m_assetManager->getFolder(m_currentFolder.c_str(), files); + + add(m_currentFolder, files); + } } } \ No newline at end of file diff --git a/Projects/Editor/Source/Editor/Space/Assets/CListFSController.h b/Projects/Editor/Source/Editor/Space/Assets/CListFSController.h index 4b0d85caa..9cfe2af6d 100644 --- a/Projects/Editor/Source/Editor/Space/Assets/CListFSController.h +++ b/Projects/Editor/Source/Editor/Space/Assets/CListFSController.h @@ -43,6 +43,8 @@ namespace Skylicht CAssetManager* m_assetManager; + std::string m_currentFolder; + public: CListFSController(GUI::CListBox* list, CTreeFSController* treeController); @@ -56,6 +58,8 @@ namespace Skylicht void OnFileOpen(GUI::CBase* node); + void refresh(); + protected: void add(const std::string& currentFolder, std::vector& files);