ProgressControlsForViews.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using UnityEditor;
  2. using PlasticGui;
  3. namespace Unity.PlasticSCM.Editor.UI.Progress
  4. {
  5. internal class ProgressControlsForViews : IProgressControls
  6. {
  7. internal class Data
  8. {
  9. internal bool IsOperationRunning;
  10. internal float ProgressPercent;
  11. internal string ProgressMessage;
  12. internal MessageType NotificationType;
  13. internal string NotificationMessage;
  14. internal void CopyInto(Data other)
  15. {
  16. other.IsOperationRunning = IsOperationRunning;
  17. other.ProgressPercent = ProgressPercent;
  18. other.ProgressMessage = ProgressMessage;
  19. other.NotificationType = NotificationType;
  20. other.NotificationMessage = NotificationMessage;
  21. }
  22. }
  23. internal Data ProgressData { get { return mData; } }
  24. internal bool IsOperationRunning()
  25. {
  26. return mData.IsOperationRunning;
  27. }
  28. internal bool HasNotification()
  29. {
  30. return !string.IsNullOrEmpty(mData.NotificationMessage);
  31. }
  32. internal void UpdateDeterminateProgress(EditorWindow parentWindow)
  33. {
  34. if (IsOperationRunning() || mRequestedRepaint)
  35. {
  36. parentWindow.Repaint();
  37. mRequestedRepaint = false;
  38. }
  39. }
  40. internal void UpdateProgress(EditorWindow parentWindow)
  41. {
  42. if (IsOperationRunning() || mRequestedRepaint)
  43. {
  44. if (IsOperationRunning())
  45. UpdateIndeterminateProgress();
  46. parentWindow.Repaint();
  47. mRequestedRepaint = false;
  48. }
  49. }
  50. void IProgressControls.HideProgress()
  51. {
  52. HideNotification();
  53. mData.IsOperationRunning = false;
  54. mData.ProgressMessage = string.Empty;
  55. mRequestedRepaint = true;
  56. }
  57. void IProgressControls.ShowProgress(string message)
  58. {
  59. HideNotification();
  60. mData.IsOperationRunning = true;
  61. mData.ProgressMessage = message;
  62. mRequestedRepaint = true;
  63. }
  64. void IProgressControls.ShowError(string message)
  65. {
  66. mData.NotificationMessage = message;
  67. mData.NotificationType = MessageType.Error;
  68. mRequestedRepaint = true;
  69. }
  70. void IProgressControls.ShowNotification(string message)
  71. {
  72. mData.NotificationMessage = message;
  73. mData.NotificationType = MessageType.Info;
  74. mRequestedRepaint = true;
  75. }
  76. void IProgressControls.ShowSuccess(string message)
  77. {
  78. mData.NotificationMessage = message;
  79. mData.NotificationType = MessageType.Info;
  80. mRequestedRepaint = true;
  81. }
  82. void IProgressControls.ShowWarning(string message)
  83. {
  84. mData.NotificationMessage = message;
  85. mData.NotificationType = MessageType.Warning;
  86. mRequestedRepaint = true;
  87. }
  88. void HideNotification()
  89. {
  90. mData.NotificationMessage = string.Empty;
  91. mData.NotificationType = MessageType.None;
  92. mRequestedRepaint = true;
  93. }
  94. void UpdateIndeterminateProgress()
  95. {
  96. // NOTE(rafa): there is no support for indeterminate progress bar
  97. // i use this neverending progress bar as workaround
  98. mData.ProgressPercent += .003f;
  99. if (mData.ProgressPercent > 1f)
  100. mData.ProgressPercent = .1f;
  101. }
  102. Data mData = new Data();
  103. bool mRequestedRepaint;
  104. }
  105. }