Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1989 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
9 changed files with 538 additions and 17 deletions
@ -0,0 +1,69 @@ |
|||||||
|
/* |
||||||
|
* Created by SharpDevelop. |
||||||
|
* User: Daniel Grunwald |
||||||
|
* Date: 10/29/2006 |
||||||
|
* Time: 8:30 AM |
||||||
|
* |
||||||
|
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||||
|
*/ |
||||||
|
|
||||||
|
using System; |
||||||
|
using System.ComponentModel; |
||||||
|
using System.Reflection; |
||||||
|
|
||||||
|
namespace ICSharpCode.SettingsEditor |
||||||
|
{ |
||||||
|
public class ProxyPropertyDescriptor : PropertyDescriptor |
||||||
|
{ |
||||||
|
PropertyDescriptor baseDescriptor; |
||||||
|
|
||||||
|
public ProxyPropertyDescriptor(PropertyDescriptor baseDescriptor) |
||||||
|
: base(baseDescriptor) |
||||||
|
{ |
||||||
|
this.baseDescriptor = baseDescriptor; |
||||||
|
} |
||||||
|
|
||||||
|
public override Type ComponentType { |
||||||
|
get { |
||||||
|
return baseDescriptor.ComponentType; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public override bool IsReadOnly { |
||||||
|
get { |
||||||
|
return baseDescriptor.IsReadOnly; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public override bool CanResetValue(object component) |
||||||
|
{ |
||||||
|
return baseDescriptor.CanResetValue(component); |
||||||
|
} |
||||||
|
|
||||||
|
public override object GetValue(object component) |
||||||
|
{ |
||||||
|
return baseDescriptor.GetValue(component); |
||||||
|
} |
||||||
|
|
||||||
|
public override void ResetValue(object component) |
||||||
|
{ |
||||||
|
baseDescriptor.ResetValue(component); |
||||||
|
} |
||||||
|
|
||||||
|
public override void SetValue(object component, object value) |
||||||
|
{ |
||||||
|
baseDescriptor.SetValue(component, value); |
||||||
|
} |
||||||
|
|
||||||
|
public override bool ShouldSerializeValue(object component) |
||||||
|
{ |
||||||
|
return baseDescriptor.ShouldSerializeValue(component); |
||||||
|
} |
||||||
|
|
||||||
|
public override Type PropertyType { |
||||||
|
get { |
||||||
|
return baseDescriptor.PropertyType; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,197 @@ |
|||||||
|
/* |
||||||
|
* Created by SharpDevelop. |
||||||
|
* User: Daniel Grunwald |
||||||
|
* Date: 10/28/2006 |
||||||
|
* Time: 11:16 PM |
||||||
|
* |
||||||
|
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||||
|
*/ |
||||||
|
|
||||||
|
using System; |
||||||
|
using System.ComponentModel; |
||||||
|
using System.Xml; |
||||||
|
using System.Configuration; |
||||||
|
using ICSharpCode.SharpDevelop.Gui; |
||||||
|
|
||||||
|
namespace ICSharpCode.SettingsEditor |
||||||
|
{ |
||||||
|
public enum SettingScope |
||||||
|
{ |
||||||
|
Application, User |
||||||
|
} |
||||||
|
|
||||||
|
public class SettingsEntry : LocalizedObject |
||||||
|
{ |
||||||
|
string description; |
||||||
|
bool generateDefaultValueInCode = true; |
||||||
|
string name; |
||||||
|
string provider = ""; |
||||||
|
bool roaming; |
||||||
|
SettingScope scope = SettingScope.User; |
||||||
|
Type type; |
||||||
|
object value; |
||||||
|
|
||||||
|
public SettingsEntry() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public SettingsEntry(XmlElement element) |
||||||
|
{ |
||||||
|
description = element.GetAttribute("Description"); |
||||||
|
if (!bool.TryParse(element.GetAttribute("GenerateDefaultValueInCode"), out generateDefaultValueInCode)) |
||||||
|
generateDefaultValueInCode = true; |
||||||
|
name = element.GetAttribute("Name"); |
||||||
|
provider = element.GetAttribute("Provider"); |
||||||
|
bool.TryParse(element.GetAttribute("Roaming"), out roaming); |
||||||
|
if ("Application".Equals(element.GetAttribute("Scope"), StringComparison.OrdinalIgnoreCase)) { |
||||||
|
scope = SettingScope.Application; |
||||||
|
} else { |
||||||
|
scope = SettingScope.User; |
||||||
|
} |
||||||
|
type = GetType(element.GetAttribute("Type")); |
||||||
|
if (type != null && type != typeof(string)) { |
||||||
|
TypeConverter c = TypeDescriptor.GetConverter(type); |
||||||
|
SettingsSerializeAs ssa; |
||||||
|
if (c.CanConvertFrom(typeof(string)) && c.CanConvertTo(typeof(string))) { |
||||||
|
ssa = SettingsSerializeAs.String; |
||||||
|
} else { |
||||||
|
ssa = SettingsSerializeAs.Xml; |
||||||
|
} |
||||||
|
SettingsProperty p = new SettingsProperty(name); |
||||||
|
p.PropertyType = type; |
||||||
|
p.SerializeAs = ssa; |
||||||
|
SettingsPropertyValue v = new SettingsPropertyValue(p); |
||||||
|
v.SerializedValue = element["Value"].InnerText; |
||||||
|
this.value = v.PropertyValue; |
||||||
|
} else { |
||||||
|
this.value = element["Value"].InnerText; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
Type GetType(string typeName) |
||||||
|
{ |
||||||
|
return typeof(object).Assembly.GetType(typeName, false) |
||||||
|
?? typeof(Uri).Assembly.GetType(typeName, false) |
||||||
|
?? typeof(System.Data.DataRow).Assembly.GetType(typeName, false); |
||||||
|
} |
||||||
|
|
||||||
|
[LocalizedProperty("Description", |
||||||
|
Description="Description of the setting.")] |
||||||
|
public string Description { |
||||||
|
get { return description; } |
||||||
|
set { description = value; } |
||||||
|
} |
||||||
|
|
||||||
|
[LocalizedProperty("Generate default value in code", |
||||||
|
Description="Specifies whether the value should be saved as attribute in the generated code.")] |
||||||
|
[DefaultValue(true)] |
||||||
|
public bool GenerateDefaultValueInCode { |
||||||
|
get { return generateDefaultValueInCode; } |
||||||
|
set { generateDefaultValueInCode = value; } |
||||||
|
} |
||||||
|
|
||||||
|
[LocalizedProperty("Name", |
||||||
|
Description="Name of the setting.")] |
||||||
|
public string Name { |
||||||
|
get { return name; } |
||||||
|
set { name = value; } |
||||||
|
} |
||||||
|
|
||||||
|
[LocalizedProperty("Provider", |
||||||
|
Description="The provider used to manage the setting.")] |
||||||
|
public string Provider { |
||||||
|
get { return provider; } |
||||||
|
set { provider = value; } |
||||||
|
} |
||||||
|
|
||||||
|
[LocalizedProperty("Roaming", |
||||||
|
Description="Specifies whether changes to the setting are stored in 'Application Data' (Roaming=true) or 'Local Application Data' (Roaming=false)")] |
||||||
|
public bool Roaming { |
||||||
|
get { return roaming; } |
||||||
|
set { roaming = value; } |
||||||
|
} |
||||||
|
|
||||||
|
[LocalizedProperty("Scope", |
||||||
|
Description="Specifies whether the setting is per-application (read-only) or per-user (read/write).")] |
||||||
|
public SettingScope Scope { |
||||||
|
get { return scope; } |
||||||
|
set { scope = value; } |
||||||
|
} |
||||||
|
|
||||||
|
[LocalizedProperty("SerializedSettingType", |
||||||
|
Description="The type used for the setting in the strongly-typed settings class.")] |
||||||
|
public string SerializedSettingType { |
||||||
|
get { |
||||||
|
if (type != null) |
||||||
|
return type.FullName; |
||||||
|
else |
||||||
|
return "(null)"; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[LocalizedProperty("Value", |
||||||
|
Description="The default value of the setting.")] |
||||||
|
public object Value { |
||||||
|
get { return value; } |
||||||
|
set { |
||||||
|
if (type == null || type.IsInstanceOfType(value)) { |
||||||
|
this.value = value; |
||||||
|
} else { |
||||||
|
throw new ArgumentException("Invalid type for property value."); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#region Custom property descriptors
|
||||||
|
protected override void FilterProperties(PropertyDescriptorCollection col) |
||||||
|
{ |
||||||
|
base.FilterProperties(col); |
||||||
|
PropertyDescriptor oldValue = col["Value"]; |
||||||
|
col.Remove(oldValue); |
||||||
|
col.Add(new CustomValuePropertyDescriptor(oldValue, type)); |
||||||
|
PropertyDescriptor oldRoaming = col["Roaming"]; |
||||||
|
col.Remove(oldRoaming); |
||||||
|
col.Add(new RoamingPropertyDescriptor(oldRoaming, this)); |
||||||
|
} |
||||||
|
|
||||||
|
class RoamingPropertyDescriptor : ProxyPropertyDescriptor |
||||||
|
{ |
||||||
|
SettingsEntry entry; |
||||||
|
|
||||||
|
public RoamingPropertyDescriptor(PropertyDescriptor baseDescriptor, SettingsEntry entry) |
||||||
|
: base(baseDescriptor) |
||||||
|
{ |
||||||
|
this.entry = entry; |
||||||
|
} |
||||||
|
|
||||||
|
public override bool IsReadOnly { |
||||||
|
get { |
||||||
|
return entry.Scope == SettingScope.Application; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class CustomValuePropertyDescriptor : ProxyPropertyDescriptor |
||||||
|
{ |
||||||
|
Type newPropertyType; |
||||||
|
|
||||||
|
public CustomValuePropertyDescriptor(PropertyDescriptor baseDescriptor, Type newPropertyType) |
||||||
|
: base(baseDescriptor) |
||||||
|
{ |
||||||
|
this.newPropertyType = newPropertyType; |
||||||
|
} |
||||||
|
|
||||||
|
public override Type PropertyType { |
||||||
|
get { |
||||||
|
return newPropertyType; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public override object GetEditor(Type editorBaseType) |
||||||
|
{ |
||||||
|
return TypeDescriptor.GetEditor(newPropertyType, editorBaseType); |
||||||
|
} |
||||||
|
} |
||||||
|
#endregion
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,120 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<root> |
||||||
|
<!-- |
||||||
|
Microsoft ResX Schema |
||||||
|
|
||||||
|
Version 2.0 |
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format |
||||||
|
that is mostly human readable. The generation and parsing of the |
||||||
|
various data types are done through the TypeConverter classes |
||||||
|
associated with the data types. |
||||||
|
|
||||||
|
Example: |
||||||
|
|
||||||
|
... ado.net/XML headers & schema ... |
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader> |
||||||
|
<resheader name="version">2.0</resheader> |
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> |
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> |
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> |
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> |
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> |
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value> |
||||||
|
</data> |
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> |
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> |
||||||
|
<comment>This is a comment</comment> |
||||||
|
</data> |
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple |
||||||
|
name/value pairs. |
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a |
||||||
|
type or mimetype. Type corresponds to a .NET class that support |
||||||
|
text/value conversion through the TypeConverter architecture. |
||||||
|
Classes that don't support this are serialized and stored with the |
||||||
|
mimetype set. |
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the |
||||||
|
ResXResourceReader how to depersist the object. This is currently not |
||||||
|
extensible. For a given mimetype the value must be set accordingly: |
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format |
||||||
|
that the ResXResourceWriter will generate, however the reader can |
||||||
|
read any of the formats listed below. |
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64 |
||||||
|
value : The object must be serialized with |
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter |
||||||
|
: and then encoded with base64 encoding. |
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64 |
||||||
|
value : The object must be serialized with |
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter |
||||||
|
: and then encoded with base64 encoding. |
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64 |
||||||
|
value : The object must be serialized into a byte array |
||||||
|
: using a System.ComponentModel.TypeConverter |
||||||
|
: and then encoded with base64 encoding. |
||||||
|
--> |
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> |
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> |
||||||
|
<xsd:element name="root" msdata:IsDataSet="true"> |
||||||
|
<xsd:complexType> |
||||||
|
<xsd:choice maxOccurs="unbounded"> |
||||||
|
<xsd:element name="metadata"> |
||||||
|
<xsd:complexType> |
||||||
|
<xsd:sequence> |
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" /> |
||||||
|
</xsd:sequence> |
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" /> |
||||||
|
<xsd:attribute name="type" type="xsd:string" /> |
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" /> |
||||||
|
<xsd:attribute ref="xml:space" /> |
||||||
|
</xsd:complexType> |
||||||
|
</xsd:element> |
||||||
|
<xsd:element name="assembly"> |
||||||
|
<xsd:complexType> |
||||||
|
<xsd:attribute name="alias" type="xsd:string" /> |
||||||
|
<xsd:attribute name="name" type="xsd:string" /> |
||||||
|
</xsd:complexType> |
||||||
|
</xsd:element> |
||||||
|
<xsd:element name="data"> |
||||||
|
<xsd:complexType> |
||||||
|
<xsd:sequence> |
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> |
||||||
|
</xsd:sequence> |
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> |
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> |
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> |
||||||
|
<xsd:attribute ref="xml:space" /> |
||||||
|
</xsd:complexType> |
||||||
|
</xsd:element> |
||||||
|
<xsd:element name="resheader"> |
||||||
|
<xsd:complexType> |
||||||
|
<xsd:sequence> |
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
||||||
|
</xsd:sequence> |
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" /> |
||||||
|
</xsd:complexType> |
||||||
|
</xsd:element> |
||||||
|
</xsd:choice> |
||||||
|
</xsd:complexType> |
||||||
|
</xsd:element> |
||||||
|
</xsd:schema> |
||||||
|
<resheader name="resmimetype"> |
||||||
|
<value>text/microsoft-resx</value> |
||||||
|
</resheader> |
||||||
|
<resheader name="version"> |
||||||
|
<value>2.0</value> |
||||||
|
</resheader> |
||||||
|
<resheader name="reader"> |
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
||||||
|
</resheader> |
||||||
|
<resheader name="writer"> |
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
||||||
|
</resheader> |
||||||
|
</root> |
Loading…
Reference in new issue