/// <summary> /// Performs the clean-up operations for this object. /// </summary> protected override void Dispose(bool disposing) { try { if (disposing) { // Dispose the stream. if (null != textStream) { ((IDisposable)textStream).Dispose(); textStream = null; } // Close the text view. if (null != textView) { // Remove the command filter. textView.RemoveCommandFilter((IOleCommandTarget)this); // Release the text view. textView.CloseView(); textView = null; } // Dispose the command service. if (null != commandService) { commandService.Dispose(); commandService = null; } } } finally { base.Dispose(disposing); } }
protected override void Initialize() { base.Initialize(); IComponentModel compMod = GetService(typeof(SComponentModel)) as IComponentModel; ITextBufferFactoryService bufferFactory = compMod.GetService <ITextBufferFactoryService>(); ITextEditorFactoryService editorFactory = compMod.GetService <ITextEditorFactoryService>(); IVsEditorAdaptersFactoryService adapterFactory = compMod.GetService <IVsEditorAdaptersFactoryService>(); IContentTypeRegistryService registryService = compMod.GetService <IContentTypeRegistryService>(); completionBroker = compMod.GetService <ICompletionBroker>(); textView = adapterFactory.CreateVsTextViewAdapter(GetService(typeof(IOleServiceProvider)) as IOleServiceProvider); IVsTextBuffer textBuffer = adapterFactory.CreateVsTextBufferAdapter(GetService(typeof(IOleServiceProvider)) as IOleServiceProvider); uint textViewInitFlags = (uint)TextViewInitFlags.VIF_DEFAULT | (uint)TextViewInitFlags.VIF_HSCROLL | (uint)TextViewInitFlags.VIF_VSCROLL; textBuffer.InitializeContent("", 0); textView.Initialize(textBuffer as IVsTextLines, IntPtr.Zero, textViewInitFlags, null); // Create Dev10 objects _textView = adapterFactory.GetWpfTextView(textView); mefTextBuffer = adapterFactory.GetDataBuffer(textBuffer); IVsUserData userData = textView as IVsUserData; if (userData != null) { Guid g = Microsoft.VisualStudio.Editor.DefGuidList.guidIWpfTextViewHost; object obj; int hr = userData.GetData(ref g, out obj); if (hr == VSConstants.S_OK) { _textViewHost = obj as IWpfTextViewHost; } } var t = Initialization.Complete; //Initialize the history history = new HistoryBuffer(); // Create the stream on top of the text buffer. textStream = new TextBufferStream(mefTextBuffer); // Initialize the engine. InitializeEngine(); IContentType ipContentType = registryService.GetContentType("text"); mefTextBuffer.ChangeContentType(ipContentType, null); var options = adapterFactory.GetWpfTextView(textView).Options; options.SetOptionValue(DefaultTextViewHostOptions.LineNumberMarginId, false); options.SetOptionValue(DefaultTextViewOptions.AutoScrollId, true); adapterFactory.GetWpfTextView(textView).Caret.MoveTo(new SnapshotPoint(mefTextBuffer.CurrentSnapshot, mefTextBuffer.CurrentSnapshot.Length)); // Set the title of the window. this.Caption = Resources.ToolWindowTitle; // Set the icon of the toolwindow. this.BitmapResourceID = 301; this.BitmapIndex = 0; return; }