Browse Source

Temporarily disable FileChangeWatcher while renaming files. Should fix forum-10029.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4876 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
588f77c0e0
  1. 22
      src/Main/Base/Project/Src/Services/File/FileChangeWatcher.cs
  2. 5
      src/Main/Base/Project/Src/Services/File/FileService.cs

22
src/Main/Base/Project/Src/Services/File/FileChangeWatcher.cs

@ -41,6 +41,26 @@ namespace ICSharpCode.SharpDevelop @@ -41,6 +41,26 @@ namespace ICSharpCode.SharpDevelop
static HashSet<FileChangeWatcher> activeWatchers = new HashSet<FileChangeWatcher>();
static int globalDisableCount;
public static void DisableAllChangeWatchers()
{
WorkbenchSingleton.AssertMainThread();
globalDisableCount++;
foreach (FileChangeWatcher w in activeWatchers)
w.SetWatcher();
}
public static void EnableAllChangeWatchers()
{
WorkbenchSingleton.AssertMainThread();
if (globalDisableCount == 0)
throw new InvalidOperationException();
globalDisableCount--;
foreach (FileChangeWatcher w in activeWatchers)
w.SetWatcher();
}
FileSystemWatcher watcher;
bool wasChangedExternally = false;
OpenedFile file;
@ -96,6 +116,8 @@ namespace ICSharpCode.SharpDevelop @@ -96,6 +116,8 @@ namespace ICSharpCode.SharpDevelop
if (!enabled)
return;
if (globalDisableCount > 0)
return;
if (DetectExternalChangesOption == false)
return;

5
src/Main/Base/Project/Src/Services/File/FileService.cs

@ -388,6 +388,8 @@ namespace ICSharpCode.SharpDevelop @@ -388,6 +388,8 @@ namespace ICSharpCode.SharpDevelop
{
if (FileUtility.IsEqualFileName(oldName, newName))
return false;
FileChangeWatcher.DisableAllChangeWatchers();
try {
FileRenamingEventArgs eargs = new FileRenamingEventArgs(oldName, newName, isDirectory);
OnFileRenaming(eargs);
if (eargs.Cancel)
@ -420,6 +422,9 @@ namespace ICSharpCode.SharpDevelop @@ -420,6 +422,9 @@ namespace ICSharpCode.SharpDevelop
}
OnFileRenamed(new FileRenameEventArgs(oldName, newName, isDirectory));
return true;
} finally {
FileChangeWatcher.EnableAllChangeWatchers();
}
}
/// <summary>

Loading…
Cancel
Save