bool EnsureIgnored(bool ignore) { ThreadHelper.ThrowIfNotOnUIThread(); if (!IsDocumentInitialized) { return(false); } else if (_ignoring == ignore) { return(true); } IVsDocDataFileChangeControl ddfcc = RawDocument as IVsDocDataFileChangeControl; if (ddfcc != null) { if (SafeSucceeded(ddfcc.IgnoreFileChanges, ignore ? 1 : 0)) { _ignoring = ignore; return(true); } } return(false); }
public SuspendFileChanges(ServiceProvider site, string strDocument) { this.site = site; this.strDocumentFileName = strDocument; this.fSuspending = false; this.fileChangeControl = null; }
/// <summary> /// Resumes file change notifications to the environment for the wrapped file. /// </summary> public void Resume() { if (!this.suspended) { return; } // Get the environment's change notifier. IVsFileChangeEx changeNotifier = Package.Instance.Context.GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx; Tracer.WriteLineIf(classType, "Resume", Tracer.Level.Warning, changeNotifier == null, "Could not get an instance of the IVsChangeEx interface."); if (changeNotifier != null) { // Tell the environment to resume sending change notifications for the file. int hr = changeNotifier.IgnoreFile(0, this.FilePath, ResumeNotification); Tracer.WriteLineIf(classType, "Resume", Tracer.Level.Warning, NativeMethods.Failed(hr), "Could not tell the environment to resume file change notifications to '{0}': Hr=0x{1:x}", this.FilePath, hr); } // Tell the environment to resume sending change notifications to editors. if (this.docDataFileChangeControl != null) { int hr = this.docDataFileChangeControl.IgnoreFileChanges(ResumeNotification); Tracer.WriteLineIf(classType, "Resume", Tracer.Level.Warning, NativeMethods.Failed(hr), "Could not tell the environment to resume file change notifications to editors of file '{0}': Hr=0x{1:x}", this.FilePath, hr); this.docDataFileChangeControl = null; } // At this point we can consider ourself resumed. this.suspended = false; Tracer.WriteLineVerbose(classType, "Resume", "Resumed file change notifications for '{0}'.", this.FilePath); }
public void Suspend() { if (this.fSuspending) { return; } try { IVsRunningDocumentTable pRDT = (IVsRunningDocumentTable)this.site.QueryService(VsConstants.SID_SVsRunningDocumentTable, typeof(IVsRunningDocumentTable)); IntPtr docData; IVsHierarchy pIVsHierarchy; uint itemId; uint uiVsDocCookie; IVsFileChangeEx vsFileChange; if (pRDT == null) { return; } pRDT.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, this.strDocumentFileName, out pIVsHierarchy, out itemId, out docData, out uiVsDocCookie); if ((uiVsDocCookie == VsConstants.VSDOCCOOKIE_NIL) || docData == IntPtr.Zero) { return; } vsFileChange = (IVsFileChangeEx)this.site.QueryService(VsConstants.SID_SVsFileChangeEx, typeof(IVsFileChangeEx)); if (vsFileChange != null) { this.fSuspending = true; vsFileChange.IgnoreFile(0, this.strDocumentFileName, (int)1); if (docData != IntPtr.Zero) { try { // if interface is not supported, return null IVsPersistDocData ppIVsPersistDocData = (IVsPersistDocData)Marshal.GetObjectForIUnknown(docData); this.fileChangeControl = (IVsDocDataFileChangeControl)ppIVsPersistDocData; if (this.fileChangeControl != null) { this.fileChangeControl.IgnoreFileChanges(1); } } catch { }; } } } catch { } return; }
public void Suspend() { if (!this.isSuspending) { IntPtr zero = IntPtr.Zero; try { IVsRunningDocumentTable service = this.site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable; if (service != null) { IVsHierarchy hierarchy; uint num; uint num2; ErrorHandler.ThrowOnFailure(service.FindAndLockDocument(0, this.documentFileName, out hierarchy, out num, out zero, out num2)); if ((num2 != 0) && (zero != IntPtr.Zero)) { IVsFileChangeEx ex = this.site.GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx; if (ex != null) { this.isSuspending = true; ErrorHandler.ThrowOnFailure(ex.IgnoreFile(0, this.documentFileName, 1)); if (zero != IntPtr.Zero) { IVsPersistDocData data = null; object objectForIUnknown = Marshal.GetObjectForIUnknown(zero); if (objectForIUnknown is IVsPersistDocData) { data = (IVsPersistDocData)objectForIUnknown; if (data is IVsDocDataFileChangeControl) { this.fileChangeControl = (IVsDocDataFileChangeControl)data; if (this.fileChangeControl != null) { ErrorHandler.ThrowOnFailure(this.fileChangeControl.IgnoreFileChanges(1)); } } } } } } } } catch (InvalidCastException exception) { Trace.WriteLine("Exception" + exception.Message); } finally { if (zero != IntPtr.Zero) { Marshal.Release(zero); } } } }
public void Suspend() { if (this.isSuspending) return; IntPtr docData = IntPtr.Zero; try { IVsRunningDocumentTable rdt = this.site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable; IVsHierarchy hierarchy; uint itemId; uint docCookie; IVsFileChangeEx fileChange; if (rdt == null) return; ErrorHandler.ThrowOnFailure(rdt.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, this.documentFileName, out hierarchy, out itemId, out docData, out docCookie)); if ((docCookie == (uint)ShellConstants.VSDOCCOOKIE_NIL) || docData == IntPtr.Zero) return; fileChange = this.site.GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx; if (fileChange != null) { this.isSuspending = true; ErrorHandler.ThrowOnFailure(fileChange.IgnoreFile(0, this.documentFileName, 1)); if (docData != IntPtr.Zero) { IVsPersistDocData persistDocData = null; // if interface is not supported, return null object unknown = Marshal.GetObjectForIUnknown(docData); if (unknown is IVsPersistDocData) { persistDocData = (IVsPersistDocData)unknown; if (persistDocData is IVsDocDataFileChangeControl) { this.fileChangeControl = (IVsDocDataFileChangeControl)persistDocData; if (this.fileChangeControl != null) { ErrorHandler.ThrowOnFailure(this.fileChangeControl.IgnoreFileChanges(1)); } } } } } } catch (InvalidCastException e) { Trace.WriteLine("Exception" + e.Message); } finally { if (docData != IntPtr.Zero) { Marshal.Release(docData); } } return; }
/// <summary> /// Turns on/off file ignore option. When file changes are ignored, VS doesn't display a dialog asking user about reloading the changes. /// </summary> public static void SetIgnoreFileChanges(string path, bool ignore) { if (string.IsNullOrEmpty(path)) { return; } IVsHierarchy ppHier; uint pitemid; IntPtr pPunkDocData; uint pdwCookie; int hr = IVsRunningDocumentTable.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, path, out ppHier, out pitemid, out pPunkDocData, out pdwCookie); Marshal.ThrowExceptionForHR(hr); if (pPunkDocData != IntPtr.Zero) { IVsFileChangeEx fileChange = (IVsFileChangeEx)Package.GetGlobalService(typeof(SVsFileChangeEx)); if (fileChange == null) { throw new InvalidOperationException("Cannot consume IVsFileChangeEx."); } IVsDocDataFileChangeControl changeControl = (IVsDocDataFileChangeControl)Marshal.GetObjectForIUnknown(pPunkDocData); if (ignore) { hr = fileChange.IgnoreFile(0, path, 1); Marshal.ThrowExceptionForHR(hr); hr = changeControl.IgnoreFileChanges(1); } else { hr = fileChange.IgnoreFile(0, path, 0); Marshal.ThrowExceptionForHR(hr); hr = changeControl.IgnoreFileChanges(0); } } }
/// <summary> /// Suspends any file change notifications to the environment for the wrapped file in /// preparation for a multi-stage file operation such as a rename. /// </summary> public void Suspend() { // We only want to suspend once. if (this.suspended) { return; } // Get the environment's change notifier. IVsFileChangeEx changeNotifier = Package.Instance.Context.GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx; if (changeNotifier == null) { Tracer.WriteLineWarning(classType, "Suspend", "Could not get an instance of the IVsChangeEx interface."); return; } // Tell the environment to stop sending change notifications for the file. int hr = changeNotifier.IgnoreFile(0, this.FilePath, IgnoreChanges); Tracer.WriteLineIf(classType, "Suspend", Tracer.Level.Warning, NativeMethods.Failed(hr), "Could not tell the environment to ignore file changes to '{0}': Hr=0x{1:x}", this.FilePath, hr); NativeMethods.ThrowOnFailure(hr); // Get the IVsDocDataFileChangeControl interface from the DocumentData. We need this // to suspend file change notifications to all editors. DocumentInfo docInfo = Package.Instance.Context.RunningDocumentTable.FindByPath(this.FilePath); if (docInfo != null) { this.docDataFileChangeControl = docInfo.DocumentData as IVsDocDataFileChangeControl; if (this.docDataFileChangeControl != null) { hr = this.docDataFileChangeControl.IgnoreFileChanges(IgnoreChanges); NativeMethods.ThrowOnFailure(hr); } } // At this point we can consider ourself suspended. this.suspended = true; Tracer.WriteLineVerbose(classType, "Suspend", "Suspended file change notifications for '{0}'.", this.FilePath); }
public void Suspend() { if (this.fSuspending) return; try { IVsRunningDocumentTable pRDT = (IVsRunningDocumentTable)this.site.QueryService(VsConstants.SID_SVsRunningDocumentTable, typeof(IVsRunningDocumentTable)); IntPtr docData; IVsHierarchy pIVsHierarchy; uint itemId; uint uiVsDocCookie; IVsFileChangeEx vsFileChange; if (pRDT == null) return; pRDT.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, this.strDocumentFileName, out pIVsHierarchy, out itemId, out docData, out uiVsDocCookie); if ((uiVsDocCookie == VsConstants.VSDOCCOOKIE_NIL) || docData == IntPtr.Zero) return; vsFileChange = (IVsFileChangeEx)this.site.QueryService(VsConstants.SID_SVsFileChangeEx, typeof(IVsFileChangeEx)); if (vsFileChange != null) { this.fSuspending = true; vsFileChange.IgnoreFile(0, this.strDocumentFileName, (int)1); if (docData != IntPtr.Zero) { try { // if interface is not supported, return null IVsPersistDocData ppIVsPersistDocData = (IVsPersistDocData)Marshal.GetObjectForIUnknown(docData); this.fileChangeControl = (IVsDocDataFileChangeControl)ppIVsPersistDocData; if (this.fileChangeControl != null) { this.fileChangeControl.IgnoreFileChanges(1); } } catch { } ; } } } catch { } return; }
public void Suspend() { if (this.isSuspending) { return; } IntPtr docData = IntPtr.Zero; try { IVsRunningDocumentTable rdt = this.site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable; IVsHierarchy hierarchy; uint itemId; uint docCookie; IVsFileChangeEx fileChange; if (rdt == null) { return; } ErrorHandler.ThrowOnFailure(rdt.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, this.documentFileName, out hierarchy, out itemId, out docData, out docCookie)); if ((docCookie == (uint)ShellConstants.VSDOCCOOKIE_NIL) || docData == IntPtr.Zero) { return; } fileChange = this.site.GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx; if (fileChange != null) { this.isSuspending = true; ErrorHandler.ThrowOnFailure(fileChange.IgnoreFile(0, this.documentFileName, (int)1)); if (docData != IntPtr.Zero) { IVsPersistDocData persistDocData = null; // if interface is not supported, return null object unknown = Marshal.GetObjectForIUnknown(docData); if (unknown is IVsPersistDocData) { persistDocData = (IVsPersistDocData)unknown; if (persistDocData is IVsDocDataFileChangeControl) { this.fileChangeControl = (IVsDocDataFileChangeControl)persistDocData; if (this.fileChangeControl != null) { ErrorHandler.ThrowOnFailure(this.fileChangeControl.IgnoreFileChanges(1)); } } } } } } catch (InvalidCastException e) { Trace.WriteLine("Exception" + e.Message); } finally { if (docData != IntPtr.Zero) { Marshal.Release(docData); } } return; }
public SuspendFileChanges(IServiceProvider site, string strDocument) { this.site = site; this.strDocumentFileName = strDocument; this.fSuspending = false; this.fileChangeControl = null; }
void ResumeWatchingProjectFileChanges() { if (!_suspended) return; IVsFileChangeEx fce = this.Site.GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx; if (fce != null) { NativeMethods.ThrowOnFailure(fce.IgnoreFile(0, filename, 0)); } if (_ddfcc != null) { NativeMethods.ThrowOnFailure(_ddfcc.IgnoreFileChanges(0)); _ddfcc = null; } _suspended = false; }
void SuspendWatchingProjectFileChanges() { if (_suspended || this.Site == null) return; IVsRunningDocumentTable pRDT = this.Site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable; if (pRDT == null) return; IVsHierarchy ppHier; uint pid; IntPtr docData; uint docCookie; NativeMethods.ThrowOnFailure(pRDT.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, filename, out ppHier, out pid, out docData, out docCookie)); if (docCookie == 0 || docData == IntPtr.Zero) return; IVsFileChangeEx fce = this.Site.GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx; if (fce != null) { _suspended = true; NativeMethods.ThrowOnFailure(fce.IgnoreFile(0, filename, 1)); try { _ddfcc = Marshal.GetTypedObjectForIUnknown(docData, typeof(IVsDocDataFileChangeControl)) as IVsDocDataFileChangeControl; if (_ddfcc != null) { NativeMethods.ThrowOnFailure(_ddfcc.IgnoreFileChanges(1)); } } catch (Exception) {} } // bugbug: do I need to "release" the docData IUnknown pointer // or does interop take care of it? }
public void Suspend() { if (mIsSuspending) { return; } mDocData = IntPtr.Zero; try { IVsRunningDocumentTable rdt = mSite.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable; if (rdt == null) { return; } ErrorHandler.ThrowOnFailure(rdt.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, mDocumentFileName, out IVsHierarchy hierarchy, out uint itemId, out mDocData, out uint docCookie)); if ((docCookie == (uint)ShellConstants.VSDOCCOOKIE_NIL) || mDocData == IntPtr.Zero) { return; } IVsFileChangeEx fileChange = mSite.GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx; if (fileChange == null) { return; } mIsSuspending = true; ErrorHandler.ThrowOnFailure(fileChange.IgnoreFile(0, mDocumentFileName, 1)); if (mDocData == IntPtr.Zero) { return; } mPersistDocData = null; object unknown = Marshal.GetObjectForIUnknown(mDocData); if (!(unknown is IVsPersistDocData)) { return; } mPersistDocData = (IVsPersistDocData)unknown; if (!(mPersistDocData is IVsDocDataFileChangeControl)) { return; } mFileChangeControl = (IVsDocDataFileChangeControl)mPersistDocData; if (mFileChangeControl != null) { ErrorHandler.ThrowOnFailure(mFileChangeControl.IgnoreFileChanges(1)); } } catch (InvalidCastException e) { Trace.WriteLine("Exception" + e.Message); } finally { if (mDocData != IntPtr.Zero) { Marshal.Release(mDocData); } } }
public void Suspend() { if (this.fSuspending) return; try { RunningDocumentTable pRDT = new RunningDocumentTable(this.site); IVsFileChangeEx vsFileChange; uint uiVsDocCookie; object docData = pRDT.FindDocument(this.strDocumentFileName, out uiVsDocCookie); if ((uiVsDocCookie == (uint)ShellConstants.VSDOCCOOKIE_NIL) || docData == null) return; vsFileChange = this.site.GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx; if (vsFileChange != null) { this.fSuspending = true; NativeMethods.ThrowOnFailure(vsFileChange.IgnoreFile(0, this.strDocumentFileName, (int)1)); if (docData is IVsDocDataFileChangeControl) { // if interface is not supported, return null IVsPersistDocData ppIVsPersistDocData = (IVsPersistDocData)docData; if (ppIVsPersistDocData is IVsDocDataFileChangeControl){ this.fileChangeControl = (IVsDocDataFileChangeControl)ppIVsPersistDocData; if (this.fileChangeControl != null) { NativeMethods.ThrowOnFailure(this.fileChangeControl.IgnoreFileChanges(1)); } } } } } catch { } return; }