using System.Collections.Generic; using Codice.CM.Common; using Unity.PlasticSCM.Editor.UI.Tree; using UnityEditor.IMGUI.Controls; namespace Unity.PlasticSCM.Editor.Views.Locks { internal sealed class LocksSelector { internal LocksSelector(TreeView treeView, ListViewItemIds listViewItemIds) { mTreeView = treeView; mListViewItemIds = listViewItemIds; } internal void SaveSelectedLocks() { mSelectedLocks = GetSelectedLocks(); } internal List GetSelectedLocks() { var result = new List(); var selectedIds = mTreeView.GetSelection(); if (selectedIds.Count == 0) { return result; } foreach (var item in mListViewItemIds.GetInfoItems()) { if (selectedIds.Contains(item.Value)) { result.Add(item.Key); } } return result; } internal void RestoreSelectedLocks() { if (mSelectedLocks == null || mSelectedLocks.Count == 0) { TableViewOperations.SelectFirstRow(mTreeView); return; } SelectLockItems(mSelectedLocks); if (!mTreeView.HasSelection()) { TableViewOperations.SelectFirstRow(mTreeView); } } void SelectLockItems(List locksToSelect) { var idsToSelect = new List(); foreach (var lockInfo in locksToSelect) { var lockInfoId = GetTreeIdForItem(lockInfo); if (lockInfoId == -1) { continue; } idsToSelect.Add(lockInfoId); } TableViewOperations.SetSelectionAndScroll(mTreeView, idsToSelect); } int GetTreeIdForItem(LockInfo lockInfo) { foreach (var item in mListViewItemIds.GetInfoItems()) { if (!lockInfo.ItemGuid.Equals(item.Key.ItemGuid)) { continue; } return item.Value; } return -1; } List mSelectedLocks; readonly TreeView mTreeView; readonly ListViewItemIds mListViewItemIds; } }