public EditorWrapper(String contentType) { ThreadHelper.ThrowIfNotOnUIThread(); var serviceProvider = (IServiceProvider)ServiceProvider.GlobalProvider.GetService(typeof(IServiceProvider)); var componentModel = (IComponentModel)ServiceProvider.GlobalProvider.GetService(typeof(SComponentModel)); if (componentModel == null) { throw new InvalidOperationException("SComponentModel service is not available"); } var service = componentModel.GetService <EditorServices>(); var message = ""; var type = service.ContentTypeRegistryService.GetContentType(contentType); // var CSharpLanguageServiceId = new Guid("694dd9b6-b865-4c5b-ad85-86356e9c88dc"); // var VisualBasicLanguageServiceId = new Guid("e34acdc0-baae-11d0-88bf-00a0c9110049"); VsTextLines = (IVsTextLines)service.VsEditorAdaptersFactoryService.CreateVsTextBufferAdapter(serviceProvider, type); VsTextLines.InitializeContent(message, message.Length); // vsTextBuffer.SetLanguageServiceID(ref CSharpLanguageServiceId); var textRoles = service.TextEditorFactoryService.CreateTextViewRoleSet( PredefinedTextViewRoles.Analyzable, PredefinedTextViewRoles.Document, PredefinedTextViewRoles.Editable, PredefinedTextViewRoles.Interactive, //PredefinedTextViewRoles.PrimaryDocument, PredefinedTextViewRoles.Structured, PredefinedTextViewRoles.Zoomable ); VsTextView = service.VsEditorAdaptersFactoryService.CreateVsTextViewAdapter(serviceProvider, textRoles); var initFlags = (UInt32)TextViewInitFlags.VIF_HSCROLL | (UInt32)TextViewInitFlags.VIF_SET_DRAGDROPMOVE | // (uint)TextViewInitFlags.VIF_SET_VISIBLE_WHITESPACE | (UInt32)TextViewInitFlags.VIF_VSCROLL | (UInt32)TextViewInitFlags3.VIF_NO_HWND_SUPPORT ; var initView = new INITVIEW[] { new INITVIEW { fSelectionMargin = 0, // original: 0 fWidgetMargin = 0, // original: 0 fVirtualSpace = 0, fDragDropMove = 1, } }; VsTextView.Initialize(VsTextLines, IntPtr.Zero, initFlags, initView); WpfTextViewHost = service.VsEditorAdaptersFactoryService.GetWpfTextViewHost(VsTextView); WpfTextViewHost.TextView.Options.SetOptionValue("Appearance/Category", "text"); WpfTextViewHost.TextView.Options.SetOptionValue("TextView/UseVisibleWhitespace", true); WpfTextViewHost.TextView.Options.SetOptionValue("TextViewHost/LineNumberMargin", true); }
public void Select(Int32 startPos, Int32 endPos) { if (ErrorHandler.Failed(VsTextView.GetLineAndColumn(startPos, out var startLine, out var startColumn))) { return; } if (ErrorHandler.Failed(VsTextView.GetLineAndColumn(endPos, out var endLine, out var endColumn))) { return; } if (ErrorHandler.Failed(VsTextView.SetSelectionMode(TextSelMode.SM_STREAM))) { return; } VsTextView.SetSelection(startLine, startColumn, endLine, endColumn); }
public void Scroll(Int32 startPos) { if (ErrorHandler.Failed(VsTextView.GetLineAndColumn(startPos, out var startLine, out var startColumn))) { return; } var span = new TextSpan() { iStartIndex = startColumn, iStartLine = startLine, iEndIndex = startColumn, iEndLine = startLine, }; VsTextView.EnsureSpanVisible(span); // VsTextView.SetTopLine(startLine); }
private void InsertCharacter(string match, int currentPosition, ITextSnapshotLine line, int column) { ITextSnapshot snapshot = TextView.TextBuffer.Insert(currentPosition, match); VsTextView.SetCaretPos(line.LineNumber, column); }
public virtual void OnSetFocus(VsTextView view){ // just in case another file we were dependent on has changed while we were // inactive, this will force us to sync up. this.source.SetDirty(); }
public virtual void OnSetBuffer(VsTextView view, IVsTextLines buffer){ }
public virtual void OnKillFocus(VsTextView view){ }
public virtual void OnChangeScrollInfo(VsTextView view, int iBar, int iMinUnit, int iMaxUnits, int iVisibleUnits, int iFirstVisibleUnit) { }
public virtual void OnChangeCaretLine(VsTextView view, int line, int col) { }
public virtual void OnNewView(VsTextView newView) { this.viewFilters.Add(this.service.CreateViewFilter(this.source, (IVsTextView)newView)); }
public virtual void OnNewView(VsTextView newView) { this.viewFilters.Add(this.service.CreateViewFilter(this.source, (IVsTextView)newView)); }
public virtual void OnSetFocus(VsTextView view) { // just in case another file we were dependent on has changed while we were // inactive, this will force us to sync up. this.source.SetDirty(); }
public virtual void OnSetBuffer(VsTextView view, IVsTextLines buffer) { }
public virtual void OnKillFocus(VsTextView view) { }
public virtual void OnChangeScrollInfo(VsTextView view, int iBar, int iMinUnit, int iMaxUnits, int iVisibleUnits, int iFirstVisibleUnit) { }
public virtual void OnChangeCaretLine(VsTextView view, int line, int col) { }