123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- 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.GetPlasticViewIcon());
-
- 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;
- }
- }
|