Browse Source

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

4.1
Daniel Grunwald 15 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
public SettingsDocument(XmlElement settingsFile, ISettingsEntryHost host) public SettingsDocument(XmlElement settingsFile, ISettingsEntryHost host)
{ {
if (settingsFile == null)
throw new ArgumentNullException("settingsFile");
if (host == null)
throw new ArgumentNullException("host");
generatedClassNamespace = settingsFile.GetAttribute("GeneratedClassNamespace"); generatedClassNamespace = settingsFile.GetAttribute("GeneratedClassNamespace");
generatedClassName = settingsFile.GetAttribute("GeneratedClassName"); generatedClassName = settingsFile.GetAttribute("GeneratedClassName");
this.UseMySettingsClassName = "true".Equals(settingsFile.GetAttribute("UseMySettingsClassName"), StringComparison.OrdinalIgnoreCase); this.UseMySettingsClassName = "true".Equals(settingsFile.GetAttribute("UseMySettingsClassName"), StringComparison.OrdinalIgnoreCase);
XmlElement settings = settingsFile["Settings"]; XmlElement settings = settingsFile["Settings"];
if (settings == null)
throw new FormatException("Not a settings file.");
foreach (XmlNode node in settings.ChildNodes) { foreach (XmlNode node in settings.ChildNodes) {
if (node is XmlElement) { if (node is XmlElement) {

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

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

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

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

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

@ -16,7 +16,7 @@ using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.SettingsEditor namespace ICSharpCode.SettingsEditor
{ {
public class SettingsViewContent : AbstractViewContent, IHasPropertyContainer public class SettingsViewContent : AbstractViewContentHandlingLoadErrors, IHasPropertyContainer
{ {
SettingsView view = new SettingsView(); SettingsView view = new SettingsView();
PropertyContainer propertyContainer = new PropertyContainer(); PropertyContainer propertyContainer = new PropertyContainer();
@ -36,6 +36,7 @@ namespace ICSharpCode.SettingsEditor
if (appConfigFile != null) if (appConfigFile != null)
appConfigFile.MakeDirty(); appConfigFile.MakeDirty();
}; };
this.UserContent = view;
} }
void TryOpenAppConfig(bool createIfNotExists) void TryOpenAppConfig(bool createIfNotExists)
@ -57,13 +58,7 @@ namespace ICSharpCode.SettingsEditor
} }
} }
public override object Control { protected override void LoadInternal(OpenedFile file, Stream stream)
get {
return view;
}
}
public override void Load(OpenedFile file, Stream stream)
{ {
if (file == PrimaryFile) { if (file == PrimaryFile) {
try { try {
@ -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) { if (file == PrimaryFile) {
using (XmlTextWriter writer = new XmlTextWriter(stream, Encoding.UTF8)) { 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
Properties memento = GetMemento(newView); Properties memento = GetMemento(newView);
using (Stream sourceStream = OpenRead()) { using (Stream sourceStream = OpenRead()) {
IViewContent oldView = currentView; IViewContent oldView = currentView;
bool success = false;
try { try {
currentView = newView; currentView = newView;
// don't reset fileData if the file is untitled, because OpenRead() wouldn't be able to read it otherwise // don't reset fileData if the file is untitled, because OpenRead() wouldn't be able to read it otherwise
if (this.IsUntitled == false) if (this.IsUntitled == false)
fileData = null; fileData = null;
newView.Load(this, sourceStream); newView.Load(this, sourceStream);
} catch { success = true;
// stay with old view in case of exceptions } finally {
currentView = oldView; // Use finally instead of catch+rethrow so that the debugger
throw; // breaks at the original crash location.
if (!success) {
// stay with old view in case of exceptions
currentView = oldView;
}
} }
} }
RestoreMemento(newView, memento); RestoreMemento(newView, memento);

Loading…
Cancel
Save