123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456 |
- using System;
- using System.Collections.Generic;
-
- using UnityEditor;
- using UnityEditor.IMGUI.Controls;
- using UnityEngine;
-
- using Codice.CM.Common;
- using Codice.Client.Common.Threading;
-
- using PlasticGui;
- using PlasticGui.WorkspaceWindow;
- using PlasticGui.WorkspaceWindow.QueryViews;
- using PlasticGui.WorkspaceWindow.QueryViews.Branches;
- using PlasticGui.WorkspaceWindow.Update;
- using Unity.PlasticSCM.Editor.AssetUtils;
- using Unity.PlasticSCM.Editor.UI;
- using Unity.PlasticSCM.Editor.UI.Progress;
- using Unity.PlasticSCM.Editor.UI.Tree;
- using Unity.PlasticSCM.Editor.Views.Branches.Dialogs;
- using Unity.PlasticSCM.Editor.Views.Changesets;
-
- using GluonNewIncomingChangesUpdater = PlasticGui.Gluon.WorkspaceWindow.NewIncomingChangesUpdater;
-
- namespace Unity.PlasticSCM.Editor.Views.Branches
- {
- internal class BranchesTab :
- IRefreshableView,
- IBranchMenuOperations,
- IQueryRefreshableView
- {
- internal BranchesListView Table { get { return mBranchesListView; } }
- internal IBranchMenuOperations Operations { get { return this; } }
-
- internal BranchesTab(
- WorkspaceInfo wkInfo,
- IWorkspaceWindow workspaceWindow,
- IViewSwitcher viewSwitcher,
- IMergeViewLauncher mergeViewLauncher,
- IUpdateReport updateReport,
- NewIncomingChangesUpdater developerNewIncomingChangesUpdater,
- GluonNewIncomingChangesUpdater gluonNewIncomingChangesUpdater,
- EditorWindow parentWindow)
- {
- mWkInfo = wkInfo;
- mParentWindow = parentWindow;
- mProgressControls = new ProgressControlsForViews();
-
- mDeveloperNewIncomingChangesUpdater = developerNewIncomingChangesUpdater;
- mGluonNewIncomingChangesUpdater = gluonNewIncomingChangesUpdater;
-
- BuildComponents(
- wkInfo,
- workspaceWindow,
- viewSwitcher,
- mergeViewLauncher,
- updateReport,
- developerNewIncomingChangesUpdater,
- parentWindow);
-
- ((IRefreshableView)this).Refresh();
- }
-
- internal void Update()
- {
- mProgressControls.UpdateProgress(mParentWindow);
- }
-
- internal void OnGUI()
- {
- DoActionsToolbar(mProgressControls);
-
- DoBranchesArea(
- mBranchesListView,
- mProgressControls.IsOperationRunning());
- }
-
- internal void SetWorkingObjectInfo(WorkingObjectInfo homeInfo)
- {
- lock(mLock)
- {
- mLoadedBranchId = homeInfo.BranchInfo.BranchId;
- }
-
- mBranchesListView.SetLoadedBranchId(mLoadedBranchId);
- }
-
- static void DoBranchesArea(
- BranchesListView branchesListView,
- bool isOperationRunning)
- {
- EditorGUILayout.BeginVertical();
-
- GUI.enabled = !isOperationRunning;
-
- Rect rect = GUILayoutUtility.GetRect(0, 100000, 0, 100000);
-
- branchesListView.OnGUI(rect);
-
- GUI.enabled = true;
-
- EditorGUILayout.EndVertical();
- }
-
- internal void DrawSearchFieldForBranchesTab()
- {
- DrawSearchField.For(
- mSearchField,
- mBranchesListView,
- UnityConstants.SEARCH_FIELD_WIDTH);
- }
-
- internal void OnDisable()
- {
- mSearchField.downOrUpArrowKeyPressed -=
- SearchField_OnDownOrUpArrowKeyPressed;
-
- TreeHeaderSettings.Save(
- mBranchesListView.multiColumnHeader.state,
- UnityConstants.BRANCHES_TABLE_SETTINGS_NAME);
- }
-
- void IRefreshableView.Refresh()
- {
- // VCS-1005209 - There are scenarios where the list of branches need to check for incoming changes.
- // For example, deleting the active branch will automatically switch your workspace to the parent changeset,
- // which might have incoming changes.
- if (mDeveloperNewIncomingChangesUpdater != null)
- mDeveloperNewIncomingChangesUpdater.Update(DateTime.Now);
-
- if (mGluonNewIncomingChangesUpdater != null)
- mGluonNewIncomingChangesUpdater.Update(DateTime.Now);
-
- string query = GetBranchesQuery(mDateFilter);
-
- FillBranches(mWkInfo, query, BranchesSelection.GetSelectedRepObjectInfos(mBranchesListView));
- }
-
- //IQueryRefreshableView
- public void RefreshAndSelect(RepObjectInfo repObj)
- {
- string query = GetBranchesQuery(mDateFilter);
-
- FillBranches(mWkInfo,
- query,
- new List<RepObjectInfo> { repObj });
- }
-
- void FillBranches(WorkspaceInfo wkInfo, string query, List<RepObjectInfo> branchesToSelect)
- {
- if (mIsRefreshing)
- return;
-
- mIsRefreshing = true;
-
- int defaultRow = TableViewOperations.
- GetFirstSelectedRow(mBranchesListView);
-
- ((IProgressControls)mProgressControls).ShowProgress(
- PlasticLocalization.GetString(
- PlasticLocalization.Name.LoadingBranches));
-
- ViewQueryResult queryResult = null;
-
- IThreadWaiter waiter = ThreadWaiter.GetWaiter();
- waiter.Execute(
- /*threadOperationDelegate*/ delegate
- {
- long loadedBranchId = GetLoadedBranchId(wkInfo);
- lock(mLock)
- {
- mLoadedBranchId = loadedBranchId;
- }
-
- queryResult = new ViewQueryResult(
- PlasticGui.Plastic.API.FindQuery(wkInfo, query));
- },
- /*afterOperationDelegate*/ delegate
- {
- try
- {
- if (waiter.Exception != null)
- {
- ExceptionsHandler.DisplayException(waiter.Exception);
- return;
- }
-
- UpdateBranchesList(
- mBranchesListView,
- queryResult,
- mLoadedBranchId);
-
- int branchesCount = GetBranchesCount(queryResult);
-
- if (branchesCount == 0)
- {
- return;
- }
-
- BranchesSelection.SelectBranches(
- mBranchesListView, branchesToSelect, defaultRow);
- }
- finally
- {
- ((IProgressControls)mProgressControls).HideProgress();
- mIsRefreshing = false;
- }
- });
- }
-
- static long GetLoadedBranchId(WorkspaceInfo wkInfo)
- {
- BranchInfo brInfo = PlasticGui.Plastic.API.GetWorkingBranch(wkInfo);
-
- if (brInfo != null)
- return brInfo.BranchId;
-
- return -1;
- }
-
- static void UpdateBranchesList(
- BranchesListView branchesListView,
- ViewQueryResult queryResult,
- long loadedBranchId)
- {
- branchesListView.BuildModel(
- queryResult, loadedBranchId);
-
- branchesListView.Refilter();
-
- branchesListView.Sort();
-
- branchesListView.Reload();
- }
-
- internal static int GetBranchesCount(
- ViewQueryResult queryResult)
- {
- if (queryResult == null)
- return 0;
-
- return queryResult.Count();
- }
-
- internal static string GetBranchesQuery(DateFilter dateFilter)
- {
- if (dateFilter.FilterType == DateFilter.Type.AllTime)
- return QueryConstants.BranchesBeginningQuery;
-
- string whereClause = QueryConstants.GetDateWhereClause(
- dateFilter.GetTimeAgo());
-
- return string.Format("{0} {1}",
- QueryConstants.BranchesBeginningQuery,
- whereClause);
- }
-
- internal void DrawDateFilter()
- {
- GUI.enabled = !mProgressControls.IsOperationRunning();
-
- EditorGUI.BeginChangeCheck();
-
- mDateFilter.FilterType = (DateFilter.Type)
- EditorGUILayout.EnumPopup(
- mDateFilter.FilterType,
- EditorStyles.toolbarDropDown,
- GUILayout.Width(100));
-
- if (EditorGUI.EndChangeCheck())
- {
- EnumPopupSetting<DateFilter.Type>.Save(
- mDateFilter.FilterType,
- UnityConstants.BRANCHES_DATE_FILTER_SETTING_NAME);
-
- ((IRefreshableView)this).Refresh();
- }
-
- GUI.enabled = true;
- }
-
- void SearchField_OnDownOrUpArrowKeyPressed()
- {
- mBranchesListView.SetFocusAndEnsureSelectedItem();
- }
-
- static void DoActionsToolbar(
- ProgressControlsForViews progressControls)
- {
- EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
-
- if (progressControls.IsOperationRunning())
- {
- DrawProgressForViews.ForIndeterminateProgress(
- progressControls.ProgressData);
- }
-
- GUILayout.FlexibleSpace();
-
- EditorGUILayout.EndHorizontal();
- }
-
- void BuildComponents(
- WorkspaceInfo wkInfo,
- IWorkspaceWindow workspaceWindow,
- IViewSwitcher viewSwitcher,
- IMergeViewLauncher mergeViewLauncher,
- IUpdateReport updateReport,
- NewIncomingChangesUpdater developerNewIncomingChangesUpdater,
- EditorWindow parentWindow)
- {
- mSearchField = new SearchField();
- mSearchField.downOrUpArrowKeyPressed += SearchField_OnDownOrUpArrowKeyPressed;
-
- DateFilter.Type dateFilterType =
- EnumPopupSetting<DateFilter.Type>.Load(
- UnityConstants.BRANCHES_DATE_FILTER_SETTING_NAME,
- DateFilter.Type.LastMonth);
- mDateFilter = new DateFilter(dateFilterType);
-
- BranchesListHeaderState headerState =
- BranchesListHeaderState.GetDefault();
-
- TreeHeaderSettings.Load(headerState,
- UnityConstants.BRANCHES_TABLE_SETTINGS_NAME,
- (int)BranchesListColumn.CreationDate, false);
-
- mBranchesListView = new BranchesListView(
- headerState,
- BranchesListHeaderState.GetColumnNames(),
- new BranchesViewMenu(this),
- sizeChangedAction: OnBranchesListViewSizeChanged);
-
- mBranchesListView.Reload();
-
- mBranchOperations = new BranchOperations(
- wkInfo,
- workspaceWindow,
- viewSwitcher,
- mergeViewLauncher,
- this,
- ViewType.BranchesView,
- mProgressControls,
- updateReport,
- new ContinueWithPendingChangesQuestionerBuilder(viewSwitcher, parentWindow),
- developerNewIncomingChangesUpdater);
- }
-
- void OnBranchesListViewSizeChanged()
- {
- if (!mShouldScrollToSelection)
- return;
-
- mShouldScrollToSelection = false;
- TableViewOperations.ScrollToSelection(mBranchesListView);
- }
-
- int IBranchMenuOperations.GetSelectedBranchesCount()
- {
- return BranchesSelection.GetSelectedBranchesCount(mBranchesListView);
- }
-
- void IBranchMenuOperations.CreateBranch()
- {
- RepositorySpec repSpec = BranchesSelection.GetSelectedRepository(mBranchesListView);
- BranchInfo branchInfo = BranchesSelection.GetSelectedBranch(mBranchesListView);
-
- BranchCreationData branchCreationData = CreateBranchDialog.CreateBranchFromLastParentBranchChangeset(
- mParentWindow,
- repSpec,
- branchInfo);
-
- mBranchOperations.CreateBranch(
- branchCreationData,
- RefreshAsset.BeforeLongAssetOperation,
- RefreshAsset.AfterLongAssetOperation);
- }
-
- void IBranchMenuOperations.CreateTopLevelBranch() { }
-
- void IBranchMenuOperations.SwitchToBranch()
- {
- RepositorySpec repSpec = BranchesSelection.GetSelectedRepository(mBranchesListView);
- BranchInfo branchInfo = BranchesSelection.GetSelectedBranch(mBranchesListView);
-
- mBranchOperations.SwitchToBranch(
- repSpec,
- branchInfo,
- RefreshAsset.BeforeLongAssetOperation,
- RefreshAsset.AfterLongAssetOperation);
- }
-
- void IBranchMenuOperations.MergeBranch() { }
-
- void IBranchMenuOperations.CherrypickBranch() { }
-
- void IBranchMenuOperations.MergeToBranch() { }
-
- void IBranchMenuOperations.PullBranch() { }
-
- void IBranchMenuOperations.PullRemoteBranch() { }
-
- void IBranchMenuOperations.SyncWithGit() { }
-
- void IBranchMenuOperations.PushBranch() { }
-
- void IBranchMenuOperations.DiffBranch() { }
-
- void IBranchMenuOperations.DiffWithAnotherBranch() { }
-
- void IBranchMenuOperations.ViewChangesets() { }
-
- void IBranchMenuOperations.RenameBranch()
- {
- RepositorySpec repSpec = BranchesSelection.GetSelectedRepository(mBranchesListView);
- BranchInfo branchInfo = BranchesSelection.GetSelectedBranch(mBranchesListView);
-
- BranchRenameData branchRenameData = RenameBranchDialog.GetBranchRenameData(
- repSpec,
- branchInfo,
- mParentWindow);
-
- mBranchOperations.RenameBranch(branchRenameData);
- }
-
- void IBranchMenuOperations.DeleteBranch()
- {
- RepositorySpec repSpec = BranchesSelection.GetSelectedRepository(mBranchesListView);
- List<RepositorySpec> repositories = BranchesSelection.GetSelectedRepositories(mBranchesListView);
- List<BranchInfo> branchesToDelete = BranchesSelection.GetSelectedBranches(mBranchesListView);
-
- mBranchOperations.DeleteBranch(repositories, branchesToDelete);
- }
-
- void IBranchMenuOperations.CreateCodeReview() { }
-
- void IBranchMenuOperations.ViewPermissions() { }
-
- SearchField mSearchField;
- bool mIsRefreshing;
-
- DateFilter mDateFilter;
- bool mShouldScrollToSelection;
- BranchesListView mBranchesListView;
- BranchOperations mBranchOperations;
-
- long mLoadedBranchId = -1;
- object mLock = new object();
-
- readonly WorkspaceInfo mWkInfo;
- readonly ProgressControlsForViews mProgressControls;
- readonly EditorWindow mParentWindow;
- readonly NewIncomingChangesUpdater mDeveloperNewIncomingChangesUpdater;
- readonly GluonNewIncomingChangesUpdater mGluonNewIncomingChangesUpdater;
- }
- }
|