Exemple #1
0
 public XmlEditorView(XmlEditorViewContent viewContent)
 {
     this.viewContent = viewContent;
     InitSyntaxHighlighting();
     xpathNodeTextMarker = new XPathNodeTextMarker(buffer);
     Buffer.Changed     += BufferChanged;
 }
        public void NamespaceQuery()
        {
            string xml =
                "<?xml version='1.0'?>\r\n" +
                "<Xml1></Xml1>";
            XPathQuery query = new XPathQuery(xml);

            XPathNodeMatch[] nodes = query.FindNodes("//namespace::*");

            ServiceContainer container = new ServiceContainer();

            container.AddService(typeof(MockTextMarkerService), new MockTextMarkerService());

            AvalonEditDocumentAdapter doc = new AvalonEditDocumentAdapter(new ICSharpCode.AvalonEdit.Document.TextDocument(), container);

            doc.Text = xml;
            XPathNodeTextMarker xpathNodeMarker = new XPathNodeTextMarker(doc);

            xpathNodeMarker.AddMarkers(nodes);

            ITextMarkerService service = doc.GetService(typeof(MockTextMarkerService)) as ITextMarkerService;
            List <ITextMarker> markers = new List <ITextMarker>(service.TextMarkers);

            Assert.AreEqual(0, markers.Count);
            Assert.AreEqual(1, nodes.Length);
        }
        public void EmptyCommentNode()
        {
            string     xml   = "<!----><root/>";
            XPathQuery query = new XPathQuery(xml);

            XPathNodeMatch[] nodes = query.FindNodes("//comment()");

            ServiceContainer container = new ServiceContainer();

            container.AddService(typeof(MockTextMarkerService), new MockTextMarkerService());

            IDocument doc = new ICSharpCode.AvalonEdit.Document.TextDocument()
            {
                ServiceProvider = container
            };

            doc.Text = xml;
            XPathNodeTextMarker xpathNodeMarker = new XPathNodeTextMarker(doc);

            xpathNodeMarker.AddMarkers(nodes);

            ITextMarkerService service = doc.GetService(typeof(MockTextMarkerService)) as ITextMarkerService;
            List <ITextMarker> markers = new List <ITextMarker>(service.TextMarkers);

            Assert.AreEqual(0, markers.Count);
            Assert.AreEqual(1, nodes.Length);
        }
Exemple #4
0
		public XmlEditorView (XmlEditorViewContent viewContent)
		{
			this.viewContent = viewContent;
			InitSyntaxHighlighting();
			xpathNodeTextMarker = new XPathNodeTextMarker(buffer);
			Buffer.Changed += BufferChanged;
		}
        public void Init()
        {
            ServiceContainer container = new ServiceContainer();

            markerService = new MockTextMarkerService();
            container.AddService(typeof(ITextMarkerService), markerService);

            // Add xpath marker to document.
            AvalonEditDocumentAdapter doc = new AvalonEditDocumentAdapter(new ICSharpCode.AvalonEdit.Document.TextDocument(), container);

            doc.Text = "<Test/>";
            XPathNodeTextMarker xpathNodeMarker = new XPathNodeTextMarker(doc);
            XPathNodeMatch      nodeMatch       = new XPathNodeMatch("Test", "<Test/>", 0, 1, XPathNodeType.Element);

            xpathNodeMarker.AddMarker(nodeMatch);

            // Add non text editor provider view to workbench.
            workbench = new MockWorkbench();

            nonTextEditorProviderView = new MockViewContent();
            workbench.ViewContentCollection.Add(nonTextEditorProviderView);

            // Add document to view content.
            textEditorView = new MockTextEditorProviderViewContent();
            textEditorView.MockTextEditor.SetDocument(doc);
            workbench.ViewContentCollection.Add(textEditorView);

            command = new RemoveXPathHighlightingCommand(workbench);
        }
Exemple #6
0
        public void Init()
        {
            IDocument doc = MockTextMarkerService.CreateDocumentWithMockService();

            markerService = doc.GetRequiredService <ITextMarkerService>();

            // Add xpath marker to document.
            doc.Text = "<Test/>";
            XPathNodeTextMarker xpathNodeMarker = new XPathNodeTextMarker(doc);
            XPathNodeMatch      nodeMatch       = new XPathNodeMatch("Test", "<Test/>", 0, 1, XPathNodeType.Element);

            xpathNodeMarker.AddMarker(nodeMatch);

            // Add non text editor provider view to workbench.
            workbench = MockRepository.GenerateStrictMock <IWorkbench>();
            workbench.Stub(w => w.ViewContentCollection).Return(new List <IViewContent>());

            nonTextEditorProviderView = new MockViewContent();
            workbench.ViewContentCollection.Add(nonTextEditorProviderView);

            // Add document to view content.
            textEditorView = new MockTextEditorProviderViewContent();
            textEditorView.MockTextEditor.SetDocument(doc);
            workbench.ViewContentCollection.Add(textEditorView);

            command = new RemoveXPathHighlightingCommand(workbench);
        }
        public void OneNodeMarked()
        {
            string xml = "<root><foo/></root>";

            XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//root");

            IDocument doc = MockDocument.Create();

            doc.TextContent = xml;
            MarkerStrategy markerStrategy = new MarkerStrategy(doc);

            XPathNodeTextMarker.AddMarkers(markerStrategy, nodes);

            List <TextMarker> markers = new List <TextMarker>();

            foreach (TextMarker marker in markerStrategy.TextMarker)
            {
                markers.Add(marker);
            }

            // Remove markers.
            XPathNodeTextMarker.RemoveMarkers(markerStrategy);
            List <TextMarker> markersAfterRemove = new List <TextMarker>();

            foreach (TextMarker markerAfterRemove in markerStrategy.TextMarker)
            {
                markers.Add(markerAfterRemove);
            }

            XPathNodeTextMarker xpathNodeTextMarker = (XPathNodeTextMarker)markers[0];

            Assert.AreEqual(1, markers.Count);
            Assert.AreEqual(1, xpathNodeTextMarker.Offset);
            Assert.AreEqual(4, xpathNodeTextMarker.Length);
            Assert.AreEqual(TextMarkerType.SolidBlock, xpathNodeTextMarker.TextMarkerType);
            Assert.AreEqual(0, markersAfterRemove.Count);
            Assert.AreEqual(XPathNodeTextMarker.MarkerBackColor, xpathNodeTextMarker.Color);
        }
        public void NamespaceQuery()
        {
            string xml = "<?xml version='1.0'?>\r\n" +
                         "<Xml1></Xml1>";

            XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//namespace::*");

            IDocument doc = MockDocument.Create();

            doc.TextContent = xml;
            MarkerStrategy markerStrategy = new MarkerStrategy(doc);

            XPathNodeTextMarker.AddMarkers(markerStrategy, nodes);

            List <TextMarker> markers = new List <TextMarker>();

            foreach (TextMarker marker in markerStrategy.TextMarker)
            {
                markers.Add(marker);
            }
            Assert.AreEqual(0, markers.Count);
            Assert.AreEqual(1, nodes.Length);
        }
        public void EmptyCommentNode()
        {
            string xml = "<!----><root/>";

            XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//comment()");

            IDocument doc = MockDocument.Create();

            doc.TextContent = xml;
            MarkerStrategy markerStrategy = new MarkerStrategy(doc);

            XPathNodeTextMarker.AddMarkers(markerStrategy, nodes);

            List <TextMarker> markers = new List <TextMarker>();

            foreach (TextMarker marker in markerStrategy.TextMarker)
            {
                markers.Add(marker);
            }

            Assert.AreEqual(0, markers.Count);
            Assert.AreEqual(1, nodes.Length);
        }
        public void Init()
        {
            string     xml   = "<root><foo/></root>";
            XPathQuery query = new XPathQuery(xml);

            XPathNodeMatch[] nodes = query.FindNodes("//root");

            IDocument doc = MockTextMarkerService.CreateDocumentWithMockService();

            doc.Text = xml;
            XPathNodeTextMarker xpathNodeMarker = new XPathNodeTextMarker(doc);

            xpathNodeMarker.AddMarkers(nodes);

            ITextMarkerService service = doc.GetService(typeof(ITextMarkerService)) as ITextMarkerService;

            markers = new List <ITextMarker>(service.TextMarkers);

            // Remove markers.
            xpathNodeMarker.RemoveMarkers();
            markersAfterRemove = new List <ITextMarker>(service.TextMarkers);

            xpathNodeTextMarker = markers[0];
        }