123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254 |
- using System;
- using System.Threading.Tasks;
-
- using UnityEditor;
- using UnityEngine;
-
- using Codice.Client.Common;
- using Codice.Client.Common.EventTracking;
- using Codice.Client.Common.Threading;
- using Codice.CM.Common;
- using Codice.LogWrapper;
- using GluonGui;
- using PlasticGui;
- using PlasticGui.WorkspaceWindow;
- 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;
-
- using GluonCheckIncomingChanges = PlasticGui.Gluon.WorkspaceWindow.CheckIncomingChanges;
- using GluonNewIncomingChangesUpdater = PlasticGui.Gluon.WorkspaceWindow.NewIncomingChangesUpdater;
- using PlasticAssetModificationProcessor = Unity.PlasticSCM.Editor.AssetUtils.Processor.AssetModificationProcessor;
-
- namespace Unity.PlasticSCM.Editor
- {
- internal class PlasticWindow : EditorWindow,
- CheckIncomingChanges.IAutoRefreshIncomingChangesView,
- GluonCheckIncomingChanges.IAutoRefreshIncomingChangesView,
- CreateWorkspaceView.ICreateWorkspaceListener
- {
- internal bool ShowWelcomeViewForTesting { get; set; }
-
- internal WorkspaceWindow WorkspaceWindowForTesting { get { return mWorkspaceWindow; } }
-
- internal ViewSwitcher ViewSwitcherForTesting { get { return mViewSwitcher; } }
-
- internal CmConnection CmConnectionForTesting { get { return CmConnection.Get(); } }
-
- internal WelcomeView GetWelcomeView()
- {
- if (mWelcomeView != null)
- return mWelcomeView;
-
- mWelcomeView = new WelcomeView(
- this,
- this,
- PlasticGui.Plastic.API,
- PlasticGui.Plastic.WebRestAPI,
- CmConnection.Get());
-
- return mWelcomeView;
- }
-
- internal void DisableCollabIfEnabledWhenLoaded()
- {
- mDisableCollabIfEnabledWhenLoaded = true;
- }
-
- internal PlasticProjectSettingsProvider.IAutoRefreshView GetPendingChangesView()
- {
- return mViewSwitcher != null ? mViewSwitcher.PendingChangesTab : null;
- }
-
- internal void UpdateWindowIcon(PlasticNotification.Status status)
- {
- Texture windowIcon = PlasticNotification.GetIcon(status);
-
- if (titleContent.image != windowIcon)
- titleContent.image = windowIcon;
- }
-
- internal void RefreshWorkspaceUI()
- {
- InitializePlastic();
- Repaint();
-
- OnFocus();
- }
-
- internal void InitializePlastic()
- {
- if (mForceToReOpen)
- {
- mForceToReOpen = 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);
-
- mViewHost = new ViewHost();
-
- mStatusBar = new StatusBar();
-
- mViewSwitcher = new ViewSwitcher(
- PlasticGui.Plastic.API.GetRepositorySpec(mWkInfo),
- mWkInfo,
- mViewHost,
- 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,
- mViewHost,
- mViewSwitcher,
- mViewSwitcher,
- mDeveloperNewIncomingChangesUpdater,
- this);
-
- mViewSwitcher.SetWorkspaceWindow(mWorkspaceWindow);
- mViewSwitcher.ShowInitialView();
-
- PlasticApp.RegisterWorkspaceWindow(mWorkspaceWindow);
- PlasticPlugin.WorkspaceOperationsMonitor.RegisterWindow(
- mWorkspaceWindow,
- mViewHost,
- mDeveloperNewIncomingChangesUpdater);
-
- UnityStyles.Initialize(Repaint);
-
- AssetMenuItems.BuildOperations(
- mWkInfo,
- mWorkspaceWindow,
- mViewSwitcher,
- mViewSwitcher,
- mViewHost,
- PlasticPlugin.WorkspaceOperationsMonitor,
- mDeveloperNewIncomingChangesUpdater,
- PlasticPlugin.AssetStatusCache,
- mViewSwitcher,
- mViewSwitcher,
- mShowDownloadPlasticExeWindow,
- mIsGluonMode);
-
- DrawInspectorOperations.BuildOperations(
- mWkInfo,
- mWorkspaceWindow,
- mViewSwitcher,
- mViewSwitcher,
- mViewHost,
- PlasticPlugin.WorkspaceOperationsMonitor,
- mDeveloperNewIncomingChangesUpdater,
- PlasticPlugin.AssetStatusCache,
- mViewSwitcher,
- mViewSwitcher,
- mShowDownloadPlasticExeWindow,
- mIsGluonMode);
-
- mLastUpdateTime = EditorApplication.timeSinceStartup;
-
- mViewSwitcher.ShowBranchesViewIfNeeded();
- mViewSwitcher.ShowLocksViewIfNeeded();
-
- // Note: this need to be initialized regardless of the type of the UVCS Edition installed
- InitializeCloudSubscriptionData(mWkInfo);
-
- if (!EditionToken.IsCloudEdition())
- return;
-
- InitializeNotificationBarUpdater(
- mWkInfo, mStatusBar.NotificationBar);
- }
- catch (Exception ex)
- {
- mException = ex;
-
- ExceptionsHandler.HandleException("InitializePlastic", ex);
- }
- }
-
- void 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();
- }
-
- 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);
-
- UpdateWindowIcon(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;
-
- UnRegisterApplicationFocusHandlers(this);
-
- ClosePlastic(this);
- }
-
- void OnDestroy()
- {
- mLog.Debug("OnDestroy");
-
- if (mException != null)
- return;
-
- if (mWkInfo == null)
- return;
-
- if (!PlasticApp.HasRunningOperation())
- 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");
-
- mForceToReOpen = true;
-
- ReOpenPlasticWindow(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;
-
- WelcomeView 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);
-
- 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);
- }
- }
-
- 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;
-
- NewIncomingChanges.LaunchUpdater(
- mDeveloperNewIncomingChangesUpdater,
- mGluonNewIncomingChangesUpdater);
-
- if (!PlasticApp.HasRunningOperation())
- mCooldownAutoRefreshChangesAction.Ping();
-
- ((IWorkspaceWindow)mWorkspaceWindow).UpdateTitle();
- }
-
- 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;
-
- ClosePlastic(this);
-
- InitializePlastic();
- }
-
- void InitializeCloudSubscriptionData(WorkspaceInfo wkInfo)
- {
- mIsCloudOrganization = false;
- mIsUGOSubscription = false;
-
- RepositorySpec repSpec = PlasticGui.Plastic.API.GetRepositorySpec(wkInfo);
-
- if (repSpec == null)
- return;
-
- mIsCloudOrganization = PlasticGui.Plastic.API.IsCloud(repSpec.Server);
-
- if (!mIsCloudOrganization)
- return;
-
- 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;
- }
-
- mIsUGOSubscription = t.Result.OrderSource == UGO_ORDER_SOURCE;
- });
- }
-
- 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);
- }
-
- 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);
- }
-
- static void DoTabToolbar(
- WorkspaceInfo workspaceInfo,
- ViewSwitcher viewSwitcher,
- LaunchTool.IShowDownloadPlasticExeWindow showDownloadPlasticExeWindow,
- LaunchTool.IProcessExecutor processExecutor,
- bool isGluonMode,
- bool isCloudOrganization,
- bool isUGOSubscription)
- {
- EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
-
- viewSwitcher.TabButtonsGUI();
-
- GUILayout.FlexibleSpace();
-
- DoSearchField(viewSwitcher);
-
- DoToolbarButtons(
- workspaceInfo,
- viewSwitcher,
- showDownloadPlasticExeWindow,
- processExecutor,
- isGluonMode,
- isCloudOrganization,
- isUGOSubscription);
-
- EditorGUILayout.EndHorizontal();
- }
-
- 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 DoToolbarButtons(
- WorkspaceInfo wkInfo,
- ViewSwitcher viewSwitcher,
- LaunchTool.IShowDownloadPlasticExeWindow showDownloadPlasticExeWindow,
- LaunchTool.IProcessExecutor processExecutor,
- bool isGluonMode,
- bool isCloudOrganization,
- bool isUGOSubscription)
- {
- //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()))
- {
- OpenDevOpsUpgradePlanUrl();
- }
- }
- }
-
- //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 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 OpenBranchListViewAndSendEvent(
- WorkspaceInfo wkInfo,
- ViewSwitcher viewSwitcher)
- {
- viewSwitcher.ShowBranchesView();
-
- TrackFeatureUseEvent.For(
- PlasticGui.Plastic.API.GetRepositorySpec(wkInfo),
- TrackFeatureUseEvent.Features.OpenBranchesView);
- }
-
- static void OpenLocksViewAndSendEvent(
- WorkspaceInfo wkInfo,
- ViewSwitcher viewSwitcher)
- {
- viewSwitcher.ShowLocksView();
-
- TrackFeatureUseEvent.For(
- PlasticGui.Plastic.API.GetRepositorySpec(wkInfo),
- TrackFeatureUseEvent.Features.OpenLocksView);
- }
-
- 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 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(string.Empty);
-
- 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,
- () => PlasticAssetModificationProcessor.SetForceCheckoutOption(
- !PlasticAssetModificationProcessor.ForceCheckout));
-
- menu.ShowAsContext();
- }
-
- static void OpenUnityDashboardInviteUsersUrl(string organization)
- {
- Application.OpenURL(UnityUrl.UnityDashboard.Plastic.GetForInviteUsers(
- organization, UnityUrl.UnityDashboard.UnityCloudRequestSource.Editor));
- }
-
- static void OpenDevOpsUpgradePlanUrl()
- {
- Application.OpenURL(UnityUrl.DevOps.GetSignUp());
- }
-
- static void DisableVCSIfEnabled(string projectPath)
- {
- if (!VCSPlugin.IsEnabled())
- return;
-
- VCSPlugin.Disable();
-
- mLog.DebugFormat("Disabled VCS Plugin on Project: {0}",
- projectPath);
- }
-
- static void DisableCollabIfEnabled(string projectPath)
- {
- if (!CollabPlugin.IsEnabled())
- return;
-
- CollabPlugin.Disable();
-
- mLog.DebugFormat("Disabled Collab 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 void InitializePlasticOnForceToReOpen(PlasticWindow window)
- {
- if (window.mWkInfo == null)
- return;
-
- window.mViewSwitcher.OnEnable();
-
- window.InitializeNewIncomingChanges(
- window.mWkInfo,
- window.mIsGluonMode,
- window.mViewSwitcher);
-
- PlasticApp.RegisterWorkspaceWindow(
- window.mWorkspaceWindow);
-
- if (PlasticPlugin.WorkspaceOperationsMonitor != null)
- {
- PlasticPlugin.WorkspaceOperationsMonitor.RegisterWindow(
- window.mWorkspaceWindow,
- window.mViewHost,
- window.mDeveloperNewIncomingChangesUpdater);
- }
-
- if (!EditionToken.IsCloudEdition())
- return;
-
- window.InitializeNotificationBarUpdater(
- window.mWkInfo,
- window.mStatusBar.NotificationBar);
- }
-
- static void ClosePlastic(PlasticWindow window)
- {
- if (window.mViewSwitcher != null)
- window.mViewSwitcher.OnDisable();
-
- PlasticApp.UnRegisterWorkspaceWindow();
-
- if (PlasticPlugin.WorkspaceOperationsMonitor != null)
- PlasticPlugin.WorkspaceOperationsMonitor.UnRegisterWindow();
-
- DisposeNewIncomingChanges(window);
-
- DisposeNotificationBarUpdater(window);
-
- AvatarImages.Dispose();
- }
-
- static void ReOpenPlasticWindow(PlasticWindow closedWindow)
- {
- EditorWindow dockWindow = FindEditorWindow.ToDock<PlasticWindow>();
-
- PlasticWindow newWindow = InstantiateFrom(closedWindow);
-
- InitializePlasticOnForceToReOpen(newWindow);
-
- if (DockEditorWindow.IsAvailable())
- DockEditorWindow.To(dockWindow, newWindow);
-
- newWindow.Show();
- newWindow.Focus();
- }
-
- static bool NeedsToDisplayWelcomeView(
- bool clientNeedsConfiguration,
- WorkspaceInfo wkInfo)
- {
- if (clientNeedsConfiguration)
- return true;
-
- if (wkInfo == null)
- return true;
-
- return false;
- }
-
- 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 PlasticWindow InstantiateFrom(PlasticWindow window)
- {
- PlasticWindow result = Instantiate(window);
- result.mIsGluonMode = window.mIsGluonMode;
- result.mIsCloudOrganization = window.mIsCloudOrganization;
- result.mIsUGOSubscription = window.mIsUGOSubscription;
- result.mDisableCollabIfEnabledWhenLoaded = window.mDisableCollabIfEnabledWhenLoaded;
- result.mLastUpdateTime = window.mLastUpdateTime;
- result.mWkInfo = window.mWkInfo;
- result.mException = window.mException;
- result.mWelcomeView = window.mWelcomeView;
- result.mViewSwitcher = window.mViewSwitcher;
- result.mViewHost = window.mViewHost;
- result.mWorkspaceWindow = window.mWorkspaceWindow;
- result.mStatusBar = window.mStatusBar;
- result.mNotificationBarUpdater = window.mNotificationBarUpdater;
- result.mCooldownAutoRefreshChangesAction = window.mCooldownAutoRefreshChangesAction;
- result.mDeveloperNewIncomingChangesUpdater = window.mDeveloperNewIncomingChangesUpdater;
- result.mGluonNewIncomingChangesUpdater = window.mGluonNewIncomingChangesUpdater;
- result.mIncomingChangesNotifier = window.mIncomingChangesNotifier;
- return result;
- }
-
- 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)
- return currentWkInfo != null;
-
- return !lastWkInfo.Equals(currentWkInfo);
- }
- }
-
- [SerializeField]
- bool mForceToReOpen;
-
- bool mIsGluonMode;
- bool mIsCloudOrganization;
- bool mIsUGOSubscription;
-
- [NonSerialized]
- WorkspaceInfo mWkInfo;
- double mLastUpdateTime = 0f;
-
- Exception mException;
- bool mDisableCollabIfEnabledWhenLoaded;
- WelcomeView mWelcomeView;
- ViewHost mViewHost;
- WorkspaceWindow mWorkspaceWindow;
- StatusBar mStatusBar;
- CooldownWindowDelayer mCooldownAutoRefreshChangesAction;
- IIncomingChangesNotifier mIncomingChangesNotifier;
- ViewSwitcher mViewSwitcher;
- NotificationBarUpdater mNotificationBarUpdater;
- NewIncomingChangesUpdater mDeveloperNewIncomingChangesUpdater;
- GluonNewIncomingChangesUpdater mGluonNewIncomingChangesUpdater;
-
- LaunchTool.IShowDownloadPlasticExeWindow mShowDownloadPlasticExeWindow =
- new LaunchTool.ShowDownloadPlasticExeWindow();
- LaunchTool.IProcessExecutor mProcessExecutor =
- new LaunchTool.ProcessExecutor();
-
- const string UGO_ORDER_SOURCE = "UGO";
-
- static readonly ILog mLog = PlasticApp.GetLogger("PlasticWindow");
- }
- }
|