No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PlasticWindow.cs 41KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211
  1. using System;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using UnityEditor;
  5. using UnityEngine;
  6. using Codice.Client.Common;
  7. using Codice.Client.Common.EventTracking;
  8. using Codice.Client.Common.FsNodeReaders.Watcher;
  9. using Codice.Client.Common.Threading;
  10. using Codice.CM.Common;
  11. using Codice.LogWrapper;
  12. using GluonCheckIncomingChanges = PlasticGui.Gluon.WorkspaceWindow.CheckIncomingChanges;
  13. using GluonGui;
  14. using GluonNewIncomingChangesUpdater = PlasticGui.Gluon.WorkspaceWindow.NewIncomingChangesUpdater;
  15. using PlasticAssetModificationProcessor = Unity.PlasticSCM.Editor.AssetUtils.Processor.AssetModificationProcessor;
  16. using PlasticGui;
  17. using PlasticGui.WorkspaceWindow.NotificationBar;
  18. using Unity.PlasticSCM.Editor.AssetMenu;
  19. using Unity.PlasticSCM.Editor.AssetUtils;
  20. using Unity.PlasticSCM.Editor.Configuration;
  21. using Unity.PlasticSCM.Editor.Configuration.CloudEdition.Welcome;
  22. using Unity.PlasticSCM.Editor.Inspector;
  23. using Unity.PlasticSCM.Editor.Tool;
  24. using Unity.PlasticSCM.Editor.UI;
  25. using Unity.PlasticSCM.Editor.UI.Avatar;
  26. using Unity.PlasticSCM.Editor.UI.Progress;
  27. using Unity.PlasticSCM.Editor.UI.StatusBar;
  28. using Unity.PlasticSCM.Editor.Views.CreateWorkspace;
  29. using Unity.PlasticSCM.Editor.Views.Welcome;
  30. using Unity.PlasticSCM.Editor.WebApi;
  31. namespace Unity.PlasticSCM.Editor
  32. {
  33. internal class PlasticWindow : EditorWindow,
  34. PlasticGui.WorkspaceWindow.CheckIncomingChanges.IAutoRefreshIncomingChangesView,
  35. GluonCheckIncomingChanges.IAutoRefreshIncomingChangesView,
  36. CreateWorkspaceView.ICreateWorkspaceListener
  37. {
  38. internal WorkspaceWindow WorkspaceWindowForTesting { get { return mWorkspaceWindow; } }
  39. internal ViewSwitcher ViewSwitcherForTesting { get { return mViewSwitcher; } }
  40. internal CmConnection CmConnectionForTesting { get { return CmConnection.Get(); } }
  41. internal bool ShowWelcomeViewForTesting;
  42. internal void SetupWindowTitle(PlasticNotification.Status status)
  43. {
  44. Texture windowIcon = PlasticNotification.GetIcon(status);
  45. // The titleContent icon does not update unless we also update the title text
  46. // Temporarily doing it by adding space characters
  47. string title = UnityConstants.PLASTIC_WINDOW_TITLE;
  48. title += String.Concat(Enumerable.Repeat(" ", (int)status));
  49. titleContent = new GUIContent(title, windowIcon);
  50. }
  51. internal void DisableCollabIfEnabledWhenLoaded()
  52. {
  53. mDisableCollabIfEnabledWhenLoaded = true;
  54. }
  55. void PlasticGui.WorkspaceWindow.CheckIncomingChanges.IAutoRefreshIncomingChangesView.IfVisible()
  56. {
  57. mViewSwitcher.AutoRefreshIncomingChangesView();
  58. }
  59. void GluonCheckIncomingChanges.IAutoRefreshIncomingChangesView.IfVisible()
  60. {
  61. mViewSwitcher.AutoRefreshIncomingChangesView();
  62. }
  63. void CreateWorkspaceView.ICreateWorkspaceListener.OnWorkspaceCreated(
  64. WorkspaceInfo wkInfo, bool isGluonMode)
  65. {
  66. mWkInfo = wkInfo;
  67. mIsGluonMode = isGluonMode;
  68. mWelcomeView = null;
  69. PlasticPlugin.Enable();
  70. if (mIsGluonMode)
  71. ConfigurePartialWorkspace.AsFullyChecked(mWkInfo);
  72. InitializePlastic();
  73. Repaint();
  74. }
  75. internal void RefreshWorkspaceUI()
  76. {
  77. InitializePlastic();
  78. Repaint();
  79. OnFocus();
  80. }
  81. void OnEnable()
  82. {
  83. wantsMouseMove = true;
  84. if (mException != null)
  85. return;
  86. minSize = new Vector2(
  87. UnityConstants.PLASTIC_WINDOW_MIN_SIZE_WIDTH,
  88. UnityConstants.PLASTIC_WINDOW_MIN_SIZE_HEIGHT);
  89. SetupWindowTitle(PlasticNotification.Status.None);
  90. RegisterApplicationFocusHandlers(this);
  91. if (!PlasticPlugin.ConnectionMonitor.IsConnected)
  92. return;
  93. PlasticPlugin.Enable();
  94. InitializePlastic();
  95. }
  96. void OnDisable()
  97. {
  98. // We need to disable FSWatcher because otherwise it hangs
  99. // when you move the window between monitors with different scale
  100. MonoFileSystemWatcher.IsEnabled = false;
  101. if (mException != null)
  102. return;
  103. if (mWkInfo == null)
  104. {
  105. ClosePlasticWindow(this);
  106. return;
  107. }
  108. mViewSwitcher.OnDisable();
  109. ClosePlasticWindow(this);
  110. }
  111. void OnDestroy()
  112. {
  113. if (mException != null)
  114. return;
  115. if (mWkInfo == null)
  116. return;
  117. if (!mWorkspaceWindow.IsOperationInProgress())
  118. return;
  119. bool bCloseWindow = GuiMessage.ShowQuestion(
  120. PlasticLocalization.GetString(PlasticLocalization.Name.OperationRunning),
  121. PlasticLocalization.GetString(PlasticLocalization.Name.ConfirmClosingRunningOperation),
  122. PlasticLocalization.GetString(PlasticLocalization.Name.YesButton));
  123. if (bCloseWindow)
  124. return;
  125. mForceToOpen = true;
  126. ShowPlasticWindow(this);
  127. }
  128. void OnFocus()
  129. {
  130. if (mException != null)
  131. return;
  132. if (mWkInfo == null)
  133. return;
  134. if (!PlasticPlugin.ConnectionMonitor.IsConnected)
  135. return;
  136. // We don't want to auto-refresh the views when the window
  137. // is focused due to a right mouse button click because
  138. // if there is no internet connection a dialog appears and
  139. // it prevents being able to open the context menu in order
  140. // to close the Plastic SCM window
  141. if (Mouse.IsRightMouseButtonPressed(Event.current))
  142. return;
  143. mViewSwitcher.AutoRefreshPendingChangesView();
  144. mViewSwitcher.AutoRefreshIncomingChangesView();
  145. }
  146. void OnGUI()
  147. {
  148. if (!PlasticPlugin.ConnectionMonitor.IsConnected)
  149. {
  150. DoNotConnectedArea();
  151. return;
  152. }
  153. if (mException != null)
  154. {
  155. DoExceptionErrorArea();
  156. return;
  157. }
  158. try
  159. {
  160. // IMPORTANT: disable collab (if needed)
  161. // must be executed before the next if statement
  162. // where we check if collab is enabled
  163. if (mDisableCollabIfEnabledWhenLoaded)
  164. {
  165. mDisableCollabIfEnabledWhenLoaded = false;
  166. DisableCollabIfEnabled(ProjectPath.FromApplicationDataPath(
  167. ApplicationDataPath.Get()));
  168. }
  169. if (CollabPlugin.IsEnabled())
  170. {
  171. // execute Close() once after all inspectors update
  172. // to avoid our window to be drawn in back color
  173. EditorApplication.delayCall = Close;
  174. return;
  175. }
  176. bool clientNeedsConfiguration = UnityConfigurationChecker.NeedsConfiguration() || ShowWelcomeViewForTesting;
  177. var welcomeView = GetWelcomeView();
  178. if (clientNeedsConfiguration && welcomeView.autoLoginState == AutoLogin.State.Off)
  179. {
  180. welcomeView.autoLoginState = AutoLogin.State.Started;
  181. }
  182. if (welcomeView.autoLoginState == AutoLogin.State.OrganizationChoosed)
  183. {
  184. OnEnable();
  185. welcomeView.autoLoginState = AutoLogin.State.InitializingPlastic;
  186. }
  187. if (NeedsToDisplayWelcomeView(clientNeedsConfiguration, mWkInfo))
  188. {
  189. welcomeView.OnGUI(clientNeedsConfiguration);
  190. return;
  191. }
  192. //TODO: Codice - beta: hide the switcher until the update dialog is implemented
  193. //DrawGuiModeSwitcher.ForMode(
  194. // isGluonMode, plasticClient, changesTreeView, editorWindow);
  195. DoTabToolbar(
  196. mWkInfo,
  197. mViewSwitcher,
  198. mShowDownloadPlasticExeWindow,
  199. mProcessExecutor,
  200. mIsGluonMode,
  201. mIsUGOSubscription,
  202. mUpgradePlanUrl);
  203. mViewSwitcher.TabViewGUI();
  204. if (mWorkspaceWindow.IsOperationInProgress())
  205. DrawProgressForOperations.For(
  206. mWorkspaceWindow, mWorkspaceWindow.Progress,
  207. position.width);
  208. mStatusBar.OnGUI(
  209. mWkInfo,
  210. mWorkspaceWindow,
  211. mViewSwitcher,
  212. mViewSwitcher,
  213. mIncomingChangesNotifier,
  214. mIsGluonMode);
  215. }
  216. catch (Exception ex)
  217. {
  218. if (IsExitGUIException(ex))
  219. throw;
  220. GUI.enabled = true;
  221. if (IsIMGUIPaintException(ex))
  222. {
  223. ExceptionsHandler.LogException("PlasticWindow", ex);
  224. return;
  225. }
  226. mException = ex;
  227. DoExceptionErrorArea();
  228. ExceptionsHandler.HandleException("OnGUI", ex);
  229. }
  230. }
  231. void Update()
  232. {
  233. if (mException != null)
  234. return;
  235. if (mWkInfo == null)
  236. return;
  237. try
  238. {
  239. double currentUpdateTime = EditorApplication.timeSinceStartup;
  240. double elapsedSeconds = currentUpdateTime - mLastUpdateTime;
  241. mViewSwitcher.Update();
  242. mWorkspaceWindow.OnParentUpdated(elapsedSeconds);
  243. if (mWelcomeView != null)
  244. mWelcomeView.Update();
  245. mLastUpdateTime = currentUpdateTime;
  246. }
  247. catch (Exception ex)
  248. {
  249. mException = ex;
  250. ExceptionsHandler.HandleException("Update", ex);
  251. }
  252. }
  253. internal void InitializePlastic()
  254. {
  255. if (mForceToOpen)
  256. {
  257. mForceToOpen = false;
  258. return;
  259. }
  260. try
  261. {
  262. if (UnityConfigurationChecker.NeedsConfiguration())
  263. return;
  264. mWkInfo = FindWorkspace.InfoForApplicationPath(
  265. ApplicationDataPath.Get(), PlasticGui.Plastic.API);
  266. if (mWkInfo == null)
  267. return;
  268. PlasticPlugin.EnableForWorkspace();
  269. DisableVCSIfEnabled(mWkInfo.ClientPath);
  270. mIsGluonMode = PlasticGui.Plastic.API.IsGluonWorkspace(mWkInfo);
  271. ViewHost viewHost = new ViewHost();
  272. mStatusBar = new StatusBar();
  273. mViewSwitcher = new ViewSwitcher(
  274. PlasticGui.Plastic.API.GetRepositorySpec(mWkInfo),
  275. mWkInfo,
  276. viewHost,
  277. mIsGluonMode,
  278. PlasticPlugin.AssetStatusCache,
  279. mShowDownloadPlasticExeWindow,
  280. mProcessExecutor,
  281. PlasticPlugin.WorkspaceOperationsMonitor,
  282. mStatusBar,
  283. this);
  284. InitializeNewIncomingChanges(mWkInfo, mIsGluonMode, mViewSwitcher);
  285. mCooldownAutoRefreshPendingChangesAction = new CooldownWindowDelayer(
  286. mViewSwitcher.AutoRefreshPendingChangesView,
  287. UnityConstants.AUTO_REFRESH_PENDING_CHANGES_DELAYED_INTERVAL);
  288. mWorkspaceWindow = new WorkspaceWindow(
  289. mWkInfo,
  290. viewHost,
  291. mViewSwitcher,
  292. mViewSwitcher,
  293. mDeveloperNewIncomingChangesUpdater,
  294. this);
  295. mViewSwitcher.SetWorkspaceWindow(mWorkspaceWindow);
  296. mViewSwitcher.ShowInitialView();
  297. PlasticPlugin.WorkspaceOperationsMonitor.RegisterWindow(
  298. mWorkspaceWindow,
  299. viewHost,
  300. mDeveloperNewIncomingChangesUpdater);
  301. UnityStyles.Initialize(Repaint);
  302. AssetMenuItems.BuildOperations(
  303. mWkInfo,
  304. mWorkspaceWindow,
  305. mViewSwitcher,
  306. mViewSwitcher,
  307. viewHost,
  308. PlasticPlugin.WorkspaceOperationsMonitor,
  309. mDeveloperNewIncomingChangesUpdater,
  310. PlasticPlugin.AssetStatusCache,
  311. mViewSwitcher,
  312. mViewSwitcher,
  313. mShowDownloadPlasticExeWindow,
  314. this,
  315. mIsGluonMode);
  316. DrawInspectorOperations.BuildOperations(
  317. mWkInfo,
  318. mWorkspaceWindow,
  319. mViewSwitcher,
  320. mViewSwitcher,
  321. viewHost,
  322. PlasticPlugin.WorkspaceOperationsMonitor,
  323. mDeveloperNewIncomingChangesUpdater,
  324. PlasticPlugin.AssetStatusCache,
  325. mViewSwitcher,
  326. mViewSwitcher,
  327. mShowDownloadPlasticExeWindow,
  328. this,
  329. mIsGluonMode);
  330. mLastUpdateTime = EditorApplication.timeSinceStartup;
  331. mViewSwitcher.ShowBranchesViewIfNeeded();
  332. mViewSwitcher.ShowLocksViewIfNeeded();
  333. if (!EditionToken.IsCloudEdition())
  334. return;
  335. InitializeNotificationBarUpdater(
  336. mWkInfo, mStatusBar.NotificationBar);
  337. GetSubscriptionDetails(mWkInfo);
  338. }
  339. catch (Exception ex)
  340. {
  341. mException = ex;
  342. ExceptionsHandler.HandleException("InitializePlastic", ex);
  343. }
  344. }
  345. void InitializeNewIncomingChanges(
  346. WorkspaceInfo wkInfo,
  347. bool bIsGluonMode,
  348. ViewSwitcher viewSwitcher)
  349. {
  350. if (bIsGluonMode)
  351. {
  352. Gluon.IncomingChangesNotifier gluonNotifier =
  353. new Gluon.IncomingChangesNotifier(this);
  354. mGluonNewIncomingChangesUpdater =
  355. NewIncomingChanges.BuildUpdaterForGluon(
  356. wkInfo, viewSwitcher, gluonNotifier, this, gluonNotifier,
  357. new GluonCheckIncomingChanges.CalculateIncomingChanges());
  358. mIncomingChangesNotifier = gluonNotifier;
  359. return;
  360. }
  361. Developer.IncomingChangesNotifier developerNotifier =
  362. new Developer.IncomingChangesNotifier(this);
  363. mDeveloperNewIncomingChangesUpdater =
  364. NewIncomingChanges.BuildUpdaterForDeveloper(
  365. wkInfo, viewSwitcher, developerNotifier,
  366. this, developerNotifier);
  367. mIncomingChangesNotifier = developerNotifier;
  368. }
  369. void InitializeNotificationBarUpdater(
  370. WorkspaceInfo wkInfo,
  371. INotificationBar notificationBar)
  372. {
  373. mNotificationBarUpdater = new NotificationBarUpdater(
  374. notificationBar,
  375. PlasticGui.Plastic.WebRestAPI,
  376. new UnityPlasticTimerBuilder(),
  377. new NotificationBarUpdater.NotificationBarConfig());
  378. mNotificationBarUpdater.Start();
  379. mNotificationBarUpdater.SetWorkspace(wkInfo);
  380. }
  381. void GetSubscriptionDetails(WorkspaceInfo wkInfo)
  382. {
  383. mIsUGOSubscription = false;
  384. mUpgradePlanUrl = string.Empty;
  385. RepositorySpec repSpec = PlasticGui.Plastic.API.GetRepositorySpec(wkInfo);
  386. if (repSpec == null)
  387. {
  388. return;
  389. }
  390. string organizationName = ServerOrganizationParser.GetOrganizationFromServer(repSpec.Server);
  391. Task.Run(
  392. () =>
  393. {
  394. string authToken = AuthToken.GetForServer(repSpec.Server);
  395. if (string.IsNullOrEmpty(authToken))
  396. return null;
  397. return WebRestApiClient.PlasticScm.GetSubscriptionDetails(
  398. organizationName,
  399. authToken);
  400. }).ContinueWith(
  401. t =>
  402. {
  403. if (t.Result == null)
  404. {
  405. mLog.DebugFormat("Error getting Subscription details for organization {0}", organizationName);
  406. return;
  407. }
  408. if (t.Result.OrganizationName != organizationName)
  409. {
  410. mLog.DebugFormat("Not requested organization ({0}) subscription has been received", t.Result.OrganizationName);
  411. return;
  412. }
  413. mIsUGOSubscription = t.Result.OrderSource == UGO_ORDER_SOURCE;
  414. mUpgradePlanUrl = t.Result.ExtraData.ContainsKey(UGO_CONSUMPTION_URL_KEY) && t.Result.IsAdmin ?
  415. t.Result.ExtraData[UGO_CONSUMPTION_URL_KEY].ToString() : UnityUrl.UnityDashboard.Plastic.Get();
  416. });
  417. }
  418. void OnApplicationActivated()
  419. {
  420. if (mException != null)
  421. return;
  422. if (!PlasticPlugin.ConnectionMonitor.IsConnected)
  423. return;
  424. Reload.IfWorkspaceConfigChanged(
  425. PlasticGui.Plastic.API, mWkInfo, mIsGluonMode,
  426. ExecuteFullReload);
  427. if (mWkInfo == null)
  428. return;
  429. ((IWorkspaceWindow)mWorkspaceWindow).UpdateTitle();
  430. NewIncomingChanges.LaunchUpdater(
  431. mDeveloperNewIncomingChangesUpdater,
  432. mGluonNewIncomingChangesUpdater);
  433. // When Unity Editor window is activated it writes some files to its Temp folder.
  434. // This causes the fswatcher to process those events.
  435. // We need to wait until the fswatcher finishes processing the events,
  436. // otherwise the NewChangesInWk method will return TRUE, causing
  437. // the pending changes view to unwanted auto-refresh.
  438. // So, we need to delay the auto-refresh call in order
  439. // to give the fswatcher enough time to process the events.
  440. // Note that the OnFocus event is not affected by this issue.
  441. mCooldownAutoRefreshPendingChangesAction.Ping();
  442. mViewSwitcher.AutoRefreshIncomingChangesView();
  443. }
  444. void OnApplicationDeactivated()
  445. {
  446. if (mException != null)
  447. return;
  448. if (mWkInfo == null)
  449. return;
  450. if (!PlasticPlugin.ConnectionMonitor.IsConnected)
  451. return;
  452. NewIncomingChanges.StopUpdater(
  453. mDeveloperNewIncomingChangesUpdater,
  454. mGluonNewIncomingChangesUpdater);
  455. }
  456. void ExecuteFullReload()
  457. {
  458. mException = null;
  459. DisposeNewIncomingChanges(this);
  460. DisposeNotificationBarUpdater(this);
  461. InitializePlastic();
  462. }
  463. void DoNotConnectedArea()
  464. {
  465. string labelText = PlasticLocalization.GetString(
  466. PlasticLocalization.Name.NotConnectedTryingToReconnect);
  467. string buttonText = PlasticLocalization.GetString(
  468. PlasticLocalization.Name.TryNowButton);
  469. GUI.enabled = !PlasticPlugin.ConnectionMonitor.IsTryingReconnection;
  470. DrawActionHelpBox.For(
  471. Images.GetInfoDialogIcon(), labelText, buttonText,
  472. PlasticPlugin.ConnectionMonitor.CheckConnection);
  473. GUI.enabled = true;
  474. }
  475. void DoExceptionErrorArea()
  476. {
  477. string labelText = PlasticLocalization.GetString(
  478. PlasticLocalization.Name.UnexpectedError);
  479. string buttonText = PlasticLocalization.GetString(
  480. PlasticLocalization.Name.ReloadButton);
  481. DrawActionHelpBox.For(
  482. Images.GetErrorDialogIcon(), labelText, buttonText,
  483. ExecuteFullReload);
  484. }
  485. internal WelcomeView GetWelcomeView()
  486. {
  487. if (mWelcomeView != null)
  488. return mWelcomeView;
  489. mWelcomeView = new WelcomeView(
  490. this,
  491. this,
  492. PlasticGui.Plastic.API,
  493. PlasticGui.Plastic.WebRestAPI,
  494. CmConnection.Get());
  495. return mWelcomeView;
  496. }
  497. static void DoSearchField(ViewSwitcher viewSwitcher)
  498. {
  499. if (viewSwitcher.IsViewSelected(ViewSwitcher.SelectedTab.PendingChanges))
  500. {
  501. viewSwitcher.PendingChangesTab.DrawSearchFieldForPendingChangesTab();
  502. return;
  503. }
  504. if (viewSwitcher.IsViewSelected(ViewSwitcher.SelectedTab.Changesets))
  505. {
  506. viewSwitcher.ChangesetsTab.DrawSearchFieldForChangesetsTab();
  507. return;
  508. }
  509. if (viewSwitcher.IsViewSelected(ViewSwitcher.SelectedTab.History))
  510. {
  511. viewSwitcher.HistoryTab.DrawSearchFieldForHistoryTab();
  512. return;
  513. }
  514. if (viewSwitcher.IsViewSelected(ViewSwitcher.SelectedTab.Branches))
  515. {
  516. viewSwitcher.BranchesTab.DrawSearchFieldForBranchesTab();
  517. return;
  518. }
  519. if (viewSwitcher.IsViewSelected(ViewSwitcher.SelectedTab.Locks))
  520. {
  521. viewSwitcher.LocksTab.DrawSearchFieldForLocksTab();
  522. return;
  523. }
  524. }
  525. static void DoTabToolbar(
  526. WorkspaceInfo workspaceInfo,
  527. ViewSwitcher viewSwitcher,
  528. LaunchTool.IShowDownloadPlasticExeWindow showDownloadPlasticExeWindow,
  529. LaunchTool.IProcessExecutor processExecutor,
  530. bool isGluonMode,
  531. bool isUGOSubscription,
  532. string upgradePlanUrl)
  533. {
  534. EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
  535. viewSwitcher.TabButtonsGUI();
  536. GUILayout.FlexibleSpace();
  537. DoSearchField(viewSwitcher);
  538. DoToolbarButtons(
  539. workspaceInfo,
  540. viewSwitcher,
  541. showDownloadPlasticExeWindow,
  542. processExecutor,
  543. isGluonMode,
  544. isUGOSubscription,
  545. upgradePlanUrl);
  546. EditorGUILayout.EndHorizontal();
  547. }
  548. static void OpenBranchListViewAndSendEvent(
  549. WorkspaceInfo wkInfo,
  550. ViewSwitcher viewSwitcher)
  551. {
  552. viewSwitcher.ShowBranchesView();
  553. TrackFeatureUseEvent.For(
  554. PlasticGui.Plastic.API.GetRepositorySpec(wkInfo),
  555. TrackFeatureUseEvent.Features.OpenBranchesView);
  556. }
  557. static void ShowBranchesContextMenu(
  558. WorkspaceInfo wkInfo,
  559. ViewSwitcher viewSwitcher,
  560. LaunchTool.IShowDownloadPlasticExeWindow showDownloadPlasticExeWindow,
  561. LaunchTool.IProcessExecutor processExecutor,
  562. bool isGluonMode)
  563. {
  564. GenericMenu menu = new GenericMenu();
  565. string branchesListView = PlasticLocalization.GetString(
  566. PlasticLocalization.Name.Branches);
  567. menu.AddItem(
  568. new GUIContent(branchesListView),
  569. false,
  570. () => OpenBranchListViewAndSendEvent(wkInfo, viewSwitcher));
  571. string branchExplorer = PlasticLocalization.GetString(
  572. PlasticLocalization.Name.BranchExplorerMenu);
  573. menu.AddItem(
  574. new GUIContent(branchExplorer),
  575. false,
  576. () => LaunchTool.OpenBranchExplorer(
  577. showDownloadPlasticExeWindow,
  578. processExecutor,
  579. wkInfo,
  580. isGluonMode));
  581. menu.ShowAsContext();
  582. }
  583. static void OpenLocksViewAndSendEvent(
  584. WorkspaceInfo wkInfo,
  585. ViewSwitcher viewSwitcher)
  586. {
  587. viewSwitcher.ShowLocksView();
  588. TrackFeatureUseEvent.For(
  589. PlasticGui.Plastic.API.GetRepositorySpec(wkInfo),
  590. TrackFeatureUseEvent.Features.OpenLocksView);
  591. }
  592. static void ShowSettingsContextMenu(
  593. LaunchTool.IShowDownloadPlasticExeWindow showDownloadPlasticExeWindow,
  594. LaunchTool.IProcessExecutor processExecutor,
  595. WorkspaceInfo wkInfo,
  596. bool isGluonMode)
  597. {
  598. GenericMenu menu = new GenericMenu();
  599. string openToolText = isGluonMode ?
  600. PlasticLocalization.Name.OpenInGluon.GetString() :
  601. PlasticLocalization.Name.OpenInDesktopApp.GetString();
  602. menu.AddItem(
  603. new GUIContent(openToolText),
  604. false,
  605. () => LaunchTool.OpenGUIForMode(
  606. showDownloadPlasticExeWindow,
  607. processExecutor,
  608. wkInfo,
  609. isGluonMode));
  610. menu.AddSeparator("");
  611. menu.AddItem(
  612. new GUIContent(PlasticLocalization.Name.Options.GetString()),
  613. false,
  614. () => SettingsService.OpenProjectSettings(UnityConstants.PROJECT_SETTINGS_TAB_PATH));
  615. menu.AddItem(
  616. new GUIContent(PlasticAssetModificationProcessor.ForceCheckout ?
  617. PlasticLocalization.Name.DisableForcedCheckout.GetString() :
  618. PlasticLocalization.Name.EnableForcedCheckout.GetString()),
  619. false,
  620. ForceCheckout_Clicked,
  621. null);
  622. menu.ShowAsContext();
  623. }
  624. static void DoToolbarButtons(
  625. WorkspaceInfo wkInfo,
  626. ViewSwitcher viewSwitcher,
  627. LaunchTool.IShowDownloadPlasticExeWindow showDownloadPlasticExeWindow,
  628. LaunchTool.IProcessExecutor processExecutor,
  629. bool isGluonMode,
  630. bool isUGOSubscription,
  631. string upgradePlanUrl)
  632. {
  633. //TODO: Codice - beta: hide the diff button until the behavior is implemented
  634. /*GUILayout.Button(PlasticLocalization.GetString(
  635. PlasticLocalization.Name.DiffWindowMenuItemDiff),
  636. EditorStyles.toolbarButton,
  637. GUILayout.Width(UnityConstants.REGULAR_BUTTON_WIDTH));*/
  638. if (viewSwitcher.IsViewSelected(ViewSwitcher.SelectedTab.Changesets))
  639. {
  640. viewSwitcher.ChangesetsTab.DrawDateFilter();
  641. }
  642. if (viewSwitcher.IsViewSelected(ViewSwitcher.SelectedTab.Branches))
  643. {
  644. viewSwitcher.BranchesTab.DrawDateFilter();
  645. }
  646. Texture refreshIcon = Images.GetRefreshIcon();
  647. string refreshIconTooltip = PlasticLocalization.GetString(
  648. PlasticLocalization.Name.RefreshButton);
  649. if (DrawToolbarButton(refreshIcon, refreshIconTooltip))
  650. {
  651. viewSwitcher.RefreshSelectedView();
  652. }
  653. if (viewSwitcher.IsViewSelected(ViewSwitcher.SelectedTab.PendingChanges))
  654. {
  655. Texture2D icon = Images.GetUndoIcon();
  656. string tooltip = PlasticLocalization.GetString(
  657. PlasticLocalization.Name.UndoSelectedChanges);
  658. if (DrawToolbarButton(icon, tooltip))
  659. {
  660. TrackFeatureUseEvent.For(
  661. PlasticGui.Plastic.API.GetRepositorySpec(wkInfo),
  662. TrackFeatureUseEvent.Features.UndoIconButton);
  663. viewSwitcher.PendingChangesTab.UndoForMode(wkInfo, isGluonMode);
  664. }
  665. }
  666. if (isGluonMode)
  667. {
  668. string label = PlasticLocalization.GetString(PlasticLocalization.Name.ConfigureGluon);
  669. if (DrawActionButton.For(label))
  670. LaunchTool.OpenWorkspaceConfiguration(
  671. showDownloadPlasticExeWindow,
  672. processExecutor,
  673. wkInfo,
  674. isGluonMode);
  675. }
  676. else
  677. {
  678. Texture2D icon = Images.GetBranchIcon();
  679. string tooltip = PlasticLocalization.GetString(PlasticLocalization.Name.Branches);
  680. if (DrawToolbarButton(icon, tooltip))
  681. {
  682. ShowBranchesContextMenu(
  683. wkInfo,
  684. viewSwitcher,
  685. showDownloadPlasticExeWindow,
  686. processExecutor,
  687. isGluonMode);
  688. }
  689. }
  690. if (DrawToolbarButton(Images.GetLockIcon(), PlasticLocalization.Name.ShowLocks.GetString()))
  691. {
  692. OpenLocksViewAndSendEvent(wkInfo, viewSwitcher);
  693. }
  694. RepositorySpec repSpec = PlasticGui.Plastic.API.GetRepositorySpec(wkInfo);
  695. if (PlasticGui.Plastic.API.IsCloud(repSpec.Server))
  696. {
  697. if (DrawToolbarButton(
  698. Images.GetInviteUsersIcon(),
  699. PlasticLocalization.Name.InviteMembers.GetString()))
  700. {
  701. InviteMembersToOrganization(repSpec);
  702. }
  703. if (isUGOSubscription)
  704. {
  705. if (DrawToolbarTextButton(
  706. PlasticLocalization.Name.UpgradePlan.GetString()))
  707. {
  708. UpgradePlan(upgradePlanUrl);
  709. }
  710. }
  711. }
  712. //TODO: Add settings button tooltip localization
  713. if (DrawToolbarButton(Images.GetSettingsIcon(), string.Empty))
  714. {
  715. ShowSettingsContextMenu(
  716. showDownloadPlasticExeWindow,
  717. processExecutor,
  718. wkInfo,
  719. isGluonMode);
  720. }
  721. }
  722. static bool DrawToolbarButton(Texture icon, string tooltip)
  723. {
  724. return GUILayout.Button(
  725. new GUIContent(icon, tooltip),
  726. EditorStyles.toolbarButton,
  727. GUILayout.Width(26));
  728. }
  729. static bool DrawToolbarTextButton(string text)
  730. {
  731. return GUILayout.Button(
  732. new GUIContent(text, string.Empty),
  733. EditorStyles.toolbarButton);
  734. }
  735. static void UpgradePlan(string upgradePlanUrl)
  736. {
  737. Application.OpenURL(upgradePlanUrl);
  738. }
  739. static void InviteMembersToOrganization(RepositorySpec repSpec)
  740. {
  741. string organizationName = ServerOrganizationParser.
  742. GetOrganizationFromServer(repSpec.Server);
  743. CurrentUserAdminCheckResponse response = null;
  744. IThreadWaiter waiter = ThreadWaiter.GetWaiter(50);
  745. waiter.Execute(
  746. /*threadOperationDelegate*/
  747. delegate
  748. {
  749. string authToken = AuthToken.GetForServer(repSpec.Server);
  750. if (string.IsNullOrEmpty(authToken))
  751. {
  752. return;
  753. }
  754. response = WebRestApiClient.PlasticScm.IsUserAdmin(
  755. organizationName,
  756. authToken);
  757. },
  758. /*afterOperationDelegate*/
  759. delegate
  760. {
  761. if (waiter.Exception != null)
  762. {
  763. ExceptionsHandler.LogException(
  764. "IsUserAdmin",
  765. waiter.Exception);
  766. OpenUnityDashboardInviteUsersUrl(organizationName);
  767. return;
  768. }
  769. if (response == null)
  770. {
  771. mLog.DebugFormat(
  772. "Error checking if the user is the organization admin for {0}",
  773. organizationName);
  774. OpenUnityDashboardInviteUsersUrl(organizationName);
  775. return;
  776. }
  777. if (response.Error != null)
  778. {
  779. mLog.DebugFormat(
  780. "Error checking if the user is the organization admin: {0}",
  781. string.Format("Unable to get IsUserAdminResponse: {0} [code {1}]",
  782. response.Error.Message,
  783. response.Error.ErrorCode));
  784. OpenUnityDashboardInviteUsersUrl(organizationName);
  785. return;
  786. }
  787. if (response.IsCurrentUserAdmin)
  788. {
  789. OpenUnityDashboardInviteUsersUrl(response.OrganizationName);
  790. return;
  791. }
  792. GuiMessage.ShowInformation(
  793. PlasticLocalization.GetString(PlasticLocalization.Name.InviteMembersTitle),
  794. PlasticLocalization.GetString(PlasticLocalization.Name.InviteMembersMessage));
  795. });
  796. }
  797. static void OpenUnityDashboardInviteUsersUrl(string organization)
  798. {
  799. Application.OpenURL(UnityUrl.UnityDashboard.Plastic.GetForInviteUsers(organization));
  800. }
  801. static void ForceCheckout_Clicked(object obj)
  802. {
  803. PlasticAssetModificationProcessor.SetForceCheckoutOption(
  804. !PlasticAssetModificationProcessor.ForceCheckout);
  805. }
  806. static void DisableVCSIfEnabled(string projectPath)
  807. {
  808. if (!VCSPlugin.IsEnabled())
  809. return;
  810. VCSPlugin.Disable();
  811. mLog.DebugFormat("Disabled VCS Plugin on Project: {0}",
  812. projectPath);
  813. }
  814. static void DisposeNewIncomingChanges(PlasticWindow window)
  815. {
  816. NewIncomingChanges.DisposeUpdater(
  817. window.mDeveloperNewIncomingChangesUpdater,
  818. window.mGluonNewIncomingChangesUpdater);
  819. window.mDeveloperNewIncomingChangesUpdater = null;
  820. window.mGluonNewIncomingChangesUpdater = null;
  821. }
  822. static void DisposeNotificationBarUpdater(PlasticWindow window)
  823. {
  824. if (window.mNotificationBarUpdater == null)
  825. return;
  826. window.mNotificationBarUpdater.Dispose();
  827. window.mNotificationBarUpdater = null;
  828. }
  829. static void RegisterApplicationFocusHandlers(PlasticWindow window)
  830. {
  831. EditorWindowFocus.OnApplicationActivated += window.OnApplicationActivated;
  832. EditorWindowFocus.OnApplicationDeactivated += window.OnApplicationDeactivated;
  833. }
  834. static void UnRegisterApplicationFocusHandlers(PlasticWindow window)
  835. {
  836. EditorWindowFocus.OnApplicationActivated -= window.OnApplicationActivated;
  837. EditorWindowFocus.OnApplicationDeactivated -= window.OnApplicationDeactivated;
  838. }
  839. static bool IsExitGUIException(Exception ex)
  840. {
  841. return ex is ExitGUIException;
  842. }
  843. static bool IsIMGUIPaintException(Exception ex)
  844. {
  845. if (!(ex is ArgumentException))
  846. return false;
  847. return ex.Message.StartsWith("Getting control") &&
  848. ex.Message.Contains("controls when doing repaint");
  849. }
  850. static void ClosePlasticWindow(PlasticWindow window)
  851. {
  852. UnRegisterApplicationFocusHandlers(window);
  853. if (PlasticPlugin.WorkspaceOperationsMonitor != null)
  854. PlasticPlugin.WorkspaceOperationsMonitor.UnRegisterWindow();
  855. DisposeNewIncomingChanges(window);
  856. DisposeNotificationBarUpdater(window);
  857. AvatarImages.Dispose();
  858. }
  859. static void ShowPlasticWindow(PlasticWindow window)
  860. {
  861. EditorWindow dockWindow = FindEditorWindow.ToDock<PlasticWindow>();
  862. PlasticWindow newPlasticWindow = InstantiateFrom(window);
  863. if (DockEditorWindow.IsAvailable())
  864. DockEditorWindow.To(dockWindow, newPlasticWindow);
  865. newPlasticWindow.Show();
  866. newPlasticWindow.Focus();
  867. }
  868. static bool NeedsToDisplayWelcomeView(
  869. bool clientNeedsConfiguration,
  870. WorkspaceInfo wkInfo)
  871. {
  872. if (clientNeedsConfiguration)
  873. return true;
  874. if (wkInfo == null)
  875. return true;
  876. return false;
  877. }
  878. static void DisableCollabIfEnabled(string projectPath)
  879. {
  880. if (!CollabPlugin.IsEnabled())
  881. return;
  882. CollabPlugin.Disable();
  883. mLog.DebugFormat("Disabled Collab Plugin on Project: {0}",
  884. projectPath);
  885. }
  886. static PlasticWindow InstantiateFrom(PlasticWindow window)
  887. {
  888. PlasticWindow result = Instantiate(window);
  889. result.mWkInfo = window.mWkInfo;
  890. result.mWorkspaceWindow = window.mWorkspaceWindow;
  891. result.mViewSwitcher = window.mViewSwitcher;
  892. result.mCooldownAutoRefreshPendingChangesAction = window.mCooldownAutoRefreshPendingChangesAction;
  893. result.mDeveloperNewIncomingChangesUpdater = window.mDeveloperNewIncomingChangesUpdater;
  894. result.mGluonNewIncomingChangesUpdater = window.mGluonNewIncomingChangesUpdater;
  895. result.mException = window.mException;
  896. result.mLastUpdateTime = window.mLastUpdateTime;
  897. result.mIsGluonMode = window.mIsGluonMode;
  898. result.mIncomingChangesNotifier = window.mIncomingChangesNotifier;
  899. result.mStatusBar = window.mStatusBar;
  900. result.mWelcomeView = window.mWelcomeView;
  901. result.mNotificationBarUpdater = window.mNotificationBarUpdater;
  902. return result;
  903. }
  904. internal PlasticProjectSettingsProvider.IAutoRefreshView GetPendingChangesView()
  905. {
  906. return mViewSwitcher != null ? mViewSwitcher.PendingChangesTab : null;
  907. }
  908. static class Reload
  909. {
  910. internal static void IfWorkspaceConfigChanged(
  911. IPlasticAPI plasticApi,
  912. WorkspaceInfo lastWkInfo,
  913. bool lastIsGluonMode,
  914. Action reloadAction)
  915. {
  916. string applicationPath = ApplicationDataPath.Get();
  917. bool isGluonMode = false;
  918. WorkspaceInfo wkInfo = null;
  919. IThreadWaiter waiter = ThreadWaiter.GetWaiter(10);
  920. waiter.Execute(
  921. /*threadOperationDelegate*/ delegate
  922. {
  923. wkInfo = FindWorkspace.
  924. InfoForApplicationPath(applicationPath, plasticApi);
  925. if (wkInfo != null)
  926. isGluonMode = plasticApi.IsGluonWorkspace(wkInfo);
  927. },
  928. /*afterOperationDelegate*/ delegate
  929. {
  930. if (waiter.Exception != null)
  931. return;
  932. if (!IsWorkspaceConfigChanged(
  933. lastWkInfo, wkInfo,
  934. lastIsGluonMode, isGluonMode))
  935. return;
  936. reloadAction();
  937. });
  938. }
  939. static bool IsWorkspaceConfigChanged(
  940. WorkspaceInfo lastWkInfo,
  941. WorkspaceInfo currentWkInfo,
  942. bool lastIsGluonMode,
  943. bool currentIsGluonMode)
  944. {
  945. if (lastIsGluonMode != currentIsGluonMode)
  946. return true;
  947. if (lastWkInfo == null || currentWkInfo == null)
  948. return true;
  949. return !lastWkInfo.Equals(currentWkInfo);
  950. }
  951. }
  952. [SerializeField]
  953. bool mForceToOpen;
  954. [NonSerialized]
  955. WorkspaceInfo mWkInfo;
  956. Exception mException;
  957. internal IIncomingChangesNotifier mIncomingChangesNotifier;
  958. double mLastUpdateTime = 0f;
  959. CooldownWindowDelayer mCooldownAutoRefreshPendingChangesAction;
  960. internal ViewSwitcher mViewSwitcher;
  961. WelcomeView mWelcomeView;
  962. StatusBar mStatusBar;
  963. NotificationBarUpdater mNotificationBarUpdater;
  964. PlasticGui.WorkspaceWindow.NewIncomingChangesUpdater mDeveloperNewIncomingChangesUpdater;
  965. GluonNewIncomingChangesUpdater mGluonNewIncomingChangesUpdater;
  966. WorkspaceWindow mWorkspaceWindow;
  967. bool mIsGluonMode;
  968. bool mDisableCollabIfEnabledWhenLoaded;
  969. bool mIsUGOSubscription;
  970. string mUpgradePlanUrl;
  971. LaunchTool.IShowDownloadPlasticExeWindow mShowDownloadPlasticExeWindow =
  972. new LaunchTool.ShowDownloadPlasticExeWindow();
  973. LaunchTool.IProcessExecutor mProcessExecutor =
  974. new LaunchTool.ProcessExecutor();
  975. const string UGO_CONSUMPTION_URL_KEY = "consumptionUrl";
  976. const string UGO_ORDER_SOURCE = "UGO";
  977. static readonly ILog mLog = LogManager.GetLogger("PlasticWindow");
  978. }
  979. }