示例#1
0
        protected override bool ProcessCmdKey(ref Message msg, Keys e)
        {
            bool ctrlV    = e == (Keys.Control | Keys.V);
            bool shiftIns = e == (Keys.Shift | Keys.Insert);
            bool ctrlC    = e == (Keys.Control | Keys.C);
            bool ctrlX    = e == (Keys.Control | Keys.X);

            if (method == CopyMethod.Integers && (ctrlV || shiftIns))
            {
                var text = Clipboard.GetText();
                {
                    var split = new string[(text.Length / 2) + (text.Length % 2 == 0 ? 0 : 1)];
                    for (int i = 0; i < split.Length; i++)
                    {
                        split[i] = text.Substring(i * 2, (i * 2) + 2 > text.Length ? 1 : 2);
                    }
                    Clipboard.SetText(string.Join(" ", split));
                }
            }
            var handled = base.ProcessCmdKey(ref msg, e);

            if (method == CopyMethod.Integers)
            {
                if (ctrlC || ctrlX)
                {
                    if (string.IsNullOrWhiteSpace(SelectedText))
                    {
                        return(false);
                    }
                    Clipboard.SetText(string.Concat(SelectedText.Split(' ').Reverse()));
                    return(true);
                }
            }
            return(handled);
        }
        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            if (e.KeyChar == '@')
            {
                //autoCompleteBox.Parent = this;
                //Point cursorPt = Cursor.Position;
                //autoCompleteBox.Location = PointToClient(cursorPt);
                //autoCompleteBox.Items.Clear();
                //foreach (String s in autoCompleteList)
                //{
                //    autoCompleteBox.Items.Add(s);
                //}
                //autoCompleteBox.Show();
                //autoCompleteBox.Visible = true;
            }
            else if (e.KeyChar == (char)Keys.Return)
            {
                e.Handled = true;

                var pos            = SelectionStart;
                var lineNumber     = GetLineFromCharIndex(pos) - 1;
                var currentLineStr = Lines[lineNumber];

                var firstChar = 0;
                while (firstChar != currentLineStr.Length)
                {
                    if (!Char.IsWhiteSpace(currentLineStr[firstChar]))
                    {
                        break;
                    }
                    firstChar++;
                }
                var indent = currentLineStr.Substring(0, firstChar);
                SelectionFont = Font;
                SelectedText  = indent;
            }
            else if (e.KeyChar == '\t')
            {
                e.Handled = true;

                if (!isShift && SelectionLength == 0)
                {
                    SelectionFont = Font;
                    SelectedText  = "    ";
                }
                else
                {
                    var lineStart = GetLineFromCharIndex(SelectionStart);
                    var lineEnd   = GetLineFromCharIndex(SelectionStart + SelectionLength);
                    var selStart  = GetFirstCharIndexFromLine(lineStart);
                    var selEnd    = GetFirstCharIndexFromLine(lineEnd) + Lines[lineEnd].Length;
                    var selLength = selEnd - selStart;
                    SelectionStart  = selStart;
                    SelectionLength = selLength;

                    var lines       = SelectedText.Split(new[] { '\n' }, StringSplitOptions.None);
                    var replacement = "";
                    if (isShift)
                    {
                        replacement = string.Join("\n", lines.Select(line => line.ReduceIndent(4)));
                    }
                    else
                    {
                        replacement = string.Join("\n", lines.Select(line => line.IncreaseIndent(4)));
                    }
                    SelectionFont   = Font;
                    SelectedText    = replacement;
                    SelectionStart  = selStart;
                    SelectionLength = replacement.Length;
                }
            }

            base.OnKeyPress(e);
        }