Ejemplo n.º 1
0
        /// <inheritdoc />
        public override bool OnKeyboardInputGiven(Event inputEvent, KeyConfigs keys)
        {
            if (InspectorUtility.ActiveInspector.Preferences.keyConfigs.addComponent.DetectAndUseInput(inputEvent))
            {
                Select(ReasonSelectionChanged.KeyPressShortcut);
                Open();
                return(true);
            }

            switch (Event.current.keyCode)
            {
            case KeyCode.Return:
            case KeyCode.KeypadEnter:
                GUI.changed = true;
                DrawGUI.Use(inputEvent);
                if (!open)
                {
                    Open();
                }
                return(true);

            //TO DO: implement "opening" namespace or going back one level
            case KeyCode.LeftArrow:
            case KeyCode.RightArrow:
                DrawGUI.Use(inputEvent);
                return(true);

            default:
                return(base.OnKeyboardInputGiven(inputEvent, keys));
            }
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public override bool OnKeyboardInputGiven(Event inputEvent, KeyConfigs keys)
        {
                        #if DEV_MODE && DEBUG_KEYBOARD_INPUT
            Debug.Log(GetType().Name + ".OnKeyboardInputGiven(" + inputEvent.keyCode + ") with DrawGUI.EditingTextField=" + DrawGUI.EditingTextField);
                        #endif

            switch (inputEvent.keyCode)
            {
            case KeyCode.Escape:
                if (hasUnappliedChanges)
                {
                                                #if DEV_MODE && DEBUG_APPLY_VALUE
                    Debug.Log(GetType().Name + " - Discarding unapplied value " + StringUtils.TypeToString(valueUnapplied) + " because esc was pressed");
                                                #endif

                    DiscardUnappliedChanges();
                    GUI.changed = true;
                }
                return(true);

            case KeyCode.Return:
            case KeyCode.KeypadEnter:
                if (hasUnappliedChanges)
                {
                                                #if DEV_MODE && DEBUG_APPLY_VALUE
                    Debug.Log(GetType().Name + " - Applying value " + StringUtils.TypeToString(valueUnapplied) + " because return or enter was pressed");
                                                #endif

                    ApplyUnappliedChanges();
                    GUI.changed = true;
                }
                return(true);
            }
            return(base.OnKeyboardInputGiven(inputEvent, keys));
        }
Ejemplo n.º 3
0
        /// <inheritdoc/>
        public override bool OnKeyboardInputGiven(Event inputEvent, KeyConfigs keys)
        {
                        #if DEV_MODE && DEBUG_KEYBOARD_INPUT
            Debug.Log("OnKeyboardInputGiven(" + StringUtils.ToString(inputEvent) + ") with EditingTextField=" + DrawGUI.EditingTextField);
                        #endif

            if (keys.prevComponent.DetectAndUseInput(inputEvent))
            {
                var backButton = GetVisibleItem <BackButtonToolbarItem>();
                if (backButton != null)
                {
                    return(backButton.OnKeyboardInputGiven(inputEvent, keys));
                }
            }

            if (keys.nextComponent.DetectAndUseInput(inputEvent))
            {
                var forwardButton = GetVisibleItem <ForwardButtonToolbarItem>();
                if (forwardButton != null)
                {
                    return(forwardButton.OnKeyboardInputGiven(inputEvent, keys));
                }
            }

            return(base.OnKeyboardInputGiven(inputEvent, keys));
        }
Ejemplo n.º 4
0
        /// <inheritdoc cref="IDrawer.OnKeyboardInputGiven" />
        public override bool OnKeyboardInputGiven(Event inputEvent, KeyConfigs keys)
        {
                        #if DEV_MODE && DEBUG_KEYBOARD_INPUT
            Debug.Log(ToString() + ".OnKeyboardInputGiven(" + StringUtils.ToString(inputEvent) + ")");
                        #endif

            if (DrawToggleNullButton)
            {
                switch (inputEvent.keyCode)
                {
                case KeyCode.F2:
                    var textFieldMember = ValueDrawer as ITextFieldDrawer;
                    if (textFieldMember != null)
                    {
                        DrawGUI.Use(inputEvent);
                        textFieldMember.StartEditingField();
                        return(true);
                    }
                    return(false);

                case KeyCode.Return:
                case KeyCode.Space:
                case KeyCode.KeypadEnter:
                    if (inputEvent.modifiers == EventModifiers.None)
                    {
                        OnNullToggleButtonClicked();
                        GUI.changed = true;
                        DrawGUI.Use(inputEvent);
                        return(true);
                    }
                    break;
                }
            }
            return(base.OnKeyboardInputGiven(inputEvent, keys));
        }
Ejemplo n.º 5
0
        /// <inheritdoc />
        public sealed override bool OnKeyboardInputGiven(Event e, KeyConfigs keys)
        {
            if (DrawGUI.EditingTextField)
            {
                return(false);
            }

            switch (e.keyCode)
            {
            case KeyCode.LeftArrow:
            case KeyCode.KeypadPlus:
                GUI.changed = true;
                DrawGUI.Use(e);
                TValue value     = Value;
                TValue decreased = RoundedAndClamped(Convert.ToDouble(value) - (e.shift ? step * 10d : step));
                if (decreased.CompareTo(value) != 0)
                {
                    Value = decreased;
                }
                return(true);

            case KeyCode.RightArrow:
            case KeyCode.KeypadMinus:
                GUI.changed = true;
                DrawGUI.Use(e);
                value = Value;
                TValue increased = RoundedAndClamped(Convert.ToDouble(value) + (e.shift ? step * 10d : step));
                if (increased.CompareTo(value) != 0)
                {
                    Value = increased;
                }
                return(true);
            }
            return(base.OnKeyboardInputGiven(e, keys));
        }
Ejemplo n.º 6
0
 /// <inheritdoc cref="IDrawer.OnKeyboardInputGiven" />
 public override bool OnKeyboardInputGiven(Event inputEvent, KeyConfigs keys)
 {
     if (ParentDrawerUtility.HandleKeyboardInput(this, inputEvent, keys))
     {
         return(true);
     }
     return(base.OnKeyboardInputGiven(inputEvent, keys));
 }
Ejemplo n.º 7
0
 /// <inheritdoc />
 public override bool OnKeyboardInputGiven(Event inputEvent, KeyConfigs keys)
 {
     if (keys.activate.DetectAndUseInput(inputEvent))
     {
         OpenMenu();
         return(true);
     }
     return(base.OnKeyboardInputGiven(inputEvent, keys));
 }
Ejemplo n.º 8
0
        /// <inheritdoc/>
        public override bool OnKeyboardInputGiven(Event inputEvent, KeyConfigs keys)
        {
            if (OnKeyboardInputGivenWhenNotSelected(inputEvent, keys))
            {
                return(true);
            }

            return(base.OnKeyboardInputGiven(inputEvent, keys));
        }
Ejemplo n.º 9
0
 /// <inheritdoc />
 public override bool OnKeyboardInputGiven(Event inputEvent, KeyConfigs keys)
 {
     if (keys.activate.DetectAndUseInput(inputEvent))
     {
         EditorGUIUtility.PingObject(Value);
         return(true);
     }
     return(base.OnKeyboardInputGiven(inputEvent, keys));
 }
Ejemplo n.º 10
0
 /// <inheritdoc/>
 public bool OnKeyboardInputGivenWhenNotSelected([NotNull] Event inputEvent, [NotNull] KeyConfigs keys)
 {
     for (int n = visibleItems.Length - 1; n >= 0; n--)
     {
         if (visibleItems[n].OnKeyboardInputGivenWhenNotSelected(inputEvent, keys))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 11
0
 /// <inheritdoc />
 public override bool OnKeyboardInputGiven(Event inputEvent, KeyConfigs keys)
 {
     switch (inputEvent.keyCode)
     {
     case KeyCode.Return:
     case KeyCode.KeypadEnter:
         GUI.changed = true;
         OnClick(inputEvent);
         return(true);
     }
     return(base.OnKeyboardInputGiven(inputEvent, keys));
 }
Ejemplo n.º 12
0
        /// <inheritdoc cref="IDrawer.OnKeyboardInputGiven" />
        public override bool OnKeyboardInputGiven(Event inputEvent, KeyConfigs keys)
        {
            if (inputEvent.type == EventType.KeyDown)            // && sideBarSelected)
            {
                switch (inputEvent.keyCode)
                {
                case KeyCode.Tab:
                    if (inputEvent.shift)
                    {
                        SetPreviousViewActive(true);
                        DrawGUI.Use(inputEvent);
                        return(true);
                    }
                    SetNextViewActive(true);
                    DrawGUI.Use(inputEvent);
                    return(true);

                case KeyCode.UpArrow:
                    SetPreviousViewActive(false);
                    DrawGUI.Use(inputEvent);
                    return(true);

                case KeyCode.DownArrow:
                    SetNextViewActive(false);
                    DrawGUI.Use(inputEvent);
                    return(true);

                case KeyCode.Home:
                    SetActiveView(0);
                    return(true);

                case KeyCode.End:
                    SetActiveView(headers.Length - 1);
                    return(true);

                case KeyCode.PageUp:
                    SetActiveView(activeHeaderIndex - 10);
                    return(true);

                case KeyCode.PageDown:
                    SetActiveView(activeHeaderIndex + 10);
                    return(true);

                case KeyCode.RightArrow:
                    SelectNextFieldDown(0);
                    return(true);
                }
            }
            return(base.OnKeyboardInputGiven(inputEvent, keys));
        }
Ejemplo n.º 13
0
        /// <inheritdoc/>
        public override bool OnKeyboardInputGivenWhenNotSelected(Event inputEvent, KeyConfigs keys)
        {
            if (keys.openNavigateBackMenu.DetectAndUseInput(inputEvent))
            {
                OnRightClick(inputEvent);
                return(true);
            }

            if (keys.stepBackInSelectionHistory.DetectAndUseInput(inputEvent))
            {
                OnActivated(inputEvent, false);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 14
0
        /// <inheritdoc/>
        public override bool OnKeyboardInputGiven(Event inputEvent, KeyConfigs keys)
        {
            if (DrawGUI.EditingTextField)
            {
                return(false);
            }

            switch (inputEvent.keyCode)
            {
            case KeyCode.Return:
            case KeyCode.KeypadEnter:
                GUI.changed = true;
                DrawGUI.Use(inputEvent);
                OnClick();
                return(true);
            }
            return(false);
        }
Ejemplo n.º 15
0
        /// <inheritdoc />
        public override bool OnKeyboardInputGiven(Event inputEvent, KeyConfigs keys)
        {
            if (DrawGUI.EditingTextField)
            {
                return(false);
            }

            switch (inputEvent.keyCode)
            {
            case KeyCode.RightArrow:
                if (showGetButton && showSetButton && firstButtonSelected)
                {
                    firstButtonSelected = false;
                    GUI.changed         = true;
                    return(true);
                }
                break;

            case KeyCode.LeftArrow:
                if (showGetButton && showSetButton && !firstButtonSelected)
                {
                    firstButtonSelected = true;
                    GUI.changed         = true;
                    return(true);
                }
                break;

            case KeyCode.Return:
            case KeyCode.KeypadEnter:
                GUI.changed = true;
                DrawGUI.Use(inputEvent);
                if (showGetButton && firstButtonSelected)
                {
                    InvokeGet();
                }
                else if (showSetButton && (!showGetButton || !firstButtonSelected))
                {
                    InvokeSet();
                }
                return(true);
            }

            return(base.OnKeyboardInputGiven(inputEvent, keys));
        }
Ejemplo n.º 16
0
        /// <inheritdoc cref="IDrawer.OnKeyboardInputGiven" />
        public override bool OnKeyboardInputGiven(Event inputEvent, KeyConfigs keys)
        {
            //the latter part is needed to fix an issue where editingTextField
            //gets changed by Unity internally before things get this far
            if (DrawGUI.EditingTextField || Value != valueUnapplied)
            {
                switch (inputEvent.keyCode)
                {
                case KeyCode.Escape:
                {
                                                #if DEV_MODE && DEBUG_APPLY_VALUE
                    Debug.Log(GetType().Name + " - Discarding unapplied value " + valueUnapplied + " because esc was pressed");
                                                #endif

                    DrawGUI.Use(inputEvent);
                    valueUnapplied = Value;
                    StopEditingField();
                    GUI.changed = true;
                    return(true);
                }

                case KeyCode.Return:
                case KeyCode.KeypadEnter:
                {
                                                #if DEV_MODE && DEBUG_APPLY_VALUE
                    Debug.Log(GetType().Name + " - Applying value " + valueUnapplied + " because return or enter was pressed");
                                                #endif

                    DrawGUI.Use(inputEvent);
                    base.DoSetValue(valueUnapplied, true, true);
                    StopEditingField();
                    GUI.changed = true;
                    return(true);
                }
                }
                return(false);
            }

            return(base.OnKeyboardInputGiven(inputEvent, keys));
        }
Ejemplo n.º 17
0
        /// <inheritdoc/>
        public override bool OnKeyboardInputGiven(Event inputEvent, KeyConfigs keys)
        {
            // Pass some keyboard inputs over to first member.
            // E.g. pressing F2 should immediately start editing key field.
            // However, pass over navigation related events nor shortcuts.
            if (inputEvent.modifiers == EventModifiers.None)
            {
                var keyMember = MembersBuilt[0];
                if (keyMember.ShouldShowInInspector)
                {
                    bool passOnInput = false;

                    if (inputEvent.character != 0 && inputEvent.modifiers == EventModifiers.None)
                    {
                        passOnInput = true;
                    }
                    else
                    {
                        switch (inputEvent.keyCode)
                        {
                        case KeyCode.F2:
                        case KeyCode.Return:
                        case KeyCode.KeypadEnter:
                            passOnInput = true;
                            break;
                        }
                    }

                    if (passOnInput)
                    {
                        keyMember.Select(ReasonSelectionChanged.KeyPressOther);
                        keyMember.OnKeyboardInputGiven(inputEvent, keys);
                        return(true);
                    }
                }
            }

            return(base.OnKeyboardInputGiven(inputEvent, keys));
        }
Ejemplo n.º 18
0
        /// <inheritdoc/>
        public override bool OnKeyboardInputGiven(Event inputEvent, KeyConfigs keys)
        {
            switch (inputEvent.keyCode)
            {
            case KeyCode.LeftArrow:
                DrawGUI.Use(inputEvent);
                int select = selectedTab - 1;
                if (select >= 0)
                {
                    GUI.changed = true;
                    SelectTab(select);
                }
                return(true);

            case KeyCode.RightArrow:
                DrawGUI.Use(inputEvent);
                select = selectedTab + 1;
                if (select < tabLabels.Length)
                {
                    GUI.changed = true;
                    SelectTab(select);
                }
                return(true);

            case KeyCode.KeypadEnter:
                DrawGUI.Use(inputEvent);
                select = selectedTab + 1;
                if (select >= tabLabels.Length)
                {
                    select = 0;
                }
                GUI.changed = true;
                SelectTab(select);
                return(true);
            }

            return(base.OnKeyboardInputGiven(inputEvent, keys));
        }
Ejemplo n.º 19
0
        /// <inheritdoc cref="IDrawer.OnKeyboardInputGiven" />
        public override bool OnKeyboardInputGiven(Event inputEvent, KeyConfigs keys)
        {
            switch (inputEvent.keyCode)
            {
            case KeyCode.F2:
            {
                GUI.changed = true;
                DrawGUI.Use(inputEvent);
                StartEditingField();
                return(true);
            }

            case KeyCode.Escape:
            {
                GUI.changed = true;
                KeyboardControlUtility.KeyboardControl = 0;
                DrawGUI.Use(inputEvent);
                StopEditingField();
                return(true);
            }
            }
            return(base.OnKeyboardInputGiven(inputEvent, keys));
        }
Ejemplo n.º 20
0
        /// <inheritdoc/>
        public virtual bool OnKeyboardInputGiven(Event inputEvent, KeyConfigs keys)
        {
                        #if DEV_MODE && DEBUG_KEYBOARD_INPUT
            Debug.Log(ToString() + ".OnKeyboardInputGiven(" + StringUtils.ToString(inputEvent) + ")");
                        #endif

            if (keys.activate.DetectInput(inputEvent))
            {
                                #if DEV_MODE
                Debug.Log(ToString() + " - activate input given!");
                                #endif

                if (HandleOnBeingActivated(inputEvent, ActivationMethod.KeyboardActivate))
                {
                    return(true);
                }

                if (inputEvent.type != EventType.Used && OnActivated(inputEvent, false))
                {
                    DrawGUI.Use(inputEvent);
                    GUIUtility.ExitGUI();
                    return(true);
                }
            }

            if (inputEvent.keyCode == KeyCode.Menu)
            {
                if (OnMenuInputGiven(inputEvent))
                {
                    DrawGUI.Use(inputEvent);
                    GUIUtility.ExitGUI();
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 21
0
        /// <inheritdoc/>
        public override bool OnKeyboardInputGiven(Event inputEvent, KeyConfigs keys)
        {
            switch (inputEvent.keyCode)
            {
            case KeyCode.F2:
                StartEditing();
                return(true);

            case KeyCode.Escape:
                DrawGUI.Use(inputEvent);
                ClearFilterField(false);
                return(true);

            case KeyCode.Return:
            case KeyCode.KeypadEnter:
                if (!DrawGUI.EditingTextField)
                {
                    StartEditing();
                }
                var drawer = inspector.State.drawers.FirstVisible();
                if (drawer != null)
                {
                    var select = drawer.GetNextSelectableDrawerRight(true, null);

                    if (select == null)
                    {
                        return(false);
                    }

                    for (int n = 0; n < 20; n++)                            //arbitrarily chosen depth; not using while(true) just to prevent infinite loops from being possible
                    {
                        var parent = select as IParentDrawer;
                        if (parent == null)
                        {
                            break;
                        }

                        if (parent.SelfPassesSearchFilter(inspector.State.filter))
                        {
                            break;
                        }

                        var visibleMembers = parent.VisibleMembers;
                        if (visibleMembers.Length == 0)
                        {
                            break;
                        }

                        select = visibleMembers[0];
                    }

                    select.Select(ReasonSelectionChanged.SelectNextControl);
                }
                return(true);

            case KeyCode.LeftArrow:
                if (DrawGUI.EditingTextField && FilterString.Length > 0)
                {
                    // Return true to "consume" the click, so that toolbar won't react to the input (moving to next toolbar item).
                    // However don't actually use the Event, so that filterDrawer can react to input.
                    return(true);
                }
                // Return false to let toolbar know that it can react to the input (moving to the next toolbar item).
                return(false);

            case KeyCode.RightArrow:
                if (DrawGUI.EditingTextField && FilterString.Length > 0)
                {
                    // Return true to "consume" the click, so that toolbar won't react to the input (moving to next toolbar item).
                    // However don't actually use the Event, so that filterDrawer can react to input.
                    return(true);
                }
                // Return false to let toolbar know that it can react to the input (moving to the next toolbar item).
                return(false);
            }
            return(false);
        }
Ejemplo n.º 22
0
        /// <inheritdoc cref="IDrawer.OnKeyboardInputGiven" />
        public override bool OnKeyboardInputGiven(Event inputEvent, KeyConfigs keys)
        {
                        #if DEV_MODE && DEBUG_KEYBOARD_INPUT
            Debug.Log(ToString() + ".OnKeyboardInputGiven(" + StringUtils.ToString(inputEvent) + ")");
                        #endif

            if (DrawGUI.EditingTextField)
            {
                switch (inputEvent.keyCode)
                {
                case KeyCode.Escape:
                {
                    GUI.changed = true;
                    StopEditingField();
                    DrawGUI.Use(inputEvent);
                    return(true);
                }

                case KeyCode.Return:
                case KeyCode.KeypadEnter:
                {
                    if (inputEvent.modifiers == EventModifiers.None)
                    {
                        GUI.changed = true;
                        StopEditingField();
                        DrawGUI.Use(inputEvent);
                        return(true);
                    }
                    return(false);
                }
                }

                if (keys.DetectTextFieldReservedInput(inputEvent, TextFieldType.Numeric))
                {
                    return(false);
                }
                return(base.OnKeyboardInputGiven(inputEvent, keys));
            }

            switch (inputEvent.keyCode)
            {
            case KeyCode.Alpha0:
            case KeyCode.Alpha1:
            case KeyCode.Alpha2:
            case KeyCode.Alpha3:
            case KeyCode.Alpha4:
            case KeyCode.Alpha5:
            case KeyCode.Alpha6:
            case KeyCode.Alpha7:
            case KeyCode.Alpha8:
            case KeyCode.Alpha9:
            case KeyCode.Keypad0:
            case KeyCode.Keypad1:
            case KeyCode.Keypad2:
            case KeyCode.Keypad3:
            case KeyCode.Keypad4:
            case KeyCode.Keypad5:
            case KeyCode.Keypad6:
            case KeyCode.Keypad7:
            case KeyCode.Keypad8:
            case KeyCode.Keypad9:
                if (inputEvent.modifiers == EventModifiers.None)
                {
                    GUI.changed = true;
                    string valueString = inputEvent.ToString();

                    char valueChar    = valueString[valueString.Length - 1];
                    var  valueNumeric = char.GetNumericValue(valueChar);
                    var  setValue     = (TValue)Convert.ChangeType(valueNumeric, typeof(TValue));

                                                #if DEV_MODE
                    Debug.Log("valueString=" + valueString + ", valueChar=" + valueChar + ", valueNumeric=" + valueNumeric + ", setValue=" + setValue);
                                                #endif

                    Value = setValue;
                    DrawGUI.Use(inputEvent);
                    StartEditingField();

                                                #if UNITY_EDITOR
                    TextEditorUtility.MoveCursorToTextEditorEnd();
                                                #endif
                    return(true);
                }
                break;

            case KeyCode.Return:
            case KeyCode.KeypadEnter:
            {
                if (inputEvent.modifiers == EventModifiers.None && !ReadOnly)
                {
                    GUI.changed = true;
                    DrawGUI.Use(inputEvent);
                    StartEditingField();
                    return(true);
                }
                return(false);
            }

            case KeyCode.Comma:
            case KeyCode.Period:
            case KeyCode.KeypadPeriod:
                if (!ReadOnly)
                {
                                                #if UNITY_EDITOR
                    InspectorUtility.ActiveInspector.OnNextLayout(() => TextEditorUtility.Insert('.'));
                                                #endif
                    return(true);
                }
                return(false);

            case KeyCode.Plus:
            case KeyCode.KeypadPlus:
                if (!ReadOnly)
                {
                    GUI.changed = true;
                    DrawGUI.Use(inputEvent);
                    double valueNumeric = (double)Convert.ChangeType(Value, Types.Double) + 1d;
                    Value = (TValue)Convert.ChangeType(valueNumeric, typeof(TValue));
                    return(true);
                }
                return(false);

            case KeyCode.Minus:
            case KeyCode.KeypadMinus:
                if (!ReadOnly)
                {
                    GUI.changed = true;
                    DrawGUI.Use(inputEvent);
                    double valueNumeric = (double)Convert.ChangeType(Value, Types.Double) - 1d;
                    Value = (TValue)Convert.ChangeType(valueNumeric, typeof(TValue));
                    return(true);
                }
                return(false);

            case KeyCode.F2:
                if (!ReadOnly)
                {
                    GUI.changed = true;
                    DrawGUI.Use(inputEvent);
                    StartEditingField();
                    return(true);
                }
                return(false);
            }

            return(base.OnKeyboardInputGiven(inputEvent, keys));
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Called before keyboard input is sent to a selected member of the collection.
        ///  </summary>
        /// <param name="member"> The member that is selected. </param>
        /// <param name="inputEvent"> Iput data. </param>
        /// <param name="keys"> Key configuration data. </param>
        /// <returns> True if input event should be consumed, i.e. not sent to the selected member, otherwise false. </returns>
        private bool OnMemberKeyboardInputBeingGiven(IDrawer member, Event inputEvent, KeyConfigs keys)
        {
            if (keys.duplicate.DetectAndUseInput(inputEvent))
            {
                DuplicateMember(member);
                return(true);
            }

            switch (inputEvent.keyCode)
            {
            case KeyCode.Home:
                if (inputEvent.modifiers == EventModifiers.FunctionKey)
                {
                    GUI.changed = true;
                    DrawGUI.Use(inputEvent);
                    var firstVisibleMember = visibleMembers[0];
                    if (member != firstVisibleMember)
                    {
                        firstVisibleMember.Select(ReasonSelectionChanged.KeyPressShortcut);
                        return(true);
                    }

                    //select collection itself if first member already selected?
                    Select(ReasonSelectionChanged.KeyPressShortcut);
                    return(true);
                }
                return(false);

            case KeyCode.Delete:
                if (inputEvent.modifiers == EventModifiers.FunctionKey)
                {
                    GUI.changed = true;
                    DrawGUI.Use(inputEvent);

                    if (ReadOnly)
                    {
                        InspectorUtility.ActiveInspector.Message("Can't delete member of a read-only collection");
                        return(false);
                    }
                    var manager = InspectorUtility.ActiveManager;
                    if (manager.HasMultiSelectedControls)
                    {
                        DeleteMembers(manager.MultiSelectedControls);
                    }
                    else
                    {
                        DeleteMember(member);
                    }
                    return(true);
                }
                return(false);

            case KeyCode.End:
                if (inputEvent.modifiers == EventModifiers.FunctionKey)
                {
                    GUI.changed = true;
                    DrawGUI.Use(inputEvent);
                    var lastVisibleMember = visibleMembers[visibleMembers.Length - 1];
                    if (member != lastVisibleMember)
                    {
                        lastVisibleMember.Select(ReasonSelectionChanged.KeyPressShortcut);
                        return(true);
                    }

                    //select next control if last member already selected?
                    var next = GetNextSelectableDrawerDown(GetSelectedRowIndex(), this);
                    if (next != null)
                    {
                        next.Select(ReasonSelectionChanged.KeyPressShortcut);
                        return(true);
                    }
                }
                return(false);
            }
            return(false);
        }
Ejemplo n.º 24
0
        /// <inheritdoc/>
        public virtual bool OnKeyboardInputGiven(Event inputEvent, KeyConfigs keys)
        {
                        #if DEV_MODE && DEBUG_KEYBOARD_INPUT
            Debug.Log("OnKeyboardInputGiven(" + StringUtils.ToString(inputEvent) + ") with SelectedItem=" + StringUtils.ToString(SelectedItem) + ", EditingTextField=" + DrawGUI.EditingTextField);
                        #endif

            if (selectedItemIndex != -1)
            {
                if (items[selectedItemIndex].OnKeyboardInputGiven(inputEvent, keys))
                {
                    return(true);
                }
            }

            if (keys.nextFieldLeft.DetectAndUseInput(inputEvent))
            {
                DrawGUI.Use(inputEvent);
                SelectNextPartLeft(false);
                return(true);
            }

            if (keys.nextFieldRight.DetectAndUseInput(inputEvent))
            {
                DrawGUI.Use(inputEvent);
                SelectNextPartRight(false);
                return(true);
            }

            switch (inputEvent.keyCode)
            {
            case KeyCode.LeftArrow:
                DrawGUI.Use(inputEvent);
                SelectNextPartLeft(false);
                return(true);

            case KeyCode.RightArrow:
                DrawGUI.Use(inputEvent);
                SelectNextPartRight(false);
                return(true);

            case KeyCode.UpArrow:
                DrawGUI.Use(inputEvent);
                var mainView = inspector.InspectorDrawer.MainView;
                if (inspector != mainView)
                {
                    GUI.changed = true;
                    var nextUp = mainView.State.drawers.GetNextSelectableDrawerUp(0, null);
                    if (nextUp != null)
                    {
                        inspector.Manager.Select(mainView, InspectorPart.Viewport, nextUp, ReasonSelectionChanged.SelectControlUp);
                    }
                    return(true);
                }
                return(false);

            case KeyCode.DownArrow:
                DrawGUI.Use(inputEvent);
                GUI.changed = true;

                var nextDown = inspector.State.drawers.GetNextSelectableDrawerDown(0, null);
                if (nextDown != null)
                {
                    inspector.Manager.Select(inspector, InspectorPart.Viewport, nextDown, ReasonSelectionChanged.SelectControlDown);
                    return(true);
                }

                var splittable = inspector.InspectorDrawer as ISplittableInspectorDrawer;
                if (splittable != null && splittable.ViewIsSplit)
                {
                    mainView = splittable.MainView;
                    if (inspector == mainView)
                    {
                        inspector.Manager.Select(splittable.SplitView, InspectorPart.Toolbar, ReasonSelectionChanged.SelectControlDown);
                    }
                    else
                    {
                        inspector.Manager.Select(mainView, InspectorPart.Toolbar, ReasonSelectionChanged.SelectControlDown);
                    }
                }
                return(false);

            case KeyCode.Tab:
                if (inputEvent.modifiers == EventModifiers.None)
                {
                    DrawGUI.Use(inputEvent);
                    SelectNextPartRight(true);
                    return(true);
                }
                if (inputEvent.modifiers == EventModifiers.Shift)
                {
                    DrawGUI.Use(inputEvent);
                    SelectNextPartLeft(true);
                    return(true);
                }
                return(false);

            case KeyCode.Menu:
                var menuItem = GetVisibleItem <IMenuToolbarItem>();
                if (menuItem != null && menuItem.Clickable)
                {
                    menuItem.OnClick(inputEvent);
                    return(true);
                }
                return(false);
            }
            return(false);
        }
Ejemplo n.º 25
0
        /// <inheritdoc cref="IDrawer.OnKeyboardInputGiven" />
        public override bool OnKeyboardInputGiven(Event inputEvent, KeyConfigs keys)
        {
                        #if DEV_MODE && DEBUG_KEYBOARD_INPUT
            Debug.Log(StringUtils.ToColorizedString(ToString(), ".OnKeyboardInputGiven(", inputEvent, ") with DrawGUI.EditingTextField=", DrawGUI.EditingTextField, ")"));
                        #endif

            if (DrawGUI.EditingTextField)
            {
                switch (inputEvent.keyCode)
                {
                case KeyCode.Escape:
                    if (!ReadOnly)
                    {
                        DrawGUI.Use(inputEvent);
                        StopEditingField();
                        return(true);
                    }
                    return(false);

                case KeyCode.Return:
                case KeyCode.KeypadEnter:
                {
                    if (inputEvent.modifiers == EventModifiers.None)
                    {
                        if (!textArea)
                        {
                            DrawGUI.Use(inputEvent);
                            StopEditingField();
                            return(true);
                        }
                        return(false);
                    }

                    var textEditor  = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
                    int cursorIndex = textEditor.cursorIndex;
                    textEditor.text         = string.Concat(textEditor.text.Substring(0, cursorIndex), Environment.NewLine, textEditor.text.Substring(cursorIndex));
                    textEditor.cursorIndex += Environment.NewLine.Length;
                    return(true);
                }
                }

                if (keys.DetectTextFieldReservedInput(inputEvent, lastDrawPosition.height > DrawGUI.SingleLineHeight ? TextFieldType.TextArea : TextFieldType.TextRow))
                {
                                        #if DEV_MODE
                    Debug.Log(GetType().Name + ".OnKeyboardInputGiven aborting because detected text field reserved input\ntextArea=" + textArea + "\nInput=" + StringUtils.ToString(inputEvent));
                                        #endif

                    return(false);
                }
                return(base.OnKeyboardInputGiven(inputEvent, keys));
            }

            switch (inputEvent.keyCode)
            {
            case KeyCode.Return:
            case KeyCode.KeypadEnter:
                if (inputEvent.modifiers == EventModifiers.None && !ReadOnly)
                {
                    DrawGUI.Use(inputEvent);
                    //this needs to be delayed or the text field's content can get replaced by a new line character
                    InspectorUtility.ActiveInspector.OnNextLayout(() => InspectorUtility.ActiveInspector.OnNextLayout(StartEditingField));
                    DrawGUI.Use(inputEvent);
                    return(true);
                }
                return(false);

            case KeyCode.F2:
                if (!ReadOnly)
                {
                    GUI.changed = true;
                    DrawGUI.Use(inputEvent);
                    StartEditingField();
                    return(true);
                }
                return(false);

                                #if DEV_MODE
            case KeyCode.U:
                if (Event.current.modifiers == EventModifiers.Control && !ReadOnly)
                {
                    if (MixedContent)
                    {
                        Debug.LogWarning("Converting mixed content to upper case not yet supported...");
                        return(true);
                    }

                    if (string.IsNullOrEmpty(Value))
                    {
                        return(true);
                    }

                    GUI.changed = true;
                    DrawGUI.Use(inputEvent);
                    Value = Value.ToUpper();
                    return(true);
                }
                return(false);

            case KeyCode.L:
                if (Event.current.modifiers == EventModifiers.Control && !ReadOnly)
                {
                    if (MixedContent)
                    {
                        Debug.LogWarning("Converting mixed content to lower case not yet supported...");
                        return(true);
                    }

                    if (string.IsNullOrEmpty(Value))
                    {
                        return(true);
                    }

                    GUI.changed = true;
                    DrawGUI.Use(inputEvent);
                    Value = Value.ToLower();
                    ApplyValueToField();
                    return(true);
                }
                return(false);
                                #endif
            default:
                if (inputEvent.character != 0 && inputEvent.modifiers == EventModifiers.None && !ReadOnly)
                {
                    switch (inputEvent.character)
                    {
                    //TO DO: Don't append tab, return etc. at the end of a field
                    case '\t':
                    case '\n':
                    case '\r':
                        //break;
                        //UPDATE: with only a break here,
                        //it was causing the field to get selected again
                        //immediately after being deselected
                        //via the return or enter keys
                        return(false);

                    default:
                        Value = string.Concat(Value, inputEvent.character.ToString());
                        break;
                    }
                    GUI.changed = true;
                    DrawGUI.Use(inputEvent);
                    StartEditingField();

                                                #if UNITY_EDITOR
                    TextEditorUtility.MoveCursorToTextEditorEnd();
                                                #endif

                    return(true);
                }
                break;
            }

            return(base.OnKeyboardInputGiven(inputEvent, keys));
        }
Ejemplo n.º 26
0
 private bool OnMemberKeyboardInputBeingGiven(IDrawer keyboardInputReceiver, Event inputEvent, KeyConfigs keys)
 {
     if (inputEvent.keyCode == KeyCode.LeftArrow)
     {
         Select(ReasonSelectionChanged.SelectControlLeft);
         DrawGUI.Use(inputEvent);
         return(true);
     }
     return(false);
 }
Ejemplo n.º 27
0
        /// <inheritdoc />
        public override bool OnKeyboardInputGiven(Event inputEvent, KeyConfigs keys)
        {
            InspectorUtility.ActiveInspector.OnNextLayout(TruncateAndSelectAllTextIfEditing);

            switch (inputEvent.keyCode)
            {
            case KeyCode.Escape:
            {
                if (DrawGUI.EditingTextField)
                {
                    GUI.changed = true;
                    KeyboardControlUtility.KeyboardControl = 0;
                    DrawGUI.EditingTextField = false;
                    DrawGUI.Use(inputEvent);
                    return(true);
                }
                return(false);
            }

            case KeyCode.Return:
            case KeyCode.KeypadEnter:
                if (inputEvent.modifiers == EventModifiers.None && !ReadOnly)
                {
                    GUI.changed = true;
                    DrawGUI.Use(inputEvent);

                    if (!DrawGUI.EditingTextField)
                    {
                        StartEditingField();
                    }
                    else
                    {
                        KeyboardControlUtility.KeyboardControl = 0;
                        DrawGUI.EditingTextField = false;
                    }
                    return(true);
                }
                return(false);

            case KeyCode.F2:
                if (!ReadOnly)
                {
                    GUI.changed = true;
                    DrawGUI.Use(inputEvent);
                    StartEditingField();
                    return(true);
                }
                return(false);

                                #if DEV_MODE
            case KeyCode.U:
                if (Event.current.modifiers == EventModifiers.Control && !ReadOnly)
                {
                    GUI.changed = true;
                    DrawGUI.Use(inputEvent);
                    Value = char.ToUpper(Value);
                    return(true);
                }
                return(false);

            case KeyCode.L:
                if (Event.current.modifiers == EventModifiers.Control && !ReadOnly)
                {
                    GUI.changed = true;
                    DrawGUI.UseEvent();
                    Value = char.ToLower(Value);
                    ApplyValueToField();
                    return(true);
                }
                return(false);

            case KeyCode.UpArrow:
                if (inputEvent.modifiers == EventModifiers.FunctionKey)
                {
                    DrawGUI.Use(inputEvent);
                    SelectNextFieldUp(GetSelectedRowIndex());
                    return(true);
                }
                return(false);

            case KeyCode.DownArrow:
                if (inputEvent.modifiers == EventModifiers.FunctionKey)
                {
                    DrawGUI.Use(inputEvent);
                    SelectNextFieldDown(GetSelectedRowIndex());
                    return(true);
                }
                return(false);

            case KeyCode.LeftArrow:
                if (inputEvent.modifiers == EventModifiers.FunctionKey)
                {
                    DrawGUI.Use(inputEvent);
                    SelectNextFieldLeft(false, false);
                    return(true);
                }
                return(false);

            case KeyCode.RightArrow:
                                        #if DEV_MODE
                Debug.Log(StringUtils.ToColorizedString(ToString(), " RightArrow with modifiers=", StringUtils.ToString(inputEvent.modifiers)));
                                        #endif
                if (inputEvent.modifiers == EventModifiers.FunctionKey)
                {
                    DrawGUI.Use(inputEvent);
                    SelectNextFieldRight(false, false);
                    return(true);
                }
                return(false);
                                #endif
            default:
                if (inputEvent.character != 0 && inputEvent.modifiers == EventModifiers.None && !ReadOnly)
                {
                    switch (inputEvent.character)
                    {
                    //TO DO: Don't insert tab, return etc.
                    case '\t':
                    case '\n':
                    case '\r':
                        //break;
                        //UPDATE: with only a break here,
                        //it was causing the field to get selected again
                        //immediately after being deselected
                        //via the return or enter keys
                        return(false);

                    default:
                        Value = inputEvent.character;
                        break;
                    }
                    GUI.changed = true;
                    DrawGUI.Use(inputEvent);
                    StartEditingField();
                    return(true);
                }
                break;
            }

            if (DrawGUI.EditingTextField && keys.DetectTextFieldReservedInput(inputEvent, TextFieldType.TextRow))
            {
                                #if DEV_MODE
                Debug.Log(GetType().Name + ".OnKeyboardInputGiven aborting because detected text field reserved input\nInput=" + StringUtils.ToString(inputEvent));
                                #endif

                return(false);
            }

            if (base.OnKeyboardInputGiven(inputEvent, keys))
            {
                return(true);
            }

            // Prevent keyboard events from bleeding elsewhere. E.g. when F was pressed, would cause Scene view to focus to selected Object.
            DrawGUI.Use(inputEvent);
            return(true);
        }
Ejemplo n.º 28
0
 /// <summary>
 /// Called when the key drawer is about to receive keyboard input.
 /// </summary>
 /// <param name="keyboardInputReceiver"> The text that will receive the keyboard input. </param>
 /// <param name="inputEvent"> Information about the keyboard input event including the key code. </param>
 /// <param name="keys"> The current key configuration. </param> <returns>
 /// True input was consumed by a listener and as such keyboardInputReceiver should never receive the keyboard input.
 /// </returns>
 private bool OnKeyDrawerKeyboardInputBeingGiven([NotNull] IDrawer keyboardInputReceiver, [NotNull] Event inputEvent, [NotNull] KeyConfigs keys)
 {
     if (keyboardInputReceiver is ITextFieldDrawer)
     {
         if (inputEvent.keyCode == KeyCode.Return && DrawGUI.EditingTextField)
         {
             if (onAddButtonClicked != null)
             {
                 DrawGUI.EditingTextField = false;
                 onAddButtonClicked();
                 return(true);
             }
         }
     }
     return(false);
 }
Ejemplo n.º 29
0
 /// <inheritdoc/>
 public virtual bool OnKeyboardInputGivenWhenNotSelected([NotNull] Event inputEvent, [NotNull] KeyConfigs keys)
 {
     return(false);
 }