GetSelectedPaths.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using Unity.PlasticSCM.Editor.AssetMenu;
  4. using Unity.PlasticSCM.Editor.AssetsOverlays.Cache;
  5. using UnityEditor.VersionControl;
  6. namespace Unity.PlasticSCM.Editor.AssetUtils
  7. {
  8. internal static class GetSelectedPaths
  9. {
  10. internal static List<string> ForOperation(
  11. AssetList assetList,
  12. IAssetStatusCache assetStatusCache,
  13. AssetMenuOperations operation)
  14. {
  15. List<string> selectedPaths = AssetsSelection.GetSelectedPaths(assetList);
  16. List<string> result = new List<string>(selectedPaths);
  17. foreach (string path in selectedPaths)
  18. {
  19. if (MetaPath.IsMetaPath(path))
  20. continue;
  21. string metaPath = MetaPath.GetMetaPath(path);
  22. if (!File.Exists(metaPath))
  23. continue;
  24. if (result.Contains(metaPath))
  25. continue;
  26. if (!IsApplicableForOperation(
  27. metaPath, false, operation, assetStatusCache))
  28. continue;
  29. result.Add(metaPath);
  30. }
  31. return result;
  32. }
  33. static bool IsApplicableForOperation(
  34. string path,
  35. bool isDirectory,
  36. AssetMenuOperations operation,
  37. IAssetStatusCache assetStatusCache)
  38. {
  39. SelectedAssetGroupInfo info = SelectedAssetGroupInfo.BuildFromSingleFile(
  40. path, isDirectory, assetStatusCache);
  41. return AssetMenuUpdater.GetAvailableMenuOperations(info).HasFlag(operation);
  42. }
  43. }
  44. }