|
|
|
|
@ -79,6 +79,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
@@ -79,6 +79,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
|
|
|
|
|
public class TextEditorDisplayBindingWrapper : AbstractViewContent, IMementoCapable, IPrintable, IEditable, IUndoHandler, IPositionable, ITextEditorControlProvider, IParseInformationListener, IClipboardHandler, IContextHelpProvider |
|
|
|
|
{ |
|
|
|
|
public SharpDevelopTextAreaControl textAreaControl = null; |
|
|
|
|
FileChangeWatcher watcher; |
|
|
|
|
|
|
|
|
|
public TextEditorControl TextEditorControl { |
|
|
|
|
get { |
|
|
|
|
@ -86,10 +87,86 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
@@ -86,10 +87,86 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// KSL Start, New lines
|
|
|
|
|
protected FileSystemWatcher watcher; |
|
|
|
|
protected bool wasChangedExternally = false; |
|
|
|
|
// KSL End
|
|
|
|
|
public 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 void Dispose() |
|
|
|
|
{ |
|
|
|
|
WorkbenchSingleton.MainForm.Activated -= GotFocusEvent; |
|
|
|
|
if (watcher != null) { |
|
|
|
|
watcher.Dispose(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void Disable() |
|
|
|
|
{ |
|
|
|
|
if (watcher != null) { |
|
|
|
|
watcher.EnableRaisingEvents = false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void SetWatcher(string fileName) |
|
|
|
|
{ |
|
|
|
|
this.fileName = fileName; |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
this.watcher.Path = Path.GetDirectoryName(fileName); |
|
|
|
|
this.watcher.Filter = Path.GetFileName(fileName); |
|
|
|
|
this.watcher.NotifyFilter = NotifyFilters.LastWrite; |
|
|
|
|
this.watcher.EnableRaisingEvents = true; |
|
|
|
|
} catch (PlatformNotSupportedException) { |
|
|
|
|
if (watcher != null) { |
|
|
|
|
watcher.Dispose(); |
|
|
|
|
} |
|
|
|
|
watcher = null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void OnFileChangedEvent(object sender, FileSystemEventArgs e) |
|
|
|
|
{ |
|
|
|
|
if(e.ChangeType != WatcherChangeTypes.Deleted) { |
|
|
|
|
wasChangedExternally = true; |
|
|
|
|
if (ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.Workbench.IsActiveWindow) { |
|
|
|
|
GotFocusEvent(this, EventArgs.Empty); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void GotFocusEvent(object sender, EventArgs e) |
|
|
|
|
{ |
|
|
|
|
if (wasChangedExternally) { |
|
|
|
|
wasChangedExternally = false; |
|
|
|
|
|
|
|
|
|
string message = StringParser.Parse("${res:ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor.TextEditorDisplayBinding.FileAlteredMessage}", new string[,] {{"File", Path.GetFullPath(fileName)}}); |
|
|
|
|
if (viewContent.IsDirty == false || |
|
|
|
|
MessageBox.Show(message, |
|
|
|
|
StringParser.Parse("${res:MainWindow.DialogName}"), |
|
|
|
|
MessageBoxButtons.YesNo, |
|
|
|
|
MessageBoxIcon.Question) == DialogResult.Yes) |
|
|
|
|
{ |
|
|
|
|
viewContent.Load(fileName); |
|
|
|
|
} else { |
|
|
|
|
viewContent.IsDirty = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public bool EnableUndo { |
|
|
|
|
get { |
|
|
|
|
@ -164,7 +241,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
@@ -164,7 +241,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
|
|
|
|
|
{ |
|
|
|
|
base.OnFileNameChanged(e); |
|
|
|
|
textAreaControl.FileName = base.FileName; |
|
|
|
|
SetWatcher(); // update file name the watcher looks at
|
|
|
|
|
watcher.SetWatcher(textAreaControl.FileName); // update file name the watcher looks at
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void Undo() |
|
|
|
|
@ -190,15 +267,8 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
@@ -190,15 +267,8 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
|
|
|
|
|
textAreaControl.ActiveTextAreaControl.Caret.CaretModeChanged += new EventHandler(CaretModeChanged); |
|
|
|
|
textAreaControl.ActiveTextAreaControl.Enter += new EventHandler(CaretUpdate); |
|
|
|
|
textAreaControl.ActiveTextAreaControl.Caret.PositionChanged += CaretUpdate; |
|
|
|
|
|
|
|
|
|
// KSL Start, New lines
|
|
|
|
|
// textAreaControl.FileNameChanged += new EventHandler(FileNameChangedEvent);
|
|
|
|
|
((Form)ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.Workbench).Activated += new EventHandler(GotFocusEvent); |
|
|
|
|
// KSL End
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
watcher = new FileChangeWatcher(this); |
|
|
|
|
} |
|
|
|
|
// KSL Start, new event handlers
|
|
|
|
|
|
|
|
|
|
public void ShowHelp() |
|
|
|
|
{ |
|
|
|
|
@ -225,62 +295,6 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
@@ -225,62 +295,6 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected void SetWatcher() |
|
|
|
|
{ |
|
|
|
|
try { |
|
|
|
|
if (this.watcher == null) { |
|
|
|
|
this.watcher = new FileSystemWatcher(); |
|
|
|
|
this.watcher.Changed += new FileSystemEventHandler(this.OnFileChangedEvent); |
|
|
|
|
} else { |
|
|
|
|
this.watcher.EnableRaisingEvents = false; |
|
|
|
|
} |
|
|
|
|
this.watcher.Path = Path.GetDirectoryName(textAreaControl.FileName); |
|
|
|
|
this.watcher.Filter = Path.GetFileName(textAreaControl.FileName); |
|
|
|
|
this.watcher.NotifyFilter = NotifyFilters.LastWrite; |
|
|
|
|
this.watcher.EnableRaisingEvents = true; |
|
|
|
|
} catch (Exception) { |
|
|
|
|
if (watcher != null) { |
|
|
|
|
watcher.Dispose(); |
|
|
|
|
} |
|
|
|
|
watcher = null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
protected virtual void GotFocusEvent(object sender, EventArgs e) |
|
|
|
|
{ |
|
|
|
|
if (wasChangedExternally) { |
|
|
|
|
wasChangedExternally = false; |
|
|
|
|
|
|
|
|
|
string message = StringParser.Parse("${res:ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor.TextEditorDisplayBinding.FileAlteredMessage}", new string[,] {{"File", Path.GetFullPath(textAreaControl.FileName)}}); |
|
|
|
|
if (IsDirty == false || |
|
|
|
|
MessageBox.Show(message, |
|
|
|
|
StringParser.Parse("${res:MainWindow.DialogName}"), |
|
|
|
|
MessageBoxButtons.YesNo, |
|
|
|
|
MessageBoxIcon.Question) == DialogResult.Yes) { |
|
|
|
|
Load(textAreaControl.FileName); |
|
|
|
|
} else { |
|
|
|
|
IsDirty = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void OnFileChangedEvent(object sender, FileSystemEventArgs e) |
|
|
|
|
{ |
|
|
|
|
if(e.ChangeType != WatcherChangeTypes.Deleted) { |
|
|
|
|
wasChangedExternally = true; |
|
|
|
|
if (textAreaControl.IsHandleCreated) |
|
|
|
|
textAreaControl.BeginInvoke(new MethodInvoker(OnFileChangedEventInvoked)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void OnFileChangedEventInvoked() |
|
|
|
|
{ |
|
|
|
|
if (((Form)ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.Workbench).Focused) { |
|
|
|
|
GotFocusEvent(this, EventArgs.Empty); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// KSL End
|
|
|
|
|
|
|
|
|
|
void TextAreaChangedEvent(object sender, DocumentEventArgs e) |
|
|
|
|
{ |
|
|
|
|
IsDirty = true; |
|
|
|
|
@ -298,13 +312,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
@@ -298,13 +312,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
|
|
|
|
|
if (this.IsUntitled) { |
|
|
|
|
ParserService.ClearParseInformation(this.UntitledName); |
|
|
|
|
} |
|
|
|
|
if (WorkbenchSingleton.MainForm != null) { |
|
|
|
|
WorkbenchSingleton.MainForm.Activated -= new EventHandler(GotFocusEvent); |
|
|
|
|
} |
|
|
|
|
if (this.watcher != null) { |
|
|
|
|
this.watcher.Dispose(); |
|
|
|
|
this.watcher = null; |
|
|
|
|
} |
|
|
|
|
watcher.Dispose(); |
|
|
|
|
textAreaControl.Dispose(); |
|
|
|
|
base.Dispose(); |
|
|
|
|
} |
|
|
|
|
@ -318,11 +326,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
@@ -318,11 +326,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
|
|
|
|
|
public override void Save(string fileName) |
|
|
|
|
{ |
|
|
|
|
OnSaving(EventArgs.Empty); |
|
|
|
|
// KSL, Start new line
|
|
|
|
|
if (watcher != null) { |
|
|
|
|
this.watcher.EnableRaisingEvents = false; |
|
|
|
|
} |
|
|
|
|
// KSL End
|
|
|
|
|
watcher.Disable(); |
|
|
|
|
|
|
|
|
|
if (!textAreaControl.CanSaveWithCurrentEncoding()) { |
|
|
|
|
if (MessageService.AskQuestion("The file cannot be saved with the current encoding " + |
|
|
|
|
@ -341,7 +345,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
@@ -341,7 +345,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
|
|
|
|
|
TitleName = Path.GetFileName(fileName); |
|
|
|
|
IsDirty = false; |
|
|
|
|
|
|
|
|
|
SetWatcher(); |
|
|
|
|
watcher.SetWatcher(this.FileName); |
|
|
|
|
OnSaved(new SaveEventArgs(true)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -354,7 +358,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
@@ -354,7 +358,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
|
|
|
|
|
FileName = fileName; |
|
|
|
|
TitleName = Path.GetFileName(fileName); |
|
|
|
|
IsDirty = false; |
|
|
|
|
SetWatcher(); |
|
|
|
|
watcher.SetWatcher(fileName); |
|
|
|
|
foreach (Bookmarks.SDBookmark mark in Bookmarks.BookmarkManager.GetBookmarks(fileName)) { |
|
|
|
|
mark.Document = textAreaControl.Document; |
|
|
|
|
textAreaControl.Document.BookmarkManager.Marks.Add(mark); |
|
|
|
|
|