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. 61
      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
static HashSet<FileChangeWatcher> activeWatchers = new HashSet<FileChangeWatcher>(); 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; FileSystemWatcher watcher;
bool wasChangedExternally = false; bool wasChangedExternally = false;
OpenedFile file; OpenedFile file;
@ -96,6 +116,8 @@ namespace ICSharpCode.SharpDevelop
if (!enabled) if (!enabled)
return; return;
if (globalDisableCount > 0)
return;
if (DetectExternalChangesOption == false) if (DetectExternalChangesOption == false)
return; return;

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

@ -388,38 +388,43 @@ namespace ICSharpCode.SharpDevelop
{ {
if (FileUtility.IsEqualFileName(oldName, newName)) if (FileUtility.IsEqualFileName(oldName, newName))
return false; return false;
FileRenamingEventArgs eargs = new FileRenamingEventArgs(oldName, newName, isDirectory); FileChangeWatcher.DisableAllChangeWatchers();
OnFileRenaming(eargs); try {
if (eargs.Cancel) FileRenamingEventArgs eargs = new FileRenamingEventArgs(oldName, newName, isDirectory);
return false; OnFileRenaming(eargs);
if (!eargs.OperationAlreadyDone) { if (eargs.Cancel)
try { return false;
if (isDirectory && Directory.Exists(oldName)) { if (!eargs.OperationAlreadyDone) {
try {
if (Directory.Exists(newName)) { if (isDirectory && Directory.Exists(oldName)) {
MessageService.ShowMessage(StringParser.Parse("${res:Gui.ProjectBrowser.FileInUseError}"));
return false; if (Directory.Exists(newName)) {
MessageService.ShowMessage(StringParser.Parse("${res:Gui.ProjectBrowser.FileInUseError}"));
return false;
}
Directory.Move(oldName, newName);
} else if (File.Exists(oldName)) {
if (File.Exists(newName)) {
MessageService.ShowMessage(StringParser.Parse("${res:Gui.ProjectBrowser.FileInUseError}"));
return false;
}
File.Move(oldName, newName);
} }
Directory.Move(oldName, newName); } catch (Exception e) {
if (isDirectory) {
} else if (File.Exists(oldName)) { MessageService.ShowError(e, "Can't rename directory " + oldName);
if (File.Exists(newName)) { } else {
MessageService.ShowMessage(StringParser.Parse("${res:Gui.ProjectBrowser.FileInUseError}")); MessageService.ShowError(e, "Can't rename file " + oldName);
return false;
} }
File.Move(oldName, newName); return false;
}
} catch (Exception e) {
if (isDirectory) {
MessageService.ShowError(e, "Can't rename directory " + oldName);
} else {
MessageService.ShowError(e, "Can't rename file " + oldName);
} }
return false;
} }
OnFileRenamed(new FileRenameEventArgs(oldName, newName, isDirectory));
return true;
} finally {
FileChangeWatcher.EnableAllChangeWatchers();
} }
OnFileRenamed(new FileRenameEventArgs(oldName, newName, isDirectory));
return true;
} }
/// <summary> /// <summary>
@ -479,7 +484,7 @@ namespace ICSharpCode.SharpDevelop
bool loggingResumed = false; bool loggingResumed = false;
try { try {
IViewContent content = OpenFile(fileName); IViewContent content = OpenFile(fileName);
if (content is IPositionable) { if (content is IPositionable) {
// TODO: enable jumping to a particular view // TODO: enable jumping to a particular view

Loading…
Cancel
Save