This commit is contained in:
2026-11-24 15:51:02 +01:00
parent cca4d73e41
commit f4aa17114a
22092 changed files with 5042406 additions and 0 deletions
@@ -0,0 +1,20 @@
using UnityEditor.IMGUI.Controls;
#if UNITY_6000_2_OR_NEWER
using TreeViewItem = UnityEditor.IMGUI.Controls.TreeViewItem<int>;
#endif
namespace Unity.PlasticSCM.Editor.Views.Branches
{
class BranchListViewItem : TreeViewItem
{
internal object ObjectInfo { get; private set; }
internal BranchListViewItem(int id, object objectInfo)
: base(id, 1)
{
ObjectInfo = objectInfo;
displayName = id.ToString();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ebbbce5f7ed39ab45b6f43340727ba5e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,125 @@
using System;
using System.Collections.Generic;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
using PlasticGui;
using Unity.PlasticSCM.Editor.UI;
using Unity.PlasticSCM.Editor.UI.Tree;
namespace Unity.PlasticSCM.Editor.Views.Branches
{
internal enum BranchesListColumn
{
Name,
Comment,
CreatedBy,
CreationDate,
}
[Serializable]
internal class BranchesListHeaderState : MultiColumnHeaderState, ISerializationCallbackReceiver
{
internal static BranchesListHeaderState GetDefault()
{
return new BranchesListHeaderState(BuildColumns());
}
internal static List<string> GetColumnNames()
{
List<string> result = new List<string>();
result.Add(PlasticLocalization.GetString(PlasticLocalization.Name.NameColumn));
result.Add(PlasticLocalization.GetString(PlasticLocalization.Name.CommentColumn));
result.Add(PlasticLocalization.GetString(PlasticLocalization.Name.CreatedByColumn));
result.Add(PlasticLocalization.GetString(PlasticLocalization.Name.CreationDateColumn));
return result;
}
internal static string GetColumnName(BranchesListColumn column)
{
switch (column)
{
case BranchesListColumn.Name:
return PlasticLocalization.GetString(PlasticLocalization.Name.NameColumn);
case BranchesListColumn.Comment:
return PlasticLocalization.GetString(PlasticLocalization.Name.CommentColumn);
case BranchesListColumn.CreatedBy:
return PlasticLocalization.GetString(PlasticLocalization.Name.CreatedByColumn);
case BranchesListColumn.CreationDate:
return PlasticLocalization.GetString(PlasticLocalization.Name.CreationDateColumn);
default:
return null;
}
}
void ISerializationCallbackReceiver.OnAfterDeserialize()
{
if (mHeaderTitles != null)
TreeHeaderColumns.SetTitles(columns, mHeaderTitles);
if (mColumnsAllowedToggleVisibility != null)
TreeHeaderColumns.SetVisibilities(columns, mColumnsAllowedToggleVisibility);
}
void ISerializationCallbackReceiver.OnBeforeSerialize()
{
}
static Column[] BuildColumns()
{
return new Column[]
{
new Column()
{
width = UnityConstants.BranchesColumns.BRANCHES_NAME_WIDTH,
minWidth = UnityConstants.BranchesColumns.BRANCHES_NAME_MIN_WIDTH,
headerContent = new GUIContent(
GetColumnName(BranchesListColumn.Name)),
allowToggleVisibility = false,
sortingArrowAlignment = TextAlignment.Right
},
new Column()
{
width = UnityConstants.BranchesColumns.COMMENT_WIDTH,
minWidth = UnityConstants.BranchesColumns.COMMENT_MIN_WIDTH,
headerContent = new GUIContent(
GetColumnName(BranchesListColumn.Comment)),
sortingArrowAlignment = TextAlignment.Right
},
new Column()
{
width = UnityConstants.BranchesColumns.CREATEDBY_WIDTH,
minWidth = UnityConstants.BranchesColumns.CREATEDBY_MIN_WIDTH,
headerContent = new GUIContent(
GetColumnName(BranchesListColumn.CreatedBy)),
sortingArrowAlignment = TextAlignment.Right
},
new Column()
{
width = UnityConstants.BranchesColumns.CREATION_DATE_WIDTH,
minWidth = UnityConstants.BranchesColumns.CREATION_DATE_MIN_WIDTH,
headerContent = new GUIContent(
GetColumnName(BranchesListColumn.CreationDate)),
sortingArrowAlignment = TextAlignment.Right
},
};
}
BranchesListHeaderState(Column[] columns)
: base(columns)
{
if (mHeaderTitles == null)
mHeaderTitles = TreeHeaderColumns.GetTitles(columns);
if (mColumnsAllowedToggleVisibility == null)
mColumnsAllowedToggleVisibility = TreeHeaderColumns.GetVisibilities(columns);
}
[SerializeField]
string[] mHeaderTitles;
[SerializeField]
bool[] mColumnsAllowedToggleVisibility;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f4a41e458bcb22946bcfa6b165c90288
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,498 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using Codice.CM.Common;
using PlasticGui;
using PlasticGui.WorkspaceWindow.QueryViews;
using PlasticGui.WorkspaceWindow.QueryViews.Branches;
using Unity.PlasticSCM.Editor.UI;
using Unity.PlasticSCM.Editor.UI.Avatar;
using Unity.PlasticSCM.Editor.UI.Tree;
using Time = Codice.Client.Common.Time;
#if UNITY_6000_2_OR_NEWER
using TreeViewItem = UnityEditor.IMGUI.Controls.TreeViewItem<int>;
#endif
namespace Unity.PlasticSCM.Editor.Views.Branches
{
internal class BranchesListView :
PlasticTreeView,
IPlasticTree<BranchTreeNode>
{
internal GenericMenu Menu { get { return mMenu.Menu; } }
internal BranchesListView(
BranchesListHeaderState headerState,
List<string> columnNames,
BranchesViewMenu menu,
IGetRepositorySpec getRepositorySpec,
IGetWorkingObject getWorkingObject,
Func<bool> getIsHiddenBranchesMode,
Action delayedSelectionChangedAction,
Action doubleClickAction,
Action<IEnumerable<object>> afterItemsChangedAction)
{
mColumnNames = columnNames;
mMenu = menu;
mGetRepositorySpec = getRepositorySpec;
mGetWorkingObject = getWorkingObject;
mGetIsHiddenBranchesMode = getIsHiddenBranchesMode;
mDelayedSelectionChangedAction = delayedSelectionChangedAction;
mDoubleClickAction = doubleClickAction;
mAfterItemsChangedAction = afterItemsChangedAction;
multiColumnHeader = new MultiColumnHeader(headerState);
multiColumnHeader.canSort = true;
multiColumnHeader.sortingChanged += SortingChanged;
mDelayedFilterAction = new DelayedActionBySecondsRunner(
DelayedSearchChanged, UnityConstants.SEARCH_DELAYED_INPUT_ACTION_INTERVAL);
mDelayedSelectionRunner = new DelayedActionBySecondsRunner(
DelayedSelectionChanged, UnityConstants.SELECTION_DELAYED_INPUT_ACTION_INTERVAL);
}
protected override void SelectionChanged(IList<int> selectedIds)
{
mDelayedSelectionRunner.Run();
}
protected override IList<TreeViewItem> BuildRows(
TreeViewItem rootItem)
{
if (mQueryResult == null)
{
ClearRows(rootItem, mRows);
return mRows;
}
RegenerateRows(
mListViewItemIds,
mQueryResult.GetObjects(),
rootItem, mRows);
return mRows;
}
protected override void SearchChanged(string newSearch)
{
mDelayedFilterAction.Run();
}
protected override void ContextClicked()
{
mMenu.Popup();
Repaint();
}
public override void OnGUI(Rect rect)
{
base.OnGUI(rect);
if (!HasKeyboardFocus())
return;
Event e = Event.current;
if (e.type != EventType.KeyDown)
return;
bool isProcessed = mMenu.ProcessKeyActionIfNeeded(e);
if (isProcessed)
{
e.Use();
GUIUtility.ExitGUI();
}
}
protected override void RowGUI(RowGUIArgs args)
{
if (args.item is BranchListViewItem)
{
BranchListViewItem branchListViewItem = (BranchListViewItem)args.item;
BranchesListViewItemGUI(
mQueryResult,
rowHeight,
branchListViewItem,
args,
RepObjectInfoView.IsHighlighted(
branchListViewItem.ObjectInfo, mGetWorkingObject.Get()),
mGetIsHiddenBranchesMode(),
Repaint);
return;
}
base.RowGUI(args);
}
protected override void DoubleClickedItem(int id)
{
if (GetSelection().Count != 1)
return;
mDoubleClickAction();
}
internal void Refilter()
{
if (mQueryResult == null)
return;
Filter filter = new Filter(searchString);
mQueryResult.ApplyFilter(filter, mColumnNames);
}
internal void Sort()
{
if (mQueryResult == null)
return;
int sortedColumnIdx = multiColumnHeader.state.sortedColumnIndex;
bool sortAscending = multiColumnHeader.IsSortedAscending(sortedColumnIdx);
mQueryResult.Sort(
mColumnNames[sortedColumnIdx],
sortAscending);
}
internal List<RepositorySpec> GetSelectedRepositories()
{
List<RepositorySpec> result = new List<RepositorySpec>();
IList<int> selectedIds = GetSelection();
if (selectedIds.Count == 0)
return result;
foreach (KeyValuePair<object, int> item
in mListViewItemIds.GetInfoItems())
{
if (!selectedIds.Contains(item.Value))
continue;
RepositorySpec repSpec =
mQueryResult.GetRepositorySpec(item.Key);
result.Add(repSpec);
}
return result;
}
internal List<RepObjectInfo> GetSelectedRepObjectInfos()
{
List<RepObjectInfo> result = new List<RepObjectInfo>();
IList<int> selectedIds = GetSelection();
if (selectedIds.Count == 0)
return result;
foreach (KeyValuePair<object, int> item
in mListViewItemIds.GetInfoItems())
{
if (!selectedIds.Contains(item.Value))
continue;
RepObjectInfo repObjectInfo =
mQueryResult.GetRepObjectInfo(item.Key);
result.Add(repObjectInfo);
}
return result;
}
internal List<object> GetSelectedVisibleItems()
{
List<object> result = new List<object>();
IList<int> selectedIds = GetSelection();
if (selectedIds.Count == 0)
return result;
foreach (TreeViewItem row in mRows)
{
if (!selectedIds.Contains(row.id))
continue;
result.Add(((BranchListViewItem)row).ObjectInfo);
}
return result;
}
internal void SelectRepObjectInfos(
List<RepObjectInfo> repObjectsToSelect)
{
List<int> idsToSelect = new List<int>();
foreach (RepObjectInfo repObjectInfo in repObjectsToSelect)
{
int repObjectInfoId = GetTreeIdForItem(repObjectInfo);
if (repObjectInfoId == -1)
continue;
idsToSelect.Add(repObjectInfoId);
}
TableViewOperations.SetSelectionAndScroll(this, idsToSelect);
}
void IPlasticTree<BranchTreeNode>.FillItemsAndSelectRows(
IPlasticTree treeModel,
List<IPlasticTreeNode> itemsToSelect,
Filter currentFilter)
{
mListViewItemIds.Clear();
List<RepObjectInfo> branchesToSelect = BranchesSelection.GetBranchesToSelect(
this, itemsToSelect);
int defaultRow = TableViewOperations.GetFirstSelectedRow(this);
mQueryResult = BuildViewQueryResult(
EnumQueryObjectType.Branch, treeModel, mGetRepositorySpec.Get());
UpdateResults();
BranchesSelection.SelectBranches(this, branchesToSelect, defaultRow);
}
void DelayedSearchChanged()
{
UpdateResults();
TableViewOperations.ScrollToSelection(this);
}
void UpdateResults()
{
Refilter();
Sort();
mAfterItemsChangedAction(mQueryResult.GetObjects());
Reload();
}
void DelayedSelectionChanged()
{
if (!HasSelection())
return;
mDelayedSelectionChangedAction();
}
void SortingChanged(MultiColumnHeader multiColumnHeader)
{
Sort();
Reload();
}
int GetTreeIdForItem(RepObjectInfo repObjectInfo)
{
foreach (KeyValuePair<object, int> item in mListViewItemIds.GetInfoItems())
{
RepObjectInfo currentRepObjectInfo =
mQueryResult.GetRepObjectInfo(item.Key);
if (!currentRepObjectInfo.Equals(repObjectInfo))
continue;
if (!currentRepObjectInfo.GUID.Equals(repObjectInfo.GUID))
continue;
return item.Value;
}
return -1;
}
static void RegenerateRows(
ListViewItemIds<object> listViewItemIds,
List<object> objectInfos,
TreeViewItem rootItem,
List<TreeViewItem> rows)
{
ClearRows(rootItem, rows);
if (objectInfos.Count == 0)
return;
foreach (object objectInfo in objectInfos)
{
int objectId;
if (!listViewItemIds.TryGetInfoItemId(objectInfo, out objectId))
objectId = listViewItemIds.AddInfoItem(objectInfo);
BranchListViewItem branchListViewItem =
new BranchListViewItem(objectId, objectInfo);
rootItem.AddChild(branchListViewItem);
rows.Add(branchListViewItem);
}
}
static void ClearRows(
TreeViewItem rootItem,
List<TreeViewItem> rows)
{
if (rootItem.hasChildren)
rootItem.children.Clear();
rows.Clear();
}
static void BranchesListViewItemGUI(
ViewQueryResult queryResult,
float rowHeight,
BranchListViewItem item,
RowGUIArgs args,
bool isBoldText,
bool isHiddenBranchesMode,
Action avatarLoadedAction)
{
for (int visibleColumnIdx = 0; visibleColumnIdx < args.GetNumVisibleColumns(); visibleColumnIdx++)
{
Rect cellRect = args.GetCellRect(visibleColumnIdx);
if (visibleColumnIdx == 0)
{
cellRect.x += UnityConstants.FIRST_COLUMN_WITHOUT_ICON_INDENT;
cellRect.width -= UnityConstants.FIRST_COLUMN_WITHOUT_ICON_INDENT;
}
BranchesListColumn column =
(BranchesListColumn)args.GetColumn(visibleColumnIdx);
BranchesListViewItemCellGUI(
cellRect,
rowHeight,
queryResult,
item,
column,
avatarLoadedAction,
isHiddenBranchesMode,
args.selected,
args.focused,
isBoldText);
}
}
static void BranchesListViewItemCellGUI(
Rect rect,
float rowHeight,
ViewQueryResult queryResult,
BranchListViewItem item,
BranchesListColumn column,
Action avatarLoadedAction,
bool isHiddenBranchesMode,
bool isSelected,
bool isFocused,
bool isBoldText)
{
RepObjectInfo repObjectInfo = queryResult.GetRepObjectInfo(item.ObjectInfo);
string columnText = RepObjectInfoView.GetColumnText(
queryResult.GetRepositorySpec(item.ObjectInfo),
repObjectInfo,
BranchesListHeaderState.GetColumnName(column));
if (column == BranchesListColumn.Name)
{
DrawTreeViewItem.ForItemCell(
rect,
rowHeight,
-1,
isHiddenBranchesMode ?
Images.GetHideIcon() :
Images.GetBranchIcon(),
null,
null,
columnText,
isSelected,
isFocused,
isBoldText,
false,
false,
DrawTreeViewItem.TextTrimming.Path);
return;
}
if (column == BranchesListColumn.CreatedBy)
{
DrawTreeViewItem.ForItemCell(
rect,
rowHeight,
-1,
GetAvatar.ForEmail(columnText, avatarLoadedAction),
null,
null,
columnText,
isSelected,
isFocused,
isBoldText,
false);
return;
}
if (column == BranchesListColumn.CreationDate)
{
DrawTreeViewItem.ForLabel(
rect,
new GUIContent(
Time.GetLongTimeAgoString(repObjectInfo.LocalTimeStamp),
columnText),
isSelected,
isFocused,
isBoldText);
return;
}
DrawTreeViewItem.ForLabel(
rect,
columnText,
isSelected,
isFocused,
isBoldText);
}
static ViewQueryResult BuildViewQueryResult(
EnumQueryObjectType objectType, IPlasticTree treeModel, RepositorySpec repositorySpec)
{
IList<object> resultObjects = new List<object>();
foreach (BranchTreeNode node in treeModel.GetNodes())
{
resultObjects.Add(node.BranchInfo);
}
return new ViewQueryResult(objectType, resultObjects, repositorySpec);
}
ListViewItemIds<object> mListViewItemIds = new ListViewItemIds<object>();
ViewQueryResult mQueryResult;
readonly DelayedActionBySecondsRunner mDelayedFilterAction;
readonly DelayedActionBySecondsRunner mDelayedSelectionRunner;
readonly Action<IEnumerable<object>> mAfterItemsChangedAction;
readonly Func<bool> mGetIsHiddenBranchesMode;
readonly Action mDelayedSelectionChangedAction;
readonly IGetWorkingObject mGetWorkingObject;
readonly IGetRepositorySpec mGetRepositorySpec;
readonly Action mDoubleClickAction;
readonly BranchesViewMenu mMenu;
readonly List<string> mColumnNames;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1b909cb14b9a08c45b5d03f0b61feecb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,97 @@
using System.Collections.Generic;
using System.Linq;
using Codice.CM.Common;
using PlasticGui;
using PlasticGui.WorkspaceWindow.QueryViews.Branches;
using Unity.PlasticSCM.Editor.UI.Tree;
namespace Unity.PlasticSCM.Editor.Views.Branches
{
internal static class BranchesSelection
{
internal static void SelectBranches(
BranchesListView listView,
List<RepObjectInfo> branchesToSelect,
int defaultRow)
{
if (branchesToSelect == null || branchesToSelect.Count == 0)
{
TableViewOperations.SelectFirstRow(listView);
return;
}
listView.SelectRepObjectInfos(branchesToSelect);
if (listView.HasSelection())
return;
TableViewOperations.SelectDefaultRow(listView, defaultRow);
if (listView.HasSelection())
return;
TableViewOperations.SelectFirstRow(listView);
}
internal static List<RepObjectInfo> GetSelectedRepObjectInfos(
BranchesListView listView)
{
return listView.GetSelectedRepObjectInfos();
}
internal static int GetSelectedVisibleBranchesCount(
BranchesListView listView)
{
return listView.GetSelectedVisibleItems().Count;
}
internal static BranchInfo GetSelectedBranch(
BranchesListView listView)
{
List<RepObjectInfo> selectedRepObjectsInfos = listView.GetSelectedRepObjectInfos();
if (selectedRepObjectsInfos.Count == 0)
return null;
return (BranchInfo)selectedRepObjectsInfos[0];
}
internal static List<BranchInfo> GetSelectedBranches(
BranchesListView listView)
{
return listView.GetSelectedRepObjectInfos().Cast<BranchInfo>().ToList();
}
internal static RepositorySpec GetSelectedRepository(
BranchesListView listView)
{
List<RepositorySpec> selectedRepositories = listView.GetSelectedRepositories();
if (selectedRepositories.Count == 0)
return null;
return selectedRepositories[0];
}
internal static List<RepositorySpec> GetSelectedRepositories(
BranchesListView listView)
{
return listView.GetSelectedRepositories();
}
internal static List<RepObjectInfo> GetBranchesToSelect(
BranchesListView listView, List<IPlasticTreeNode> itemsToSelect)
{
if (itemsToSelect == null || itemsToSelect.Count == 0)
return GetSelectedRepObjectInfos(listView);
List<RepObjectInfo> result = new List<RepObjectInfo>();
foreach (BranchTreeNode node in itemsToSelect)
result.Add(node.BranchInfo);
return result;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 73306fe71bf092d4495ff28ee02b766b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,629 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
using Codice.Client.Common.EventTracking;
using Codice.Client.Common.Threading;
using Codice.CM.Common;
using Codice.CM.Common.Mount;
using GluonGui;
using PlasticGui;
using PlasticGui.WorkspaceWindow;
using PlasticGui.WorkspaceWindow.MergeRequest;
using PlasticGui.WorkspaceWindow.QueryViews;
using PlasticGui.WorkspaceWindow.QueryViews.Branches;
using PlasticGui.WorkspaceWindow.Update;
using Unity.PlasticSCM.Editor.AssetUtils;
using Unity.PlasticSCM.Editor.AssetUtils.Processor;
using Unity.PlasticSCM.Editor.AssetsOverlays.Cache;
using Unity.PlasticSCM.Editor.Inspector.Properties;
using Unity.PlasticSCM.Editor.Tool;
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.Merge;
using GluonIncomingChangesUpdater = PlasticGui.Gluon.WorkspaceWindow.IncomingChangesUpdater;
using IGluonUpdateReport = PlasticGui.Gluon.IUpdateReport;
#if !UNITY_6000_3_OR_NEWER
using SplitterGUILayout = Unity.PlasticSCM.Editor.UnityInternals.UnityEditor.SplitterGUILayout;
using SplitterState = Unity.PlasticSCM.Editor.UnityInternals.UnityEditor.SplitterState;
#endif
namespace Unity.PlasticSCM.Editor.Views.Branches
{
internal partial class BranchesTab :
IRefreshableView,
IQueryRefreshableView,
IBranchMenuOperations,
ILaunchCodeReviewWindow,
IGetQueryText,
IGetFilter,
FillBranchesView.IShowContentView,
FillBranchesView.IShowHiddenBranchesButton
{
internal string EmptyStateMessage { get { return mEmptyStatePanel.Text; } }
internal bool ShowHiddenBranchesForTesting { set { mShowHiddenBranches = value; } }
internal DateFilter DateFilterForTesting { set { mDateFilter = value; } }
internal IBranchMenuOperations Operations { get { return this; } }
internal BranchesListView Table { get { return mBranchesListView; } }
internal bool IsVisible { get; set; } = true; // we need to initialize it to true for the OnDelayedSelectionChanged event to be executed on tests
internal BranchesTab(
WorkspaceInfo wkInfo,
ViewHost viewHost,
WorkspaceWindow workspaceWindow,
BranchInfo branchToSelect,
IViewSwitcher viewSwitcher,
IMergeViewLauncher mergeViewLauncher,
IUpdateReport updateReport,
IGluonUpdateReport gluonUpdateReport,
IShelvedChangesUpdater shelvedChangesUpdater,
IAssetStatusCache assetStatusCache,
ISaveAssets saveAssets,
LaunchTool.IShowDownloadPlasticExeWindow showDownloadPlasticExeWindow,
LaunchTool.IProcessExecutor processExecutor,
WorkspaceOperationsMonitor workspaceOperationsMonitor,
IPendingChangesUpdater pendingChangesUpdater,
IncomingChangesUpdater developerIncomingChangesUpdater,
GluonIncomingChangesUpdater gluonIncomingChangesUpdater,
EditorWindow parentWindow,
bool isGluonMode,
bool showHiddenBranches)
{
mWkInfo = wkInfo;
mViewHost = viewHost;
mWorkspaceWindow = workspaceWindow;
mGluonUpdateReport = gluonUpdateReport;
mShelvedChangesUpdater = shelvedChangesUpdater;
mAssetStatusCache = assetStatusCache;
mSaveAssets = saveAssets;
mShowDownloadPlasticExeWindow = showDownloadPlasticExeWindow;
mProcessExecutor = processExecutor;
mWorkspaceOperationsMonitor = workspaceOperationsMonitor;
mPendingChangesUpdater = pendingChangesUpdater;
mDeveloperIncomingChangesUpdater = developerIncomingChangesUpdater;
mGluonIncomingChangesUpdater = gluonIncomingChangesUpdater;
mParentWindow = parentWindow;
mIsGluonMode = isGluonMode;
mShowHiddenBranches = showHiddenBranches;
mProgressControls = new ProgressControlsForViews();
mShelvePendingChangesQuestionerBuilder =
new ShelvePendingChangesQuestionerBuilder(parentWindow);
mEnableSwitchAndShelveFeatureDialog = new EnableSwitchAndShelveFeature(
PlasticGui.Plastic.API.GetRepositorySpec(mWkInfo),
mParentWindow);
mEmptyStatePanel = new EmptyStatePanel(parentWindow.Repaint);
mFillBranchesView = new FillBranchesView(
wkInfo,
null,
null,
this,
this,
this,
this);
BuildComponents(mFillBranchesView);
mBranchOperations = new BranchOperations(
wkInfo,
workspaceWindow,
mergeViewLauncher,
this,
ViewType.BranchesView,
mProgressControls,
updateReport,
new ApplyShelveReport(parentWindow),
new ContinueWithPendingChangesQuestionerBuilder(viewSwitcher, parentWindow),
mShelvePendingChangesQuestionerBuilder,
new ApplyShelveWithConflictsQuestionerBuilder(),
pendingChangesUpdater,
developerIncomingChangesUpdater,
shelvedChangesUpdater,
mEnableSwitchAndShelveFeatureDialog);
RefreshAndSelect(branchToSelect);
}
internal void OnEnable()
{
mSearchField.downOrUpArrowKeyPressed +=
SearchField_OnDownOrUpArrowKeyPressed;
}
internal void OnDisable()
{
mSearchField.downOrUpArrowKeyPressed -=
SearchField_OnDownOrUpArrowKeyPressed;
TreeHeaderSettings.Save(
mBranchesListView.multiColumnHeader.state,
UnityConstants.BRANCHES_TABLE_SETTINGS_NAME);
}
internal void Update()
{
mProgressControls.UpdateProgress(mParentWindow);
}
internal SerializableBranchesTabState GetSerializableState()
{
return new SerializableBranchesTabState(
BranchesSelection.GetSelectedBranch(mBranchesListView),
mShowHiddenBranches);
}
internal void OnGUI()
{
EditorGUILayout.BeginVertical();
DoActionsToolbar(
mProgressControls,
mDateFilter,
ref mShowHiddenBranches,
mSearchField,
mBranchesListView,
this);
Rect viewRect = OverlayProgress.CaptureViewRectangle();
GUI.enabled = !mProgressControls.IsOperationRunning();
Rect rect = GUILayoutUtility.GetRect(0, 100000, 0, 100000);
mBranchesListView.OnGUI(rect);
if (Event.current.type == EventType.Layout)
mShouldShowEmptyState = !mEmptyStatePanel.IsEmpty();
if (mShouldShowEmptyState)
mEmptyStatePanel.OnGUI(rect);
GUI.enabled = true;
EditorGUILayout.EndVertical();
if (mProgressControls.IsOperationRunning())
{
OverlayProgress.DoOverlayProgress(
viewRect,
mProgressControls.ProgressData.ProgressPercent,
mProgressControls.ProgressData.ProgressMessage);
}
}
internal void SetWorkingObjectInfo(BranchInfo branchInfo)
{
mFillBranchesView.UpdateWorkingObject(branchInfo, mWkInfo);
}
internal void SetLaunchToolForTesting(
LaunchTool.IShowDownloadPlasticExeWindow showDownloadPlasticExeWindow,
LaunchTool.IProcessExecutor processExecutor)
{
mShowDownloadPlasticExeWindow = showDownloadPlasticExeWindow;
mProcessExecutor = processExecutor;
}
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 (mDeveloperIncomingChangesUpdater != null)
mDeveloperIncomingChangesUpdater.Update(DateTime.Now);
if (mGluonIncomingChangesUpdater != null)
mGluonIncomingChangesUpdater.Update(DateTime.Now);
RefreshAndSelect(null);
}
//IQueryRefreshableView
public void RefreshAndSelect(RepObjectInfo objectToSelect)
{
List<IPlasticTreeNode> branchesToSelect = objectToSelect == null ?
null : new List<IPlasticTreeNode> { new BranchTreeNode(
null, (BranchInfo)objectToSelect, null) };
if (branchesToSelect == null && EditorWindow.focusedWindow == mParentWindow)
Selection.activeObject = null;
mFillBranchesView.FillView(
mBranchesListView,
mProgressControls,
null,
null,
null,
branchesToSelect,
FillBranchesView.ViewMode.List,
mShowHiddenBranches);
}
BranchInfo IBranchMenuOperations.GetSelectedBranch()
{
return BranchesSelection.GetSelectedBranch(mBranchesListView);
}
int IBranchMenuOperations.GetSelectedBranchesCount()
{
return BranchesSelection.GetSelectedVisibleBranchesCount(mBranchesListView);
}
bool IBranchMenuOperations.AreHiddenBranchesShown()
{
return mShowHiddenBranches;
}
void IBranchMenuOperations.CreateBranch()
{
CreateBranch();
}
void IBranchMenuOperations.CreateTopLevelBranch() { }
void IBranchMenuOperations.SwitchToBranch()
{
SwitchToBranchForMode();
}
void IBranchMenuOperations.MergeBranch()
{
mBranchOperations.MergeBranch(
BranchesSelection.GetSelectedRepository(mBranchesListView),
BranchesSelection.GetSelectedBranch(mBranchesListView));
}
void IBranchMenuOperations.CherrypickBranch() { }
void IBranchMenuOperations.MergeToBranch() { }
void IBranchMenuOperations.PullBranch() { }
void IBranchMenuOperations.PullRemoteBranch() { }
void IBranchMenuOperations.SyncWithGit() { }
void IBranchMenuOperations.PushBranch() { }
void IBranchMenuOperations.DiffBranch()
{
LaunchDiffOperations.DiffBranch(
mShowDownloadPlasticExeWindow,
mProcessExecutor,
BranchesSelection.GetSelectedRepository(mBranchesListView),
BranchesSelection.GetSelectedBranch(mBranchesListView),
mIsGluonMode);
}
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.HideUnhideBranch()
{
if (mShowHiddenBranches)
{
mBranchOperations.UnhideBranch(
BranchesSelection.GetSelectedRepositories(mBranchesListView),
BranchesSelection.GetSelectedBranches(mBranchesListView));
return;
}
mBranchOperations.HideBranch(
BranchesSelection.GetSelectedRepositories(mBranchesListView),
BranchesSelection.GetSelectedBranches(mBranchesListView));
}
void IBranchMenuOperations.DeleteBranch()
{
var branchesToDelete = BranchesSelection.GetSelectedBranches(mBranchesListView);
if (!DeleteBranchDialog.ConfirmDelete(mParentWindow, branchesToDelete))
return;
mBranchOperations.DeleteBranch(
BranchesSelection.GetSelectedRepositories(mBranchesListView),
branchesToDelete,
DeleteBranchOptions.IncludeChangesets,
!mShowHiddenBranches);
}
void IBranchMenuOperations.CreateCodeReview()
{
RepositorySpec repSpec = BranchesSelection.GetSelectedRepository(mBranchesListView);
BranchInfo branchInfo = BranchesSelection.GetSelectedBranch(mBranchesListView);
NewCodeReviewBehavior choice = SelectNewCodeReviewBehavior.For(repSpec.Server);
switch (choice)
{
case NewCodeReviewBehavior.CreateAndOpenInDesktop:
mBranchOperations.CreateReview(repSpec, branchInfo, this);
break;
case NewCodeReviewBehavior.RequestFromUnityCloud:
OpenRequestReviewPage.ForBranch(repSpec, branchInfo.BranchId);
break;
case NewCodeReviewBehavior.Ask:
default:
break;
}
}
void ILaunchCodeReviewWindow.Show(
WorkspaceInfo wkInfo,
RepositorySpec repSpec,
ReviewInfo reviewInfo,
RepObjectInfo repObjectInfo,
bool bShowReviewChangesTab)
{
LaunchTool.OpenCodeReview(
mShowDownloadPlasticExeWindow,
mProcessExecutor,
repSpec,
reviewInfo.Id,
mIsGluonMode);
}
void IBranchMenuOperations.CreateMergeRequest() { }
void IBranchMenuOperations.ViewPermissions() { }
string IGetQueryText.Get()
{
return QueryConstants.BuildBranchesQuery(
mDateFilter.GetLayoutFilter(), mShowHiddenBranches);
}
Filter IGetFilter.Get()
{
return new Filter(mBranchesListView.searchString);
}
void IGetFilter.Clear()
{
// Not used by the Plugin, needed for the Reset filters button
}
void FillBranchesView.IShowContentView.ShowContentPanel()
{
mEmptyStatePanel.UpdateContent(string.Empty);
}
void FillBranchesView.IShowContentView.ShowEmptyStatePanel(
string explanationText, bool showResetFilterButton)
{
mEmptyStatePanel.UpdateContent(explanationText);
}
bool FillBranchesView.IShowHiddenBranchesButton.IsChecked
{
get { return mShowHiddenBranches; }
set { mShowHiddenBranches = value; }
}
void SearchField_OnDownOrUpArrowKeyPressed()
{
mBranchesListView.SetFocusAndEnsureSelectedItem();
}
void OnDelayedSelectionChanged()
{
if (EditorWindow.focusedWindow != mParentWindow)
return;
if (!IsVisible)
return;
List<RepObjectInfo> selectedBranches = BranchesSelection.
GetSelectedRepObjectInfos(mBranchesListView);
if (selectedBranches.Count != 1)
return;
RepositorySpec repSpec = BranchesSelection.GetSelectedRepository(mBranchesListView);
MountPointWithPath mountPoint = MountPointWithPath.BuildWorkspaceRootMountPoint(repSpec);
RepObjectInfo cachedBranch = selectedBranches[0];
BranchInfo resolvedBranch = null;
IThreadWaiter waiter = ThreadWaiter.GetWaiter(10);
waiter.Execute(
threadOperationDelegate: delegate
{
resolvedBranch = PlasticGui.Plastic.API.GetBranchInfo(
repSpec, cachedBranch.GUID);
},
afterOperationDelegate: delegate
{
if (waiter.Exception != null)
{
ExceptionsHandler.DisplayException(waiter.Exception);
return;
}
List<RepObjectInfo> selectedBranches = BranchesSelection.
GetSelectedRepObjectInfos(mBranchesListView);
if (selectedBranches.Count != 1 || !selectedBranches[0].Equals(cachedBranch))
return;
SelectedRepObjectInfoData.SetActiveObject(resolvedBranch, repSpec, mountPoint);
});
}
static void DoActionsToolbar(
ProgressControlsForViews progressControls,
DateFilter dateFilter,
ref bool showHiddenBranchesButton,
SearchField searchField,
BranchesListView branchesListView,
IRefreshableView view)
{
EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
if (GUILayout.Button(
new GUIContent(Images.GetRefreshIcon(),
PlasticLocalization.Name.RefreshButton.GetString()),
UnityStyles.ToolbarButtonLeft,
GUILayout.Width(UnityConstants.TOOLBAR_ICON_BUTTON_WIDTH)))
{
view.Refresh();
}
DrawDateFilter(progressControls, dateFilter, view);
GUILayout.FlexibleSpace();
DrawShowHiddenBranchesButton(
progressControls, ref showHiddenBranchesButton, branchesListView, view);
GUILayout.Space(2);
DrawSearchField.For(
searchField,
branchesListView,
UnityConstants.SEARCH_FIELD_WIDTH);
EditorGUILayout.EndHorizontal();
}
static void DrawDateFilter(
ProgressControlsForViews progressControls,
DateFilter dateFilter,
IRefreshableView view)
{
GUI.enabled = !progressControls.IsOperationRunning();
EditorGUI.BeginChangeCheck();
dateFilter.FilterType = (DateFilter.Type)
EditorGUILayout.EnumPopup(
dateFilter.FilterType,
EditorStyles.toolbarDropDown,
GUILayout.Width(UnityConstants.TOOLBAR_DATE_FILTER_COMBO_WIDTH));
if (EditorGUI.EndChangeCheck())
{
EnumPopupSetting<DateFilter.Type>.Save(
dateFilter.FilterType,
UnityConstants.BRANCHES_DATE_FILTER_SETTING_NAME);
view.Refresh();
}
GUI.enabled = true;
}
static void DrawShowHiddenBranchesButton(
ProgressControlsForViews progressControls,
ref bool showHiddenBranches,
BranchesListView branchesListView,
IRefreshableView view)
{
GUI.enabled = !progressControls.IsOperationRunning();
EditorGUI.BeginChangeCheck();
showHiddenBranches = GUILayout.Toggle(
showHiddenBranches,
new GUIContent(
showHiddenBranches ?
Images.GetUnhideIcon() :
Images.GetHideIcon(),
showHiddenBranches ?
PlasticLocalization.Name.DontShowHiddenBranchesTooltip.GetString() :
PlasticLocalization.Name.ShowHiddenBranchesTooltip.GetString()),
EditorStyles.toolbarButton,
GUILayout.Width(UnityConstants.TOOLBAR_ICON_BUTTON_WIDTH));
if (EditorGUI.EndChangeCheck())
{
TrackFeatureUseEvent.For(
BranchesSelection.GetSelectedRepository(branchesListView),
TrackFeatureUseEvent.Features.Branches.ToggleShowHiddenBranches);
view.Refresh();
}
GUI.enabled = true;
}
void BuildComponents(FillBranchesView fillBranchesView)
{
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, mGluonIncomingChangesUpdater != null),
fillBranchesView,
fillBranchesView,
() => mShowHiddenBranches,
delayedSelectionChangedAction: OnDelayedSelectionChanged,
doubleClickAction: ((IBranchMenuOperations)this).DiffBranch,
afterItemsChangedAction: fillBranchesView.ShowContentOrEmptyState);
mBranchesListView.Reload();
}
bool mShouldShowEmptyState;
bool mShowHiddenBranches;
DateFilter mDateFilter;
SearchField mSearchField;
BranchesListView mBranchesListView;
LaunchTool.IProcessExecutor mProcessExecutor;
LaunchTool.IShowDownloadPlasticExeWindow mShowDownloadPlasticExeWindow;
readonly BranchOperations mBranchOperations;
readonly FillBranchesView mFillBranchesView;
readonly EmptyStatePanel mEmptyStatePanel;
readonly SwitchAndShelve.IEnableSwitchAndShelveFeatureDialog mEnableSwitchAndShelveFeatureDialog;
readonly IShelvePendingChangesQuestionerBuilder mShelvePendingChangesQuestionerBuilder;
readonly ProgressControlsForViews mProgressControls;
readonly bool mIsGluonMode;
readonly EditorWindow mParentWindow;
readonly IPendingChangesUpdater mPendingChangesUpdater;
readonly GluonIncomingChangesUpdater mGluonIncomingChangesUpdater;
readonly IncomingChangesUpdater mDeveloperIncomingChangesUpdater;
readonly WorkspaceOperationsMonitor mWorkspaceOperationsMonitor;
readonly ISaveAssets mSaveAssets;
readonly IAssetStatusCache mAssetStatusCache;
readonly IShelvedChangesUpdater mShelvedChangesUpdater;
readonly IGluonUpdateReport mGluonUpdateReport;
readonly WorkspaceWindow mWorkspaceWindow;
readonly ViewHost mViewHost;
readonly WorkspaceInfo mWkInfo;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2350e7d7f6d79024da24dea8f15a6881
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,174 @@
using Codice.Client.Common.Threading;
using Codice.CM.Common;
using Codice.LogWrapper;
using GluonGui.WorkspaceWindow.Views.WorkspaceExplorer.Explorer;
using PlasticGui.WorkspaceWindow.QueryViews.Branches;
using Unity.PlasticSCM.Editor.AssetUtils;
using Unity.PlasticSCM.Editor.UI;
using Unity.PlasticSCM.Editor.Views.Branches.Dialogs;
namespace Unity.PlasticSCM.Editor.Views.Branches
{
internal partial class BranchesTab
{
void SwitchToBranchForMode()
{
bool isCancelled;
mSaveAssets.UnderWorkspaceWithConfirmation(
mWkInfo.ClientPath, mWorkspaceOperationsMonitor,
canContinueWithDirtyScenes: false,
out isCancelled);
if (isCancelled)
return;
if (mIsGluonMode)
{
SwitchToBranchForGluon();
return;
}
SwitchToBranchForDeveloper();
}
void SwitchToBranchForDeveloper()
{
RepositorySpec repSpec = BranchesSelection.GetSelectedRepository(mBranchesListView);
BranchInfo branchInfo = BranchesSelection.GetSelectedBranch(mBranchesListView);
mBranchOperations.SwitchToBranch(
repSpec,
branchInfo,
RefreshAsset.BeforeLongAssetOperation,
items => RefreshAsset.AfterLongAssetOperation(
mAssetStatusCache,
ProjectPackages.ShouldBeResolvedFromUpdateReport(mWkInfo, items)));
}
void SwitchToBranchForGluon()
{
BranchInfo branchInfo = BranchesSelection.GetSelectedBranch(mBranchesListView);
new SwitchToUIOperation().SwitchToBranch(
mWkInfo,
branchInfo,
mViewHost,
mPendingChangesUpdater,
mGluonIncomingChangesUpdater,
new UnityPlasticGuiMessage(),
mProgressControls,
mWorkspaceWindow.GluonProgressOperationHandler,
mGluonUpdateReport,
mWorkspaceWindow,
mShelvePendingChangesQuestionerBuilder,
mShelvedChangesUpdater,
mEnableSwitchAndShelveFeatureDialog,
RefreshAsset.BeforeLongAssetOperation,
items => RefreshAsset.AfterLongAssetOperation(
mAssetStatusCache,
ProjectPackages.ShouldBeResolvedFromPaths(mWkInfo, items)));
}
void CreateBranch()
{
if (BranchesSelection.GetSelectedVisibleBranchesCount(mBranchesListView) > 0)
{
CreateBranchFromSelectedBranch();
return;
}
CreateBranchFromMainOrCurrentBranch();
}
void CreateBranchFromSelectedBranch()
{
RepositorySpec repSpec = BranchesSelection.GetSelectedRepository(mBranchesListView);
BranchInfo branchInfo = BranchesSelection.GetSelectedBranch(mBranchesListView);
BranchCreationData branchCreationData = CreateBranchDialog.CreateBranchFromLastParentBranchChangeset(
mParentWindow, repSpec, branchInfo, null);
CreateBranchForMode(branchCreationData);
}
void CreateBranchFromMainOrCurrentBranch()
{
RepositorySpec repSpec = null;
BranchInfo currentBranchInfo = null;
BranchInfo mainBranchInfo = null;
IThreadWaiter waiter = ThreadWaiter.GetWaiter();
waiter.Execute(
/*threadOperationDelegate*/ delegate
{
repSpec = PlasticGui.Plastic.API.GetRepositorySpec(mWkInfo);
currentBranchInfo = PlasticGui.Plastic.API.GetWorkingBranch(mWkInfo);
mainBranchInfo = PlasticGui.Plastic.API.GetMainBranch(mWkInfo);
},
/*afterOperationDelegate*/ delegate
{
if (waiter.Exception != null)
{
ExceptionsHandler.LogException(typeof(BranchesTab).Name, waiter.Exception);
return;
}
if (repSpec == null || currentBranchInfo == null || mainBranchInfo == null)
{
mLog.DebugFormat("Error obtaining the base information for the branch creation");
return;
}
BranchCreationData branchCreationData = CreateBranchDialog.CreateBranchFromMainOrCurrentBranch(
mParentWindow, repSpec, mainBranchInfo, currentBranchInfo, null);
CreateBranchForMode(branchCreationData);
});
}
void CreateBranchForMode(BranchCreationData branchCreationData)
{
if (mIsGluonMode)
{
CreateBranchForGluon(branchCreationData);
return;
}
CreateBranchForDeveloper(branchCreationData);
}
void CreateBranchForDeveloper(BranchCreationData branchCreationData)
{
mBranchOperations.CreateBranch(
branchCreationData,
RefreshAsset.BeforeLongAssetOperation,
items => RefreshAsset.AfterLongAssetOperation(
mAssetStatusCache,
ProjectPackages.ShouldBeResolvedFromUpdateReport(mWkInfo, items)));
}
void CreateBranchForGluon(BranchCreationData branchCreationData)
{
CreateBranchOperation.CreateBranch(
mWkInfo,
branchCreationData,
mViewHost,
mPendingChangesUpdater,
mGluonIncomingChangesUpdater,
new UnityPlasticGuiMessage(),
mProgressControls,
mWorkspaceWindow.GluonProgressOperationHandler,
mGluonUpdateReport,
mWorkspaceWindow,
mShelvePendingChangesQuestionerBuilder,
mShelvedChangesUpdater,
mEnableSwitchAndShelveFeatureDialog,
RefreshAsset.BeforeLongAssetOperation,
items => RefreshAsset.AfterLongAssetOperation(
mAssetStatusCache,
ProjectPackages.ShouldBeResolvedFromPaths(mWkInfo, items)));
}
static readonly ILog mLog = PlasticApp.GetLogger("BranchesTab");
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 732707d2b1ec963458b4ab9ffe539cbe
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,299 @@
using UnityEditor;
using UnityEngine;
using Codice.CM.Common;
using PlasticGui;
using PlasticGui.WorkspaceWindow.QueryViews.Branches;
using Unity.PlasticSCM.Editor.UI;
namespace Unity.PlasticSCM.Editor.Views.Branches
{
internal class BranchesViewMenu
{
internal GenericMenu Menu { get { return mMenu; } }
internal BranchesViewMenu(
IBranchMenuOperations branchMenuOperations,
bool isGluonMode)
{
mBranchMenuOperations = branchMenuOperations;
mIsGluonMode = isGluonMode;
BuildComponents();
}
internal void Popup()
{
mMenu = new GenericMenu();
UpdateMenuItems(mMenu);
mMenu.ShowAsContext();
}
internal bool ProcessKeyActionIfNeeded(Event e)
{
BranchMenuOperations operationToExecute = GetMenuOperations(e);
if (operationToExecute == BranchMenuOperations.None)
return false;
BranchMenuOperations operations =
BranchMenuUpdater.GetAvailableMenuOperations(
mBranchMenuOperations.GetSelectedBranchesCount(),
mIsGluonMode,
false);
if (!operations.HasFlag(operationToExecute))
return false;
ProcessMenuOperation(operationToExecute, mBranchMenuOperations);
return true;
}
void CreateBranchMenuItem_Click()
{
mBranchMenuOperations.CreateBranch();
}
void SwitchToBranchMenuItem_Click()
{
mBranchMenuOperations.SwitchToBranch();
}
void RenameBranchMenuItem_Click()
{
mBranchMenuOperations.RenameBranch();
}
void HideUnhideBranchMenuItem_Click()
{
mBranchMenuOperations.HideUnhideBranch();
}
void DeleteBranchMenuItem_Click()
{
mBranchMenuOperations.DeleteBranch();
}
void MergeBranchMenuItem_Click()
{
mBranchMenuOperations.MergeBranch();
}
void DiffBranchMenuItem_Click()
{
mBranchMenuOperations.DiffBranch();
}
void CreateCodeReviewMenuItem_Click()
{
mBranchMenuOperations.CreateCodeReview();
}
void UpdateMenuItems(GenericMenu menu)
{
BranchMenuOperations operations = BranchMenuUpdater.GetAvailableMenuOperations(
mBranchMenuOperations.GetSelectedBranchesCount(), mIsGluonMode, false);
AddBranchMenuItem(
mCreateBranchMenuItemContent,
menu,
operations,
BranchMenuOperations.CreateBranch,
CreateBranchMenuItem_Click);
AddBranchMenuItem(
mSwitchToBranchMenuItemContent,
menu,
operations,
BranchMenuOperations.SwitchToBranch,
SwitchToBranchMenuItem_Click);
if (!mIsGluonMode)
{
menu.AddSeparator(string.Empty);
AddBranchMenuItem(
mMergeBranchMenuItemContent,
menu,
operations,
BranchMenuOperations.MergeBranch,
MergeBranchMenuItem_Click);
}
menu.AddSeparator(string.Empty);
mDiffBranchMenuItemContent.text = string.Format("{0} {1}",
PlasticLocalization.Name.DiffBranchMenuItem.GetString(GetSelectedBranchName()),
GetPlasticShortcut.ForDiff());
AddBranchMenuItem(
mDiffBranchMenuItemContent,
menu,
operations,
BranchMenuOperations.DiffBranch,
DiffBranchMenuItem_Click);
menu.AddSeparator(string.Empty);
AddBranchMenuItem(
mRenameBranchMenuItemContent,
menu,
operations,
BranchMenuOperations.Rename,
RenameBranchMenuItem_Click);
mHideUnhideBranchMenuItemContent.text = string.Format("{0} {1}",
mBranchMenuOperations.AreHiddenBranchesShown() ?
PlasticLocalization.Name.BranchMenuItemUnhideBranch.GetString() :
PlasticLocalization.Name.BranchMenuItemHideBranch.GetString(),
GetPlasticShortcut.ForHideUnhide());
AddBranchMenuItem(
mHideUnhideBranchMenuItemContent,
menu,
operations,
BranchMenuOperations.HideUnhide,
HideUnhideBranchMenuItem_Click);
AddBranchMenuItem(
mDeleteBranchMenuItemContent,
menu,
operations,
BranchMenuOperations.Delete,
DeleteBranchMenuItem_Click);
menu.AddSeparator(string.Empty);
AddBranchMenuItem(
mCreateCodeReviewMenuItemContent,
menu,
operations,
BranchMenuOperations.CreateCodeReview,
CreateCodeReviewMenuItem_Click);
}
string GetSelectedBranchName()
{
if (mBranchMenuOperations.GetSelectedBranchesCount() == 0)
return string.Empty;
BranchInfo branchInfo = mBranchMenuOperations.GetSelectedBranch();
return GetShorten.BranchNameFromBranch(branchInfo);
}
static void AddBranchMenuItem(
GUIContent menuItemContent,
GenericMenu menu,
BranchMenuOperations operations,
BranchMenuOperations operationsToCheck,
GenericMenu.MenuFunction menuFunction)
{
if (operations.HasFlag(operationsToCheck))
{
menu.AddItem(
menuItemContent,
false,
menuFunction);
return;
}
menu.AddDisabledItem(menuItemContent);
}
static void ProcessMenuOperation(
BranchMenuOperations operationToExecute,
IBranchMenuOperations branchMenuOperations)
{
if (operationToExecute == BranchMenuOperations.Rename)
{
branchMenuOperations.RenameBranch();
return;
}
if (operationToExecute == BranchMenuOperations.Delete)
{
branchMenuOperations.DeleteBranch();
return;
}
if (operationToExecute == BranchMenuOperations.MergeBranch)
{
branchMenuOperations.MergeBranch();
return;
}
if (operationToExecute == BranchMenuOperations.DiffBranch)
{
branchMenuOperations.DiffBranch();
return;
}
if (operationToExecute == BranchMenuOperations.HideUnhide)
{
branchMenuOperations.HideUnhideBranch();
return;
}
}
static BranchMenuOperations GetMenuOperations(Event e)
{
if (Keyboard.IsKeyPressed(e, KeyCode.F2))
return BranchMenuOperations.Rename;
if (Keyboard.IsKeyPressed(e, KeyCode.Delete))
return BranchMenuOperations.Delete;
if (Keyboard.IsControlOrCommandKeyPressed(e) &&
Keyboard.IsKeyPressed(e, KeyCode.M))
return BranchMenuOperations.MergeBranch;
if (Keyboard.IsControlOrCommandKeyPressed(e) &&
Keyboard.IsKeyPressed(e, KeyCode.D))
return BranchMenuOperations.DiffBranch;
if (Keyboard.IsControlOrCommandKeyPressed(e) &&
Keyboard.IsKeyPressed(e, KeyCode.H))
return BranchMenuOperations.HideUnhide;
return BranchMenuOperations.None;
}
void BuildComponents()
{
mCreateBranchMenuItemContent = new GUIContent(
PlasticLocalization.GetString(PlasticLocalization.Name.BranchMenuItemCreateBranch));
mSwitchToBranchMenuItemContent = new GUIContent(
PlasticLocalization.GetString(PlasticLocalization.Name.BranchMenuItemSwitchToBranch));
mMergeBranchMenuItemContent = new GUIContent(string.Format("{0} {1}",
PlasticLocalization.GetString(PlasticLocalization.Name.BranchMenuItemMergeFromBranch),
GetPlasticShortcut.ForMerge()));
mDiffBranchMenuItemContent = new GUIContent();
mRenameBranchMenuItemContent = new GUIContent(string.Format("{0} {1}",
PlasticLocalization.GetString(PlasticLocalization.Name.BranchMenuItemRenameBranch),
GetPlasticShortcut.ForRename()));
mHideUnhideBranchMenuItemContent = new GUIContent();
mDeleteBranchMenuItemContent = new GUIContent(string.Format("{0} {1}",
PlasticLocalization.GetString(PlasticLocalization.Name.BranchMenuItemDeleteBranch),
GetPlasticShortcut.ForDelete()));
mCreateCodeReviewMenuItemContent = new GUIContent(
PlasticLocalization.Name.BranchMenuCreateANewCodeReview.GetString());
}
GenericMenu mMenu;
GUIContent mCreateBranchMenuItemContent;
GUIContent mSwitchToBranchMenuItemContent;
GUIContent mMergeBranchMenuItemContent;
GUIContent mDiffBranchMenuItemContent;
GUIContent mRenameBranchMenuItemContent;
GUIContent mHideUnhideBranchMenuItemContent;
GUIContent mDeleteBranchMenuItemContent;
GUIContent mCreateCodeReviewMenuItemContent;
readonly IBranchMenuOperations mBranchMenuOperations;
readonly bool mIsGluonMode;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a1f5156c89fd104459e8ec0cc3098899
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 16e16045695760047a9bd172458c5d6b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,373 @@
using UnityEditor;
using UnityEngine;
using Codice.Client.Common;
using Codice.CM.Common;
using PlasticGui;
using PlasticGui.WorkspaceWindow;
using PlasticGui.WorkspaceWindow.QueryViews.Branches;
using Unity.PlasticSCM.Editor.UI;
#if !UNITY_6000_3_OR_NEWER
using EditorGUI = Unity.PlasticSCM.Editor.UnityInternals.UnityEditor.EditorGUI;
#endif
namespace Unity.PlasticSCM.Editor.Views.Branches.Dialogs
{
class CreateBranchDialog : PlasticDialog
{
internal BranchInfo SelectedBranchBase { get { return mSelectedBaseBranch; } }
internal string NewBranchName { get { return mNewBranchName; } set { mNewBranchName = value; } }
internal bool AllowToChangeBaseBranch { get { return mAllowToChangeBaseBranch; } }
protected override Rect DefaultRect
{
get
{
var baseRect = base.DefaultRect;
return new Rect(baseRect.x, baseRect.y, 710, baseRect.height);
}
}
protected override string GetTitle()
{
return mAllowToChangeBaseBranch ?
PlasticLocalization.Name.CreateChildBranchBasedOnTitle.GetString() :
PlasticLocalization.Name.CreateChildBranchTitle.GetString();
}
protected override void DoComponentsArea()
{
DoTopArea();
DoFieldsArea();
}
internal static BranchCreationData CreateBranchFromMainOrCurrentBranch(
EditorWindow parentWindow,
RepositorySpec repSpec,
BranchInfo mainBranch,
BranchInfo currentBranch,
string proposedBranchName)
{
string changesetStr = PlasticLocalization.Name.LastChangeset.GetString();
string explanation = BranchCreationUserInfo.GetFromObjectString(
repSpec, currentBranch, changesetStr);
return CreateBranch(
parentWindow,
repSpec,
mainBranch,
mainBranch,
currentBranch,
-1,
explanation,
true,
proposedBranchName);
}
internal static BranchCreationData CreateBranchFromLastParentBranchChangeset(
EditorWindow parentWindow,
RepositorySpec repSpec,
BranchInfo parentBranchInfo,
string proposedBranchName)
{
string changesetStr = PlasticLocalization.Name.LastChangeset.GetString();
string explanation = BranchCreationUserInfo.GetFromObjectString(
repSpec, parentBranchInfo, changesetStr);
return CreateBranch(
parentWindow,
repSpec,
parentBranchInfo,
null,
null,
-1,
explanation,
false,
proposedBranchName);
}
internal static BranchCreationData CreateBranchFromChangeset(
EditorWindow parentWindow,
RepositorySpec repSpec,
ChangesetInfo changesetInfo,
string proposedBranchName)
{
BranchInfo parentBranchInfo = BranchInfoCache.GetBranch(
repSpec, changesetInfo.BranchId);
string changesetStr = SpecPreffix.CHANGESET + changesetInfo.ChangesetId.ToString();
string explanation = BranchCreationUserInfo.GetFromObjectString(
repSpec, parentBranchInfo, changesetStr);
return CreateBranch(
parentWindow,
repSpec,
parentBranchInfo,
null,
null,
changesetInfo.ChangesetId,
explanation,
false,
proposedBranchName);
}
internal static BranchCreationData CreateBranchFromLabel(
EditorWindow parentWindow,
RepositorySpec repSpec,
MarkerExtendedInfo labelInfo)
{
BranchInfo parentBranchInfo = BranchInfoCache.GetBranch(
repSpec, labelInfo.BranchId);
string explanation = BranchCreationUserInfo.GetFromObjectString(
repSpec, labelInfo);
return CreateBranch(
parentWindow,
repSpec,
parentBranchInfo,
null,
null,
labelInfo.Changeset,
explanation,
false,
null);
}
internal void CheckMainBranchRadioToggle()
{
mIsMainBranchSelected = true;
mIsCurrentBranchSelected = false;
mSelectedBaseBranch = mMainBranch;
}
internal void CheckCurrentBranchRadioToggle()
{
mIsMainBranchSelected = false;
mIsCurrentBranchSelected = true;
mSelectedBaseBranch = mCurrentBranch;
}
static BranchCreationData CreateBranch(
EditorWindow parentWindow,
RepositorySpec repSpec,
BranchInfo baseBranch,
BranchInfo mainBranch,
BranchInfo currentBranch,
long changesetId,
string explanation,
bool allowToChangeBaseBranch,
string proposedBranchName)
{
CreateBranchDialog dialog = Create(
repSpec,
baseBranch,
mainBranch,
currentBranch,
changesetId,
explanation,
allowToChangeBaseBranch,
proposedBranchName);
ResponseType dialogueResult = dialog.RunModal(parentWindow);
BranchCreationData result = dialog.BuildCreationData();
result.Result = dialogueResult == ResponseType.Ok;
return result;
}
void DoTopArea()
{
if (mAllowToChangeBaseBranch)
{
DoBranchSelectionArea();
return;
}
Paragraph(string.Format("{0} {1}",
PlasticLocalization.Name.CreateChildBranchExplanation.GetString(), mExplanation));
}
void DoBranchSelectionArea()
{
int descriptionLabelLeftMargin = 25;
GUILayout.BeginVertical();
if (GUILayout.Toggle(
mIsMainBranchSelected,
GetBranchName.FromFullBranchName(mMainBranch.Name),
UnityStyles.Dialog.BoldRadioToggle))
{
mIsMainBranchSelected = true;
mIsCurrentBranchSelected = false;
mSelectedBaseBranch = mMainBranch;
}
GUILayout.BeginHorizontal();
GUILayout.Space(descriptionLabelLeftMargin);
GUILayout.Label(
PlasticLocalization.Name.CreateChildBranchBasedOnMainExplanation.GetString(),
EditorStyles.miniLabel);
GUILayout.EndHorizontal();
if (GUILayout.Toggle(
mIsCurrentBranchSelected,
GetBranchName.FromFullBranchName(mCurrentBranch.Name),
UnityStyles.Dialog.BoldRadioToggle))
{
mIsMainBranchSelected = false;
mIsCurrentBranchSelected = true;
mSelectedBaseBranch = mCurrentBranch;
}
GUILayout.BeginHorizontal();
GUILayout.Space(descriptionLabelLeftMargin);
GUILayout.Label(
PlasticLocalization.Name.CreateChildBranchBasedOnCurrentBranchExplanation.GetString(),
EditorStyles.miniLabel);
GUILayout.EndHorizontal();
GUILayout.Space(15);
GUILayout.EndVertical();
}
void DoFieldsArea()
{
GUILayout.BeginVertical();
using (new EditorGUILayout.HorizontalScope())
{
GUILayout.Label(
PlasticLocalization.Name.BranchNameEntry.GetString(),
GUILayout.Width(100));
Rect nameRect = GUILayoutUtility.GetRect(
new GUIContent(string.Empty),
EditorStyles.textField,
GUILayout.ExpandWidth(true));
GUI.SetNextControlName(NAME_FIELD_CONTROL_NAME);
mNewBranchName = UnityEditor.EditorGUI.TextField(nameRect, mNewBranchName);
FocusTextAreaIfNeeded(NAME_FIELD_CONTROL_NAME);
}
GUILayout.Space(5);
using (new EditorGUILayout.HorizontalScope())
{
using (new EditorGUILayout.VerticalScope(GUILayout.Width(100)))
{
GUILayout.Space(49);
GUILayout.Label(
PlasticLocalization.Name.CommentsEntry.GetString(),
GUILayout.Width(100));
}
Rect commentRect = GUILayoutUtility.GetRect(
new GUIContent(string.Empty),
EditorStyles.textArea,
GUILayout.Height(100),
GUILayout.ExpandWidth(true));
GUI.SetNextControlName(COMMENT_TEXTAREA_CONTROL_NAME);
mComment = EditorGUI.ScrollableTextAreaInternal(
commentRect,
mComment,
ref mScrollPosition,
EditorStyles.textArea);
}
GUILayout.Space(15);
mSwitchToBranch = GUILayout.Toggle(
mSwitchToBranch,
PlasticLocalization.Name.SwitchToBranchCheckButton.GetString());
GUILayout.Space(5);
GUILayout.EndVertical();
}
Vector2 mScrollPosition;
internal override void OkButtonAction()
{
BranchCreationValidation.AsyncValidation(
BuildCreationData(), this, mProgressControls);
}
internal static CreateBranchDialog Create(
RepositorySpec repSpec,
BranchInfo baseBranch,
BranchInfo mainBranch,
BranchInfo currentBranch,
long changesetId,
string explanation,
bool allowToChangeBaseBranch,
string proposedBranchName)
{
CreateBranchDialogAssertions.AssertValidBaseBranchChangeArguments(
mainBranch,
currentBranch,
allowToChangeBaseBranch);
if (allowToChangeBaseBranch && currentBranch.IsMainBranch())
allowToChangeBaseBranch = false;
var instance = CreateInstance<CreateBranchDialog>();
instance.IsResizable = false;
instance.mEnterKeyAction = instance.OkButtonAction;
instance.AddControlConsumingEnterKey(COMMENT_TEXTAREA_CONTROL_NAME);
instance.mEscapeKeyAction = instance.CloseButtonAction;
instance.mOkButtonText = PlasticLocalization.Name.CreateButton.GetString();
instance.mRepositorySpec = repSpec;
instance.mSelectedBaseBranch = baseBranch;
instance.mMainBranch = mainBranch;
instance.mCurrentBranch = currentBranch;
instance.mAllowToChangeBaseBranch = allowToChangeBaseBranch;
instance.mNewBranchName = proposedBranchName == null ?
string.Empty : proposedBranchName;
instance.mComment = "";
instance.mSwitchToBranch = true;
instance.mExplanation = explanation;
instance.mChangesetId = changesetId;
return instance;
}
BranchCreationData BuildCreationData()
{
return new BranchCreationData(
mRepositorySpec,
mSelectedBaseBranch,
mChangesetId,
mNewBranchName,
mComment,
null,
mSwitchToBranch);
}
RepositorySpec mRepositorySpec;
BranchInfo mSelectedBaseBranch;
BranchInfo mMainBranch;
BranchInfo mCurrentBranch;
bool mAllowToChangeBaseBranch;
long mChangesetId;
string mNewBranchName;
string mComment;
bool mSwitchToBranch;
string mExplanation;
bool mIsMainBranchSelected = true;
bool mIsCurrentBranchSelected;
const string NAME_FIELD_CONTROL_NAME = "CreateBranchNameField";
const string COMMENT_TEXTAREA_CONTROL_NAME = "CreateBranchCommentTextArea";
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a0fc5252a48d8b34f945b4ae3ad45030
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,91 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using Codice.CM.Common;
using PlasticGui;
using Unity.PlasticSCM.Editor.UI;
namespace Unity.PlasticSCM.Editor.Views.Branches.Dialogs
{
internal class DeleteBranchDialog : PlasticDialog
{
internal static bool ConfirmDelete(
EditorWindow parentWindow,
IList<BranchInfo> branches)
{
DeleteBranchDialog dialog = Create(branches);
return dialog.RunModal(parentWindow) == ResponseType.Ok;
}
protected override string GetExplanation()
{
return mMessage;
}
protected override string GetTitle()
{
return mTitle;
}
protected override void DoOkButton()
{
GUI.enabled = IsDeleteButtonEnabled();
if (NormalButton(PlasticLocalization.Name.DeleteButton.GetString()))
OkButtonAction();
GUI.enabled = true;
}
protected override void DoButtonsArea()
{
using (new EditorGUILayout.HorizontalScope())
{
GUILayout.FlexibleSpace();
mConfirmDelete = EntryBuilder.CreateToggleEntry(
PlasticLocalization.Name.ConfirmationCheckBox.GetString(),
mConfirmDelete);
GUILayout.Space(10);
DoButtonsWithPlatformOrdering(DoOkButton, DoCloseButton, DoCancelButton);
}
}
internal override void OkButtonAction()
{
if (!IsDeleteButtonEnabled())
return;
base.OkButtonAction();
}
bool IsDeleteButtonEnabled()
{
return mConfirmDelete;
}
static DeleteBranchDialog Create(IList<BranchInfo> branches)
{
var instance = CreateInstance<DeleteBranchDialog>();
instance.mMessage = DeleteObjectsAlert.BuildDeleteBranchConfirmationMessage(branches);
instance.mEnterKeyAction = instance.OkButtonAction;
instance.mEscapeKeyAction = instance.CancelButtonAction;
instance.mCancelButtonText = PlasticLocalization.Name.NoButton.GetString();
instance.mNumberOfBranches = branches.Count;
instance.mTitle = PlasticLocalization.Name.ConfirmDeleteTitle.GetString();
return instance;
}
const int MAX_ITEMS_TO_SHOW = 10;
string mMessage;
string mTitle;
int mNumberOfBranches;
bool mConfirmDelete;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6780ea954e283bd4f82686f6e5ebafee
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,39 @@
using UnityEditor;
using Codice.CM.Common;
using PlasticGui;
using PlasticGui.WorkspaceWindow.QueryViews.Branches;
using Unity.PlasticSCM.Editor.UI;
namespace Unity.PlasticSCM.Editor.Views.Branches.Dialogs
{
internal class RenameBranchDialog
{
internal static BranchRenameData GetBranchRenameData(
RepositorySpec repSpec,
BranchInfo branchInfo,
EditorWindow parentWindow)
{
InputTextDialogResult dialogResult = InputTextDialog.GetInputText(
PlasticLocalization.Name.RenameBranchTitle.GetString(),
null,
PlasticLocalization.GetString(PlasticLocalization.Name.NewName),
GetShorten.BranchNameFromString(branchInfo.BranchName),
PlasticLocalization.GetString(PlasticLocalization.Name.RenameButton),
(text, closer, progressControls) =>
{
BranchRenameData data = new BranchRenameData(
repSpec, branchInfo, text);
BranchRenameValidation.AsyncValidation(data, closer, progressControls);
},
parentWindow,
width: 500);
BranchRenameData result = new BranchRenameData(
repSpec, branchInfo, dialogResult.Text);
result.Result = dialogResult.Result;
return result;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1de62e30afcba544e8e8da4b93a4fa39
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,23 @@
using System;
using Codice.CM.Common;
namespace Unity.PlasticSCM.Editor.Views.Branches
{
[Serializable]
internal class SerializableBranchesTabState
{
internal BranchInfo BranchToSelect;
internal bool ShowHiddenBranches;
internal bool IsInitialized { get; private set; }
internal SerializableBranchesTabState(
BranchInfo branchToSelect,
bool showHiddenBranches)
{
ShowHiddenBranches = showHiddenBranches;
IsInitialized = true;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9e592d81aca24e489c0bac69b894dd31
timeCreated: 1741940913