Skip to content

Commit

Permalink
#119 Implement shell command on context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Mar 10, 2021
1 parent 3865083 commit 3f49352
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Projects/Editor/Source/AssetManager/CAssetManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
4 changes: 4 additions & 0 deletions Projects/Editor/Source/AssetManager/CAssetManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 16 additions & 2 deletions Projects/Editor/Source/Editor/Space/Assets/CContextMenuFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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")
{
Expand Down
6 changes: 4 additions & 2 deletions Projects/Editor/Source/Editor/Space/Assets/CContextMenuFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ namespace Skylicht
{
protected:
GUI::CTreeControl* m_treeFS;

GUI::CListBox* m_listFS;

CListFSController* m_listFSController;

GUI::CMenu* m_contextMenu;
Expand All @@ -49,6 +49,8 @@ namespace Skylicht

GUI::CBase* m_selected;

CAssetManager* m_assetManager;

std::string m_selectedPath;

public:
Expand Down
20 changes: 20 additions & 0 deletions Projects/Editor/Source/Editor/Space/Assets/CListFSController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -116,6 +117,8 @@ namespace Skylicht
}

m_listFS->setScrollVertical(0.0f);

m_currentFolder = currentFolder;
}

void CListFSController::OnFileOpen(GUI::CBase* node)
Expand All @@ -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<SFileInfo> files;

if (m_currentFolder.empty())
m_assetManager->getRoot(files);
else
m_assetManager->getFolder(m_currentFolder.c_str(), files);

add(m_currentFolder, files);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ namespace Skylicht

CAssetManager* m_assetManager;

std::string m_currentFolder;

public:
CListFSController(GUI::CListBox* list, CTreeFSController* treeController);

Expand All @@ -56,6 +58,8 @@ namespace Skylicht

void OnFileOpen(GUI::CBase* node);

void refresh();

protected:

void add(const std::string& currentFolder, std::vector<SFileInfo>& files);
Expand Down

0 comments on commit 3f49352

Please sign in to comment.