Example #1
0
        public void OnKeyUp(Event e)
        {
            switch (e.keyCode)
            {
            case KeyCode.AltGr:
            case KeyCode.RightAlt:
            {
                KeyConfig.OnAltGrUp();
            }
            break;
            }

            if (e.keyCode == keyHeldDown)
            {
                keyHeldDown = KeyCode.None;
            }
        }
        public static void OnKeyDown(this IInspectorDrawer inspectorDrawer, Event e)
        {
                        #if DEV_MODE && DEBUG_KEYBOARD_INPUT
            Debug.Log(StringUtils.ToColorizedString(inspectorDrawer.ToString(), ".OnKeyDown(", e.keyCode, ") with HasFocus=", inspectorDrawer.HasFocus, ", selectedControl=", StringUtils.ToString(inspectorDrawer.SelectedOrDefaultView().FocusedDrawer), ", SelectedPart=", inspectorDrawer.Manager.SelectedInspectorPart));
                        #endif

            if (!inspectorDrawer.HasFocus)
            {
                return;
            }

            var view = inspectorDrawer.SelectedOrDefaultView();
            var keys = view.Preferences.keyConfigs;

                        #if !POWER_INSPECTOR_LITE
            if (keys.stepBackInSelectionHistory.DetectAndUseInput(e))
            {
                view.StepBackInSelectionHistory();
                return;
            }
            if (keys.stepForwardInSelectionHistory.DetectAndUseInput(e))
            {
                view.StepForwardInSelectionHistory();
                return;
            }
                        #endif

            inspectorDrawer.Repaint();

            DrawGUI.RegisterInputEvent(e);

            var activeView = inspectorDrawer.SelectedOrDefaultView();

            // give controls time to react to selection changes, editing text field changes etc.
            // before cached values are updated. (e.g. unapplied changes in delayed fields are
            // not discarded before they have time to get applied
            activeView.ResetNextUpdateCachedValues();

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(!inspectorDrawer.HasFocus || activeView.Selected);
                        #endif

                        #if DEV_MODE && DEBUG_KEYBOARD_INPUT
            Debug.Log(StringUtils.ToColorizedString("OnKeyDown activeView.Selected=", activeView.Selected, ", activeView.FocusedDrawer=", activeView.FocusedDrawer + ", Manager.SelectedInspector=", inspectorDrawer.Manager.SelectedInspector, ", inspectorDrawer.HasFocus=", inspectorDrawer.HasFocus));
                        #endif

            if (activeView.Toolbar.OnKeyboardInputGivenWhenNotSelected(e, activeView.Preferences.keyConfigs))
            {
                if (e.type != EventType.Used)
                {
                    DrawGUI.Use(e);
                    ExitGUIUtility.ExitGUI();
                }
            }

            IDrawer selectedControl = null;
            if (activeView.Selected)
            {
                selectedControl = activeView.FocusedDrawer;
                if (selectedControl != null)
                {
                    var onKeyboardInputBeingGiven = selectedControl.OnKeyboardInputBeingGiven;
                    if (onKeyboardInputBeingGiven != null)
                    {
                                                #if DEV_MODE && DEBUG_KEYBOARD_INPUT
                        Debug.Log("onKeyboardInputBeingGiven(" + StringUtils.ToString(e) + "): " + StringUtils.ToString(onKeyboardInputBeingGiven));
                                                #endif
                        if (onKeyboardInputBeingGiven(selectedControl, e, selectedControl.Inspector.Preferences.keyConfigs))
                        {
                            return;
                        }
                    }

                    if (selectedControl.OnKeyboardInputGiven(e, selectedControl.Inspector.Preferences.keyConfigs))
                    {
                        return;
                    }
                }
                else if (inspectorDrawer.Manager.SelectedInspectorPart == InspectorPart.Toolbar)
                {
                    activeView.Toolbar.OnKeyboardInputGiven(e, activeView.Preferences.keyConfigs);
                }
                else if (inspectorDrawer.Manager.SelectedInspectorPart == InspectorPart.Viewport || inspectorDrawer.Manager.SelectedInspectorPart == InspectorPart.None)
                {
                    bool fieldChangeInputGiven;
                    if (keys.DetectNextField(e, true) || keys.DetectPreviousField(e, true) ||
                        keys.nextFieldLeft.DetectAndUseInput(e) || keys.nextFieldRight.DetectAndUseInput(e) ||
                        keys.nextFieldDown.DetectAndUseInput(e) || keys.nextFieldUp.DetectAndUseInput(e))
                    {
                        fieldChangeInputGiven = true;
                    }
                    else if (e.modifiers == EventModifiers.FunctionKey)
                    {
                        switch (e.keyCode)
                        {
                        case KeyCode.DownArrow:
                        case KeyCode.UpArrow:
                        case KeyCode.LeftArrow:
                        case KeyCode.RightArrow:
                            fieldChangeInputGiven = true;
                            break;

                        default:
                            fieldChangeInputGiven = false;
                            break;
                        }
                    }
                    else
                    {
                        fieldChangeInputGiven = false;
                    }

                    if (fieldChangeInputGiven)
                    {
                        var drawers = activeView.State.drawers;
                        if (drawers.Length == 0)
                        {
                            if (activeView.Toolbar != null)
                            {
                                activeView.Toolbar.OnFindCommandGiven();
                            }
                            else
                            {
                                KeyboardControlUtility.SetKeyboardControl(0, 3);
                            }
                        }
                        else
                        {
                            var first  = drawers[0];
                            var select = first.GetNextSelectableDrawerRight(true, null);

                                                        #if DEV_MODE && DEBUG_NEXT_FIELD
                            Debug.Log(first + ".GetNextSelectableDrawerRight: " + StringUtils.ToString(select));
                                                        #endif

                            if (select != null)
                            {
                                activeView.Select(select, ReasonSelectionChanged.SelectNextControl);
                            }
                        }
                    }
                }
            }

            if (DrawGUI.EditingTextField && keys.DetectTextFieldReservedInput(e, TextFieldType.TextRow))
            {
                                #if DEV_MODE && DEBUG_KEYBOARD_INPUT
                Debug.Log(StringUtils.ToColorizedString("OnKeyboardInputGiven( ", StringUtils.ToString(e), ") DetectTextFieldReservedInput: ", true, " with selectedControl=", selectedControl));
                                #endif
                return;
            }

            if (keys.addComponent.DetectInput(e))
            {
                                #if DEV_MODE
                Debug.Log("AddComponent shortcut detected");
                                #endif

                if (AddComponentButtonDrawer.OpenSelectedOrFirstFoundInstance(activeView))
                {
                    DrawGUI.Use(e);
                }
            }

            if (keys.toggleSplitView.DetectInput(e))
            {
                var splittable = inspectorDrawer as ISplittableInspectorDrawer;
                if (splittable != null && splittable.CanSplitView)
                {
                    DrawGUI.Use(e);
                    bool setSplitView = !splittable.ViewIsSplit;
                    splittable.MainView.OnNextLayout(() => splittable.SetSplitView(setSplitView));
                }
            }

            if (keys.refresh.DetectAndUseInput(e))
            {
                var selectedInspector = inspectorDrawer.Manager.SelectedInspector;
                if (selectedInspector != null && selectedInspector.InspectorDrawer == inspectorDrawer)
                {
                    selectedInspector.ForceRebuildDrawers();
                }
                else
                {
                    var mainView = inspectorDrawer.MainView;
                    mainView.ForceRebuildDrawers();
                    var splittable = inspectorDrawer as ISplittableInspectorDrawer;
                    if (splittable != null && splittable.ViewIsSplit)
                    {
                        splittable.SplitView.ForceRebuildDrawers();
                    }
                }
            }

            var keyCode = e.keyCode;
            switch (keyCode)
            {
            case KeyCode.Menu:
                if (selectedControl != null)
                {
                    selectedControl.OpenContextMenu(e, selectedControl.RightClickArea, false, selectedControl.SelectedPart);
                }
                break;

            case KeyCode.Space:
                inspectorDrawer.Manager.RegisterKeyHeldDown(keyCode, "space");
                break;

            case KeyCode.F2:
                inspectorDrawer.Repaint();
                if (!DrawGUI.EditingTextField)
                {
                    DrawGUI.Use(e);
                    DrawGUI.EditingTextField = true;
                }
                break;

            case KeyCode.Escape:

                                        #if DEV_MODE
                Debug.Log("!!! ESCAPE !!!");
                                        #endif

                //when dragging a control, allow aborting using the escape key
                if (inspectorDrawer.Manager.MouseDownInfo.MouseDownOverDrawer != null)
                {
                    inspectorDrawer.Manager.MouseDownInfo.Clear();
                }

                if (DrawGUI.EditingTextField)
                {
                    DrawGUI.Use(e);
                    DrawGUI.EditingTextField = false;
                }
                break;

            case KeyCode.AltGr:
            case KeyCode.RightAlt:
                KeyConfig.OnAltGrDown();
                break;

                                #if DEV_MODE
            case KeyCode.I:
                if (e.control && e.alt)
                {
                    Debug.Log("INFO: FocusedDrawer=" + StringUtils.ToString(inspectorDrawer.SelectedOrDefaultView().FocusedDrawer) + ", EditingTextField=" + DrawGUI.EditingTextField);
                }
                break;
                                #endif
            }
        }
Example #3
0
 public KeyConfig2(KeyConfig setMain, KeyConfig setSecondary)
 {
     main      = setMain;
     secondary = setSecondary;
 }