Exemplo n.º 1
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);
            if (this.focusEditor != null)
            {
                PropertyEditor current = this.focusEditor;
                while (current != null)
                {
                    current.OnKeyDown(e);
                    if (e.Handled)
                    {
                        break;
                    }
                    current = current.ParentEditor;
                }
            }

            if (!e.Handled)
            {
                if (this.focusEditor != null)
                {
                    if (e.KeyCode == Keys.Down)
                    {
                        PropertyEditor current = this.focusEditor;
                        PropertyEditor next    = current.NextEditor;
                        if (next == null)
                        {
                            next = current.Children.FirstOrDefault();
                        }
                        if (next == null && current.ParentEditor != null)
                        {
                            next = current.ParentEditor.NextEditor;
                        }

                        next = this.GetFocusReciever(next, true);
                        if (next != null)
                        {
                            next.Focus();
                        }
                        e.Handled = true;
                    }
                    else if (e.KeyCode == Keys.Up)
                    {
                        PropertyEditor current = this.focusEditor;
                        PropertyEditor prev    = current.PrevEditor;
                        if (prev == null)
                        {
                            prev = current.ParentEditor;
                        }

                        prev = this.GetFocusReciever(prev, false);
                        if (prev != null)
                        {
                            prev.Focus();
                        }
                        e.Handled = true;
                    }
                    else if (e.KeyCode == Keys.Left)
                    {
                        PropertyEditor current = this.focusEditor;
                        while (current != null)
                        {
                            current = current.ParentEditor;
                            while (current != null && !current.CanGetFocus)
                            {
                                current = current.ParentEditor;
                            }
                            if (current != null)
                            {
                                current.Focus();
                                break;
                            }
                        }
                        e.Handled = true;
                    }
                    else if (e.KeyCode == Keys.Right)
                    {
                        if (this.focusEditor != null)
                        {
                            if (this.focusEditor is GroupedPropertyEditor)
                            {
                                (this.focusEditor as GroupedPropertyEditor).Expanded = true;
                            }
                            PropertyEditor current = null;
                            current = this.focusEditor.Children.FirstOrDefault(editor => editor.CanGetFocus);
                            if (current == null)
                            {
                                current = this.focusEditor.ChildrenDeep.FirstOrDefault(editor => editor.CanGetFocus);
                            }
                            if (current != null)
                            {
                                current.Focus();
                            }
                        }
                        e.Handled = true;
                    }
                    else if (e.KeyCode == Keys.PageUp || e.KeyCode == Keys.Home)
                    {
                        if (this.focusEditor.ParentEditor != null)
                        {
                            PropertyEditor current = this.focusEditor.ParentEditor;
                            current = current.Children.FirstOrDefault(editor => editor.CanGetFocus);
                            if (current != null)
                            {
                                current.Focus();
                            }
                        }
                        e.Handled = true;
                    }
                    else if (e.KeyCode == Keys.PageDown || e.KeyCode == Keys.End)
                    {
                        if (this.focusEditor.ParentEditor != null)
                        {
                            PropertyEditor current = this.focusEditor.ParentEditor;
                            current = current.Children.LastOrDefault(editor => editor.CanGetFocus);
                            if (current != null)
                            {
                                current.Focus();
                            }
                        }
                        e.Handled = true;
                    }
                }
            }
        }