From bbd91755ea8c8177b34ab44434cf85a6224abb96 Mon Sep 17 00:00:00 2001 From: Benjamin Jillich <43751992+amzn-jillich@users.noreply.github.com> Date: Thu, 27 Jan 2022 13:23:39 +0100 Subject: [PATCH] EMotion FX: Recent files menu in Animation Editor also shows files from external gems (#7160) Recent files were only shown from sub-folders of the project and assets from gems (inside project and external) were not visible. Signed-off-by: Benjamin Jillich --- .../Code/MysticQt/Source/RecentFiles.cpp | 74 +++++++++---------- 1 file changed, 35 insertions(+), 39 deletions(-) diff --git a/Gems/EMotionFX/Code/MysticQt/Source/RecentFiles.cpp b/Gems/EMotionFX/Code/MysticQt/Source/RecentFiles.cpp index b5dfd2ead1..26f0bb8e57 100644 --- a/Gems/EMotionFX/Code/MysticQt/Source/RecentFiles.cpp +++ b/Gems/EMotionFX/Code/MysticQt/Source/RecentFiles.cpp @@ -11,13 +11,13 @@ #include #include #include +#include #include #include #include #include #include - namespace MysticQt { class ToolTipMenu @@ -128,56 +128,52 @@ namespace MysticQt { m_recentFilesMenu->clear(); - AZStd::string sourceFolder = EMotionFX::GetEMotionFX().GetAssetSourceFolder(); AZStd::string cacheFolder = EMotionFX::GetEMotionFX().GetAssetCacheFolder(); - AzFramework::StringFunc::Path::Normalize(sourceFolder); AzFramework::StringFunc::Path::Normalize(cacheFolder); - AzFramework::StringFunc::Strip(sourceFolder, AZ_CORRECT_FILESYSTEM_SEPARATOR, true, false, true); AzFramework::StringFunc::Strip(cacheFolder, AZ_CORRECT_FILESYSTEM_SEPARATOR, true, false, true); int recentFilesAdded = 0; - QString menuItemText; - AZStd::string folder; const int recentFileCount = m_recentFiles.size(); for (int i = 0; i < recentFileCount; ++i) { - const QFileInfo fileInfo(m_recentFiles[i]); - folder = fileInfo.absolutePath().toUtf8().data(); - AzFramework::StringFunc::Path::Normalize(folder); - AzFramework::StringFunc::Strip(folder, AZ_CORRECT_FILESYSTEM_SEPARATOR, true, false, true); - - auto CharacterCompareIgnoreCase = [](const char lhs, const char rhs) + const QString recentFilePath = m_recentFiles[i]; + if (!QFile::exists(recentFilePath)) { - return tolower(lhs) == tolower(rhs); - }; - auto PathCompareIgnoreCase = [&CharacterCompareIgnoreCase](const AZ::IO::PathView& lhs, const AZ::IO::PathView& rhs) - { - AZStd::string_view lhsStringView = lhs.Native(); - AZStd::string_view rhsStringView = rhs.Native(); - return AZStd::equal(lhsStringView.begin(), lhsStringView.end(), rhsStringView.begin(), rhsStringView.end(), - CharacterCompareIgnoreCase); - }; + continue; + } - AZ::IO::PathView folderPathView(folder); - AZ::IO::PathView assetSourceView(sourceFolder); - AZ::IO::PathView assetCacheView(cacheFolder); - // The source folder is case-sensitive, so use the normal path compare - auto [folderPathIter, assetSourceIter] = AZStd::mismatch(folderPathView.begin(), folderPathView.end(), - assetSourceView.begin(), assetSourceView.end()); - // The Cache folder is always lowercase, so compare while ignoring case - auto [folderPathIter2, assetCacheIter] = AZStd::mismatch(folderPathView.begin(), folderPathView.end(), - assetCacheView.begin(), assetCacheView.end(), PathCompareIgnoreCase); - // Both of the above mismatch checks if folder path is a sub-directory of the asset source path or - // the asset cache path. If either asset source path or asset cache path PathView reaches the end - // iterator, then the folder path is either equal to one of them or a sub-directory of one of them + AZStd::string normalizedPath = recentFilePath.toUtf8().data(); + AzFramework::StringFunc::Path::Normalize(normalizedPath); - // Skip files that are not part of the current game directory. - if (sourceFolder == folder - || assetSourceIter == assetSourceView.end() - || cacheFolder == folder - || assetCacheIter == assetCacheView.end()) + // Check if the file can be found in any of the scan folders (Project asset paths, gem asset paths, etc.) + bool foundInScanFolders = false; { - menuItemText = QString("&%1 %2").arg(i + 1).arg(fileInfo.fileName()); + bool getScanFoldersSuccess = false; + AZStd::vector scanFolders; + AzToolsFramework::AssetSystemRequestBus::BroadcastResult(getScanFoldersSuccess, &AzToolsFramework::AssetSystemRequestBus::Events::GetScanFolders, scanFolders); + if (getScanFoldersSuccess) + { + for (AZStd::string& scanFolder : scanFolders) + { + AzFramework::StringFunc::Path::Normalize(scanFolder); + if (AzFramework::StringFunc::Contains(normalizedPath, scanFolder)) + { + foundInScanFolders = true; + } + } + } + + // Is the file part of the asset cache folder? + if (AzFramework::StringFunc::Contains(normalizedPath, cacheFolder)) + { + foundInScanFolders = true; + } + } + + if (foundInScanFolders) + { + const QFileInfo fileInfo(m_recentFiles[i]); + const QString menuItemText = QString("&%1 %2").arg(i + 1).arg(fileInfo.fileName()); QAction* action = new QAction(m_recentFilesMenu); action->setText(menuItemText);