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); }
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); }
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); }
/// <summary> /// Create an ITextBuffer instance with the given IContentType /// </summary> public ITextBuffer CreateTextBuffer(IContentType contentType, params string[] lines) { return(TextBufferFactoryService.CreateTextBuffer(contentType, lines)); }
/// <summary> /// Create an ITextBuffer instance with the given lines /// </summary> public ITextBuffer CreateTextBuffer(params string[] lines) { return(TextBufferFactoryService.CreateTextBuffer(lines)); }
public IWpfTextView CreateTextView(IContentType contentType, params string[] lines) { var textBuffer = TextBufferFactoryService.CreateTextBuffer(contentType, lines); return(TextEditorFactoryService.CreateTextView(textBuffer)); }
/// <summary> /// Create an ITextBuffer instance with the given content /// </summary> public ITextBuffer CreateTextBufferRaw(string content, IContentType contentType = null) { return(TextBufferFactoryService.CreateTextBufferRaw(content, contentType)); }