From c82b185296f15aaddef48ee00409e8d6e6d0a230 Mon Sep 17 00:00:00 2001 From: Eusebiu Marcu Date: Tue, 16 Aug 2011 12:35:18 +0200 Subject: [PATCH] fix error when the file is deleted. --- .../Src/AvalonEditViewContent.cs | 10 ++++++---- .../Src/Services/File/FileChangeWatcher.cs | 17 ++++++++++++----- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditViewContent.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditViewContent.cs index fff266648c..6b1a2cafc2 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditViewContent.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditViewContent.cs @@ -60,10 +60,12 @@ namespace ICSharpCode.AvalonEdit.AddIn void OnFileExternallyChanged(object sender, EventArgs e) { // handle readonly - bool isExternalReadOnly = (File.GetAttributes(this.PrimaryFileName) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly; - if (isExternalReadOnly != IsReadOnly) { - codeEditor.PrimaryTextEditor.IsReadOnly = isExternalReadOnly; - OnIsReadOnlyChanged(EventArgs.Empty); + if (this.PrimaryFileName != null && File.Exists(this.PrimaryFileName)) { + bool isExternalReadOnly = (File.GetAttributes(this.PrimaryFileName) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly; + if (isExternalReadOnly != IsReadOnly) { + codeEditor.PrimaryTextEditor.IsReadOnly = isExternalReadOnly; + OnIsReadOnlyChanged(EventArgs.Empty); + } } } diff --git a/src/Main/Base/Project/Src/Services/File/FileChangeWatcher.cs b/src/Main/Base/Project/Src/Services/File/FileChangeWatcher.cs index 47b476c502..e9d57f3ff9 100644 --- a/src/Main/Base/Project/Src/Services/File/FileChangeWatcher.cs +++ b/src/Main/Base/Project/Src/Services/File/FileChangeWatcher.cs @@ -9,6 +9,7 @@ using System.Windows.Forms; using ICSharpCode.Core; using ICSharpCode.SharpDevelop.Gui; +using ICSharpCode.SharpDevelop.Project; namespace ICSharpCode.SharpDevelop { @@ -162,6 +163,7 @@ namespace ICSharpCode.SharpDevelop watcher.Changed += OnFileChangedEvent; watcher.Created += OnFileChangedEvent; watcher.Renamed += OnFileChangedEvent; + watcher.Deleted += OnFileChangedEvent; } watcher.Path = Path.GetDirectoryName(fileName); watcher.Filter = Path.GetFileName(fileName); @@ -196,11 +198,16 @@ namespace ICSharpCode.SharpDevelop wasChangedExternally = true; OnFileChanged(EventArgs.Empty); - // if the file was only made readonly, don't prevent reloading it from disk - bool readOnly = (System.IO.File.GetAttributes(this.file.FileName) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly; - if (readOnly != isFileReadOnly) - wasChangedExternally = false; - isFileReadOnly = readOnly; + 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; + if (readOnly != isFileReadOnly) + wasChangedExternally = false; + isFileReadOnly = readOnly; + } else { + // use to raise the events + FileService.RemoveFile(this.file.FileName, false); + } if (WorkbenchSingleton.Workbench.IsActiveWindow) { // delay reloading message a bit, prevents showing two messages