public MockTextEditor()
 {
     documentAdapter   = new AvalonEditDocumentAdapter(textDocument, null);
     textArea          = new TextArea();
     textArea.Document = textDocument;
     selection         = Selection.Create(textArea, -1, -1);
 }
        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);
        }
Example #3
0
        public void SetUpFixture()
        {
            AvalonEdit.TextEditor textEditor = new AvalonEdit.TextEditor();
            document        = textEditor.Document;
            textEditor.Text = GetTextEditorCode();

            RubyParser       parser          = new RubyParser();
            ICompilationUnit compilationUnit = parser.Parse(new DefaultProjectContent(), @"test.py", document.Text);

            using (DesignSurface designSurface = new DesignSurface(typeof(UserControl))) {
                IDesignerHost host        = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                UserControl   userControl = (UserControl)host.RootComponent;
                userControl.ClientSize = new Size(489, 389);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(userControl);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(userControl, "userControl1");

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    AvalonEditDocumentAdapter docAdapter = new AvalonEditDocumentAdapter(document, null);
                    RubyDesignerGenerator     generator  = new RubyDesignerGenerator(new MockTextEditorOptions());
                    generator.Merge(host, docAdapter, compilationUnit, serializationManager);
                }
            }
        }
        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);
        }
        public void SetUpFixture()
        {
            resourceWriter  = new MockResourceWriter();
            resourceService = new MockResourceService();
            resourceService.SetResourceWriter(resourceWriter);

            AvalonEdit.TextEditor textEditor = new AvalonEdit.TextEditor();
            document        = textEditor.Document;
            textEditor.Text = GetTextEditorCode();

            PythonParser     parser          = new PythonParser();
            ICompilationUnit compilationUnit = parser.Parse(new DefaultProjectContent(), @"test.py", document.Text);

            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                Form          form = (Form)host.RootComponent;
                form.ClientSize = new Size(499, 309);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    AvalonEditDocumentAdapter adapter   = new AvalonEditDocumentAdapter(document, null);
                    MockTextEditorOptions     options   = new MockTextEditorOptions();
                    PythonDesignerGenerator   generator = new PythonDesignerGenerator(options);
                    generator.Merge(host, adapter, compilationUnit, serializationManager);
                }
            }
        }
        /// <summary>
        /// Resolves a resource reference.
        /// Line and column are 0-based.
        /// </summary>
        protected ResourceResolveResult Resolve(string fileName, string code, int caretLine, int caretColumn, char?charTyped, bool parseFile)
        {
            this.EnlistTestFile(fileName, code, parseFile);
            IDocument doc = new AvalonEditDocumentAdapter();

            doc.Text = code;
            return(ResourceResolverService.Resolve(fileName, doc, caretLine, caretColumn, charTyped));
        }
 void OnDocumentChanged()
 {
     if (textEditor.Document != null)
     {
         document = new AvalonEditDocumentAdapter(textEditor.Document, this);
     }
     else
     {
         document = null;
     }
 }
Example #8
0
        public void Init()
        {
            formattingStrategy = new XmlFormattingStrategy();

            options            = new MockTextEditorOptions();
            textEditor         = new MockTextEditor();
            textEditor.Options = options;

            textDocument = new TextDocument();
            document     = new AvalonEditDocumentAdapter(textDocument, null);
            textEditor.SetDocument(document);
        }
        public void SetUpFixture()
        {
            AvalonEdit.TextEditor textEditor = new AvalonEdit.TextEditor();
            document        = textEditor.Document;
            textEditor.Text = GetTextEditorCode();

            RubyParser         parser         = new RubyParser();
            MockProjectContent projectContent = new MockProjectContent();
            MockProject        project        = new MockProject();

            project.RootNamespace  = "RootNamespace";
            projectContent.Project = project;
            ICompilationUnit compilationUnit = parser.Parse(projectContent, @"test.py", document.Text);

            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                // Add picture box
                PictureBox pictureBox = (PictureBox)host.CreateComponent(typeof(PictureBox), "pictureBox1");
                pictureBox.Location = new Point(0, 0);
                pictureBox.Image    = new Bitmap(10, 10);
                pictureBox.Size     = new Size(100, 120);
                pictureBox.TabIndex = 0;
                form.Controls.Add(pictureBox);

                MockTextEditorOptions options = new MockTextEditorOptions();
                options.ConvertTabsToSpaces = true;
                options.IndentationSize     = 4;

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    AvalonEditDocumentAdapter docAdapter = new AvalonEditDocumentAdapter(document, null);
                    RubyDesignerGenerator     generator  = new RubyDesignerGenerator(options);
                    generator.Merge(host, docAdapter, compilationUnit, serializationManager);
                }
            }
        }
        public void Init()
        {
            formattingStrategy = new XmlFormattingStrategy();

            options            = new MockTextEditorOptions();
            textEditor         = new MockTextEditor();
            textEditor.Options = options;

            textDocument = new TextDocument();
            document     = new AvalonEditDocumentAdapter(textDocument, null);
            textEditor.SetDocument(document);

            document.Text =
                "<root>\r\n" +
                "\t<child>\r\n" +
                "</root>\r\n";

            // Just typed the '>' character of the <child> element
            textEditor.Caret.Offset = 16;
            formattingStrategy.FormatLine(textEditor, '>');
        }
Example #11
0
        public void Init()
        {
            formattingStrategy = new XmlFormattingStrategy();

            options            = new MockTextEditorOptions();
            textEditor         = new MockTextEditor();
            textEditor.Options = options;

            textDocument = new TextDocument();
            document     = new AvalonEditDocumentAdapter(textDocument, null);
            textEditor.SetDocument(document);

            document.Text =
                "<root>\r\n" +
                "\t<child>\r\n" +
                "</child>\r\n" +
                "</root>\r\n";

            docLine            = new MockDocumentLine();
            docLine.LineNumber = 3;
            formattingStrategy.IndentLine(textEditor, docLine);
        }
        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());

            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);
        }
Example #13
0
        public void Init()
        {
            formattingStrategy = new XmlFormattingStrategy();

            options            = new MockTextEditorOptions();
            textEditor         = new MockTextEditor();
            textEditor.Options = options;

            textDocument = new TextDocument();
            document     = new AvalonEditDocumentAdapter(textDocument, null);
            textEditor.SetDocument(document);

            textDocument.Text =
                "<root>\r\n" +
                "\t<child></child>\r\n" +
                "</root>";

            int selectionStart  = 9;
            int selectionLength = 15;

            textEditor.Select(selectionStart, selectionLength);

            formattingStrategy.SurroundSelectionWithComment(textEditor);
        }
 public void Init()
 {
     document = new AvalonEditDocumentAdapter();
 }
Example #15
0
 public MockXmlViewContent(OpenedFile file)
 {
     this.file = file;
     this.Files.Add(file);
     this.document = new AvalonEditDocumentAdapter();
 }
Example #16
0
        void TextEditorMouseHover(object sender, MouseEventArgs e)
        {
            ToolTipRequestEventArgs args = new ToolTipRequestEventArgs(this.adapter);
            var pos = adapter.TextEditor.GetPositionFromPoint(e.GetPosition(this));

            args.InDocument = pos.HasValue;
            if (pos.HasValue)
            {
                args.LogicalPosition = AvalonEditDocumentAdapter.ToLocation(pos.Value.Location);
            }

            if (!args.Handled)
            {
                // if request wasn't handled by a marker, pass it to the ToolTipRequestService
                ToolTipRequestService.RequestToolTip(args);
            }

            if (args.ContentToShow != null)
            {
                var contentToShowITooltip = args.ContentToShow as ITooltip;

                if (contentToShowITooltip != null && contentToShowITooltip.ShowAsPopup)
                {
                    if (!(args.ContentToShow is UIElement))
                    {
                        throw new NotSupportedException("Content to show in Popup must be UIElement: " + args.ContentToShow);
                    }
                    if (popup == null)
                    {
                        popup = CreatePopup();
                    }
                    if (TryCloseExistingPopup(false))
                    {
                        // when popup content decides to close, close the popup
                        contentToShowITooltip.Closed += (closedSender, closedArgs) => { popup.IsOpen = false; };
                        popup.Child = (UIElement)args.ContentToShow;
                        //ICSharpCode.SharpDevelop.Debugging.DebuggerService.CurrentDebugger.IsProcessRunningChanged
                        SetPopupPosition(popup, e);
                        popup.IsOpen = true;
                    }
                    e.Handled = true;
                }
                else
                {
                    if (toolTip == null)
                    {
                        toolTip         = new ToolTip();
                        toolTip.Closed += delegate { toolTip = null; };
                    }
                    toolTip.PlacementTarget = this.adapter.TextEditor;                     // required for property inheritance

                    if (args.ContentToShow is string)
                    {
                        toolTip.Content = new TextBlock
                        {
                            Text         = args.ContentToShow as string,
                            TextWrapping = TextWrapping.Wrap
                        };
                    }
                    else
                    {
                        toolTip.Content = args.ContentToShow;
                    }

                    toolTip.IsOpen = true;
                    e.Handled      = true;
                }
            }
            else
            {
                // close popup if mouse hovered over empty area
                if (popup != null)
                {
                    e.Handled = true;
                }
                TryCloseExistingPopup(false);
            }
        }
Example #17
0
        void TextEditorMouseHover(object sender, MouseEventArgs e)
        {
            Debug.Assert(sender == this);
            ToolTipRequestEventArgs args = new ToolTipRequestEventArgs(this.Adapter);
            var pos = GetPositionFromPoint(e.GetPosition(this));

            args.InDocument = pos.HasValue;
            if (pos.HasValue)
            {
                args.LogicalPosition = AvalonEditDocumentAdapter.ToLocation(pos.Value);
            }

            TextMarkerService textMarkerService = this.Adapter.GetService(typeof(ITextMarkerService)) as TextMarkerService;

            if (args.InDocument && textMarkerService != null)
            {
                var markersAtOffset = textMarkerService.GetMarkersAtOffset(args.Editor.Document.PositionToOffset(args.LogicalPosition.Line, args.LogicalPosition.Column));

                ITextMarker markerWithToolTip = markersAtOffset.FirstOrDefault(marker => marker.ToolTip != null);

                if (markerWithToolTip != null)
                {
                    args.SetToolTip(markerWithToolTip.ToolTip);
                }
            }

            if (!args.Handled)
            {
                // if request wasn't handled by a marker, pass it to the ToolTipRequestService
                ToolTipRequestService.RequestToolTip(args);
            }

            if (args.ContentToShow != null)
            {
                var contentToShowITooltip = args.ContentToShow as ITooltip;

                if (contentToShowITooltip != null && contentToShowITooltip.ShowAsPopup)
                {
                    if (!(args.ContentToShow is UIElement))
                    {
                        throw new NotSupportedException("Content to show in Popup must be UIElement: " + args.ContentToShow);
                    }
                    if (popup == null)
                    {
                        popup = CreatePopup();
                    }
                    // if popup was only first level, hovering somewhere else closes it
                    if (TryCloseExistingPopup(false))
                    {
                        // when popup content decides to close, close the popup
                        contentToShowITooltip.Closed += (closedSender, closedArgs) => { popup.IsOpen = false; };
                        popup.Child = (UIElement)args.ContentToShow;
                        //ICSharpCode.SharpDevelop.Debugging.DebuggerService.CurrentDebugger.IsProcessRunningChanged
                        SetPopupPosition(popup, e);
                        popup.IsOpen = true;
                    }
                    e.Handled = true;
                }
                else
                {
                    if (toolTip == null)
                    {
                        toolTip         = new ToolTip();
                        toolTip.Closed += ToolTipClosed;
                    }
                    toolTip.PlacementTarget = this;                     // required for property inheritance

                    if (args.ContentToShow is string)
                    {
                        toolTip.Content = new TextBlock
                        {
                            Text         = args.ContentToShow as string,
                            TextWrapping = TextWrapping.Wrap
                        };
                    }
                    else
                    {
                        toolTip.Content = args.ContentToShow;
                    }

                    toolTip.IsOpen = true;
                    e.Handled      = true;
                }
            }
            else
            {
                // close popup if mouse hovered over empty area
                if (popup != null)
                {
                    e.Handled = true;
                }
                TryCloseExistingPopup(false);
            }
        }
Example #18
0
 public MockTextEditor()
 {
     documentAdapter = new AvalonEditDocumentAdapter(textDocument, null);
 }