Example #1
0
        /// <summary>
        /// Registers for code model events.
        /// </summary>
        private void AdviseCodeModelEvents()
        {
            try
            {
                languageService.OnFileCodeModelChanged += OnFileCodeModelChanged;

                var dte2 = dte as DTE2;
                if (dte2 == null)
                {
                    throw new NullReferenceException("dte2 is NULL");
                }

                var events2 = dte2.Events as Events2;
                if (events2 == null)
                {
                    throw new NullReferenceException("events2 is NULL");
                }

                codeModelEvents = events2.get_CodeModelEvents(null);
                if (codeModelEvents != null)
                {
                    codeModelEvents.ElementAdded   += codeModelEvents_Added;
                    codeModelEvents.ElementChanged += codeModelEvents_Changed;
                    codeModelEvents.ElementDeleted += codeModelEvents_Deleted;
                }
            }
            catch (ArgumentException)
            {
                // Failed to get CodeModelEvents, this should not occur.
                SourceOutlineToolWindow.DisplayMessage(Resources.ErrorPrefix, "Failed to get Code Model events.");
                throw;
            }
        }
Example #2
0
        /// <summary>
        /// Raised when a CodeElement object has been changed.
        /// </summary>
        /// <param name="modifiedElement">The CodeElement that was changed.</param>
        /// <param name="iChangeType">The type of change event that was fired.</param>
        private void codeModelEvents_Changed(CodeElement modifiedElement, vsCMChangeKind iChangeType)
        {
            try
            {
                if (CurrentFileManager == null)
                {
                    return;
                }

                ForceReload();
            }
            catch (Exception ex)
            {
                SourceOutlineToolWindow.DisplayMessage(Resources.ErrorPrefix, "codeModelEvents_Changed exception: " + ex);
            }
        }
Example #3
0
        /// <summary>
        /// Raised when a FileCodeModel object has been changed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnFileCodeModelChanged(object sender, FileCodeModelChangedEventArgs e)
        {
            try
            {
                if (CurrentFileManager == null)
                {
                    return;
                }

                SourceOutlineToolWindow.DisplayMessage(Resources.StatusPrefix, "OnFileCodeModelChanged fired.");
                control.Invoke(new MethodInvoker(ForceReload));
            }
            catch (Exception ex)
            {
                SourceOutlineToolWindow.DisplayMessage(Resources.ErrorPrefix, "OnFileCodeModelChanged exception: " + ex);
            }
        }
Example #4
0
        /// <summary>
        /// Raised when a CodeElement object has been deleted.
        /// </summary>
        /// <param name="parent">The parent object for the CodeElement.</param>
        /// <param name="deletedElement">The CodeElement object that was deleted.</param>
        private void codeModelEvents_Deleted(object parent, CodeElement deletedElement)
        {
            try
            {
                if (CurrentFileManager == null)
                {
                    return;
                }

                if (!CurrentFileManager.FileIsOutlined)
                {
                    ForceReload();
                    return;
                }

                fileManager.OnCodeModelElementDeleted(parent, deletedElement);
            }
            catch (Exception ex)
            {
                SourceOutlineToolWindow.DisplayMessage(Resources.ErrorPrefix, "codeModelEvents_Deleted exception: " + ex);
            }
        }
Example #5
0
        /// <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)
            {
                SourceOutlineToolWindow.DisplayMessage(Resources.ErrorPrefix, "codeModelEvents_Added exception: " + ex);
            }
        }