CollabHistoryDropDownItem.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using UnityEngine;
  5. #if UNITY_2019_1_OR_NEWER
  6. using UnityEngine.UIElements;
  7. #else
  8. using UnityEngine.Experimental.UIElements;
  9. #endif
  10. namespace UnityEditor.Collaboration
  11. {
  12. internal class CollabHistoryDropDownItem : VisualElement
  13. {
  14. public CollabHistoryDropDownItem(string path, string action)
  15. {
  16. var fileName = Path.GetFileName(path);
  17. var isFolder = Path.GetFileNameWithoutExtension(path).Equals(fileName);
  18. var fileIcon = GetIconElement(action, fileName, isFolder);
  19. var metaContainer = new VisualElement();
  20. var fileNameLabel = new Label
  21. {
  22. name = "FileName",
  23. text = fileName
  24. };
  25. var filePathLabel = new Label
  26. {
  27. name = "FilePath",
  28. text = path
  29. };
  30. metaContainer.Add(fileNameLabel);
  31. metaContainer.Add(filePathLabel);
  32. Add(fileIcon);
  33. Add(metaContainer);
  34. }
  35. private Image GetIconElement(string action, string fileName, bool isFolder)
  36. {
  37. var prefix = isFolder ? "Folder" : "File";
  38. var actionName = action.First().ToString().ToUpper() + action.Substring(1);
  39. // Use the same icon for renamed and moved files
  40. actionName = actionName.Equals("Renamed") ? "Moved" : actionName;
  41. var iconElement = new Image
  42. {
  43. name = "FileIcon",
  44. image = EditorGUIUtility.LoadIcon("Icons/Collab." + prefix + actionName + ".png")
  45. };
  46. return iconElement;
  47. }
  48. }
  49. }