feat: 添加Project面板拖拽移动功能

This commit is contained in:
2026-03-12 19:48:51 +08:00
parent 1fc84b9538
commit 909f430c7a
5 changed files with 55 additions and 0 deletions

View File

@@ -85,6 +85,7 @@ void ProjectManager::Initialize(const std::string& projectPath) {
m_rootFolder = ScanDirectory(assetsPath.wstring());
m_rootFolder->name = "Assets";
m_rootFolder->fullPath = WstringToUtf8(assetsPath.wstring());
m_path.clear();
m_path.push_back(m_rootFolder);
@@ -143,6 +144,27 @@ void ProjectManager::DeleteItem(int index) {
}
}
bool ProjectManager::MoveItem(const std::string& sourceFullPath, const std::string& destFolderFullPath) {
try {
fs::path sourcePath = Utf8ToWstring(sourceFullPath);
fs::path destPath = fs::path(Utf8ToWstring(destFolderFullPath)) / sourcePath.filename();
if (!fs::exists(sourcePath)) {
return false;
}
if (fs::exists(destPath)) {
return false;
}
fs::rename(sourcePath, destPath);
RefreshCurrentFolder();
return true;
} catch (...) {
return false;
}
}
AssetItemPtr ProjectManager::ScanDirectory(const std::wstring& path) {
auto folder = std::make_shared<AssetItem>();
folder->name = WstringToUtf8(fs::path(path).filename().wstring());
@@ -175,6 +197,7 @@ AssetItemPtr ProjectManager::CreateAssetItem(const std::wstring& path, const std
auto item = std::make_shared<AssetItem>();
item->name = WstringToUtf8(nameW);
item->isFolder = isFolder;
item->fullPath = WstringToUtf8(path);
if (isFolder) {
item->type = "Folder";