Browse Source

fix error when the file is deleted.

4.1
Eusebiu Marcu 15 years ago
parent
commit
c82b185296
  1. 2
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditViewContent.cs
  2. 9
      src/Main/Base/Project/Src/Services/File/FileChangeWatcher.cs

2
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditViewContent.cs

@ -60,12 +60,14 @@ namespace ICSharpCode.AvalonEdit.AddIn
void OnFileExternallyChanged(object sender, EventArgs e) void OnFileExternallyChanged(object sender, EventArgs e)
{ {
// handle readonly // handle readonly
if (this.PrimaryFileName != null && File.Exists(this.PrimaryFileName)) {
bool isExternalReadOnly = (File.GetAttributes(this.PrimaryFileName) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly; bool isExternalReadOnly = (File.GetAttributes(this.PrimaryFileName) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly;
if (isExternalReadOnly != IsReadOnly) { if (isExternalReadOnly != IsReadOnly) {
codeEditor.PrimaryTextEditor.IsReadOnly = isExternalReadOnly; codeEditor.PrimaryTextEditor.IsReadOnly = isExternalReadOnly;
OnIsReadOnlyChanged(EventArgs.Empty); OnIsReadOnlyChanged(EventArgs.Empty);
} }
} }
}
void codeEditor_Document_UndoStack_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) void codeEditor_Document_UndoStack_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{ {

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

@ -9,6 +9,7 @@ using System.Windows.Forms;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.SharpDevelop namespace ICSharpCode.SharpDevelop
{ {
@ -162,6 +163,7 @@ namespace ICSharpCode.SharpDevelop
watcher.Changed += OnFileChangedEvent; watcher.Changed += OnFileChangedEvent;
watcher.Created += OnFileChangedEvent; watcher.Created += OnFileChangedEvent;
watcher.Renamed += OnFileChangedEvent; watcher.Renamed += OnFileChangedEvent;
watcher.Deleted += OnFileChangedEvent;
} }
watcher.Path = Path.GetDirectoryName(fileName); watcher.Path = Path.GetDirectoryName(fileName);
watcher.Filter = Path.GetFileName(fileName); watcher.Filter = Path.GetFileName(fileName);
@ -196,11 +198,16 @@ namespace ICSharpCode.SharpDevelop
wasChangedExternally = true; wasChangedExternally = true;
OnFileChanged(EventArgs.Empty); OnFileChanged(EventArgs.Empty);
// if the file was only made readonly, don't prevent reloading it from disk if (System.IO.File.Exists(this.file.FileName)) {
// if the file was only made readonly, prevent reloading it from disk
bool readOnly = (System.IO.File.GetAttributes(this.file.FileName) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly; bool readOnly = (System.IO.File.GetAttributes(this.file.FileName) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly;
if (readOnly != isFileReadOnly) if (readOnly != isFileReadOnly)
wasChangedExternally = false; wasChangedExternally = false;
isFileReadOnly = readOnly; isFileReadOnly = readOnly;
} else {
// use to raise the events
FileService.RemoveFile(this.file.FileName, false);
}
if (WorkbenchSingleton.Workbench.IsActiveWindow) { if (WorkbenchSingleton.Workbench.IsActiveWindow) {
// delay reloading message a bit, prevents showing two messages // delay reloading message a bit, prevents showing two messages

Loading…
Cancel
Save