Esempio n. 1
0
        private XamlFormatter.XmlElementFormatting GetElementFormatting(ElementNode elementNode)
        {
            XamlFormatter.XmlElementFormatting elementFormatting = new XamlFormatter.XmlElementFormatting();
            XmlElementReference elementReference = elementNode.SourceContextReference.SourceContext as XmlElementReference;

            if (elementReference != null && elementReference.TextRange != null)
            {
                IReadableTextBuffer textBuffer = (IReadableTextBuffer)TextBufferHelper.GetHostBuffer(elementReference.TextBuffer);
                elementFormatting.LeadingWhitespace          = XamlFormatter.GetLeadingWhitespace((XamlSourceContext)elementReference);
                elementFormatting.TrailingWhitespace         = XamlFormatter.GetTrailingWhitespace((XamlSourceContext)elementReference);
                elementFormatting.AttributeLeadingWhitespace = XamlFormatter.GetTrailingWhitespace(textBuffer, elementReference.TextRange.Offset);
                if (elementReference.StartTagRange != null)
                {
                    elementFormatting.AttributeTrailingWhitespace = XamlFormatter.GetLeadingWhitespace(textBuffer, elementReference.StartTagRange.Offset + elementReference.StartTagRange.Length - 1);
                    elementFormatting.ContentLeadingWhitespace    = XamlFormatter.GetTrailingWhitespace(textBuffer, elementReference.StartTagRange.Offset + elementReference.StartTagRange.Length);
                    int num = elementReference.TextRange.Offset + elementReference.TextRange.Length;
                    elementFormatting.ContentTrailingWhitespace = XamlFormatter.GetLeadingWhitespace(textBuffer, num - (elementNode.Name.FullName.Length + 3));
                }
                else
                {
                    elementFormatting.AttributeTrailingWhitespace = XamlFormatter.GetLeadingWhitespace(textBuffer, elementReference.TextRange.Offset + elementReference.TextRange.Length - 2);
                    elementFormatting.ContentLeadingWhitespace    = (string)null;
                    elementFormatting.ContentTrailingWhitespace   = (string)null;
                }
            }
            return(elementFormatting);
        }
Esempio n. 2
0
        public static ITextRange ExpandSpanToFillWhitespace(IReadableTextBuffer textBuffer, ITextRange span, bool walkLeft, bool walkRight)
        {
            if (textBuffer.Length == 0)
            {
                return(span);
            }
            int offset1 = Math.Max(0, span.Offset - 64);
            int num     = Math.Min(textBuffer.Length - 1, span.Offset + span.Length + 64);
            int offset2 = span.Offset;
            int end     = span.Offset + span.Length;

            for (int offset3 = span.Offset; walkLeft && offset1 < offset3 && offset2 == offset3; offset1 = Math.Max(0, offset3 - 64))
            {
                string text  = textBuffer.GetText(offset1, offset3 - offset1);
                int    index = text.Length - 1;
                while (index >= 0 && char.IsWhiteSpace(text[index]))
                {
                    --index;
                    --offset2;
                }
                offset3 -= text.Length;
            }
            for (int offset3 = span.Offset + span.Length; walkRight && num > offset3 && end == offset3; num = Math.Min(textBuffer.Length - 1, offset3 + 64))
            {
                string text  = textBuffer.GetText(offset3, num - offset3 + 1);
                int    index = 0;
                while (index < text.Length && char.IsWhiteSpace(text[index]))
                {
                    ++index;
                    ++end;
                }
                offset3 += text.Length;
            }
            return((ITextRange) new TextRange(offset2, end));
        }
Esempio n. 3
0
        private static string GetTrailingWhitespace(IReadableTextBuffer textBuffer, int offset)
        {
            if (textBuffer.Length == 0)
            {
                return(string.Empty);
            }
            ITextRange textRange = TextBufferHelper.ExpandSpanToFillWhitespace(textBuffer, (ITextRange) new TextRange(offset, offset), false, true);

            return(textBuffer.GetText(textRange.Offset, textRange.Length));
        }
Esempio n. 4
0
        private static string GetTrailingWhitespace(XamlSourceContext sourceContext)
        {
            IReadableTextBuffer textBuffer = (IReadableTextBuffer)TextBufferHelper.GetHostBuffer(sourceContext.TextBuffer);

            if (textBuffer.Length == 0)
            {
                return(string.Empty);
            }
            return(XamlFormatter.GetTrailingWhitespace(textBuffer, sourceContext.TextRange.Offset + sourceContext.TextRange.Length));
        }
Esempio n. 5
0
 private bool FindInFile(IProjectItem projectItem, FindInFilesDialog.ProcessResult callback, FindInFilesResult previousResult)
 {
     if (!this.IsTargetExtension(projectItem.DocumentType.DefaultFileExtension))
     {
         return(false);
     }
     try
     {
         if (Microsoft.Expression.Framework.Documents.PathHelper.FileExists(projectItem.DocumentReference.Path))
         {
             if (!projectItem.IsDirty)
             {
                 using (TextReader textReader = (TextReader) new StreamReader((Stream) new FileStream(projectItem.DocumentReference.Path, FileMode.Open, FileAccess.Read)))
                 {
                     if (!this.SearchText(projectItem, textReader, callback, previousResult))
                     {
                         return(false);
                     }
                 }
             }
             else
             {
                 string s = (string)null;
                 IReadableTextBuffer readableTextBuffer = projectItem.Document as IReadableTextBuffer;
                 if (readableTextBuffer != null)
                 {
                     s = readableTextBuffer.GetText(0, readableTextBuffer.Length);
                 }
                 else
                 {
                     CodeDocument codeDocument = projectItem.Document as CodeDocument;
                     if (codeDocument != null)
                     {
                         s = codeDocument.Document != null ? codeDocument.Document.Text : string.Empty;
                     }
                 }
                 if (s != null)
                 {
                     using (TextReader textReader = (TextReader) new StringReader(s))
                     {
                         if (!this.SearchText(projectItem, textReader, callback, previousResult))
                         {
                             return(false);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
     }
     return(true);
 }
Esempio n. 6
0
        private string GetDocumentText(IProjectItem projectItem)
        {
            string str  = (string)null;
            bool   flag = false;

            if (projectItem.Document == null)
            {
                flag = projectItem.OpenDocument(false, true);
            }
            if (projectItem.Document != null)
            {
                IReadableTextBuffer readableTextBuffer = projectItem.Document as IReadableTextBuffer;
                str = readableTextBuffer.GetText(0, readableTextBuffer.Length);
            }
            if (flag)
            {
                projectItem.CloseDocument();
            }
            return(str);
        }
Esempio n. 7
0
 public static ITextRange ExpandSpanLeftToFillWhitespace(IReadableTextBuffer textBuffer, ITextRange span)
 {
     return(TextBufferHelper.ExpandSpanToFillWhitespace(textBuffer, span, true, false));
 }