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,146 @@
using System;
using System.Collections.Generic;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
using PlasticGui;
using Unity.PlasticSCM.Editor.UI.Tree;
namespace Unity.PlasticSCM.Editor.Views.History
{
internal enum HistoryListColumn
{
Comment,
CreationDate,
Type,
CreatedBy,
Changeset,
Branch,
}
[Serializable]
internal class HistoryListHeaderState : MultiColumnHeaderState, ISerializationCallbackReceiver
{
internal static HistoryListHeaderState GetDefault()
{
return new HistoryListHeaderState(BuildColumns());
}
internal static List<string> GetColumnNames()
{
List<string> result = new List<string>();
result.Add(PlasticLocalization.GetString(PlasticLocalization.Name.CommentColumn));
result.Add(PlasticLocalization.GetString(PlasticLocalization.Name.CreationDateColumn));
result.Add(PlasticLocalization.GetString(PlasticLocalization.Name.TypeColumn));
result.Add(PlasticLocalization.GetString(PlasticLocalization.Name.CreatedByColumn));
result.Add(PlasticLocalization.GetString(PlasticLocalization.Name.ChangesetColumn));
result.Add(PlasticLocalization.GetString(PlasticLocalization.Name.BranchColumn));
return result;
}
internal static string GetColumnName(HistoryListColumn column)
{
switch (column)
{
case HistoryListColumn.Comment:
return PlasticLocalization.GetString(PlasticLocalization.Name.CommentColumn);
case HistoryListColumn.CreationDate:
return PlasticLocalization.GetString(PlasticLocalization.Name.CreationDateColumn);
case HistoryListColumn.Type:
return PlasticLocalization.GetString(PlasticLocalization.Name.TypeColumn);
case HistoryListColumn.CreatedBy:
return PlasticLocalization.GetString(PlasticLocalization.Name.CreatedByColumn);
case HistoryListColumn.Changeset:
return PlasticLocalization.GetString(PlasticLocalization.Name.ChangesetColumn);
case HistoryListColumn.Branch:
return PlasticLocalization.GetString(PlasticLocalization.Name.BranchColumn);
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 = 400,
headerContent = new GUIContent(
GetColumnName(HistoryListColumn.Comment)),
minWidth = 100,
sortingArrowAlignment = TextAlignment.Right
},
new Column()
{
width = 250,
headerContent = new GUIContent(
GetColumnName(HistoryListColumn.CreationDate)),
minWidth = 100,
sortingArrowAlignment = TextAlignment.Right
},
new Column()
{
width = 120,
headerContent = new GUIContent(
GetColumnName(HistoryListColumn.Type)),
minWidth = 50,
},
new Column()
{
width = 250,
headerContent = new GUIContent(
GetColumnName(HistoryListColumn.CreatedBy)),
minWidth = 100,
sortingArrowAlignment = TextAlignment.Right
},
new Column()
{
width = 100,
headerContent = new GUIContent(
GetColumnName(HistoryListColumn.Changeset)),
minWidth = 50,
sortingArrowAlignment = TextAlignment.Right
},
new Column()
{
width = 200,
headerContent = new GUIContent(
GetColumnName(HistoryListColumn.Branch)),
minWidth = 100,
sortingArrowAlignment = TextAlignment.Right
},
};
}
HistoryListHeaderState(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: 5b6e8a80709e2264eb383ef6b40e181f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,487 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
using Codice.CM.Common;
using PlasticGui;
using PlasticGui.WorkspaceWindow.History;
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.History
{
internal class HistoryListView : PlasticTreeView
{
internal GenericMenu Menu { get { return mMenu.Menu; } }
internal HistoryListView(
string wkPath,
HistoryListHeaderState headerState,
HistoryListViewMenu menu,
List<string> columnNames,
Action delayedSelectionChangedAction,
Action doubleClickAction,
Action<IEnumerable<RepObjectInfo>> afterItemsChangedAction)
{
mWkPath = wkPath;
mMenu = menu;
mColumnNames = columnNames;
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);
}
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 IList<TreeViewItem> BuildRows(
TreeViewItem rootItem)
{
if (mRevisionsList == null)
{
ClearRows(rootItem, mRows);
return mRows;
}
RegenerateRows(
mListViewItemIds,
mRevisionsList,
rootItem,
mRows);
return mRows;
}
protected override void SearchChanged(string newSearch)
{
mDelayedFilterAction.Run();
}
protected override void ContextClickedItem(int id)
{
mMenu.Popup();
Repaint();
}
protected override void RowGUI(RowGUIArgs args)
{
if (args.item is HistoryListViewItem)
{
HistoryListViewItem historyListViewItem = (HistoryListViewItem)args.item;
HistoryListViewItemGUI(
mWkPath,
mRepSpec,
rowHeight,
historyListViewItem,
args,
mLoadedRevisionId == historyListViewItem.Revision.Id,
Repaint);
return;
}
base.RowGUI(args);
}
protected override void DoubleClickedItem(int id)
{
mDoubleClickAction();
}
protected override void SelectionChanged(IList<int> selectedIds)
{
mDelayedSelectionRunner.Run();
}
void DelayedSelectionChanged()
{
if (!HasSelection())
return;
mDelayedSelectionChangedAction();
}
internal void BuildModel(
RepositorySpec repSpec,
HistoryRevisionList historyRevisionList,
long loadedRevisionId)
{
mListViewItemIds.Clear();
mRepSpec = repSpec;
mRevisionsList = historyRevisionList;
mLoadedRevisionId = loadedRevisionId;
}
internal void Refilter()
{
if (mRevisionsList == null)
return;
Filter filter = new Filter(searchString);
mRevisionsList.Filter(filter, mColumnNames, null, null);
mAfterItemsChangedAction(mRevisionsList.GetRevisions());
}
internal void Sort()
{
if (mRevisionsList == null)
return;
int sortedColumnIdx = multiColumnHeader.state.sortedColumnIndex;
bool sortAscending = multiColumnHeader.IsSortedAscending(sortedColumnIdx);
mRevisionsList.Sort(
mColumnNames[sortedColumnIdx],
sortAscending);
}
internal long GetLoadedRevisionId()
{
return mLoadedRevisionId;
}
internal List<RepObjectInfo> GetSelectedRepObjectInfos()
{
List<RepObjectInfo> result = new List<RepObjectInfo>();
IList<int> selectedIds = GetSelection();
if (selectedIds.Count == 0)
return result;
foreach (KeyValuePair<RepObjectInfo, int> item
in mListViewItemIds.GetInfoItems())
{
if (!selectedIds.Contains(item.Value))
continue;
result.Add(item.Key);
}
return result;
}
internal List<RepObjectInfo> GetAllRepObjectInfos()
{
List<RepObjectInfo> result = new List<RepObjectInfo>();
foreach (KeyValuePair<RepObjectInfo, int> item
in mListViewItemIds.GetInfoItems())
{
result.Add(item.Key);
}
return result;
}
internal List<HistoryRevision> GetSelectedHistoryRevisions()
{
return GetSelectedRepObjectInfos().OfType<HistoryRevision>().ToList();
}
internal long GetSelectedChangesetId()
{
List<RepObjectInfo> repObjectInfos = GetSelectedRepObjectInfos();
foreach (RepObjectInfo info in repObjectInfos)
{
if (info is HistoryRevision)
return ((HistoryRevision)info).ChangeSet;
if (info is MoveRealizationInfo)
return ((MoveRealizationInfo)info).DstDirRev.Changeset;
if (info is RemovedRealizationInfo)
return ((RemovedRealizationInfo)info).DirRev.Changeset;
}
return -1;
}
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);
}
internal HistoryRevision GetRevisionFromId(long revisionId)
{
return mRevisionsList.
GetRevisions().
SingleOrDefault(r => r.Id == revisionId) as HistoryRevision;
}
int GetTreeIdForItem(RepObjectInfo currentRepObjectInfo)
{
foreach (KeyValuePair<RepObjectInfo, int> item in mListViewItemIds.GetInfoItems())
{
if (!currentRepObjectInfo.Equals(item.Key))
continue;
if (!currentRepObjectInfo.GUID.Equals(item.Key.GUID))
continue;
return item.Value;
}
return -1;
}
void DelayedSearchChanged()
{
Refilter();
Sort();
Reload();
TableViewOperations.ScrollToSelection(this);
}
void SortingChanged(MultiColumnHeader multiColumnHeader)
{
Sort();
Reload();
}
static void RegenerateRows(
ListViewItemIds<RepObjectInfo> listViewItemIds,
HistoryRevisionList revisions,
TreeViewItem rootItem,
List<TreeViewItem> rows)
{
ClearRows(rootItem, rows);
if (revisions.GetCount() == 0)
return;
foreach (RepObjectInfo objectInfo in revisions.GetRevisions())
{
int objectId;
if (!listViewItemIds.TryGetInfoItemId(objectInfo, out objectId))
objectId = listViewItemIds.AddInfoItem(objectInfo);
HistoryListViewItem changesetListViewItem =
new HistoryListViewItem(objectId, objectInfo);
rootItem.AddChild(changesetListViewItem);
rows.Add(changesetListViewItem);
}
}
static void ClearRows(
TreeViewItem rootItem,
List<TreeViewItem> rows)
{
if (rootItem.hasChildren)
rootItem.children.Clear();
rows.Clear();
}
static void HistoryListViewItemGUI(
string wkPath,
RepositorySpec repSpec,
float rowHeight,
HistoryListViewItem item,
RowGUIArgs args,
bool isBoldText,
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;
}
HistoryListColumn column =
(HistoryListColumn)args.GetColumn(visibleColumnIdx);
HistoryListViewItemCellGUI(
cellRect,
rowHeight,
wkPath,
repSpec,
item,
column,
avatarLoadedAction,
args.selected,
args.focused,
isBoldText);
}
}
static void HistoryListViewItemCellGUI(
Rect rect,
float rowHeight,
string wkPath,
RepositorySpec repSpec,
HistoryListViewItem item,
HistoryListColumn column,
Action avatarLoadedAction,
bool isSelected,
bool isFocused,
bool isBoldText)
{
string columnText = HistoryInfoView.GetColumnText(
wkPath, repSpec, item.Revision,
HistoryListHeaderState.GetColumnName(column));
string userName = PlasticGui.Plastic.API.GetUserName(repSpec.Server, item.Revision.Owner);
bool isPurged = IsPurged(item);
bool isDisabled = isPurged;
if (column == HistoryListColumn.Comment)
{
DrawTreeViewItem.ForItemCell(
rect,
rowHeight,
-1,
GetAvatar.ForEmail(userName, avatarLoadedAction),
isPurged ? PlasticLocalization.Name.PurgedRevision.GetString() : userName,
isPurged ? Images.GetDeletedLocalOverlayIcon() : null,
columnText,
isSelected,
isFocused,
isBoldText,
false,
isDisabled);
return;
}
if (column == HistoryListColumn.Type)
{
DrawTreeViewItem.ForItemCell(
rect,
rowHeight,
-1,
null,
null,
null,
GetRevisionText(item.Revision),
isSelected,
isFocused,
isBoldText,
false,
isDisabled);
return;
}
if (column == HistoryListColumn.CreationDate)
{
DrawTreeViewItem.ForLabel(
rect,
new GUIContent(
Time.GetLongTimeAgoString(item.Revision.LocalTimeStamp),
columnText),
isSelected,
isFocused,
isBoldText,
isDisabled);
return;
}
if (column == HistoryListColumn.Branch)
{
DrawTreeViewItem.ForSecondaryLabel(
rect, columnText, isSelected, isFocused, isBoldText, isDisabled);
return;
}
DrawTreeViewItem.ForLabel(
rect, columnText, isSelected, isFocused, isBoldText, isDisabled);
}
static bool IsPurged(HistoryListViewItem item)
{
return item.Revision is HistoryRevision &&
((HistoryRevision)item.Revision).DataStatus ==
HistoryRevision.DataAvailability.Purged;
}
static string GetRevisionText(RepObjectInfo revision)
{
if (revision is MoveRealizationInfo)
return PlasticLocalization.Name.MovedDiffCategory.GetString();
if (revision is RemovedRealizationInfo)
return PlasticLocalization.Name.DeletedDiffCategory.GetString();
if (((HistoryRevision)revision).ParentRevisionId == -1)
return PlasticLocalization.Name.AddedDiffCategory.GetString();
return PlasticLocalization.Name.ChangedDiffCategory.GetString();
}
ListViewItemIds<RepObjectInfo> mListViewItemIds = new ListViewItemIds<RepObjectInfo>();
HistoryRevisionList mRevisionsList;
long mLoadedRevisionId;
RepositorySpec mRepSpec;
readonly DelayedActionBySecondsRunner mDelayedFilterAction;
readonly DelayedActionBySecondsRunner mDelayedSelectionRunner;
readonly HistoryListViewMenu mMenu;
readonly List<string> mColumnNames;
readonly Action mDelayedSelectionChangedAction;
readonly Action mDoubleClickAction;
readonly Action<IEnumerable<RepObjectInfo>> mAfterItemsChangedAction;
readonly string mWkPath;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0ee2845d0d4db9a4a9e8f4f6d0fa4e5e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,23 @@

using UnityEditor.IMGUI.Controls;
using Codice.CM.Common;
#if UNITY_6000_2_OR_NEWER
using TreeViewItem = UnityEditor.IMGUI.Controls.TreeViewItem<int>;
#endif
namespace Unity.PlasticSCM.Editor.Views.History
{
internal class HistoryListViewItem : TreeViewItem
{
internal RepObjectInfo Revision { get; private set; }
internal HistoryListViewItem(int id, RepObjectInfo revision)
: base(id, 1)
{
Revision = revision;
displayName = id.ToString();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b1b8657301e8ead4a9389eda02c15883
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,225 @@
using UnityEditor;
using UnityEngine;
using PlasticGui;
using PlasticGui.WorkspaceWindow.History;
using PlasticGui.WorkspaceWindow.Open;
using Unity.PlasticSCM.Editor.UI;
namespace Unity.PlasticSCM.Editor.Views.History
{
internal class HistoryListViewMenu
{
internal GenericMenu Menu { get { return mMenu; } }
public interface IMenuOperations
{
long GetSelectedChangesetId();
}
internal HistoryListViewMenu(
IOpenMenuOperations openMenuOperations,
IHistoryViewMenuOperations operations,
IMenuOperations menuOperations)
{
mOpenMenuOperations = openMenuOperations;
mOperations = operations;
mMenuOperations = menuOperations;
BuildComponents();
}
internal void Popup()
{
mMenu = new GenericMenu();
UpdateMenuItems(mMenu);
mMenu.ShowAsContext();
}
internal bool ProcessKeyActionIfNeeded(Event e)
{
HistoryMenuOperations operationToExecute = GetMenuOperation(e);
if (operationToExecute == HistoryMenuOperations.None)
return false;
SelectedHistoryGroupInfo info =
mOperations.GetSelectedHistoryGroupInfo();
HistoryMenuOperations operations =
HistoryMenuUpdater.GetAvailableMenuOperations(info);
if (!operations.HasFlag(operationToExecute))
return false;
ProcessMenuOperation(operationToExecute);
return true;
}
void OpenRevisionMenu_Click()
{
mOpenMenuOperations.Open();
}
void OpenRevisionWithMenu_Click()
{
mOpenMenuOperations.OpenWith();
}
void SaveRevisionasMenu_Click()
{
mOperations.SaveRevisionAs();
}
void DiffWithPreviousMenuItem_Click()
{
mOperations.DiffWithPrevious();
}
void DiffSelectedRevisionsMenu_Click()
{
mOperations.DiffSelectedRevisions();
}
void DiffChangesetMenu_Click()
{
mOperations.DiffChangeset();
}
void RevertToThisRevisionMenu_Click()
{
mOperations.RevertToThisRevision();
}
void UpdateMenuItems(GenericMenu menu)
{
SelectedHistoryGroupInfo info =
mOperations.GetSelectedHistoryGroupInfo();
HistoryMenuOperations operations =
HistoryMenuUpdater.GetAvailableMenuOperations(info);
OpenMenuOperations openOperations =
GetOpenMenuOperations.ForHistoryView(info);
if (operations == HistoryMenuOperations.None &&
openOperations == OpenMenuOperations.None)
{
menu.AddDisabledItem(GetNoActionMenuItemContent(), false);
return;
}
if (openOperations.HasFlag(OpenMenuOperations.Open))
menu.AddItem(mOpenRevisionMenuItemContent, false, OpenRevisionMenu_Click);
else
menu.AddDisabledItem(mOpenRevisionMenuItemContent, false);
if (openOperations.HasFlag(OpenMenuOperations.OpenWith))
menu.AddItem(mOpenRevisionWithMenuItemContent, false, OpenRevisionWithMenu_Click);
else
menu.AddDisabledItem(mOpenRevisionWithMenuItemContent, false);
if (operations.HasFlag(HistoryMenuOperations.SaveAs))
menu.AddItem(mSaveRevisionAsMenuItemContent, false, SaveRevisionasMenu_Click);
else
menu.AddDisabledItem(mSaveRevisionAsMenuItemContent, false);
menu.AddSeparator(string.Empty);
if (operations.HasFlag(HistoryMenuOperations.DiffWithPrevious))
menu.AddItem(mDiffWithPreviousMenuItemContent, false, DiffWithPreviousMenuItem_Click);
if (operations.HasFlag(HistoryMenuOperations.DiffSelected))
menu.AddItem(mDiffSelectedRevisionsMenuItemContent, false, DiffSelectedRevisionsMenu_Click);
mDiffChangesetMenuItemContent.text =
PlasticLocalization.GetString(PlasticLocalization.Name.HistoryMenuItemDiffChangeset) +
string.Format(" {0}", GetSelectedChangesetName(mMenuOperations));
if (operations.HasFlag(HistoryMenuOperations.DiffChangeset))
menu.AddItem(mDiffChangesetMenuItemContent, false, DiffChangesetMenu_Click);
else
menu.AddDisabledItem(mDiffChangesetMenuItemContent, false);
menu.AddSeparator(string.Empty);
if (operations.HasFlag(HistoryMenuOperations.RevertTo))
menu.AddItem(mRevertToThisRevisionMenuItemContent, false, RevertToThisRevisionMenu_Click);
else
menu.AddDisabledItem(mRevertToThisRevisionMenuItemContent, false);
}
static HistoryMenuOperations GetMenuOperation(Event e)
{
if (Keyboard.IsControlOrCommandKeyPressed(e) && Keyboard.IsKeyPressed(e, KeyCode.D))
return HistoryMenuOperations.DiffWithPrevious;
return HistoryMenuOperations.None;
}
void ProcessMenuOperation(HistoryMenuOperations operationToExecute)
{
if (operationToExecute == HistoryMenuOperations.DiffWithPrevious)
{
DiffWithPreviousMenuItem_Click();
}
}
GUIContent GetNoActionMenuItemContent()
{
if (mNoActionMenuItemContent == null)
{
mNoActionMenuItemContent = new GUIContent(
PlasticLocalization.GetString(PlasticLocalization.
Name.NoActionMenuItem));
}
return mNoActionMenuItemContent;
}
static string GetSelectedChangesetName(IMenuOperations menuOperations)
{
long selectedChangesetId = menuOperations.GetSelectedChangesetId();
if (selectedChangesetId == -1)
return string.Empty;
return selectedChangesetId.ToString();
}
void BuildComponents()
{
mOpenRevisionMenuItemContent = new GUIContent(PlasticLocalization.
GetString(PlasticLocalization.Name.HistoryMenuItemOpen));
mOpenRevisionWithMenuItemContent = new GUIContent(PlasticLocalization.
GetString(PlasticLocalization.Name.HistoryMenuItemOpenWith));
mSaveRevisionAsMenuItemContent = new GUIContent(PlasticLocalization.
GetString(PlasticLocalization.Name.SaveThisRevisionAs));
mDiffWithPreviousMenuItemContent = new GUIContent(string.Format("{0} {1}",
PlasticLocalization.GetString(PlasticLocalization.Name.HistoryMenuItemDiffWithPrevious),
GetPlasticShortcut.ForDiff()));
mDiffSelectedRevisionsMenuItemContent = new GUIContent(PlasticLocalization.
GetString(PlasticLocalization.Name.HistoryMenuItemDiffSelectedRevisions));
mDiffChangesetMenuItemContent = new GUIContent();
mRevertToThisRevisionMenuItemContent = new GUIContent(PlasticLocalization.
GetString(PlasticLocalization.Name.HistoryMenuItemRevertToThisRevision));
}
GenericMenu mMenu;
GUIContent mNoActionMenuItemContent;
GUIContent mOpenRevisionMenuItemContent;
GUIContent mOpenRevisionWithMenuItemContent;
GUIContent mSaveRevisionAsMenuItemContent;
GUIContent mDiffWithPreviousMenuItemContent;
GUIContent mDiffSelectedRevisionsMenuItemContent;
GUIContent mDiffChangesetMenuItemContent;
GUIContent mRevertToThisRevisionMenuItemContent;
readonly IOpenMenuOperations mOpenMenuOperations;
readonly IHistoryViewMenuOperations mOperations;
readonly IMenuOperations mMenuOperations;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c3cec769cd6ff2849aa09c811b62e611
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,58 @@
using System.Collections.Generic;
using Codice.CM.Common;
using Unity.PlasticSCM.Editor.UI.Tree;
namespace Unity.PlasticSCM.Editor.Views.History
{
internal static class HistorySelection
{
internal static void SelectRevisions(
HistoryListView listView,
List<RepObjectInfo> revisionsToSelect)
{
if (revisionsToSelect == null || revisionsToSelect.Count == 0)
{
TableViewOperations.SelectFirstRow(listView);
return;
}
listView.SelectRepObjectInfos(revisionsToSelect);
if (listView.HasSelection())
return;
TableViewOperations.SelectFirstRow(listView);
}
internal static List<RepObjectInfo> GetSelectedRepObjectInfos(
HistoryListView listView)
{
return listView.GetSelectedRepObjectInfos();
}
internal static List<HistoryRevision> GetSelectedHistoryRevisions(
HistoryListView listView)
{
return listView.GetSelectedHistoryRevisions();
}
internal static HistoryRevision GetSelectedHistoryRevision(
HistoryListView listView)
{
List<HistoryRevision> revisions =
listView.GetSelectedHistoryRevisions();
if (revisions.Count == 0)
return null;
return revisions[0];
}
internal static long GetSelectedChangesetId(
HistoryListView listView)
{
return listView.GetSelectedChangesetId();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9553f392d0be2a24daf3cad457d2c612
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,625 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
using Codice.CM.Common;
using Codice.Client.Common;
using Codice.Client.Common.EventTracking;
using Codice.Utils;
using GluonGui;
using PlasticGui;
using PlasticGui.WorkspaceWindow;
using PlasticGui.WorkspaceWindow.Diff;
using PlasticGui.WorkspaceWindow.History;
using PlasticGui.WorkspaceWindow.Open;
using PlasticGui.WorkspaceWindow.Configuration;
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 GluonIncomingChangesUpdater = PlasticGui.Gluon.WorkspaceWindow.IncomingChangesUpdater;
using GluonRevertOperation = GluonGui.WorkspaceWindow.Views.Details.History.RevertOperation;
using HistoryDescriptor = GluonGui.WorkspaceWindow.Views.Details.History.HistoryDescriptor;
using OpenRevisionOperation = PlasticGui.WorkspaceWindow.History.OpenRevisionOperation;
using Unity.PlasticSCM.Editor.Diff;
namespace Unity.PlasticSCM.Editor.Views.History
{
internal class HistoryTab :
IRefreshableView,
HistoryViewLogic.IHistoryView,
HistoryListViewMenu.IMenuOperations,
IOpenMenuOperations,
IHistoryViewMenuOperations
{
internal HistoryListView Table { get { return mHistoryListView; } }
internal string EmptyStateMessage { get { return mEmptyStatePanel.Text; } }
internal HistoryTab(
WorkspaceInfo wkInfo,
ViewHost viewHost,
IWorkspaceWindow workspaceWindow,
IAssetStatusCache assetStatusCache,
LaunchTool.IShowDownloadPlasticExeWindow showDownloadPlasticExeWindow,
LaunchTool.IProcessExecutor processExecutor,
IPendingChangesUpdater pendingChangesUpdater,
IncomingChangesUpdater developerIncomingChangesUpdater,
GluonIncomingChangesUpdater gluonIncomingChangesUpdater,
EditorWindow parentWindow,
bool isGluonMode)
{
mWkInfo = wkInfo;
mViewHost = viewHost;
mWorkspaceWindow = workspaceWindow;
mAssetStatusCache = assetStatusCache;
mShowDownloadPlasticExeWindow = showDownloadPlasticExeWindow;
mProcessExecutor = processExecutor;
mPendingChangesUpdater = pendingChangesUpdater;
mDeveloperIncomingChangesUpdater = developerIncomingChangesUpdater;
mGluonIncomingChangesUpdater = gluonIncomingChangesUpdater;
mParentWindow = parentWindow;
mIsGluonMode = isGluonMode;
BuildComponents(wkInfo);
mProgressControls = new ProgressControlsForViews();
mHistoryViewLogic = new HistoryViewLogic(
wkInfo, this, mProgressControls);
mEmptyStatePanel = new EmptyStatePanel(parentWindow.Repaint);
}
internal void RefreshForItem(
RepositorySpec repSpec,
long itemId,
string path,
bool isDirectory)
{
mRepSpec = repSpec;
mItemId = itemId;
mPath = path;
mIsDirectory = isDirectory;
// IMPORTANT: Clear selection before populating the list,
// so UpdateData's HasSelection() check falls through to
// SelectFirstRow, which fires the selection-changed event
//and updates the diff window with the new item's first revision.
mHistoryListView.SetSelection(new List<int>());
((IRefreshableView)this).Refresh();
}
internal void OnEnable()
{
mSearchField.downOrUpArrowKeyPressed +=
SearchField_OnDownOrUpArrowKeyPressed;
}
internal void OnDisable()
{
mSearchField.downOrUpArrowKeyPressed -=
SearchField_OnDownOrUpArrowKeyPressed;
TreeHeaderSettings.Save(
mHistoryListView.multiColumnHeader.state,
UnityConstants.HISTORY_TABLE_SETTINGS_NAME);
GetWindowIfOpened.Diff()?.ClearIfShownFrom(DiffSource.History);
}
internal SerializableHistoryTabState GetSerializableState()
{
return new SerializableHistoryTabState(mRepSpec, mItemId, mPath, mIsDirectory);
}
internal void Update()
{
mProgressControls.UpdateProgress(mParentWindow);
}
internal void OnGUI(Action closeViewAction)
{
DoActionsToolbar(
mProgressControls,
mSearchField,
mHistoryListView,
GetViewTitle(mPath),
this,
closeViewAction);
Rect viewRect = OverlayProgress.CaptureViewRectangle();
DoHistoryArea(
mHistoryListView,
mEmptyStatePanel,
mProgressControls.IsOperationRunning());
if (mProgressControls.IsOperationRunning())
{
OverlayProgress.DoOverlayProgress(
viewRect,
mProgressControls.ProgressData.ProgressPercent,
mProgressControls.ProgressData.ProgressMessage);
}
}
internal void SetLaunchToolForTesting(
LaunchTool.IShowDownloadPlasticExeWindow showDownloadPlasticExeWindow,
LaunchTool.IProcessExecutor processExecutor)
{
mShowDownloadPlasticExeWindow = showDownloadPlasticExeWindow;
mProcessExecutor = processExecutor;
}
void IRefreshableView.Refresh()
{
mHistoryViewLogic.RefreshForItem(mRepSpec, mItemId, new CancelToken());
}
void HistoryViewLogic.IHistoryView.UpdateData(
List<ResolvedUser> resolvedUsers,
ResolvedUser currentUser,
Dictionary<BranchInfo, ChangesetInfo> branchesAndChangesets,
BranchInfo workingBranch,
HistoryRevisionList list,
long loadedRevisionId,
WorkspaceUIConfiguration config)
{
mHistoryListView.BuildModel(mRepSpec, list, loadedRevisionId);
mHistoryListView.Refilter();
mHistoryListView.Sort();
mHistoryListView.Reload();
if (!mHistoryListView.HasSelection())
TableViewOperations.SelectFirstRow(mHistoryListView);
}
long HistoryListViewMenu.IMenuOperations.GetSelectedChangesetId()
{
return HistorySelection.GetSelectedChangesetId(mHistoryListView);
}
SelectedHistoryGroupInfo IHistoryViewMenuOperations.GetSelectedHistoryGroupInfo()
{
return SelectedHistoryGroupInfo.BuildFromSelection(
HistorySelection.GetSelectedRepObjectInfos(mHistoryListView),
HistorySelection.GetSelectedHistoryRevisions(mHistoryListView),
mHistoryListView.GetLoadedRevisionId(),
mIsDirectory);
}
void IOpenMenuOperations.Open()
{
OpenRevisionOperation.Open(
mRepSpec,
Path.GetFileName(mPath),
HistorySelection.GetSelectedHistoryRevisions(
mHistoryListView));
}
void IOpenMenuOperations.OpenWith()
{
List<HistoryRevision> revisions = HistorySelection.
GetSelectedHistoryRevisions(mHistoryListView);
OpenRevisionOperation.OpenWith(
mRepSpec,
FileSystemOperation.GetExePath(),
Path.GetFileName(mPath),
revisions);
}
void IOpenMenuOperations.OpenWithCustom(string exePath, string args)
{
}
void IOpenMenuOperations.OpenInExplorer()
{
}
void IHistoryViewMenuOperations.SaveRevisionAs()
{
TrackFeatureUseEvent.For(
mRepSpec,
TrackFeatureUseEvent.Features.UnityPackage.SaveRevisionFromFileHistory);
HistoryRevision revision = HistorySelection.
GetSelectedHistoryRevision(mHistoryListView);
string defaultFileName = DefaultRevisionName.Get(
Path.GetFileName(mPath), revision.ChangeSet);
string destinationPath = SaveAction.GetDestinationPath(
mWkInfo.ClientPath, mPath, defaultFileName);
if (string.IsNullOrEmpty(destinationPath))
return;
SaveRevisionOperation.SaveRevision(
mRepSpec,
destinationPath,
revision,
mProgressControls);
}
void IHistoryViewMenuOperations.DiffWithPrevious()
{
HistoryRevision revision = HistorySelection.
GetSelectedHistoryRevision(mHistoryListView);
IUnityDiffWindow diffWindow = ShowWindow.Diff();
diffWindow.ShowDiffFromHistory(
mHistoryListView.GetRevisionFromId(revision.ParentRevisionId),
revision,
mRepSpec,
mPath,
mItemId,
showDiffInDesktopApp: () => DiffWithPreviousInDesktopApp(revision));
}
void IHistoryViewMenuOperations.DiffSelectedRevisions()
{
HistoryRevision leftRevision;
HistoryRevision rightRevision;
GetOrderedSelectedRevisions(out leftRevision, out rightRevision);
IUnityDiffWindow diffWindow = ShowWindow.Diff();
diffWindow.ShowDiffFromHistory(
leftRevision,
rightRevision,
mRepSpec,
mPath,
mItemId,
showDiffInDesktopApp: () => DiffSelectedRevisionsInDesktopApp(
leftRevision, rightRevision));
}
void DiffWithPreviousInDesktopApp(HistoryRevision revision)
{
DiffOperation.DiffWithPrevious(
mWkInfo,
mRepSpec,
Path.GetFileName(mPath),
string.Empty,
revision.Id,
mItemId,
revision.ChangeSet,
mProgressControls,
PlasticExeLauncher.BuildForDiffRevision(mRepSpec, mIsGluonMode, mShowDownloadPlasticExeWindow),
null);
}
void DiffSelectedRevisionsInDesktopApp(
HistoryRevision leftRevision, HistoryRevision rightRevision)
{
DiffOperation.DiffRevisions(
mWkInfo,
mRepSpec,
Path.GetFileName(mPath),
string.Empty,
mItemId,
leftRevision,
rightRevision,
mProgressControls,
PlasticExeLauncher.BuildForDiffSelectedRevisions(mRepSpec, mIsGluonMode, mShowDownloadPlasticExeWindow),
null);
}
void GetOrderedSelectedRevisions(
out HistoryRevision leftRevision,
out HistoryRevision rightRevision)
{
List<HistoryRevision> revisions = HistorySelection.
GetSelectedHistoryRevisions(mHistoryListView);
bool areReversed = revisions[0].Id > revisions[1].Id;
leftRevision = revisions[(areReversed) ? 1 : 0];
rightRevision = revisions[(areReversed) ? 0 : 1];
}
void IHistoryViewMenuOperations.DiffChangeset()
{
long changeset = HistorySelection.GetSelectedChangesetId(mHistoryListView);
LaunchDiffOperations.DiffChangeset(
mShowDownloadPlasticExeWindow,
mProcessExecutor,
mRepSpec,
changeset,
mIsGluonMode);
}
void IHistoryViewMenuOperations.RevertToThisRevision()
{
HistoryRevision revision = HistorySelection.
GetSelectedHistoryRevision(mHistoryListView);
string fullPath = GetFullPath(mWkInfo.ClientPath, mPath);
if (mIsGluonMode)
{
HistoryDescriptor historyDescriptor = new HistoryDescriptor(
mRepSpec, fullPath, mItemId, revision.Id, mIsDirectory);
GluonRevertOperation.RevertToThisRevision(
mWkInfo,
mViewHost,
mProgressControls,
historyDescriptor,
revision,
mPendingChangesUpdater,
mGluonIncomingChangesUpdater,
() => RefreshAsset.UnityAssetDatabase(mAssetStatusCache));
return;
}
RevertOperation.RevertToThisRevision(
mWkInfo,
mProgressControls,
mWorkspaceWindow,
mRepSpec,
revision,
fullPath,
mPendingChangesUpdater,
mDeveloperIncomingChangesUpdater,
null,
() => RefreshAsset.UnityAssetDatabase(mAssetStatusCache));
}
void SearchField_OnDownOrUpArrowKeyPressed()
{
mHistoryListView.SetFocusAndEnsureSelectedItem();
}
static string GetFullPath(string wkPath, string path)
{
if (PathHelper.IsContainedOn(path, wkPath))
return path;
return WorkspacePath.GetWorkspacePathFromCmPath(
wkPath, path, Path.DirectorySeparatorChar);
}
static void DoActionsToolbar(
ProgressControlsForViews progressControls,
SearchField searchField,
HistoryListView historyListView,
string viewTitle,
IRefreshableView view,
Action closeViewAction)
{
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();
}
GUILayout.Label(
viewTitle,
UnityStyles.HistoryTab.HeaderLabel);
GUILayout.FlexibleSpace();
DrawSearchField.For(
searchField,
historyListView,
UnityConstants.SEARCH_FIELD_WIDTH);
if (GUILayout.Button(
Images.GetCloseIcon(),
UnityStyles.CloseViewIconButtonStyle))
{
closeViewAction();
}
EditorGUILayout.EndHorizontal();
}
void DoHistoryArea(
HistoryListView historyListView,
EmptyStatePanel emptyStatePanel,
bool isOperationRunning)
{
GUI.enabled = !isOperationRunning;
Rect rect = GUILayoutUtility.GetRect(0, 100000, 0, 100000);
historyListView.OnGUI(rect);
if (Event.current.type == EventType.Layout)
mShouldShowEmptyState = !emptyStatePanel.IsEmpty();
if (mShouldShowEmptyState)
emptyStatePanel.OnGUI(rect);
GUI.enabled = true;
}
void OnDelayedSelectionChanged()
{
List<RepObjectInfo> selection =
HistorySelection.GetSelectedRepObjectInfos(mHistoryListView);
if (selection.Count == 0)
return;
IUnityDiffWindow diffWindow = GetWindowIfOpened.Diff();
if (diffWindow == null)
return;
if (selection.Count == 2 &&
selection[0] is HistoryRevision firstRevision &&
selection[1] is HistoryRevision secondRevision)
{
bool areReversed = firstRevision.Id > secondRevision.Id;
HistoryRevision leftRevision = areReversed ? secondRevision : firstRevision;
HistoryRevision rightRevision = areReversed ? firstRevision : secondRevision;
diffWindow.ShowDiffFromHistory(
leftRevision,
rightRevision,
mRepSpec,
mPath,
mItemId,
showDiffInDesktopApp: () => DiffSelectedRevisionsInDesktopApp(
leftRevision, rightRevision));
return;
}
RepObjectInfo lastSelectedObject = selection[0];
if (lastSelectedObject is HistoryRevision historyRevision)
{
diffWindow.ShowDiffFromHistory(
mHistoryListView.GetRevisionFromId(historyRevision.ParentRevisionId),
historyRevision,
mRepSpec,
mPath,
mItemId,
showDiffInDesktopApp: () => DiffWithPreviousInDesktopApp(historyRevision));
return;
}
if (lastSelectedObject is MoveRealizationInfo moveRealizationInfo)
{
diffWindow?.ShowMoveRealizationInfo(moveRealizationInfo);
return;
}
if (lastSelectedObject is RemovedRealizationInfo)
{
diffWindow?.ShowRemovedRealizationInfo();
return;
}
}
void OnRowDoubleClickAction()
{
if (mHistoryListView.GetSelection().Count != 1)
return;
List<RepObjectInfo> selection =
HistorySelection.GetSelectedRepObjectInfos(mHistoryListView);
if (selection.Count == 0)
return;
RepObjectInfo selectedObject = selection[0];
if (selectedObject is HistoryRevision selectedRevision)
{
ShowWindow.Diff().ShowDiffFromHistory(
null,
selectedRevision,
mRepSpec,
mPath,
mItemId,
showDiffInDesktopApp: () => DiffWithPreviousInDesktopApp(selectedRevision));
return;
}
if (selectedObject is MoveRealizationInfo moveRealizationInfo)
{
ShowWindow.Diff().ShowMoveRealizationInfo(moveRealizationInfo);
return;
}
if (selectedObject is RemovedRealizationInfo)
{
ShowWindow.Diff().ShowRemovedRealizationInfo();
return;
}
}
void OnItemsChangedAction(IEnumerable<RepObjectInfo> items)
{
if (items.Count() > 0)
{
mEmptyStatePanel.UpdateContent(string.Empty);
return;
}
mEmptyStatePanel.UpdateContent(
PlasticLocalization.Name.NoRevisionsMatchingFilters.GetString());
}
static string GetViewTitle(string path)
{
path = PathHelper.RemoveLastSlash(
path, Path.DirectorySeparatorChar);
return PlasticLocalization.GetString(
PlasticLocalization.Name.HistoryViewTitle,
Path.GetFileName(path));
}
void BuildComponents(WorkspaceInfo wkInfo)
{
mSearchField = new SearchField();
mSearchField.downOrUpArrowKeyPressed += SearchField_OnDownOrUpArrowKeyPressed;
HistoryListHeaderState headerState =
HistoryListHeaderState.GetDefault();
TreeHeaderSettings.Load(headerState,
UnityConstants.HISTORY_TABLE_SETTINGS_NAME,
(int)HistoryListColumn.CreationDate,
false);
mHistoryListView = new HistoryListView(
wkInfo.ClientPath,
headerState,
new HistoryListViewMenu(this, this, this),
HistoryListHeaderState.GetColumnNames(),
OnDelayedSelectionChanged,
OnRowDoubleClickAction,
afterItemsChangedAction: OnItemsChangedAction);
mHistoryListView.Reload();
}
bool mShouldShowEmptyState;
bool mIsDirectory;
long mItemId;
string mPath;
RepositorySpec mRepSpec;
SearchField mSearchField;
HistoryListView mHistoryListView;
LaunchTool.IProcessExecutor mProcessExecutor;
LaunchTool.IShowDownloadPlasticExeWindow mShowDownloadPlasticExeWindow;
readonly EmptyStatePanel mEmptyStatePanel;
readonly HistoryViewLogic mHistoryViewLogic;
readonly ProgressControlsForViews mProgressControls;
readonly bool mIsGluonMode;
readonly EditorWindow mParentWindow;
readonly IPendingChangesUpdater mPendingChangesUpdater;
readonly IncomingChangesUpdater mDeveloperIncomingChangesUpdater;
readonly GluonIncomingChangesUpdater mGluonIncomingChangesUpdater;
readonly IAssetStatusCache mAssetStatusCache;
readonly IWorkspaceWindow mWorkspaceWindow;
readonly ViewHost mViewHost;
readonly WorkspaceInfo mWkInfo;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3a49359b59c12b74386ca6816923ec2c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,38 @@
using System.IO;
using UnityEditor;
using Codice.Client.Common;
using PlasticGui;
namespace Unity.PlasticSCM.Editor.Views.History
{
internal static class SaveAction
{
internal static string GetDestinationPath(
string wkPath,
string path,
string defaultFileName)
{
string title = PlasticLocalization.GetString(
PlasticLocalization.Name.SaveRevisionAs);
string parentDirectory = GetDirectoryForSaveAs(wkPath, path);
return EditorUtility.SaveFilePanel(
title, parentDirectory, defaultFileName,
string.Empty);
}
static string GetDirectoryForSaveAs(string wkPath, string path)
{
if (PathHelper.IsContainedOn(path, wkPath))
return Path.GetDirectoryName(path);
return WorkspacePath.GetWorkspacePathFromCmPath(
wkPath,
Path.GetDirectoryName(path),
Path.DirectorySeparatorChar);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 025a530ab434a7e40ad318955f571e50
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,31 @@
using System;
using Codice.CM.Common;
namespace Unity.PlasticSCM.Editor.Views.History
{
[Serializable]
internal class SerializableHistoryTabState
{
internal RepositorySpec RepSpec { get; private set; }
internal long ItemId { get; private set; }
internal string Path { get; private set; }
internal bool IsDirectory { get; private set; }
internal bool IsInitialized { get; private set; }
internal SerializableHistoryTabState(
RepositorySpec repSpec,
long itemId,
string path,
bool isDirectory)
{
RepSpec = repSpec;
ItemId = itemId;
Path = path;
IsDirectory = isDirectory;
IsInitialized = true;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: aa38aeb612889ca428824f7e31a50747
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: