1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237 |
- using System;
- using System.Linq;
- using System.Threading.Tasks;
-
- using UnityEditor;
- using UnityEngine;
-
- using Codice.Client.Common;
- using Codice.Client.Common.EventTracking;
- using Codice.Client.Common.FsNodeReaders.Watcher;
- using Codice.Client.Common.Threading;
- using Codice.CM.Common;
- using Codice.LogWrapper;
- using GluonCheckIncomingChanges = PlasticGui.Gluon.WorkspaceWindow.CheckIncomingChanges;
- using GluonGui;
- using GluonNewIncomingChangesUpdater = PlasticGui.Gluon.WorkspaceWindow.NewIncomingChangesUpdater;
- using PlasticAssetModificationProcessor = Unity.PlasticSCM.Editor.AssetUtils.Processor.AssetModificationProcessor;
- using PlasticGui;
- using PlasticGui.WorkspaceWindow.NotificationBar;
- using Unity.PlasticSCM.Editor.AssetMenu;
- using Unity.PlasticSCM.Editor.AssetUtils;
- using Unity.PlasticSCM.Editor.Configuration;
- using Unity.PlasticSCM.Editor.Configuration.CloudEdition.Welcome;
- using Unity.PlasticSCM.Editor.Inspector;
- using Unity.PlasticSCM.Editor.Tool;
- using Unity.PlasticSCM.Editor.UI;
- using Unity.PlasticSCM.Editor.UI.Avatar;
- using Unity.PlasticSCM.Editor.UI.Progress;
- using Unity.PlasticSCM.Editor.UI.StatusBar;
- using Unity.PlasticSCM.Editor.Views.CreateWorkspace;
- using Unity.PlasticSCM.Editor.Views.Welcome;
- using Unity.PlasticSCM.Editor.WebApi;
-
- namespace Unity.PlasticSCM.Editor
- {
- internal class PlasticWindow : EditorWindow,
- PlasticGui.WorkspaceWindow.CheckIncomingChanges.IAutoRefreshIncomingChangesView,
- GluonCheckIncomingChanges.IAutoRefreshIncomingChangesView,
- CreateWorkspaceView.ICreateWorkspaceListener
- {
- internal WorkspaceWindow WorkspaceWindowForTesting { get { return mWorkspaceWindow; } }
- internal ViewSwitcher ViewSwitcherForTesting { get { return mViewSwitcher; } }
- internal CmConnection CmConnectionForTesting { get { return CmConnection.Get(); } }
-
- internal bool ShowWelcomeViewForTesting;
-
- internal void SetupWindowTitle(PlasticNotification.Status status)
- {
- Texture windowIcon = PlasticNotification.GetIcon(status);
-
- // The titleContent icon does not update unless we also update the title text
- // Temporarily doing it by adding space characters
- string title = UnityConstants.PLASTIC_WINDOW_TITLE;
- title += String.Concat(Enumerable.Repeat(" ", (int)status));
-
- titleContent = new GUIContent(title, windowIcon);
- }
-
- internal void DisableCollabIfEnabledWhenLoaded()
- {
- mDisableCollabIfEnabledWhenLoaded = true;
- }
-
- void PlasticGui.WorkspaceWindow.CheckIncomingChanges.IAutoRefreshIncomingChangesView.IfVisible()
- {
- mViewSwitcher.AutoRefreshIncomingChangesView();
- }
-
- void GluonCheckIncomingChanges.IAutoRefreshIncomingChangesView.IfVisible()
- {
- mViewSwitcher.AutoRefreshIncomingChangesView();
- }
-
- void CreateWorkspaceView.ICreateWorkspaceListener.OnWorkspaceCreated(
- WorkspaceInfo wkInfo, bool isGluonMode)
- {
- mWkInfo = wkInfo;
- mIsGluonMode = isGluonMode;
- mWelcomeView = null;
-
- PlasticPlugin.Enable();
-
- if (mIsGluonMode)
- ConfigurePartialWorkspace.AsFullyChecked(mWkInfo);
-
- InitializePlastic();
- Repaint();
- }
-
- internal void RefreshWorkspaceUI()
- {
- InitializePlastic();
- Repaint();
-
- OnFocus();
- }
-
- void OnEnable()
- {
- mLog.Debug("OnEnable");
-
- wantsMouseMove = true;
-
- if (mException != null)
- return;
-
- minSize = new Vector2(
- UnityConstants.PLASTIC_WINDOW_MIN_SIZE_WIDTH,
- UnityConstants.PLASTIC_WINDOW_MIN_SIZE_HEIGHT);
-
- SetupWindowTitle(PlasticNotification.Status.None);
-
- RegisterApplicationFocusHandlers(this);
-
- if (!PlasticPlugin.ConnectionMonitor.IsConnected)
- return;
-
- PlasticPlugin.Enable();
- InitializePlastic();
- }
-
- void OnDisable()
- {
- mLog.Debug("OnDisable");
-
- // We need to disable MonoFSWatcher because otherwise it hangs
- // when you move the window between monitors with different scale
- PlasticApp.DisableMonoFsWatcherIfNeeded();
-
- if (mException != null)
- return;
-
- if (mWkInfo == null)
- {
- ClosePlasticWindow(this);
- return;
- }
-
- mViewSwitcher.OnDisable();
-
- ClosePlasticWindow(this);
- }
-
- void OnDestroy()
- {
- mLog.Debug("OnDestroy");
-
- if (mException != null)
- return;
-
- if (mWkInfo == null)
- return;
-
- if (!mWorkspaceWindow.IsOperationInProgress())
- return;
-
- bool bCloseWindow = GuiMessage.ShowQuestion(
- PlasticLocalization.GetString(PlasticLocalization.Name.OperationRunning),
- PlasticLocalization.GetString(PlasticLocalization.Name.ConfirmClosingRunningOperation),
- PlasticLocalization.GetString(PlasticLocalization.Name.YesButton));
-
- if (bCloseWindow)
- return;
-
- mLog.Debug(
- "Show window again because the user doesn't want " +
- "to quit it due to there is an operation running");
-
- mForceToOpen = true;
- ShowPlasticWindow(this);
- }
-
- void OnFocus()
- {
- mLog.Debug("OnFocus");
-
- if (mException != null)
- return;
-
- if (mWkInfo == null)
- return;
-
- if (!PlasticPlugin.ConnectionMonitor.IsConnected)
- return;
-
- // We don't want to auto-refresh the views when the window
- // is focused due to a right mouse button click because
- // if there is no internet connection a dialog appears and
- // it prevents being able to open the context menu in order
- // to close the Plastic SCM window
- if (Mouse.IsRightMouseButtonPressed(Event.current))
- return;
-
- mCooldownAutoRefreshChangesAction.Ping();
- }
-
- void OnGUI()
- {
- if (!PlasticPlugin.ConnectionMonitor.IsConnected)
- {
- DoNotConnectedArea();
- return;
- }
-
- if (mException != null)
- {
- DoExceptionErrorArea();
- return;
- }
-
- try
- {
- // IMPORTANT: disable collab (if needed)
- // must be executed before the next if statement
- // where we check if collab is enabled
- if (mDisableCollabIfEnabledWhenLoaded)
- {
- mDisableCollabIfEnabledWhenLoaded = false;
- DisableCollabIfEnabled(ProjectPath.FromApplicationDataPath(
- ApplicationDataPath.Get()));
- }
-
- if (CollabPlugin.IsEnabled())
- {
- // execute Close() once after all inspectors update
- // to avoid our window to be drawn in back color
- EditorApplication.delayCall = Close;
- return;
- }
-
- bool clientNeedsConfiguration = UnityConfigurationChecker.NeedsConfiguration() || ShowWelcomeViewForTesting;
-
- var welcomeView = GetWelcomeView();
-
- if (clientNeedsConfiguration && welcomeView.autoLoginState == AutoLogin.State.Off)
- {
- welcomeView.autoLoginState = AutoLogin.State.Started;
- }
-
- if (welcomeView.autoLoginState == AutoLogin.State.OrganizationChoosed)
- {
- OnEnable();
- welcomeView.autoLoginState = AutoLogin.State.InitializingPlastic;
- }
-
- if (NeedsToDisplayWelcomeView(clientNeedsConfiguration, mWkInfo))
- {
- welcomeView.OnGUI(clientNeedsConfiguration);
- return;
- }
-
- //TODO: Codice - beta: hide the switcher until the update dialog is implemented
- //DrawGuiModeSwitcher.ForMode(
- // isGluonMode, plasticClient, changesTreeView, editorWindow);
-
- DoTabToolbar(
- mWkInfo,
- mViewSwitcher,
- mShowDownloadPlasticExeWindow,
- mProcessExecutor,
- mIsGluonMode,
- mIsCloudOrganization,
- mIsUGOSubscription,
- mUpgradePlanUrl);
-
- mViewSwitcher.TabViewGUI();
-
- if (mWorkspaceWindow.IsOperationInProgress())
- DrawProgressForOperations.For(
- mWorkspaceWindow, mWorkspaceWindow.Progress,
- position.width);
-
- mStatusBar.OnGUI(
- mWkInfo,
- mWorkspaceWindow,
- mViewSwitcher,
- mViewSwitcher,
- mIncomingChangesNotifier,
- mIsGluonMode);
- }
- catch (Exception ex)
- {
- if (IsExitGUIException(ex))
- throw;
-
- GUI.enabled = true;
-
- if (IsIMGUIPaintException(ex))
- {
- ExceptionsHandler.LogException("PlasticWindow", ex);
- return;
- }
-
- mException = ex;
-
- DoExceptionErrorArea();
-
- ExceptionsHandler.HandleException("OnGUI", ex);
- }
- }
-
- void Update()
- {
- if (mException != null)
- return;
-
- if (mWkInfo == null)
- return;
-
- try
- {
- double currentUpdateTime = EditorApplication.timeSinceStartup;
- double elapsedSeconds = currentUpdateTime - mLastUpdateTime;
-
- mViewSwitcher.Update();
- mWorkspaceWindow.OnParentUpdated(elapsedSeconds);
-
- if (mWelcomeView != null)
- mWelcomeView.Update();
-
- mLastUpdateTime = currentUpdateTime;
- }
- catch (Exception ex)
- {
- mException = ex;
-
- ExceptionsHandler.HandleException("Update", ex);
- }
- }
-
- internal void InitializePlastic()
- {
- if (mForceToOpen)
- {
- mForceToOpen = false;
- return;
- }
-
- try
- {
- if (UnityConfigurationChecker.NeedsConfiguration())
- return;
-
- mWkInfo = FindWorkspace.InfoForApplicationPath(
- ApplicationDataPath.Get(), PlasticGui.Plastic.API);
-
- if (mWkInfo == null)
- return;
-
- PlasticPlugin.EnableForWorkspace();
-
- DisableVCSIfEnabled(mWkInfo.ClientPath);
-
- mIsGluonMode = PlasticGui.Plastic.API.IsGluonWorkspace(mWkInfo);
-
- ViewHost viewHost = new ViewHost();
-
- mStatusBar = new StatusBar();
-
- mViewSwitcher = new ViewSwitcher(
- PlasticGui.Plastic.API.GetRepositorySpec(mWkInfo),
- mWkInfo,
- viewHost,
- mIsGluonMode,
- PlasticPlugin.AssetStatusCache,
- mShowDownloadPlasticExeWindow,
- mProcessExecutor,
- PlasticPlugin.WorkspaceOperationsMonitor,
- mStatusBar,
- this);
-
- InitializeNewIncomingChanges(mWkInfo, mIsGluonMode, mViewSwitcher);
-
- // Create a CooldownWindowDelayer to make the auto-refresh changes delayed.
- // In this way, we cover the following scenario:
- // * When Unity Editor window is activated it writes some files to its Temp
- // folder. This causes the fswatcher to process those events.
- // * We need to wait until the fswatcher finishes processing the events,
- // otherwise the NewChangesInWk method will return TRUE because there
- // are pending events to process, which causes an unwanted 'get pending
- // changes' operation when there are no new changes.
- // * So, we need to delay the auto-refresh call in order
- // to give the fswatcher enough time to process the events.
- mCooldownAutoRefreshChangesAction = new CooldownWindowDelayer(
- () =>
- {
- mViewSwitcher.AutoRefreshPendingChangesView();
- mViewSwitcher.AutoRefreshIncomingChangesView();
- },
- UnityConstants.AUTO_REFRESH_CHANGES_DELAYED_INTERVAL);
-
- mWorkspaceWindow = new WorkspaceWindow(
- mWkInfo,
- viewHost,
- mViewSwitcher,
- mViewSwitcher,
- mDeveloperNewIncomingChangesUpdater,
- this);
-
- mViewSwitcher.SetWorkspaceWindow(mWorkspaceWindow);
- mViewSwitcher.ShowInitialView();
-
- PlasticPlugin.WorkspaceOperationsMonitor.RegisterWindow(
- mWorkspaceWindow,
- viewHost,
- mDeveloperNewIncomingChangesUpdater);
-
- UnityStyles.Initialize(Repaint);
-
- AssetMenuItems.BuildOperations(
- mWkInfo,
- mWorkspaceWindow,
- mViewSwitcher,
- mViewSwitcher,
- viewHost,
- PlasticPlugin.WorkspaceOperationsMonitor,
- mDeveloperNewIncomingChangesUpdater,
- PlasticPlugin.AssetStatusCache,
- mViewSwitcher,
- mViewSwitcher,
- mShowDownloadPlasticExeWindow,
- mIsGluonMode);
-
- DrawInspectorOperations.BuildOperations(
- mWkInfo,
- mWorkspaceWindow,
- mViewSwitcher,
- mViewSwitcher,
- viewHost,
- PlasticPlugin.WorkspaceOperationsMonitor,
- mDeveloperNewIncomingChangesUpdater,
- PlasticPlugin.AssetStatusCache,
- mViewSwitcher,
- mViewSwitcher,
- mShowDownloadPlasticExeWindow,
- mIsGluonMode);
-
- mLastUpdateTime = EditorApplication.timeSinceStartup;
-
- mViewSwitcher.ShowBranchesViewIfNeeded();
- mViewSwitcher.ShowLocksViewIfNeeded();
-
- if (!EditionToken.IsCloudEdition())
- return;
-
- InitializeNotificationBarUpdater(
- mWkInfo, mStatusBar.NotificationBar);
-
- GetSubscriptionDetails(mWkInfo);
- }
- catch (Exception ex)
- {
- mException = ex;
-
- ExceptionsHandler.HandleException("InitializePlastic", ex);
- }
- }
-
- void InitializeNewIncomingChanges(
- WorkspaceInfo wkInfo,
- bool bIsGluonMode,
- ViewSwitcher viewSwitcher)
- {
- if (bIsGluonMode)
- {
- Gluon.IncomingChangesNotifier gluonNotifier =
- new Gluon.IncomingChangesNotifier(this);
- mGluonNewIncomingChangesUpdater =
- NewIncomingChanges.BuildUpdaterForGluon(
- wkInfo, viewSwitcher, gluonNotifier, this, gluonNotifier,
- new GluonCheckIncomingChanges.CalculateIncomingChanges());
- mIncomingChangesNotifier = gluonNotifier;
- return;
- }
-
- Developer.IncomingChangesNotifier developerNotifier =
- new Developer.IncomingChangesNotifier(this);
- mDeveloperNewIncomingChangesUpdater =
- NewIncomingChanges.BuildUpdaterForDeveloper(
- wkInfo, viewSwitcher, developerNotifier,
- this, developerNotifier);
- mIncomingChangesNotifier = developerNotifier;
- }
-
- void InitializeNotificationBarUpdater(
- WorkspaceInfo wkInfo,
- INotificationBar notificationBar)
- {
- mNotificationBarUpdater = new NotificationBarUpdater(
- notificationBar,
- PlasticGui.Plastic.WebRestAPI,
- new UnityPlasticTimerBuilder(),
- new NotificationBarUpdater.NotificationBarConfig());
- mNotificationBarUpdater.Start();
- mNotificationBarUpdater.SetWorkspace(wkInfo);
- }
-
- void GetSubscriptionDetails(WorkspaceInfo wkInfo)
- {
- mIsCloudOrganization = false;
- mIsUGOSubscription = false;
- mUpgradePlanUrl = string.Empty;
-
- RepositorySpec repSpec = PlasticGui.Plastic.API.GetRepositorySpec(wkInfo);
-
- if (repSpec == null)
- {
- return;
- }
-
- mIsCloudOrganization = PlasticGui.Plastic.API.IsCloud(repSpec.Server);
-
- string organizationName = ServerOrganizationParser.GetOrganizationFromServer(repSpec.Server);
-
- Task.Run(
- () =>
- {
- string authToken = AuthToken.GetForServer(repSpec.Server);
-
- if (string.IsNullOrEmpty(authToken))
- return null;
-
- return WebRestApiClient.PlasticScm.GetSubscriptionDetails(
- organizationName,
- authToken);
- }).ContinueWith(
- t =>
- {
- if (t.Result == null)
- {
- mLog.DebugFormat("Error getting Subscription details for organization {0}", organizationName);
- return;
- }
-
- if (t.Result.OrganizationName != organizationName)
- {
- mLog.DebugFormat("Not requested organization ({0}) subscription has been received", t.Result.OrganizationName);
- return;
- }
-
- mIsUGOSubscription = t.Result.OrderSource == UGO_ORDER_SOURCE;
- mUpgradePlanUrl = t.Result.ExtraData.ContainsKey(UGO_CONSUMPTION_URL_KEY) && t.Result.IsAdmin ?
- t.Result.ExtraData[UGO_CONSUMPTION_URL_KEY].ToString() : UnityUrl.UnityDashboard.Plastic.Get();
- });
- }
-
- void OnApplicationActivated()
- {
- mLog.Debug("OnApplicationActivated");
-
- if (mException != null)
- return;
-
- if (!PlasticPlugin.ConnectionMonitor.IsConnected)
- return;
-
- Reload.IfWorkspaceConfigChanged(
- PlasticGui.Plastic.API, mWkInfo, mIsGluonMode,
- ExecuteFullReload);
-
- if (mWkInfo == null)
- return;
-
- ((IWorkspaceWindow)mWorkspaceWindow).UpdateTitle();
-
- NewIncomingChanges.LaunchUpdater(
- mDeveloperNewIncomingChangesUpdater,
- mGluonNewIncomingChangesUpdater);
-
- mCooldownAutoRefreshChangesAction.Ping();
- }
-
- void OnApplicationDeactivated()
- {
- mLog.Debug("OnApplicationDeactivated");
-
- if (mException != null)
- return;
-
- if (mWkInfo == null)
- return;
-
- if (!PlasticPlugin.ConnectionMonitor.IsConnected)
- return;
-
- NewIncomingChanges.StopUpdater(
- mDeveloperNewIncomingChangesUpdater,
- mGluonNewIncomingChangesUpdater);
- }
-
- void ExecuteFullReload()
- {
- mException = null;
-
- DisposeNewIncomingChanges(this);
-
- DisposeNotificationBarUpdater(this);
-
- InitializePlastic();
- }
-
- void DoNotConnectedArea()
- {
- string labelText = PlasticLocalization.GetString(
- PlasticLocalization.Name.NotConnectedTryingToReconnect);
-
- string buttonText = PlasticLocalization.GetString(
- PlasticLocalization.Name.TryNowButton);
-
- GUI.enabled = !PlasticPlugin.ConnectionMonitor.IsTryingReconnection;
-
- DrawActionHelpBox.For(
- Images.GetInfoDialogIcon(), labelText, buttonText,
- PlasticPlugin.ConnectionMonitor.CheckConnection);
-
- GUI.enabled = true;
- }
-
- void DoExceptionErrorArea()
- {
- string labelText = PlasticLocalization.GetString(
- PlasticLocalization.Name.UnexpectedError);
-
- string buttonText = PlasticLocalization.GetString(
- PlasticLocalization.Name.ReloadButton);
-
- DrawActionHelpBox.For(
- Images.GetErrorDialogIcon(), labelText, buttonText,
- ExecuteFullReload);
- }
-
- internal WelcomeView GetWelcomeView()
- {
- if (mWelcomeView != null)
- return mWelcomeView;
-
- mWelcomeView = new WelcomeView(
- this,
- this,
- PlasticGui.Plastic.API,
- PlasticGui.Plastic.WebRestAPI,
- CmConnection.Get());
-
- return mWelcomeView;
- }
-
- static void DoSearchField(ViewSwitcher viewSwitcher)
- {
- if (viewSwitcher.IsViewSelected(ViewSwitcher.SelectedTab.PendingChanges))
- {
- viewSwitcher.PendingChangesTab.DrawSearchFieldForPendingChangesTab();
- return;
- }
- if (viewSwitcher.IsViewSelected(ViewSwitcher.SelectedTab.Changesets))
- {
- viewSwitcher.ChangesetsTab.DrawSearchFieldForChangesetsTab();
- return;
- }
- if (viewSwitcher.IsViewSelected(ViewSwitcher.SelectedTab.History))
- {
- viewSwitcher.HistoryTab.DrawSearchFieldForHistoryTab();
- return;
- }
- if (viewSwitcher.IsViewSelected(ViewSwitcher.SelectedTab.Branches))
- {
- viewSwitcher.BranchesTab.DrawSearchFieldForBranchesTab();
- return;
- }
- if (viewSwitcher.IsViewSelected(ViewSwitcher.SelectedTab.Locks))
- {
- viewSwitcher.LocksTab.DrawSearchFieldForLocksTab();
- return;
- }
- }
-
- static void DoTabToolbar(
- WorkspaceInfo workspaceInfo,
- ViewSwitcher viewSwitcher,
- LaunchTool.IShowDownloadPlasticExeWindow showDownloadPlasticExeWindow,
- LaunchTool.IProcessExecutor processExecutor,
- bool isGluonMode,
- bool isCloudOrganization,
- bool isUGOSubscription,
- string upgradePlanUrl)
- {
- EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
-
- viewSwitcher.TabButtonsGUI();
-
- GUILayout.FlexibleSpace();
-
- DoSearchField(viewSwitcher);
-
- DoToolbarButtons(
- workspaceInfo,
- viewSwitcher,
- showDownloadPlasticExeWindow,
- processExecutor,
- isGluonMode,
- isCloudOrganization,
- isUGOSubscription,
- upgradePlanUrl);
-
- EditorGUILayout.EndHorizontal();
- }
-
- static void OpenBranchListViewAndSendEvent(
- WorkspaceInfo wkInfo,
- ViewSwitcher viewSwitcher)
- {
- viewSwitcher.ShowBranchesView();
- TrackFeatureUseEvent.For(
- PlasticGui.Plastic.API.GetRepositorySpec(wkInfo),
- TrackFeatureUseEvent.Features.OpenBranchesView);
- }
-
- static void ShowBranchesContextMenu(
- WorkspaceInfo wkInfo,
- ViewSwitcher viewSwitcher,
- LaunchTool.IShowDownloadPlasticExeWindow showDownloadPlasticExeWindow,
- LaunchTool.IProcessExecutor processExecutor,
- bool isGluonMode)
- {
- GenericMenu menu = new GenericMenu();
-
- string branchesListView = PlasticLocalization.GetString(
- PlasticLocalization.Name.Branches);
-
- menu.AddItem(
- new GUIContent(branchesListView),
- false,
- () => OpenBranchListViewAndSendEvent(wkInfo, viewSwitcher));
-
- string branchExplorer = PlasticLocalization.GetString(
- PlasticLocalization.Name.BranchExplorerMenu);
-
- menu.AddItem(
- new GUIContent(branchExplorer),
- false,
- () => LaunchTool.OpenBranchExplorer(
- showDownloadPlasticExeWindow,
- processExecutor,
- wkInfo,
- isGluonMode));
-
- menu.ShowAsContext();
- }
-
- static void OpenLocksViewAndSendEvent(
- WorkspaceInfo wkInfo,
- ViewSwitcher viewSwitcher)
- {
- viewSwitcher.ShowLocksView();
- TrackFeatureUseEvent.For(
- PlasticGui.Plastic.API.GetRepositorySpec(wkInfo),
- TrackFeatureUseEvent.Features.OpenLocksView);
- }
-
- static void ShowSettingsContextMenu(
- LaunchTool.IShowDownloadPlasticExeWindow showDownloadPlasticExeWindow,
- LaunchTool.IProcessExecutor processExecutor,
- WorkspaceInfo wkInfo,
- bool isGluonMode)
- {
- GenericMenu menu = new GenericMenu();
-
- string openToolText = isGluonMode ?
- PlasticLocalization.Name.OpenInGluon.GetString() :
- PlasticLocalization.Name.OpenInDesktopApp.GetString();
-
- menu.AddItem(
- new GUIContent(openToolText),
- false,
- () => LaunchTool.OpenGUIForMode(
- showDownloadPlasticExeWindow,
- processExecutor,
- wkInfo,
- isGluonMode));
-
- menu.AddSeparator("");
-
- menu.AddItem(
- new GUIContent(PlasticLocalization.Name.Options.GetString()),
- false,
- () => SettingsService.OpenProjectSettings(UnityConstants.PROJECT_SETTINGS_TAB_PATH));
-
- menu.AddItem(
- new GUIContent(PlasticAssetModificationProcessor.ForceCheckout ?
- PlasticLocalization.Name.DisableForcedCheckout.GetString() :
- PlasticLocalization.Name.EnableForcedCheckout.GetString()),
- false,
- ForceCheckout_Clicked,
- null);
-
- menu.ShowAsContext();
- }
-
- static void DoToolbarButtons(
- WorkspaceInfo wkInfo,
- ViewSwitcher viewSwitcher,
- LaunchTool.IShowDownloadPlasticExeWindow showDownloadPlasticExeWindow,
- LaunchTool.IProcessExecutor processExecutor,
- bool isGluonMode,
- bool isCloudOrganization,
- bool isUGOSubscription,
- string upgradePlanUrl)
- {
- //TODO: Codice - beta: hide the diff button until the behavior is implemented
- /*GUILayout.Button(PlasticLocalization.GetString(
- PlasticLocalization.Name.DiffWindowMenuItemDiff),
- EditorStyles.toolbarButton,
- GUILayout.Width(UnityConstants.REGULAR_BUTTON_WIDTH));*/
-
- if (viewSwitcher.IsViewSelected(ViewSwitcher.SelectedTab.Changesets))
- {
- viewSwitcher.ChangesetsTab.DrawDateFilter();
- }
- if (viewSwitcher.IsViewSelected(ViewSwitcher.SelectedTab.Branches))
- {
- viewSwitcher.BranchesTab.DrawDateFilter();
- }
-
- Texture refreshIcon = Images.GetRefreshIcon();
- string refreshIconTooltip = PlasticLocalization.GetString(
- PlasticLocalization.Name.RefreshButton);
-
- if (DrawToolbarButton(refreshIcon, refreshIconTooltip))
- {
- viewSwitcher.RefreshSelectedView();
- }
-
- if (viewSwitcher.IsViewSelected(ViewSwitcher.SelectedTab.PendingChanges))
- {
- Texture2D icon = Images.GetUndoIcon();
- string tooltip = PlasticLocalization.GetString(
- PlasticLocalization.Name.UndoSelectedChanges);
-
- if (DrawToolbarButton(icon, tooltip))
- {
- TrackFeatureUseEvent.For(
- PlasticGui.Plastic.API.GetRepositorySpec(wkInfo),
- TrackFeatureUseEvent.Features.UndoIconButton);
-
- viewSwitcher.PendingChangesTab.UndoForMode(wkInfo, isGluonMode);
- }
- }
-
- if (isGluonMode)
- {
- string label = PlasticLocalization.GetString(PlasticLocalization.Name.ConfigureGluon);
- if (DrawActionButton.For(label))
- LaunchTool.OpenWorkspaceConfiguration(
- showDownloadPlasticExeWindow,
- processExecutor,
- wkInfo,
- isGluonMode);
- }
- else
- {
- Texture2D icon = Images.GetBranchIcon();
- string tooltip = PlasticLocalization.GetString(PlasticLocalization.Name.Branches);
- if (DrawToolbarButton(icon, tooltip))
- {
- ShowBranchesContextMenu(
- wkInfo,
- viewSwitcher,
- showDownloadPlasticExeWindow,
- processExecutor,
- isGluonMode);
- }
- }
-
- if (DrawToolbarButton(Images.GetLockIcon(), PlasticLocalization.Name.ShowLocks.GetString()))
- {
- OpenLocksViewAndSendEvent(wkInfo, viewSwitcher);
- }
-
- if (isCloudOrganization)
- {
- if (DrawToolbarButton(
- Images.GetInviteUsersIcon(),
- PlasticLocalization.Name.InviteMembers.GetString()))
- {
- InviteMembersToOrganization(wkInfo);
- }
-
- if (isUGOSubscription)
- {
- if (DrawToolbarTextButton(
- PlasticLocalization.Name.UpgradePlan.GetString()))
- {
- UpgradePlan(upgradePlanUrl);
- }
- }
- }
-
- //TODO: Add settings button tooltip localization
- if (DrawToolbarButton(Images.GetSettingsIcon(), string.Empty))
- {
- ShowSettingsContextMenu(
- showDownloadPlasticExeWindow,
- processExecutor,
- wkInfo,
- isGluonMode);
- }
- }
-
- static bool DrawToolbarButton(Texture icon, string tooltip)
- {
- return GUILayout.Button(
- new GUIContent(icon, tooltip),
- EditorStyles.toolbarButton,
- GUILayout.Width(26));
- }
-
- static bool DrawToolbarTextButton(string text)
- {
- return GUILayout.Button(
- new GUIContent(text, string.Empty),
- EditorStyles.toolbarButton);
- }
-
- static void UpgradePlan(string upgradePlanUrl)
- {
- Application.OpenURL(upgradePlanUrl);
- }
-
- static void InviteMembersToOrganization(WorkspaceInfo wkInfo)
- {
- RepositorySpec repSpec = PlasticGui.Plastic.API.GetRepositorySpec(wkInfo);
-
- string organizationName = ServerOrganizationParser.
- GetOrganizationFromServer(repSpec.Server);
-
- CurrentUserAdminCheckResponse response = null;
-
- IThreadWaiter waiter = ThreadWaiter.GetWaiter(50);
- waiter.Execute(
- /*threadOperationDelegate*/
- delegate
- {
- string authToken = AuthToken.GetForServer(repSpec.Server);
-
- if (string.IsNullOrEmpty(authToken))
- {
- return;
- }
-
- response = WebRestApiClient.PlasticScm.IsUserAdmin(
- organizationName,
- authToken);
- },
- /*afterOperationDelegate*/
- delegate
- {
- if (waiter.Exception != null)
- {
- ExceptionsHandler.LogException(
- "IsUserAdmin",
- waiter.Exception);
-
- OpenUnityDashboardInviteUsersUrl(organizationName);
- return;
- }
-
- if (response == null)
- {
- mLog.DebugFormat(
- "Error checking if the user is the organization admin for {0}",
- organizationName);
-
- OpenUnityDashboardInviteUsersUrl(organizationName);
- return;
- }
-
- if (response.Error != null)
- {
- mLog.DebugFormat(
- "Error checking if the user is the organization admin: {0}",
- string.Format("Unable to get IsUserAdminResponse: {0} [code {1}]",
- response.Error.Message,
- response.Error.ErrorCode));
-
- OpenUnityDashboardInviteUsersUrl(organizationName);
- return;
- }
-
- if (response.IsCurrentUserAdmin)
- {
- OpenUnityDashboardInviteUsersUrl(response.OrganizationName);
- return;
- }
-
- GuiMessage.ShowInformation(
- PlasticLocalization.GetString(PlasticLocalization.Name.InviteMembersTitle),
- PlasticLocalization.GetString(PlasticLocalization.Name.InviteMembersMessage));
- });
- }
-
- static void OpenUnityDashboardInviteUsersUrl(string organization)
- {
- Application.OpenURL(UnityUrl.UnityDashboard.Plastic.GetForInviteUsers(
- organization, UnityUrl.UnityDashboard.UnityCloudRequestSource.Editor));
- }
-
- static void ForceCheckout_Clicked(object obj)
- {
- PlasticAssetModificationProcessor.SetForceCheckoutOption(
- !PlasticAssetModificationProcessor.ForceCheckout);
- }
-
- static void DisableVCSIfEnabled(string projectPath)
- {
- if (!VCSPlugin.IsEnabled())
- return;
-
- VCSPlugin.Disable();
-
- mLog.DebugFormat("Disabled VCS Plugin on Project: {0}",
- projectPath);
- }
-
- static void DisposeNewIncomingChanges(PlasticWindow window)
- {
- NewIncomingChanges.DisposeUpdater(
- window.mDeveloperNewIncomingChangesUpdater,
- window.mGluonNewIncomingChangesUpdater);
-
- window.mDeveloperNewIncomingChangesUpdater = null;
- window.mGluonNewIncomingChangesUpdater = null;
- }
-
- static void DisposeNotificationBarUpdater(PlasticWindow window)
- {
- if (window.mNotificationBarUpdater == null)
- return;
-
- window.mNotificationBarUpdater.Dispose();
- window.mNotificationBarUpdater = null;
- }
-
- static void RegisterApplicationFocusHandlers(PlasticWindow window)
- {
- EditorWindowFocus.OnApplicationActivated += window.OnApplicationActivated;
- EditorWindowFocus.OnApplicationDeactivated += window.OnApplicationDeactivated;
- }
-
- static void UnRegisterApplicationFocusHandlers(PlasticWindow window)
- {
- EditorWindowFocus.OnApplicationActivated -= window.OnApplicationActivated;
- EditorWindowFocus.OnApplicationDeactivated -= window.OnApplicationDeactivated;
- }
-
- static bool IsExitGUIException(Exception ex)
- {
- return ex is ExitGUIException;
- }
-
- static bool IsIMGUIPaintException(Exception ex)
- {
- if (!(ex is ArgumentException))
- return false;
-
- return ex.Message.StartsWith("Getting control") &&
- ex.Message.Contains("controls when doing repaint");
- }
-
- static void ClosePlasticWindow(PlasticWindow window)
- {
- UnRegisterApplicationFocusHandlers(window);
-
- if (PlasticPlugin.WorkspaceOperationsMonitor != null)
- PlasticPlugin.WorkspaceOperationsMonitor.UnRegisterWindow();
-
- DisposeNewIncomingChanges(window);
-
- DisposeNotificationBarUpdater(window);
-
- AvatarImages.Dispose();
- }
-
- static void ShowPlasticWindow(PlasticWindow window)
- {
- EditorWindow dockWindow = FindEditorWindow.ToDock<PlasticWindow>();
-
- PlasticWindow newPlasticWindow = InstantiateFrom(window);
-
- if (DockEditorWindow.IsAvailable())
- DockEditorWindow.To(dockWindow, newPlasticWindow);
-
- newPlasticWindow.Show();
-
- newPlasticWindow.Focus();
- }
-
- static bool NeedsToDisplayWelcomeView(
- bool clientNeedsConfiguration,
- WorkspaceInfo wkInfo)
- {
- if (clientNeedsConfiguration)
- return true;
-
- if (wkInfo == null)
- return true;
-
- return false;
- }
-
- static void DisableCollabIfEnabled(string projectPath)
- {
- if (!CollabPlugin.IsEnabled())
- return;
-
- CollabPlugin.Disable();
-
- mLog.DebugFormat("Disabled Collab Plugin on Project: {0}",
- projectPath);
- }
-
- static PlasticWindow InstantiateFrom(PlasticWindow window)
- {
- PlasticWindow result = Instantiate(window);
- result.mWkInfo = window.mWkInfo;
- result.mWorkspaceWindow = window.mWorkspaceWindow;
- result.mViewSwitcher = window.mViewSwitcher;
- result.mCooldownAutoRefreshChangesAction = window.mCooldownAutoRefreshChangesAction;
- result.mDeveloperNewIncomingChangesUpdater = window.mDeveloperNewIncomingChangesUpdater;
- result.mGluonNewIncomingChangesUpdater = window.mGluonNewIncomingChangesUpdater;
- result.mException = window.mException;
- result.mLastUpdateTime = window.mLastUpdateTime;
- result.mIsGluonMode = window.mIsGluonMode;
- result.mIncomingChangesNotifier = window.mIncomingChangesNotifier;
- result.mStatusBar = window.mStatusBar;
- result.mWelcomeView = window.mWelcomeView;
- result.mNotificationBarUpdater = window.mNotificationBarUpdater;
- return result;
- }
-
- internal PlasticProjectSettingsProvider.IAutoRefreshView GetPendingChangesView()
- {
- return mViewSwitcher != null ? mViewSwitcher.PendingChangesTab : null;
- }
-
- static class Reload
- {
- internal static void IfWorkspaceConfigChanged(
- IPlasticAPI plasticApi,
- WorkspaceInfo lastWkInfo,
- bool lastIsGluonMode,
- Action reloadAction)
- {
- string applicationPath = ApplicationDataPath.Get();
-
- bool isGluonMode = false;
- WorkspaceInfo wkInfo = null;
-
- IThreadWaiter waiter = ThreadWaiter.GetWaiter(10);
- waiter.Execute(
- /*threadOperationDelegate*/ delegate
- {
- wkInfo = FindWorkspace.
- InfoForApplicationPath(applicationPath, plasticApi);
-
- if (wkInfo != null)
- isGluonMode = plasticApi.IsGluonWorkspace(wkInfo);
- },
- /*afterOperationDelegate*/ delegate
- {
- if (waiter.Exception != null)
- return;
-
- if (!IsWorkspaceConfigChanged(
- lastWkInfo, wkInfo,
- lastIsGluonMode, isGluonMode))
- return;
-
- reloadAction();
- });
- }
-
- static bool IsWorkspaceConfigChanged(
- WorkspaceInfo lastWkInfo,
- WorkspaceInfo currentWkInfo,
- bool lastIsGluonMode,
- bool currentIsGluonMode)
- {
- if (lastIsGluonMode != currentIsGluonMode)
- return true;
-
- if (lastWkInfo == null || currentWkInfo == null)
- return true;
-
- return !lastWkInfo.Equals(currentWkInfo);
- }
- }
-
- [SerializeField]
- bool mForceToOpen;
-
- [NonSerialized]
- WorkspaceInfo mWkInfo;
-
- Exception mException;
-
- internal IIncomingChangesNotifier mIncomingChangesNotifier;
-
- double mLastUpdateTime = 0f;
-
- CooldownWindowDelayer mCooldownAutoRefreshChangesAction;
- internal ViewSwitcher mViewSwitcher;
- WelcomeView mWelcomeView;
-
- StatusBar mStatusBar;
- NotificationBarUpdater mNotificationBarUpdater;
-
- PlasticGui.WorkspaceWindow.NewIncomingChangesUpdater mDeveloperNewIncomingChangesUpdater;
- GluonNewIncomingChangesUpdater mGluonNewIncomingChangesUpdater;
-
- WorkspaceWindow mWorkspaceWindow;
-
- bool mIsGluonMode;
- bool mDisableCollabIfEnabledWhenLoaded;
- bool mIsCloudOrganization;
- bool mIsUGOSubscription;
- string mUpgradePlanUrl;
-
- LaunchTool.IShowDownloadPlasticExeWindow mShowDownloadPlasticExeWindow =
- new LaunchTool.ShowDownloadPlasticExeWindow();
- LaunchTool.IProcessExecutor mProcessExecutor =
- new LaunchTool.ProcessExecutor();
-
- const string UGO_CONSUMPTION_URL_KEY = "consumptionUrl";
- const string UGO_ORDER_SOURCE = "UGO";
-
- static readonly ILog mLog = PlasticApp.GetLogger("PlasticWindow");
- }
- }
|