public void OffsetSourceContext(int start)
        {
            XamlSourceContext xamlSourceContext = this.SourceContext;

            if (xamlSourceContext == null)
            {
                if (this.documentNode == null)
                {
                    return;
                }
                xamlSourceContext = this.documentNode.ContainerSourceContext as XamlSourceContext;
            }
            if (xamlSourceContext == null)
            {
                return;
            }
            if (this.documentNode != null)
            {
                this.OffsetSourceContext(this.documentNode, start - xamlSourceContext.TextRange.Offset);
            }
            else
            {
                this.OffsetSourceContext((INodeSourceContext)xamlSourceContext, start - xamlSourceContext.TextRange.Offset);
            }
        }
 internal Attribute(XmlElementReference.AttributeType type, XmlAttribute attribute, XamlSourceContext sourceContext)
 {
     this.type                    = type;
     this.sourceContext           = sourceContext;
     this.attribute               = new XmlAttribute(XmlElementReference.Attribute.CloneIdentifier(attribute.Name));
     this.attribute.SourceContext = XmlElementReference.Attribute.CloneSourceContext(attribute.SourceContext);
     this.attribute.AddChild((Microsoft.Expression.DesignModel.Markup.Xml.Node) new Literal(attribute.Value.Value, XmlElementReference.Attribute.CloneSourceContext(attribute.Value.SourceContext)));
 }
 internal XmlElementReference(XmlContainerReference parent, SourceContext sourceContext, SourceContext startTagContext, bool beginTracking)
     : base(parent, parent.TextBuffer, sourceContext, beginTracking)
 {
     if (beginTracking && startTagContext.EndCol > startTagContext.StartCol)
     {
         this.startTagRange = XamlSourceContext.ToTextRange(this.TextBuffer, startTagContext);
     }
     this.xmlSpace = parent.XmlSpace;
 }
 protected XamlSourceContext(XmlContainerReference parent, IReadableSelectableTextBuffer textBuffer, SourceContext sourceContext, bool beginTracking)
 {
     this.parent = parent;
     if (!beginTracking)
     {
         return;
     }
     this.textRange = XamlSourceContext.ToTextRange(textBuffer, sourceContext);
     this.ordering  = sourceContext.StartCol;
 }
 internal virtual void CloneCopy(XamlSourceContext other, bool keepOldRanges)
 {
     other.InitialTextSpan = this.InitialTextSpan;
     other.ordering        = this.ordering;
     if (!keepOldRanges)
     {
         return;
     }
     other.TextRange = this.TextRange;
 }
Beispiel #6
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));
        }
Beispiel #7
0
        private XamlFormatter.UnprocessedNodeFormatting GetNodeFormatting(UnprocessedNode unprocessedNode)
        {
            XamlFormatter.UnprocessedNodeFormatting unprocessedNodeFormatting = new XamlFormatter.UnprocessedNodeFormatting();
            XamlSourceContext sourceContext = unprocessedNode.SourceContextReference.SourceContext;

            if (sourceContext != null && sourceContext.TextRange != null)
            {
                unprocessedNodeFormatting.LeadingWhitespace  = XamlFormatter.GetLeadingWhitespace(sourceContext);
                unprocessedNodeFormatting.TrailingWhitespace = XamlFormatter.GetTrailingWhitespace(sourceContext);
            }
            return(unprocessedNodeFormatting);
        }
        public string GetIndent(string childIndent)
        {
            if (this.documentNode == null)
            {
                return(string.Empty);
            }
            DocumentCompositeNode parent = this.documentNode.Parent;

            if (parent == null)
            {
                return(string.Empty);
            }
            XamlSourceContext xamlSourceContext = (XamlSourceContext)null;

            if (this.documentNode.IsChild)
            {
                for (int index = this.documentNode.SiteChildIndex - 1; index >= 0; --index)
                {
                    xamlSourceContext = parent.Children[index].SourceContext as XamlSourceContext;
                    if (xamlSourceContext != null && xamlSourceContext.TextRange != null)
                    {
                        break;
                    }
                }
            }
            bool flag = false;

            while (parent != null && (xamlSourceContext == null || xamlSourceContext.TextRange == null))
            {
                xamlSourceContext = parent.SourceContext as XamlSourceContext ?? parent.ContainerSourceContext as XamlSourceContext;
                parent            = parent.Parent;
                flag = true;
            }
            if (xamlSourceContext == null)
            {
                return(string.Empty);
            }
            IReadableSelectableTextBuffer hostBuffer = TextBufferHelper.GetHostBuffer(xamlSourceContext.TextBuffer);
            ITextRange textRange = TextBufferHelper.ExpandSpanLeftToFillWhitespace((IReadableTextBuffer)hostBuffer, (ITextRange) new TextRange(xamlSourceContext.TextRange.Offset, xamlSourceContext.TextRange.Offset));
            string     str       = hostBuffer.GetText(textRange.Offset, textRange.Length);
            int        num       = str.LastIndexOf('\n');

            if (num != -1)
            {
                str = str.Substring(num + 1);
            }
            if (flag)
            {
                str += childIndent;
            }
            return(str);
        }
        internal override void CloneCopy(XamlSourceContext other, bool keepOldRanges)
        {
            XmlContainerReference containerReference = (XmlContainerReference)other;

            if (this.ChildNodesToPreserveCount > 0)
            {
                foreach (XmlContainerReference.ChildNode childNode in this.ChildNodesToPreserve)
                {
                    containerReference.AddChildNode(childNode);
                }
            }
            base.CloneCopy(other, keepOldRanges);
        }
        internal override void CloneCopy(XamlSourceContext other, bool keepOldRanges)
        {
            base.CloneCopy(other, keepOldRanges);
            XmlElementReference elementReference = (XmlElementReference)other;

            elementReference.comment = this.Comment == null ? (XmlContainerReference.ChildNode)null : new XmlContainerReference.ChildNode(this.Comment);
            elementReference.attributesToPreserve = this.attributesToPreserve == null ? (IList <XmlElementReference.Attribute>)null : (IList <XmlElementReference.Attribute>) new List <XmlElementReference.Attribute>((IEnumerable <XmlElementReference.Attribute>) this.attributesToPreserve);
            elementReference.ignorableNamespaces  = this.ignorableNamespaces == null ? (IList <XmlNamespace>)null : (IList <XmlNamespace>) new List <XmlNamespace>((IEnumerable <XmlNamespace>) this.ignorableNamespaces);
            elementReference.xmlSpace             = this.xmlSpace;
            elementReference.initialStartTagSpan  = this.initialStartTagSpan;
            if (!keepOldRanges)
            {
                return;
            }
            elementReference.startTagRange = this.startTagRange;
        }
Beispiel #11
0
        private static void ClearSourceContextInitialRange(INodeSourceContext sourceContext)
        {
            XamlSourceContext xamlSourceContext = sourceContext as XamlSourceContext;

            if (xamlSourceContext == null)
            {
                return;
            }
            xamlSourceContext.InitialTextSpan = TextRange.Null;
            XmlElementReference elementReference = xamlSourceContext as XmlElementReference;

            if (elementReference == null)
            {
                return;
            }
            elementReference.InitialStartTagSpan = TextRange.Null;
        }
Beispiel #12
0
        private static ITextRange CaculateTextRange(XamlSourceContext sourceContext, ITextBuffer textBuffer)
        {
            ITextRange        textRange        = sourceContext.TextRange;
            IMappingTextRange mappingTextRange = textRange as IMappingTextRange;

            if (mappingTextRange != null)
            {
                textRange = mappingTextRange.GetRangeForBuffer(textBuffer);
            }
            else if (TextBufferHelper.GetHostBuffer(sourceContext.TextBuffer) != TextBufferHelper.GetHostBuffer((IReadableSelectableTextBuffer)textBuffer))
            {
                return(TextRange.Null);
            }
            int offset = textRange.Offset;

            return((ITextRange) new TextRange(offset, offset + textRange.Length));
        }
        private void OffsetSourceContext(INodeSourceContext context, int offset)
        {
            XamlSourceContext xamlSourceContext = context as XamlSourceContext;

            if (xamlSourceContext == null || xamlSourceContext.TextRange == null)
            {
                return;
            }
            int start = xamlSourceContext.TextRange.Offset + offset;

            xamlSourceContext.InitialTextSpan = (ITextRange) new TextRange(start, start + xamlSourceContext.TextRange.Length);
            XmlElementReference elementReference = xamlSourceContext as XmlElementReference;

            if (elementReference == null || elementReference.StartTagRange == null)
            {
                return;
            }
            elementReference.InitialStartTagSpan = (ITextRange) new TextRange(start, elementReference.StartTagRange.Length);
        }
Beispiel #14
0
        private static void UpdateSourceContextRangeFromInitialRange(IReadableSelectableTextBuffer textBuffer, INodeSourceContext context, int offset)
        {
            XamlSourceContext xamlSourceContext = context as XamlSourceContext;

            if (xamlSourceContext == null)
            {
                return;
            }
            if (!TextRange.IsNull(xamlSourceContext.InitialTextSpan))
            {
                ITextRange initialTextSpan = xamlSourceContext.InitialTextSpan;
                ITextRange textRange1      = (ITextRange) new TextRange(initialTextSpan.Offset + offset, initialTextSpan.Offset + initialTextSpan.Length + offset);
                xamlSourceContext.InitialTextSpan = textRange1;
                xamlSourceContext.SetTextRange(textBuffer, textRange1.Offset, textRange1.Length);
                XmlElementReference elementReference = xamlSourceContext as XmlElementReference;
                if (elementReference == null)
                {
                    return;
                }
                foreach (XmlElementReference.Attribute attribute in elementReference.AttributesToPreserve)
                {
                    XamlSerializerUtilities.UpdateSourceContextRangeFromInitialRange(textBuffer, (INodeSourceContext)attribute.SourceContext, offset);
                }
                if (TextRange.IsNull(elementReference.InitialStartTagSpan))
                {
                    return;
                }
                ITextRange initialStartTagSpan = elementReference.InitialStartTagSpan;
                ITextRange textRange2          = (ITextRange) new TextRange(initialStartTagSpan.Offset + offset, initialStartTagSpan.Offset + initialStartTagSpan.Length + offset);
                elementReference.InitialStartTagSpan = textRange2;
                elementReference.StartTagRange       = textBuffer.CreateRange(textRange2.Offset, textRange2.Length);
            }
            else
            {
                xamlSourceContext.ClearTextRange();
                XmlElementReference elementReference = xamlSourceContext as XmlElementReference;
                if (elementReference == null)
                {
                    return;
                }
                elementReference.StartTagRange = (ITextRange)null;
            }
        }
Beispiel #15
0
        private static void RefreshSiblingOrdering(DocumentNode node)
        {
            IDocumentRoot documentRoot = node.DocumentRoot;

            if (documentRoot == null || node.Parent == null)
            {
                return;
            }
            foreach (KeyValuePair <IProperty, DocumentNode> keyValuePair in (IEnumerable <KeyValuePair <IProperty, DocumentNode> >)node.Parent.Properties)
            {
                if (node != keyValuePair.Value)
                {
                    XamlSourceContext xamlSourceContext1 = keyValuePair.Value.ContainerSourceContext as XamlSourceContext;
                    if (xamlSourceContext1 != null)
                    {
                        XamlSourceContext xamlSourceContext2 = (XamlSourceContext)xamlSourceContext1.Clone(true);
                        xamlSourceContext2.RefreshOrdering();
                        documentRoot.SetContainerSourceContext(keyValuePair.Value, (INodeSourceContext)xamlSourceContext2);
                    }
                }
            }
        }
Beispiel #16
0
        internal static ITextRange GetNodeSpan(ITextBuffer textBuffer, DocumentNode node, bool includeContainer, DocumentNode skipSelf)
        {
            if (textBuffer == null)
            {
                throw new ArgumentNullException("textBuffer");
            }
            ITextRange range = TextRange.Null;

            if (node == skipSelf)
            {
                return(range);
            }
            XamlSourceContext sourceContext1 = node.SourceContext as XamlSourceContext;

            if (sourceContext1 != null && !sourceContext1.IsCloned && sourceContext1.TextRange != null)
            {
                ITextRange other = XamlSerializerUtilities.CaculateTextRange(sourceContext1, textBuffer);
                range = TextRange.Union(range, other);
            }
            XamlSourceContext sourceContext2 = node.ContainerSourceContext as XamlSourceContext;

            if (sourceContext2 != null && !sourceContext2.IsCloned && sourceContext2.TextRange != null && (includeContainer || sourceContext2 is XmlAttributeReference))
            {
                ITextRange other = XamlSerializerUtilities.CaculateTextRange(sourceContext2, textBuffer);
                range = TextRange.Union(range, other);
            }
            if (!TextRange.IsNull(range))
            {
                return(range);
            }
            foreach (DocumentNode node1 in node.ChildNodes)
            {
                range = TextRange.Union(range, XamlSerializerUtilities.GetNodeSpan(textBuffer, node1, true, skipSelf));
            }
            return(range);
        }
Beispiel #17
0
 public UnprocessedNodeSourceContextReference(XamlSourceContext sourceContext)
     : base((DocumentNode)null)
 {
     this.sourceContext = sourceContext;
 }
 public ChildNode(XmlContainerReference.ChildType type, XmlContainerReference parent, Microsoft.Expression.DesignModel.Markup.Xml.Node node)
 {
     this.type          = type;
     this.sourceContext = (XamlSourceContext) new UnprocessedNodeReference(parent, node.SourceContext);
     this.text          = node.SourceContext.SourceText;
 }