/// <summary>
        /// Waits until the active inspector has finished rendering and then opens the menu.
        /// Delaying the opening of the menu like this can help avoid with some graphical glitches that can happen if the menu is opened in the middle of an inspector being drawn.
        /// </summary>
        /// <param name="menu"> Menu that should be opened. </param>
        /// <param name="disposeAfter"> Should the menu object be disposed after menu has been opened? Set this to false if the Menu is cached and reused, otherwise set this true. </param>
        /// <param name="inspector"> Inspector for which the context menu is being opened. Null if not opening for any inspector. </param>
        /// <param name="inspectorPart"> Part of the inspector for which the context menu is being opened. None if not opening for any inspector. </param>
        /// <param name="subject"> IDrawer for which the context menu is opened. Null if context menu doesn't belong to any IDrawer (e.g. toolbar menu item). </param>
        /// <param name="part"> Part of the subject for which the context menu is opened. E.g. reference to the targeted toolbar item. Can be null. </param>
        /// <param name="doOnMenuClosed"> Delegate to be called once menu has closed. Set to ContextMenuUtility.SelectLastContextMenuSubject to select the context menu subject once the context menu window has been closed. </param>
        public static void Open([NotNull] Menu menu, bool disposeAfter, [CanBeNull] IInspector inspector, InspectorPart inspectorPart, [CanBeNull] IDrawer subject, [CanBeNull] object part, Action <object> doOnMenuClosed = null)
        {
                        #if DEV_MODE
            Debug.Assert(menu.Count > 0);
            Debug.Assert(inspector != null || subject == null);
                        #endif

            openingMenu              = menu;
            openingMenuInspector     = inspector;
            openingMenuInspectorPart = inspectorPart;
            openingMenuSubject       = new DrawerTarget(subject);
            openingMenuPart          = part;
            openingMenuPosition      = null;
            disposeMenuAfterOpening  = disposeAfter;
            onMenuClosed             = doOnMenuClosed;

            if (IsSafeToChangeInspectorContents || inspector == null)
            {
                                #if DEV_MODE
                Debug.Log("Opening context menu immediately");
                                #endif
                OpenContextMenu();
            }
            else
            {
                openDelayCounter = 2;
            }
        }
Example #2
0
        /// <summary>
        /// Sets mouseovered inspector part to given value. Optionally clears controls.
        /// </summary>
        /// <param name="setInspector"> The inspector to set as the mouseovered inspector. Can be null. </param>
        /// <param name="clearControls">
        /// True to also clear mouseovered selectable and right-clickable drawer.
        /// If setInspector is null, drawer will get cleared regardless of the value of this flag.
        /// </param>
        /// <returns> True if mouseovered inspector changed. </returns>
        public bool SetInspector([CanBeNull] IInspector setInspector, bool clearControls)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            if (setInspector == null && !clearControls)
            {
                Debug.LogWarning("Mouseovered.SetInspector setInspector was " + StringUtils.Null + " but clearControls was " + StringUtils.False);
            }
                        #endif

            bool changed;
            if (setInspector != inspector)
            {
                changed = true;

                                #if DEV_MODE && DEBUG_SET_INSPECTOR
                Debug.Log(StringUtils.ToColorizedString("Mouseovered.SetInspector(", setInspector, ")"));
                                #endif

                var inspectorWas = Inspector;

                Inspector = setInspector;
                if (setInspector == null)
                {
                    InspectorPart = InspectorPart.None;
                    ClearControls();
                }
                else if (clearControls)
                {
                    ClearControls();
                }

                if (onInspectorChanged != null)
                {
                    onInspectorChanged(inspectorWas, setInspector);
                }
            }
            else if (clearControls)
            {
                                #if DEV_MODE && PI_ASSERTATIONS
                if (inspectorPart == InspectorPart.Viewport)
                {
                    Debug.LogWarning("Mouseovered.SetInspector was called with clearControls " + StringUtils.True + " but inspector did not change and inspectorPart " + StringUtils.ToColorizedString(inspectorPart));
                }
                                #endif

                changed = ClearControls();
            }
            else
            {
                changed = false;
            }

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(Inspector == setInspector);
            AssertStateIsValid();
                        #endif

            return(changed);
        }
Example #3
0
        /// <inheritdoc/>
        public void SetMouseoveredInspector(IInspector inspector, InspectorPart inspectorPart)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            if (inspectorPart == InspectorPart.None)
            {
                if (inspector != null)
                {
                    Debug.LogError("SetMouseoveredInspector was called with inspector " + inspector + " but inspectorPart " + StringUtils.ToColorizedString(inspectorPart) + ".");
                }
            }
            else if (inspector == null)
            {
                Debug.LogError("SetMouseoveredInspector was called with inspector " + StringUtils.Null + " but inspectorPart " + StringUtils.ToColorizedString(inspectorPart) + ".");
            }
                        #endif

                        #if DEV_MODE && DEBUG_SET_MOUSEOVERED_INSPECTOR
            if (mouseovered.Inspector != inspector || inspectorPart != mouseovered.InspectorPart)
            {
                Debug.Log(StringUtils.ToColorizedString("SetMouseoveredInspector(", inspector, ", part=", inspectorPart + ") with IgnoreAllMouseInputs=", IgnoreAllMouseInputs, ", Cursor.CanRequestLocalPosition=", Cursor.CanRequestLocalPosition, ", Cursor.LocalPosition=", Cursor.LocalPosition));
            }
                        #endif

            bool mouseoveredViewportChanged = false;

            if (mouseovered.Inspector != inspector)
            {
                mouseoveredViewportChanged = true;
                mouseovered.SetInspectorAndPart(inspector, inspectorPart, true);
            }
            else if (mouseovered.InspectorPart != inspectorPart)
            {
                if (inspectorPart == InspectorPart.Viewport || mouseovered.InspectorPart == InspectorPart.Viewport)
                {
                    mouseoveredViewportChanged = true;
                }
                mouseovered.SetInspectorPart(inspectorPart);
            }

            if (mouseoveredViewportChanged && mouseDownInfo.IsDrag())
            {
                if (inspectorPart != InspectorPart.Viewport)
                {
                    mouseDownInfo.OnCursorLeftInspectorViewportDuringDrag();
                }
                else
                {
                                        #if DEV_MODE && DEBUG_DRAG
                    Debug.Log(StringUtils.ToColorizedString("OnCursorEnteredInspectorViewportDuringDrag(", inspector, ") with NowReordering=", mouseDownInfo.NowReordering, ", DrawGUI.IsUnityObjectDrag=", DrawGUI.IsUnityObjectDrag));
                                        #endif

                    mouseDownInfo.OnCursorEnteredInspectorViewportDuringDrag(inspector);
                }
            }
        }
Example #4
0
        private void Select(IInspector inspector, InspectorPart part, [CanBeNull] IDrawer control, ReasonSelectionChanged reason, int multiSelect)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(!(multiSelect != 0 && control == null), "Select was called with multiSelect " + multiSelect + " but control null. Reason: " + reason);
            Debug.Assert(control == null || part == InspectorPart.Viewport, "Select was called with InspectorPart " + part + " but control (" + control + ") not being null. Reason: " + reason);
            Debug.Assert(control == null || inspector != null, "Select was called with control null but inspector (" + inspector + ") not null. Reason: " + reason);
            Debug.Assert((part == InspectorPart.None) == (inspector == null), "Select was called with InspectorPart " + StringUtils.ToColorizedString(part) + " and inspector " + StringUtils.ToColorizedString(StringUtils.ToString(inspector)) + " (control = " + StringUtils.ToString(control) + "). Reason: " + reason);
                        #endif

            selected.Set(inspector, part, control, multiSelect, reason);
        }
Example #5
0
        private void OnSelectionChanged(IInspector selectedInspector, InspectorPart inspectorPart, IDrawer focusedDrawer)
        {
                        #if DEV_MODE
            Debug.Log(StringUtils.ToColorizedString("OnSelectionChanged: inspector=", selectedInspector, ", drawer=", focusedDrawer));
                        #endif

            if (selectedInspector == inspector && focusedDrawer != null)
            {
                ShowDocumentationForMember(focusedDrawer);
            }
        }
Example #6
0
        public void Set([CanBeNull] IInspector setInspector, InspectorPart setPart, [CanBeNull] IDrawer setDrawer, int multiSelect, ReasonSelectionChanged reason)
        {
            bool suppressed = suppressOnSelectionChangedEvents;

            suppressOnSelectionChangedEvents = true;

            SetInspectorAndPart(setInspector, setPart, reason);
            SetFocusedDrawer(setDrawer, multiSelect, reason);

            suppressOnSelectionChangedEvents = suppressed;
            HandleOnSelectionEvent();
        }
Example #7
0
        /// <summary>
        /// Sets mouseovered inspector part to given value.
        /// </summary>
        /// <param name="setInspectorPart"> The inspector part to set as the mouseovered part. </param>
        /// <returns> True if mouseovered inspector part changed. </returns>
        public bool SetInspectorPart(InspectorPart setInspectorPart)
        {
            bool changed;

            if (InspectorPart != setInspectorPart)
            {
                changed = true;

                                #if DEV_MODE && DEBUG_SET_INSPECTOR_PART
                Debug.Log(StringUtils.ToColorizedString("Mouseovered.SetInspectorPart(", setInspectorPart, ")"));
                                #endif

                InspectorPart = setInspectorPart;

                if (inspectorPart == InspectorPart.None)
                {
                    Clear();
                }
                else
                {
                                        #if DEV_MODE && PI_ASSERTATIONS
                    Debug.Assert(Inspector != null);
                                        #endif

                    if (inspectorPart != InspectorPart.Viewport)
                    {
                        ClearControls();
                    }
                }
            }
            else
            {
                changed = false;
            }

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(InspectorPart == setInspectorPart);
            if (setInspectorPart == InspectorPart.None)
            {
                Debug.Assert(Inspector == null);
            }
            else
            {
                Debug.Assert(Inspector != null);
            }
            AssertStateIsValid();
                        #endif

            return(changed);
        }
Example #8
0
        public void SetInspectorAndPart(IInspector setInspector, InspectorPart setPart, ReasonSelectionChanged reason)
        {
            bool suppressed = suppressOnSelectionChangedEvents;

            suppressOnSelectionChangedEvents = true;

            var fromInspector = inspector;
            var fromPart      = inspectorPart;

            bool inspectorChanged = fromInspector != setInspector;
            bool partChanged      = inspectorChanged || fromPart != setPart;

                        #if DEV_MODE && DEBUG_SET_INSPECTOR
            UnityEngine.Debug.Log(StringUtils.ToColorizedString("Selected.SetInspectorAndPart(", setInspector, ", part=", setPart, ", reason=", reason, ") with inspectorChanged=", inspectorChanged, ", partChanged=", partChanged));
                        #endif

            if (partChanged)
            {
                if (setPart != InspectorPart.Viewport)
                {
                    ClearSelectedDrawers(reason, null);
                }

                InspectorPart = setPart;
                SetInspectorOnly(setInspector);

                if (!inspectorChanged)
                {
                    if (setInspector != null)
                    {
                        setInspector.OnSelectedPartChanged(fromPart, setPart, reason);
                    }
                }
                else
                {
                    if (fromInspector != null)
                    {
                        fromInspector.OnSelectedPartChanged(fromPart, InspectorPart.None, reason);
                    }

                    if (setInspector != null)
                    {
                        setInspector.OnSelectedPartChanged(InspectorPart.None, setPart, reason);
                    }
                }
            }

            suppressOnSelectionChangedEvents = suppressed;
            HandleOnSelectionEvent();
        }
        /// <summary>
        /// Waits until the active inspector has finished rendering and then opens the menu
        /// at the given position as a dropdown menu.
        /// Delaying the opening of the menu like this can help avoid with some graphical glitches that
        /// can happen if the menu is opened in the middle of an inspector being drawn
        /// </summary>
        /// <param name="menu"> Menu that should be opened. </param>
        /// <param name="position"> Position where menu should be opened. </param>
        /// <param name="disposeAfter">
        /// Should the menu object be disposed after menu has been opened?
        /// Set this to false if the Menu is cached and reused, otherwise set this true.
        /// </param>
        /// <param name="inspector"> Inspector for which the context menu is being opened. Null if not opening for any inspector. </param>
        /// <param name="inspectorPart"> Part of the inspector for which the context menu is being opened. None if not opening for any inspector. </param>
        /// <param name="subject"> IDrawer whose context menu is being opened. Null if context menu doesn't belong to any IDrawer (e.g. toolbar menu item). </param>
        /// <param name="part"> Can contain the part of the subject for which the context menu is opened. E.g. reference to the targeted toolbar item. </param>
        /// <param name="doOnMenuClosed"> Delegate to be called once menu has closed. Set to ContextMenuUtility.SelectLastContextMenuSubject to select the context menu subject once the context menu window has been closed. Can be null. </param>
        public static void OpenAt([NotNull] Menu menu, Rect position, bool disposeAfter, [CanBeNull] IInspector inspector, InspectorPart inspectorPart, [CanBeNull] IDrawer subject, [CanBeNull] object part, [CanBeNull] Action <object> doOnMenuClosed)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(menu != null);
            Debug.Assert(menu.Count > 0);
            Debug.Assert(position.x >= 0f);
            Debug.Assert(position.y >= 0f);
            Debug.Assert(position.x < Screen.currentResolution.width);
            Debug.Assert(position.y < Screen.currentResolution.height);
            if (subject != null)
            {
                Debug.Assert(inspector != null);
                Debug.Assert(inspector == subject.Inspector);
                Debug.Assert(inspectorPart == InspectorPart.Viewport);
            }
            Debug.Assert(inspectorPart != InspectorPart.None || inspector == null);
            Debug.Assert(inspectorPart == InspectorPart.None || inspector != null);
                        #endif

            openingMenu              = menu;
            openingMenuInspector     = inspector;
            openingMenuInspectorPart = inspectorPart;
            openingMenuSubject       = new DrawerTarget(subject);
            openingMenuPart          = part;
            disposeMenuAfterOpening  = disposeAfter;
            onMenuClosed             = doOnMenuClosed;

            var openAtLocalPoint  = position.position;
            var openAtScreenPoint = GUIUtility.GUIToScreenPoint(openAtLocalPoint);
            position.position   = openAtScreenPoint;
            openingMenuPosition = position;

            if (IsSafeToChangeInspectorContents || inspector == null)
            {
                                #if DEV_MODE && DEBUG_OPEN_MENU
                Debug.Log("Opening context menu @ " + position + " immediately.");
                                #endif
                OpenContextMenu();
            }
            else
            {
                                #if DEV_MODE && DEBUG_OPEN_MENU
                Debug.Log("Opening context menu @ " + position + " delayed... inspector.State.WindowRect.y=" + inspector.State.WindowRect.y + ", LocalDrawAreaOffset=" + DrawGUI.GetLocalDrawAreaOffset());
                                #endif

                openDelayCounter = 2;
                inspector.RefreshView();
            }
        }
        public static bool MouseIsOver(this Rect area, Vector2 mousePosition, InspectorPart inspectorPart = InspectorPart.Viewport)
        {
            if (area.Contains(mousePosition))
            {
                var manager = InspectorUtility.ActiveManager;
                if (manager != null)
                {
                    if (manager.MouseoveredInspectorPart != inspectorPart)
                    {
                                                #if DEV_MODE
                        if (Event.current != null && Event.current.type == EventType.MouseDown)
                        {
                            Debug.LogWarning("MouseIsOver - ignoring click because MouseoveredInspectorPart (" + manager.MouseoveredInspectorPart + ") did not match required inspectorPart " + inspectorPart + "!");
                        }
                                                #endif
                        return(false);
                    }

                    if (manager.IgnoreAllMouseInputs)
                    {
                                                #if DEV_MODE
                        if (Event.current != null && Event.current.type == EventType.MouseDown)
                        {
                            Debug.LogWarning("MouseIsOver - ignoring click because IgnoreAllMouseInputs was true!");
                        }
                                                #endif
                        return(false);
                    }

                    if (manager.ActiveInspector != manager.MouseoveredInspector)
                    {
                                                #if DEV_MODE
                        if (Event.current != null && Event.current.type == EventType.MouseDown)
                        {
                            Debug.LogWarning("MouseIsOver - ignoring click because ActiveInspector (" + StringUtils.ToString(manager.ActiveInspector) + ") != MouseoveredInspector (" + StringUtils.ToString(manager.MouseoveredInspector) + ")!");
                        }
                                                #endif
                        return(false);
                    }
                }

                return(true);
            }
            return(false);
        }
 /// <summary>
 /// Waits until the active inspector has finished rendering and then opens the menu at the given position as a dropdown menu.
 /// Delaying the opening of the menu like this can help avoid with some graphical glitches that can happen if the menu is opened in the middle of an inspector being drawn
 ///
 /// Once opened context menu has been the subject of the context menu will be selected (if necessary data is provided).
 /// </summary>
 /// <param name="menu"> Menu that should be opened. </param>
 /// <param name="position"> Position where menu should be opened. </param>
 /// <param name="disposeAfter">
 /// Should the menu object be disposed after menu has been opened?
 /// Set this to false if the Menu is cached and reused, otherwise set this true.
 /// </param>
 /// <param name="inspector"> Inspector for which the context menu is being opened. Null if not opening for any inspector. </param>
 /// <param name="inspectorPart"> Part of the inspector for which the context menu is being opened. None if not opening for any inspector. </param>
 /// <param name="subject"> IDrawer whose context menu is being opened. Null if context menu doesn't belong to any IDrawer (e.g. toolbar menu item). </param>
 /// <param name="part"> Can contain the part of the subject for which the context menu is opened. E.g. reference to the targeted toolbar item. </param>
 public static void OpenAt([NotNull] Menu menu, Rect position, bool disposeAfter, [CanBeNull] IInspector inspector, InspectorPart inspectorPart, [CanBeNull] IDrawer subject, [CanBeNull] object part)
 {
     OpenAt(menu, position, disposeAfter, inspector, inspectorPart, subject, part, SelectLastContextMenuSubject);
 }
Example #12
0
 /// <inheritdoc/>
 public void Select(IInspector inspector, InspectorPart part, IDrawer control, ReasonSelectionChanged reason)
 {
     Select(inspector, part, control, reason, 0);
 }
        public static bool DetectMouseButtonEvent(this Rect clickableArea, EventType eventType, int mouseButton, InspectorPart inspectorPart = InspectorPart.Viewport)
        {
            var e = Event.current;

            if (e.type == eventType && e.button == mouseButton)
            {
                return(MouseIsOver(clickableArea, e.mousePosition, inspectorPart));
            }
            return(false);
        }
 public static bool DetectClick(this Rect clickableArea, InspectorPart inspectorPart = InspectorPart.Viewport)
 {
     return(DetectMouseButtonEvent(clickableArea, EventType.MouseDown, 0));
 }
Example #15
0
        /// <summary>
        /// Sets focused drawer and handles calling OnDeselected (first) and OnSelected (second) for setDrawer
        /// and any previously focused drawer that is no longer selected. Also makes sure that selected inspector
        /// and inspector part are valid.
        /// </summary>
        /// <param name="setDrawer"> The drawer to set as the focused drawer. Can be null if focused drawer should be set to none. </param>
        /// <param name="multiSelect"> If 0 this is not a multi selection, if -1 remove from multi-selection, and if 1 add to multi-selection. </param>
        /// <param name="reason">Reason why focus is changing.</param>
        private void SetFocusedDrawer([CanBeNull] IDrawer setDrawer, int multiSelect, ReasonSelectionChanged reason)
        {
            var focusedDrawerWas = focusedDrawer;

                        #if DEV_MODE && PI_ASSERTATIONS
            UnityEngine.Debug.Assert(multiSelect == 0 || setDrawer != null);                     //multi-selecting doesn't make sense for a null drawer
            UnityEngine.Debug.Assert(multiSelect == 0 || setDrawer.Parent is ICollectionDrawer); //for now multi-selection is only supported for collection members
            UnityEngine.Debug.Assert(multiSelect != -1 || isMultiSelection);                     //can't remove from multi-selection if there is no multi-selection
            UnityEngine.Debug.Assert(!isMultiSelection || multiSelection.Count >= 2);            //multi-selection requires at least two selected drawers
                        #endif

                        #if SAFE_MODE || DEV_MODE
            if (setDrawer != null && !setDrawer.Selectable)
            {
                                #if DEV_MODE
                UnityEngine.Debug.LogError("SetFocusedDrawer(" + StringUtils.ToString(setDrawer) + ").Selectable was " + StringUtils.False);
                                #endif
                for (setDrawer = setDrawer.Parent; setDrawer != null && !setDrawer.Selectable; setDrawer = setDrawer.Parent)
                {
                    ;
                }
            }
                        #endif

                        #if SAFE_MODE || DEV_MODE
            if (setDrawer != null)
            {
                                #if DEV_MODE && PI_ASSERTATIONS
                UnityEngine.Debug.Assert(setDrawer.Selectable, "SetFocusedDrawer(" + StringUtils.ToString(setDrawer) + ").Selectable was " + StringUtils.False);
                UnityEngine.Debug.Assert(!setDrawer.Inactive, "SetFocusedDrawer(" + StringUtils.ToString(setDrawer) + ").Inactive was " + StringUtils.True);
                UnityEngine.Debug.Assert(setDrawer.ShouldShowInInspector, "SetFocusedDrawer(" + StringUtils.ToString(setDrawer) + ").ShowInInspector was " + StringUtils.False);
                UnityEngine.Debug.Assert(inspector != null, "SetFocusedDrawer(" + StringUtils.ToString(setDrawer) + ") inspector was " + StringUtils.Null);
                UnityEngine.Debug.Assert(inspectorPart == InspectorPart.Viewport, "SetFocusedDrawer(" + StringUtils.ToString(setDrawer) + ") inspectorPart was " + inspectorPart);
                UnityEngine.Debug.Assert(!ObjectPicker.IsOpen, "SetFocusedDrawer(" + StringUtils.ToString(setDrawer) + ") ObjectPicker.IsOpen was " + StringUtils.True);
                //UnityEngine.Debug.Assert(inspector.InspectorDrawer.HasFocus); //this can be true if an item is right cicked
                                #endif

                if (inspector == null)
                {
                    Inspector = InspectorUtility.ActiveInspector;
                }
                inspectorPart = InspectorPart.Viewport;

                //this can be true if an item was just right-clicked
                if (!inspector.InspectorDrawer.HasFocus)
                {
                                        #if DEV_MODE
                    UnityEngine.Debug.Log("Manually focusing window! Event=" + StringUtils.ToString(UnityEngine.Event.current));
                                        #endif
                    inspector.InspectorDrawer.FocusWindow();
                }
            }
                        #endif

                        #if DEV_MODE && DEBUG_SET_DRAWER
            UnityEngine.Debug.Log(StringUtils.ToColorizedString("Selected.SetFocusedDrawer(", setDrawer, ", multiSelect=", multiSelect, ", reason=", reason, ")"));
                        #endif

            switch (multiSelect)
            {
            case 0:
                focusedDrawer = setDrawer;
                ClearMultiSelection(reason, setDrawer);
                if (setDrawer != focusedDrawerWas)
                {
                    if (focusedDrawerWas != null && !focusedDrawerWas.Inactive)
                    {
                        focusedDrawerWas.OnDeselected(reason, setDrawer);
                    }
                    if (setDrawer != null)
                    {
                        if (!(setDrawer is ITextFieldDrawer) && !(setDrawer is ICustomEditorDrawer))
                        {
                            DrawGUI.EditingTextField = false;
                        }
                        setDrawer.OnSelected(reason, focusedDrawerWas, false);
                    }
                    else
                    {
                        DrawGUI.EditingTextField = false;
                    }

                    if (inspector != null)
                    {
                        // This can possibly help in ensuring that selection rects are drawn in the right place
                        // and in ensuring that the inspector feels very responsive.
                        inspector.OnNextLayout(inspector.RefreshView);
                    }
                }
                break;

            case 1:
                DrawGUI.EditingTextField = false;

                bool wasSelected = IsSelected(setDrawer);
                focusedDrawer = setDrawer;

                multiSelection.AddIfDoesNotContain(focusedDrawerWas);
                multiSelection.AddIfDoesNotContain(setDrawer);

                UpdateMultiSelection();

                if (!wasSelected)
                {
                    setDrawer.OnSelected(reason, focusedDrawerWas, isMultiSelection);
                }

                if (inspector != null)
                {
                    // This can possibly help in ensuring that selection rects are drawn in the right place
                    // and in ensuring that the inspector feels very responsive.
                    inspector.OnNextLayout(inspector.RefreshView);
                }

                break;

            case -1:
                multiSelection.Remove(setDrawer);
                if (setDrawer == focusedDrawer)
                {
                    int selectedCount = multiSelection.Count;
                    focusedDrawer = selectedCount == 0 ? setDrawer : multiSelection[selectedCount - 1];
                }
                UpdateMultiSelection();

                if (setDrawer != focusedDrawer && !setDrawer.Inactive)
                {
                    setDrawer.OnDeselected(reason, focusedDrawer);
                }

                if (!isMultiSelection)
                {
                    DrawGUI.EditingTextField = false;
                }
                else if (focusedDrawer != null)
                {
                    if (!(setDrawer is ITextFieldDrawer))
                    {
                        DrawGUI.EditingTextField = false;
                    }
                }
                else
                {
                    DrawGUI.EditingTextField = false;
                }

                if (inspector != null)
                {
                    // This can possibly help in ensuring that selection rects are drawn in the right place
                    // and in ensuring that the inspector feels very responsive.
                    inspector.OnNextLayout(inspector.RefreshView);
                }

                break;
            }

            if (focusedDrawer != null)
            {
                rowIndex        = focusedDrawer.GetSelectedRowIndex();
                rowElementCount = setDrawer.GetRowSelectableCount();
            }

                        #if DEV_MODE && PI_ASSERTATIONS
            UnityEngine.Debug.Assert(multiSelect != 0 || !isMultiSelection);
            UnityEngine.Debug.Assert(!isMultiSelection || multiSelection.Count >= 2);
                        #endif
        }
Example #16
0
 /// <inheritdoc/>
 public void Select(IInspector inspector, InspectorPart part, ReasonSelectionChanged reason)
 {
     selected.SetInspectorAndPart(inspector, part, reason);
 }
Example #17
0
 /// <inheritdoc/>
 public void AddToMultiSelection(IInspector setInspector, InspectorPart setPart, IDrawer add, ReasonSelectionChanged reason)
 {
     Select(setInspector, setPart, add, reason, 1);
 }
Example #18
0
        /// <summary>
        /// Sets mouseovered inspector part to given value. Optionally clears controls.
        /// </summary>
        /// <param name="setInspector"> The inspector to set as the mouseovered inspector. Can be null. </param>
        /// <param name="setInspectorPart"> The inspector part to set as the mouseovered part. </param>
        /// <param name="clearControls">
        /// True to also clear mouseovered selectable and right-clickable drawer.
        /// If setInspector is null or InspectorPart is not Viewport, drawer will get cleared regardless of the value of this flag.
        /// </param>
        /// <returns> True if mouseovered inspector or part changed. </returns>
        public bool SetInspectorAndPart([CanBeNull] IInspector setInspector, InspectorPart setInspectorPart, bool clearControls)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            var inspectorWasForDebugging = Inspector;
            var partWasForDebugging      = InspectorPart;
            if (setInspector == null && !clearControls)
            {
                Debug.LogWarning("Mouseovered.SetInspector setInspector was " + StringUtils.Null + " but clearControls was " + StringUtils.False);
            }
                        #endif

            bool changed;

            if (InspectorPart != setInspectorPart)
            {
                changed = true;

                                #if DEV_MODE && (DEBUG_SET_INSPECTOR || DEBUG_SET_INSPECTOR_PART)
                Debug.Log(StringUtils.ToColorizedString("Mouseovered.SetInspectorAndPart(", setInspector, ", ", setInspectorPart, ")"));
                                #endif

                var inspectorWas = Inspector;

                if (setInspectorPart == InspectorPart.None)
                {
                                        #if DEV_MODE && PI_ASSERTATIONS
                    Debug.Assert(clearControls);
                    Debug.Assert(setInspector == null, "Mouseovered.SetInspectorAndPart called with inspectorPart " + StringUtils.Red("None") + " but setInspector " + setInspector);
                                        #endif
                    Clear();

                                        #if DEV_MODE && PI_ASSERTATIONS
                    Debug.Assert(Inspector == setInspector);
                                        #endif
                }
                else if (setInspectorPart != InspectorPart.Viewport || clearControls)
                {
                    InspectorPart = setInspectorPart;
                    SetInspector(setInspector, true);

                                        #if DEV_MODE && PI_ASSERTATIONS
                    Debug.Assert(Inspector == setInspector);
                                        #endif
                }
                else
                {
                    InspectorPart = setInspectorPart;
                    SetInspector(setInspector, false);

                                        #if DEV_MODE && PI_ASSERTATIONS
                    Debug.Assert(Inspector == setInspector);
                                        #endif
                }
            }
            else if (setInspector != Inspector)
            {
                var inspectorWas = Inspector;

                changed = true;

                                #if DEV_MODE && (DEBUG_SET_INSPECTOR || DEBUG_SET_INSPECTOR_PART)
                Debug.Log(StringUtils.ToColorizedString("Mouseovered.SetInspectorAndPart(", setInspector, ", ", setInspectorPart, ")"));
                                #endif

                Inspector = setInspector;
                if (setInspector == null)
                {
                    SetInspector(null, true);
                }
                else
                {
                    SetInspector(setInspector, clearControls);
                }

                                #if DEV_MODE && PI_ASSERTATIONS
                Debug.Assert(inspectorWas != setInspector);
                                #endif
            }
            else
            {
                if (clearControls)
                {
                                        #if DEV_MODE
                    if (setInspector != null && setInspectorPart == InspectorPart.Viewport)
                    {
                        Debug.LogWarning("Mouseovered.SetInspectorAndPart was called with clearControls " + StringUtils.True + " even though mouseovered inspector " + setInspector + " or part " + setInspectorPart + " did not change. Was this intentional?");
                    }
                                        #endif

                    changed = ClearControls();
                }
                else
                {
                    changed = false;
                }
            }

                        #if DEV_MODE && PI_ASSERTATIONS
            if (Inspector != setInspector)
            {
                Debug.LogError("Mouseovered.Inspector value was " + (Inspector == null ? "null" : Inspector.ToString()) + " after SetInspectorAndPart(" + (setInspector == null ? "null" : setInspector.ToString()) + ", " + StringUtils.ToColorizedString(InspectorPart) + ") finished. Inspector was " + (inspectorWasForDebugging == null ? "null" : inspectorWasForDebugging.ToString()) + " and part " + partWasForDebugging + " when method was called.");
            }
            AssertStateIsValid();
                        #endif

            return(changed);
        }
Example #19
0
 /// <inheritdoc/>
 public void RemoveFromMultiSelection(IInspector setInspector, InspectorPart setPart, IDrawer remove, ReasonSelectionChanged reason)
 {
     Select(setInspector, setPart, remove, reason, -1);
 }