Browse Source

Implemented SD2-1137: Option to auto-load changes when file changed externally

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2133 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
a9a5ae9d42
  1. 61
      src/Main/Base/Project/Resources/LoadSaveOptionPanel.xfrm
  2. 17
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/LoadSavePanel.cs
  3. 30
      src/Main/Base/Project/Src/TextEditor/Gui/Editor/TextEditorDisplayBinding.cs

61
src/Main/Base/Project/Resources/LoadSaveOptionPanel.xfrm

@ -1,59 +1,76 @@
<Components version="1.0"> <Components version="1.0">
<System.Windows.Forms.UserControl> <System.Windows.Forms.UserControl>
<Name value="MyUserControl" /> <Name value="MyUserControl" />
<DockPadding value="" /> <ClientSize value="{Width=280, Height=233}" />
<Size value="{Width=280, Height=208}" />
<Controls> <Controls>
<System.Windows.Forms.GroupBox> <System.Windows.Forms.GroupBox>
<Name value="groupBox2" /> <Name value="groupBox2" />
<TabIndex value="1" /> <Location value="8, 108" />
<Location value="{X=8,Y=80}" />
<Anchor value="Top, Left, Right" />
<Size value="{Width=264, Height=112}" />
<Text value="${res:Dialog.Options.IDEOptions.LoadSaveOptions.SaveLabel}" /> <Text value="${res:Dialog.Options.IDEOptions.LoadSaveOptions.SaveLabel}" />
<Anchor value="Top, Left, Right" />
<Size value="264, 112" />
<TabIndex value="1" />
<Controls> <Controls>
<System.Windows.Forms.ComboBox> <System.Windows.Forms.ComboBox>
<Name value="lineTerminatorStyleComboBox" /> <Name value="lineTerminatorStyleComboBox" />
<Anchor value="Top, Left, Right" /> <Size value="104, 21" />
<TabIndex value="2" /> <TabIndex value="2" />
<Location value="{X=8,Y=72}" />
<Size value="{Width=104, Height=21}" />
<DropDownStyle value="DropDownList" /> <DropDownStyle value="DropDownList" />
<Location value="8, 72" />
<Anchor value="Top, Left, Right" />
</System.Windows.Forms.ComboBox> </System.Windows.Forms.ComboBox>
<System.Windows.Forms.Label> <System.Windows.Forms.Label>
<Name value="label" /> <Name value="label" />
<Location value="8, 49" />
<Text value="${res:Dialog.Options.IDEOptions.LoadSaveOptions.LineTerminatorStyleGroupBox}" /> <Text value="${res:Dialog.Options.IDEOptions.LoadSaveOptions.LineTerminatorStyleGroupBox}" />
<TextAlign value="BottomLeft" />
<Anchor value="Top, Left, Right" /> <Anchor value="Top, Left, Right" />
<TextAlign value="BottomLeft" />
<Size value="248, 23" />
<TabIndex value="1" /> <TabIndex value="1" />
<Size value="{Width=248, Height=23}" />
<Location value="{X=8,Y=49}" />
</System.Windows.Forms.Label> </System.Windows.Forms.Label>
<System.Windows.Forms.CheckBox> <System.Windows.Forms.CheckBox>
<Name value="createBackupCopyCheckBox" /> <Name value="createBackupCopyCheckBox" />
<Location value="{X=8,Y=25}" /> <Location value="8, 25" />
<Size value="{Width=248, Height=24}" />
<Text value="${res:Dialog.Options.IDEOptions.LoadSaveOptions.CreateBackupCopyCheckBox}" /> <Text value="${res:Dialog.Options.IDEOptions.LoadSaveOptions.CreateBackupCopyCheckBox}" />
<Anchor value="Top, Left, Right" />
<TabIndex value="0" /> <TabIndex value="0" />
<Size value="248, 24" />
<Anchor value="Top, Left, Right" />
</System.Windows.Forms.CheckBox> </System.Windows.Forms.CheckBox>
</Controls> </Controls>
</System.Windows.Forms.GroupBox> </System.Windows.Forms.GroupBox>
<System.Windows.Forms.GroupBox> <System.Windows.Forms.GroupBox>
<Name value="groupBox" /> <Name value="groupBox" />
<TabIndex value="0" /> <Location value="8, 8" />
<Location value="{X=8,Y=8}" />
<Anchor value="Top, Left, Right" />
<Size value="{Width=264, Height=64}" />
<Text value="${res:Dialog.Options.IDEOptions.LoadSaveOptions.LoadLabel}" /> <Text value="${res:Dialog.Options.IDEOptions.LoadSaveOptions.LoadLabel}" />
<Anchor value="Top, Left, Right" />
<Size value="264, 94" />
<TabIndex value="0" />
<Controls> <Controls>
<System.Windows.Forms.CheckBox>
<Name value="autoLoadExternalChangesCheckBox" />
<Location value="21, 64" />
<Text value="${res:Dialog.Options.IDEOptions.LoadSaveOptions.AutoLoadExternalChanges}" />
<TabIndex value="2" />
<Size value="235, 24" />
<UseVisualStyleBackColor value="True" />
<Anchor value="Top, Left, Right" />
</System.Windows.Forms.CheckBox>
<System.Windows.Forms.CheckBox>
<Name value="detectExternalChangesCheckBox" />
<Location value="8, 46" />
<Text value="${res:Dialog.Options.IDEOptions.LoadSaveOptions.DetectExternalChanges}" />
<TabIndex value="1" />
<Size value="248, 24" />
<UseVisualStyleBackColor value="True" />
<Anchor value="Top, Left, Right" />
</System.Windows.Forms.CheckBox>
<System.Windows.Forms.CheckBox> <System.Windows.Forms.CheckBox>
<Name value="loadUserDataCheckBox" /> <Name value="loadUserDataCheckBox" />
<Location value="{X=8,Y=25}" /> <Location value="8, 25" />
<Size value="{Width=248, Height=24}" />
<Text value="${res:Dialog.Options.IDEOptions.LoadSaveOptions.LoadUserDataCheckBox}" /> <Text value="${res:Dialog.Options.IDEOptions.LoadSaveOptions.LoadUserDataCheckBox}" />
<Anchor value="Top, Left, Right" />
<TabIndex value="0" /> <TabIndex value="0" />
<Size value="248, 24" />
<Anchor value="Top, Left, Right" />
</System.Windows.Forms.CheckBox> </System.Windows.Forms.CheckBox>
</Controls> </Controls>
</System.Windows.Forms.GroupBox> </System.Windows.Forms.GroupBox>

17
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/LoadSavePanel.cs

@ -8,6 +8,7 @@
using System; using System;
using System.Windows.Forms; using System.Windows.Forms;
using ICSharpCode.Core; using ICSharpCode.Core;
using FileChangeWatcher = ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor.TextEditorDisplayBindingWrapper.FileChangeWatcher;
namespace ICSharpCode.SharpDevelop.Gui.OptionPanels namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
{ {
@ -26,6 +27,8 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
const string createBackupCopyCheckBox = "createBackupCopyCheckBox"; const string createBackupCopyCheckBox = "createBackupCopyCheckBox";
const string lineTerminatorStyleComboBox = "lineTerminatorStyleComboBox"; const string lineTerminatorStyleComboBox = "lineTerminatorStyleComboBox";
CheckBox autoLoadExternalChangesCheckBox, detectExternalChangesCheckBox;
public override void LoadPanelContents() public override void LoadPanelContents()
{ {
SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("Resources.LoadSaveOptionPanel.xfrm")); SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("Resources.LoadSaveOptionPanel.xfrm"));
@ -38,6 +41,17 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
((ComboBox)ControlDictionary[lineTerminatorStyleComboBox]).Items.Add(StringParser.Parse("${res:Dialog.Options.IDEOptions.LoadSaveOptions.UnixRadioButton}")); ((ComboBox)ControlDictionary[lineTerminatorStyleComboBox]).Items.Add(StringParser.Parse("${res:Dialog.Options.IDEOptions.LoadSaveOptions.UnixRadioButton}"));
((ComboBox)ControlDictionary[lineTerminatorStyleComboBox]).SelectedIndex = (int)(LineTerminatorStyle)PropertyService.Get("SharpDevelop.LineTerminatorStyle", LineTerminatorStyle.Windows); ((ComboBox)ControlDictionary[lineTerminatorStyleComboBox]).SelectedIndex = (int)(LineTerminatorStyle)PropertyService.Get("SharpDevelop.LineTerminatorStyle", LineTerminatorStyle.Windows);
autoLoadExternalChangesCheckBox = Get<CheckBox>("autoLoadExternalChanges");
detectExternalChangesCheckBox = Get<CheckBox>("detectExternalChanges");
detectExternalChangesCheckBox.CheckedChanged += delegate {
autoLoadExternalChangesCheckBox.Enabled = detectExternalChangesCheckBox.Checked;
};
autoLoadExternalChangesCheckBox.Enabled = detectExternalChangesCheckBox.Checked;
detectExternalChangesCheckBox.Checked = FileChangeWatcher.DetectExternalChangesOption;
autoLoadExternalChangesCheckBox.Checked = FileChangeWatcher.AutoLoadExternalChangesOption;
} }
public override bool StorePanelContents() public override bool StorePanelContents()
@ -46,6 +60,9 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
PropertyService.Set("SharpDevelop.CreateBackupCopy", ((CheckBox)ControlDictionary[createBackupCopyCheckBox]).Checked); PropertyService.Set("SharpDevelop.CreateBackupCopy", ((CheckBox)ControlDictionary[createBackupCopyCheckBox]).Checked);
PropertyService.Set("SharpDevelop.LineTerminatorStyle", (LineTerminatorStyle)((ComboBox)ControlDictionary[lineTerminatorStyleComboBox]).SelectedIndex); PropertyService.Set("SharpDevelop.LineTerminatorStyle", (LineTerminatorStyle)((ComboBox)ControlDictionary[lineTerminatorStyleComboBox]).SelectedIndex);
FileChangeWatcher.DetectExternalChangesOption = detectExternalChangesCheckBox.Checked;
FileChangeWatcher.AutoLoadExternalChangesOption = autoLoadExternalChangesCheckBox.Checked;
return true; return true;
} }
} }

30
src/Main/Base/Project/Src/TextEditor/Gui/Editor/TextEditorDisplayBinding.cs

@ -99,6 +99,24 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
WorkbenchSingleton.MainForm.Activated += GotFocusEvent; WorkbenchSingleton.MainForm.Activated += GotFocusEvent;
} }
public static bool DetectExternalChangesOption {
get {
return PropertyService.Get("SharpDevelop.FileChangeWatcher.DetectExternalChanges", true);
}
set {
PropertyService.Set("SharpDevelop.FileChangeWatcher.DetectExternalChanges", value);
}
}
public static bool AutoLoadExternalChangesOption {
get {
return PropertyService.Get("SharpDevelop.FileChangeWatcher.AutoLoadExternalChanges", true);
}
set {
PropertyService.Set("SharpDevelop.FileChangeWatcher.AutoLoadExternalChanges", value);
}
}
public void Dispose() public void Dispose()
{ {
WorkbenchSingleton.MainForm.Activated -= GotFocusEvent; WorkbenchSingleton.MainForm.Activated -= GotFocusEvent;
@ -117,6 +135,8 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
public void SetWatcher(string fileName) public void SetWatcher(string fileName)
{ {
this.fileName = fileName; this.fileName = fileName;
if (DetectExternalChangesOption == false)
return;
try { try {
if (this.watcher == null) { if (this.watcher == null) {
this.watcher = new FileSystemWatcher(); this.watcher = new FileSystemWatcher();
@ -139,10 +159,12 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
void OnFileChangedEvent(object sender, FileSystemEventArgs e) void OnFileChangedEvent(object sender, FileSystemEventArgs e)
{ {
if(e.ChangeType != WatcherChangeTypes.Deleted) { if (e.ChangeType != WatcherChangeTypes.Deleted) {
wasChangedExternally = true; wasChangedExternally = true;
if (ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.Workbench.IsActiveWindow) { if (ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.Workbench.IsActiveWindow) {
GotFocusEvent(this, EventArgs.Empty); // delay showing message a bit, prevents showing two messages
// when the file changes twice in quick succession
WorkbenchSingleton.SafeThreadAsyncCall(GotFocusEvent, this, EventArgs.Empty);
} }
} }
} }
@ -153,8 +175,8 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
wasChangedExternally = false; wasChangedExternally = false;
string message = StringParser.Parse("${res:ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor.TextEditorDisplayBinding.FileAlteredMessage}", new string[,] {{"File", Path.GetFullPath(fileName)}}); string message = StringParser.Parse("${res:ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor.TextEditorDisplayBinding.FileAlteredMessage}", new string[,] {{"File", Path.GetFullPath(fileName)}});
if (viewContent.IsDirty == false || if ((AutoLoadExternalChangesOption && viewContent.IsDirty == false)
MessageBox.Show(message, || MessageBox.Show(message,
StringParser.Parse("${res:MainWindow.DialogName}"), StringParser.Parse("${res:MainWindow.DialogName}"),
MessageBoxButtons.YesNo, MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes) MessageBoxIcon.Question) == DialogResult.Yes)

Loading…
Cancel
Save