CollabHistoryRevisionLine.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using UnityEditor;
  3. using UnityEditor.Collaboration;
  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 CollabHistoryRevisionLine : VisualElement
  13. {
  14. public CollabHistoryRevisionLine(int number)
  15. {
  16. AddNumber(number);
  17. AddLine("topLine");
  18. AddLine("bottomLine");
  19. AddIndicator();
  20. }
  21. public CollabHistoryRevisionLine(DateTime date, bool isFullDateObtained)
  22. {
  23. AddLine(isFullDateObtained ? "obtainedDateLine" : "absentDateLine");
  24. AddHeader(GetFormattedHeader(date));
  25. AddToClassList("revisionLineHeader");
  26. }
  27. private void AddHeader(string content)
  28. {
  29. Add(new Label
  30. {
  31. text = content
  32. });
  33. }
  34. private void AddIndicator()
  35. {
  36. Add(new VisualElement
  37. {
  38. name = "RevisionIndicator"
  39. });
  40. }
  41. private void AddLine(string className = null)
  42. {
  43. var line = new VisualElement
  44. {
  45. name = "RevisionLine"
  46. };
  47. if (!String.IsNullOrEmpty(className))
  48. {
  49. line.AddToClassList(className);
  50. }
  51. Add(line);
  52. }
  53. private void AddNumber(int number)
  54. {
  55. Add(new Label
  56. {
  57. text = number.ToString(),
  58. name = "RevisionIndex"
  59. });
  60. }
  61. private string GetFormattedHeader(DateTime date)
  62. {
  63. string result = "Commits on " + date.ToString("MMM d");
  64. switch (date.Day)
  65. {
  66. case 1:
  67. case 21:
  68. case 31:
  69. result += "st";
  70. break;
  71. case 2:
  72. case 22:
  73. result += "nd";
  74. break;
  75. case 3:
  76. case 23:
  77. result += "rd";
  78. break;
  79. default:
  80. result += "th";
  81. break;
  82. }
  83. return result;
  84. }
  85. }
  86. }