From 176bd92662dbbde7e6bfa3bfd70207bfb6f8ed27 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 25 May 2009 19:09:28 +0000 Subject: [PATCH] - Added new StringParseExtension and OptionBinding - Implemented XML option panels in WPF git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/XmlEditor@4148 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../XmlCodeCompletionBinding.cs | 30 ++ .../XmlCompletionDataCollection.cs | 288 ------------ ...CompletionData.cs => XmlCompletionItem.cs} | 33 +- .../XmlCompletionItemCollection.cs | 117 +++++ .../Src/Gui/Dialogs/SelectXmlSchema.xaml | 6 +- .../Src/Gui/Dialogs/SelectXmlSchema.xaml.cs | 61 ++- .../Gui/Dialogs/XmlEditorOptionsPanel.xaml | 14 +- .../Gui/Dialogs/XmlEditorOptionsPanel.xaml.cs | 21 +- .../Src/Gui/Dialogs/XmlSchemasPanel.xaml | 81 ++-- .../Src/Gui/Dialogs/XmlSchemasPanel.xaml.cs | 329 +++++++++++++- .../XmlBinding/Src/Gui/SelectXmlSchemaForm.cs | 90 ---- .../Src/Src/XmlEditorOptionsPanel.cs | 49 --- .../Src/Src/XmlSchemaCompletionData.cs | 112 ++--- .../Src/Src/XmlSchemaListBoxItem.cs | 2 + .../XmlBinding/Src/Src/XmlSchemasPanel.cs | 412 ------------------ .../XmlBinding/XmlBinding.csproj | 11 +- .../Src/Gui/Dialogs/AbstractOptionPanel.cs | 46 +- .../ICSharpCode.Core.Presentation.csproj | 3 + .../IOptionBindingContainer.cs | 24 + .../LocalizeExtension.cs | 25 +- .../OptionBinding.cs | 111 +++++ .../StringParseExtension.cs | 34 ++ 22 files changed, 886 insertions(+), 1013 deletions(-) delete mode 100644 src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCompletionDataCollection.cs rename src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/{XmlCompletionData.cs => XmlCompletionItem.cs} (73%) create mode 100644 src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCompletionItemCollection.cs delete mode 100644 src/AddIns/BackendBindings/XmlBinding/Src/Gui/SelectXmlSchemaForm.cs delete mode 100644 src/AddIns/BackendBindings/XmlBinding/Src/Src/XmlEditorOptionsPanel.cs delete mode 100644 src/AddIns/BackendBindings/XmlBinding/Src/Src/XmlSchemasPanel.cs create mode 100644 src/Main/ICSharpCode.Core.Presentation/IOptionBindingContainer.cs create mode 100644 src/Main/ICSharpCode.Core.Presentation/OptionBinding.cs create mode 100644 src/Main/ICSharpCode.Core.Presentation/StringParseExtension.cs diff --git a/src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCodeCompletionBinding.cs b/src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCodeCompletionBinding.cs index 6faa0d6a9a..1e22c0e8d9 100644 --- a/src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCodeCompletionBinding.cs +++ b/src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCodeCompletionBinding.cs @@ -18,6 +18,17 @@ namespace ICSharpCode.XmlBinding /// public class XmlCodeCompletionBinding : ICodeCompletionBinding { + static XmlCodeCompletionBinding instance; + + public static XmlCodeCompletionBinding Instance { + get { + if (instance == null) + instance = new XmlCodeCompletionBinding(); + + return instance; + } + } + public XmlCodeCompletionBinding() { } @@ -81,6 +92,25 @@ namespace ICSharpCode.XmlBinding public bool CtrlSpace(ITextEditor editor) { + string text = editor.Document.Text; + int offset = editor.Caret.Offset; + + string extension = Path.GetExtension(editor.FileName); + string defaultNamespacePrefix = XmlSchemaManager.GetNamespacePrefix(extension); + XmlSchemaCompletionData defaultSchemaCompletionData = XmlSchemaManager.GetSchemaCompletionData(extension); + XmlCompletionDataProvider provider = new XmlCompletionDataProvider(XmlSchemaManager.SchemaCompletionDataItems, + defaultSchemaCompletionData, + defaultNamespacePrefix); + + // Attribute value completion. + if (XmlParser.IsInsideAttributeValue(text, offset)) { + XmlElementPath path = XmlParser.GetActiveElementStartPath(text, offset); + if (path.Elements.Count > 0) { + editor.ShowCompletionWindow(provider.GetAttributeValueCompletionData(path, XmlParser.GetAttributeNameAtIndex(text, offset))); + return true; + } + } + return false; } } diff --git a/src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCompletionDataCollection.cs b/src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCompletionDataCollection.cs deleted file mode 100644 index a32a25013b..0000000000 --- a/src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCompletionDataCollection.cs +++ /dev/null @@ -1,288 +0,0 @@ -// -// -// -// -// $Revision: 1965 $ -// - -using ICSharpCode.SharpDevelop.Editor; -using System; -using System.Collections; - -namespace ICSharpCode.XmlEditor -{ - /// - /// A collection that stores objects. - /// - [Serializable()] - public class XmlCompletionDataCollection : CollectionBase { - - /// - /// Initializes a new instance of . - /// - public XmlCompletionDataCollection() - { - } - - /// - /// Initializes a new instance of based on another . - /// - /// - /// A from which the contents are copied - /// - public XmlCompletionDataCollection(XmlCompletionDataCollection val) - { - this.AddRange(val); - } - - /// - /// Initializes a new instance of containing any array of objects. - /// - /// - /// A array of objects with which to intialize the collection - /// - public XmlCompletionDataCollection(XmlCompletionItem[] val) - { - this.AddRange(val); - } - - /// - /// Represents the entry at the specified index of the . - /// - /// The zero-based index of the entry to locate in the collection. - /// The entry at the specified index of the collection. - /// is outside the valid range of indexes for the collection. - public XmlCompletionItem this[int index] { - get { - return ((XmlCompletionItem)(List[index])); - } - set { - List[index] = value; - } - } - - /// - /// Adds a with the specified value to the - /// . - /// - /// - /// If the completion data already exists in the collection it is not added. - /// - /// The to add. - /// The index at which the new element was inserted. - /// - public int Add(XmlCompletionItem val) - { - int index = -1; - if (!Contains(val)) { - index = List.Add(val); - } - return index; - } - - /// - /// Copies the elements of an array to the end of the . - /// - /// - /// An array of type containing the objects to add to the collection. - /// - /// - public void AddRange(XmlCompletionItem[] val) - { - for (int i = 0; i < val.Length; i++) { - this.Add(val[i]); - } - } - - /// - /// Adds the contents of another to the end of the collection. - /// - /// - /// A containing the objects to add to the collection. - /// - /// - public void AddRange(XmlCompletionDataCollection val) - { - for (int i = 0; i < val.Count; i++) - { - this.Add(val[i]); - } - } - - /// - /// Gets a value indicating whether the - /// contains the specified . - /// - /// The to locate. - /// - /// if the is contained in the collection; - /// otherwise, . - /// - /// - public bool Contains(XmlCompletionItem val) - { - if (val.Text != null) { - if (val.Text.Length > 0) { - return Contains(val.Text); - } - } - return false; - } - - public bool Contains(string name) - { - bool contains = false; - - foreach (XmlCompletionItem data in this) { - if (data.Text != null) { - if (data.Text.Length > 0) { - if (data.Text == name) { - contains = true; - break; - } - } - } - } - - return contains; - } - - /// - /// Copies the values to a one-dimensional instance at the - /// specified index. - /// - /// The one-dimensional that is the destination of the values copied from . - /// The index in where copying begins. - /// - /// is multidimensional. - /// -or- - /// The number of elements in the is greater than - /// the available space between and the end of - /// . - /// - /// is . - /// is less than 's lowbound. - /// - public void CopyTo(XmlCompletionItem[] array, int index) - { - List.CopyTo(array, index); - } - - /// - /// Copies the values to a one-dimensional instance at the - /// specified index. - /// - public void CopyTo(ICompletionItem[] array, int index) - { - List.CopyTo(array, index); - } - - /// - /// Returns the index of a in - /// the . - /// - /// The to locate. - /// - /// The index of the of in the - /// , if found; otherwise, -1. - /// - /// - public int IndexOf(XmlCompletionItem val) - { - return List.IndexOf(val); - } - - /// - /// Inserts a into the at the specified index. - /// - /// The zero-based index where should be inserted. - /// The to insert. - /// - public void Insert(int index, XmlCompletionItem val) - { - List.Insert(index, val); - } - - /// - /// Returns an array of items. - /// - /// - public ICompletionItem[] ToArray() - { - XmlCompletionItem[] data = new XmlCompletionItem[Count]; - CopyTo(data, 0); - return data; - } - - /// - /// Returns an enumerator that can iterate through the . - /// - /// - public new XmlCompletionDataEnumerator GetEnumerator() - { - return new XmlCompletionDataEnumerator(this); - } - - /// - /// Removes a specific from the . - /// - /// The to remove from the . - /// is not found in the Collection. - public void Remove(XmlCompletionItem val) - { - List.Remove(val); - } - - /// - /// Enumerator that can iterate through a XmlCompletionDataCollection. - /// - /// - /// - /// - public class XmlCompletionDataEnumerator : IEnumerator - { - IEnumerator baseEnumerator; - IEnumerable temp; - - /// - /// Initializes a new instance of . - /// - public XmlCompletionDataEnumerator(XmlCompletionDataCollection mappings) - { - this.temp = ((IEnumerable)(mappings)); - this.baseEnumerator = temp.GetEnumerator(); - } - - /// - /// Gets the current in the . - /// - public XmlCompletionItem Current { - get { - return ((XmlCompletionItem)(baseEnumerator.Current)); - } - } - - object IEnumerator.Current { - get { - return baseEnumerator.Current; - } - } - - /// - /// Advances the enumerator to the next of the . - /// - public bool MoveNext() - { - return baseEnumerator.MoveNext(); - } - - /// - /// Sets the enumerator to its initial position, which is before the first element in the . - /// - public void Reset() - { - baseEnumerator.Reset(); - } - } - } -} diff --git a/src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCompletionData.cs b/src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCompletionItem.cs similarity index 73% rename from src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCompletionData.cs rename to src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCompletionItem.cs index b6785979f6..004bafc74c 100644 --- a/src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCompletionData.cs +++ b/src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCompletionItem.cs @@ -5,13 +5,13 @@ // $Revision: 2932 $ // -using ICSharpCode.SharpDevelop.Editor; using System; +using ICSharpCode.SharpDevelop.Editor; -namespace ICSharpCode.XmlEditor +namespace ICSharpCode.XmlBinding { /// - /// Holds the text for namespace, child element or attribute + /// Holds the text for namespace, child element or attribute /// autocomplete (intellisense). /// public class XmlCompletionItem : DefaultCompletionItem @@ -42,14 +42,14 @@ namespace ICSharpCode.XmlEditor public XmlCompletionItem(string text, DataType dataType) : this(text, String.Empty, dataType) { - } + } public XmlCompletionItem(string text, string description, DataType dataType) : base(text) { this.description = description; - this.dataType = dataType; - } + this.dataType = dataType; + } /// /// Returns the xml item's documentation as retrieved from @@ -65,16 +65,17 @@ namespace ICSharpCode.XmlEditor { base.Complete(context); -// if (dataType == DataType.NamespaceUri) { -// textArea.InsertString(String.Concat("\"", text, "\"")); -// } else { -// // Insert an attribute. -// Caret caret = textArea.Caret; -// textArea.InsertString(String.Concat(text, "=\"\"")); -// -// // Move caret into the middle of the attribute quotes. -// caret.Position = textArea.Document.OffsetToPosition(caret.Offset - 1); -// } + switch (dataType) { + case DataType.NamespaceUri: + context.Editor.Document.Insert(context.StartOffset, "\""); + context.Editor.Document.Insert(context.EndOffset, "\""); + break; + case DataType.XmlAttribute: + context.Editor.Document.Insert(context.EndOffset, "=\"\""); + context.Editor.Caret.Offset--; + XmlCodeCompletionBinding.Instance.CtrlSpace(context.Editor); + break; + } } } } diff --git a/src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCompletionItemCollection.cs b/src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCompletionItemCollection.cs new file mode 100644 index 0000000000..fee85f36e3 --- /dev/null +++ b/src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCompletionItemCollection.cs @@ -0,0 +1,117 @@ +// +// +// +// +// $Revision: 1965 $ +// + +using ICSharpCode.XmlBinding; +using System; +using System.Collections; +using System.Collections.ObjectModel; +using ICSharpCode.SharpDevelop.Editor; + +namespace ICSharpCode.XmlEditor +{ + /// + /// A collection that stores objects. + /// + [Serializable()] + public class XmlCompletionItemCollection : Collection { + + /// + /// Initializes a new instance of . + /// + public XmlCompletionItemCollection() + { + } + + /// + /// Initializes a new instance of based on another . + /// + /// + /// A from which the contents are copied + /// + public XmlCompletionItemCollection(XmlCompletionItemCollection val) + { + this.AddRange(val); + } + + /// + /// Initializes a new instance of containing any array of objects. + /// + /// + /// A array of objects with which to intialize the collection + /// + public XmlCompletionItemCollection(XmlCompletionItem[] val) + { + this.AddRange(val); + } + + /// + /// Copies the elements of an array to the end of the . + /// + /// + /// An array of type containing the objects to add to the collection. + /// + /// + public void AddRange(XmlCompletionItem[] val) + { + for (int i = 0; i < val.Length; i++) { + this.Add(val[i]); + } + } + + /// + /// Adds the contents of another to the end of the collection. + /// + /// + /// A containing the objects to add to the collection. + /// + /// + public void AddRange(XmlCompletionItemCollection val) + { + for (int i = 0; i < val.Count; i++) + this.Add(val[i]); + } + + public bool Contains(string name) + { + bool contains = false; + + foreach (XmlCompletionItem data in this) { + if (data.Text != null) { + if (data.Text.Length > 0) { + if (data.Text == name) { + contains = true; + break; + } + } + } + } + + return contains; + } + + /// + /// Copies the values to a one-dimensional instance at the + /// specified index. + /// + public void CopyTo(ICompletionItem[] array, int index) + { + for (int i = index; i < this.Count; i++) + array[i] = this[i - index]; + } + + /// + /// Returns an array of items. + /// + /// + public ICompletionItem[] ToArray() + { + XmlCompletionItem[] data = new XmlCompletionItem[Count]; + CopyTo(data, 0); + return data; + } + } +} diff --git a/src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/SelectXmlSchema.xaml b/src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/SelectXmlSchema.xaml index 0921289ab7..4074f174d4 100644 --- a/src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/SelectXmlSchema.xaml +++ b/src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/SelectXmlSchema.xaml @@ -6,9 +6,9 @@ > - public ICompletionItemList GetElementCompletionData(string namespacePrefix) { - XmlCompletionDataCollection data = new XmlCompletionDataCollection(); + XmlCompletionItemCollection data = new XmlCompletionItemCollection(); foreach (XmlSchemaElement element in schema.Elements.Values) { if (element.Name != null) { @@ -175,7 +175,7 @@ namespace ICSharpCode.XmlEditor /// public ICompletionItem[] GetAttributeCompletionData(XmlElementPath path) { - XmlCompletionDataCollection data = new XmlCompletionDataCollection(); + XmlCompletionItemCollection data = new XmlCompletionItemCollection(); // Locate matching element. XmlSchemaElement element = FindElement(path); @@ -195,7 +195,7 @@ namespace ICSharpCode.XmlEditor /// public ICompletionItem[] GetChildElementCompletionData(XmlElementPath path) { - XmlCompletionDataCollection data = new XmlCompletionDataCollection(); + XmlCompletionItemCollection data = new XmlCompletionItemCollection(); // Locate matching element. XmlSchemaElement element = FindElement(path); @@ -213,7 +213,7 @@ namespace ICSharpCode.XmlEditor /// public ICompletionItem[] GetAttributeValueCompletionData(XmlElementPath path, string name) { - XmlCompletionDataCollection data = new XmlCompletionDataCollection(); + XmlCompletionItemCollection data = new XmlCompletionItemCollection(); // Locate matching element. XmlSchemaElement element = FindElement(path); @@ -440,9 +440,9 @@ namespace ICSharpCode.XmlEditor return matchedElement; } - XmlCompletionDataCollection GetChildElementCompletionData(XmlSchemaElement element, string prefix) + XmlCompletionItemCollection GetChildElementCompletionData(XmlSchemaElement element, string prefix) { - XmlCompletionDataCollection data = new XmlCompletionDataCollection(); + XmlCompletionItemCollection data = new XmlCompletionItemCollection(); XmlSchemaComplexType complexType = GetElementAsComplexType(element); @@ -453,9 +453,9 @@ namespace ICSharpCode.XmlEditor return data; } - XmlCompletionDataCollection GetChildElementCompletionData(XmlSchemaComplexType complexType, string prefix) + XmlCompletionItemCollection GetChildElementCompletionData(XmlSchemaComplexType complexType, string prefix) { - XmlCompletionDataCollection data = new XmlCompletionDataCollection(); + XmlCompletionItemCollection data = new XmlCompletionItemCollection(); XmlSchemaSequence sequence = complexType.Particle as XmlSchemaSequence; XmlSchemaChoice choice = complexType.Particle as XmlSchemaChoice; @@ -478,9 +478,9 @@ namespace ICSharpCode.XmlEditor return data; } - XmlCompletionDataCollection GetChildElementCompletionData(XmlSchemaObjectCollection items, string prefix) + XmlCompletionItemCollection GetChildElementCompletionData(XmlSchemaObjectCollection items, string prefix) { - XmlCompletionDataCollection data = new XmlCompletionDataCollection(); + XmlCompletionItemCollection data = new XmlCompletionItemCollection(); foreach (XmlSchemaObject schemaObject in items) { @@ -518,9 +518,9 @@ namespace ICSharpCode.XmlEditor return data; } - XmlCompletionDataCollection GetChildElementCompletionData(XmlSchemaComplexContent complexContent, string prefix) + XmlCompletionItemCollection GetChildElementCompletionData(XmlSchemaComplexContent complexContent, string prefix) { - XmlCompletionDataCollection data = new XmlCompletionDataCollection(); + XmlCompletionItemCollection data = new XmlCompletionItemCollection(); XmlSchemaComplexContentExtension extension = complexContent.Content as XmlSchemaComplexContentExtension; if (extension != null) { @@ -535,9 +535,9 @@ namespace ICSharpCode.XmlEditor return data; } - XmlCompletionDataCollection GetChildElementCompletionData(XmlSchemaComplexContentExtension extension, string prefix) + XmlCompletionItemCollection GetChildElementCompletionData(XmlSchemaComplexContentExtension extension, string prefix) { - XmlCompletionDataCollection data = new XmlCompletionDataCollection(); + XmlCompletionItemCollection data = new XmlCompletionItemCollection(); XmlSchemaComplexType complexType = FindNamedType(schema, extension.BaseTypeName); if (complexType != null) { @@ -562,9 +562,9 @@ namespace ICSharpCode.XmlEditor return data; } - XmlCompletionDataCollection GetChildElementCompletionData(XmlSchemaGroupRef groupRef, string prefix) + XmlCompletionItemCollection GetChildElementCompletionData(XmlSchemaGroupRef groupRef, string prefix) { - XmlCompletionDataCollection data = new XmlCompletionDataCollection(); + XmlCompletionItemCollection data = new XmlCompletionItemCollection(); XmlSchemaGroup group = FindGroup(groupRef.RefName.Name); if (group != null) { @@ -581,9 +581,9 @@ namespace ICSharpCode.XmlEditor return data; } - XmlCompletionDataCollection GetChildElementCompletionData(XmlSchemaComplexContentRestriction restriction, string prefix) + XmlCompletionItemCollection GetChildElementCompletionData(XmlSchemaComplexContentRestriction restriction, string prefix) { - XmlCompletionDataCollection data = new XmlCompletionDataCollection(); + XmlCompletionItemCollection data = new XmlCompletionItemCollection(); // Add any elements. if (restriction.Particle != null) { @@ -607,7 +607,7 @@ namespace ICSharpCode.XmlEditor /// Adds an element completion data to the collection if it does not /// already exist. /// - void AddElement(XmlCompletionDataCollection data, string name, string prefix, string documentation) + void AddElement(XmlCompletionItemCollection data, string name, string prefix, string documentation) { if (!data.Contains(name)) { if (prefix.Length > 0) { @@ -622,7 +622,7 @@ namespace ICSharpCode.XmlEditor /// Adds an element completion data to the collection if it does not /// already exist. /// - void AddElement(XmlCompletionDataCollection data, string name, string prefix, XmlSchemaAnnotation annotation) + void AddElement(XmlCompletionItemCollection data, string name, string prefix, XmlSchemaAnnotation annotation) { // Get any annotation documentation. string documentation = GetDocumentation(annotation); @@ -633,7 +633,7 @@ namespace ICSharpCode.XmlEditor /// /// Adds elements to the collection if it does not already exist. /// - void AddElements(XmlCompletionDataCollection lhs, XmlCompletionDataCollection rhs) + void AddElements(XmlCompletionItemCollection lhs, XmlCompletionItemCollection rhs) { foreach (XmlCompletionItem data in rhs) { if (!lhs.Contains(data)) { @@ -677,9 +677,9 @@ namespace ICSharpCode.XmlEditor return documentation; } - XmlCompletionDataCollection GetAttributeCompletionData(XmlSchemaElement element) + XmlCompletionItemCollection GetAttributeCompletionData(XmlSchemaElement element) { - XmlCompletionDataCollection data = new XmlCompletionDataCollection(); + XmlCompletionItemCollection data = new XmlCompletionItemCollection(); XmlSchemaComplexType complexType = GetElementAsComplexType(element); @@ -690,9 +690,9 @@ namespace ICSharpCode.XmlEditor return data; } - XmlCompletionDataCollection GetAttributeCompletionData(XmlSchemaComplexContentRestriction restriction) + XmlCompletionItemCollection GetAttributeCompletionData(XmlSchemaComplexContentRestriction restriction) { - XmlCompletionDataCollection data = new XmlCompletionDataCollection(); + XmlCompletionItemCollection data = new XmlCompletionItemCollection(); data.AddRange(GetAttributeCompletionData(restriction.Attributes)); @@ -704,9 +704,9 @@ namespace ICSharpCode.XmlEditor return data; } - XmlCompletionDataCollection GetAttributeCompletionData(XmlSchemaComplexType complexType) + XmlCompletionItemCollection GetAttributeCompletionData(XmlSchemaComplexType complexType) { - XmlCompletionDataCollection data = new XmlCompletionDataCollection(); + XmlCompletionItemCollection data = new XmlCompletionItemCollection(); data = GetAttributeCompletionData(complexType.Attributes); @@ -730,9 +730,9 @@ namespace ICSharpCode.XmlEditor return data; } - XmlCompletionDataCollection GetAttributeCompletionData(XmlSchemaComplexContentExtension extension) + XmlCompletionItemCollection GetAttributeCompletionData(XmlSchemaComplexContentExtension extension) { - XmlCompletionDataCollection data = new XmlCompletionDataCollection(); + XmlCompletionItemCollection data = new XmlCompletionItemCollection(); data.AddRange(GetAttributeCompletionData(extension.Attributes)); XmlSchemaComplexType baseComplexType = FindNamedType(schema, extension.BaseTypeName); @@ -743,9 +743,9 @@ namespace ICSharpCode.XmlEditor return data; } - XmlCompletionDataCollection GetAttributeCompletionData(XmlSchemaSimpleContent simpleContent) + XmlCompletionItemCollection GetAttributeCompletionData(XmlSchemaSimpleContent simpleContent) { - XmlCompletionDataCollection data = new XmlCompletionDataCollection(); + XmlCompletionItemCollection data = new XmlCompletionItemCollection(); XmlSchemaSimpleContentExtension extension = simpleContent.Content as XmlSchemaSimpleContentExtension; if (extension != null) { @@ -755,18 +755,18 @@ namespace ICSharpCode.XmlEditor return data; } - XmlCompletionDataCollection GetAttributeCompletionData(XmlSchemaSimpleContentExtension extension) + XmlCompletionItemCollection GetAttributeCompletionData(XmlSchemaSimpleContentExtension extension) { - XmlCompletionDataCollection data = new XmlCompletionDataCollection(); + XmlCompletionItemCollection data = new XmlCompletionItemCollection(); data.AddRange(GetAttributeCompletionData(extension.Attributes)); return data; } - XmlCompletionDataCollection GetAttributeCompletionData(XmlSchemaObjectCollection attributes) + XmlCompletionItemCollection GetAttributeCompletionData(XmlSchemaObjectCollection attributes) { - XmlCompletionDataCollection data = new XmlCompletionDataCollection(); + XmlCompletionItemCollection data = new XmlCompletionItemCollection(); foreach (XmlSchemaObject schemaObject in attributes) { XmlSchemaAttribute attribute = schemaObject as XmlSchemaAttribute; @@ -811,7 +811,7 @@ namespace ICSharpCode.XmlEditor /// /// Note the special handling of xml:lang attributes. /// - void AddAttribute(XmlCompletionDataCollection data, XmlSchemaAttribute attribute) + void AddAttribute(XmlCompletionItemCollection data, XmlSchemaAttribute attribute) { string name = attribute.Name; if (name == null) { @@ -830,9 +830,9 @@ namespace ICSharpCode.XmlEditor /// /// Gets attribute completion data from a group ref. /// - XmlCompletionDataCollection GetAttributeCompletionData(XmlSchemaAttributeGroupRef groupRef) + XmlCompletionItemCollection GetAttributeCompletionData(XmlSchemaAttributeGroupRef groupRef) { - XmlCompletionDataCollection data = new XmlCompletionDataCollection(); + XmlCompletionItemCollection data = new XmlCompletionItemCollection(); XmlSchemaAttributeGroup group = FindAttributeGroup(schema, groupRef.RefName.Name); if (group != null) { data = GetAttributeCompletionData(group.Attributes); @@ -1064,9 +1064,9 @@ namespace ICSharpCode.XmlEditor return matchedGroup; } - XmlCompletionDataCollection GetAttributeValueCompletionData(XmlSchemaElement element, string name) + XmlCompletionItemCollection GetAttributeValueCompletionData(XmlSchemaElement element, string name) { - XmlCompletionDataCollection data = new XmlCompletionDataCollection(); + XmlCompletionItemCollection data = new XmlCompletionItemCollection(); XmlSchemaComplexType complexType = GetElementAsComplexType(element); if (complexType != null) { @@ -1079,9 +1079,9 @@ namespace ICSharpCode.XmlEditor return data; } - XmlCompletionDataCollection GetAttributeValueCompletionData(XmlSchemaAttribute attribute) + XmlCompletionItemCollection GetAttributeValueCompletionData(XmlSchemaAttribute attribute) { - XmlCompletionDataCollection data = new XmlCompletionDataCollection(); + XmlCompletionItemCollection data = new XmlCompletionItemCollection(); if (attribute.SchemaType != null) { XmlSchemaSimpleTypeRestriction simpleTypeRestriction = attribute.SchemaType.Content as XmlSchemaSimpleTypeRestriction; @@ -1103,9 +1103,9 @@ namespace ICSharpCode.XmlEditor return data; } - XmlCompletionDataCollection GetAttributeValueCompletionData(XmlSchemaSimpleTypeRestriction simpleTypeRestriction) + XmlCompletionItemCollection GetAttributeValueCompletionData(XmlSchemaSimpleTypeRestriction simpleTypeRestriction) { - XmlCompletionDataCollection data = new XmlCompletionDataCollection(); + XmlCompletionItemCollection data = new XmlCompletionItemCollection(); foreach (XmlSchemaObject schemaObject in simpleTypeRestriction.Facets) { XmlSchemaEnumerationFacet enumFacet = schemaObject as XmlSchemaEnumerationFacet; @@ -1117,9 +1117,9 @@ namespace ICSharpCode.XmlEditor return data; } - XmlCompletionDataCollection GetAttributeValueCompletionData(XmlSchemaSimpleTypeUnion union) + XmlCompletionItemCollection GetAttributeValueCompletionData(XmlSchemaSimpleTypeUnion union) { - XmlCompletionDataCollection data = new XmlCompletionDataCollection(); + XmlCompletionItemCollection data = new XmlCompletionItemCollection(); foreach (XmlSchemaObject schemaObject in union.BaseTypes) { XmlSchemaSimpleType simpleType = schemaObject as XmlSchemaSimpleType; @@ -1131,9 +1131,9 @@ namespace ICSharpCode.XmlEditor return data; } - XmlCompletionDataCollection GetAttributeValueCompletionData(XmlSchemaSimpleType simpleType) + XmlCompletionItemCollection GetAttributeValueCompletionData(XmlSchemaSimpleType simpleType) { - XmlCompletionDataCollection data = new XmlCompletionDataCollection(); + XmlCompletionItemCollection data = new XmlCompletionItemCollection(); XmlSchemaSimpleTypeRestriction simpleTypeRestriction = simpleType.Content as XmlSchemaSimpleTypeRestriction; XmlSchemaSimpleTypeUnion union = simpleType.Content as XmlSchemaSimpleTypeUnion; @@ -1150,9 +1150,9 @@ namespace ICSharpCode.XmlEditor return data; } - XmlCompletionDataCollection GetAttributeValueCompletionData(XmlSchemaSimpleTypeList list) + XmlCompletionItemCollection GetAttributeValueCompletionData(XmlSchemaSimpleTypeList list) { - XmlCompletionDataCollection data = new XmlCompletionDataCollection(); + XmlCompletionItemCollection data = new XmlCompletionItemCollection(); if (list.ItemType != null) { data.AddRange(GetAttributeValueCompletionData(list.ItemType)); @@ -1169,9 +1169,9 @@ namespace ICSharpCode.XmlEditor /// /// Gets the set of attribute values for an xs:boolean type. /// - XmlCompletionDataCollection GetBooleanAttributeValueCompletionData() + XmlCompletionItemCollection GetBooleanAttributeValueCompletionData() { - XmlCompletionDataCollection data = new XmlCompletionDataCollection(); + XmlCompletionItemCollection data = new XmlCompletionItemCollection(); AddAttributeValue(data, "0"); AddAttributeValue(data, "1"); @@ -1273,7 +1273,7 @@ namespace ICSharpCode.XmlEditor /// /// Adds an attribute value to the completion data collection. /// - void AddAttributeValue(XmlCompletionDataCollection data, string valueText) + void AddAttributeValue(XmlCompletionItemCollection data, string valueText) { XmlCompletionItem completionData = new XmlCompletionItem(valueText, XmlCompletionItem.DataType.XmlAttributeValue); data.Add(completionData); @@ -1282,7 +1282,7 @@ namespace ICSharpCode.XmlEditor /// /// Adds an attribute value to the completion data collection. /// - void AddAttributeValue(XmlCompletionDataCollection data, string valueText, XmlSchemaAnnotation annotation) + void AddAttributeValue(XmlCompletionItemCollection data, string valueText, XmlSchemaAnnotation annotation) { string documentation = GetDocumentation(annotation); XmlCompletionItem completionData = new XmlCompletionItem(valueText, documentation, XmlCompletionItem.DataType.XmlAttributeValue); @@ -1292,7 +1292,7 @@ namespace ICSharpCode.XmlEditor /// /// Adds an attribute value to the completion data collection. /// - void AddAttributeValue(XmlCompletionDataCollection data, string valueText, string description) + void AddAttributeValue(XmlCompletionItemCollection data, string valueText, string description) { XmlCompletionItem completionData = new XmlCompletionItem(valueText, description, XmlCompletionItem.DataType.XmlAttributeValue); data.Add(completionData); @@ -1318,7 +1318,7 @@ namespace ICSharpCode.XmlEditor /// /// Adds any elements that have the specified substitution group. /// - void AddSubstitionGroupElements(XmlCompletionDataCollection data, XmlQualifiedName group, string prefix) + void AddSubstitionGroupElements(XmlCompletionItemCollection data, XmlQualifiedName group, string prefix) { foreach (XmlSchemaElement element in schema.Elements.Values) { if (element.SubstitutionGroup == group) { diff --git a/src/AddIns/BackendBindings/XmlBinding/Src/Src/XmlSchemaListBoxItem.cs b/src/AddIns/BackendBindings/XmlBinding/Src/Src/XmlSchemaListBoxItem.cs index 45a7326bbb..ac9ee8062a 100644 --- a/src/AddIns/BackendBindings/XmlBinding/Src/Src/XmlSchemaListBoxItem.cs +++ b/src/AddIns/BackendBindings/XmlBinding/Src/Src/XmlSchemaListBoxItem.cs @@ -6,6 +6,8 @@ // using System; +using System.Windows.Controls; +using System.Windows.Media; namespace ICSharpCode.XmlEditor { diff --git a/src/AddIns/BackendBindings/XmlBinding/Src/Src/XmlSchemasPanel.cs b/src/AddIns/BackendBindings/XmlBinding/Src/Src/XmlSchemasPanel.cs deleted file mode 100644 index bdc5faa5ce..0000000000 --- a/src/AddIns/BackendBindings/XmlBinding/Src/Src/XmlSchemasPanel.cs +++ /dev/null @@ -1,412 +0,0 @@ -// -// -// -// -// $Revision: 3568 $ -// - -using ICSharpCode.XmlBinding.Gui; -using System; -using System.Collections.Specialized; -using System.Drawing; -using System.IO; -using System.Windows.Forms; -using ICSharpCode.Core; -using ICSharpCode.SharpDevelop.Gui; -using ICSharpCode.SharpDevelop.Gui.OptionPanels; - -namespace ICSharpCode.XmlEditor -{ -/* - /// - /// Shows the xml schemas that SharpDevelop knows about. - /// - public class XmlSchemasPanel : XmlFormsOptionPanel - { - ListBox schemaListBox; - Button removeButton; - ComboBox fileExtensionComboBox; - TextBox schemaTextBox; - TextBox namespacePrefixTextBox; - - bool ignoreNamespacePrefixTextChanges; - - bool changed; - XmlSchemaCompletionDataCollection addedSchemas = new XmlSchemaCompletionDataCollection(); - StringCollection removedSchemaNamespaces = new StringCollection(); - - SolidBrush readonlyTextBrush = new SolidBrush(SystemColors.GrayText); - SolidBrush selectedTextBrush = new SolidBrush(SystemColors.HighlightText); - SolidBrush normalTextBrush = new SolidBrush(SystemColors.WindowText); - - /// - /// Initialises the panel. - /// - public override void LoadPanelContents() - { - SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("ICSharpCode.XmlEditor.Resources.XmlSchemasPanel.xfrm")); - - schemaListBox = (ListBox)ControlDictionary["schemaListBox"]; - schemaListBox.DrawMode = DrawMode.OwnerDrawFixed; - schemaListBox.DrawItem += new DrawItemEventHandler(SchemaListBoxDrawItem); - schemaListBox.Sorted = true; - PopulateSchemaListBox(); - schemaListBox.SelectedIndexChanged += new EventHandler(SchemaListBoxSelectedIndexChanged); - - namespacePrefixTextBox = (TextBox)ControlDictionary["namespacePrefixTextBox"]; - namespacePrefixTextBox.TextChanged += new EventHandler(NamespacePrefixTextBoxTextChanged); - - ControlDictionary["addButton"].Click += new EventHandler(AddButtonClick); - removeButton = (Button)ControlDictionary["removeButton"]; - removeButton.Click += new EventHandler(RemoveButtonClick); - removeButton.Enabled = false; - - ControlDictionary["changeSchemaButton"].Click += new EventHandler(ChangeSchemaButtonClick); - - schemaTextBox = (TextBox)ControlDictionary["schemaTextBox"]; - fileExtensionComboBox = (ComboBox)ControlDictionary["fileExtensionComboBox"]; - fileExtensionComboBox.Sorted = true; - PopulateFileExtensionComboBox(); - fileExtensionComboBox.SelectedIndexChanged += new EventHandler(FileExtensionComboBoxSelectedIndexChanged); - } - - /// - /// Saves any changes to the configured schemas. - /// - public override bool StorePanelContents() - { - if (changed) { - try { - return SaveSchemaChanges(); - } catch (Exception ex) { - MessageService.ShowError(ex, "${res:ICSharpCode.XmlEditor.XmlSchemasPanel.UnableToSaveChanges}"); - return false; - } - } - - // Update schema associations after we have added any new schemas to - // the schema manager. - UpdateSchemaAssociations(); - - return true; - } - - void AddButtonClick(object source, EventArgs e) - { - try { - // Browse for schema. - - string schemaFileName = BrowseForSchema(); - - // Add schema if the namespace does not already exist. - - if (schemaFileName.Length > 0) { - changed = AddSchema(schemaFileName); - } - } catch (Exception ex) { - MessageService.ShowError("${res:ICSharpCode.XmlEditor.XmlSchemasPanel.UnableToAddSchema}\n\n" + ex.Message); - } - } - - void RemoveButtonClick(object source, EventArgs e) - { - // Remove selected schema. - XmlSchemaListBoxItem item = schemaListBox.SelectedItem as XmlSchemaListBoxItem; - if (item != null) { - RemoveSchema(item.NamespaceUri); - changed = true; - } - } - - /// - /// Enables the remove button if a list box item is selected. - /// - void SchemaListBoxSelectedIndexChanged(object source, EventArgs e) - { - XmlSchemaListBoxItem item = schemaListBox.SelectedItem as XmlSchemaListBoxItem; - if (item != null) { - if (item.ReadOnly) { - removeButton.Enabled = false; - } else { - removeButton.Enabled = true; - } - } else { - removeButton.Enabled = false; - } - } - - /// - /// Adds the schema namespaces to the list. - /// - void PopulateSchemaListBox() - { - foreach (XmlSchemaCompletionData schema in XmlSchemaManager.SchemaCompletionDataItems) { - XmlSchemaListBoxItem item = new XmlSchemaListBoxItem(schema.NamespaceUri, schema.ReadOnly); - schemaListBox.Items.Add(item); - } - } - - /// - /// Saves any changes to the configured schemas. - /// - /// - bool SaveSchemaChanges() - { - RemoveUserSchemas(); - AddUserSchemas(); - - return true; - } - - /// - /// Allows the user to browse the file system for a schema. - /// - /// The schema file name the user selected; otherwise an - /// empty string. - string BrowseForSchema() - { - string fileName = String.Empty; - - using (OpenFileDialog openFileDialog = new OpenFileDialog()) { - openFileDialog.CheckFileExists = true; - openFileDialog.Multiselect = false; - openFileDialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.XmlSchemaFiles}|*.xsd|${res:SharpDevelop.FileFilter.AllFiles}|*.*"); - - if (openFileDialog.ShowDialog() == DialogResult.OK) { - fileName = openFileDialog.FileName; - } - } - - return fileName; - } - - /// - /// Loads the specified schema and adds it to an internal collection. - /// - /// The schema file is not copied to the user's schema folder - /// until they click the OK button. - /// if the schema namespace - /// does not already exist; otherwise - /// - bool AddSchema(string fileName) - { - // Load the schema. - XmlSchemaCompletionData schema = new XmlSchemaCompletionData(fileName); - - // Make sure the schema has a target namespace. - if (schema.NamespaceUri == null) { - MessageService.ShowErrorFormatted("${res:ICSharpCode.XmlEditor.XmlSchemasPanel.NoTargetNamespace}", Path.GetFileName(schema.FileName)); - return false; - } - - // Check that the schema does not exist. - if (SchemaNamespaceExists(schema.NamespaceUri)) { - MessageService.ShowErrorFormatted("${res:ICSharpCode.XmlEditor.XmlSchemasPanel.NamespaceExists}", schema.NamespaceUri); - return false; - } - - // Store the schema so we can add it later. - int index = schemaListBox.Items.Add(new XmlSchemaListBoxItem(schema.NamespaceUri)); - schemaListBox.SelectedIndex = index; - addedSchemas.Add(schema); - if (removedSchemaNamespaces.Contains(schema.NamespaceUri)) { - removedSchemaNamespaces.Remove(schema.NamespaceUri); - } - - return true; - } - - /// - /// Checks that the schema namespace does not already exist. - /// - bool SchemaNamespaceExists(string namespaceURI) - { - bool exists = true; - if ((XmlSchemaManager.SchemaCompletionDataItems[namespaceURI] == null) && - (addedSchemas[namespaceURI] == null)){ - exists = false; - } else { - // Makes sure it has not been flagged for removal. - exists = !removedSchemaNamespaces.Contains(namespaceURI); - } - return exists; - } - - /// - /// Schedules the schema for removal. - /// - void RemoveSchema(string namespaceUri) - { - RemoveListBoxItem(namespaceUri); - - XmlSchemaCompletionData addedSchema = addedSchemas[namespaceUri]; - if (addedSchema != null) { - addedSchemas.Remove(addedSchema); - } else { - removedSchemaNamespaces.Add(namespaceUri); - } - } - - void RemoveListBoxItem(string namespaceUri) - { - foreach (XmlSchemaListBoxItem item in schemaListBox.Items) { - if (item.NamespaceUri == namespaceUri) { - schemaListBox.Items.Remove(item); - break; - } - } - } - - /// - /// Removes the schemas from the schema manager. - /// - void RemoveUserSchemas() - { - while (removedSchemaNamespaces.Count > 0) { - XmlSchemaManager.RemoveUserSchema(removedSchemaNamespaces[0]); - removedSchemaNamespaces.RemoveAt(0); - } - } - - /// - /// Adds the schemas to the schema manager. - /// - void AddUserSchemas() - { - while (addedSchemas.Count > 0) { - XmlSchemaManager.AddUserSchema(addedSchemas[0]); - addedSchemas.RemoveAt(0); - } - } - - /// - /// Draws the list box items so we can show the read only schemas in - /// a different colour. - /// - void SchemaListBoxDrawItem(object sender, DrawItemEventArgs e) - { - e.DrawBackground(); - - if (e.Index >= 0) { - XmlSchemaListBoxItem item = (XmlSchemaListBoxItem)schemaListBox.Items[e.Index]; - - if (IsListBoxItemSelected(e.State)) { - e.Graphics.DrawString(item.NamespaceUri, schemaListBox.Font, selectedTextBrush, e.Bounds); - } else if (item.ReadOnly) { - e.Graphics.DrawString(item.NamespaceUri, schemaListBox.Font, readonlyTextBrush, e.Bounds); - } else { - e.Graphics.DrawString(item.NamespaceUri, schemaListBox.Font, normalTextBrush, e.Bounds); - } - } - - e.DrawFocusRectangle(); - } - - bool IsListBoxItemSelected(DrawItemState state) - { - return ((state & DrawItemState.Selected) == DrawItemState.Selected); - } - - /// - /// Shows the namespace associated with the selected xml file extension. - /// - void FileExtensionComboBoxSelectedIndexChanged(object source, EventArgs e) - { - schemaTextBox.Text = String.Empty; - ignoreNamespacePrefixTextChanges = true; - namespacePrefixTextBox.Text = String.Empty; - - try { - XmlSchemaAssociationListBoxItem association = fileExtensionComboBox.SelectedItem as XmlSchemaAssociationListBoxItem; - if (association != null) { - schemaTextBox.Text = association.NamespaceUri; - namespacePrefixTextBox.Text = association.NamespacePrefix; - } - } finally { - ignoreNamespacePrefixTextChanges = false; - } - } - - /// - /// Allows the user to change the schema associated with an xml file - /// extension. - /// - void ChangeSchemaButtonClick(object source, EventArgs e) - { - string[] namespaces = GetSchemaListBoxNamespaces(); - using (SelectXmlSchemaForm form = new SelectXmlSchemaForm(namespaces)) { - form.SelectedNamespaceUri = schemaTextBox.Text; - if (form.ShowDialog(this) == DialogResult.OK) { - schemaTextBox.Text = form.SelectedNamespaceUri; - XmlSchemaAssociationListBoxItem item = (XmlSchemaAssociationListBoxItem)fileExtensionComboBox.SelectedItem; - item.NamespaceUri = form.SelectedNamespaceUri; - item.IsDirty = true; - } - } - } - - /// - /// Reads the configured xml file extensions and their associated namespaces. - /// - void PopulateFileExtensionComboBox() - { - string [] extensions = XmlDisplayBinding.GetXmlFileExtensions(); - - foreach (string extension in extensions) { - XmlSchemaAssociation association = XmlEditorAddInOptions.GetSchemaAssociation(extension); - XmlSchemaAssociationListBoxItem item = new XmlSchemaAssociationListBoxItem(association.Extension, association.NamespaceUri, association.NamespacePrefix); - fileExtensionComboBox.Items.Add(item); - } - - if (fileExtensionComboBox.Items.Count > 0) { - fileExtensionComboBox.SelectedIndex = 0; - FileExtensionComboBoxSelectedIndexChanged(this, new EventArgs()); - } - } - - /// - /// Updates the configured file extension to namespace mappings. - /// - void UpdateSchemaAssociations() - { - foreach (XmlSchemaAssociationListBoxItem item in fileExtensionComboBox.Items) { - if (item.IsDirty) { - XmlSchemaAssociation association = new XmlSchemaAssociation(item.Extension, item.NamespaceUri, item.NamespacePrefix); - XmlEditorAddInOptions.SetSchemaAssociation(association); - } - } - } - - /// - /// Returns an array of schema namespace strings that will be displayed - /// when the user chooses to associated a namespace to a file extension - /// by default. - /// - string[] GetSchemaListBoxNamespaces() - { - string[] namespaces = new string[schemaListBox.Items.Count]; - - for (int i = 0; i < schemaListBox.Items.Count; ++i) { - XmlSchemaListBoxItem item = (XmlSchemaListBoxItem)schemaListBox.Items[i]; - namespaces[i] = item.NamespaceUri; - } - - return namespaces; - } - - /// - /// User has changed the namespace prefix. - /// - void NamespacePrefixTextBoxTextChanged(object source, EventArgs e) - { - if (!ignoreNamespacePrefixTextChanges) { - XmlSchemaAssociationListBoxItem item = fileExtensionComboBox.SelectedItem as XmlSchemaAssociationListBoxItem; - if (item != null) { - item.NamespacePrefix = namespacePrefixTextBox.Text; - item.IsDirty = true; - } - } - } - } - * */ -} diff --git a/src/AddIns/BackendBindings/XmlBinding/XmlBinding.csproj b/src/AddIns/BackendBindings/XmlBinding/XmlBinding.csproj index 780094b0e8..3d28f64d52 100644 --- a/src/AddIns/BackendBindings/XmlBinding/XmlBinding.csproj +++ b/src/AddIns/BackendBindings/XmlBinding/XmlBinding.csproj @@ -85,8 +85,8 @@ - - + + @@ -115,8 +115,6 @@ - - @@ -135,8 +133,6 @@ - - @@ -144,9 +140,6 @@ - - UserControl - diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/AbstractOptionPanel.cs b/src/Main/Base/Project/Src/Gui/Dialogs/AbstractOptionPanel.cs index ee9d9b94ea..ead1e771d0 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/AbstractOptionPanel.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/AbstractOptionPanel.cs @@ -1,20 +1,58 @@ // // // -// +// // $Revision$ // using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Windows.Controls; +using System.Windows.Data; + +using ICSharpCode.Core.Presentation; namespace ICSharpCode.SharpDevelop.Gui { - public abstract class AbstractOptionPanel : IOptionPanel + public abstract class AbstractOptionPanel : UserControl, IOptionPanel, IOptionBindingContainer { public virtual object Owner { get; set; } - public abstract object Control { get; } + IList bindings; + + public IList Bindings { + get { + return bindings; + } + } + + public virtual object Control { + get { + return this; + } + } + public abstract void LoadOptions(); - public abstract bool SaveOptions(); + + public virtual bool SaveOptions() + { + foreach (OptionBinding b in Bindings) { + if (!b.Save()) + return false; + } + + return true; + } + + public AbstractOptionPanel() + { + this.bindings = new List(); + } + + public void AddBinding(OptionBinding binding) + { + this.bindings.Add(binding); + } } } diff --git a/src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj b/src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj index 54fed8d8d4..6e887527f1 100644 --- a/src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj +++ b/src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj @@ -65,6 +65,7 @@ + @@ -72,10 +73,12 @@ + + diff --git a/src/Main/ICSharpCode.Core.Presentation/IOptionBindingContainer.cs b/src/Main/ICSharpCode.Core.Presentation/IOptionBindingContainer.cs new file mode 100644 index 0000000000..d214d70200 --- /dev/null +++ b/src/Main/ICSharpCode.Core.Presentation/IOptionBindingContainer.cs @@ -0,0 +1,24 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.ComponentModel; +using System.Reflection; +using System.Windows; +using System.Windows.Data; +using System.Windows.Markup; + +namespace ICSharpCode.Core.Presentation +{ + /// + /// Provides access to objects containing OptionBindings, such as OptionPanels. + /// + public interface IOptionBindingContainer + { + void AddBinding(OptionBinding binding); + } +} diff --git a/src/Main/ICSharpCode.Core.Presentation/LocalizeExtension.cs b/src/Main/ICSharpCode.Core.Presentation/LocalizeExtension.cs index 38fee19842..ea213bf16e 100644 --- a/src/Main/ICSharpCode.Core.Presentation/LocalizeExtension.cs +++ b/src/Main/ICSharpCode.Core.Presentation/LocalizeExtension.cs @@ -6,6 +6,10 @@ // using System; +using System.ComponentModel; +using System.Reflection; +using System.Windows; +using System.Windows.Data; using System.Windows.Markup; namespace ICSharpCode.Core.Presentation @@ -28,21 +32,8 @@ namespace ICSharpCode.Core.Presentation } } - /// - /// Markup extension that works like StringParser.Parse - /// - public class StringParseExtension : MarkupExtension - { - protected string text; - - public StringParseExtension(string text) - { - this.text = text; - } - - public override object ProvideValue(IServiceProvider serviceProvider) - { - return StringParser.Parse(text); - } - } + + + + } diff --git a/src/Main/ICSharpCode.Core.Presentation/OptionBinding.cs b/src/Main/ICSharpCode.Core.Presentation/OptionBinding.cs new file mode 100644 index 0000000000..182e6d102d --- /dev/null +++ b/src/Main/ICSharpCode.Core.Presentation/OptionBinding.cs @@ -0,0 +1,111 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.ComponentModel; +using System.Reflection; +using System.Windows; +using System.Windows.Data; +using System.Windows.Markup; + +namespace ICSharpCode.Core.Presentation +{ + /// + /// Custom binding to allow direct bindings of option properties to WPF controls. + /// + /// + /// Properties accessed by this binding have to be managed by a custom
+ /// settings class, which contains all settings as static properties or fields.
+ /// Do not use PropertyService directly!
+ /// This markup extension can only be used in OptionPanels or other
classes implementing IOptionBindingContainer! + ///
+ /// Example: + /// + /// {sd:OptionBinding addin:XmlEditorAddInOptions.ShowAttributesWhenFolded} + /// + ///
+ /// Whereas 'sd' is the xml namespace of ICSharpCode.Core.Presentation.OptionBinding and 'addin'
+ /// is the xml namespace, in which your settings class is defined. + ///
+ public class OptionBinding : MarkupExtension + { + public string PropertyName { get; set; } + + DependencyObject target; + DependencyProperty dp; + + object propertyInfo; + + public OptionBinding(string propertyName) + { + this.PropertyName = propertyName; + } + + public override object ProvideValue(IServiceProvider provider) + { + IProvideValueTarget service = (IProvideValueTarget)provider.GetService(typeof(IProvideValueTarget)); + + if (service == null) + return null; + + target = service.TargetObject as DependencyObject; + dp = service.TargetProperty as DependencyProperty; + + if (target == null || dp == null) + return null; + + string[] name = PropertyName.Split('.'); + IXamlTypeResolver typeResolver = provider.GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver; + Type t = typeResolver.Resolve(name[0]); + + this.propertyInfo = t.GetProperty(name[1]); + + IOptionBindingContainer container = TryFindContainer(target as FrameworkElement); + + if (container == null) + throw new InvalidOperationException("This extension can only be used in OptionPanels"); + + container.AddBinding(this); + + if (this.propertyInfo is PropertyInfo) + return (propertyInfo as PropertyInfo).GetValue(null, null); + else { + this.propertyInfo = t.GetField(name[1]); + if (this.propertyInfo is FieldInfo) + return (propertyInfo as FieldInfo).GetValue(null); + } + + return null; + } + + IOptionBindingContainer TryFindContainer(FrameworkElement start) + { + if (start == null) + return null; + + while (start != null && !(start is IOptionBindingContainer)) + start = start.Parent as FrameworkElement; + + return start as IOptionBindingContainer; + } + + public bool Save() + { + if (propertyInfo is PropertyInfo) { + (propertyInfo as PropertyInfo).SetValue(null, target.GetValue(dp), null); + return true; + } + + if (propertyInfo is FieldInfo) { + (propertyInfo as FieldInfo).SetValue(null, target.GetValue(dp)); + return true; + } + + return false; + } + } +} diff --git a/src/Main/ICSharpCode.Core.Presentation/StringParseExtension.cs b/src/Main/ICSharpCode.Core.Presentation/StringParseExtension.cs new file mode 100644 index 0000000000..de2281a6f7 --- /dev/null +++ b/src/Main/ICSharpCode.Core.Presentation/StringParseExtension.cs @@ -0,0 +1,34 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.ComponentModel; +using System.Reflection; +using System.Windows; +using System.Windows.Data; +using System.Windows.Markup; + +namespace ICSharpCode.Core.Presentation +{ + /// + /// Markup extension that works like StringParser.Parse + /// + public class StringParseExtension : MarkupExtension + { + protected string text; + + public StringParseExtension(string text) + { + this.text = text; + } + + public override object ProvideValue(IServiceProvider serviceProvider) + { + return StringParser.Parse(text); + } + } +}