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,21 @@
using UnityEditor.IMGUI.Controls;
using PlasticGui.WorkspaceWindow.Diff;
#if UNITY_6000_2_OR_NEWER
using TreeViewItem = UnityEditor.IMGUI.Controls.TreeViewItem<int>;
#endif
namespace Unity.PlasticSCM.Editor.Views.Diff
{
internal class ChangeCategoryTreeViewItem : TreeViewItem
{
internal ChangeCategory Category { get; private set; }
internal ChangeCategoryTreeViewItem(
int id, int depth, ChangeCategory category)
: base(id, depth, category.GetHeaderText())
{
Category = category;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 156e16594aa6bd54cb77aa3f8eae5c82
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,395 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
using Codice.CM.Common;
using Codice.CM.Common.Mount;
using Codice.Utils;
using PlasticGui;
using PlasticGui.Diff;
using PlasticGui.WorkspaceWindow;
using PlasticGui.WorkspaceWindow.QueryViews;
using PlasticGui.WorkspaceWindow.Diff.Type;
using Unity.PlasticSCM.Editor.AssetsOverlays.Cache;
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.Properties;
#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.Diff
{
internal class ChangesetByChangesetDiffPanel :
ExploreChangesets.IChangesetsPanel
{
internal DiffPanel DiffPanel { get { return mDiffPanel; } }
internal ChangesetByChangesetDiffPanel(
Action repaint,
WorkspaceInfo wkInfo,
IWorkspaceWindow workspaceWindow,
IViewSwitcher viewSwitcher,
IHistoryViewLauncher historyViewLauncher,
IRefreshView refreshView,
IAssetStatusCache assetStatusCache,
LaunchTool.IShowDownloadPlasticExeWindow showDownloadPlasticExeWindow,
IPendingChangesUpdater pendingChangesUpdater,
IIncomingChangesUpdater developerIncomingChangesUpdater,
IIncomingChangesUpdater gluonIncomingChangesUpdater,
EditorWindow parentWindow,
bool isGluonMode)
{
mRepaint = repaint;
mWkInfo = wkInfo;
mWorkspaceWindow = workspaceWindow;
mViewSwitcher = viewSwitcher;
mHistoryViewLauncher = historyViewLauncher;
mRefreshView = refreshView;
mAssetStatusCache = assetStatusCache;
mShowDownloadPlasticExeWindow = showDownloadPlasticExeWindow;
mPendingChangesUpdater = pendingChangesUpdater;
mDeveloperIncomingChangesUpdater = developerIncomingChangesUpdater;
mGluonIncomingChangesUpdater = gluonIncomingChangesUpdater;
mParentWindow = parentWindow;
mIsGluonMode = isGluonMode;
mEmptyStatePanel = new EmptyStatePanel(repaint);
mProgressControls = new ProgressControlsForViews();
mShowDiffsDataCalculator = ShowChangesetDiffsDataCalculator.BuildForUnix(
new GetDifferences());
BuildComponents();
mDiffSplitterState = new SplitterState(
SplitterSettings.Load(
UnityConstants.DIFF_SPLITTER_SETTINGS_NAME,
new float[] { 0.3f, 0.7f }),
new int[] { 100, 233 },
new int[] { 100000, 100000 }
);
}
internal void ClearInfo()
{
mSelectedMountWithPath = null;
mSelectedRepObjectInfo = null;
RefreshChangesetsList();
mRepaint();
}
internal void UpdateInfo(
MountPointWithPath mountWithPath,
RepObjectInfo repObjectInfo)
{
if (mSelectedRepObjectInfo != null &&
mSelectedRepObjectInfo.Equals(repObjectInfo))
return;
mSelectedMountWithPath = mountWithPath;
mSelectedRepObjectInfo = repObjectInfo;
if (repObjectInfo is BranchInfo)
{
RefreshChangesetsList();
}
mRepaint();
}
internal void OnEnable()
{
mDiffPanel.OnEnable();
}
internal void OnDisable()
{
mDiffPanel.OnDisable();
SplitterSettings.Save(
mDiffSplitterState,
UnityConstants.DIFF_SPLITTER_SETTINGS_NAME);
}
internal void Update()
{
mProgressControls.UpdateProgress(mRepaint);
mDiffPanel.Update();
mPropertiesPanel.Update();
}
internal void OnGUI()
{
EditorGUILayout.BeginVertical();
SplitterGUILayout.BeginVerticalSplit(mDiffSplitterState);
DoChangesetsArea();
DoPropertiesAndDiffArea();
SplitterGUILayout.EndVerticalSplit();
if (mProgressControls.HasNotification())
{
DrawProgressForViews.ForNotificationArea(
mProgressControls.ProgressData);
}
EditorGUILayout.EndVertical();
}
string ExploreChangesets.IChangesetsPanel.GetFilterText()
{
return mChangesetsListView.searchString;
}
void ExploreChangesets.IChangesetsPanel.ShowContentPanel()
{
mEmptyStatePanel.UpdateContent(string.Empty);
}
void ExploreChangesets.IChangesetsPanel.ShowEmptyStatePanel(string explanationText)
{
mEmptyStatePanel.UpdateContent(explanationText);
}
void ExploreChangesets.IChangesetsPanel.ShowWaitingAnimation()
{
((IProgressControls)mProgressControls).ShowProgress(
PlasticLocalization.Name.Loading.GetString());
}
void ExploreChangesets.IChangesetsPanel.SetChangesetList(
List<ChangesetInfo> changesets,
ChangesetInfo csetInfoToSelect,
Dictionary<SEID, string> resolvedUsers)
{
mResolvedUsers = resolvedUsers;
((IPlasticTable<ChangesetInfo>)mChangesetsListView).FillEntriesAndSelectRows(
changesets,
changesets.Count == 0 ?
new List<ChangesetInfo>() :
new List<ChangesetInfo> { csetInfoToSelect ?? changesets[0] },
null);
}
void ExploreChangesets.IChangesetsPanel.HideWaitingAnimation()
{
((IProgressControls)mProgressControls).HideProgress();
}
string ResolveUserName(SEID seid)
{
string result = seid.Data;
mResolvedUsers?.TryGetValue(seid, out result);
return result;
}
void RefreshChangesetsList()
{
mPropertiesPanel.ClearInfo();
mDiffPanel.ClearInfo();
mExploreChangesets.SetBranchInfo(
(BranchInfo)mSelectedRepObjectInfo,
mSelectedMountWithPath?.RepSpec);
mExploreChangesets.LoadChangesets(mChangesetsListView.searchString);
}
void DoPropertiesAndDiffArea()
{
GUILayout.BeginVertical();
DoPropertiesArea();
DoDiffArea();
GUILayout.EndVertical();
}
void DoChangesetsArea()
{
EditorGUILayout.BeginVertical();
DoChangesetsToolbar();
Rect viewRect = OverlayProgress.CaptureViewRectangle();
DoChangesetsListView();
EditorGUILayout.EndVertical();
if (mProgressControls.IsOperationRunning())
{
OverlayProgress.DoOverlayProgress(
viewRect,
mProgressControls.ProgressData.ProgressPercent,
mProgressControls.ProgressData.ProgressMessage);
}
}
void DoPropertiesArea()
{
GUILayout.BeginVertical();
Rect separatorRect = GUILayoutUtility.GetRect(
0,
1,
GUILayout.ExpandHeight(false),
GUILayout.ExpandWidth(true));
EditorGUI.DrawRect(separatorRect, UnityStyles.Colors.BarBorder);
mPropertiesPanel.OnGUI();
GUILayout.EndVertical();
}
void DoChangesetsToolbar()
{
EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
GUILayout.FlexibleSpace();
GUILayout.Space(3);
DrawSearchField.For(
mSearchField,
mChangesetsListView,
UnityConstants.SEARCH_FIELD_WIDTH);
EditorGUILayout.EndHorizontal();
}
void DoChangesetsListView()
{
GUI.enabled = !mProgressControls.IsOperationRunning();
Rect rect = GUILayoutUtility.GetRect(0, 100000, 0, 100000);
mChangesetsListView.OnGUI(rect);
if (Event.current.type == EventType.Layout)
mShouldShowEmptyState = !mEmptyStatePanel.IsEmpty();
if (mShouldShowEmptyState)
mEmptyStatePanel.OnGUI(rect);
GUI.enabled = true;
}
void DoDiffArea()
{
EditorGUILayout.BeginVertical();
Rect separatorRect = GUILayoutUtility.GetRect(
0,
1,
GUILayout.ExpandWidth(true));
EditorGUI.DrawRect(separatorRect, UnityStyles.Colors.BarBorder);
mDiffPanel.OnGUI();
EditorGUILayout.EndVertical();
}
void BuildComponents()
{
mSearchField = new SearchField();
mSearchField.downOrUpArrowKeyPressed += SearchField_OnDownOrUpArrowKeyPressed;
mPropertiesPanel = new PropertiesPanel(
mRepaint,
mWorkspaceWindow,
mParentWindow);
mDiffPanel = new DiffPanel(
mRepaint,
mWkInfo,
mWorkspaceWindow,
mViewSwitcher,
mHistoryViewLauncher,
mRefreshView,
mAssetStatusCache,
mShowDownloadPlasticExeWindow,
mPendingChangesUpdater,
mDeveloperIncomingChangesUpdater,
mGluonIncomingChangesUpdater,
mParentWindow,
mIsGluonMode);
mExploreChangesets = new ExploreChangesets(mDiffPanel, this);
mChangesetsListView = new ChangesetByChangesetListView(
mExploreChangesets,
ResolveUserName,
delayedSelectionChangedAction: OnDelayedChangesetSelectionChanged);
mChangesetsListView.Reload();
}
void SearchField_OnDownOrUpArrowKeyPressed()
{
mChangesetsListView.SetFocusAndEnsureSelectedItem();
}
void OnDelayedChangesetSelectionChanged()
{
List<ChangesetInfo> selectedChangesetInfos = mChangesetsListView.GetSelectedChangesetInfos();
if (selectedChangesetInfos.Count == 0 || selectedChangesetInfos[0] == null)
return;
if (mSelectedMountWithPath == null)
return;
mPropertiesPanel.UpdateInfo(selectedChangesetInfos[0], mSelectedMountWithPath.RepSpec);
mExploreChangesets.LoadChangesetDiffs(
selectedChangesetInfos[0],
mShowDiffsDataCalculator,
new CancelToken());
}
RepObjectInfo mSelectedRepObjectInfo;
MountPointWithPath mSelectedMountWithPath;
bool mShouldShowEmptyState;
SearchField mSearchField;
ChangesetByChangesetListView mChangesetsListView;
PropertiesPanel mPropertiesPanel;
DiffPanel mDiffPanel;
ExploreChangesets mExploreChangesets;
Dictionary<SEID, string> mResolvedUsers;
readonly ProgressControlsForViews mProgressControls;
readonly ExploreChangesets.IShowDiffsDataCalculator mShowDiffsDataCalculator;
readonly EmptyStatePanel mEmptyStatePanel;
readonly Action mRepaint;
readonly SplitterState mDiffSplitterState;
readonly bool mIsGluonMode;
readonly EditorWindow mParentWindow;
readonly IRefreshView mRefreshView;
readonly LaunchTool.IShowDownloadPlasticExeWindow mShowDownloadPlasticExeWindow;
readonly IAssetStatusCache mAssetStatusCache;
readonly IHistoryViewLauncher mHistoryViewLauncher;
readonly IViewSwitcher mViewSwitcher;
readonly IWorkspaceWindow mWorkspaceWindow;
readonly WorkspaceInfo mWkInfo;
readonly IPendingChangesUpdater mPendingChangesUpdater;
readonly IIncomingChangesUpdater mDeveloperIncomingChangesUpdater;
readonly IIncomingChangesUpdater mGluonIncomingChangesUpdater;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 88f7d95ce0bbb004d8b7fb2d5c2b3a64
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,337 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
using Codice.CM.Common;
using PlasticGui;
using PlasticGui.WorkspaceWindow.Diff.Type;
using Unity.PlasticSCM.Editor.UI;
using Unity.PlasticSCM.Editor.UI.Avatar;
using Unity.PlasticSCM.Editor.UI.Tree;
using Unity.PlasticSCM.Editor.Views.Changesets;
using Unity.PlasticSCM.Editor.Views.Labels.Dialogs;
#if UNITY_6000_2_OR_NEWER
using TreeViewItem = UnityEditor.IMGUI.Controls.TreeViewItem<int>;
#endif
namespace Unity.PlasticSCM.Editor.Views.Diff
{
internal class ChangesetByChangesetListView :
PlasticTreeView,
IPlasticTable<ChangesetInfo>
{
internal ChangesetByChangesetListView(
ExploreChangesets exploreChangesets,
Func<SEID, string> resolveUserName,
Action delayedSelectionChangedAction): base(showCustomBackground: false)
{
mExploreChangesets = exploreChangesets;
mResolveUserName = resolveUserName;
mDelayedSelectionChangedAction = delayedSelectionChangedAction;
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 (mChangesets == null)
{
ClearRows(rootItem, mRows);
return mRows;
}
RegenerateRows(
mListViewItemIds,
mChangesets,
rootItem, mRows);
return mRows;
}
protected override void SearchChanged(string newSearch)
{
// HACK: if CreateLabelDialog is open, update the results
// since the mDelayedFilterAction does not work properly
if (EditorWindow.HasOpenInstances<CreateLabelDialog>())
{
Refilter();
Reload();
return;
}
mDelayedFilterAction.Run();
}
protected override void RowGUI(RowGUIArgs args)
{
if (args.item is ChangesetListViewItem)
{
ChangesetListViewItem changesetListViewItem = (ChangesetListViewItem)args.item;
ChangesetsListViewItemGUI(
rowHeight,
changesetListViewItem,
args,
false,
false,
mResolveUserName,
Repaint);
return;
}
base.RowGUI(args);
}
internal List<ChangesetInfo> GetSelectedChangesetInfos()
{
List<ChangesetInfo> result = new List<ChangesetInfo>();
IList<int> selectedIds = GetSelection();
if (selectedIds.Count == 0)
return result;
foreach (KeyValuePair<object, int> item
in mListViewItemIds.GetInfoItems())
{
if (!selectedIds.Contains(item.Value))
continue;
result.Add((ChangesetInfo)item.Key);
}
return result;
}
void Refilter()
{
mExploreChangesets.ApplyFilter(searchString);
}
void SelectChangesetInfos(
List<ChangesetInfo> changesetsToSelect)
{
List<int> idsToSelect = new List<int>();
foreach (ChangesetInfo changesetInfo in changesetsToSelect)
{
int changesetId = GetTreeIdForItem(changesetInfo);
if (changesetId == -1)
continue;
idsToSelect.Add(changesetId);
}
TableViewOperations.SetSelectionAndScroll(this, idsToSelect);
}
void IPlasticTable<ChangesetInfo>.FillEntriesAndSelectRows(
IList<ChangesetInfo> entries,
List<ChangesetInfo> entriesToSelect,
string currentFilter)
{
mListViewItemIds.Clear();
List<ChangesetInfo> changesetsToSelect =
entriesToSelect == null || entriesToSelect.Count == 0 ?
GetSelectedChangesetInfos() :
entriesToSelect;
int defaultRow = TableViewOperations.GetFirstSelectedRow(this);
mChangesets = new List<ChangesetInfo>(entries);
Reload();
SelectChangesets(changesetsToSelect, defaultRow);
}
void SelectChangesets(
List<ChangesetInfo> csetsToSelect,
int defaultRow)
{
if (csetsToSelect == null || csetsToSelect.Count == 0)
{
TableViewOperations.SelectFirstRow(this);
return;
}
SelectChangesetInfos(csetsToSelect);
if (HasSelection())
return;
TableViewOperations.SelectDefaultRow(this, defaultRow);
if (HasSelection())
return;
TableViewOperations.SelectFirstRow(this);
}
void DelayedSearchChanged()
{
Refilter();
Reload();
TableViewOperations.ScrollToSelection(this);
mDelayedSelectionChangedAction();
}
void DelayedSelectionChanged()
{
if (!HasSelection())
return;
mDelayedSelectionChangedAction();
}
int GetTreeIdForItem(ChangesetInfo changesetInfo)
{
foreach (KeyValuePair<object, int> item in mListViewItemIds.GetInfoItems())
{
if (!item.Key.Equals(changesetInfo))
continue;
if (!((ChangesetInfo)item.Key).GUID.Equals(changesetInfo.GUID))
continue;
return item.Value;
}
return -1;
}
static void RegenerateRows(
ListViewItemIds<object> listViewItemIds,
IList<ChangesetInfo> changesets,
TreeViewItem rootItem,
List<TreeViewItem> rows)
{
ClearRows(rootItem, rows);
if (changesets.Count == 0)
return;
foreach (ChangesetInfo changeset in changesets)
{
int changesetId;
if (!listViewItemIds.TryGetInfoItemId(changeset, out changesetId))
changesetId = listViewItemIds.AddInfoItem(changeset);
ChangesetListViewItem changesetListViewItem =
new ChangesetListViewItem(changesetId, changeset);
rootItem.AddChild(changesetListViewItem);
rows.Add(changesetListViewItem);
}
}
static void ClearRows(
TreeViewItem rootItem,
List<TreeViewItem> rows)
{
if (rootItem.hasChildren)
rootItem.children.Clear();
rows.Clear();
}
static void ChangesetsListViewItemGUI(
float rowHeight,
ChangesetListViewItem item,
RowGUIArgs args,
bool isBoldText,
bool isMultiColumn,
Func<SEID, string> resolveUserName,
Action avatarLoadedAction)
{
if (!isMultiColumn)
{
ChangesetsListViewItemCellGUI(
args.rowRect,
rowHeight,
item,
resolveUserName,
avatarLoadedAction,
args.selected,
args.focused,
isBoldText);
return;
}
for (int visibleColumnIdx = 0; visibleColumnIdx < args.GetNumVisibleColumns(); visibleColumnIdx++)
{
Rect cellRect = args.GetCellRect(visibleColumnIdx);
ChangesetsListViewItemCellGUI(
cellRect,
rowHeight,
item,
resolveUserName,
avatarLoadedAction,
args.selected,
args.focused,
isBoldText);
}
}
static void ChangesetsListViewItemCellGUI(
Rect rect,
float rowHeight,
ChangesetListViewItem item,
Func<SEID, string> resolveUserName,
Action avatarLoadedAction,
bool isSelected,
bool isFocused,
bool isBoldText)
{
rect.x += UnityConstants.FIRST_COLUMN_WITHOUT_ICON_INDENT;
rect.width -= UnityConstants.FIRST_COLUMN_WITHOUT_ICON_INDENT;
string columnText = CommentFormatter.GetFormattedComment(
((ChangesetInfo)item.ObjectInfo).Comment);
string userName = resolveUserName(((ChangesetInfo)item.ObjectInfo).Owner);
DrawTreeViewItem.ForItemCell(
rect,
rowHeight,
-1,
GetAvatar.ForEmail(userName, avatarLoadedAction),
userName,
null,
columnText,
isSelected,
isFocused,
isBoldText,
false);
}
ListViewItemIds<object> mListViewItemIds = new ListViewItemIds<object>();
List<ChangesetInfo> mChangesets;
readonly DelayedActionBySecondsRunner mDelayedFilterAction;
readonly DelayedActionBySecondsRunner mDelayedSelectionRunner;
readonly Action mDelayedSelectionChangedAction;
readonly Func<SEID, string> mResolveUserName;
readonly ExploreChangesets mExploreChangesets;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1448ee204d2f476b8b002dbf6a65436a
timeCreated: 1767861758
@@ -0,0 +1,23 @@
using UnityEditor.IMGUI.Controls;
using PlasticGui.WorkspaceWindow.Diff;
#if UNITY_6000_2_OR_NEWER
using TreeViewItem = UnityEditor.IMGUI.Controls.TreeViewItem<int>;
#endif
namespace Unity.PlasticSCM.Editor.Views.Diff
{
internal class ClientDiffTreeViewItem : TreeViewItem
{
internal ClientDiffInfo Difference { get; private set; }
internal ClientDiffTreeViewItem(
int id, int depth, ClientDiffInfo diff)
: base(id, depth)
{
Difference = diff;
displayName = diff.PathString;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3fdd86a000d1ef04094416eefed53087
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3ac250bc549a212428286f328779be0e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,185 @@
using System.IO;
using UnityEditor;
using UnityEngine;
using PlasticGui;
using PlasticGui.WorkspaceWindow;
using PlasticGui.WorkspaceWindow.Diff;
using Unity.PlasticSCM.Editor.AssetUtils;
using Unity.PlasticSCM.Editor.UI;
namespace Unity.PlasticSCM.Editor.Views.Diff.Dialogs
{
internal class GetRestorePathDialog : PlasticDialog
{
internal static GetRestorePathData GetRestorePath(
string wkPath,
string restorePath,
string explanation,
bool isDirectory,
bool showSkipButton,
EditorWindow parentWindow)
{
GetRestorePathDialog dialog = Create(
wkPath,
GetProposedRestorePath.For(restorePath),
explanation,
isDirectory,
showSkipButton);
ResponseType dialogResult = dialog.RunModal(parentWindow);
GetRestorePathData result = dialog.BuildGetRestorePathResult();
result.Result = GetRestorePathResultType(dialogResult);
return result;
}
protected override void DoComponentsArea()
{
GUILayout.Label(PlasticLocalization.GetString(
PlasticLocalization.Name.EnterRestorePathFormTextBoxExplanation),
EditorStyles.label);
GUILayout.BeginHorizontal();
Rect pathRect = GUILayoutUtility.GetRect(
new GUIContent(string.Empty),
EditorStyles.textField,
GUILayout.ExpandWidth(true));
mRestorePath = EditorGUI.TextField(pathRect, mRestorePath);
if (GUILayout.Button("...", UnityStyles.Dialog.SmallButton))
{
mRestorePath = (mIsDirectory) ?
DoOpenFolderPanel(mRestorePath) :
DoOpenFilePanel(mRestorePath);
}
GUILayout.EndHorizontal();
}
protected override string GetTitle()
{
return PlasticLocalization.GetString(
PlasticLocalization.Name.EnterRestorePathFormTitle);
}
protected override string GetExplanation()
{
return mExplanation;
}
static string DoOpenFolderPanel(string actualPath)
{
string parentDirectory = null;
string directoryName = null;
if (!string.IsNullOrEmpty(actualPath))
{
parentDirectory = Path.GetDirectoryName(actualPath);
directoryName = Path.GetFileName(actualPath);
}
string result = EditorUtility.SaveFolderPanel(
PlasticLocalization.GetString(PlasticLocalization.Name.SelectPathToRestore),
parentDirectory,
directoryName);
if (string.IsNullOrEmpty(result))
return actualPath;
return AssetsPath.GetFullPath.ForPath(result);
}
static string DoOpenFilePanel(string actualPath)
{
string parentDirectory = null;
string fileName = null;
string extension = null;
if (!string.IsNullOrEmpty(actualPath))
{
parentDirectory = Path.GetDirectoryName(actualPath);
fileName = Path.GetFileName(actualPath);
extension = Path.GetExtension(actualPath);
}
string result = EditorUtility.SaveFilePanel(
PlasticLocalization.GetString(PlasticLocalization.Name.SelectPathToRestore),
parentDirectory,
fileName,
extension);
if (string.IsNullOrEmpty(result))
return actualPath;
return AssetsPath.GetFullPath.ForPath(result);
}
protected override void DoCloseButton()
{
if (!mShowSkipButton)
return;
if (!NormalButton(PlasticLocalization.Name.SkipRestoreButton.GetString()))
return;
CloseButtonAction();
}
internal override void OkButtonAction()
{
GetRestorePathValidation.Validation(
mWkPath, BuildGetRestorePathResult(),
this, mProgressControls);
}
GetRestorePathData BuildGetRestorePathResult()
{
return new GetRestorePathData(mRestorePath);
}
static GetRestorePathData.ResultType GetRestorePathResultType(
ResponseType dialogResult)
{
switch (dialogResult)
{
case ResponseType.None:
return GetRestorePathData.ResultType.Skip;
case ResponseType.Ok:
return GetRestorePathData.ResultType.OK;
case ResponseType.Cancel:
return GetRestorePathData.ResultType.Cancel;
}
return GetRestorePathData.ResultType.Cancel;
}
static GetRestorePathDialog Create(
string wkPath,
string restorePath,
string explanation,
bool isDirectory,
bool showSkipButton)
{
var instance = CreateInstance<GetRestorePathDialog>();
instance.mWkPath = wkPath;
instance.mRestorePath = restorePath;
instance.mExplanation = explanation;
instance.mIsDirectory = isDirectory;
instance.mShowSkipButton = showSkipButton;
instance.mEnterKeyAction = instance.OkButtonAction;
instance.mEscapeKeyAction = instance.CancelButtonAction;
return instance;
}
bool mIsDirectory;
bool mShowSkipButton;
string mExplanation = string.Empty;
string mRestorePath = string.Empty;
string mWkPath = string.Empty;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 281456381b1a4c742b0efbe305328c7a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,777 @@
using System;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
using Codice.Client.Commands;
using Codice.Client.Common;
using Codice.Client.Common.EventTracking;
using Codice.Client.Common.Threading;
using Codice.CM.Common;
using Codice.CM.Common.Mount;
using PlasticGui;
using PlasticGui.Diff;
using PlasticGui.WorkspaceWindow;
using PlasticGui.WorkspaceWindow.BrowseRepository;
using PlasticGui.WorkspaceWindow.Diff;
using PlasticGui.WorkspaceWindow.Diff.Type;
using Unity.PlasticSCM.Editor.Diff;
using Unity.PlasticSCM.Editor.AssetsOverlays.Cache;
using Unity.PlasticSCM.Editor.AssetUtils;
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.Diff.Dialogs;
using Unity.PlasticSCM.Editor.Views.History;
namespace Unity.PlasticSCM.Editor.Views.Diff
{
internal class DiffPanel :
IDiffTreeViewMenuOperations,
DiffTreeViewMenu.IMetaMenuOperations,
UndeleteClientDiffsOperation.IGetRestorePathDialog,
IShowDiffs
{
internal DiffTreeView Table { get { return mDiffTreeView; } }
internal string EmptyStateMessage { get { return mEmptyStatePanel.Text; } }
internal DiffPanel(
Action repaint,
WorkspaceInfo wkInfo,
IWorkspaceWindow workspaceWindow,
IViewSwitcher viewSwitcher,
IHistoryViewLauncher historyViewLauncher,
IRefreshView refreshView,
IAssetStatusCache assetStatusCache,
LaunchTool.IShowDownloadPlasticExeWindow showDownloadPlasticExeWindow,
IPendingChangesUpdater pendingChangesUpdater,
IIncomingChangesUpdater developerIncomingChangesUpdater,
IIncomingChangesUpdater gluonIncomingChangesUpdater,
EditorWindow parentWindow,
bool isGluonMode)
{
mRepaint = repaint;
mWkInfo = wkInfo;
mWorkspaceWindow = workspaceWindow;
mViewSwitcher = viewSwitcher;
mHistoryViewLauncher = historyViewLauncher;
mRefreshView = refreshView;
mAssetStatusCache = assetStatusCache;
mShowDownloadPlasticExeWindow = showDownloadPlasticExeWindow;
mPendingChangesUpdater = pendingChangesUpdater;
mDeveloperIncomingChangesUpdater = developerIncomingChangesUpdater;
mGluonIncomingChangesUpdater = gluonIncomingChangesUpdater;
mParentWindow = parentWindow;
mIsGluonMode = isGluonMode;
mGuiMessage = new UnityPlasticGuiMessage();
mEmptyStatePanel = new EmptyStatePanel(repaint);
BuildComponents();
mProgressControls = new ProgressControlsForViews();
}
internal void ClearInfo()
{
ClearData();
mRepaint();
}
internal void UpdateInfo(
MountPointWithPath mountWithPath,
RepObjectInfo repObjectInfo)
{
if (mSelectedRepObjectInfo != null &&
mSelectedRepObjectInfo.Equals(repObjectInfo))
return;
mSelectedMountWithPath = mountWithPath;
mSelectedRepObjectInfo = repObjectInfo;
FillData(mountWithPath, repObjectInfo);
mRepaint();
}
internal void OnEnable()
{
mSearchField.downOrUpArrowKeyPressed +=
SearchField_OnDownOrUpArrowKeyPressed;
}
internal void OnDisable()
{
mSearchField.downOrUpArrowKeyPressed -=
SearchField_OnDownOrUpArrowKeyPressed;
}
internal void Update()
{
mProgressControls.UpdateProgress(mRepaint);
}
internal void OnGUI()
{
EditorGUILayout.BeginVertical();
DoActionsToolbar(
mDiffs,
mDiffsBranchResolver,
mProgressControls,
mIsSkipMergeTrackingButtonVisible,
mIsSkipMergeTrackingButtonChecked,
mSearchField,
mDiffTreeView);
Rect viewRect = OverlayProgress.CaptureViewRectangle();
if (mIsDiffDeferred)
{
DoDeferredDiffsPanel();
}
else
{
DoDiffTreeViewArea(
mDiffTreeView,
mEmptyStatePanel,
mProgressControls.IsOperationRunning());
}
if (mProgressControls.HasNotification())
{
DrawProgressForViews.ForNotificationArea(
mProgressControls.ProgressData);
}
EditorGUILayout.EndVertical();
if (mProgressControls.IsOperationRunning())
{
OverlayProgress.DoOverlayProgress(
viewRect,
mProgressControls.ProgressData.ProgressPercent,
mProgressControls.ProgressData.ProgressMessage);
}
}
void DoDeferredDiffsPanel()
{
GUILayout.FlexibleSpace();
GUILayout.BeginHorizontal();
GUILayout.Space(20);
GUILayout.BeginVertical();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUIStyle wrappedLabelStyle = new GUIStyle(
UnityStyles.EmptyState.Label);
wrappedLabelStyle.wordWrap = true;
GUILayout.Label(
mIsDiffDeferredExplanation,
wrappedLabelStyle);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.Space(10);
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (GUILayout.Button(
PlasticLocalization.Name.CalculateDiffsButton.GetString(),
GUILayout.Width(150)))
{
CalculateDiffsDeferred();
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.EndVertical();
GUILayout.Space(20);
GUILayout.EndHorizontal();
GUILayout.FlexibleSpace();
}
void IDiffTreeViewMenuOperations.SaveRevisionAs()
{
TrackFeatureUseEvent.For(
PlasticGui.Plastic.API.GetRepositorySpec(mWkInfo),
TrackFeatureUseEvent.Features.UnityPackage.SaveRevisionFromDiff);
ClientDiffInfo clientDiffInfo =
DiffSelection.GetSelectedDiff(mDiffTreeView);
RepositorySpec repSpec = clientDiffInfo.DiffWithMount.Mount.RepSpec;
RevisionInfo revision = clientDiffInfo.DiffWithMount.Difference.RevInfo;
string defaultFileName = DefaultRevisionName.Get(
Path.GetFileName(clientDiffInfo.DiffWithMount.Difference.Path), revision.Changeset);
string destinationPath = SaveAction.GetDestinationPath(
mWkInfo.ClientPath,
clientDiffInfo.DiffWithMount.Difference.Path,
defaultFileName);
if (string.IsNullOrEmpty(destinationPath))
return;
SaveRevisionOperation.SaveRevision(
repSpec,
destinationPath,
revision,
mProgressControls);
}
SelectedDiffsGroupInfo IDiffTreeViewMenuOperations.GetSelectedDiffsGroupInfo()
{
return SelectedDiffsGroupInfo.BuildFromSelectedNodes(
DiffSelection.GetSelectedDiffsWithoutMeta(mDiffTreeView),
mWkInfo != null);
}
void IDiffTreeViewMenuOperations.Diff()
{
ClientDiffInfo clientDiffInfo =
DiffSelection.GetSelectedDiff(mDiffTreeView);
IUnityDiffWindow diffWindow = ShowWindow.Diff();
diffWindow.ShowDiffFromDiff(
clientDiffInfo.DiffWithMount.Mount.Mount,
clientDiffInfo.DiffWithMount.Difference,
showDiffInDesktopApp: () => DiffInDesktopApp(clientDiffInfo));
}
void IDiffTreeViewMenuOperations.DiffInNewWindow()
{
((IDiffTreeViewMenuOperations)this).Diff();
}
void DiffInDesktopApp(ClientDiffInfo clientDiffInfo)
{
DiffOperation.DiffClientDiff(
mWkInfo,
clientDiffInfo.DiffWithMount.Mount.Mount,
clientDiffInfo.DiffWithMount.Difference,
PlasticExeLauncher.BuildForDiffRevision(mWkInfo, mIsGluonMode, mShowDownloadPlasticExeWindow),
imageDiffLauncher: null);
}
void IDiffTreeViewMenuOperations.History()
{
ClientDiffInfo clientDiffInfo =
DiffSelection.GetSelectedDiff(mDiffTreeView);
mHistoryViewLauncher.ShowHistoryView(
clientDiffInfo.DiffWithMount.Mount.RepSpec,
clientDiffInfo.DiffWithMount.Difference.RevInfo.ItemId,
clientDiffInfo.DiffWithMount.Difference.Path,
clientDiffInfo.DiffWithMount.Difference.IsDirectory);
}
void IDiffTreeViewMenuOperations.RevertChanges()
{
RevertClientDiffsOperation.RevertChanges(
mWkInfo,
DiffSelection.GetSelectedDiffs(mDiffTreeView),
mWorkspaceWindow,
mProgressControls,
mGuiMessage,
mPendingChangesUpdater,
mIsGluonMode ?
mGluonIncomingChangesUpdater :
mDeveloperIncomingChangesUpdater,
AfterRevertOrUndeleteOperation);
}
void IDiffTreeViewMenuOperations.Undelete()
{
UndeleteClientDiffsOperation.Undelete(
mWkInfo,
DiffSelection.GetSelectedDiffs(mDiffTreeView),
mRefreshView,
mProgressControls,
this,
mGuiMessage,
mPendingChangesUpdater,
mIsGluonMode ?
mGluonIncomingChangesUpdater :
mDeveloperIncomingChangesUpdater,
AfterRevertOrUndeleteOperation);
}
void IDiffTreeViewMenuOperations.UndeleteToSpecifiedPaths()
{
UndeleteClientDiffsOperation.UndeleteToSpecifiedPaths(
mWkInfo,
DiffSelection.GetSelectedDiffs(mDiffTreeView),
mRefreshView,
mProgressControls,
this,
mGuiMessage,
mPendingChangesUpdater,
mIsGluonMode ?
mGluonIncomingChangesUpdater :
mDeveloperIncomingChangesUpdater,
AfterRevertOrUndeleteOperation);
}
void IDiffTreeViewMenuOperations.Annotate()
{
}
void IDiffTreeViewMenuOperations.CopyFilePath(bool relativePath)
{
EditorGUIUtility.systemCopyBuffer = GetFilePathList.FromClientDiffInfos(
DiffSelection.GetSelectedDiffsWithoutMeta(mDiffTreeView),
relativePath,
mWkInfo.ClientPath);
}
bool DiffTreeViewMenu.IMetaMenuOperations.SelectionHasMeta()
{
return mDiffTreeView.SelectionHasMeta();
}
void DiffTreeViewMenu.IMetaMenuOperations.DiffMeta()
{
ClientDiffInfo clientDiffInfo =
DiffSelection.GetSelectedDiff(mDiffTreeView);
ClientDiffInfo clientDiffInfoMeta =
mDiffTreeView.GetMetaDiff(clientDiffInfo);
IUnityDiffWindow diffWindow = ShowWindow.Diff();
diffWindow.ShowDiffFromDiff(
clientDiffInfoMeta.DiffWithMount.Mount.Mount,
clientDiffInfoMeta.DiffWithMount.Difference,
showDiffInDesktopApp: () => DiffInDesktopApp(clientDiffInfoMeta));
}
GetRestorePathData
UndeleteClientDiffsOperation.IGetRestorePathDialog.GetRestorePath(
string wkPath, string restorePath, string explanation,
bool isDirectory, bool showSkipButton)
{
return GetRestorePathDialog.GetRestorePath(
wkPath, restorePath, explanation, isDirectory,
showSkipButton, mParentWindow);
}
void DiffTreeViewMenu.IMetaMenuOperations.HistoryMeta()
{
ClientDiffInfo clientDiffInfo =
DiffSelection.GetSelectedDiff(mDiffTreeView);
ClientDiffInfo clientDiffInfoMeta =
mDiffTreeView.GetMetaDiff(clientDiffInfo);
mHistoryViewLauncher.ShowHistoryView(
clientDiffInfoMeta.DiffWithMount.Mount.RepSpec,
clientDiffInfoMeta.DiffWithMount.Difference.RevInfo.ItemId,
clientDiffInfoMeta.DiffWithMount.Difference.Path,
clientDiffInfoMeta.DiffWithMount.Difference.IsDirectory);
}
void SearchField_OnDownOrUpArrowKeyPressed()
{
mDiffTreeView.SetFocusAndEnsureSelectedItem();
}
void AfterRevertOrUndeleteOperation()
{
RefreshAsset.UnityAssetDatabase(mAssetStatusCache);
mViewSwitcher.ShowPendingChanges();
}
void ClearData()
{
mSelectedMountWithPath = null;
mSelectedRepObjectInfo = null;
mDiffs = null;
mIsDiffDeferred = false;
mDiffTreeView.searchString = null;
ClearDiffs();
}
void IShowDiffs.ShowWaitingAnimation()
{
((IProgressControls)mProgressControls).ShowProgress(
PlasticLocalization.Name.Loading.GetString());
}
void IShowDiffs.HideWaitingAnimation()
{
((IProgressControls)mProgressControls).HideProgress();
}
void IShowDiffs.For(
ShowDiffsData showDiffsData,
DiffViewEntryDescriptor selectedItem,
bool selectItem,
Action afterUpdateDiffs)
{
mDiffs = showDiffsData.Diffs;
mDiffsBranchResolver = showDiffsData.BranchResolver;
ShowDiffsData();
}
void FillData(
MountPointWithPath mountWithPath,
RepObjectInfo repObjectInfo)
{
if (repObjectInfo.Id == -1)
{
ClearDiffs();
UpdateEmptyState();
return;
}
if (ShouldDeferDiffCalculation(repObjectInfo, out mIsDiffDeferredExplanation))
{
mIsDiffDeferred = true;
ClearDiffs();
UpdateEmptyState();
return;
}
mIsDiffDeferred = false;
CalculateDiffs(mountWithPath, repObjectInfo);
}
internal void CalculateDiffsDeferred()
{
if (!mIsDiffDeferred)
return;
mIsDiffDeferred = false;
CalculateDiffs(mSelectedMountWithPath, mSelectedRepObjectInfo);
}
void CalculateDiffs(
MountPointWithPath mountWithPath,
RepObjectInfo repObjectInfo)
{
((IProgressControls)mProgressControls).ShowProgress(
PlasticLocalization.GetString(PlasticLocalization.Name.Loading));
mIsSkipMergeTrackingButtonVisible = false;
IThreadWaiter waiter = ThreadWaiter.GetWaiter(100);
waiter.Execute(
threadOperationDelegate: delegate
{
if (repObjectInfo is BranchInfo)
{
mDiffs = PlasticGui.Plastic.API.GetBranchDifferencesForMountPoint(
mountWithPath,
(BranchInfo)repObjectInfo);
}
if (repObjectInfo is ChangesetInfo)
{
mDiffs = PlasticGui.Plastic.API.GetChangesetDifferences(
mountWithPath,
(ChangesetInfo)repObjectInfo);
}
mDiffsBranchResolver = BuildBranchResolver.ForDiffs(mDiffs);
},
afterOperationDelegate: delegate
{
((IProgressControls)mProgressControls).HideProgress();
if (mSelectedMountWithPath != mountWithPath ||
mSelectedRepObjectInfo != repObjectInfo)
return;
if (waiter.Exception != null)
{
ExceptionsHandler.LogException("DiffPanel", waiter.Exception);
((IProgressControls)mProgressControls).ShowError(waiter.Exception.Message);
ClearDiffs();
return;
}
ShowDiffsData();
});
}
void ShowDiffsData()
{
mDiffTreeView.searchString = null;
if (mDiffs == null || mDiffs.Count == 0)
{
ClearDiffs();
UpdateEmptyState();
return;
}
mIsSkipMergeTrackingButtonVisible =
ClientDiffList.HasMerges(mDiffs);
bool skipMergeTracking =
mIsSkipMergeTrackingButtonVisible &&
mIsSkipMergeTrackingButtonChecked;
UpdateDiffTreeView(
mWkInfo,
mDiffs,
mDiffsBranchResolver,
skipMergeTracking,
mDiffTreeView);
UpdateEmptyState();
}
void ClearDiffs()
{
mIsSkipMergeTrackingButtonVisible = false;
ClearDiffTreeView(mDiffTreeView);
}
static void ClearDiffTreeView(
DiffTreeView diffTreeView)
{
diffTreeView.ClearModel();
diffTreeView.Reload();
}
static void UpdateDiffTreeView(
WorkspaceInfo wkInfo,
List<ClientDiff> diffs,
BranchResolver brResolver,
bool skipMergeTracking,
DiffTreeView diffTreeView)
{
diffTreeView.BuildModel(
wkInfo, diffs, brResolver, skipMergeTracking);
diffTreeView.Refilter();
diffTreeView.Sort();
diffTreeView.Reload();
}
void DoActionsToolbar(
List<ClientDiff> diffs,
BranchResolver brResolver,
ProgressControlsForViews progressControls,
bool isSkipMergeTrackingButtonVisible,
bool isSkipMergeTrackingButtonChecked,
SearchField searchField,
DiffTreeView diffTreeView)
{
EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
GUILayout.FlexibleSpace();
if (isSkipMergeTrackingButtonVisible)
{
DoSkipMergeTrackingButton(
diffs, brResolver,
isSkipMergeTrackingButtonChecked,
diffTreeView);
}
DrawSearchField.For(
searchField,
diffTreeView,
UnityConstants.SEARCH_FIELD_WIDTH);
EditorGUILayout.EndHorizontal();
}
void DoSkipMergeTrackingButton(
List<ClientDiff> diffs,
BranchResolver brResolver,
bool isSkipMergeTrackingButtonChecked,
DiffTreeView diffTreeView)
{
bool wasChecked = isSkipMergeTrackingButtonChecked;
GUIContent buttonContent = new GUIContent(
PlasticLocalization.GetString(
PlasticLocalization.Name.SkipDiffMergeTracking));
GUIStyle buttonStyle = new GUIStyle(EditorStyles.toolbarButton);
float buttonWidth = buttonStyle.CalcSize(buttonContent).x + 10;
Rect toggleRect = GUILayoutUtility.GetRect(
buttonContent, buttonStyle, GUILayout.Width(buttonWidth));
bool isChecked = GUI.Toggle(
toggleRect, wasChecked, buttonContent, buttonStyle);
if (wasChecked == isChecked)
return;
// if user just checked the skip merge tracking button
if (isChecked)
{
TrackFeatureUseEvent.For(
PlasticGui.Plastic.API.GetRepositorySpec(mWkInfo),
TrackFeatureUseEvent.Features.UnityPackage.ChangesetViewSkipMergeTrackingButton);
}
UpdateDiffTreeView(mWkInfo, diffs, brResolver, isChecked, diffTreeView);
mIsSkipMergeTrackingButtonChecked = isChecked;
}
void OnDelayedSelectionChanged()
{
if (mDiffTreeView.GetSelection().Count != 1)
return;
ClientDiffInfo clientDiffInfo =
DiffSelection.GetSelectedDiff(mDiffTreeView);
if (clientDiffInfo == null)
return;
IUnityDiffWindow diffWindow = GetWindowIfOpened.Diff();
diffWindow?.ShowDiffFromDiff(
clientDiffInfo.DiffWithMount.Mount.Mount,
clientDiffInfo.DiffWithMount.Difference,
showDiffInDesktopApp: () => DiffInDesktopApp(clientDiffInfo));
}
void OnRowDoubleClickAction()
{
if (mDiffTreeView.GetSelection().Count != 1)
return;
if (DiffSelection.GetSelectedDiff(mDiffTreeView) != null)
{
((IDiffTreeViewMenuOperations)this).Diff();
return;
}
int selectedNode = mDiffTreeView.GetSelection()[0];
mDiffTreeView.SetExpanded(
selectedNode, expanded: !mDiffTreeView.IsExpanded(selectedNode));
}
void UpdateEmptyState()
{
mEmptyStatePanel.UpdateContent(GetEmptyStateMessage(mDiffTreeView));
}
void DoDiffTreeViewArea(
DiffTreeView diffTreeView,
EmptyStatePanel emptyStatePanel,
bool isOperationRunning)
{
GUI.enabled = !isOperationRunning;
Rect rect = GUILayoutUtility.GetRect(0, 100000, 0, 100000);
if (Event.current.type == EventType.Layout)
UpdateEmptyState();
if (emptyStatePanel.IsEmpty())
{
diffTreeView.OnGUI(rect);
}
else
{
emptyStatePanel.OnGUI(rect);
}
GUI.enabled = true;
}
static string GetEmptyStateMessage(DiffTreeView diffTreeView)
{
if (diffTreeView.GetRows().Count > 0)
return string.Empty;
return string.IsNullOrEmpty(diffTreeView.searchString) ?
PlasticLocalization.Name.NoContentToCompareExplanation.GetString() :
PlasticLocalization.Name.NoDiffsMatchingFilters.GetString();
}
void BuildComponents()
{
mSearchField = new SearchField();
mSearchField.downOrUpArrowKeyPressed += SearchField_OnDownOrUpArrowKeyPressed;
DiffTreeViewMenu diffTreeViewMenu = new DiffTreeViewMenu(this, this);
mDiffTreeView = new DiffTreeView(
diffTreeViewMenu,
OnDelayedSelectionChanged,
OnRowDoubleClickAction,
UpdateEmptyState);
mDiffTreeView.Reload();
}
bool ShouldDeferDiffCalculation(RepObjectInfo repObjectInfo, out string message)
{
if (repObjectInfo is BranchInfo branchInfo && branchInfo.IsMainBranch())
{
message = PlasticLocalization.Name.MainBranchDiffDeferredExplanation.GetString();
return true;
}
message = string.Empty;
return false;
}
bool mIsSkipMergeTrackingButtonVisible;
bool mIsSkipMergeTrackingButtonChecked;
bool mIsDiffDeferred;
string mIsDiffDeferredExplanation;
RepObjectInfo mSelectedRepObjectInfo;
MountPointWithPath mSelectedMountWithPath;
volatile List<ClientDiff> mDiffs;
volatile BranchResolver mDiffsBranchResolver;
SearchField mSearchField;
DiffTreeView mDiffTreeView;
readonly Action mRepaint;
readonly IPendingChangesUpdater mPendingChangesUpdater;
readonly IIncomingChangesUpdater mDeveloperIncomingChangesUpdater;
readonly ProgressControlsForViews mProgressControls;
readonly IIncomingChangesUpdater mGluonIncomingChangesUpdater;
readonly EmptyStatePanel mEmptyStatePanel;
readonly GuiMessage.IGuiMessage mGuiMessage;
readonly bool mIsGluonMode;
readonly EditorWindow mParentWindow;
readonly IRefreshView mRefreshView;
readonly LaunchTool.IShowDownloadPlasticExeWindow mShowDownloadPlasticExeWindow;
readonly IAssetStatusCache mAssetStatusCache;
readonly IHistoryViewLauncher mHistoryViewLauncher;
readonly IViewSwitcher mViewSwitcher;
readonly IWorkspaceWindow mWorkspaceWindow;
readonly WorkspaceInfo mWkInfo;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0ee79162e06c6984a97600b7c0680611
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,43 @@
using System.Collections.Generic;
using PlasticGui.WorkspaceWindow.Diff;
namespace Unity.PlasticSCM.Editor.Views.Diff
{
internal static class DiffSelection
{
internal static List<ClientDiffInfo> GetSelectedDiffs(
DiffTreeView treeView)
{
return treeView.GetSelectedDiffs(true);
}
internal static List<ClientDiffInfo> GetSelectedDiffsWithoutMeta(
DiffTreeView treeView)
{
return treeView.GetSelectedDiffs(false);
}
internal static ClientDiffInfo GetSelectedDiff(
DiffTreeView treeView)
{
if (!treeView.HasSelection())
return null;
List<ClientDiffInfo> selectedDiffs = treeView.GetSelectedDiffs(false);
return selectedDiffs.Count > 0 ? selectedDiffs[0] : null;
}
internal static bool IsApplicableDiffClientDiff(
DiffTreeView treeView)
{
ClientDiffInfo selectedDiff = GetSelectedDiff(treeView);
if (selectedDiff == null)
return false;
return DiffOperation.IsApplicableDiffClientDiff(selectedDiff.DiffWithMount.Difference);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4ef5fb54cd29b40468eaf5a14e9845ed
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,529 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
using Codice.Client.Commands;
using Codice.Client.Common;
using Codice.CM.Common;
using Codice.Utils;
using PlasticGui;
using PlasticGui.WorkspaceWindow.Diff;
using Unity.PlasticSCM.Editor.UI;
using Unity.PlasticSCM.Editor.UI.Tree;
#if UNITY_6000_2_OR_NEWER
using TreeView = UnityEditor.IMGUI.Controls.TreeView<int>;
using TreeViewItem = UnityEditor.IMGUI.Controls.TreeViewItem<int>;
#endif
namespace Unity.PlasticSCM.Editor.Views.Diff
{
internal class DiffTreeView : PlasticTreeView
{
internal GenericMenu Menu { get { return mMenu.Menu; } }
internal DiffTreeView(
DiffTreeViewMenu menu,
Action delayedSelectionChangedAction,
Action doubleClickAction,
Action afterItemsChangedAction) : base(showCustomBackground: false)
{
mMenu = menu;
mDelayedSelectionChangedAction = delayedSelectionChangedAction;
mDoubleClickAction = doubleClickAction;
mAfterItemsChangedAction = afterItemsChangedAction;
customFoldoutYOffset = UnityConstants.TREEVIEW_FOLDOUT_Y_OFFSET;
mDelayedFilterAction = new DelayedActionBySecondsRunner(
DelayedSearchChanged, UnityConstants.SEARCH_DELAYED_INPUT_ACTION_INTERVAL);
mDelayedSelectionRunner = new DelayedActionBySecondsRunner(
DelayedSelectionChanged, UnityConstants.SELECTION_DELAYED_INPUT_ACTION_INTERVAL);
}
internal bool ProcessKeyActionForTesting(Event e)
{
return mMenu.ProcessKeyActionIfNeeded(e);
}
internal void ProcessDoubleClickForTesting()
{
mDoubleClickAction();
}
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();
}
protected override bool CanChangeExpandedState(TreeViewItem item)
{
return item is ChangeCategoryTreeViewItem
|| item is MergeCategoryTreeViewItem;
}
protected override IList<TreeViewItem> BuildRows(TreeViewItem rootItem)
{
try
{
RegenerateRows(
mDiffTree,
mTreeViewItemIds,
this,
rootItem,
mRows,
mExpandCategories);
}
finally
{
mExpandCategories = false;
}
return mRows;
}
protected override void CommandEventHandling()
{
// NOTE - empty override to prevent crash when pressing ctrl-a in the treeview
}
protected override void SearchChanged(string newSearch)
{
mDelayedFilterAction.Run();
}
protected override void ContextClickedItem(int id)
{
mMenu.Popup();
Repaint();
}
protected override void RowGUI(RowGUIArgs args)
{
args.rowRect.width = Mathf.Max(0f, args.rowRect.width - ROW_RIGHT_MARGIN);
TreeViewItemGUI(
args.item, args.rowRect, rowHeight, mDiffTree, args.selected, args.focused);
}
protected override void DoubleClickedItem(int id)
{
mDoubleClickAction();
}
protected override void SelectionChanged(IList<int> selectedIds)
{
mDelayedSelectionRunner.Run();
}
void DelayedSelectionChanged()
{
if (!HasSelection())
return;
mDelayedSelectionChangedAction();
}
internal void ClearModel()
{
mTreeViewItemIds.Clear();
mDiffTree = new UnityDiffTree();
}
internal void BuildModel(
WorkspaceInfo wkInfo,
List<ClientDiff> diffs,
BranchResolver brResolver,
bool skipMergeTracking)
{
mTreeViewItemIds.Clear();
mDiffTree.BuildCategories(wkInfo, diffs, brResolver, skipMergeTracking);
}
internal void Refilter()
{
Filter filter = new Filter(searchString);
mDiffTree.Filter(filter, ColumnsNames);
mExpandCategories = true;
}
internal void Sort()
{
mDiffTree.Sort(
PlasticLocalization.GetString(PlasticLocalization.Name.PathColumn),
sortAscending: true);
}
internal ClientDiffInfo GetMetaDiff(ClientDiffInfo diff)
{
return mDiffTree.GetMetaDiff(diff);
}
internal bool SelectionHasMeta()
{
if (!HasSelection())
return false;
ClientDiffInfo selectedDiff = GetSelectedDiffs(false)[0];
if (selectedDiff == null)
return false;
return mDiffTree.HasMeta(selectedDiff);
}
internal List<ClientDiffInfo> GetSelectedDiffs(bool includeMetaFiles)
{
List<ClientDiffInfo> result = new List<ClientDiffInfo>();
IList<int> selectedIds = GetSelection();
if (selectedIds.Count == 0)
return result;
foreach (KeyValuePair<ITreeViewNode, int> item
in mTreeViewItemIds.GetInfoItems())
{
if (!selectedIds.Contains(item.Value))
continue;
if (!(item.Key is ClientDiffInfo))
continue;
result.Add((ClientDiffInfo)item.Key);
}
if (includeMetaFiles)
mDiffTree.FillWithMeta(result);
return result;
}
void DelayedSearchChanged()
{
Refilter();
Sort();
Reload();
mAfterItemsChangedAction();
TableViewOperations.ScrollToSelection(this);
}
static void RegenerateRows(
UnityDiffTree diffTree,
TreeViewItemIds<IDiffCategory, ITreeViewNode> treeViewItemIds,
TreeView treeView,
TreeViewItem rootItem,
List<TreeViewItem> rows,
bool expandCategories)
{
ClearRows(rootItem, rows);
List<IDiffCategory> categories = diffTree.GetNodes();
if (categories == null)
return;
foreach (IDiffCategory category in categories)
{
if (category is CategoryGroup &&
((CategoryGroup)category).CategoryType == CategoryGroup.Type.MergeCategory)
{
AddMergeCategory(
rootItem,
category,
rows,
treeViewItemIds,
treeView,
expandCategories);
}
if (category is ChangeCategory)
{
AddChangeCategory(
rootItem,
category,
rows,
treeViewItemIds,
treeView,
expandCategories);
}
}
if (!expandCategories)
return;
treeView.state.expandedIDs = treeViewItemIds.GetCategoryIds();
}
static void ClearRows(
TreeViewItem rootItem,
List<TreeViewItem> rows)
{
if (rootItem.hasChildren)
rootItem.children.Clear();
rows.Clear();
}
static void AddMergeCategory(
TreeViewItem rootItem,
IDiffCategory category,
List<TreeViewItem> rows,
TreeViewItemIds<IDiffCategory, ITreeViewNode> treeViewItemIds,
TreeView treeView,
bool expandCategories)
{
int categoryId;
if (!treeViewItemIds.TryGetCategoryItemId(category, out categoryId))
categoryId = treeViewItemIds.AddCategoryItem(category);
MergeCategoryTreeViewItem mergeCategoryTreeViewItem =
new MergeCategoryTreeViewItem(
categoryId,
rootItem.depth + 1,
(CategoryGroup)category);
rootItem.AddChild(mergeCategoryTreeViewItem);
rows.Add(mergeCategoryTreeViewItem);
if (!expandCategories &&
!treeView.IsExpanded(mergeCategoryTreeViewItem.id))
return;
for (int i = 0; i < category.GetChildrenCount(); i++)
{
IDiffCategory child = (IDiffCategory)((ITreeViewNode)category)
.GetChild(i);
AddChangeCategory(
mergeCategoryTreeViewItem,
child,
rows,
treeViewItemIds,
treeView,
expandCategories);
}
}
static void AddChangeCategory(
TreeViewItem parentItem,
IDiffCategory category,
List<TreeViewItem> rows,
TreeViewItemIds<IDiffCategory, ITreeViewNode> treeViewItemIds,
TreeView treeView,
bool expandCategories)
{
int categoryId;
if (!treeViewItemIds.TryGetCategoryItemId(category, out categoryId))
categoryId = treeViewItemIds.AddCategoryItem(category);
ChangeCategoryTreeViewItem changeCategoryTreeViewItem =
new ChangeCategoryTreeViewItem(
categoryId,
parentItem.depth + 1,
(ChangeCategory)category);
parentItem.AddChild(changeCategoryTreeViewItem);
rows.Add(changeCategoryTreeViewItem);
if (!expandCategories &&
!treeView.IsExpanded(changeCategoryTreeViewItem.id))
return;
AddClientDiffs(
changeCategoryTreeViewItem,
(ITreeViewNode)category,
rows,
treeViewItemIds);
}
static void AddClientDiffs(
TreeViewItem parentItem,
ITreeViewNode parentNode,
List<TreeViewItem> rows,
TreeViewItemIds<IDiffCategory, ITreeViewNode> treeViewItemIds)
{
for (int i = 0; i < parentNode.GetChildrenCount(); i++)
{
ITreeViewNode child = parentNode.GetChild(i);
int nodeId;
if (!treeViewItemIds.TryGetInfoItemId(child, out nodeId))
nodeId = treeViewItemIds.AddInfoItem(child);
TreeViewItem changeTreeViewItem =
new ClientDiffTreeViewItem(
nodeId,
parentItem.depth + 1,
(ClientDiffInfo)child);
parentItem.AddChild(changeTreeViewItem);
rows.Add(changeTreeViewItem);
}
}
static void TreeViewItemGUI(
TreeViewItem item,
Rect rowRect,
float rowHeight,
UnityDiffTree diffTree,
bool isSelected,
bool isFocused)
{
if (item is MergeCategoryTreeViewItem)
{
MergeCategoryTreeViewItemGUI(
rowRect,
(MergeCategoryTreeViewItem)item,
isSelected,
isFocused);
return;
}
if (item is ChangeCategoryTreeViewItem)
{
ChangeCategoryTreeViewItemGUI(
rowRect,
(ChangeCategoryTreeViewItem)item,
isSelected,
isFocused);
return;
}
if (item is ClientDiffTreeViewItem)
{
ClientDiffTreeViewItemGUI(
rowRect,
rowHeight,
diffTree,
(ClientDiffTreeViewItem)item,
isSelected,
isFocused);
}
}
static void MergeCategoryTreeViewItemGUI(
Rect rowRect,
MergeCategoryTreeViewItem item,
bool isSelected,
bool isFocused)
{
string label = item.Category.CategoryName;
string infoLabel = PlasticLocalization.Name.ItemsCount.GetString(
item.Category.GetChildrenCount());
DrawTreeViewItem.ForIndentedItem(
rowRect,
item.depth,
label,
infoLabel,
isSelected,
isFocused);
}
static void ChangeCategoryTreeViewItemGUI(
Rect rowRect,
ChangeCategoryTreeViewItem item,
bool isSelected,
bool isFocused)
{
string label = item.Category.CategoryName;
string infoLabel = PlasticLocalization.Name.ItemsCount.GetString(
item.Category.GetChildrenCount());
DrawTreeViewItem.ForIndentedItem(
rowRect,
item.depth,
label,
infoLabel,
isSelected,
isFocused);
}
static void ClientDiffTreeViewItemGUI(
Rect rowRect,
float rowHeight,
UnityDiffTree diffTree,
ClientDiffTreeViewItem item,
bool isSelected,
bool isFocused)
{
string label = ClientDiffView.GetColumnText(
item.Difference.DiffWithMount.Mount.RepSpec,
item.Difference.DiffWithMount.Difference,
PlasticLocalization.GetString(PlasticLocalization.Name.PathColumn));
if (diffTree.HasMeta(item.Difference))
label = string.Concat(label, UnityConstants.TREEVIEW_META_LABEL);
Texture icon = GetClientDiffIcon(
item.Difference.DiffWithMount.Difference.IsDirectory,
label);
DrawTreeViewItem.ForItemCell(
rowRect,
rowHeight,
item.depth,
icon,
null,
null,
label,
isSelected,
isFocused,
false,
false,
false,
DrawTreeViewItem.TextTrimming.Path);
}
static Texture GetClientDiffIcon(bool isDirectory, string path)
{
if (isDirectory)
return Images.GetFolderIcon();
return Images.GetFileIconFromCmPath(path);
}
bool mExpandCategories;
TreeViewItemIds<IDiffCategory, ITreeViewNode> mTreeViewItemIds =
new TreeViewItemIds<IDiffCategory, ITreeViewNode>();
UnityDiffTree mDiffTree = new UnityDiffTree();
readonly DelayedActionBySecondsRunner mDelayedFilterAction;
readonly DelayedActionBySecondsRunner mDelayedSelectionRunner;
static readonly List<string> ColumnsNames = new List<string> {
PlasticLocalization.GetString(PlasticLocalization.Name.PathColumn)};
readonly DiffTreeViewMenu mMenu;
readonly Action mAfterItemsChangedAction;
readonly Action mDelayedSelectionChangedAction;
readonly Action mDoubleClickAction;
const float ROW_RIGHT_MARGIN = 8f;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ba4e6e12f66973142a87299287cb34dc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,329 @@
using Codice.Utils;
using UnityEditor;
using UnityEngine;
using PlasticGui;
using PlasticGui.WorkspaceWindow.Diff;
using Unity.PlasticSCM.Editor.UI;
namespace Unity.PlasticSCM.Editor.Views.Diff
{
internal class DiffTreeViewMenu
{
internal GenericMenu Menu { get { return mMenu; } }
internal interface IMetaMenuOperations
{
bool SelectionHasMeta();
void DiffMeta();
void HistoryMeta();
}
internal DiffTreeViewMenu(
IDiffTreeViewMenuOperations operations,
IMetaMenuOperations metaMenuOperations)
{
mOperations = operations;
mMetaMenuOperations = metaMenuOperations;
BuildComponents();
}
internal void Popup()
{
mMenu = new GenericMenu();
UpdateMenuItems(mMenu);
mMenu.ShowAsContext();
}
internal bool ProcessKeyActionIfNeeded(Event e)
{
DiffTreeViewMenuOperations operationToExecute = GetMenuOperation(e);
if (operationToExecute == DiffTreeViewMenuOperations.None)
return false;
SelectedDiffsGroupInfo info =
mOperations.GetSelectedDiffsGroupInfo();
DiffTreeViewMenuOperations operations =
DiffTreeViewMenuUpdater.GetAvailableMenuOperations(info);
if (!operations.HasFlag(operationToExecute))
return false;
ProcessMenuOperation(operationToExecute);
return true;
}
void SaveRevisionAsMenuItem_Click()
{
mOperations.SaveRevisionAs();
}
void DiffMenuItem_Click()
{
mOperations.Diff();
}
void DiffMetaMenuItem_Click()
{
mMetaMenuOperations.DiffMeta();
}
void HistoryMenuItem_Click()
{
mOperations.History();
}
void HistoryMetaMenuItem_Click()
{
mMetaMenuOperations.HistoryMeta();
}
void RevertMenuItem_Click()
{
mOperations.RevertChanges();
}
void UndeleteMenuItem_Click()
{
mOperations.Undelete();
}
void UndeleteToSpecifiedPathMenuItem_Click()
{
mOperations.UndeleteToSpecifiedPaths();
}
void CopyFilePathMenuItem_Click()
{
mOperations.CopyFilePath(relativePath: false);
}
void CopyRelativeFilePathMenuItem_Click()
{
mOperations.CopyFilePath(relativePath: true);
}
void UpdateMenuItems(GenericMenu menu)
{
SelectedDiffsGroupInfo groupInfo =
mOperations.GetSelectedDiffsGroupInfo();
DiffTreeViewMenuOperations operations =
DiffTreeViewMenuUpdater.GetAvailableMenuOperations(groupInfo);
if (operations == DiffTreeViewMenuOperations.None)
{
menu.AddDisabledItem(GetNoActionMenuItemContent());
return;
}
bool isMultipleSelection = groupInfo.SelectedItemsCount > 1;
bool selectionHasMeta = mMetaMenuOperations.SelectionHasMeta();
if (operations.HasFlag(DiffTreeViewMenuOperations.SaveAs))
menu.AddItem(mSaveRevisionAsMenuItemContent, false, SaveRevisionAsMenuItem_Click);
if (operations.HasFlag(DiffTreeViewMenuOperations.Diff))
menu.AddItem(mDiffMenuItemContent, false, DiffMenuItem_Click);
else
menu.AddDisabledItem(mDiffMenuItemContent, false);
if (mMetaMenuOperations.SelectionHasMeta())
{
if (operations.HasFlag(DiffTreeViewMenuOperations.Diff))
menu.AddItem(mDiffMetaMenuItemContent, false, DiffMetaMenuItem_Click);
else
menu.AddDisabledItem(mDiffMetaMenuItemContent);
}
menu.AddSeparator(string.Empty);
if (operations.HasFlag(DiffTreeViewMenuOperations.History))
menu.AddItem(mViewHistoryMenuItemContent, false, HistoryMenuItem_Click);
else
menu.AddDisabledItem(mViewHistoryMenuItemContent, false);
if (mMetaMenuOperations.SelectionHasMeta())
{
if (operations.HasFlag(DiffTreeViewMenuOperations.History))
menu.AddItem(mViewHistoryMetaMenuItemContent, false, HistoryMetaMenuItem_Click);
else
menu.AddDisabledItem(mViewHistoryMetaMenuItemContent, false);
}
if (operations.HasFlag(DiffTreeViewMenuOperations.RevertChanges))
{
menu.AddSeparator(string.Empty);
mRevertMenuItemContent.text = GetRevertMenuItemText(
isMultipleSelection,
selectionHasMeta);
menu.AddItem(mRevertMenuItemContent, false, RevertMenuItem_Click);
}
if (operations.HasFlag(DiffTreeViewMenuOperations.Undelete) ||
operations.HasFlag(DiffTreeViewMenuOperations.UndeleteToSpecifiedPaths))
{
menu.AddSeparator(string.Empty);
}
if (operations.HasFlag(DiffTreeViewMenuOperations.Undelete))
{
mUndeleteMenuItemContent.text = GetUndeleteMenuItemText(
isMultipleSelection,
selectionHasMeta);
menu.AddItem(mUndeleteMenuItemContent, false, UndeleteMenuItem_Click);
}
if (operations.HasFlag(DiffTreeViewMenuOperations.UndeleteToSpecifiedPaths))
{
mUndeleteToSpecifiedPathMenuItemContent.text = GetUndeleteToSpecifiedPathMenuItemText(
isMultipleSelection,
selectionHasMeta);
menu.AddItem(mUndeleteToSpecifiedPathMenuItemContent, false, UndeleteToSpecifiedPathMenuItem_Click);
}
if (operations.HasFlag(DiffTreeViewMenuOperations.CopyFilePath))
{
menu.AddSeparator(string.Empty);
menu.AddItem(
mCopyFilePathMenuItemContent, false, CopyFilePathMenuItem_Click);
menu.AddItem(
mCopyRelativeFilePathMenuItemContent, false, CopyRelativeFilePathMenuItem_Click);
}
}
GUIContent GetNoActionMenuItemContent()
{
if (mNoActionMenuItemContent == null)
{
mNoActionMenuItemContent = new GUIContent(
PlasticLocalization.GetString(PlasticLocalization.
Name.NoActionMenuItem));
}
return mNoActionMenuItemContent;
}
static string GetRevertMenuItemText(
bool isMultipleSelection,
bool selectionHasMeta)
{
if (selectionHasMeta && !isMultipleSelection)
return PlasticLocalization.GetString(PlasticLocalization.Name.RevertThisFilePlusMeta);
return isMultipleSelection ?
PlasticLocalization.GetString(PlasticLocalization.Name.RevertSelectedFiles) :
PlasticLocalization.GetString(PlasticLocalization.Name.RevertThisFile);
}
static string GetUndeleteMenuItemText(
bool isMultipleSelection,
bool selectionHasMeta)
{
if (selectionHasMeta && !isMultipleSelection)
return PlasticLocalization.GetString(PlasticLocalization.Name.UndeleteRevisionPlusMeta);
return isMultipleSelection ?
PlasticLocalization.GetString(PlasticLocalization.Name.UndeleteSelectedRevisions) :
PlasticLocalization.GetString(PlasticLocalization.Name.UndeleteRevisions);
}
static string GetUndeleteToSpecifiedPathMenuItemText(
bool isMultipleSelection,
bool selectionHasMeta)
{
if (selectionHasMeta && !isMultipleSelection)
return PlasticLocalization.GetString(PlasticLocalization.Name.UndeleteRevisionPlusMetaPath);
return isMultipleSelection ?
PlasticLocalization.GetString(PlasticLocalization.Name.UndeleteSelectedRevisionsPaths) :
PlasticLocalization.GetString(PlasticLocalization.Name.UndeleteRevisionPath);
}
void ProcessMenuOperation(DiffTreeViewMenuOperations operationToExecute)
{
if (operationToExecute == DiffTreeViewMenuOperations.SaveAs)
{
SaveRevisionAsMenuItem_Click();
return;
}
if (operationToExecute == DiffTreeViewMenuOperations.Diff)
{
DiffMenuItem_Click();
return;
}
if (operationToExecute == DiffTreeViewMenuOperations.History)
{
HistoryMenuItem_Click();
}
}
static DiffTreeViewMenuOperations GetMenuOperation(Event e)
{
if (Keyboard.IsControlOrCommandKeyPressed(e) && Keyboard.IsKeyPressed(e, KeyCode.D))
return DiffTreeViewMenuOperations.Diff;
bool isHistoryShortcut = PlatformIdentifier.IsMac()
? Keyboard.IsControlOrCommandAndShiftKeyPressed(e) && Keyboard.IsKeyPressed(e, KeyCode.H)
: Keyboard.IsControlOrCommandKeyPressed(e) && Keyboard.IsKeyPressed(e, KeyCode.H);
if (isHistoryShortcut)
return DiffTreeViewMenuOperations.History;
return DiffTreeViewMenuOperations.None;
}
void BuildComponents()
{
mSaveRevisionAsMenuItemContent = new GUIContent(
PlasticLocalization.GetString(PlasticLocalization.Name.DiffMenuItemSaveRevisionAs));
mDiffMenuItemContent = new GUIContent(
string.Format("{0} {1}",
PlasticLocalization.GetString(PlasticLocalization.Name.DiffMenuItem),
GetPlasticShortcut.ForDiff()));
mDiffMetaMenuItemContent = new GUIContent(
PlasticLocalization.GetString(PlasticLocalization.Name.DiffMetaMenuItem));
mViewHistoryMenuItemContent = new GUIContent(
string.Format("{0} {1}",
PlasticLocalization.GetString(PlasticLocalization.Name.ViewHistoryMenuItem),
GetPlasticShortcut.ForHistory()));
mViewHistoryMetaMenuItemContent = new GUIContent(
PlasticLocalization.GetString(PlasticLocalization.Name.ViewHistoryMetaMenuItem));
mRevertMenuItemContent = new GUIContent();
mUndeleteMenuItemContent = new GUIContent();
mUndeleteToSpecifiedPathMenuItemContent = new GUIContent();
mCopyFilePathMenuItemContent = new GUIContent(PlasticLocalization.Name.CopyFilePathMenuItem.GetString());
mCopyRelativeFilePathMenuItemContent =
new GUIContent(PlasticLocalization.Name.CopyRelativeFilePathMenuItem.GetString());
}
GenericMenu mMenu;
GUIContent mNoActionMenuItemContent;
GUIContent mSaveRevisionAsMenuItemContent;
GUIContent mDiffMenuItemContent;
GUIContent mDiffMetaMenuItemContent;
GUIContent mViewHistoryMenuItemContent;
GUIContent mViewHistoryMetaMenuItemContent;
GUIContent mRevertMenuItemContent;
GUIContent mUndeleteMenuItemContent;
GUIContent mUndeleteToSpecifiedPathMenuItemContent;
GUIContent mCopyFilePathMenuItemContent;
GUIContent mCopyRelativeFilePathMenuItemContent;
readonly IDiffTreeViewMenuOperations mOperations;
readonly IMetaMenuOperations mMetaMenuOperations;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2c9c0041347ae4e4cb794a3da850fa79
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,33 @@
using System.Collections.Generic;
using Codice.Utils;
using PlasticGui.WorkspaceWindow.Diff;
namespace Unity.PlasticSCM.Editor.Views.Diff
{
internal static class GetClientDiffInfos
{
internal static List<ClientDiffInfo> FromCategories(List<IDiffCategory> categories)
{
List<ClientDiffInfo> result = new List<ClientDiffInfo>();
foreach (ITreeViewNode node in categories)
AddClientDiffInfos(node, result);
return result;
}
static void AddClientDiffInfos(ITreeViewNode node, List<ClientDiffInfo> result)
{
if (node is ClientDiffInfo)
{
result.Add((ClientDiffInfo)node);
return;
}
for (int i = 0; i < node.GetChildrenCount(); i++)
AddClientDiffInfos(node.GetChild(i), result);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5ab43506dddfc244ab5b44585140c5a6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,21 @@
using UnityEditor.IMGUI.Controls;
using PlasticGui.WorkspaceWindow.Diff;
#if UNITY_6000_2_OR_NEWER
using TreeViewItem = UnityEditor.IMGUI.Controls.TreeViewItem<int>;
#endif
namespace Unity.PlasticSCM.Editor.Views.Diff
{
internal class MergeCategoryTreeViewItem : TreeViewItem
{
internal CategoryGroup Category { get; private set; }
internal MergeCategoryTreeViewItem(
int id, int depth, CategoryGroup categoryGroup)
: base(id, depth, categoryGroup.GetHeaderText())
{
Category = categoryGroup;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 923dacaaac477a941a4a5c7c1657a250
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,233 @@
using System.Collections.Generic;
using Codice.Client.Commands;
using Codice.Client.Common;
using Codice.CM.Common;
using Codice.Utils;
using PlasticGui;
using PlasticGui.Diff;
using PlasticGui.WorkspaceWindow.Diff;
namespace Unity.PlasticSCM.Editor.Views.Diff
{
internal class UnityDiffTree
{
internal UnityDiffTree()
{
mInnerTree = new DiffTree();
mMetaCache = new MetaCache();
}
internal void BuildCategories(
WorkspaceInfo wkInfo,
List<ClientDiff> diffs,
BranchResolver brResolver,
bool skipMergeTracking)
{
mInnerTree.BuildCategories(
RevisionInfoCodeReviewAdapter.CalculateCodeReviewEntries(
wkInfo,
diffs,
brResolver,
skipMergeTracking),
brResolver);
mMetaCache.Build(mInnerTree.GetNodes());
}
internal List<IDiffCategory> GetNodes()
{
return mInnerTree.GetNodes();
}
internal bool HasMeta(ClientDiffInfo difference)
{
return mMetaCache.ContainsMeta(difference);
}
internal ClientDiffInfo GetMetaDiff(ClientDiffInfo diff)
{
return mMetaCache.GetExistingMeta(diff);
}
internal void FillWithMeta(List<ClientDiffInfo> diffs)
{
diffs.AddRange(
mMetaCache.GetExistingMeta(diffs));
}
internal void Sort(string key, bool sortAscending)
{
mInnerTree.Sort(key, sortAscending);
}
internal void Filter(Filter filter, List<string> columnNames)
{
mInnerTree.Filter(filter, columnNames);
}
MetaCache mMetaCache = new MetaCache();
DiffTree mInnerTree;
class MetaCache
{
internal void Build(List<IDiffCategory> categories)
{
mCache.Clear();
HashSet<string> indexedKeys = BuildIndexedKeys(
GetClientDiffInfos.FromCategories(categories));
for (int i = 0; i < categories.Count; i++)
{
ExtractToMetaCache(
(ITreeViewNode)categories[i],
i,
mCache,
indexedKeys);
}
}
internal bool ContainsMeta(ClientDiffInfo diff)
{
return mCache.ContainsKey(
BuildKey.ForMetaDiff(diff));
}
internal ClientDiffInfo GetExistingMeta(ClientDiffInfo diff)
{
ClientDiffInfo result;
if (!mCache.TryGetValue(BuildKey.ForMetaDiff(diff), out result))
return null;
return result;
}
internal List<ClientDiffInfo> GetExistingMeta(List<ClientDiffInfo> diffs)
{
List<ClientDiffInfo> result = new List<ClientDiffInfo>();
foreach (ClientDiffInfo diff in diffs)
{
string key = BuildKey.ForMetaDiff(diff);
ClientDiffInfo metaDiff;
if (!mCache.TryGetValue(key, out metaDiff))
continue;
result.Add(metaDiff);
}
return result;
}
static void ExtractToMetaCache(
ITreeViewNode node,
int nodeIndex,
Dictionary<string, ClientDiffInfo> cache,
HashSet<string> indexedKeys)
{
if (node is ClientDiffInfo)
{
ClientDiffInfo diff = (ClientDiffInfo)node;
string path = diff.DiffWithMount.Difference.Path;
if (!MetaPath.IsMetaPath(path))
return;
string realPath = MetaPath.GetPathFromMetaPath(path);
if (!indexedKeys.Contains(BuildKey.BuildCacheKey(
BuildKey.GetCategoryGroup(diff),
BuildKey.GetChangeCategory(diff),
realPath)))
return;
// found foo.c and foo.c.meta
// with the same chage types - move .meta to cache
cache.Add(BuildKey.ForDiff(diff), diff);
((ChangeCategory)node.GetParent()).RemoveDiffAt(nodeIndex);
}
for (int i = node.GetChildrenCount() - 1; i >= 0; i--)
{
ExtractToMetaCache(
node.GetChild(i),
i,
cache,
indexedKeys);
}
}
HashSet<string> BuildIndexedKeys(List<ClientDiffInfo> diffs)
{
HashSet<string> result = new HashSet<string>();
foreach (ClientDiffInfo diff in diffs)
{
if (MetaPath.IsMetaPath(diff.DiffWithMount.Difference.Path))
continue;
result.Add(BuildKey.ForDiff(diff));
}
return result;
}
Dictionary<string, ClientDiffInfo> mCache =
new Dictionary<string, ClientDiffInfo>();
static class BuildKey
{
internal static string ForDiff(
ClientDiffInfo diff)
{
return BuildCacheKey(
GetCategoryGroup(diff),
GetChangeCategory(diff),
diff.DiffWithMount.Difference.Path);
}
internal static string ForMetaDiff(
ClientDiffInfo diff)
{
return BuildCacheKey(
GetCategoryGroup(diff),
GetChangeCategory(diff),
MetaPath.GetMetaPath(diff.DiffWithMount.Difference.Path));
}
internal static string BuildCacheKey(
CategoryGroup categoryGroup,
ChangeCategory changeCategory,
string path)
{
string result = string.Concat(changeCategory.Type, ":", path);
if (categoryGroup == null)
return result;
return string.Concat(categoryGroup.GetHeaderText(), ":", result);
}
internal static ChangeCategory GetChangeCategory(ClientDiffInfo diff)
{
return (ChangeCategory)diff.GetParent();
}
internal static CategoryGroup GetCategoryGroup(ClientDiffInfo diff)
{
ChangeCategory changeCategory = GetChangeCategory(diff);
ITreeViewNode categoryGroup = changeCategory.GetParent();
if (categoryGroup == null)
return null;
return (CategoryGroup)categoryGroup;
}
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e89b1e9e9f1060b4f817977507831248
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: