Example #1
0
 public MainWindow()
 {
     InitializeComponent();
     // 更新状态栏
     CodeBox.SelectionChanged += (s, e) =>
     {
         int lineIndex = CodeBox.GetLineIndexFromCharacterIndex(CodeBox.CaretIndex);
         LineIndexSBI.Content       = lineIndex + 1;
         ColIndexSBI.Content        = CodeBox.CaretIndex - CodeBox.GetCharacterIndexFromLineIndex(lineIndex) + 1;
         SelectionLengthSBI.Content = CodeBox.SelectionLength;
     };
     CodeBox.DecorationScheme = CodeBoxControl.Decorations.DecorationSchemes.Java;
 }
Example #2
0
        /// <summary>
        /// 注释多行
        /// </summary>
        private void CommentMultiLines()
        {
            // 将选择区域修正成首行行头到末行行尾
            int firstLine = CodeBox.GetLineIndexFromCharacterIndex(CodeBox.SelectionStart);
            int lastLine  = CodeBox.GetLineIndexFromCharacterIndex(CodeBox.SelectionStart + CodeBox.SelectionLength);

            CodeBox.SelectionStart  = CodeBox.GetCharacterIndexFromLineIndex(firstLine);
            CodeBox.SelectionLength = CodeBox.GetCharacterIndexFromLineIndex(lastLine)
                                      + CodeBox.GetLineLength(lastLine)
                                      - CodeBox.SelectionStart;

            string[]      lines = CodeBox.SelectedText.Split('\n');
            StringBuilder sb    = new StringBuilder();
            int           i     = 0;

            for (; i < lines.Length - 1; i++)
            {
                sb.Append("//").Append(lines[i]).Append('\n');
            }
            sb.Append("//").Append(lines[i]);
            CodeBox.textChangedEnable = false;
            CodeBox.SelectedText      = sb.ToString();
            CodeBox.textChangedEnable = true;
        }
Example #3
0
        /// <summary>
        /// 注释单行
        /// </summary>
        private void CommentOneLine()
        {
            int lineindex      = CodeBox.GetLineIndexFromCharacterIndex(CodeBox.SelectionStart);
            int firstCharIndex = CodeBox.GetCharacterIndexFromLineIndex(lineindex);
            int lastCharIndex  = firstCharIndex + CodeBox.GetLineLength(lineindex) - 1;
            // 判断是否选择了该行所有非空白字符
            bool selectWholeLine = true;

            for (int i = firstCharIndex; i <= lastCharIndex; i++)
            {
                if (i >= CodeBox.SelectionStart && i < CodeBox.SelectionStart + CodeBox.SelectionLength)
                {
                    continue;
                }
                else if (char.IsWhiteSpace(CodeBox.Text[i]))
                {
                    continue;
                }
                else
                {
                    selectWholeLine = false;
                    break;
                }
            }

            CodeBox.textChangedEnable = false;
            if (selectWholeLine)
            {
                CodeBox.SelectedText = "//" + CodeBox.SelectedText;
            }
            else
            {
                CodeBox.SelectedText = "/*" + CodeBox.SelectedText + "*/";
            }
            CodeBox.textChangedEnable = true;
        }