public void ClearDeletedEntriesShouldKeepSelectedIndex() { var selectionHistory = new SelectionHistory(); var selection1 = new GameObject(); var selection2 = new GameObject(); var selection3 = new GameObject(); var selection4 = new GameObject(); selectionHistory.UpdateSelection(selection1); selectionHistory.UpdateSelection(selection2); selectionHistory.UpdateSelection(selection3); selectionHistory.UpdateSelection(selection4); Assert.IsTrue(selectionHistory.IsSelected(3)); Assert.AreEqual(selectionHistory.GetHistoryCount(), 4); GameObject.DestroyImmediate(selection2); selectionHistory.ClearDeleted(); Assert.IsTrue(selectionHistory.IsSelected(2)); Assert.AreEqual(selectionHistory.GetHistoryCount(), 3); selectionHistory.SetSelection(selection3); GameObject.DestroyImmediate(selection1); GameObject.DestroyImmediate(selection4); selectionHistory.ClearDeleted(); Assert.IsTrue(selectionHistory.IsSelected(0)); Assert.AreEqual(selectionHistory.GetHistoryCount(), 1); }
public void ClearDeletedItemsShouldntSelectIfSelectionDeleted() { var selectionHistory = new SelectionHistory(); var selection1 = new GameObject(); var selection2 = new GameObject(); var selection3 = new GameObject(); selectionHistory.UpdateSelection(selection1); selectionHistory.UpdateSelection(selection2); selectionHistory.UpdateSelection(selection3); Assert.IsTrue(selectionHistory.IsSelected(2)); Assert.That(selectionHistory.GetHistoryCount(), Is.EqualTo(3)); GameObject.DestroyImmediate(selection3); selectionHistory.ClearDeleted(); Assert.IsFalse(selectionHistory.IsSelected(0)); Assert.IsFalse(selectionHistory.IsSelected(1)); Assert.AreEqual(selectionHistory.GetHistoryCount(), 2); }
void OnGUI() { if (shouldReloadPreferences) { selectionHistory.HistorySize = EditorPrefs.GetInt(SelectionHistoryWindow.HistorySizePrefKey, 10); automaticRemoveDeleted = EditorPrefs.GetBool(SelectionHistoryWindow.HistoryAutomaticRemoveDeletedPrefKey, true); allowDuplicatedEntries = EditorPrefs.GetBool(SelectionHistoryWindow.HistoryAllowDuplicatedEntriesPrefKey, false); showHierarchyViewObjects = EditorPrefs.GetBool(SelectionHistoryWindow.HistoryShowHierarchyObjectsPrefKey, true); showProjectViewObjects = EditorPrefs.GetBool(SelectionHistoryWindow.HistoryShowProjectViewObjectsPrefKey, true); shouldReloadPreferences = false; } if (automaticRemoveDeleted) { selectionHistory.ClearDeleted(); } if (!allowDuplicatedEntries) { selectionHistory.RemoveDuplicated(); } var favoritesEnabled = EditorPrefs.GetBool(HistoryFavoritesPrefKey, true); if (favoritesEnabled && selectionHistory.Favorites.Count > 0) { _favoritesScrollPosition = EditorGUILayout.BeginScrollView(_favoritesScrollPosition); DrawFavorites(); EditorGUILayout.EndScrollView(); EditorGUILayout.Separator(); } bool changedBefore = GUI.changed; _historyScrollPosition = EditorGUILayout.BeginScrollView(_historyScrollPosition); bool changedAfter = GUI.changed; if (!changedBefore && changedAfter) { Debug.Log("changed"); } DrawHistory(); EditorGUILayout.EndScrollView(); if (GUILayout.Button("Clear")) { selectionHistory.Clear(); Repaint(); } if (!automaticRemoveDeleted) { if (GUILayout.Button("Remove Deleted")) { selectionHistory.ClearDeleted(); Repaint(); } } if (allowDuplicatedEntries) { if (GUILayout.Button("Remove Duplciated")) { selectionHistory.RemoveDuplicated(); Repaint(); } } DrawSettingsButton(); }