12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211 |
- 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()
- {
- 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()
- {
- // We need to disable FSWatcher because otherwise it hangs
- // when you move the window between monitors with different scale
- MonoFileSystemWatcher.IsEnabled = false;
-
- if (mException != null)
- return;
-
- if (mWkInfo == null)
- {
- ClosePlasticWindow(this);
- return;
- }
-
- mViewSwitcher.OnDisable();
-
- ClosePlasticWindow(this);
- }
-
- void 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;
-
- mForceToOpen = true;
- ShowPlasticWindow(this);
- }
-
- void 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;
-
- mViewSwitcher.AutoRefreshPendingChangesView();
- mViewSwitcher.AutoRefreshIncomingChangesView();
- }
-
- 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,
- 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);
-
- mCooldownAutoRefreshPendingChangesAction = new CooldownWindowDelayer(
- mViewSwitcher.AutoRefreshPendingChangesView,
- UnityConstants.AUTO_REFRESH_PENDING_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,
- this,
- mIsGluonMode);
-
- DrawInspectorOperations.BuildOperations(
- mWkInfo,
- mWorkspaceWindow,
- mViewSwitcher,
- mViewSwitcher,
- viewHost,
- PlasticPlugin.WorkspaceOperationsMonitor,
- mDeveloperNewIncomingChangesUpdater,
- PlasticPlugin.AssetStatusCache,
- mViewSwitcher,
- mViewSwitcher,
- mShowDownloadPlasticExeWindow,
- this,
- 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)
- {
- mIsUGOSubscription = false;
- mUpgradePlanUrl = string.Empty;
-
- RepositorySpec repSpec = PlasticGui.Plastic.API.GetRepositorySpec(wkInfo);
-
- if (repSpec == null)
- {
- 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;
- }
-
- 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()
- {
- 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);
-
- // 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, causing
- // the pending changes view to unwanted auto-refresh.
- // So, we need to delay the auto-refresh call in order
- // to give the fswatcher enough time to process the events.
- // Note that the OnFocus event is not affected by this issue.
- mCooldownAutoRefreshPendingChangesAction.Ping();
-
- mViewSwitcher.AutoRefreshIncomingChangesView();
- }
-
- void 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 isUGOSubscription,
- string upgradePlanUrl)
- {
- EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
-
- viewSwitcher.TabButtonsGUI();
-
- GUILayout.FlexibleSpace();
-
- DoSearchField(viewSwitcher);
-
- DoToolbarButtons(
- workspaceInfo,
- viewSwitcher,
- showDownloadPlasticExeWindow,
- processExecutor,
- isGluonMode,
- 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 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);
- }
-
- RepositorySpec repSpec = PlasticGui.Plastic.API.GetRepositorySpec(wkInfo);
-
- if (PlasticGui.Plastic.API.IsCloud(repSpec.Server))
- {
- if (DrawToolbarButton(
- Images.GetInviteUsersIcon(),
- PlasticLocalization.Name.InviteMembers.GetString()))
- {
- InviteMembersToOrganization(repSpec);
- }
-
- 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(RepositorySpec repSpec)
- {
- 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));
- }
-
- 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.mCooldownAutoRefreshPendingChangesAction = window.mCooldownAutoRefreshPendingChangesAction;
- 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 mCooldownAutoRefreshPendingChangesAction;
- internal ViewSwitcher mViewSwitcher;
- WelcomeView mWelcomeView;
-
- StatusBar mStatusBar;
- NotificationBarUpdater mNotificationBarUpdater;
-
- PlasticGui.WorkspaceWindow.NewIncomingChangesUpdater mDeveloperNewIncomingChangesUpdater;
- GluonNewIncomingChangesUpdater mGluonNewIncomingChangesUpdater;
-
- WorkspaceWindow mWorkspaceWindow;
-
- bool mIsGluonMode;
- bool mDisableCollabIfEnabledWhenLoaded;
- 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 = LogManager.GetLogger("PlasticWindow");
- }
- }
|