Exemple #1
0
        public void AddPaddingIntOffset()
        {
            int            initialOffset = 0;
            DocumentEditor editor        = new DocumentEditor();
            TextBuffer     buffer        = editor.Buffer;

            int nextOffset = DocumentUtils.AddPadding(buffer, initialOffset, "#0");

            Assert.AreEqual(1, nextOffset, "APIO");
        }
Exemple #2
0
        public void AddPaddingVoidOffset()
        {
            DocumentEditor editor = new DocumentEditor();
            TextBuffer     buffer = editor.Buffer;

            TextIter insertIter = buffer.StartIter;

            DocumentUtils.AddPadding(buffer, ref insertIter, "#0");

            Assert.AreEqual(1, insertIter.Offset, "APVO");
        }
Exemple #3
0
        public void AddPaddingVoidValidRegion()
        {
            DocumentEditor editor = new DocumentEditor();
            TextBuffer     buffer = editor.Buffer;

            TextIter insertIter = buffer.StartIter;

            DocumentUtils.AddPadding(buffer, ref insertIter, "#0");

            TextTag expectedTag   = buffer.TagTable.Lookup("padding#0");
            bool    beginsPadding = buffer.StartIter.BeginsTag(expectedTag);
            bool    endsPadding   = DocumentUtils.TagEndsHere(expectedTag, buffer.GetIterAtOffset(insertIter.Offset - 1), insertIter);

            Assert.IsTrue(beginsPadding, "APVR01");
            Assert.IsTrue(endsPadding, "APVR02");
        }
Exemple #4
0
        public void AddPaddingIntValidRegion()
        {
            int            initialOffset, endOffset, nextOffset;
            DocumentEditor editor = new DocumentEditor();
            TextBuffer     buffer = editor.Buffer;

            initialOffset = 0;
            nextOffset    = DocumentUtils.AddPadding(buffer, initialOffset, "#0");
            endOffset     = nextOffset - 1;

            TextTag expectedTag   = buffer.TagTable.Lookup("padding#0");
            bool    beginsPadding = buffer.GetIterAtOffset(initialOffset).BeginsTag(expectedTag);
            bool    endsPadding   = DocumentUtils.TagEndsHere(expectedTag, buffer.GetIterAtOffset(endOffset), buffer.GetIterAtOffset(nextOffset));

            Assert.IsTrue(beginsPadding, "APIVR01");
            Assert.IsTrue(endsPadding, "APIVR02");
        }
Exemple #5
0
        private static int InsertEndElement(TextBuffer buffer, int offset, Stack stack, ref int depth)
        {
            TextIter insertAt, applyStart, applyEnd;
            TagStart tagStart = (TagStart)stack.Pop();
            string   suffix   = '#' + depth.ToString();

                #if DEBUG
            Console.WriteLine("Element: {0}, End: {1}", tagStart.Tag.Name, offset);
                #endif

            if (((DocumentTag)tagStart.Tag).IsEditable)
            {
                if (tagStart.Start + 1 == offset)
                {
                    offset = DocumentUtils.AddStub(buffer, offset, "To be added test", suffix);
                }

                insertAt = buffer.GetIterAtOffset(offset);
                buffer.Insert(ref insertAt, "]");
                offset += 1;
            }
            else if (tagStart.Start == offset)
            {
                offset = DocumentUtils.AddPaddingEmpty(buffer, offset, suffix);
            }

            applyStart = buffer.GetIterAtOffset(tagStart.Start);
            applyEnd   = buffer.GetIterAtOffset(offset);
            buffer.ApplyTag(tagStart.Tag, applyStart, applyEnd);
            offset = FormatEnd(buffer, offset, suffix, tagStart.Name);
            depth--;

                #if DEBUG
            Console.WriteLine("Applied: {0}, Start: {1}, End: {2}", tagStart.Tag.Name, tagStart.Start, offset);
                #endif

            // Padding between tag regions
            suffix = "#" + depth;
            offset = DocumentUtils.AddPadding(buffer, offset, suffix);

            return(offset);
        }
Exemple #6
0
        private static int InsertStartElement(TextBuffer buffer, int offset, XmlTextReader xmlReader, Stack stack, ref int depth, ref int count)
        {
            string           elementName = xmlReader.Name;
            string           suffix = String.Empty;
            DocumentTagTable tagTable = (DocumentTagTable)buffer.TagTable;
            bool             emptyElement = xmlReader.IsEmptyElement;
            bool             isDynamic = DocumentTagTable.IsDynamic(elementName);
            TextIter         insertAt, applyStart, applyEnd;

            depth++;

            // We define a suffix so each dynamic tag has an unique name.
            // Suffix has format: #{depth level}
            if (isDynamic)
            {
                suffix = "#" + depth;
            }

            // We add any needed string to give format to the document.
            offset = FormatStart(buffer, offset, suffix, elementName);

            TagStart tagStart = new TagStart();

            tagStart.Start = offset;
            tagStart.Name  = elementName;

            // We first lookup the tag name, if the element is dynamic, we can
            // have three scenarios.
            // 1) The tag is not in the table: So we create it in the spot.
            // 2) Tag is in table but it priority is wrong: We created a new
            // dynamic tag with an extra suffix. Format #{depth level}.{count}
            // 3) Tag is in table with right priority: We reuse it and we don't
            // create a new dymamic tag.
            tagStart.Tag = tagTable.Lookup(elementName + suffix);
            if (isDynamic && tagStart.Tag == null)
            {
                tagStart.Tag = tagTable.CreateDynamicTag(elementName + suffix);
            }
            else if (isDynamic && tagStart.Tag != null && tagStart.Tag.Priority < ((TagStart)stack.Peek()).Tag.Priority)
            {
                suffix      += "." + count;
                tagStart.Tag = tagTable.CreateDynamicTag(elementName + suffix);
                count++;
            }

                #if DEBUG
            try {
                Console.WriteLine("Element: {0} Start: {1}", tagStart.Tag.Name, tagStart.Start);
            } catch (NullReferenceException) {
                Console.WriteLine("Error: Missing {0} element", xmlReader.Name);
                Environment.Exit(1);
            }
                #endif

            // If element has attributes we have to get them and deserialize them.
            if (xmlReader.HasAttributes)
            {
                offset = DeserializeAttributes(buffer, offset, xmlReader, suffix);
            }

            // Special case when an elment is empty.
            // Case A: If element is editable a string stub is inserted to allow edition.
            // Case B: If element is not editable then a padding is inserted to handle
            // TextTag behaviour in which zero length ranges are lost.
            if (emptyElement)
            {
                if (((DocumentTag)tagStart.Tag).IsEditable)
                {
                    insertAt = buffer.GetIterAtOffset(offset);
                    buffer.Insert(ref insertAt, "[");
                    offset += 1;

                    offset = DocumentUtils.AddStub(buffer, offset, "Click to Add Documentation", suffix);

                    insertAt = buffer.GetIterAtOffset(offset);
                    buffer.Insert(ref insertAt, "]");
                    offset += 1;
                }
                else
                {
                    offset = DocumentUtils.AddPaddingEmpty(buffer, offset, suffix);
                }

                applyStart = buffer.GetIterAtOffset(tagStart.Start);
                applyEnd   = buffer.GetIterAtOffset(offset);
                buffer.ApplyTag(tagStart.Tag, applyStart, applyEnd);
                offset = FormatEnd(buffer, offset, suffix, elementName);

                // Padding between tag regions
                offset = DocumentUtils.AddPadding(buffer, offset, suffix);
                depth--;

                        #if DEBUG
                Console.WriteLine("Empty Element: {0}, Start: {1}, End: {2}", tagStart.Tag.Name, tagStart.Start, offset);
                        #endif
            }
            else
            {
                stack.Push(tagStart);

                if (((DocumentTag)tagStart.Tag).IsEditable)
                {
                    insertAt = buffer.GetIterAtOffset(offset);
                    buffer.Insert(ref insertAt, "[");
                    offset += 1;
                }
            }

            return(offset);
        }