Exemplo n.º 1
0
        void ToggleCodeCommentWithBlockComments()
        {
            var blockStarts = TextEditorFactory.GetSyntaxProperties(Editor.MimeType, "BlockCommentStart");
            var blockEnds   = TextEditorFactory.GetSyntaxProperties(Editor.MimeType, "BlockCommentEnd");

            if (blockStarts == null || blockEnds == null || blockStarts.Length == 0 || blockEnds.Length == 0)
            {
                return;
            }

            string blockStart = blockStarts[0];
            string blockEnd   = blockEnds[0];

            using (var undo = Editor.OpenUndoGroup()) {
                IDocumentLine startLine;
                IDocumentLine endLine;

                if (Editor.IsSomethingSelected)
                {
                    startLine = Editor.GetLineByOffset(Editor.SelectionRange.Offset);
                    endLine   = Editor.GetLineByOffset(Editor.SelectionRange.EndOffset);

                    // If selection ends at begining of line... This is visible as previous line
                    // is selected, hence we want to select previous line Bug 26287
                    if (endLine.Offset == Editor.SelectionRange.EndOffset)
                    {
                        endLine = endLine.PreviousLine;
                    }
                }
                else
                {
                    startLine = endLine = Editor.GetLine(Editor.CaretLine);
                }
                string startLineText = Editor.GetTextAt(startLine.Offset, startLine.Length);
                string endLineText   = Editor.GetTextAt(endLine.Offset, endLine.Length);
                if (startLineText.StartsWith(blockStart, StringComparison.Ordinal) && endLineText.EndsWith(blockEnd, StringComparison.Ordinal))
                {
                    Editor.RemoveText(endLine.Offset + endLine.Length - blockEnd.Length, blockEnd.Length);
                    Editor.RemoveText(startLine.Offset, blockStart.Length);
                    if (Editor.IsSomethingSelected)
                    {
                        Editor.SelectionAnchorOffset -= blockEnd.Length;
                    }
                }
                else
                {
                    Editor.InsertText(endLine.Offset + endLine.Length, blockEnd);
                    Editor.InsertText(startLine.Offset, blockStart);
                    if (Editor.IsSomethingSelected)
                    {
                        Editor.SelectionAnchorOffset += blockEnd.Length;
                    }
                }
            }
        }
Exemplo n.º 2
0
        bool TryGetLineCommentTag(out string commentTag)
        {
            var lineComments = TextEditorFactory.GetSyntaxProperties(Editor.MimeType, "LineComment");

            if (lineComments == null || lineComments.Length == 0)
            {
                commentTag = null;
                return(false);
            }
            commentTag = lineComments [0];
            return(true);
        }
Exemplo n.º 3
0
        void OnUpdateToggleComment(CommandInfo info)
        {
            var lineComments = TextEditorFactory.GetSyntaxProperties(Editor.MimeType, "LineComment");

            if (lineComments != null && lineComments.Length > 0)
            {
                info.Visible = true;
                return;
            }
            var blockStarts = TextEditorFactory.GetSyntaxProperties(Editor.MimeType, "BlockCommentStart");
            var blockEnds   = TextEditorFactory.GetSyntaxProperties(Editor.MimeType, "BlockCommentEnd");

            info.Visible = blockStarts != null && blockStarts.Length > 0 && blockEnds != null && blockEnds.Length > 0;
        }
Exemplo n.º 4
0
        public static string[] GetCommentTags(string fileName)
        {
            //Document doc = IdeApp.Workbench.ActiveDocument;
            string loadedMimeType = DesktopService.GetMimeTypeForUri(fileName);

            var result = TextEditorFactory.GetSyntaxProperties(loadedMimeType, "LineComment");

            if (result != null)
            {
                return(result);
            }

            var start = TextEditorFactory.GetSyntaxProperties(loadedMimeType, "BlockCommentStart");
            var end   = TextEditorFactory.GetSyntaxProperties(loadedMimeType, "BlockCommentEnd");

            if (start != null && end != null)
            {
                return new [] { start[0], end[0] }
            }
            ;
            return(null);
        }
Exemplo n.º 5
0
 static string [] GetList(IReadonlyTextDocument document, string name)
 {
     return(TextEditorFactory.GetSyntaxProperties(document.MimeType, name) ?? emptyList);
 }