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. 139
      src/Main/Base/Project/Resources/LoadSaveOptionPanel.xfrm
  2. 17
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/LoadSavePanel.cs
  3. 36
      src/Main/Base/Project/Src/TextEditor/Gui/Editor/TextEditorDisplayBinding.cs

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

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

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

@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
using System;
using System.Windows.Forms;
using ICSharpCode.Core;
using FileChangeWatcher = ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor.TextEditorDisplayBindingWrapper.FileChangeWatcher;
namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
{
@ -26,6 +27,8 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -26,6 +27,8 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
const string createBackupCopyCheckBox = "createBackupCopyCheckBox";
const string lineTerminatorStyleComboBox = "lineTerminatorStyleComboBox";
CheckBox autoLoadExternalChangesCheckBox, detectExternalChangesCheckBox;
public override void LoadPanelContents()
{
SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("Resources.LoadSaveOptionPanel.xfrm"));
@ -38,6 +41,17 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -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]).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()
@ -46,6 +60,9 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -46,6 +60,9 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
PropertyService.Set("SharpDevelop.CreateBackupCopy", ((CheckBox)ControlDictionary[createBackupCopyCheckBox]).Checked);
PropertyService.Set("SharpDevelop.LineTerminatorStyle", (LineTerminatorStyle)((ComboBox)ControlDictionary[lineTerminatorStyleComboBox]).SelectedIndex);
FileChangeWatcher.DetectExternalChangesOption = detectExternalChangesCheckBox.Checked;
FileChangeWatcher.AutoLoadExternalChangesOption = autoLoadExternalChangesCheckBox.Checked;
return true;
}
}

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

@ -99,6 +99,24 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor @@ -99,6 +99,24 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
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()
{
WorkbenchSingleton.MainForm.Activated -= GotFocusEvent;
@ -117,6 +135,8 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor @@ -117,6 +135,8 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
public void SetWatcher(string fileName)
{
this.fileName = fileName;
if (DetectExternalChangesOption == false)
return;
try {
if (this.watcher == null) {
this.watcher = new FileSystemWatcher();
@ -139,10 +159,12 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor @@ -139,10 +159,12 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
void OnFileChangedEvent(object sender, FileSystemEventArgs e)
{
if(e.ChangeType != WatcherChangeTypes.Deleted) {
if (e.ChangeType != WatcherChangeTypes.Deleted) {
wasChangedExternally = true;
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,11 +175,11 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor @@ -153,11 +175,11 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
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)
if ((AutoLoadExternalChangesOption && viewContent.IsDirty == false)
|| MessageBox.Show(message,
StringParser.Parse("${res:MainWindow.DialogName}"),
MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes)
{
viewContent.Load(fileName);
} else {

Loading…
Cancel
Save