public void TestRemoveDuplicatedElementsInOrder()
        {
            var selectionHistory = new SelectionHistory();

            var selection1 = new GameObject();
            var selection2 = new GameObject();
            var selection3 = new GameObject();

            selectionHistory.UpdateSelection(selection1);
            selectionHistory.UpdateSelection(selection2);
            selectionHistory.UpdateSelection(selection1);
            selectionHistory.UpdateSelection(selection3);
            selectionHistory.UpdateSelection(selection1);

            selectionHistory.RemoveDuplicated();

            Assert.That(selectionHistory.GetHistoryCount(), Is.EqualTo(3));
            Assert.That(selectionHistory.GetSelection(), Is.SameAs(selection1));
            Assert.That(selectionHistory.IsSelected(2), Is.True);

            selectionHistory.UpdateSelection(selection3);
            Assert.That(selectionHistory.GetSelection(), Is.SameAs(selection3));

            selectionHistory.UpdateSelection(selection2);
            Assert.That(selectionHistory.GetSelection(), Is.SameAs(selection2));
        }
Ejemplo n.º 2
0
        private void OnGUI()
        {
            // Ensure styles are loaded.
            InitializeStyles();

            // Ensure preferences are loaded.
            if (shouldReloadPreferences)
            {
                selectionHistory.HistorySize = EditorPrefs.GetInt(SelectionHistoryWindow.HistorySizePrefKey, 10);
                allowDuplicatedEntries       = EditorPrefs.GetBool(SelectionHistoryWindow.HistoryAllowDuplicatedEntriesPrefKey, false);
                automaticRemoveDeleted       = EditorPrefs.GetBool(SelectionHistoryWindow.HistoryAutomaticRemoveDeletedPrefKey, true);
                showHierarchyViewObjects     = EditorPrefs.GetBool(SelectionHistoryWindow.HistoryShowHierarchyObjectsPrefKey, true);
                showProjectViewObjects       = EditorPrefs.GetBool(SelectionHistoryWindow.HistoryShowProjectViewObjectsPrefKey, true);
                favoritesEnabled             = EditorPrefs.GetBool(SelectionHistoryWindow.HistoryFavoritesPrefKey, true);
                favoritesFirst          = EditorPrefs.GetBool(SelectionHistoryWindow.HistoryFavoritesFirstPrefKey, false);
                shouldReloadPreferences = false;
            }

            // Clear any items that should not be shown.
            if (automaticRemoveDeleted)
            {
                selectionHistory.RemovedDestroyed();
            }
            if (!allowDuplicatedEntries)
            {
                selectionHistory.RemoveDuplicated();
            }

            // Draw the elements in a scroll view.
            historyScrollPosition = EditorGUILayout.BeginScrollView(historyScrollPosition, GUILayout.ExpandHeight(true));
            if (favoritesFirst)
            {
                DrawFavorites();
                DrawHistory();
            }
            else
            {
                DrawHistory();
                DrawFavorites();
            }
            EditorGUILayout.EndScrollView();

            // Draw a sidebar on the left to match the hierarchy view visually.
            if (favoritesEnabled)
            {
                var sidebar = GUILayoutUtility.GetLastRect();
                sidebar.width = LINE_HEIGHT;
                DrawColoredBox(sidebar, Color.black * 0.176f);
            }

            DrawButtorBar();
        }
        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();
        }