/// <summary> /// Raised when a CodeElement object has been created. /// </summary> /// <param name="newElement">The CodeElement object that was added.</param> private void codeModelEvents_Added(CodeElement newElement) { try { if (CurrentFileManager == null) { return; } if (!CurrentFileManager.FileIsOutlined) { ForceReload(); return; } _control.ShowWaitWhileReadyMessage(); _fileManager.OnCodeModelElementAdd(newElement); _control.HideWaitWhileReadyMessage(); } catch (Exception ex) { Utils.DisplayMessage(Resources.ErrorPrefix, "codeModelEvents_Added exception: " + ex.ToString()); } }
/// <summary> /// Called when the Visual Studio IDE goes idle to give /// the component a chance to perform idle time tasks. /// </summary> /// <remarks> /// The component may periodically call FContinueIdle and, if it returns /// false, the component should terminate its idle time processing and return. /// If a component reaches a point where it has no idle tasks and does not need /// FDoIdle calls, it should remove its idle task registration via /// FUpdateComponentRegistration. If this method is called while the component /// is performing a tracking operation, the component should only perform idle time /// tasks that it deems appropriate to perform during tracking. /// </remarks> public void OnIdle() { if (Dte == null || _codeCache == null) { // Initialize is in progress. // return; } var tickCount = (uint)Environment.TickCount; if (tickCount < _lastTickCount) { // The tick count rolled over, so treat this as if the timeout has expired // to keep from waiting until the count gets up to the required value again. } else { // Check to see when the last occurrence was. Only search once per second. if ((tickCount - _lastTickCount) < _delayBetweenIdleProcessing) { return; } } try { if (_codeCache.CurrentFileManager != null) { CodeOutlineFileManager.OutlineFileManagerState state = _codeCache.CurrentFileManager.State; switch (state) { case CodeOutlineFileManager.OutlineFileManagerState.Failed: _control.ShowException(_codeCache.CurrentFileManager.ParseException); _control.Enabled = true; return; case CodeOutlineFileManager.OutlineFileManagerState.StartLoadingCodeModel: // Load completely anew. _control.ShowWaitWhileReadyMessage(); _codeCache.CurrentFileManager.Load(); return; case CodeOutlineFileManager.OutlineFileManagerState.LoadingCodeModel: // Continue loading after an interruption. _codeCache.CurrentFileManager.ContinueLoading(); return; case CodeOutlineFileManager.OutlineFileManagerState.DoneLoadingCodeModel: // Loading is complete. _codeCache.CurrentFileManager.FinishLoading(); _codeCache.CurrentFileManager.TreeView.Refresh(); _codeCache.CurrentFileManager.FilterView.Refresh(); _control.Enabled = _codeCache.CurrentFileManager.FileIsOutlined; if (_control.Enabled) { var selectedType = (CodeElementType)Enum.Parse(typeof(CodeElementType), _control.filterToolStripCombo.SelectedItem.ToString()); _codeCache.CurrentFileManager.ElementFilter = selectedType; } _control.HideWaitWhileReadyMessage(); _control.Reset(); _codeCache.CurrentFileManager.State = CodeOutlineFileManager.OutlineFileManagerState.WaitToStartOver; return; case CodeOutlineFileManager.OutlineFileManagerState.WaitToStartOver: break; } } // Get the current active TextPoint from the DTE. if (!_control.Enabled || Dte.ActiveDocument == null || _codeCache.CurrentFileManager == null || _codeCache.CurrentFileManager.TreeViewFocused) { return; } var sel = (TextSelection)Dte.ActiveDocument.Selection; if (sel == null) { return; } TextPoint tp = sel.ActivePoint; if ((tp.Line == _lineNum) && (tp.LineCharOffset == _colNum)) { if (!_codeElementSelectedOnIdle && ((tickCount - _lastTickCountBeforeUpdate) > _delayBetweenCodeElementSelection)) { _codeElementSelectedOnIdle = true; // Turn off pretty listing to fix the problem with line autocompletion // being invoked when the code element position is determined. EnvDTE.Properties properties = Dte.get_Properties("TextEditor", "Basic-Specific"); Property property = null; foreach (Property p in properties) { if (p.Name == "PrettyListing") { property = p; break; } } bool currentPrettyListing = true; if (property != null) { currentPrettyListing = (bool)property.Value; property.Value = false; } _codeCache.CurrentFileManager.SelectCodeElement(tp); // Set pretty listing back to its previous value. if (property != null) { property.Value = currentPrettyListing; } _lastTickCountBeforeUpdate = tickCount; } } else { _codeElementSelectedOnIdle = false; } _lineNum = tp.Line; _colNum = tp.LineCharOffset; } catch (Exception ex) { //exceptions from time to time occur in Nemerle parser if (_codeCache.CurrentFileManager != null) { _codeCache.CurrentFileManager.OnException(ex); } //Utils.DisplayMessage(Resources.ErrorPrefix, "FDoIdle exception: " + ex.ToString()); } _lastTickCount = tickCount; }