/// <summary>
        /// Delegates the call to the inner hierarchy.
        /// </summary>
        /// <param name="reserved">Reserved parameter defined at the IVsPersistHierarchyItem2::ReloadItem parameter.</param>
        protected internal override void ReloadItem(uint reserved)
        {
            #region precondition
            if (this.isDisposed || this.ProjectMgr == null || this.ProjectMgr.IsClosed)
            {
                throw new InvalidOperationException();
            }

            Debug.Assert(this.nestedHierarchy != null, "The nested hierarchy object must be created before calling this method");
            #endregion

            IVsPersistHierarchyItem2 persistHierachyItem = this.nestedHierarchy as IVsPersistHierarchyItem2;

            // We are expecting that if we get called then the nestedhierarchy supports IVsPersistHierarchyItem2, since then hierrachy should support handling its own reload.
            // There should be no errormessage to the user since this is an internal error, that it cannot be fixed at user level.
            if (persistHierachyItem == null)
            {
                throw new InvalidOperationException();
            }

            ErrorHandler.ThrowOnFailure(persistHierachyItem.ReloadItem(VSConstants.VSITEMID_ROOT, reserved));
        }
        /// <summary>
        /// Flag indicating that changes to a file can be ignored when item is saved or reloaded.
        /// </summary>
        /// <param name="ignoreFlag">Flag indicating whether or not to ignore changes (1 to ignore, 0 to stop ignoring).</param>
        protected internal override void IgnoreItemFileChanges(bool ignoreFlag)
        {
            #region precondition
            if (this.isDisposed || this.ProjectMgr == null || this.ProjectMgr.IsClosed)
            {
                throw new InvalidOperationException();
            }

            Debug.Assert(this.nestedHierarchy != null, "The nested hierarchy object must be created before calling this method");
            #endregion

            this.IgnoreNestedProjectFile(ignoreFlag);

            IVsPersistHierarchyItem2 persistHierachyItem = this.nestedHierarchy as IVsPersistHierarchyItem2;

            // If the IVsPersistHierarchyItem2 is not implemented by the nested just return
            if (persistHierachyItem == null)
            {
                return;
            }

            ErrorHandler.ThrowOnFailure(persistHierachyItem.IgnoreItemFileChanges(VSConstants.VSITEMID_ROOT, ignoreFlag ? 1 : 0));
        }
Exemple #3
0
        /// <summary>
        /// Reloads the document and optionally clears the undo state
        /// </summary>
        /// <param name="clearUndo">if set to <c>true</c> [clear undo].</param>
        /// <returns><c>true</c> if the document is reloaded, otherwise false</returns>
        public bool Reload(bool clearUndo)
        {
            if (_disposed)
            {
                return(false);
            }

            if (!IsDocumentInitialized)
            {
                return(true); // Not loaded, so no reload necessary!
            }
            int  reloadCookie = _reloadTick;
            bool wasDirty     = IsDirty;

            IVsPersistDocData vsPersistDocData = RawDocument as IVsPersistDocData;

            if (vsPersistDocData != null)
            {
                // This method is valid on all text editors and probably many other editors

                uint flags = 0;
                if (clearUndo)
                {
                    flags |= (uint)_VSRELOADDOCDATA.RDD_RemoveUndoStack;
                }

                bool ok;

                // Temporarily suspend our ignore 'lock' as without that documents
                // don't reload properly.

                if (_ignoring)
                {
                    EnsureIgnored(false);
                }

                try
                {
                    ok = SafeSucceeded(vsPersistDocData.ReloadDocData, flags);
                }
                finally
                {
                    EnsureIgnored(_ignored > 0);
                }

                if (ok)
                {
                    if (_disposed || (reloadCookie != _reloadTick) || (wasDirty != IsDirty))
                    {
                        return(true);
                    }
                }
            }

            IVsPersistHierarchyItem2 vsPersistHierarchyItem2 = RawDocument as IVsPersistHierarchyItem2;

            if (vsPersistHierarchyItem2 != null)
            {
                // This route works for some project types and at least the solution
                bool assumeOk = (_rawDocument is IVsSolution);

                if (SafeSucceeded(vsPersistHierarchyItem2.ReloadItem, VSItemId.Root, (uint)0))
                {
                    if (assumeOk || _disposed || reloadCookie != _reloadTick)
                    {
                        return(true);
                    }
                }
            }


            vsPersistHierarchyItem2 = Hierarchy as IVsPersistHierarchyItem2;

            if (vsPersistHierarchyItem2 != null &&
                SafeSucceeded(vsPersistHierarchyItem2.ReloadItem, ItemId, (uint)0))
            {
                // Our parent reloaded us
                return(true);
            }

            return(false); // We can't be reloaded by ourselves.. Let our caller reload our parent instead
        }