Exemplo n.º 1
0
    protected virtual PastingEventArgs OnPasting(string value)
    {
        var handler = Pasting;
        var args    = new PastingEventArgs(value);

        if (handler != null)
        {
            handler(this, args);
        }
        return(args);
    }
Exemplo n.º 2
0
        public RichTextBoxPlus()
        {
            var multiEditBrain = new MyMultiEditBrain(this);

            AcceptsTab = true;

            // A hack to properly disable AutoWordSelection. It is first set to true in the constructor, and sometime after the constructor it is
            // set back to false.
            AutoWordSelection = true;

            KeyDown += async(s, e) =>
            {
                if (e.Handled)
                {
                    return;
                }
                switch (e.KeyData)
                {
                case Keys.F | Keys.Control:
                    e.Handled = true;
                    await ShowFindDialog();

                    break;

                case Keys.F3:
                    e.Handled = true;
                    FindNext(Math.Min(TextLength, SelectionStart + 1));
                    break;

                case Keys.Shift | Keys.F3:
                    e.Handled = true;
                    FindPrev(SelectionStart - 1);
                    break;

                case Keys.F7:
                    e.Handled = true;
                    Tidy();
                    break;

                case Keys.V | Keys.Control:
                case Keys.Insert | Keys.Shift:
                    if (CanPaste(DataFormats.GetFormat("Text")))
                    {
                        e.Handled = true;
                        var e1 = new PastingEventArgs();
                        Pasting(e1);
                        if (!e1.Handled)
                        {
                            Paste(DataFormats.GetFormat("Text"));
                        }
                    }
                    break;

                case Keys.Shift | Keys.Delete:
                    e.Handled = true;
                    RemoveSelectedLines();
                    break;

                case Keys.Control | Keys.Shift | Keys.D:
                    e.Handled = true;
                    DuplicateSelectionOrLine();
                    break;

                case Keys.Alt | Keys.Up:
                    e.Handled = true;
                    MoveSelectedLines(ArrowDirection.Up);
                    break;

                case Keys.Alt | Keys.Down:
                    e.Handled = true;
                    MoveSelectedLines(ArrowDirection.Down);
                    break;

                case Keys.Control | Keys.Alt | Keys.Shift | Keys.C:
                    CropText();
                    break;

                case Keys.Control | Keys.X:
                    if (!ContainsJson || 0 < SelectionLength)
                    {
                        break;
                    }
                    e.Handled = true;
                    CutOutJsonString();
                    break;

                case Keys.Control | Keys.C:
                    if (!ContainsJson || 0 < SelectionLength)
                    {
                        break;
                    }
                    e.Handled = true;
                    CopyJsonString();
                    break;

                case Keys.Shift | Keys.Back:
                    if (!ContainsJson || 0 < SelectionLength)
                    {
                        break;
                    }
                    e.Handled = true;
                    DeleteJsonString();
                    break;
                }
            };

            KeyPress += (s, e) =>
            {
                if (e.KeyChar == '\t')
                {
                    e.Handled    = true;
                    SelectedText = "  ";
                }
            };

            KeyUp += async(s, e) =>
            {
                // A hack to fix the "Chinese Character Bug".
                if (!e.KeyData.HasFlag(Keys.Alt) || Parent == null)
                {
                    return;
                }
                await Task.Yield();

                Parent.Focus();
                Focus();
            };

            Disposed += (s, e) =>
            {
                multiEditBrain.Dispose();
            };

            LinkClicked += async(s, e) =>
            {
                await Helper.StartProcessAsync(e.LinkText);
            };

            MouseDown += (s, e) =>
            {
                if (AutoWordSelection)
                {
                    AutoWordSelection = false;
                }
            };
        }