From 793e35797a4e4e047ff2125b8d0bdd3bffbc21e3 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald <daniel@danielgrunwald.de> Date: Tue, 16 Aug 2011 14:08:55 +0200 Subject: [PATCH] Revert patches for SD-1783 (react to "read only" changes). --- .../Scripting/Test/Utils/MockViewContent.cs | 8 --- .../WixBinding/Test/Utils/MockViewContent.cs | 1 - .../Src/AvalonEditViewContent.cs | 22 ++------ .../XmlEditor/Test/Utils/MockViewContent.cs | 9 ---- .../Test/Designer/MockViewContend.cs | 8 --- .../Project/Src/Gui/AbstractViewContent.cs | 15 ++---- src/Main/Base/Project/Src/Gui/IViewContent.cs | 5 -- .../Layouts/AvalonWorkbenchWindow.cs | 4 +- .../Src/Services/File/FileChangeWatcher.cs | 50 ++++--------------- .../Project/Src/Util/FakeXmlViewContent.cs | 9 ---- 10 files changed, 17 insertions(+), 114 deletions(-) diff --git a/src/AddIns/BackendBindings/Scripting/Test/Utils/MockViewContent.cs b/src/AddIns/BackendBindings/Scripting/Test/Utils/MockViewContent.cs index c571024080..63c062ea2c 100644 --- a/src/AddIns/BackendBindings/Scripting/Test/Utils/MockViewContent.cs +++ b/src/AddIns/BackendBindings/Scripting/Test/Utils/MockViewContent.cs @@ -26,7 +26,6 @@ namespace ICSharpCode.Scripting.Tests.Utils public event EventHandler TabPageTextChanged; public event EventHandler Disposed; public event EventHandler IsDirtyChanged; - public event EventHandler IsReadOnlyChanged; public string TitleName { get { @@ -235,13 +234,6 @@ namespace ICSharpCode.Scripting.Tests.Utils } } - protected virtual void OnIsReadOnlyChanged(EventArgs e) - { - if (IsReadOnlyChanged != null) { - IsReadOnlyChanged(this, e); - } - } - public object GetService(Type serviceType) { return null; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockViewContent.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockViewContent.cs index 759927190b..f46e5dfc15 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockViewContent.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockViewContent.cs @@ -41,7 +41,6 @@ namespace WixBinding.Tests.Utils public event EventHandler IsDirtyChanged; public event EventHandler TitleNameChanged; public event EventHandler InfoTipChanged; - public event EventHandler IsReadOnlyChanged; #pragma warning restore 67 public IList<OpenedFile> Files { diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditViewContent.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditViewContent.cs index 6b1a2cafc2..0f6e95a0aa 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditViewContent.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditViewContent.cs @@ -5,12 +5,15 @@ using System; using System.IO; using System.Linq; using System.Text; - +using System.Windows.Threading; using ICSharpCode.AvalonEdit.AddIn.Options; +using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Highlighting; +using ICSharpCode.AvalonEdit.Utils; using ICSharpCode.Core; using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Bookmarks; +using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Project; @@ -50,23 +53,6 @@ namespace ICSharpCode.AvalonEdit.AddIn codeEditor.Document.UndoStack.PropertyChanged += codeEditor_Document_UndoStack_PropertyChanged; codeEditor.CaretPositionChanged += CaretChanged; codeEditor.TextCopied += codeEditor_TextCopied; - - // get the watcher for the file - var watcher = FileChangeWatcher.ActiveWatchers.FirstOrDefault(w => w.File == file); - if (watcher != null) - watcher.FileChanged += OnFileExternallyChanged; - } - - void OnFileExternallyChanged(object sender, EventArgs e) - { - // handle readonly - 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); - } - } } void codeEditor_Document_UndoStack_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) diff --git a/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockViewContent.cs b/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockViewContent.cs index 426b0fa041..dc81f5cc3c 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockViewContent.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockViewContent.cs @@ -53,15 +53,6 @@ namespace XmlEditor.Tests.Utils } } - public event EventHandler IsReadOnlyChanged; - - protected virtual void OnIsReadOnlyChanged(EventArgs e) - { - if (IsReadOnlyChanged != null) { - IsReadOnlyChanged(this, e); - } - } - public object Control { get { throw new NotImplementedException(); diff --git a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Test/Designer/MockViewContend.cs b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Test/Designer/MockViewContend.cs index c4318d0603..468ed8876c 100644 --- a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Test/Designer/MockViewContend.cs +++ b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Test/Designer/MockViewContend.cs @@ -28,7 +28,6 @@ namespace ICSharpCode.Reports.Addin.Test.Designer public event EventHandler TabPageTextChanged; public event EventHandler Disposed; public event EventHandler IsDirtyChanged; - public event EventHandler IsReadOnlyChanged; public object Control { @@ -231,13 +230,6 @@ namespace ICSharpCode.Reports.Addin.Test.Designer } } - protected virtual void OnIsReadOnlyChanged(EventArgs e) - { - if (IsReadOnlyChanged != null) { - IsReadOnlyChanged(this, e); - } - } - public object InitiallyFocusedControl { get { throw new NotImplementedException(); diff --git a/src/Main/Base/Project/Src/Gui/AbstractViewContent.cs b/src/Main/Base/Project/Src/Gui/AbstractViewContent.cs index 03bd333ac5..121abe3c91 100644 --- a/src/Main/Base/Project/Src/Gui/AbstractViewContent.cs +++ b/src/Main/Base/Project/Src/Gui/AbstractViewContent.cs @@ -2,10 +2,11 @@ // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; +using System.ComponentModel.Design; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.ComponentModel.Design; using System.IO; +using System.Windows.Forms; using ICSharpCode.Core; using ICSharpCode.Core.Presentation; @@ -392,6 +393,7 @@ namespace ICSharpCode.SharpDevelop.Gui } #endregion + #region InfoTip public event EventHandler InfoTipChanged; @@ -606,7 +608,6 @@ namespace ICSharpCode.SharpDevelop.Gui return null; } - #region Read only /// <summary> /// Gets if the view content is read-only (can be saved only when choosing another file name). /// </summary> @@ -614,16 +615,6 @@ namespace ICSharpCode.SharpDevelop.Gui get { return false; } } - public event EventHandler IsReadOnlyChanged; - - protected virtual void OnIsReadOnlyChanged(EventArgs e) - { - if (IsReadOnlyChanged != null) { - IsReadOnlyChanged(this, e); - } - } - #endregion - /// <summary> /// Gets if the view content is view-only (cannot be saved at all). /// </summary> diff --git a/src/Main/Base/Project/Src/Gui/IViewContent.cs b/src/Main/Base/Project/Src/Gui/IViewContent.cs index 05f420334c..ec18b3f5c3 100644 --- a/src/Main/Base/Project/Src/Gui/IViewContent.cs +++ b/src/Main/Base/Project/Src/Gui/IViewContent.cs @@ -145,11 +145,6 @@ namespace ICSharpCode.SharpDevelop.Gui /// </summary> bool IsReadOnly { get; } - /// <summary> - /// Is called each time the IsReadonly for the content has changed. - /// </summary> - event EventHandler IsReadOnlyChanged; - /// <summary> /// Gets if the view content is view-only (cannot be saved at all). /// </summary> diff --git a/src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonWorkbenchWindow.cs b/src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonWorkbenchWindow.cs index a8e10c1d35..63deff3e5b 100644 --- a/src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonWorkbenchWindow.cs +++ b/src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonWorkbenchWindow.cs @@ -145,10 +145,8 @@ namespace ICSharpCode.SharpDevelop.Gui UpdateTitleAndInfoTip(); IViewContent newActiveViewContent = this.ActiveViewContent; - if (newActiveViewContent != null) { + if (newActiveViewContent != null) IsLocked = newActiveViewContent.IsReadOnly; - newActiveViewContent.IsReadOnlyChanged += delegate { IsLocked = newActiveViewContent.IsReadOnly; }; - } if (oldActiveViewContent != newActiveViewContent && ActiveViewContentChanged != null) { ActiveViewContentChanged(this, 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 490f5ec286..dcfe810a6e 100644 --- a/src/Main/Base/Project/Src/Services/File/FileChangeWatcher.cs +++ b/src/Main/Base/Project/Src/Services/File/FileChangeWatcher.cs @@ -3,14 +3,15 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; - -using ICSharpCode.Core; +using System.Windows.Forms; using ICSharpCode.SharpDevelop.Gui; +using ICSharpCode.Core; namespace ICSharpCode.SharpDevelop { - public sealed class FileChangeWatcher : IDisposable + internal sealed class FileChangeWatcher : IDisposable { public static bool DetectExternalChangesOption { get { @@ -36,10 +37,6 @@ namespace ICSharpCode.SharpDevelop static HashSet<FileChangeWatcher> activeWatchers = new HashSet<FileChangeWatcher>(); - public static HashSet<FileChangeWatcher> ActiveWatchers { - get { return activeWatchers; } - } - static int globalDisableCount; public static bool AllChangeWatchersDisabled { @@ -66,23 +63,9 @@ namespace ICSharpCode.SharpDevelop Project.ProjectChangeWatcher.OnAllChangeWatchersDisabledChanged(); } - public event EventHandler FileChanged; - - void OnFileChanged(EventArgs e) - { - if (FileChanged != null) { - FileChanged(this, e); - } - } - FileSystemWatcher watcher; bool wasChangedExternally = false; OpenedFile file; - bool isFileReadOnly; - - public OpenedFile File { - get { return file; } - } public FileChangeWatcher(OpenedFile file) { @@ -93,10 +76,6 @@ namespace ICSharpCode.SharpDevelop file.FileNameChanged += file_FileNameChanged; activeWatchers.Add(this); SetWatcher(); - - if (System.IO.File.Exists(this.file.FileName)) { - isFileReadOnly = (System.IO.File.GetAttributes(this.file.FileName) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly; - } } void file_FileNameChanged(object sender, EventArgs e) @@ -164,7 +143,6 @@ namespace ICSharpCode.SharpDevelop watcher.Path = Path.GetDirectoryName(fileName); watcher.Filter = Path.GetFileName(fileName); watcher.EnableRaisingEvents = true; - watcher.NotifyFilter |= NotifyFilters.Attributes; } catch (PlatformNotSupportedException) { if (watcher != null) { watcher.Dispose(); @@ -192,8 +170,6 @@ namespace ICSharpCode.SharpDevelop LoggingService.Debug("File " + file.FileName + " was changed externally: " + e.ChangeType); if (!wasChangedExternally) { wasChangedExternally = true; - OnFileChanged(EventArgs.Empty); - if (WorkbenchSingleton.Workbench.IsActiveWindow) { // delay reloading message a bit, prevents showing two messages // when the file changes twice in quick succession; and prevents @@ -207,22 +183,14 @@ namespace ICSharpCode.SharpDevelop void MainForm_Activated(object sender, EventArgs e) { - if (file == null) - return; - - if (System.IO.File.Exists(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; - } - if (wasChangedExternally) { wasChangedExternally = false; + if (file == null) + return; + string fileName = file.FileName; - if (!System.IO.File.Exists(fileName)) + if (!File.Exists(fileName)) return; string message = StringParser.Parse( @@ -232,7 +200,7 @@ namespace ICSharpCode.SharpDevelop if ((AutoLoadExternalChangesOption && file.IsDirty == false) || MessageService.AskQuestion(message, StringParser.Parse("${res:MainWindow.DialogName}"))) { - if (System.IO.File.Exists(fileName)) { + if (File.Exists(fileName)) { file.ReloadFromDisk(); } } else { diff --git a/src/Main/Base/Project/Src/Util/FakeXmlViewContent.cs b/src/Main/Base/Project/Src/Util/FakeXmlViewContent.cs index 46bfa4d3d3..fa3d7f3250 100644 --- a/src/Main/Base/Project/Src/Util/FakeXmlViewContent.cs +++ b/src/Main/Base/Project/Src/Util/FakeXmlViewContent.cs @@ -213,14 +213,5 @@ namespace ICSharpCode.SharpDevelop.Util return null; } #endregion - - public event EventHandler IsReadOnlyChanged; - - protected void OnIsReadOnlyChanged(EventArgs e) - { - if (IsReadOnlyChanged != null) { - IsReadOnlyChanged(this, e); - } - } } }