|
|
|
@ -9,31 +9,24 @@ using System;
@@ -9,31 +9,24 @@ using System;
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.Diagnostics; |
|
|
|
|
using System.IO; |
|
|
|
|
using System.Windows.Forms; |
|
|
|
|
using ICSharpCode.SharpDevelop.Gui; |
|
|
|
|
using ICSharpCode.Core; |
|
|
|
|
|
|
|
|
|
namespace ICSharpCode.SharpDevelop |
|
|
|
|
{ |
|
|
|
|
internal sealed class FileChangeWatcher //: IDisposable
|
|
|
|
|
internal sealed class FileChangeWatcher : IDisposable |
|
|
|
|
{ |
|
|
|
|
/*FileSystemWatcher watcher; |
|
|
|
|
bool wasChangedExternally = false; |
|
|
|
|
string fileName; |
|
|
|
|
AbstractViewContent viewContent; |
|
|
|
|
|
|
|
|
|
public FileChangeWatcher(AbstractViewContent viewContent) |
|
|
|
|
{ |
|
|
|
|
this.viewContent = viewContent; |
|
|
|
|
WorkbenchSingleton.MainForm.Activated += GotFocusEvent; |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
public static bool DetectExternalChangesOption { |
|
|
|
|
get { |
|
|
|
|
return PropertyService.Get("SharpDevelop.FileChangeWatcher.DetectExternalChanges", true); |
|
|
|
|
} |
|
|
|
|
set { |
|
|
|
|
WorkbenchSingleton.AssertMainThread(); |
|
|
|
|
PropertyService.Set("SharpDevelop.FileChangeWatcher.DetectExternalChanges", value); |
|
|
|
|
foreach (FileChangeWatcher watcher in activeWatchers) { |
|
|
|
|
watcher.SetWatcher(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -46,39 +39,69 @@ namespace ICSharpCode.SharpDevelop
@@ -46,39 +39,69 @@ namespace ICSharpCode.SharpDevelop
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
static Set<FileChangeWatcher> activeWatchers = new Set<FileChangeWatcher>(); |
|
|
|
|
|
|
|
|
|
FileSystemWatcher watcher; |
|
|
|
|
bool wasChangedExternally = false; |
|
|
|
|
OpenedFile file; |
|
|
|
|
|
|
|
|
|
public FileChangeWatcher(OpenedFile file) |
|
|
|
|
{ |
|
|
|
|
if (file == null) |
|
|
|
|
throw new ArgumentNullException("file"); |
|
|
|
|
WorkbenchSingleton.AssertMainThread(); |
|
|
|
|
this.file = file; |
|
|
|
|
WorkbenchSingleton.MainForm.Activated += MainForm_Activated; |
|
|
|
|
file.FileNameChanged += file_FileNameChanged; |
|
|
|
|
activeWatchers.Add(this); |
|
|
|
|
SetWatcher(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void file_FileNameChanged(object sender, EventArgs e) |
|
|
|
|
{ |
|
|
|
|
SetWatcher(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void Dispose() |
|
|
|
|
{ |
|
|
|
|
WorkbenchSingleton.MainForm.Activated -= GotFocusEvent; |
|
|
|
|
WorkbenchSingleton.AssertMainThread(); |
|
|
|
|
activeWatchers.Remove(this); |
|
|
|
|
if (file != null) { |
|
|
|
|
WorkbenchSingleton.MainForm.Activated -= MainForm_Activated; |
|
|
|
|
file.FileNameChanged -= file_FileNameChanged; |
|
|
|
|
file = null; |
|
|
|
|
} |
|
|
|
|
if (watcher != null) { |
|
|
|
|
watcher.Dispose(); |
|
|
|
|
watcher = null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void Disable() |
|
|
|
|
void SetWatcher() |
|
|
|
|
{ |
|
|
|
|
if (watcher != null) { |
|
|
|
|
watcher.EnableRaisingEvents = false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void SetWatcher(string fileName) |
|
|
|
|
{ |
|
|
|
|
this.fileName = fileName; |
|
|
|
|
|
|
|
|
|
if (DetectExternalChangesOption == false) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
string fileName = file.FileName; |
|
|
|
|
if (FileUtility.IsUrl(fileName)) |
|
|
|
|
return; |
|
|
|
|
if (!Path.IsPathRooted(fileName)) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
if (this.watcher == null) { |
|
|
|
|
this.watcher = new FileSystemWatcher(); |
|
|
|
|
this.watcher.SynchronizingObject = WorkbenchSingleton.MainForm; |
|
|
|
|
this.watcher.Changed += new FileSystemEventHandler(this.OnFileChangedEvent); |
|
|
|
|
} else { |
|
|
|
|
this.watcher.EnableRaisingEvents = false; |
|
|
|
|
if (watcher == null) { |
|
|
|
|
watcher = new FileSystemWatcher(); |
|
|
|
|
watcher.SynchronizingObject = WorkbenchSingleton.MainForm; |
|
|
|
|
watcher.Changed += new FileSystemEventHandler(this.OnFileChangedEvent); |
|
|
|
|
} |
|
|
|
|
this.watcher.Path = Path.GetDirectoryName(fileName); |
|
|
|
|
this.watcher.Filter = Path.GetFileName(fileName); |
|
|
|
|
this.watcher.NotifyFilter = NotifyFilters.LastWrite; |
|
|
|
|
this.watcher.EnableRaisingEvents = true; |
|
|
|
|
watcher.Path = Path.GetDirectoryName(fileName); |
|
|
|
|
watcher.Filter = Path.GetFileName(fileName); |
|
|
|
|
watcher.NotifyFilter = NotifyFilters.LastWrite; |
|
|
|
|
watcher.EnableRaisingEvents = true; |
|
|
|
|
} catch (PlatformNotSupportedException) { |
|
|
|
|
if (watcher != null) { |
|
|
|
|
watcher.Dispose(); |
|
|
|
@ -91,34 +114,38 @@ namespace ICSharpCode.SharpDevelop
@@ -91,34 +114,38 @@ namespace ICSharpCode.SharpDevelop
|
|
|
|
|
{ |
|
|
|
|
if (e.ChangeType != WatcherChangeTypes.Deleted) { |
|
|
|
|
wasChangedExternally = true; |
|
|
|
|
if (ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.Workbench.IsActiveWindow) { |
|
|
|
|
if (WorkbenchSingleton.Workbench.IsActiveWindow) { |
|
|
|
|
// delay showing message a bit, prevents showing two messages
|
|
|
|
|
// when the file changes twice in quick succession
|
|
|
|
|
WorkbenchSingleton.SafeThreadAsyncCall(GotFocusEvent, this, EventArgs.Empty); |
|
|
|
|
WorkbenchSingleton.SafeThreadAsyncCall(MainForm_Activated, this, EventArgs.Empty); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void GotFocusEvent(object sender, EventArgs e) |
|
|
|
|
void MainForm_Activated(object sender, EventArgs e) |
|
|
|
|
{ |
|
|
|
|
if (wasChangedExternally) { |
|
|
|
|
wasChangedExternally = false; |
|
|
|
|
|
|
|
|
|
if (file == null) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
string fileName = file.FileName; |
|
|
|
|
|
|
|
|
|
string message = StringParser.Parse("${res:ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor.TextEditorDisplayBinding.FileAlteredMessage}", new string[,] {{"File", Path.GetFullPath(fileName)}}); |
|
|
|
|
if ((AutoLoadExternalChangesOption && viewContent.IsDirty == false) |
|
|
|
|
if ((AutoLoadExternalChangesOption && file.IsDirty == false) |
|
|
|
|
|| MessageBox.Show(message, |
|
|
|
|
StringParser.Parse("${res:MainWindow.DialogName}"), |
|
|
|
|
MessageBoxButtons.YesNo, |
|
|
|
|
MessageBoxIcon.Question) == DialogResult.Yes) |
|
|
|
|
{ |
|
|
|
|
if (File.Exists(fileName)) { |
|
|
|
|
viewContent.Load(fileName); |
|
|
|
|
file.ReloadFromDisk(); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
viewContent.IsDirty = true; |
|
|
|
|
file.MakeDirty(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|