first commit
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.PlasticSCM.Editor.UI.StatusBar
|
||||
{
|
||||
internal class GUIContentNotification : INotificationContent
|
||||
{
|
||||
internal GUIContentNotification(string content) : this(new GUIContent(content)) { }
|
||||
|
||||
internal GUIContentNotification(GUIContent content)
|
||||
{
|
||||
mGUIContent = content;
|
||||
}
|
||||
|
||||
void INotificationContent.OnGUI()
|
||||
{
|
||||
GUILayout.Label(
|
||||
mGUIContent,
|
||||
UnityStyles.StatusBar.NotificationLabel);
|
||||
}
|
||||
|
||||
readonly GUIContent mGUIContent;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61c9e0bcd840dcb4f907e8cc9b89772a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Unity.PlasticSCM.Editor.UI.StatusBar
|
||||
{
|
||||
internal interface INotificationContent
|
||||
{
|
||||
void OnGUI();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2bd4f044bfa05a14ebd7f4e6dcd0fb74
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,189 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
using Codice.Client.Common.WebApi.Responses;
|
||||
using PlasticGui.WorkspaceWindow.NotificationBar;
|
||||
|
||||
namespace Unity.PlasticSCM.Editor.UI.StatusBar
|
||||
{
|
||||
class NotificationBar : INotificationBar
|
||||
{
|
||||
internal bool HasNotification { get; private set; }
|
||||
internal bool IsVisible { get; private set; }
|
||||
|
||||
internal NotificationBar()
|
||||
{
|
||||
mSubscriptionPanel = new ActionPanel();
|
||||
mContactPanel = new ActionPanel();
|
||||
|
||||
IsVisible = EditorPrefs.GetBool(
|
||||
UnityConstants.SHOW_NOTIFICATION_KEY_NAME,
|
||||
true);
|
||||
}
|
||||
|
||||
internal void SetVisibility(bool isVisible)
|
||||
{
|
||||
IsVisible = isVisible;
|
||||
|
||||
EditorPrefs.SetBool(
|
||||
UnityConstants.SHOW_NOTIFICATION_KEY_NAME,
|
||||
isVisible);
|
||||
}
|
||||
|
||||
internal void OnGUI()
|
||||
{
|
||||
GUILayout.BeginVertical();
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.BeginHorizontal(UnityStyles.StatusBar.NotificationPanel);
|
||||
|
||||
if (mSubscriptionPanel.HasNotification)
|
||||
mSubscriptionPanel.OnGUI();
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
if (mContactPanel.HasNotification)
|
||||
mContactPanel.OnGUI();
|
||||
|
||||
DrawCloseButton(this);
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
void INotificationBar.SetActions(
|
||||
CloudServerInfo cloudServerInfo,
|
||||
CloudOrganizationHelpActionsResponse.Action subscriptionAction,
|
||||
CloudOrganizationHelpActionsResponse.Action contactAction)
|
||||
{
|
||||
mSubscriptionPanel.SetAction(cloudServerInfo, subscriptionAction, false);
|
||||
mContactPanel.SetAction(cloudServerInfo, contactAction, true);
|
||||
|
||||
HasNotification = mSubscriptionPanel.HasNotification || mContactPanel.HasNotification;
|
||||
}
|
||||
|
||||
void INotificationBar.CleanActions()
|
||||
{
|
||||
HasNotification = false;
|
||||
|
||||
mSubscriptionPanel.SetAction(null, null, false);
|
||||
mContactPanel.SetAction(null, null, false);
|
||||
}
|
||||
|
||||
static void DrawCloseButton(NotificationBar notificationBar)
|
||||
{
|
||||
GUILayout.BeginVertical();
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
if (GUILayout.Button(
|
||||
new GUIContent(Images.GetCloseIcon()),
|
||||
UnityStyles.StatusBar.NotificationPanelCloseButton))
|
||||
{
|
||||
notificationBar.SetVisibility(false);
|
||||
}
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
class ActionPanel
|
||||
{
|
||||
internal bool HasNotification { get; private set; }
|
||||
|
||||
internal void SetAction(
|
||||
CloudServerInfo cloudServerInfo,
|
||||
CloudOrganizationHelpActionsResponse.Action action,
|
||||
bool isContactSupportAction)
|
||||
{
|
||||
if (action == null)
|
||||
{
|
||||
HasNotification = false;
|
||||
return;
|
||||
}
|
||||
|
||||
mCloudServerInfo = cloudServerInfo;
|
||||
mActionButton = action.Button;
|
||||
mIsContactSupportAction = isContactSupportAction;
|
||||
|
||||
HasNotification = true;
|
||||
mLabelText = action.Message;
|
||||
SetButton(action.Button);
|
||||
}
|
||||
|
||||
internal void OnGUI()
|
||||
{
|
||||
DrawLabel(mLabelText);
|
||||
|
||||
if (!mIsButtonVisible)
|
||||
return;
|
||||
|
||||
DrawButton(
|
||||
mCloudServerInfo, mActionButton.Url,
|
||||
mIsContactSupportAction, mButtonText);
|
||||
}
|
||||
|
||||
void SetButton(
|
||||
CloudOrganizationHelpActionsResponse.ActionButton actionButton)
|
||||
{
|
||||
if (actionButton == null)
|
||||
{
|
||||
mButtonText = string.Empty;
|
||||
mIsButtonVisible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
mButtonText = actionButton.Caption;
|
||||
mIsButtonVisible = true;
|
||||
}
|
||||
|
||||
static void DrawLabel(string text)
|
||||
{
|
||||
GUILayout.BeginVertical();
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
GUILayout.Label(
|
||||
text,
|
||||
UnityStyles.StatusBar.Label);
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
static void DrawButton(
|
||||
CloudServerInfo cloudServerInfo,
|
||||
string actionButtonUrl,
|
||||
bool isContactSupportAction,
|
||||
string buttonText)
|
||||
{
|
||||
GUILayout.BeginVertical();
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
if (GUILayout.Button(
|
||||
buttonText,
|
||||
UnityStyles.StatusBar.LinkLabel))
|
||||
{
|
||||
LaunchNotificationAction.For(
|
||||
cloudServerInfo,
|
||||
actionButtonUrl,
|
||||
isContactSupportAction);
|
||||
}
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
bool mIsButtonVisible;
|
||||
string mButtonText;
|
||||
string mLabelText;
|
||||
|
||||
bool mIsContactSupportAction;
|
||||
CloudOrganizationHelpActionsResponse.ActionButton mActionButton;
|
||||
CloudServerInfo mCloudServerInfo;
|
||||
}
|
||||
|
||||
ActionPanel mSubscriptionPanel;
|
||||
ActionPanel mContactPanel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f8fb5a27b8554a74b8c566355a3c50f9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,317 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
using PlasticGui;
|
||||
using PlasticGui.WorkspaceWindow;
|
||||
using Unity.PlasticSCM.Editor.Developer;
|
||||
|
||||
namespace Unity.PlasticSCM.Editor.UI.StatusBar
|
||||
{
|
||||
internal class StatusBar
|
||||
{
|
||||
internal interface IIncomingChangesNotification
|
||||
{
|
||||
bool HasNotification { get; }
|
||||
void OnGUI();
|
||||
}
|
||||
|
||||
internal class IncomingChangesNotificationData
|
||||
{
|
||||
internal string InfoText { get; private set; }
|
||||
internal string ActionText { get; private set; }
|
||||
internal string TooltipText { get; private set; }
|
||||
internal bool HasUpdateAction { get; private set; }
|
||||
internal PlasticNotification.Status Status { get; private set; }
|
||||
|
||||
internal void UpdateData(
|
||||
string infoText,
|
||||
string actionText,
|
||||
string tooltipText,
|
||||
bool hasUpdateAction,
|
||||
PlasticNotification.Status status)
|
||||
{
|
||||
InfoText = infoText;
|
||||
ActionText = actionText;
|
||||
TooltipText = tooltipText;
|
||||
HasUpdateAction = hasUpdateAction;
|
||||
Status = status;
|
||||
}
|
||||
|
||||
internal void Clear()
|
||||
{
|
||||
InfoText = string.Empty;
|
||||
ActionText = string.Empty;
|
||||
TooltipText = string.Empty;
|
||||
HasUpdateAction = false;
|
||||
Status = PlasticNotification.Status.None;
|
||||
}
|
||||
}
|
||||
|
||||
internal interface IShelvedChangesNotification :
|
||||
CheckShelvedChanges.IUpdateShelvedChangesNotification
|
||||
{
|
||||
bool HasNotification { get; }
|
||||
void SetWorkspaceWindow(
|
||||
WorkspaceWindow workspaceWindow);
|
||||
void SetShelvedChangesUpdater(
|
||||
IShelvedChangesUpdater shelvedChangesUpdater);
|
||||
void OnGUI();
|
||||
}
|
||||
|
||||
internal void Notify(INotificationContent content, MessageType type, Texture2D image)
|
||||
{
|
||||
mNotification = new Notification(
|
||||
content,
|
||||
type,
|
||||
image);
|
||||
mCooldownNotificationClearAction.Ping();
|
||||
}
|
||||
|
||||
internal NotificationBar NotificationBar { get; private set; }
|
||||
|
||||
internal StatusBar()
|
||||
{
|
||||
mCooldownNotificationClearAction = new CooldownWindowDelayer(
|
||||
DelayedClearNotification,
|
||||
UnityConstants.NOTIFICATION_CLEAR_INTERVAL);
|
||||
|
||||
NotificationBar = new NotificationBar();
|
||||
}
|
||||
|
||||
internal void Initialize(
|
||||
WorkspaceWindow workspaceWindow,
|
||||
IIncomingChangesNotification incomingChangesNotification,
|
||||
IShelvedChangesNotification shelvedChangesNotification)
|
||||
{
|
||||
mWorkspaceWindow = workspaceWindow;
|
||||
mIncomingChangesNotification = incomingChangesNotification;
|
||||
mShelvedChangesNotification = shelvedChangesNotification;
|
||||
|
||||
if (incomingChangesNotification is IncomingChangesNotification)
|
||||
((IncomingChangesNotification)incomingChangesNotification).SetWorkspaceWindow(workspaceWindow);
|
||||
|
||||
shelvedChangesNotification.SetWorkspaceWindow(workspaceWindow);
|
||||
}
|
||||
|
||||
void DelayedClearNotification()
|
||||
{
|
||||
mNotification = null;
|
||||
}
|
||||
|
||||
internal void OnGUI()
|
||||
{
|
||||
if (NotificationBar.HasNotification &&
|
||||
NotificationBar.IsVisible)
|
||||
{
|
||||
BeginDrawBar();
|
||||
NotificationBar.OnGUI();
|
||||
EndDrawBar();
|
||||
}
|
||||
|
||||
BeginDrawBar();
|
||||
|
||||
if (NotificationBar.HasNotification)
|
||||
{
|
||||
DrawNotificationAvailablePanel(NotificationBar);
|
||||
}
|
||||
|
||||
if (mIncomingChangesNotification.HasNotification)
|
||||
{
|
||||
mIncomingChangesNotification.OnGUI();
|
||||
}
|
||||
|
||||
if (mShelvedChangesNotification.HasNotification)
|
||||
{
|
||||
if (mIncomingChangesNotification.HasNotification)
|
||||
EditorGUILayout.Space(15);
|
||||
|
||||
mShelvedChangesNotification.OnGUI();
|
||||
}
|
||||
|
||||
if (mNotification != null)
|
||||
DrawNotification(mNotification);
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
DrawWorkspaceStatus(mWorkspaceWindow);
|
||||
|
||||
EndDrawBar();
|
||||
|
||||
Rect lastRect = GUILayoutUtility.GetLastRect();
|
||||
|
||||
if (MouseEntered(mIsMouseOver, lastRect))
|
||||
{
|
||||
mIsMouseOver = true;
|
||||
mCooldownNotificationClearAction.Pause();
|
||||
}
|
||||
|
||||
if (MouseExited(mIsMouseOver, lastRect))
|
||||
{
|
||||
mIsMouseOver = false;
|
||||
mCooldownNotificationClearAction.Resume();
|
||||
}
|
||||
}
|
||||
|
||||
internal static void DrawNotification(INotificationContent notification)
|
||||
{
|
||||
GUILayout.BeginVertical();
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
notification.OnGUI();
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
internal static bool DrawButton(GUIContent content)
|
||||
{
|
||||
GUIStyle buttonStyle = new GUIStyle(EditorStyles.miniButton);
|
||||
|
||||
Rect rt = GUILayoutUtility.GetRect(
|
||||
content,
|
||||
buttonStyle,
|
||||
GUILayout.Width(60));
|
||||
|
||||
return GUI.Button(
|
||||
rt,
|
||||
content,
|
||||
buttonStyle);
|
||||
}
|
||||
|
||||
static void DrawNotificationAvailablePanel(
|
||||
NotificationBar notificationBar)
|
||||
{
|
||||
GUILayout.BeginVertical();
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
if (GUILayout.Button(PlasticLocalization.GetString(
|
||||
notificationBar.IsVisible ?
|
||||
PlasticLocalization.Name.HideNotification :
|
||||
PlasticLocalization.Name.ShowNotification)))
|
||||
{
|
||||
notificationBar.SetVisibility(!notificationBar.IsVisible);
|
||||
}
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
static void DrawNotification(Notification notification)
|
||||
{
|
||||
DrawIcon(notification.Image);
|
||||
DrawNotification(notification.Content);
|
||||
}
|
||||
|
||||
static void DrawWorkspaceStatus(WorkspaceWindow workspaceWindow)
|
||||
{
|
||||
DrawIcon(Images.GetBranchIcon());
|
||||
|
||||
if (workspaceWindow.WorkspaceStatus == null)
|
||||
return;
|
||||
|
||||
DrawWorkspaceStatusLabel(string.Format(
|
||||
"{0}@{1}@{2}",
|
||||
workspaceWindow.WorkspaceStatus.ObjectSpec,
|
||||
workspaceWindow.WorkspaceStatus.RepositoryName,
|
||||
workspaceWindow.ServerDisplayName));
|
||||
}
|
||||
|
||||
internal static void DrawIcon(Texture2D icon, int size = UnityConstants.STATUS_BAR_ICON_SIZE)
|
||||
{
|
||||
GUILayout.BeginVertical();
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
GUILayout.Label(
|
||||
icon,
|
||||
UnityStyles.StatusBar.Icon,
|
||||
GUILayout.Height(size),
|
||||
GUILayout.Width(size));
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
static void DrawWorkspaceStatusLabel(string label)
|
||||
{
|
||||
GUILayout.BeginVertical();
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
DrawCopyableLabel.For(label, UnityStyles.StatusBar.Label);
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
static void BeginDrawBar()
|
||||
{
|
||||
EditorGUILayout.BeginVertical(
|
||||
GetBarStyle(),
|
||||
GUILayout.Height(UnityConstants.STATUS_BAR_HEIGHT));
|
||||
GUILayout.FlexibleSpace();
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
}
|
||||
|
||||
static void EndDrawBar()
|
||||
{
|
||||
EditorGUILayout.EndHorizontal();
|
||||
GUILayout.FlexibleSpace();
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
|
||||
static GUIStyle GetBarStyle()
|
||||
{
|
||||
if (sBarTexture == null)
|
||||
sBarTexture = new Texture2D(1, 1);
|
||||
|
||||
if (sBarStyle == null)
|
||||
sBarStyle = new GUIStyle();
|
||||
|
||||
sBarTexture.SetPixel(0, 0, UnityStyles.Colors.BackgroundBar);
|
||||
sBarTexture.Apply();
|
||||
sBarStyle.normal.background = sBarTexture;
|
||||
|
||||
return sBarStyle;
|
||||
}
|
||||
|
||||
static bool MouseEntered(
|
||||
bool isMouseOver,
|
||||
Rect lastRect)
|
||||
{
|
||||
bool isInside = lastRect.Contains(Event.current.mousePosition);
|
||||
return isInside && !isMouseOver;
|
||||
}
|
||||
|
||||
static bool MouseExited(
|
||||
bool isMouseOver,
|
||||
Rect lastRect)
|
||||
{
|
||||
bool isInside = lastRect.Contains(Event.current.mousePosition);
|
||||
return !isInside && isMouseOver;
|
||||
}
|
||||
|
||||
class Notification
|
||||
{
|
||||
internal INotificationContent Content { get; private set; }
|
||||
internal MessageType MessageType { get; private set; }
|
||||
internal Texture2D Image { get; private set; }
|
||||
|
||||
internal Notification(INotificationContent content, MessageType messageType, Texture2D image)
|
||||
{
|
||||
Content = content;
|
||||
MessageType = messageType;
|
||||
Image = image;
|
||||
}
|
||||
}
|
||||
|
||||
Notification mNotification;
|
||||
WorkspaceWindow mWorkspaceWindow;
|
||||
IIncomingChangesNotification mIncomingChangesNotification;
|
||||
IShelvedChangesNotification mShelvedChangesNotification;
|
||||
bool mIsMouseOver = false;
|
||||
|
||||
readonly CooldownWindowDelayer mCooldownNotificationClearAction;
|
||||
|
||||
static Texture2D sBarTexture;
|
||||
static GUIStyle sBarStyle;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2dae17e8419667e46a2a476dd2cd18e0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user