Example #1
0
 /// <inheritdoc/>
 public override bool OnMiddleClick(Event inputEvent)
 {
     if (CanBeActivated())
     {
         DrawGUI.Ping(inspector.State.selectionHistory.PeekPreviousInSelectionHistory());
         GUIUtility.ExitGUI();
         return(true);
     }
     return(false);
 }
Example #2
0
        /// <summary>
        /// Invokes the Method, messages the user about it and updates results member if method has a return value.
        /// </summary>
        /// <param name="pingIfUnityObject"> True if should "ping" the return value, if the method has one, and it's of type UnityEngine.Object  or UnityEngine.Object[], and not null or empty. </param>
        /// <param name="displayDialogIfNotUnityObject"> True if should display a popup dialog to the user about the results, if method has a return type, and it's not of type UnityEngine.Object or UnityEngine.Object[]. </param>
        /// <param name="copyToClipboardIfNotPingedOrDialogShown"> True if should copy the method return value to clipboard, if it has one, and if value was not pinged and popup was not displayed. </param>
        ///  <param name="pingIfUnityObject"> True if should select the return value(s), if the method has one, and it's of type UnityEngine.Object  or UnityEngine.Object[], and not null or empty. </param>
        private void Invoke(bool pingIfUnityObject, bool displayDialogIfNotUnityObject, bool copyToClipboardIfNotPingedOrDialogShown, bool selectIfUnityObject)
        {
            Inspector.RefreshView();             // make sure repaint gets called immediately

            string error;
            bool   suppressMessages = pingIfUnityObject || displayDialogIfNotUnityObject || copyToClipboardIfNotPingedOrDialogShown || selectIfUnityObject;

            Invoke(out error, suppressMessages);

            if (!hasReturnValue)
            {
                                #if DEV_MODE && PI_ASSERTATIONS
                Debug.Assert(!suppressMessages);
                                #endif
                return;
            }

            if (pingIfUnityObject)
            {
                var list = new List <Object>(0);
                if (UnityObjectExtensions.TryExtractObjectReferences(results, ref list))
                {
                    DrawGUI.Ping(list.ToArray());
                }
            }

            if (selectIfUnityObject)
            {
                var list = new List <Object>(0);
                if (UnityObjectExtensions.TryExtractObjectReferences(results, ref list))
                {
                    Inspector.Select(list.ToArray());
                }
            }

            if (displayDialogIfNotUnityObject && !isCoroutine)
            {
                TryDisplayDialogForResult();
            }
            else if (copyToClipboardIfNotPingedOrDialogShown)
            {
                Clipboard.Copy(result);
            }

            if (Event.current != null)
            {
                ExitGUIUtility.ExitGUI();                 // avoid ArgumentException: Getting control 1's position in a group with only 1 controls when doing repaint
            }
        }
Example #3
0
        private bool TryPingResult()
        {
            if (!hasReturnValue)
            {
                return(false);
            }

            if (!hasResult)
            {
                Invoke();
            }

            var list = new List <Object>(0);

            if (UnityObjectExtensions.TryExtractObjectReferences(results, ref list))
            {
                DrawGUI.Ping(list.ToArray());
            }
            return(true);
        }
Example #4
0
        private bool Draw(ref bool menuItemWasClicked)
        {
            if (instance == null)
            {
                return(false);
            }

                        #if DEV_MODE || PROFILE_POWER_INSPECTOR
            Profiler.BeginSample("PopupMenu.Draw");
                        #endif

            PopupMenuItemUtility.drawWithFullPath = filter.Length > 0;

            bool dirty = false;
            var  e     = Event.current;
            //using raw type, since we consume all click events
            var  eventType = e.rawType;
            bool lmbClick  = eventType == EventType.MouseDown && e.button == 0;
            bool mmbClick  = eventType == EventType.MouseDown && e.button == 2;

            if (clearingText)
            {
                if (eventType == EventType.Layout)
                {
                    clearingText = false;
                }
                GUI.changed = true;
                dirty       = true;
            }
            else
            {
                if (!DrawGUI.EditingTextField)
                {
                    DrawGUI.EditingTextField = true;
                    GUI.changed = true;
                    dirty       = true;
                }

                if (!string.Equals(GUI.GetNameOfFocusedControl(), ControlName))
                {
                    DrawGUI.FocusControl(ControlName);
                    GUI.changed = true;
                    dirty       = true;
                }
            }

            if (DrawFilterField())
            {
                dirty = true;
            }

            DrawGUI.Active.ColorRect(headerRect, BgColorNavigationBar);

            bool hasFilter      = FilterString.Length > 0;
            bool drawBackArrow  = !hasFilter && activeGroup != null;
            bool drawLabelField = currentViewLabel.text.Length > 0;

            if (drawBackArrow || drawLabelField)
            {
                if (drawBackArrow)
                {
                    GUI.Label(backArrowRect, GUIContent.none, "AC LeftArrow");
                    if (lmbClick && backArrowRect.Contains(e.mousePosition))
                    {
                        goBackLevelNextLayout = true;
                        dirty = true;
                    }
                }

                DrawGUI.DrawRect(headerRect, new Color32(24, 24, 24, 255), localDrawAreaOffset);

                if (drawLabelField)
                {
                    GUI.Label(headerLabelRect, currentViewLabel, InspectorPreferences.Styles.PopupMenuTitle);
                }

                GUI.DrawTexture(dividerRect, InspectorUtility.Preferences.graphics.horizontalSplitterBg);
            }

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(contentRect.x == 0f, "contentRect.x=" + contentRect.x);
            Debug.Assert(contentRect.y == 0f, "contentRect.y=" + contentRect.y);
            Debug.Assert(contentRect.height == currentViewItemCount * DrawGUI.SingleLineHeight, "contentRect.height=" + contentRect.height + ", currentViewItemCount=" + currentViewItemCount);
            Debug.Assert(currentViewItemCount == currentViewItems.Count, "currentViewItemCount=" + currentViewItemCount + ", currentViewItems.Count=" + currentViewItems.Count);
            Debug.Assert(viewRect.height == contentRect.height || viewRect.height == ScrollAreaMaxHeight, "viewRect.height (" + viewRect.height + ") != contentRect.height (" + contentRect.height + ") NOR ScrollAreaMaxHeight (" + ScrollAreaMaxHeight + ")");
                        #endif

            var setScrollPos = GUI.BeginScrollView(viewRect, scrollPos, contentRect);
            {
                if (setScrollPos.y != scrollPos.y)
                {
                    SetScrollPos(setScrollPos.y, true);
                    dirty = true;
                }

                var memberRect = contentRect;
                DrawGUI.Active.ColorRect(memberRect, BgColor);

                memberRect.height = DrawGUI.SingleLineHeight;

                //only start drawing from first visible member
                memberRect.y += firstVisibleIndex * DrawGUI.SingleLineHeight;

                int last = lastVisibleIndex;
                if (last >= currentViewItemCount)
                {
                                        #if DEV_MODE
                    Debug.LogWarning(ToString() + " - last (" + last + ") >= visibleCount (" + (lastVisibleIndex - firstVisibleIndex + 1) + ") with firstVisibleIndex=" + firstVisibleIndex + " and lastVisibleIndex=" + lastVisibleIndex);
                                        #endif
                    last = currentViewItemCount - 1;
                }

                for (int n = firstVisibleIndex; n <= last; n++)
                {
                    var  item     = currentViewItems[n];
                    bool selected = n == selectedMemberIndex;

                    if (selected)
                    {
                        DrawGUI.Active.ColorRect(memberRect, InspectorUtility.Preferences.theme.BackgroundSelected);
                    }

                    if (memberRect.Contains(e.mousePosition))
                    {
                        if (!selected)
                        {
                            SetSelectedMember(n, false);
                            dirty = true;
                        }

                        if (lmbClick)
                        {
                            dirty = true;
                            if (item.IsGroup)
                            {
                                SetActiveItem(item);
                                break;
                            }

                            menuItemWasClicked = true;
                            inspector.OnNextLayout(() => OnMenuItemClicked(item));
                            break;
                        }

                        if (mmbClick)
                        {
                            if (item.IsGroup)
                            {
                                var unityObjects = item.children.Select(menuItem => menuItem.IdentifyingObject as Object).ToArray();
                                if (unityObjects.Length > 0)
                                {
                                    DrawGUI.Ping(unityObjects);
                                }
                            }
                            else
                            {
                                var itemValue   = item.IdentifyingObject;
                                var unityObject = itemValue as Object;
                                if (unityObject != null)
                                {
                                    DrawGUI.Ping(unityObject);
                                }
                                var unityObjects = itemValue as Object[];
                                if (unityObjects != null)
                                {
                                    DrawGUI.Ping(unityObjects);
                                }
                            }
                        }
                    }

                    if (PopupMenuItemUtility.Draw(memberRect, selectedMemberIndex == n, item))
                    {
                                                #if DEV_MODE
                        Debug.Log(GetType().Name + " - member " + item + " clicked with eventType " + eventType + "! (member returned true)");
                                                #endif

                        dirty = true;

                        if (item.IsGroup)
                        {
                            SetActiveItem(item);
                            break;
                        }

                        menuItemWasClicked = true;
                        inspector.OnNextLayout(() => OnMenuItemClicked(item));
                        DrawGUI.Use(e);
                        break;
                    }

                    if (!item.IsGroup)
                    {
                        bool ticked = tickedItems != null && tickedItems.Contains(item);

                        var toggleRect = memberRect;
                        toggleRect.width = 16f;
                        toggleRect.x    += memberRect.width - toggleRect.width;

                        if (canTickMultiple)
                        {
                            bool setTicked = GUI.Toggle(toggleRect, ticked, GUIContent.none, InspectorUtility.Preferences.GetStyle("OL Toggle"));
                            if (setTicked != ticked)
                            {
                                if (ticked)
                                {
                                    tickedItems.Add(item);
                                }
                                else
                                {
                                    tickedItems.Remove(item);
                                }

                                menuItemWasClicked = true;
                                inspector.OnNextLayout(() => OnMenuItemClicked(item));
                                DrawGUI.Use(e);
                                break;
                            }
                        }
                        else if (ticked)
                        {
                            GUI.Toggle(toggleRect, true, GUIContent.none, InspectorUtility.Preferences.GetStyle("OL Toggle"));
                        }
                    }

                    GUI.enabled   = true;
                    memberRect.y += DrawGUI.SingleLineHeight;
                }

                ///after visible part, count * DrawGUI.singleLineHeight
                GUI.EndScrollView();
            }

                        #if DEV_MODE || PROFILE_POWER_INSPECTOR
            Profiler.EndSample();
                        #endif

            return(dirty);
        }
        /// <inheritdoc/>
        public override bool DrawBody(Rect position)
        {
            position.y     += 10f;
            position.height = DrawGUI.SingleLineHeight;
            position.x     += DrawGUI.LeftPadding;
            position.width -= DrawGUI.LeftPadding + DrawGUI.RightPadding;

            var buttonRect = position;

            if (GUI.Button(buttonRect, "Switch To Stacked Mode"))
            {
                UserSettings.MergedMultiEditMode = false;
                Inspector.ForceRebuildDrawers();
            }

            position.y += position.height + 10f;

            GUI.Label(position, "Narrow the Selection:");
            position.y += position.height + 2f;

            bool changed = false;

            //position.y += 4f;
            var backgroundRect = position;

            backgroundRect.width -= 19f;
            backgroundRect.height = DrawGUI.SingleLineHeight + 2f;

            var iconRect = backgroundRect;

            iconRect.width  = 16f;
            iconRect.height = 16f;
            iconRect.x     += 2f;
            iconRect.y     += 1f;

            var labelRect = iconRect;

            labelRect.x    += iconRect.width + 2f;
            labelRect.width = backgroundRect.width - iconRect.width - 4f;

            var peekRect = backgroundRect;

            peekRect.x      = backgroundRect.xMax + 3f;
            peekRect.width  = 20f;
            peekRect.height = 20f;

            float offset = DrawGUI.SingleLineHeight + 5f;

            for (int n = 0, count = targetsGrouped.Count; n < count; n++)
            {
                if (GUI.Button(backgroundRect, GUIContent.none, InspectorPreferences.Styles.MethodBackground))
                {
                    if (Event.current.button == 0)
                    {
                        Inspector.Select(targetsGrouped[n].targets.ToArray());
                    }
                    else if (Event.current.button == 2)
                    {
                        DrawGUI.Ping(targetsGrouped[n].targets.ToArray());
                    }

                    DrawGUI.Use(Event.current);
                    changed = true;
                }
                else if (GUIUtility.hotControl == 0)
                {
                    DrawGUI.Active.AddCursorRect(backgroundRect, MouseCursor.Link);
                }

                var group = targetsGrouped[n];

                GUI.DrawTexture(iconRect, group.preview);

                GUI.Label(labelRect, group.label);

                GUIContent peekLabel  = InspectorUtility.Preferences.labels.SplitViewIcon;
                var        tooltipWas = peekLabel.tooltip;
                peekLabel.tooltip = "Peek";
                if (GUI.Button(peekRect, InspectorUtility.Preferences.labels.SplitViewIcon, InspectorPreferences.Styles.Centered))
                {
                    var splittable = Inspector.InspectorDrawer as ISplittableInspectorDrawer;
                    if (splittable != null && splittable.CanSplitView)
                    {
                        splittable.ShowInSplitView(targetsGrouped[n].targets.ToArray());
                    }
                    else
                    {
                        Inspector.Select(targetsGrouped[n].targets.ToArray());
                    }
                    DrawGUI.Use(Event.current);
                    changed = true;
                }
                else if (GUIUtility.hotControl == 0)
                {
                    DrawGUI.Active.AddCursorRect(peekRect, MouseCursor.Link);
                }
                peekLabel.tooltip = tooltipWas;

                backgroundRect.y += offset;
                labelRect.y      += offset;
                iconRect.y       += offset;
                peekRect.y       += offset;
            }

            return(changed);
        }