コード例 #1
0
        public void ApplyActionToSelection(Xwt.ModifierKeys modifier, int unicodeKey)
        {
            if (Data.IsSomethingSelected && (modifier & (Xwt.ModifierKeys.Control)) == 0)
            {
                switch ((char)unicodeKey)
                {
                case 'x':
                case 'd':
                    RunAction(ClipboardActions.Cut);
                    Reset("Deleted selection");
                    return;

                case 'y':
                    int offset = Data.SelectionRange.Offset;
                    RunAction(ClipboardActions.Copy);
                    Reset("Yanked selection");
                    Caret.Offset = offset;
                    return;

                case 's':
                case 'c':
                    RunAction(ClipboardActions.Cut);
                    Caret.Mode = CaretMode.Insert;
                    CurState   = State.Insert;
                    Status     = "-- INSERT --";
                    return;

                case 'S':
                    Data.SetSelectLines(Data.MainSelection.Anchor.Line, Data.Caret.Line);
                    goto case 'c';

                case '>':
                    RunAction(MiscActions.IndentSelection);
                    Reset("");
                    return;

                case '<':
                    RunAction(MiscActions.RemoveIndentSelection);
                    Reset("");
                    return;

                case ':':
                    commandBuffer.Append(":");
                    Status   = commandBuffer.ToString();
                    CurState = State.Command;
                    break;

                case 'J':
                    RunAction(ViActions.Join);
                    Reset("");
                    return;

                case '~':
                    RunAction(ViActions.ToggleCase);
                    Reset("");
                    return;
                }
            }
        }
コード例 #2
0
        public static int GetKeyCode(Key key, Xwt.ModifierKeys modifier)
        {
            uint m = (uint)(((modifier & Xwt.ModifierKeys.Control) != 0) ? 1 : 0);

            m = (m << 1) | (uint)(((modifier & Xwt.ModifierKeys.Shift) != 0) ? 1 : 0);
            m = (m << 1) | (uint)(((modifier & Xwt.ModifierKeys.Command) != 0) ? 1 : 0);
            m = (m << 1) | (uint)(((modifier & Xwt.ModifierKeys.Alt) != 0) ? 1 : 0);

            return(GetKeyCode(key) | (int)(m << 16));
        }
コード例 #3
0
ファイル: SimpleEditMode.cs プロジェクト: radtek/datawf
        protected override void HandleKeypress(Key key, int unicodeKey, Xwt.ModifierKeys modifier)
        {
            int keyCode = GetKeyCode(key, modifier);

            if (keyBindings.ContainsKey(keyCode))
            {
                RunAction(keyBindings[keyCode]);
            }
            else if (unicodeKey != 0)// && modifier == Xwt.ModifierKeys.None)
            {
                InsertCharacter(unicodeKey);
            }
        }
コード例 #4
0
        internal bool ProcessKey(Xwt.Key key, Xwt.ModifierKeys state)
        {
            switch (key)
            {
            case Xwt.Key.Up:
                if (state.HasFlag(Xwt.ModifierKeys.Command))
                {
                    goto case Xwt.Key.PageUp;
                }
                if (state.HasFlag(Xwt.ModifierKeys.Control))
                {
                    SelectFirstCategory();
                }
                else
                {
                    SelectItemUp();
                }
                return(true);

            case Xwt.Key.Down:
                if (state.HasFlag(Xwt.ModifierKeys.Command))
                {
                    goto case Xwt.Key.PageDown;
                }
                if (state.HasFlag(Xwt.ModifierKeys.Control))
                {
                    SelectLastCatgory();
                }
                else
                {
                    SelectItemDown();
                }
                return(true);

            case (Xwt.Key)Gdk.Key.KP_Page_Down:
            case Xwt.Key.PageDown:
                SelectNextCategory();
                return(true);

            case (Xwt.Key)Gdk.Key.KP_Page_Up:
            case Xwt.Key.PageUp:
                SelectPrevCategory();
                return(true);

            case Xwt.Key.Return:
                OnItemActivated(EventArgs.Empty);
                return(true);
            }
            return(false);
        }
コード例 #5
0
ファイル: ViEditor.cs プロジェクト: radtek/datawf
        public void ProcessKey(Xwt.ModifierKeys modifiers, Key key, char ch)
        {
            if (Context == null)
            {
                Reset("");
            }

            Context.ProcessKey(key, ch, modifiers);
            if (Context.Completed)
            {
                Reset(Context.Message);
            }
            else
            {
                Message = Context.Message;
            }
        }
コード例 #6
0
        void HandleKeyPressEvent(object o, KeyEventArgs args)
        {
            keyHandled = false;

            keyChar  = CharFromKey(args.Key);
            modifier = args.Modifiers;
            key      = args.Key;

            if ((args.Key == Key.Down || args.Key == Key.Up))
            {
                keyChar = '\0';
            }

            if (list != null)
            {
                args.Handled = keyHandled = CompletionWindowManager.PreProcessKeyEvent(KeyDescriptor.FromXwt(key, keyChar, modifier));
            }
        }
コード例 #7
0
 ViKey(ModifierKeys modifiers, char ch, Key key) : this()
 {
     this.modifiers = modifiers & KnownModifiers;
     this.ch        = ch;
     this.key       = key;
 }
コード例 #8
0
ファイル: TooltipProvider.cs プロジェクト: radtek/datawf
        public virtual Xwt.Window ShowTooltipWindow(TextEditor editor, double offset, Xwt.ModifierKeys modifierState, Point mouse, TooltipItem item)
        {
            Xwt.Window tipWindow = CreateTooltipWindow(editor, offset, modifierState, item);
            if (tipWindow == null)
            {
                return(null);
            }

            var point = editor.ConvertToScreenCoordinates(mouse);

            double w;
            double xalign;

            GetRequiredPosition(editor, tipWindow, out w, out xalign);
            w += 10;

            Rectangle geometry = editor.ParentWindow.Screen.VisibleBounds;

            point.X -= (int)((double)w * xalign);
            point.Y += 10;

            if (point.X + w >= geometry.X + geometry.Width)
            {
                point.X = geometry.X + geometry.Width - w;
            }
            if (point.X < geometry.Left)
            {
                point.X = geometry.Left;
            }

            var h = tipWindow.Size.Height;

            if (point.Y + h >= geometry.Y + geometry.Height)
            {
                point.Y = geometry.Y + geometry.Height - h;
            }
            if (point.Y < geometry.Top)
            {
                point.Y = geometry.Top;
            }

            tipWindow.Location = point;

            tipWindow.Show();

            return(tipWindow);
        }
コード例 #9
0
ファイル: TooltipProvider.cs プロジェクト: radtek/datawf
 protected virtual Xwt.Window CreateTooltipWindow(TextEditor editor, double offset, Xwt.ModifierKeys modifierState, TooltipItem item)
 {
     return(null);
 }
コード例 #10
0
        public ListWindowKeyAction ProcessKey(Key key, Xwt.ModifierKeys modifier)
        {
            switch (key)
            {
            case Key.Up:
                if (list.SelectionDisabled)
                {
                    list.SelectionDisabled = false;
                }
                else
                {
                    list.Selection--;
                }
                return(ListWindowKeyAction.Ignore);

            case Key.Down:
                if (list.SelectionDisabled)
                {
                    list.SelectionDisabled = false;
                }
                else
                {
                    list.Selection++;
                }
                return(ListWindowKeyAction.Ignore);

            case Key.PageUp:
                list.Selection -= list.VisibleRows - 1;
                return(ListWindowKeyAction.Ignore);

            case Key.PageDown:
                list.Selection += list.VisibleRows - 1;
                return(ListWindowKeyAction.Ignore);

            case Key.Left:
                //if (curPos == 0) return KeyAction.CloseWindow | KeyAction.Process;
                //curPos--;
                return(ListWindowKeyAction.Process);

            case Key.BackSpace:
                if (curPos == 0 || (modifier & Xwt.ModifierKeys.Control) != 0)
                {
                    return(ListWindowKeyAction.CloseWindow | ListWindowKeyAction.Process);
                }
                curPos--;
                word.Remove(curPos, 1);
                UpdateWordSelection();
                return(ListWindowKeyAction.Process);

            case Key.Right:
                //if (curPos == word.Length) return KeyAction.CloseWindow | KeyAction.Process;
                //curPos++;
                return(ListWindowKeyAction.Process);

            case Key.CapsLock:
            case Key.NumLock:
            case Key.ScrollLock:
                return(ListWindowKeyAction.Ignore);

            case Key.Return:
                return((list.SelectionDisabled ? ListWindowKeyAction.Process : (ListWindowKeyAction.Complete | ListWindowKeyAction.Ignore))
                       | ListWindowKeyAction.CloseWindow);

            case Key.Escape:
                return(ListWindowKeyAction.CloseWindow | ListWindowKeyAction.Ignore);

            case Key.Home:
            case Key.End:
                return(ListWindowKeyAction.CloseWindow | ListWindowKeyAction.Process);

            case Key.ControlLeft:
            case Key.ControlRight:
            case Key.AltLeft:
            case Key.AltRight:
            case Key.ShiftLeft:
            case Key.ShiftRight:
                return(ListWindowKeyAction.Process);
            }


            return(ListWindowKeyAction.CloseWindow | ListWindowKeyAction.Process);
        }
コード例 #11
0
 protected abstract void HandleKeypress(Key key, int unicodeKey, Xwt.ModifierKeys modifier);
コード例 #12
0
ファイル: ViActionMaps.cs プロジェクト: radtek/datawf
        public static Action <TextEditorData> GetInsertKeyAction(Key key, Xwt.ModifierKeys modifier)
        {
            //
            // NO MODIFIERS
            //
            if ((modifier & (Xwt.ModifierKeys.Shift | Xwt.ModifierKeys.Control)) == 0)
            {
                switch (key)
                {
                case Key.Tab:
                    return(MiscActions.InsertTab);

                case Key.Return:
                case Key.NumPadEnter:
                    return(MiscActions.InsertNewLine);

                case Key.BackSpace:
                    return(DeleteActions.Backspace);

                case Key.Delete:
                case Key.NumPadDelete:
                    return(DeleteActions.Delete);

                case Key.Insert:
                    return(MiscActions.SwitchCaretMode);
                }
            }
            //
            // CONTROL
            //
            else if ((modifier & Xwt.ModifierKeys.Control) != 0 &&
                     (modifier & Xwt.ModifierKeys.Shift) == 0)
            {
                switch (key)
                {
                case Key.BackSpace:
                    return(DeleteActions.PreviousWord);

                case Key.Delete:
                case Key.NumPadDelete:
                    return(DeleteActions.NextWord);
                }
            }
            //
            // SHIFT
            //
            else if ((modifier & Xwt.ModifierKeys.Control) == 0 &&
                     (modifier & Xwt.ModifierKeys.Shift) != 0)
            {
                switch (key)
                {
                case Key.Tab:
                    return(MiscActions.RemoveTab);

                case Key.BackSpace:
                    return(DeleteActions.Backspace);

                case Key.Return:
                case Key.NumPadEnter:
                    return(MiscActions.InsertNewLine);
                }
            }
            return(null);
        }
コード例 #13
0
ファイル: GtkWorkarounds.cs プロジェクト: radtek/datawf
 public KeyboardShortcut(Key key, Xwt.ModifierKeys modifier)
 {
     this.modifier = modifier;
     this.key      = key;
 }
コード例 #14
0
ファイル: SimpleEditMode.cs プロジェクト: radtek/datawf
        void InitCommonBindings()
        {
            Action <TextEditorData> action;

            Xwt.ModifierKeys wordModifier    = Platform.IsMac ? Xwt.ModifierKeys.Alt : Xwt.ModifierKeys.Control;
            Xwt.ModifierKeys subwordModifier = Platform.IsMac ? Xwt.ModifierKeys.Control : Xwt.ModifierKeys.Alt;

            // ==== Left ====

            action = CaretMoveActions.Left;
            keyBindings.Add(GetKeyCode(Key.Left), action);

            action = SelectionActions.MoveLeft;
            keyBindings.Add(GetKeyCode(Key.Left, Xwt.ModifierKeys.Shift), action);

            action = CaretMoveActions.PreviousWord;
            keyBindings.Add(GetKeyCode(Key.Left, wordModifier), action);

            action = SelectionActions.MovePreviousWord;
            keyBindings.Add(GetKeyCode(Key.Left, Xwt.ModifierKeys.Shift | wordModifier), action);

            // ==== Right ====

            action = CaretMoveActions.Right;
            keyBindings.Add(GetKeyCode(Key.Right), action);

            action = SelectionActions.MoveRight;
            keyBindings.Add(GetKeyCode(Key.Right, Xwt.ModifierKeys.Shift), action);

            action = CaretMoveActions.NextWord;
            keyBindings.Add(GetKeyCode(Key.Right, wordModifier), action);

            action = SelectionActions.MoveNextWord;
            keyBindings.Add(GetKeyCode(Key.Right, Xwt.ModifierKeys.Shift | wordModifier), action);

            // ==== Up ====

            action = CaretMoveActions.Up;
            keyBindings.Add(GetKeyCode(Key.Up), action);

            action = ScrollActions.Up;
            keyBindings.Add(GetKeyCode(Key.Up, Xwt.ModifierKeys.Control), action);

            // ==== Down ====

            action = CaretMoveActions.Down;
            keyBindings.Add(GetKeyCode(Key.Down), action);

            action = ScrollActions.Down;
            keyBindings.Add(GetKeyCode(Key.Down, Xwt.ModifierKeys.Control), action);

            // ==== Deletion, insertion ====

            action = MiscActions.SwitchCaretMode;
            keyBindings.Add(GetKeyCode(Key.Insert), action);

            keyBindings.Add(GetKeyCode(Key.Tab), MiscActions.InsertTab);
            keyBindings.Add(GetKeyCode(Key.Tab, Xwt.ModifierKeys.Shift), MiscActions.RemoveTab);

            action = MiscActions.InsertNewLine;
            keyBindings.Add(GetKeyCode(Key.Return), action);

            keyBindings.Add(GetKeyCode(Key.Return, Xwt.ModifierKeys.Control), MiscActions.InsertNewLinePreserveCaretPosition);
            keyBindings.Add(GetKeyCode(Key.Return, Xwt.ModifierKeys.Shift), MiscActions.InsertNewLineAtEnd);

            action = DeleteActions.Backspace;
            keyBindings.Add(GetKeyCode(Key.BackSpace), action);
            keyBindings.Add(GetKeyCode(Key.BackSpace, Xwt.ModifierKeys.Shift), action);

            keyBindings.Add(GetKeyCode(Key.BackSpace, wordModifier), DeleteActions.PreviousWord);

            action = DeleteActions.Delete;
            keyBindings.Add(GetKeyCode(Key.Delete), action);

            action = DeleteActions.NextWord;
            keyBindings.Add(GetKeyCode(Key.Delete, wordModifier), action);


            // == subword motions ==

            action = CaretMoveActions.PreviousSubword;
            keyBindings.Add(GetKeyCode(Key.Left, subwordModifier), action);

            action = SelectionActions.MovePreviousSubword;
            keyBindings.Add(GetKeyCode(Key.Left, Xwt.ModifierKeys.Shift | subwordModifier), action);

            action = CaretMoveActions.NextSubword;
            keyBindings.Add(GetKeyCode(Key.Right, subwordModifier), action);

            action = SelectionActions.MoveNextSubword;
            keyBindings.Add(GetKeyCode(Key.Right, Xwt.ModifierKeys.Shift | subwordModifier), action);

            keyBindings.Add(GetKeyCode(Key.BackSpace, subwordModifier), DeleteActions.PreviousSubword);

            action = DeleteActions.NextSubword;
            keyBindings.Add(GetKeyCode(Key.Delete, subwordModifier), action);
        }
コード例 #15
0
        protected override void HandleKeypress(Key key, int unicodeKey, Xwt.ModifierKeys modifier)
        {
            // Reset on Esc, Ctrl-C, Ctrl-[
            if (key == Key.Escape)
            {
                if (currentMacro != null)
                {
                    // Record Escapes into the macro since it actually does something
                    ViMacro.KeySet toAdd = new ViMacro.KeySet();
                    toAdd.Key        = key;
                    toAdd.Modifiers  = modifier;
                    toAdd.UnicodeKey = unicodeKey;
                    currentMacro.KeysPressed.Enqueue(toAdd);
                }
                Reset(string.Empty);
                return;
            }
            else if (((key == Key.c || key == Key.LeftBracket) && (modifier & Xwt.ModifierKeys.Control) != 0))
            {
                Reset(string.Empty);
                if (currentMacro != null)
                {
                    // Otherwise remove the macro from the pool
                    macros.Remove(currentMacro.MacroCharacter);
                    currentMacro = null;
                }
                return;
            }
            else if (currentMacro != null && !((char)unicodeKey == 'q' && modifier == Xwt.ModifierKeys.None))
            {
                ViMacro.KeySet toAdd = new ViMacro.KeySet();
                toAdd.Key        = key;
                toAdd.Modifiers  = modifier;
                toAdd.UnicodeKey = unicodeKey;
                currentMacro.KeysPressed.Enqueue(toAdd);
            }

            Action <TextEditorData> action = null;
            bool lineAction = false;

            switch (CurState)
            {
            case State.Unknown:
                Reset(string.Empty);
                goto case State.Normal;

            case State.Normal:
                if (((modifier & (Xwt.ModifierKeys.Control)) == 0))
                {
                    if (key == Key.Delete)
                    {
                        unicodeKey = 'x';
                    }
                    switch ((char)unicodeKey)
                    {
                    case '?':
                    case '/':
                    case ':':
                        CurState = State.Command;
                        commandBuffer.Append((char)unicodeKey);
                        Status = commandBuffer.ToString();
                        return;

                    case 'A':
                        RunAction(CaretMoveActions.LineEnd);
                        goto case 'i';

                    case 'I':
                        RunAction(CaretMoveActions.LineFirstNonWhitespace);
                        goto case 'i';

                    case 'a':
                        //use CaretMoveActions so that we can move past last character on line end
                        RunAction(CaretMoveActions.Right);
                        goto case 'i';

                    case 'i':
                        Caret.Mode = CaretMode.Insert;
                        Status     = "-- INSERT --";
                        CurState   = State.Insert;
                        return;

                    case 'R':
                        Caret.Mode = CaretMode.Underscore;
                        Status     = "-- REPLACE --";
                        CurState   = State.Replace;
                        return;

                    case 'V':
                        Status = "-- VISUAL LINE --";
                        Data.SetSelectLines(Caret.Line, Caret.Line);
                        CurState = State.VisualLine;
                        return;

                    case 'v':
                        Status   = "-- VISUAL --";
                        CurState = State.Visual;
                        RunAction(ViActions.VisualSelectionFromMoveAction(ViActions.Right));
                        return;

                    case 'd':
                        Status   = "d";
                        CurState = State.Delete;
                        return;

                    case 'y':
                        Status   = "y";
                        CurState = State.Yank;
                        return;

                    case 'Y':
                        CurState = State.Yank;
                        HandleKeypress(Key.y, (int)'y', Xwt.ModifierKeys.None);
                        return;

                    case 'O':
                        RunAction(ViActions.NewLineAbove);
                        goto case 'i';

                    case 'o':
                        RunAction(ViActions.NewLineBelow);
                        goto case 'i';

                    case 'r':
                        Caret.Mode = CaretMode.Underscore;
                        Status     = "-- REPLACE --";
                        CurState   = State.WriteChar;
                        return;

                    case 'c':
                        Caret.Mode = CaretMode.Insert;
                        Status     = "c";
                        CurState   = State.Change;
                        return;

                    case 'x':
                        if (Data.Caret.Column == Data.Document.GetLine(Data.Caret.Line).Length + 1)
                        {
                            return;
                        }
                        Status = string.Empty;
                        if (!Data.IsSomethingSelected)
                        {
                            RunActions(SelectionActions.FromMoveAction(CaretMoveActions.Right), ClipboardActions.Cut);
                        }
                        else
                        {
                            RunAction(ClipboardActions.Cut);
                        }
                        ViActions.RetreatFromLineEnd(Data);
                        return;

                    case 'X':
                        if (Data.Caret.Column == DocumentLocation.MinColumn)
                        {
                            return;
                        }
                        Status = string.Empty;
                        if (!Data.IsSomethingSelected && 0 < Caret.Offset)
                        {
                            RunActions(SelectionActions.FromMoveAction(CaretMoveActions.Left), ClipboardActions.Cut);
                        }
                        else
                        {
                            RunAction(ClipboardActions.Cut);
                        }
                        return;

                    case 'D':
                        RunActions(SelectionActions.FromMoveAction(CaretMoveActions.LineEnd), ClipboardActions.Cut);
                        return;

                    case 'C':
                        RunActions(SelectionActions.FromMoveAction(CaretMoveActions.LineEnd), ClipboardActions.Cut);
                        goto case 'i';

                    case '>':
                        Status   = ">";
                        CurState = State.Indent;
                        return;

                    case '<':
                        Status   = "<";
                        CurState = State.Unindent;
                        return;

                    case 'n':
                        Search();
                        return;

                    case 'N':
                        searchBackward = !searchBackward;
                        Search();
                        searchBackward = !searchBackward;
                        return;

                    case 'p':
                        PasteAfter(false);
                        return;

                    case 'P':
                        PasteBefore(false);
                        return;

                    case 's':
                        if (!Data.IsSomethingSelected)
                        {
                            RunAction(SelectionActions.FromMoveAction(CaretMoveActions.Right));
                        }
                        RunAction(ClipboardActions.Cut);
                        goto case 'i';

                    case 'S':
                        if (!Data.IsSomethingSelected)
                        {
                            RunAction(SelectionActions.LineActionFromMoveAction(CaretMoveActions.LineEnd));
                        }
                        else
                        {
                            Data.SetSelectLines(Data.MainSelection.Anchor.Line, Data.Caret.Line);
                        }
                        RunAction(ClipboardActions.Cut);
                        goto case 'i';

                    case 'g':
                        Status   = "g";
                        CurState = State.G;
                        return;

                    case 'H':
                        Caret.Line = System.Math.Max(DocumentLocation.MinLine, Editor.PointToLocation(0, Editor.LineHeight - 1).Line);
                        return;

                    case 'J':
                        RunAction(ViActions.Join);
                        return;

                    case 'L':
                        int line = Editor.PointToLocation(0, Editor.Bounds.Height - Editor.LineHeight * 2 - 2).Line;
                        if (line < DocumentLocation.MinLine)
                        {
                            line = Document.LineCount;
                        }
                        Caret.Line = line;
                        return;

                    case 'M':
                        line = Editor.PointToLocation(0, Editor.Bounds.Height / 2).Line;
                        if (line < DocumentLocation.MinLine)
                        {
                            line = Document.LineCount;
                        }
                        Caret.Line = line;
                        return;

                    case '~':
                        RunAction(ViActions.ToggleCase);
                        return;

                    case 'z':
                        Status   = "z";
                        CurState = State.Fold;
                        return;

                    case 'm':
                        Status   = "m";
                        CurState = State.Mark;
                        return;

                    case '`':
                        Status   = "`";
                        CurState = State.GoToMark;
                        return;

                    case '@':
                        Status   = "@";
                        CurState = State.PlayMacro;
                        return;

                    case 'q':
                        if (currentMacro == null)
                        {
                            Status   = "q";
                            CurState = State.NameMacro;
                            return;
                        }
                        currentMacro = null;
                        Reset("Macro Recorded");
                        return;

                    case '*':
                        SearchWordAtCaret();
                        return;
                    }
                }

                action = ViActionMaps.GetNavCharAction((char)unicodeKey);
                if (action == null)
                {
                    action = ViActionMaps.GetDirectionKeyAction(key, modifier);
                }
                if (action == null)
                {
                    action = ViActionMaps.GetCommandCharAction((char)unicodeKey);
                }

                if (action != null)
                {
                    RunAction(action);
                }

                //undo/redo may leave MD with a selection mode without activating visual mode
                CheckVisualMode();
                return;

            case State.Delete:
                if (IsInnerOrOuterMotionKey(unicodeKey, ref motion))
                {
                    return;
                }

                if (motion != Motion.None)
                {
                    action = ViActionMaps.GetEditObjectCharAction((char)unicodeKey, motion);
                }
                else if (((modifier & (Xwt.ModifierKeys.Shift | Xwt.ModifierKeys.Control)) == 0 &&
                          unicodeKey == 'd'))
                {
                    action     = SelectionActions.LineActionFromMoveAction(CaretMoveActions.LineEnd);
                    lineAction = true;
                }
                else
                {
                    action = ViActionMaps.GetNavCharAction((char)unicodeKey);
                    if (action == null)
                    {
                        action = ViActionMaps.GetDirectionKeyAction(key, modifier);
                    }
                    if (action != null)
                    {
                        action = SelectionActions.FromMoveAction(action);
                    }
                }

                if (action != null)
                {
                    if (lineAction)
                    {
                        RunActions(action, ClipboardActions.Cut, CaretMoveActions.LineFirstNonWhitespace);
                    }
                    else
                    {
                        RunActions(action, ClipboardActions.Cut);
                    }
                    Reset("");
                }
                else
                {
                    Reset("Unrecognised motion");
                }

                return;

            case State.Yank:
                if (IsInnerOrOuterMotionKey(unicodeKey, ref motion))
                {
                    return;
                }
                int offset = Caret.Offset;

                if (motion != Motion.None)
                {
                    action = ViActionMaps.GetEditObjectCharAction((char)unicodeKey, motion);
                }
                else if (((modifier & (Xwt.ModifierKeys.Shift | Xwt.ModifierKeys.Control)) == 0 &&
                          unicodeKey == 'y'))
                {
                    action     = SelectionActions.LineActionFromMoveAction(CaretMoveActions.LineEnd);
                    lineAction = true;
                }
                else
                {
                    action = ViActionMaps.GetNavCharAction((char)unicodeKey);
                    if (action == null)
                    {
                        action = ViActionMaps.GetDirectionKeyAction(key, modifier);
                    }
                    if (action != null)
                    {
                        action = SelectionActions.FromMoveAction(action);
                    }
                }

                if (action != null)
                {
                    RunAction(action);
                    if (Data.IsSomethingSelected && !lineAction)
                    {
                        offset = Data.SelectionRange.Offset;
                    }
                    RunAction(ClipboardActions.Copy);
                    Reset(string.Empty);
                }
                else
                {
                    Reset("Unrecognised motion");
                }
                Caret.Offset = offset;

                return;

            case State.Change:
                if (IsInnerOrOuterMotionKey(unicodeKey, ref motion))
                {
                    return;
                }

                if (motion != Motion.None)
                {
                    action = ViActionMaps.GetEditObjectCharAction((char)unicodeKey, motion);
                }
                //copied from delete action
                else if (((modifier & (Xwt.ModifierKeys.Shift | Xwt.ModifierKeys.Control)) == 0 &&
                          unicodeKey == 'c'))
                {
                    action     = SelectionActions.LineActionFromMoveAction(CaretMoveActions.LineEnd);
                    lineAction = true;
                }
                else
                {
                    action = ViActionMaps.GetEditObjectCharAction((char)unicodeKey);
                    if (action == null)
                    {
                        action = ViActionMaps.GetDirectionKeyAction(key, modifier);
                    }
                    if (action != null)
                    {
                        action = SelectionActions.FromMoveAction(action);
                    }
                }

                if (action != null)
                {
                    if (lineAction)
                    {
                        RunActions(action, ClipboardActions.Cut, ViActions.NewLineAbove);
                    }
                    else
                    {
                        RunActions(action, ClipboardActions.Cut);
                    }
                    Status     = "-- INSERT --";
                    CurState   = State.Insert;
                    motion     = Motion.None;
                    Caret.Mode = CaretMode.Insert;
                }
                else
                {
                    Reset("Unrecognised motion");
                }

                return;

            case State.Insert:
            case State.Replace:
                action = GetInsertAction(key, modifier);

                if (action != null)
                {
                    RunAction(action);
                }
                else if (unicodeKey != 0)
                {
                    InsertCharacter(unicodeKey);
                }

                return;

            case State.VisualLine:
                if (key == Key.Delete)
                {
                    unicodeKey = 'x';
                }
                switch ((char)unicodeKey)
                {
                case 'p':
                    PasteAfter(true);
                    return;

                case 'P':
                    PasteBefore(true);
                    return;
                }
                action = ViActionMaps.GetNavCharAction((char)unicodeKey);
                if (action == null)
                {
                    action = ViActionMaps.GetDirectionKeyAction(key, modifier);
                }
                if (action == null)
                {
                    action = ViActionMaps.GetCommandCharAction((char)unicodeKey);
                }
                if (action != null)
                {
                    RunAction(SelectionActions.LineActionFromMoveAction(action));
                    return;
                }

                ApplyActionToSelection(modifier, unicodeKey);
                return;

            case State.Visual:
                if (IsInnerOrOuterMotionKey(unicodeKey, ref motion))
                {
                    return;
                }

                if (motion != Motion.None)
                {
                    action = ViActionMaps.GetEditObjectCharAction((char)unicodeKey, motion);
                    if (action != null)
                    {
                        RunAction(action);
                        return;
                    }
                }

                if (key == Key.Delete)
                {
                    unicodeKey = 'x';
                }
                switch ((char)unicodeKey)
                {
                case 'p':
                    PasteAfter(false);
                    return;

                case 'P':
                    PasteBefore(false);
                    return;
                }
                action = ViActionMaps.GetNavCharAction((char)unicodeKey);
                if (action == null)
                {
                    action = ViActionMaps.GetDirectionKeyAction(key, modifier);
                }
                if (action == null)
                {
                    action = ViActionMaps.GetCommandCharAction((char)unicodeKey);
                }
                if (action != null)
                {
                    RunAction(ViActions.VisualSelectionFromMoveAction(action));
                    return;
                }

                ApplyActionToSelection(modifier, unicodeKey);
                return;

            case State.Command:
                switch (key)
                {
                case Key.Return:
                case Key.NumPadEnter:
                    Status = RunExCommand(commandBuffer.ToString());
                    commandBuffer.Length = 0;
                    CurState             = State.Normal;
                    break;

                case Key.BackSpace:
                case Key.Delete:
                case Key.NumPadDelete:
                    if (0 < commandBuffer.Length)
                    {
                        commandBuffer.Remove(commandBuffer.Length - 1, 1);
                        Status = commandBuffer.ToString();
                        if (0 == commandBuffer.Length)
                        {
                            Reset(Status);
                        }
                    }
                    break;

                default:
                    if (unicodeKey != 0)
                    {
                        commandBuffer.Append((char)unicodeKey);
                        Status = commandBuffer.ToString();
                    }
                    break;
                }
                return;

            case State.WriteChar:
                if (unicodeKey != 0)
                {
                    RunAction(SelectionActions.StartSelection);
                    int roffset = Data.SelectionRange.Offset;
                    InsertCharacter((char)unicodeKey);
                    Reset(string.Empty);
                    Caret.Offset = roffset;
                }
                else
                {
                    Reset("Keystroke was not a character");
                }
                return;

            case State.Indent:
                if (((modifier & (Xwt.ModifierKeys.Control)) == 0 && unicodeKey == '>'))
                {
                    RunAction(MiscActions.IndentSelection);
                    Reset("");
                    return;
                }

                action = ViActionMaps.GetNavCharAction((char)unicodeKey);
                if (action == null)
                {
                    action = ViActionMaps.GetDirectionKeyAction(key, modifier);
                }

                if (action != null)
                {
                    RunActions(SelectionActions.FromMoveAction(action), MiscActions.IndentSelection);
                    Reset("");
                }
                else
                {
                    Reset("Unrecognised motion");
                }
                return;

            case State.Unindent:
                if (((modifier & (Xwt.ModifierKeys.Control)) == 0 && ((char)unicodeKey) == '<'))
                {
                    RunAction(MiscActions.RemoveIndentSelection);
                    Reset("");
                    return;
                }

                action = ViActionMaps.GetNavCharAction((char)unicodeKey);
                if (action == null)
                {
                    action = ViActionMaps.GetDirectionKeyAction(key, modifier);
                }

                if (action != null)
                {
                    RunActions(SelectionActions.FromMoveAction(action), MiscActions.RemoveIndentSelection);
                    Reset("");
                }
                else
                {
                    Reset("Unrecognised motion");
                }
                return;

            case State.G:
                if (((modifier & (Xwt.ModifierKeys.Control)) == 0))
                {
                    switch ((char)unicodeKey)
                    {
                    case 'g':
                        Caret.Offset = 0;
                        Reset("");
                        return;
                    }
                }
                Reset("Unknown command");
                return;

            case State.Mark:
            {
                char   k    = (char)unicodeKey;
                ViMark mark = null;
                if (!char.IsLetterOrDigit(k))
                {
                    Reset("Invalid Mark");
                    return;
                }
                if (marks.ContainsKey(k))
                {
                    mark = marks[k];
                }
                else
                {
                    mark     = new ViMark(k);
                    marks[k] = mark;
                }
                RunAction(mark.SaveMark);
                Reset("");
                return;
            }

            case State.NameMacro:
            {
                char k = (char)unicodeKey;
                if (!char.IsLetterOrDigit(k))
                {
                    Reset("Invalid Macro Name");
                    return;
                }
                currentMacro             = new ViMacro(k);
                currentMacro.KeysPressed = new Queue <ViMacro.KeySet>();
                macros[k] = currentMacro;
                Reset("");
                return;
            }

            case State.PlayMacro:
            {
                char k = (char)unicodeKey;
                if (k == '@')
                {
                    k = macros_lastplayed;
                }
                if (macros.ContainsKey(k))
                {
                    Reset("");
                    macros_lastplayed = k;         // FIXME play nice when playing macros from inside macros?
                    ViMacro macroToPlay = macros[k];
                    foreach (ViMacro.KeySet keySet in macroToPlay.KeysPressed)
                    {
                        HandleKeypress(keySet.Key, keySet.UnicodeKey, keySet.Modifiers);         // FIXME stop on errors? essential with multipliers and nowrapscan
                    }
                    /* Once all the keys have been played back, quickly exit. */
                    return;
                }
                else
                {
                    Reset("Invalid Macro Name '" + k + "'");
                    return;
                }
            }

            case State.GoToMark:
            {
                char k = (char)unicodeKey;
                if (marks.ContainsKey(k))
                {
                    RunAction(marks[k].LoadMark);
                    Reset("");
                }
                else
                {
                    Reset("Unknown Mark");
                }
                return;
            }

            case State.Fold:
                if (((modifier & (Xwt.ModifierKeys.Control)) == 0))
                {
                    switch ((char)unicodeKey)
                    {
                    case 'A':
                        // Recursive fold toggle
                        action = FoldActions.ToggleFoldRecursive;
                        break;

                    case 'C':
                        // Recursive fold close
                        action = FoldActions.CloseFoldRecursive;
                        break;

                    case 'M':
                        // Close all folds
                        action = FoldActions.CloseAllFolds;
                        break;

                    case 'O':
                        // Recursive fold open
                        action = FoldActions.OpenFoldRecursive;
                        break;

                    case 'R':
                        // Expand all folds
                        action = FoldActions.OpenAllFolds;
                        break;

                    case 'a':
                        // Fold toggle
                        action = FoldActions.ToggleFold;
                        break;

                    case 'c':
                        // Fold close
                        action = FoldActions.CloseFold;
                        break;

                    case 'o':
                        // Fold open
                        action = FoldActions.OpenFold;
                        break;

                    case 'z':
                    case '.':
                        editor.CenterToCaret();
                        Reset("");
                        break;

                    default:
                        Reset("Unknown command");
                        break;
                    }

                    if (null != action)
                    {
                        RunAction(action);
                        Reset(string.Empty);
                    }
                }

                return;
            }
        }
コード例 #16
0
 protected virtual Action <TextEditorData> GetInsertAction(Key key, Xwt.ModifierKeys modifier)
 {
     return(ViActionMaps.GetInsertKeyAction(key, modifier) ??
            ViActionMaps.GetDirectionKeyAction(key, modifier));
 }
コード例 #17
0
 public virtual bool PreemptIM(Key key, int unicodeKey, Xwt.ModifierKeys modifier)
 {
     return(false);
 }
コード例 #18
0
 public MarginMouseEventArgs(TextEditor editor, int button, double x, double y, Xwt.ModifierKeys modifierState)
 {
     this.Editor        = editor;
     this.Button        = button;
     this.X             = x;
     this.Y             = y;
     this.ModifierState = modifierState;
 }
コード例 #19
0
 public MarginMouseEventArgs(TextEditor editor, EventArgs raw, int button, double x, double y, Xwt.ModifierKeys modifierState)
     : this(editor, button, x, y, modifierState)
 {
     this.RawEvent = raw;
 }
コード例 #20
0
ファイル: TextEditor.cs プロジェクト: radtek/datawf
 /// <remarks>
 /// The Key may be null if it has been handled by the IMContext. In such cases, the char is the value.
 /// </remarks>
 protected internal virtual bool OnIMProcessedKeyPressEvent(Key key, int ch, Xwt.ModifierKeys state)
 {
     SimulateKeyPress(key, ch, state);
     return(true);
 }
コード例 #21
0
 protected override void HandleKeypress(Key key, int unicodeKey, Xwt.ModifierKeys modifier)
 {
     ViEditor.ProcessKey(modifier, key, (char)unicodeKey);
 }
コード例 #22
0
ファイル: TextLinkEditMode.cs プロジェクト: radtek/datawf
        protected override Xwt.Window CreateTooltipWindow(TextEditor Editor, double offset, Xwt.ModifierKeys modifierState, TooltipItem item)
        {
            TextLink link = item.Item as TextLink;

            if (link == null || string.IsNullOrEmpty(link.Tooltip))
            {
                return(null);
            }

            TooltipWindow window = new TooltipWindow();

            window.Markup = link.Tooltip;
            return(window);
        }
コード例 #23
0
ファイル: TextLinkEditMode.cs プロジェクト: radtek/datawf
        protected override void HandleKeypress(Key key, int unicodeKey, Xwt.ModifierKeys modifier)
        {
            var wnd = window;

            if (wnd != null)
            {
                ListWindowKeyAction action = wnd.ProcessKey(key, modifier);
                if ((action & ListWindowKeyAction.Complete) == ListWindowKeyAction.Complete)
                {
                    CompleteWindow();
                }
                if ((action & ListWindowKeyAction.CloseWindow) == ListWindowKeyAction.CloseWindow)
                {
                    closedLink = (TextLink)wnd.DataProvider;
                    DestroyWindow();
                }
                if ((action & ListWindowKeyAction.Complete) == ListWindowKeyAction.Complete)
                {
                    GotoNextLink(closedLink);
                }

                if ((action & ListWindowKeyAction.Ignore) == ListWindowKeyAction.Ignore)
                {
                    return;
                }
            }
            int      caretOffset = Editor.Caret.Offset - baseOffset;
            TextLink link        = links.Find(l => l.Links.Any(s => s.Offset <= caretOffset && caretOffset <= s.EndOffset));

            switch (key)
            {
            case Key.BackSpace:
                if (link != null && caretOffset == link.PrimaryLink.Offset)
                {
                    return;
                }
                goto default;

            case Key.Space:
                if (link == null || !link.IsIdentifier)
                {
                    goto default;
                }
                return;

            case Key.Delete:
                if (link != null && caretOffset == link.PrimaryLink.EndOffset)
                {
                    return;
                }
                goto default;

            case Key.Tab:
                if ((modifier & Xwt.ModifierKeys.Control) != 0)
                {
                    if (link != null && !link.IsIdentifier)
                    {
                        goto default;
                    }
                }
                if ((modifier & Xwt.ModifierKeys.Shift) == 0)
                {
                    GotoNextLink(link);
                }
                else
                {
                    GotoPreviousLink(link);
                }
                return;

            case Key.Escape:
            case Key.Return:
            case Key.NumPadEnter:
                if ((modifier & Xwt.ModifierKeys.Control) != 0)
                {
                    if (link != null && !link.IsIdentifier)
                    {
                        goto default;
                    }
                }
                if (wnd != null)
                {
                    CompleteWindow();
                }
                else
                {
                    ExitTextLinkMode();
                }
                if (key == Key.Escape)
                {
                    OnCancel(EventArgs.Empty);
                }
                return;

            default:
                wasReplaced = false;
                base.HandleKeypress(key, unicodeKey, modifier);
                if (wasReplaced && link == null)
                {
                    resetCaret = false;
                    ExitTextLinkMode();
                }
                break;
            }

            /*			if (link != null)
             *              UpdateTextLink (link);
             *          UpdateTextLinks ();
             *          Editor.Document.CommitUpdateAll ();*/
        }
コード例 #24
0
ファイル: ViActionMaps.cs プロジェクト: radtek/datawf
        public static Action <TextEditorData> GetDirectionKeyAction(Key key, Xwt.ModifierKeys modifier)
        {
            //
            // NO MODIFIERS
            //
            if ((modifier & (Xwt.ModifierKeys.Shift | Xwt.ModifierKeys.Control)) == 0)
            {
                switch (key)
                {
                case Key.Left:
                case Key.NumPadLeft:
                    return(ViActions.Left);

                case Key.Right:
                case Key.NumPadRight:
                    return(ViActions.Right);

                case Key.Up:
                case Key.NumPadUp:
                    return(ViActions.Up);

                case Key.Down:
                case Key.NumPadDown:
                    return(ViActions.Down);

                //not strictly vi, but more useful IMO
                case Key.NumPadHome:
                case Key.Home:
                    return(CaretMoveActions.LineHome);

                case Key.NumPadEnd:
                case Key.End:
                    return(ViActions.LineEnd);

                case Key.PageUp:
                    return(CaretMoveActions.PageUp);

                case Key.PageDown:
                    return(CaretMoveActions.PageDown);
                }
            }
            //
            // === CONTROL ===
            //
            else if ((modifier & Xwt.ModifierKeys.Shift) == 0 &&
                     (modifier & Xwt.ModifierKeys.Control) != 0)
            {
                switch (key)
                {
                case Key.Left:
                case Key.NumPadLeft:
                    return(CaretMoveActions.PreviousWord);

                case Key.Right:
                case Key.NumPadRight:
                    return(CaretMoveActions.NextWord);

                case Key.Up:
                case Key.NumPadUp:
                    return(ScrollActions.Up);

                // usually bound at IDE level
                case Key.u:
                    return(CaretMoveActions.PageUp);

                case Key.Down:
                case Key.NumPadDown:
                    return(ScrollActions.Down);

                case Key.d:
                    return(CaretMoveActions.PageDown);

                case Key.NumPadHome:
                case Key.Home:
                    return(CaretMoveActions.ToDocumentStart);

                case Key.NumPadEnd:
                case Key.End:
                    return(CaretMoveActions.ToDocumentEnd);
                }
            }
            return(null);
        }