summaryrefslogtreecommitdiff
path: root/Library/PackageCache/com.unity.collab-proxy@1.2.16/Editor/Collab/Views/CollabHistoryDropDownItem.cs
blob: 3ad43f23ae92a55f4f4e9cba477d58f78212853f (plain) (blame)
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
using System;
using System.IO;
using System.Linq;
using UnityEngine;

#if UNITY_2019_1_OR_NEWER
using UnityEngine.UIElements;
#else
using UnityEngine.Experimental.UIElements;
#endif


namespace UnityEditor.Collaboration
{
    internal class CollabHistoryDropDownItem : VisualElement
    {
        public CollabHistoryDropDownItem(string path, string action)
        {
            var fileName = Path.GetFileName(path);
            var isFolder = Path.GetFileNameWithoutExtension(path).Equals(fileName);
            var fileIcon = GetIconElement(action, fileName, isFolder);
            var metaContainer = new VisualElement();
            var fileNameLabel = new Label
            {
                name = "FileName",
                text = fileName
            };
            var filePathLabel = new Label
            {
                name = "FilePath",
                text = path
            };
            metaContainer.Add(fileNameLabel);
            metaContainer.Add(filePathLabel);
            Add(fileIcon);
            Add(metaContainer);
        }

        private Image GetIconElement(string action, string fileName, bool isFolder)
        {
            var prefix = isFolder ? "Folder" : "File";
            var actionName = action.First().ToString().ToUpper() + action.Substring(1);
            // Use the same icon for renamed and moved files
            actionName = actionName.Equals("Renamed") ? "Moved" : actionName;
            var iconElement = new Image
            {
                name = "FileIcon",
                image = EditorGUIUtility.LoadIcon("Icons/Collab." + prefix + actionName + ".png")
            };
            return iconElement;
        }
    }
}