-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFileDrop.cpp
More file actions
85 lines (70 loc) · 3.02 KB
/
FileDrop.cpp
File metadata and controls
85 lines (70 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//// FileDrop.cpp /////////////////////////////////////////////////////////////
//
// zzzzz zzz zzzzzzzzzzzzz zzzz zzzz zzzzzz zzzzz
// zzzzzzz zzz zzzz zzzz zzzz zzzz
// zzz zzz zzz zzzzzzzzzzzzz zzzz zzzz zzz
// zzz zzz zzz z zzzz zzzz zzzz zzzz
// zzz zzz zzzzzzzzzzzzz zzzz zzz zzzzzzz zzzzz
//
// Author: Jean CARDONNE
// Date: 30/06/2025
// Description: Implementation of file drop handling for asset manager
//
///////////////////////////////////////////////////////////////////////////////
#include "AssetManagerWindow.hpp"
#include "assets/AssetImporter.hpp"
#include "assets/AssetLocation.hpp"
#include "Logger.hpp"
#include <filesystem>
#include <algorithm>
namespace nexo::editor {
assets::AssetLocation AssetManagerWindow::getAssetLocation(const std::filesystem::path &path) const
{
const std::string assetName = path.stem().string();
std::filesystem::path folderPath;
const std::string targetFolder = !m_hoveredFolder.empty() ? m_hoveredFolder : m_currentFolder;
std::string locationString = assetName + "@" + targetFolder;
LOG(NEXO_DEV,
"Creating asset location: {} (current folder: '{}', hovered: '{}')",
locationString,
m_currentFolder,
m_hoveredFolder);
assets::AssetLocation location(locationString);
return location;
}
void AssetManagerWindow::handleEvent(event::EventFileDrop& event)
{
m_pendingDroppedFiles.insert(m_pendingDroppedFiles.end(),
event.files.begin(),
event.files.end());
}
void AssetManagerWindow::handleDroppedFiles()
{
if (m_pendingDroppedFiles.empty())
return;
for (const auto& filePath : m_pendingDroppedFiles)
importDroppedFile(filePath);
m_pendingDroppedFiles.clear();
m_folderStructure.clear();
buildFolderStructure();
}
void AssetManagerWindow::importDroppedFile(const std::string& filePath) const
{
const std::filesystem::path path(filePath);
if (!std::filesystem::exists(path)) {
LOG(NEXO_WARN, "Dropped file does not exist: {}", filePath);
return;
}
std::string extension = path.extension().string();
std::ranges::transform(extension, extension.begin(), ::tolower);
const assets::AssetLocation location = getAssetLocation(path);
assets::ImporterFileInput fileInput{path};
try {
assets::AssetImporter importer;
if (const auto assetRef = importer.importAssetAuto(location, fileInput); !assetRef)
LOG(NEXO_ERROR, "Failed to import asset: {}", location.getPath().data());
} catch (const std::exception& e) {
LOG(NEXO_ERROR, "Exception while importing {}: {}", location.getPath().data(), e.what());
}
}
}