diff --git a/src/AddIns/DisplayBindings/SettingsEditor/Project/ProxyPropertyDescriptor.cs b/src/AddIns/DisplayBindings/SettingsEditor/Project/ProxyPropertyDescriptor.cs new file mode 100644 index 0000000000..03092f38ce --- /dev/null +++ b/src/AddIns/DisplayBindings/SettingsEditor/Project/ProxyPropertyDescriptor.cs @@ -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; + } + } + } +} diff --git a/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsEditor.csproj b/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsEditor.csproj index 1f43977814..6881d6f249 100644 --- a/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsEditor.csproj +++ b/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsEditor.csproj @@ -39,6 +39,7 @@ + @@ -54,6 +55,11 @@ SettingsView.cs + + + SettingsView.cs + + diff --git a/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsEntry.cs b/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsEntry.cs new file mode 100644 index 0000000000..145f787c41 --- /dev/null +++ b/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsEntry.cs @@ -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 + } +} diff --git a/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.Designer.cs b/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.Designer.cs index 7ba97da331..91a6036266 100644 --- a/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.Designer.cs +++ b/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.Designer.cs @@ -1,4 +1,4 @@ -/* +/* * Created by SharpDevelop. * User: Daniel Grunwald * Date: 10/28/2006 @@ -36,11 +36,46 @@ namespace ICSharpCode.SettingsEditor /// private void InitializeComponent() { + this.grid = new System.Windows.Forms.DataGridView(); + this.label1 = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.grid)).BeginInit(); + this.SuspendLayout(); + // + // grid + // + this.grid.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.grid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.grid.Location = new System.Drawing.Point(3, 38); + this.grid.Name = "grid"; + this.grid.Size = new System.Drawing.Size(480, 321); + this.grid.TabIndex = 0; + this.grid.SelectionChanged += new System.EventHandler(this.GridSelectionChanged); + this.grid.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.GridCellContentClick); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(4, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(292, 13); + this.label1.TabIndex = 1; + this.label1.Text = "SettingsView prototype. Code generation not implemented!"; // // SettingsView // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.label1); + this.Controls.Add(this.grid); this.Name = "SettingsView"; + this.Size = new System.Drawing.Size(486, 362); + ((System.ComponentModel.ISupportInitialize)(this.grid)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); } + private System.Windows.Forms.Label label1; + private System.Windows.Forms.DataGridView grid; } } diff --git a/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.cs b/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.cs index bf69606a9c..db33d0696f 100644 --- a/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.cs +++ b/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.cs @@ -11,6 +11,7 @@ using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; +using System.Collections.Generic; namespace ICSharpCode.SettingsEditor { @@ -30,5 +31,58 @@ namespace ICSharpCode.SettingsEditor // TODO: Add constructor code after the InitializeComponent() call. // } + + void GridCellContentClick(object sender, System.Windows.Forms.DataGridViewCellEventArgs e) + { + + } + + public void ShowEntries(List list) + { + grid.AutoGenerateColumns = false; + grid.DataSource = list; + if (grid.Columns.Count == 0) { + grid.Columns.Add("Name", "Name"); + grid.Columns[0].DataPropertyName = "Name"; + grid.Columns.Add("Value", "Value"); + grid.Columns[1].DataPropertyName = "Value"; + grid.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + grid.Columns[1].MinimumWidth = 75; + } + grid.AllowUserToAddRows = true; + /*foreach (SettingsEntry e in list) { + grid.Rows.Add(e.Name, + e.SerializedSettingType, + e.Scope, + e.Value); + }*/ + } + + void GridSelectionChanged(object sender, EventArgs e) + { + if (SelectionChanged != null) + SelectionChanged(this, e); + } + + public List GetSelectedEntries() + { + List l = new List(); + if (grid.SelectedRows.Count > 0) { + foreach (DataGridViewRow row in grid.SelectedRows) { + l.Add((SettingsEntry)row.DataBoundItem); + } + } else { + bool[] rowAdded = new bool[grid.Rows.Count]; + foreach (DataGridViewCell cell in grid.SelectedCells) { + if (rowAdded[cell.RowIndex] == false) { + rowAdded[cell.RowIndex] = true; + l.Add((SettingsEntry)cell.OwningRow.DataBoundItem); + } + } + } + return l; + } + + public event EventHandler SelectionChanged; } } diff --git a/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.resx b/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.resx new file mode 100644 index 0000000000..7080a7d118 --- /dev/null +++ b/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsViewContent.cs b/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsViewContent.cs index 99963ad2ea..0018503c09 100644 --- a/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsViewContent.cs +++ b/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsViewContent.cs @@ -1,13 +1,16 @@ /* * Created by SharpDevelop. - * User: tfssetup + * User: Daniel Grunwald * Date: 10/28/2006 * Time: 5:54 PM * * To change this template use Tools | Options | Coding | Edit Standard Headers. */ +using System.Xml; using System; +using System.IO; +using System.Collections.Generic; using ICSharpCode.Core; using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Gui; @@ -15,9 +18,17 @@ using System.Windows.Forms; namespace ICSharpCode.SettingsEditor { - public class SettingsViewContent : AbstractViewContent + public class SettingsViewContent : AbstractViewContent, IHasPropertyContainer { SettingsView view = new SettingsView(); + PropertyContainer propertyContainer = new PropertyContainer(); + + public SettingsViewContent() + { + view.SelectionChanged += delegate { + propertyContainer.SelectedObjects = view.GetSelectedEntries().ToArray(); + }; + } public override Control Control { get { @@ -25,12 +36,36 @@ namespace ICSharpCode.SettingsEditor } } - public override void Load(string fileName) + public override void Load(string filename) { + TitleName = Path.GetFileName(filename); + FileName = filename; + IsDirty = false; + + try { + XmlDocument doc = new XmlDocument(); + doc.Load(filename); + XmlElement settings = doc.DocumentElement["Settings"]; + List entries = new List(); + foreach (XmlNode node in settings.ChildNodes) { + if (node is XmlElement) { + entries.Add(new SettingsEntry(node as XmlElement)); + } + } + view.ShowEntries(entries); + } catch (XmlException ex) { + MessageService.ShowMessage(ex.Message); + } } public override void Save() { } + + public PropertyContainer PropertyContainer { + get { + return propertyContainer; + } + } } } diff --git a/src/Main/Base/Project/Src/Gui/Components/LocalizedPropertyGrid/LocalizedObject.cs b/src/Main/Base/Project/Src/Gui/Components/LocalizedPropertyGrid/LocalizedObject.cs index 64f51ab5c5..da14012ab8 100644 --- a/src/Main/Base/Project/Src/Gui/Components/LocalizedPropertyGrid/LocalizedObject.cs +++ b/src/Main/Base/Project/Src/Gui/Components/LocalizedPropertyGrid/LocalizedObject.cs @@ -22,57 +22,61 @@ namespace ICSharpCode.SharpDevelop.Gui { PropertyDescriptorCollection globalizedProps; - public string GetClassName() + string ICustomTypeDescriptor.GetClassName() { return TypeDescriptor.GetClassName(this,true); } - public AttributeCollection GetAttributes() + AttributeCollection ICustomTypeDescriptor.GetAttributes() { return TypeDescriptor.GetAttributes(this,true); } - public string GetComponentName() + string ICustomTypeDescriptor.GetComponentName() { return TypeDescriptor.GetComponentName(this, true); } - public TypeConverter GetConverter() + TypeConverter ICustomTypeDescriptor.GetConverter() { return TypeDescriptor.GetConverter(this, true); } - public EventDescriptor GetDefaultEvent() + EventDescriptor ICustomTypeDescriptor.GetDefaultEvent() { return TypeDescriptor.GetDefaultEvent(this, true); } - public PropertyDescriptor GetDefaultProperty() + PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty() { return TypeDescriptor.GetDefaultProperty(this, true); } - public object GetEditor(Type editorBaseType) + object ICustomTypeDescriptor.GetEditor(Type editorBaseType) { return TypeDescriptor.GetEditor(this, editorBaseType, true); } - public EventDescriptorCollection GetEvents(Attribute[] attributes) + EventDescriptorCollection ICustomTypeDescriptor.GetEvents(Attribute[] attributes) { return TypeDescriptor.GetEvents(this, attributes, true); } - public EventDescriptorCollection GetEvents() + EventDescriptorCollection ICustomTypeDescriptor.GetEvents() { return TypeDescriptor.GetEvents(this, true); } + protected virtual void FilterProperties(PropertyDescriptorCollection globalizedProps) + { + } + /// /// Called to get the properties of a type. /// /// /// - public PropertyDescriptorCollection GetProperties(Attribute[] attributes) + PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes) { if ( globalizedProps == null) { // Get the collection of properties @@ -84,11 +88,12 @@ namespace ICSharpCode.SharpDevelop.Gui foreach (PropertyDescriptor oProp in baseProps) { globalizedProps.Add(new LocalizedPropertyDescriptor(oProp)); } + FilterProperties(globalizedProps); } return globalizedProps; } - public PropertyDescriptorCollection GetProperties() + PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties() { // Only do once if (globalizedProps == null) { @@ -100,11 +105,12 @@ namespace ICSharpCode.SharpDevelop.Gui foreach (PropertyDescriptor oProp in baseProps) { globalizedProps.Add(new LocalizedPropertyDescriptor(oProp)); } + FilterProperties(globalizedProps); } return globalizedProps; } - public object GetPropertyOwner(PropertyDescriptor pd) + object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd) { return this; } diff --git a/src/Main/Base/Project/Src/Gui/Components/LocalizedPropertyGrid/LocalizedPropertyDescriptor.cs b/src/Main/Base/Project/Src/Gui/Components/LocalizedPropertyGrid/LocalizedPropertyDescriptor.cs index 363f8437aa..dcd7b7669d 100644 --- a/src/Main/Base/Project/Src/Gui/Components/LocalizedPropertyGrid/LocalizedPropertyDescriptor.cs +++ b/src/Main/Base/Project/Src/Gui/Components/LocalizedPropertyGrid/LocalizedPropertyDescriptor.cs @@ -136,6 +136,5 @@ namespace ICSharpCode.SharpDevelop.Gui ((LocalizedObject)component).InformSetValue(this, component, value); } } - } }