Browse Source

Fixed crash when opening an invalid file in the settings editor (using AbstractViewContentHandlingLoadErrors).

4.1
Daniel Grunwald 14 years ago
parent
commit
e2e52d35d5
  1. 6
      src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsDocument.cs
  2. 2
      src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsEntry.cs
  3. 1
      src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.cs
  4. 13
      src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsViewContent.cs
  5. 13
      src/Main/Base/Project/Src/Services/File/OpenedFile.cs

6
src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsDocument.cs

@ -49,11 +49,17 @@ namespace ICSharpCode.SettingsEditor @@ -49,11 +49,17 @@ namespace ICSharpCode.SettingsEditor
public SettingsDocument(XmlElement settingsFile, ISettingsEntryHost host)
{
if (settingsFile == null)
throw new ArgumentNullException("settingsFile");
if (host == null)
throw new ArgumentNullException("host");
generatedClassNamespace = settingsFile.GetAttribute("GeneratedClassNamespace");
generatedClassName = settingsFile.GetAttribute("GeneratedClassName");
this.UseMySettingsClassName = "true".Equals(settingsFile.GetAttribute("UseMySettingsClassName"), StringComparison.OrdinalIgnoreCase);
XmlElement settings = settingsFile["Settings"];
if (settings == null)
throw new FormatException("Not a settings file.");
foreach (XmlNode node in settings.ChildNodes) {
if (node is XmlElement) {

2
src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsEntry.cs

@ -53,6 +53,8 @@ namespace ICSharpCode.SettingsEditor @@ -53,6 +53,8 @@ namespace ICSharpCode.SettingsEditor
{
if (element == null)
throw new ArgumentNullException("element");
if (element["Value"] == null)
throw new FormatException("Not a settings file.");
description = element.GetAttribute("Description");
if (!bool.TryParse(element.GetAttribute("GenerateDefaultValueInCode"), out generateDefaultValueInCode))
generateDefaultValueInCode = GenerateDefaultValueInCodeDefault;

1
src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.cs

@ -67,6 +67,7 @@ namespace ICSharpCode.SettingsEditor @@ -67,6 +67,7 @@ namespace ICSharpCode.SettingsEditor
public void ShowEntries(IList<SettingsEntry> list)
{
bindingSource.Clear();
foreach (SettingsEntry entry in list) {
bindingSource.Add(entry);
}

13
src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsViewContent.cs

@ -16,7 +16,7 @@ using ICSharpCode.SharpDevelop.Project; @@ -16,7 +16,7 @@ using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.SettingsEditor
{
public class SettingsViewContent : AbstractViewContent, IHasPropertyContainer
public class SettingsViewContent : AbstractViewContentHandlingLoadErrors, IHasPropertyContainer
{
SettingsView view = new SettingsView();
PropertyContainer propertyContainer = new PropertyContainer();
@ -36,6 +36,7 @@ namespace ICSharpCode.SettingsEditor @@ -36,6 +36,7 @@ namespace ICSharpCode.SettingsEditor
if (appConfigFile != null)
appConfigFile.MakeDirty();
};
this.UserContent = view;
}
void TryOpenAppConfig(bool createIfNotExists)
@ -57,13 +58,7 @@ namespace ICSharpCode.SettingsEditor @@ -57,13 +58,7 @@ namespace ICSharpCode.SettingsEditor
}
}
public override object Control {
get {
return view;
}
}
public override void Load(OpenedFile file, Stream stream)
protected override void LoadInternal(OpenedFile file, Stream stream)
{
if (file == PrimaryFile) {
try {
@ -89,7 +84,7 @@ namespace ICSharpCode.SettingsEditor @@ -89,7 +84,7 @@ namespace ICSharpCode.SettingsEditor
}
}
public override void Save(OpenedFile file, Stream stream)
protected override void SaveInternal(OpenedFile file, Stream stream)
{
if (file == PrimaryFile) {
using (XmlTextWriter writer = new XmlTextWriter(stream, Encoding.UTF8)) {

13
src/Main/Base/Project/Src/Services/File/OpenedFile.cs

@ -285,16 +285,21 @@ namespace ICSharpCode.SharpDevelop @@ -285,16 +285,21 @@ namespace ICSharpCode.SharpDevelop
Properties memento = GetMemento(newView);
using (Stream sourceStream = OpenRead()) {
IViewContent oldView = currentView;
bool success = false;
try {
currentView = newView;
// don't reset fileData if the file is untitled, because OpenRead() wouldn't be able to read it otherwise
if (this.IsUntitled == false)
fileData = null;
newView.Load(this, sourceStream);
} catch {
// stay with old view in case of exceptions
currentView = oldView;
throw;
success = true;
} finally {
// Use finally instead of catch+rethrow so that the debugger
// breaks at the original crash location.
if (!success) {
// stay with old view in case of exceptions
currentView = oldView;
}
}
}
RestoreMemento(newView, memento);

Loading…
Cancel
Save