Browse Source

Fixed saving CodeEditorOptions.

newNRvisualizers
Daniel Grunwald 14 years ago
parent
commit
c9860fb9bc
  1. 3
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj
  2. 13
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/CodeEditorOptions.cs
  3. 4
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XPathQueryControl.cs
  4. 2
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XPathQueryPad.cs
  5. 16
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditorOptions.cs
  6. 19
      src/Main/Core/Project/Src/Services/PropertyService/Properties.cs

3
src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj

@ -61,6 +61,9 @@
<Reference Include="System.Printing"> <Reference Include="System.Printing">
<RequiredTargetFramework>3.0</RequiredTargetFramework> <RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference> </Reference>
<Reference Include="System.Runtime.Serialization">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="System.Xaml" /> <Reference Include="System.Xaml" />

13
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/CodeEditorOptions.cs

@ -3,8 +3,8 @@
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.Runtime.Serialization;
using System.Windows.Data; using System.Windows.Data;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
@ -14,8 +14,17 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
[Serializable] [Serializable]
public class CodeEditorOptions : TextEditorOptions, ITextEditorOptions public class CodeEditorOptions : TextEditorOptions, ITextEditorOptions
{ {
static readonly Lazy<CodeEditorOptions> instance = new Lazy<CodeEditorOptions>(
() => PropertyService.Get("CodeEditorOptions", new CodeEditorOptions()));
public static CodeEditorOptions Instance { public static CodeEditorOptions Instance {
get { return PropertyService.Get("CodeEditorOptions", new CodeEditorOptions()); } get { return instance.Value; }
}
protected override void OnPropertyChanged(PropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
PropertyService.Set("CodeEditorOptions", this);
} }
// always support scrolling below the end of the document - it's better when folding is enabled // always support scrolling below the end of the document - it's better when folding is enabled

4
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XPathQueryControl.cs

@ -150,7 +150,7 @@ namespace ICSharpCode.XmlEditor
void LoadNamespaces(Properties properties) void LoadNamespaces(Properties properties)
{ {
string[] namespaces = properties.GetList<string>(NamespacesProperty); var namespaces = properties.GetList<string>(NamespacesProperty);
foreach (string ns in namespaces) { foreach (string ns in namespaces) {
XmlNamespace xmlNamespace = XmlNamespace.FromString(ns); XmlNamespace xmlNamespace = XmlNamespace.FromString(ns);
AddNamespace(xmlNamespace.Prefix, xmlNamespace.Name); AddNamespace(xmlNamespace.Prefix, xmlNamespace.Name);
@ -171,7 +171,7 @@ namespace ICSharpCode.XmlEditor
void LoadXPathQueryHistory(Properties properties) void LoadXPathQueryHistory(Properties properties)
{ {
XPathComboBox.Text = properties.Get(XPathComboBoxTextProperty, string.Empty); XPathComboBox.Text = properties.Get(XPathComboBoxTextProperty, string.Empty);
string[] xpaths = properties.GetList<string>(XPathComboBoxItemsProperty); var xpaths = properties.GetList<string>(XPathComboBoxItemsProperty);
foreach (string xpath in xpaths) { foreach (string xpath in xpaths) {
xpathComboBox.Items.Add(xpath); xpathComboBox.Items.Add(xpath);
} }

2
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XPathQueryPad.cs

@ -42,7 +42,7 @@ namespace ICSharpCode.XmlEditor
disposed = true; disposed = true;
WorkbenchSingleton.Workbench.ActiveViewContentChanged -= ActiveViewContentChanged; WorkbenchSingleton.Workbench.ActiveViewContentChanged -= ActiveViewContentChanged;
Properties properties = xpathQueryControl.CreateMemento(); Properties properties = xpathQueryControl.CreateMemento();
PropertyService.PropertiesContainer.SetNestedProperties(XPathQueryControlProperties, properties); PropertyService.SetNestedProperties(XPathQueryControlProperties, properties);
xpathQueryControl.Dispose(); xpathQueryControl.Dispose();
} }
} }

16
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditorOptions.cs

@ -194,7 +194,7 @@ namespace ICSharpCode.AvalonEdit
// The fields should be accessed only by their property - the fields might not be used // The fields should be accessed only by their property - the fields might not be used
// if someone overrides the property. // if someone overrides the property.
int _indentationSize = 4; int indentationSize = 4;
/// <summary> /// <summary>
/// Gets/Sets the width of one indentation unit. /// Gets/Sets the width of one indentation unit.
@ -202,7 +202,7 @@ namespace ICSharpCode.AvalonEdit
/// <remarks>The default value is 4.</remarks> /// <remarks>The default value is 4.</remarks>
[DefaultValue(4)] [DefaultValue(4)]
public virtual int IndentationSize { public virtual int IndentationSize {
get { return _indentationSize; } get { return indentationSize; }
set { set {
if (value < 1) if (value < 1)
throw new ArgumentOutOfRangeException("value", value, "value must be positive"); throw new ArgumentOutOfRangeException("value", value, "value must be positive");
@ -210,15 +210,15 @@ namespace ICSharpCode.AvalonEdit
// (it only crashed in the hundred thousands for me; but might crash earlier with larger fonts) // (it only crashed in the hundred thousands for me; but might crash earlier with larger fonts)
if (value > 1000) if (value > 1000)
throw new ArgumentOutOfRangeException("value", value, "indentation size is too large"); throw new ArgumentOutOfRangeException("value", value, "indentation size is too large");
if (_indentationSize != value) { if (indentationSize != value) {
_indentationSize = value; indentationSize = value;
OnPropertyChanged("IndentationSize"); OnPropertyChanged("IndentationSize");
OnPropertyChanged("IndentationString"); OnPropertyChanged("IndentationString");
} }
} }
} }
bool _convertTabsToSpaces; bool convertTabsToSpaces;
/// <summary> /// <summary>
/// Gets/Sets whether to use spaces for indentation instead of tabs. /// Gets/Sets whether to use spaces for indentation instead of tabs.
@ -226,10 +226,10 @@ namespace ICSharpCode.AvalonEdit
/// <remarks>The default value is <c>false</c>.</remarks> /// <remarks>The default value is <c>false</c>.</remarks>
[DefaultValue(false)] [DefaultValue(false)]
public virtual bool ConvertTabsToSpaces { public virtual bool ConvertTabsToSpaces {
get { return _convertTabsToSpaces; } get { return convertTabsToSpaces; }
set { set {
if (_convertTabsToSpaces != value) { if (convertTabsToSpaces != value) {
_convertTabsToSpaces = value; convertTabsToSpaces = value;
OnPropertyChanged("ConvertTabsToSpaces"); OnPropertyChanged("ConvertTabsToSpaces");
OnPropertyChanged("IndentationString"); OnPropertyChanged("IndentationString");
} }

19
src/Main/Core/Project/Src/Services/PropertyService/Properties.cs

@ -168,7 +168,12 @@ namespace ICSharpCode.Core
lock (syncRoot) { lock (syncRoot) {
object val; object val;
if (dict.TryGetValue(key, out val)) { if (dict.TryGetValue(key, out val)) {
return (T)Deserialize(val, typeof(T)); try {
return (T)Deserialize(val, typeof(T));
} catch (SerializationException ex) {
LoggingService.Warn(ex);
return defaultValue;
}
} else { } else {
return defaultValue; return defaultValue;
} }
@ -221,11 +226,15 @@ namespace ICSharpCode.Core
if (dict.TryGetValue(key, out val)) { if (dict.TryGetValue(key, out val)) {
object[] serializedArray = val as object[]; object[] serializedArray = val as object[];
if (serializedArray != null) { if (serializedArray != null) {
T[] array = new T[serializedArray.Length]; try {
for (int i = 0; i < array.Length; i++) { T[] array = new T[serializedArray.Length];
array[i] = (T)Deserialize(serializedArray[i], typeof(T)); for (int i = 0; i < array.Length; i++) {
array[i] = (T)Deserialize(serializedArray[i], typeof(T));
}
return array;
} catch (SerializationException ex) {
LoggingService.Warn(ex);
} }
return array;
} else { } else {
LoggingService.Warn("Properties.GetList(" + key + ") - this entry is not a list"); LoggingService.Warn("Properties.GetList(" + key + ") - this entry is not a list");
} }

Loading…
Cancel
Save