/// <summary> /// Initializes a new instance of the CodeOutlineFileManager class. /// </summary> /// <param name="control">The outline control object.</param> /// <param name="dte">A DTE object exposing the Visual Studio automation object model.</param> /// <param name="d">The source file Document.</param> /// <param name="toolWindow">The tool window for the package.</param> public CodeOutlineFileManager(SourceOutlinerControl control, EnvDTE.DTE dte, Document d, SourceOutlineToolWindow toolWindow) { _control = control; _dte = dte; _sourceOutlineToolWindow = toolWindow; _viewType = ViewType.TreeView; _searchCriteria = new SearchCriteria(CodeElementType.All); _currentFilterText = ""; _currentDocument = d; _codeTreeView = new System.Windows.Forms.TreeView(); _codeFilterView = new System.Windows.Forms.TreeView(); // // _codeTreeView // _codeTreeView.Dock = System.Windows.Forms.DockStyle.Fill; _codeTreeView.HideSelection = false; _codeTreeView.Location = new System.Drawing.Point(0, 45); _codeTreeView.Name = "codeTreeView"; _codeTreeView.ShowNodeToolTips = true; _codeTreeView.Size = new System.Drawing.Size(352, 294); _codeTreeView.TabIndex = 2; // // _codeFilterView // _codeFilterView.Dock = System.Windows.Forms.DockStyle.Fill; _codeFilterView.HideSelection = false; _codeFilterView.Location = new System.Drawing.Point(0, 45); _codeFilterView.Name = "codeFilterView"; _codeFilterView.ShowNodeToolTips = true; _codeFilterView.Size = new System.Drawing.Size(352, 294); _codeFilterView.TabIndex = 3; _codeFilterView.Visible = false; _codeFilterView.ShowLines = false; _codeFilterView.ShowRootLines = false; _codeFilterView.FullRowSelect = true; }
/// <summary> /// Loads a document into display TreeViews, updates the cache, and /// rebuilds the file manager that represents the document. /// </summary> /// <param name="d">The Document to load.</param> /// <param name="tw">The tool window associated with the cache.</param> /// <remarks> /// If the document is in the cache, it is reused. /// </remarks> public void AddDocumentToCache(Document doc, SourceOutlineToolWindow tw) { Debug.Assert(doc != null); _toolWindow = tw; if (doc == _document) { return; } if (_document != null) { // Unregister events for the previous document. tw.UnRegisterTreeEvents(_fileManager.TreeView, _fileManager.FilterView); _control.RemoveTreeFromControls(_fileManager.TreeView); _control.RemoveTreeFromControls(_fileManager.FilterView); } _document = doc; _fileManager = new CodeOutlineFileManager(_control, _dte, doc, tw); tw.RegisterTreeEvents(_fileManager.TreeView, _fileManager.FilterView); // Load the control. _control.AddTreeToControls(_fileManager.TreeView); _control.AddTreeToControls(_fileManager.FilterView); _fileManager.State = CodeOutlineFileManager.OutlineFileManagerState.StartLoadingCodeModel; _fileManager.HideTrees(); _control.HideTrees(); _control.TreeView = _fileManager.TreeView; _control.FilterView = _fileManager.FilterView; // Re-display the last CodeElementType selected for this document. tw.SelectedType = _fileManager.ElementFilter; // Re-display the last filter text entered for this document, but only if the file is loaded. if (_fileManager.State == CodeOutlineFileManager.OutlineFileManagerState.DoneLoadingCodeModel) { _fileManager.ReApplyText(); tw.SelectedFilterText = _fileManager.FilterText; } else { _control.Reset(); } }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put any initialization code that relies on services provided by Visual Studio. /// </summary> protected override void Initialize() { DisplayMessage(Resources.StatusPrefix, string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString())); base.Initialize(); // Add command handlers for the menu (commands must exist in the .ctc file) OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (null != mcs) { // Create the command for the tool window in the Other Windows menu. CommandID toolwndCommandID = new CommandID(GuidList.guidSourceOutlinerCmdSet, (int)PkgCmdIDList.cmdidSourceOutliner1); MenuCommand menuToolWin = new MenuCommand(new EventHandler(ShowToolWindow), toolwndCommandID); mcs.AddCommand(menuToolWin); } _dte = GetService(typeof(EnvDTE._DTE)) as EnvDTE.DTE; if (_dte == null) { throw new NullReferenceException("DTE is null"); } _window = (SourceOutlineToolWindow)this.FindToolWindow(typeof(SourceOutlineToolWindow), 0, true); _window.Package = this; _componentManager = (IOleComponentManager)GetService(typeof(SOleComponentManager)); if (_componentID == 0) { OLECRINFO[] crinfo = new OLECRINFO[1]; crinfo[0].cbSize = (uint)Marshal.SizeOf(typeof(OLECRINFO)); crinfo[0].grfcrf = (uint)_OLECRF.olecrfNeedIdleTime | (uint)_OLECRF.olecrfNeedPeriodicIdleTime | (uint)_OLECRF.olecrfNeedAllActiveNotifs | (uint)_OLECRF.olecrfNeedSpecActiveNotifs; crinfo[0].grfcadvf = (uint)_OLECADVF.olecadvfModal | (uint)_OLECADVF.olecadvfRedrawOff | (uint)_OLECADVF.olecadvfWarningsOff; crinfo[0].uIdleTimeInterval = 100; int hr = _componentManager.FRegisterComponent(_window, crinfo, out this._componentID); if (!ErrorHandler.Succeeded(hr)) { DisplayMessage(Resources.ErrorPrefix, "Initialize->IOleComponent registration failed"); } } // Initialize the DTE and the code outline file manager, and hook up events. InitializeToolWindow(); }