예제 #1
0
        /// <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();
            }
        }
예제 #2
0
        /// <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;
        }