summaryrefslogtreecommitdiff
path: root/Library/PackageCache/com.unity.collab-proxy@1.2.16/Editor/Collab/Views/CollabHistoryRevisionLine.cs
blob: 2b8fe65209b2ff1cb49f63cc982c5dc144e9bed4 (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
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
86
87
88
89
90
91
92
93
94
using System;
using UnityEditor;
using UnityEditor.Collaboration;
using UnityEngine;

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

namespace UnityEditor.Collaboration
{
    internal class CollabHistoryRevisionLine : VisualElement
    {
        public CollabHistoryRevisionLine(int number)
        {
            AddNumber(number);
            AddLine("topLine");
            AddLine("bottomLine");
            AddIndicator();
        }

        public CollabHistoryRevisionLine(DateTime date, bool isFullDateObtained)
        {
            AddLine(isFullDateObtained ? "obtainedDateLine" : "absentDateLine");
            AddHeader(GetFormattedHeader(date));
            AddToClassList("revisionLineHeader");
        }

        private void AddHeader(string content)
        {
            Add(new Label
            {
                text = content
            });
        }

        private void AddIndicator()
        {
            Add(new VisualElement
            {
                name = "RevisionIndicator"
            });
        }

        private void AddLine(string className = null)
        {
            var line = new VisualElement
            {
                name = "RevisionLine"
            };
            if (!String.IsNullOrEmpty(className))
            {
                line.AddToClassList(className);
            }
            Add(line);
        }

        private void AddNumber(int number)
        {
            Add(new Label
            {
                text = number.ToString(),
                name = "RevisionIndex"
            });
        }

        private string GetFormattedHeader(DateTime date)
        {
            string result = "Commits on " + date.ToString("MMM d");
            switch (date.Day)
            {
                case 1:
                case 21:
                case 31:
                    result += "st";
                    break;
                case 2:
                case 22:
                    result += "nd";
                    break;
                case 3:
                case 23:
                    result += "rd";
                    break;
                default:
                    result += "th";
                    break;
            }
            return result;
        }
    }
}