示例#1
0
        protected override void Convert(Document.Document document, int startOffset, int length)
        {
            StringBuilder sb       = new StringBuilder();
            string        sin      = document.GetText(startOffset, length);
            char          lastChar = '_';

            // Fix any errant spaces.
            sin = sin.Replace(' ', '_');

            if (sin != null)
            {
                foreach (char c in sin)
                {
                    if (c == '_')
                    {
                        sb.Append(' ');
                    }
                    else if (lastChar == '_')
                    {
                        sb.Append(char.ToUpper(c));
                    }
                    else
                    {
                        sb.Append(char.ToLower(c));
                    }

                    lastChar = c;
                }
            }

            document.Replace(startOffset, length, sb.ToString());
        }
示例#2
0
        protected override void Convert(Document.Document document, int startLine, int endLine)
        {
            List <string> lines = new List <string>();

            for (int i = startLine; i <= endLine; ++i)
            {
                LineSegment line = document.GetLineSegment(i);
                lines.Add(document.GetText(line.Offset, line.Length));
            }

            for (int i = 0; i < lines.Count - 1; ++i)
            {
                if (lines[i] == "")
                {
                    lines.RemoveAt(i);
                    --i;
                }
            }

            for (int i = 0; i < lines.Count; ++i)
            {
                LineSegment line = document.GetLineSegment(startLine + i);
                document.Replace(line.Offset, line.Length, lines[i].ToString());
            }

            // remove removed lines
            for (int i = startLine + lines.Count; i <= endLine; ++i)
            {
                LineSegment line = document.GetLineSegment(startLine + lines.Count);
                document.Remove(line.Offset, line.TotalLength);
            }
        }
示例#3
0
        protected override void Convert(Document.Document document, int y1, int y2)
        {
            for (int i = y2; i >= y1; --i)
            {
                LineSegment line = document.GetLineSegment(i);

                if (line.Length > 0)
                {
                    // count how many whitespace characters there are at the start
                    int whiteSpace;

                    for (whiteSpace = 0; whiteSpace < line.Length && char.IsWhiteSpace(document.GetCharAt(line.Offset + whiteSpace)); whiteSpace++)
                    {
                        // deliberately empty
                    }

                    if (whiteSpace > 0)
                    {
                        string newLine   = document.GetText(line.Offset, whiteSpace);
                        string newPrefix = newLine.Replace("\t", new string(' ', Shared.TEP.TabIndent));
                        document.Replace(line.Offset, whiteSpace, newPrefix);
                    }
                }
            }
        }
示例#4
0
        protected override void Convert(Document.Document document, int startOffset, int length)
        {
            string what   = document.GetText(startOffset, length);
            string spaces = new string(' ', Shared.TEP.TabIndent);

            document.Replace(startOffset, length, what.Replace(spaces, "\t"));
        }
示例#5
0
        protected override void Convert(Document.Document document, int startOffset, int length)
        {
            StringBuilder what = new StringBuilder(document.GetText(startOffset, length));

            for (int i = 0; i < what.Length; ++i)
            {
                what[i] = char.IsUpper(what[i]) ? Char.ToLower(what[i]) : Char.ToUpper(what[i]);
            }

            document.Replace(startOffset, length, what.ToString());
        }
示例#6
0
        protected override void Convert(Document.Document document, int startOffset, int length)
        {
            StringBuilder what = new StringBuilder(document.GetText(startOffset, length));

            for (int i = 0; i < what.Length; ++i)
            {
                if (!char.IsLetter(what[i]) && i < what.Length - 1)
                {
                    what[i + 1] = char.ToUpper(what[i + 1]);
                }
            }
            document.Replace(startOffset, length, what.ToString());
        }
示例#7
0
 protected override void Convert(Document.Document document, int y1, int y2)
 {
     for (int i = y2; i >= y1; --i)
     {
         LineSegment line = document.GetLineSegment(i);
         if (line.Length > 0)
         {
             // note: some users may prefer a more radical ConvertLeadingSpacesToTabs that
             // means there can be no spaces before the first character even if the spaces
             // didn't add up to a whole number of tabs
             string newLine = TextUtilities.LeadingWhiteSpaceToTabs(document.GetText(line.Offset, line.Length), Shared.TEP.TabIndent);
             document.Replace(line.Offset, line.Length, newLine);
         }
     }
 }
示例#8
0
        protected override void Convert(Document.Document document, int startOffset, int length)
        {
            string sin = document.GetText(startOffset, length);
            string sout;

            try
            {
                XDocument doc = XDocument.Parse(sin);
                sout = doc.ToString();
            }
            catch (Exception)
            {
                sout = sin;
            }

            document.Replace(startOffset, length, sout);
        }
 bool ShouldComment(Document.Document document, string comment, SelectionManager selmgr, int startLine, int endLine)
 {
     for (int i = endLine; i >= startLine; --i)
     {
         LineSegment line = document.GetLineSegment(i);
         if (selmgr != null && i == endLine && line.Offset == selmgr.StartOffset + selmgr.Length)
         {
             --lastLine;
             continue;
         }
         string lineText = document.GetText(line.Offset, line.Length);
         if (!lineText.Trim().StartsWith(comment))
         {
             return(true);
         }
     }
     return(false);
 }
        void SetCommentAt(Document.Document document, string comment, SelectionManager selmgr, int y1, int y2)
        {
            firstLine = y1;
            lastLine  = y2;

            for (int i = y2; i >= y1; --i)
            {
                LineSegment line = document.GetLineSegment(i);
                if (selmgr != null && i == y2 && line.Offset == selmgr.StartOffset + selmgr.Length)
                {
                    --lastLine;
                    continue;
                }

                string lineText = document.GetText(line.Offset, line.Length);
                document.Insert(line.Offset, comment);
            }
        }
        void RemoveCommentAt(Document.Document document, string comment, SelectionManager selmgr, int y1, int y2)
        {
            firstLine = y1;
            lastLine  = y2;

            for (int i = y2; i >= y1; --i)
            {
                LineSegment line = document.GetLineSegment(i);
                if (selmgr != null && i == y2 && line.Offset == selmgr.StartOffset + selmgr.Length)
                {
                    --lastLine;
                    continue;
                }

                string lineText = document.GetText(line.Offset, line.Length);
                if (lineText.Trim().StartsWith(comment))
                {
                    document.Remove(line.Offset + lineText.IndexOf(comment), comment.Length);
                }
            }
        }
示例#12
0
        protected override void Convert(Document.Document document, int startOffset, int length)
        {
            StringBuilder sb       = new StringBuilder();
            string        sin      = document.GetText(startOffset, length);
            char          lastChar = sin[0];

            foreach (char c in sin)
            {
                if (char.IsUpper(c) && char.IsLower(lastChar))
                {
                    sb.Append(' ');
                    sb.Append(c);
                }
                else
                {
                    sb.Append(c);
                }

                lastChar = c;
            }

            document.Replace(startOffset, length, sb.ToString());
        }
        public static BlockCommentRegion FindSelectedCommentRegion(Document.Document document, string commentStart, string commentEnd, int selectionStartOffset, int selectionEndOffset)
        {
            if (document.TextLength == 0)
            {
                return(null);
            }

            // Find start of comment in selected text.

            int    commentEndOffset = -1;
            string selectedText     = document.GetText(selectionStartOffset, selectionEndOffset - selectionStartOffset);

            int commentStartOffset = selectedText.IndexOf(commentStart);

            if (commentStartOffset >= 0)
            {
                commentStartOffset += selectionStartOffset;
            }

            // Find end of comment in selected text.

            if (commentStartOffset >= 0)
            {
                commentEndOffset = selectedText.IndexOf(commentEnd, commentStartOffset + commentStart.Length - selectionStartOffset);
            }
            else
            {
                commentEndOffset = selectedText.IndexOf(commentEnd);
            }

            if (commentEndOffset >= 0)
            {
                commentEndOffset += selectionStartOffset;
            }

            // Find start of comment before or partially inside the
            // selected text.

            int commentEndBeforeStartOffset = -1;

            if (commentStartOffset == -1)
            {
                int offset = selectionEndOffset + commentStart.Length - 1;
                if (offset > document.TextLength)
                {
                    offset = document.TextLength;
                }
                string text = document.GetText(0, offset);
                commentStartOffset = text.LastIndexOf(commentStart);
                if (commentStartOffset >= 0)
                {
                    // Find end of comment before comment start.
                    commentEndBeforeStartOffset = text.IndexOf(commentEnd, commentStartOffset, selectionStartOffset - commentStartOffset);
                    if (commentEndBeforeStartOffset > commentStartOffset)
                    {
                        commentStartOffset = -1;
                    }
                }
            }

            // Find end of comment after or partially after the selected text.
            if (commentEndOffset == -1)
            {
                int offset = selectionStartOffset + 1 - commentEnd.Length;
                if (offset < 0)
                {
                    offset = selectionStartOffset;
                }
                string text = document.GetText(offset, document.TextLength - offset);
                commentEndOffset = text.IndexOf(commentEnd);
                if (commentEndOffset >= 0)
                {
                    commentEndOffset += offset;
                }
            }

            if (commentStartOffset != -1 && commentEndOffset != -1)
            {
                return(new BlockCommentRegion(commentStart, commentEnd, commentStartOffset, commentEndOffset));
            }

            return(null);
        }
示例#14
0
        protected override void Convert(Document.Document document, int startOffset, int length)
        {
            string sin = document.GetText(startOffset, length);

            document.Replace(startOffset, length, sin.Replace(' ', '_').ToUpper());
        }
示例#15
0
        protected override void Convert(Document.Document document, int startOffset, int length)
        {
            string what = document.GetText(startOffset, length).ToLower();

            document.Replace(startOffset, length, what);
        }