/// <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 d, SourceOutlinerToolWindow tw) { Debug.Assert(d != null); _toolWindow = tw; if (d == _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 = d; _fileManager = new CodeOutlineFileManager(_control, _dte, d, 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> /// 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, SourceOutlinerToolWindow toolWindow) { _control = control; _dte = dte; _sourceOutlinerToolWindow = 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; }