PlasticSCMWindow.cs
5.6 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using PlasticGui;
using System.Collections;
using System.Collections.Generic;
using Unity.PlasticSCM.Editor.UI;
using Unity.PlasticSCM.Editor.UI.UIElements;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
namespace Unity.PlasticSCM.Editor
{
internal class PlasticSCMWindow : EditorWindow
{
internal static void ShowWindow()
{
PlasticSCMWindow window = GetWindow<PlasticSCMWindow>();
window.titleContent = new GUIContent(
UnityConstants.PLASTIC_WINDOW_TITLE,
Images.GetImage(Images.Name.IconPlasticView));
window.minSize= new Vector2(750, 260);
window.Show();
}
void OnEnable()
{
BuildComponents();
}
void OnDestroy()
{
Dispose();
}
void Dispose()
{
mRefreshButton.clicked -= RefreshButton_Clicked;
mSettingsButton.clicked -= SettingsButton_Clicked;
}
void BuildComponents()
{
VisualElement root = rootVisualElement;
root.Clear();
root.LoadStyle("PlasticWindow/PlasticWindow");
BuildTabview(root);
BuildStatusBar(root);
}
/*** Tabview ***/
void BuildTabview(VisualElement root)
{
mTabView = new TabView();
mTabView.LoadStyle("PlasticWindow/PlasticWindow");
mTabView.AddTab(
PlasticLocalization.GetString(PlasticLocalization.Name.PendingChangesViewTitle),
new VisualElement()).clicked += () =>
{
// TODO: Add view switch to Pending Changes here
};
mTabView.AddTab(
PlasticLocalization.GetString(PlasticLocalization.Name.ChangesetsViewTitle),
new VisualElement()).clicked += () =>
{
// TODO: Add view switch to Changesets here
};
mTabView.AddTab(
PlasticLocalization.GetString(PlasticLocalization.Name.IncomingChangesViewTitle),
new VisualElement()).clicked += () =>
{
// TODO: Add view switch to Incoming Changes here
};
VisualElement controlsContainer = new VisualElement() { name = "ControlsContainer" };
controlsContainer.AddToClassList("row");
mRefreshButton = new Button() { name = "RefreshButton" };
mRefreshButton.Add(new Image() { image = Images.GetRefreshIcon() });
mRefreshButton.clicked += RefreshButton_Clicked;
controlsContainer.Add(mRefreshButton);
mSettingsButton = new Button() { name = "SettingsButton" };
mSettingsButton.Add(new Image() { image = EditorGUIUtility.IconContent("settings").image });
mSettingsButton.clicked += SettingsButton_Clicked;
controlsContainer.Add(mSettingsButton);
var tabArea = mTabView.Q<VisualElement>("TabArea");
tabArea.Add(controlsContainer);
root.Add(mTabView);
}
void RefreshButton_Clicked()
{
// TODO
}
void SettingsButton_Clicked()
{
GenericMenu menu = new GenericMenu();
menu.AddItem(new GUIContent("Invite Members to Workspace"),
false,
InviteMemberButton_clicked,
null);
menu.ShowAsContext();
}
static void InviteMemberButton_clicked(object obj)
{
Application.OpenURL("https://www.plasticscm.com/dashboard/cloud/unity_cloud/users-and-groups");
}
/*** Update Bar ***/
void BuildStatusBar(VisualElement root)
{
VisualElement StatusBar = new VisualElement() { name = "StatusBar" };
StatusBar.AddToClassList("row");
StatusBar.LoadLayout("PlasticWindow/StatusBar");
mUpdateNotification = StatusBar.Q<VisualElement>("UpdateNotificationContainer");
mUpdateNotificaionImage = StatusBar.Q<Image>("UpdateNotificationImage");
mUpdateNotificationLabel = StatusBar.Q<Label>("UpdateNotificationLabel");
mUpdateButton = StatusBar.Q<Button>("UpdateButton");
mUpdateButton.text = PlasticLocalization.GetString(PlasticLocalization.Name.UpdateButton);
mBranchLabel = StatusBar.Q<Label>("BranchLabel");
mBranchLabel.text = "Branch main @ codice @ codice@cloud";
ShowUpdateNotification(false);
root.Add(StatusBar);
}
// For the icon string, the name of unity icons can be found at
// https://unitylist.com/p/5c3/Unity-editor-icons
internal void ShowUpdateNotification(bool show, string icon = "", string notification = "")
{
if (!string.IsNullOrEmpty(icon))
mUpdateNotificaionImage.image = EditorGUIUtility.IconContent(icon).image;
if (!string.IsNullOrEmpty(notification))
mUpdateNotificationLabel.text = notification;
if (show)
mUpdateNotification.RemoveFromClassList("display-none");
else
mUpdateNotification.AddToClassList("display-none");
}
// Tabview variables
internal TabView mTabView;
Button mRefreshButton;
Button mSettingsButton;
// Update bar variables
VisualElement mUpdateNotification;
Image mUpdateNotificaionImage;
Label mUpdateNotificationLabel;
Button mUpdateButton;
Label mBranchLabel;
}
}