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);
        }
Esempio n. 2
0
 private void OnSelectionChanged()
 {
     if (selectionHistory.IsSelected(selectionHistory.GetHistoryCount() - 1))
     {
         historyScrollPosition.y = float.MaxValue;
     }
     // TODO: Calculate the scroll position, and set it for every selection.
     Repaint();
 }
        void OnEnable()
        {
            automaticRemoveDeleted = EditorPrefs.GetBool(HistoryAutomaticRemoveDeletedPrefKey, true);

            selectionHistory             = EditorTemporaryMemory.Instance.selectionHistory;
            selectionHistory.HistorySize = EditorPrefs.GetInt(HistorySizePrefKey, 10);

            Selection.selectionChanged += delegate {
                if (selectionHistory.IsSelected(selectionHistory.GetHistoryCount() - 1))
                {
                    _historyScrollPosition.y = float.MaxValue;
                }

                Repaint();
            };

            try {
                var asm = Assembly.GetAssembly(typeof(EditorWindow));
                var t   = asm.GetType("UnityEditor.PreferencesWindow");
                openPreferencesWindow = t.GetMethod("ShowPreferencesWindow", BindingFlags.NonPublic | BindingFlags.Static);
            } catch {
                // couldnt get preferences window...
                openPreferencesWindow = null;
            }
        }
        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));
        }
        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 DrawElement(Object obj, int i, Color originalColor)
        {
            var buttonStyle = windowSkin.GetStyle("SelectionButton");

            buttonStyle.fixedWidth = position.width - buttonsWidth;
            var nonSelectedColor = originalColor;

            if (!EditorUtility.IsPersistent(obj))
            {
                if (!showHierarchyViewObjects)
                {
                    return;
                }
                nonSelectedColor = hierarchyElementColor;
            }
            else
            {
                if (!showProjectViewObjects)
                {
                    return;
                }
            }

            if (selectionHistory.IsSelected(obj))
            {
                GUI.contentColor = selectedElementColor;
            }
            else
            {
                GUI.contentColor = nonSelectedColor;
            }

            var rect = EditorGUILayout.BeginHorizontal();

            if (obj == null)
            {
                GUILayout.Label("Deleted", buttonStyle);
            }
            else
            {
                var icon = AssetPreview.GetMiniThumbnail(obj);

                GUIContent content = new GUIContent();

                content.image = icon;
                content.text  = obj.name;

                // chnanged to label to be able to handle events for drag
                GUILayout.Label(content, buttonStyle);

                GUI.contentColor = originalColor;

                if (GUILayout.Button("Ping", windowSkin.button))
                {
                    EditorGUIUtility.PingObject(obj);
                }

                var favoritesEnabled = EditorPrefs.GetBool(HistoryFavoritesPrefKey, true);

                if (favoritesEnabled)
                {
                    var pinString  = "Pin";
                    var isFavorite = selectionHistory.IsFavorite(obj);

                    if (isFavorite)
                    {
                        pinString = "Unpin";
                    }

                    if (GUILayout.Button(pinString, windowSkin.button))
                    {
                        selectionHistory.ToggleFavorite(obj);
                        Repaint();
                    }
                }
            }

            EditorGUILayout.EndHorizontal();

            ButtonLogic(rect, obj);
        }