Ejemplo n.º 1
0
        private IWpfTextViewHost CreateTextViewHost()
        {
            // Create buffer

            var contentType = ContentTypeRegistryService.GetContentType("NQuery");
            var textBuffer  = TextBufferFactoryService.CreateTextBuffer(contentType);

            var textView     = TextEditorFactoryService.CreateTextView(textBuffer);
            var textViewHost = TextEditorFactoryService.CreateTextViewHost(textView, false);

            // Set the appearance of collapsed text
            textViewHost.TextView.VisualElement.Resources["CollapsedTextForeground"] = new SolidColorBrush(Color.FromRgb(0xA5, 0xA5, 0xA5));
            textViewHost.HostControl.Resources["outlining.verticalrule.foreground"]  = new SolidColorBrush(Color.FromRgb(0xA5, 0xA5, 0xA5));

            // Set the background color of glyph margin
            const string indicatorMargin    = "Indicator Margin";
            var          backgroundColor    = Color.FromRgb(0xF0, 0xF0, 0xF0);
            var          editorFormatMap    = EditorFormatMapService.GetEditorFormatMap(textViewHost.TextView);
            var          resourceDictionary = editorFormatMap.GetProperties(indicatorMargin);

            resourceDictionary["BackgroundColor"] = backgroundColor;
            resourceDictionary["Background"]      = new SolidColorBrush(backgroundColor);
            editorFormatMap.SetProperties(indicatorMargin, resourceDictionary);

            return(textViewHost);
        }
Ejemplo n.º 2
0
        private void CreateTextViewHost(string text, string filePath)
        {
            if (text == null)
            {
                text = string.Empty;
            }

            var diskBuffer = TextBufferFactoryService.CreateTextBuffer(text, ContentType);

            _editorIntance = EditorInstanceFactory.CreateEditorInstance(diskBuffer, _compositionService);

            ITextDataModel textDataModel;

            if (_editorIntance != null)
            {
                textDataModel = new TextDataModel(diskBuffer, _editorIntance.ViewBuffer);
            }
            else
            {
                textDataModel = new TextDataModel(diskBuffer, diskBuffer);
            }

            var textBuffer = textDataModel.DocumentBuffer;

            TextDocument = TextDocumentFactoryService.CreateTextDocument(textBuffer, filePath);

            SetGlobalEditorOptions();

            var textView = TextEditorFactoryService.CreateTextView(textDataModel,
                                                                   new DefaultTextViewRoleSet(),
                                                                   GlobalOptions);

            _wpftextViewHost = TextEditorFactoryService.CreateTextViewHost(textView, true);

            ApplyDefaultSettings();

            _contentControl.Content = _wpftextViewHost.HostControl;

            var baseController = new BaseController();

            BaseController = baseController;

            if (_editorIntance != null)
            {
                CommandTarget = _editorIntance.GetCommandTarget(textView);
                var controller = CommandTarget as Microsoft.Languages.Editor.Controller.Controller;
                controller.ChainedController = baseController;
            }
            else
            {
                CommandTarget = baseController;
            }

            baseController.Initialize(textView, EditorOperations, UndoManager, _coreShell);
        }
Ejemplo n.º 3
0
        private void TestSimpleBlockComment(string initialText, string finalText, int caretPosition)
        {
            ITextBuffer textBuffer = TextBufferFactoryService.CreateTextBuffer(initialText, ContentTypeRegistryService.GetContentType(TestContentType));

            BlockCommentFormat   blockCommentFormat = new BlockCommentFormat("/*", "*/");
            FormatCommenter      commenter          = new FormatCommenter(textBuffer, blockCommentFormat);
            VirtualSnapshotPoint caret     = new VirtualSnapshotPoint(textBuffer.CurrentSnapshot.Lines.First(), caretPosition);
            VirtualSnapshotSpan  caretSpan = new VirtualSnapshotSpan(caret, caret);
            ReadOnlyCollection <VirtualSnapshotSpan> commentSpans = commenter.CommentSpans(new ReadOnlyCollection <VirtualSnapshotSpan>(new[] { caretSpan }));

            Assert.AreEqual(finalText, textBuffer.CurrentSnapshot.GetText());
            Assert.AreEqual(1, commentSpans.Count);
            Assert.AreEqual(finalText.Length - finalText.TrimStart().Length, commentSpans[0].Start.Position);
            Assert.AreEqual(initialText.Length + blockCommentFormat.StartText.Length + blockCommentFormat.EndText.Length, commentSpans[0].End.Position);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Create an ITextBuffer instance with the given IContentType
 /// </summary>
 public ITextBuffer CreateTextBuffer(IContentType contentType, params string[] lines)
 {
     return(TextBufferFactoryService.CreateTextBuffer(contentType, lines));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Create an ITextBuffer instance with the given lines
 /// </summary>
 public ITextBuffer CreateTextBuffer(params string[] lines)
 {
     return(TextBufferFactoryService.CreateTextBuffer(lines));
 }
Ejemplo n.º 6
0
        public IWpfTextView CreateTextView(IContentType contentType, params string[] lines)
        {
            var textBuffer = TextBufferFactoryService.CreateTextBuffer(contentType, lines);

            return(TextEditorFactoryService.CreateTextView(textBuffer));
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Create an ITextBuffer instance with the given content
 /// </summary>
 public ITextBuffer CreateTextBufferRaw(string content, IContentType contentType = null)
 {
     return(TextBufferFactoryService.CreateTextBufferRaw(content, contentType));
 }