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 @@
>
-
-
+
+
-
+
\ No newline at end of file
diff --git a/src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/SelectXmlSchema.xaml.cs b/src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/SelectXmlSchema.xaml.cs
index 567d891e52..83bd9fa7a4 100644
--- a/src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/SelectXmlSchema.xaml.cs
+++ b/src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/SelectXmlSchema.xaml.cs
@@ -1,5 +1,7 @@
-using System;
+using ICSharpCode.Core;
+using System;
using System.Collections.Generic;
+using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
@@ -10,7 +12,6 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
-
namespace ICSharpCode.XmlBinding.Gui.Dialogs
{
///
@@ -18,10 +19,62 @@ namespace ICSharpCode.XmlBinding.Gui.Dialogs
///
public partial class SelectXmlSchema : Window
{
- public SelectXmlSchema()
+ string noSelection;
+
+ public SelectXmlSchema(string[] namespaces)
{
InitializeComponent();
+ PopulateListBox(namespaces);
+
+ noSelection = StringParser.Parse("${res:Dialog.Options.IDEOptions.TextEditor.Behaviour.IndentStyle.None}");
}
-
+
+ void BtnOKClick(object sender, RoutedEventArgs e)
+ {
+ this.DialogResult = true;
+ }
+
+ void BtnCancelClick(object sender, RoutedEventArgs e)
+ {
+ this.DialogResult = false;
+ }
+
+ ///
+ /// Gets or sets the selected schema namesace.
+ ///
+ public string SelectedNamespaceUri {
+ get {
+ string namespaceUri = schemaListBox.SelectedItem.ToString();
+ if (namespaceUri == noSelection) {
+ namespaceUri = string.Empty;
+ }
+ return namespaceUri;
+ }
+ set {
+ int index = 0;
+ if (value.Length > 0) {
+ index = schemaListBox.Items.IndexOf(value);
+ }
+
+ // Select the option representing "no schema" if
+ // the value does not exist in the list box.
+ if (index == -1) {
+ index = 0;
+ }
+
+ schemaListBox.SelectedIndex = index;
+ }
+ }
+
+ void PopulateListBox(string[] namespaces)
+ {
+ var list = namespaces.OrderBy(item => item);
+
+ foreach (string schemaNamespace in namespaces) {
+ schemaListBox.Items.Add(schemaNamespace);
+ }
+
+ schemaListBox.Items.Insert(0, noSelection);
+ }
}
}
\ No newline at end of file
diff --git a/src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/XmlEditorOptionsPanel.xaml b/src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/XmlEditorOptionsPanel.xaml
index b85288f1e3..bad8d5df90 100644
--- a/src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/XmlEditorOptionsPanel.xaml
+++ b/src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/XmlEditorOptionsPanel.xaml
@@ -1,13 +1,19 @@
-
-
+
-
+
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/XmlEditorOptionsPanel.xaml.cs b/src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/XmlEditorOptionsPanel.xaml.cs
index 67fab157cc..f0f8c685d5 100644
--- a/src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/XmlEditorOptionsPanel.xaml.cs
+++ b/src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/XmlEditorOptionsPanel.xaml.cs
@@ -1,4 +1,4 @@
-using ICSharpCode.XmlEditor;
+using ICSharpCode.SharpDevelop.Gui;
using System;
using System.Collections.Generic;
using System.Text;
@@ -12,35 +12,28 @@ using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ICSharpCode.SharpDevelop;
+using ICSharpCode.XmlEditor;
namespace ICSharpCode.XmlBinding.Gui.Dialogs
{
///
/// Interaction logic for XmlEditorOptionsPanel.xaml
///
- public partial class XmlEditorOptionsPanel : UserControl, IOptionPanel
+ public partial class XmlEditorOptionsPanel : AbstractOptionPanel
{
public XmlEditorOptionsPanel()
{
InitializeComponent();
}
-
- public object Owner { get; set; }
-
- public object Control {
- get {
- return this;
- }
- }
- public void LoadOptions()
+ public override void LoadOptions()
{
- chkShowAttributesWhenFolded.IsChecked = XmlEditorAddInOptions.ShowAttributesWhenFolded;
- chkShowSchemaAnnotation.IsChecked = XmlEditorAddInOptions.ShowSchemaAnnotation;
}
- public bool SaveOptions()
+ public override bool SaveOptions()
{
+ base.SaveOptions();
+
XmlEditorAddInOptions.ShowAttributesWhenFolded = chkShowAttributesWhenFolded.IsChecked == true;
XmlEditorAddInOptions.ShowSchemaAnnotation = chkShowSchemaAnnotation.IsChecked == true;
diff --git a/src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/XmlSchemasPanel.xaml b/src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/XmlSchemasPanel.xaml
index f2f44f31da..9ca5bd02cf 100644
--- a/src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/XmlSchemasPanel.xaml
+++ b/src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/XmlSchemasPanel.xaml
@@ -1,38 +1,47 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:sd="http://icsharpcode.net/sharpdevelop/core"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/XmlSchemasPanel.xaml.cs b/src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/XmlSchemasPanel.xaml.cs
index 556824dd0f..d615a2d4d2 100644
--- a/src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/XmlSchemasPanel.xaml.cs
+++ b/src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/XmlSchemasPanel.xaml.cs
@@ -1,21 +1,14 @@
using System;
-using System.Collections.Generic;
using System.Collections.Specialized;
-using System.Drawing;
-using System.Text;
+using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
using System.Windows.Shapes;
+using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
-using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.XmlEditor;
+using Microsoft.Win32;
namespace ICSharpCode.XmlBinding.Gui.Dialogs
{
@@ -28,6 +21,11 @@ namespace ICSharpCode.XmlBinding.Gui.Dialogs
{
InitializeComponent();
}
+
+ bool ignoreNamespacePrefixTextChanges;
+ bool changed;
+ XmlSchemaCompletionDataCollection addedSchemas = new XmlSchemaCompletionDataCollection();
+ StringCollection removedSchemaNamespaces = new StringCollection();
public object Owner { get; set; }
@@ -39,11 +37,320 @@ namespace ICSharpCode.XmlBinding.Gui.Dialogs
public void LoadOptions()
{
+ PopulateSchemaListBox();
+ PopulateFileExtensionComboBox();
}
+ ///
+ /// Saves any changes to the configured schemas.
+ ///
public bool SaveOptions()
{
- return false;
+ 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;
+ }
+
+ ///
+ /// 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);
+ }
+ }
+ }
+
+ ///
+ /// 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);
+ }
+
+ schemaListBox.Items.SortDescriptions.Add(new SortDescription("NamespaceUri", ListSortDirection.Ascending));
+ }
+
+ ///
+ /// 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);
+ }
+
+ fileExtensionComboBox.Items.SortDescriptions.Add(new SortDescription("Extension", ListSortDirection.Ascending));
+
+ if (fileExtensionComboBox.Items.Count > 0) {
+ fileExtensionComboBox.SelectedIndex = 0;
+ FileExtensionComboBoxSelectionChanged(this, null);
+ }
+ }
+
+ ///
+ /// Shows the namespace associated with the selected xml file extension.
+ ///
+ void FileExtensionComboBoxSelectionChanged(object sender, SelectionChangedEventArgs 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;
+ }
+ }
+
+ ///
+ /// Enables the remove button if a list box item is selected.
+ ///
+ void SchemaListBoxSelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ XmlSchemaListBoxItem item = schemaListBox.SelectedItem as XmlSchemaListBoxItem;
+ if (item != null) {
+ if (item.ReadOnly) {
+ btnRemove.IsEnabled = false;
+ } else {
+ btnRemove.IsEnabled = true;
+ }
+ } else {
+ btnRemove.IsEnabled = false;
+ }
+ }
+
+ void BtnAddClick(object sender, RoutedEventArgs 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 BtnRemoveClick(object sender, RoutedEventArgs e)
+ {
+ // Remove selected schema.
+ XmlSchemaListBoxItem item = schemaListBox.SelectedItem as XmlSchemaListBoxItem;
+ if (item != null) {
+ RemoveSchema(item.NamespaceUri);
+ changed = true;
+ }
+ }
+
+ ///
+ /// 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;
+
+ 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() ?? false) {
+ 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}", System.IO.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);
+ }
+ }
+
+ ///
+ /// User has changed the namespace prefix.
+ ///
+ void NamespacePrefixTextBoxTextChanged(object sender, TextChangedEventArgs e)
+ {
+ if (!ignoreNamespacePrefixTextChanges) {
+ XmlSchemaAssociationListBoxItem item = fileExtensionComboBox.SelectedItem as XmlSchemaAssociationListBoxItem;
+ if (item != null) {
+ item.NamespacePrefix = namespacePrefixTextBox.Text;
+ item.IsDirty = true;
+ }
+ }
+ }
+
+ ///
+ /// 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;
+ }
+
+ ///
+ /// Allows the user to change the schema associated with an xml file
+ /// extension.
+ ///
+ void BtnChangeSchemaClick(object sender, RoutedEventArgs e)
+ {
+ string[] namespaces = GetSchemaListBoxNamespaces();
+ SelectXmlSchema form = new SelectXmlSchema(namespaces);
+ form.SelectedNamespaceUri = schemaTextBox.Text;
+ if (form.ShowDialog() ?? false) {
+ schemaTextBox.Text = form.SelectedNamespaceUri;
+ XmlSchemaAssociationListBoxItem item = (XmlSchemaAssociationListBoxItem)fileExtensionComboBox.SelectedItem;
+ item.NamespaceUri = form.SelectedNamespaceUri;
+ item.IsDirty = true;
+ }
}
}
}
\ No newline at end of file
diff --git a/src/AddIns/BackendBindings/XmlBinding/Src/Gui/SelectXmlSchemaForm.cs b/src/AddIns/BackendBindings/XmlBinding/Src/Gui/SelectXmlSchemaForm.cs
deleted file mode 100644
index a3c1a81271..0000000000
--- a/src/AddIns/BackendBindings/XmlBinding/Src/Gui/SelectXmlSchemaForm.cs
+++ /dev/null
@@ -1,90 +0,0 @@
-//
-//
-//
-//
-// $Revision: -1 $
-//
-
-using System;
-using System.Windows.Forms;
-using ICSharpCode.Core;
-using ICSharpCode.SharpDevelop.Gui.XmlForms;
-
-namespace ICSharpCode.XmlEditor
-{
- ///
- /// Allows the use to choose a schema from the schemas that SharpDevelop
- /// knows about.
- ///
- public class SelectXmlSchemaForm : XmlForm
- {
- ListBox schemaListBox;
- string NoSchemaSelectedText = String.Empty;
-
- public SelectXmlSchemaForm(string[] namespaces)
- {
- Initialize();
- PopulateListBox(namespaces);
- }
-
- ///
- /// Gets or sets the selected schema namesace.
- ///
- public string SelectedNamespaceUri {
- get {
- string namespaceUri = schemaListBox.Text;
- if (namespaceUri == NoSchemaSelectedText) {
- namespaceUri = String.Empty;
- }
- return namespaceUri;
- }
-
- set {
- int index = 0;
- if (value.Length > 0) {
- index = schemaListBox.Items.IndexOf(value);
- }
-
- // Select the option representing "no schema" if
- // the value does not exist in the list box.
- if (index == -1) {
- index = 0;
- }
-
- schemaListBox.SelectedIndex = index;
- }
- }
-
- protected override void SetupXmlLoader()
- {
- xmlLoader.StringValueFilter = new SharpDevelopStringValueFilter();
- xmlLoader.PropertyValueCreator = new SharpDevelopPropertyValueCreator();
- }
-
- void Initialize()
- {
- SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("ICSharpCode.XmlEditor.Resources.SelectXmlSchema.xfrm"));
-
- NoSchemaSelectedText = StringParser.Parse("${res:Dialog.Options.IDEOptions.TextEditor.Behaviour.IndentStyle.None}");
-
- schemaListBox = (ListBox)ControlDictionary["schemaListBox"];
-
- AcceptButton = (Button)ControlDictionary["okButton"];
- CancelButton = (Button)ControlDictionary["cancelButton"];
- AcceptButton.DialogResult = DialogResult.OK;
- }
-
- void PopulateListBox(string[] namespaces)
- {
- foreach (string schemaNamespace in namespaces) {
- schemaListBox.Items.Add(schemaNamespace);
- }
-
- // Add the "None" string at the top of the list.
- schemaListBox.Sorted = true;
- schemaListBox.Sorted = false;
-
- schemaListBox.Items.Insert(0, NoSchemaSelectedText);
- }
- }
-}
diff --git a/src/AddIns/BackendBindings/XmlBinding/Src/Src/XmlEditorOptionsPanel.cs b/src/AddIns/BackendBindings/XmlBinding/Src/Src/XmlEditorOptionsPanel.cs
deleted file mode 100644
index f0b08fb765..0000000000
--- a/src/AddIns/BackendBindings/XmlBinding/Src/Src/XmlEditorOptionsPanel.cs
+++ /dev/null
@@ -1,49 +0,0 @@
-//
-//
-//
-//
-// $Revision: 3568 $
-//
-
-using ICSharpCode.SharpDevelop.Gui.OptionPanels;
-using System;
-using System.Windows.Forms;
-using ICSharpCode.SharpDevelop.Gui;
-
-namespace ICSharpCode.XmlEditor
-{
- ///
- /// Configuration settings for the xml editor.
- ///
- public class XmlEditorOptionsPanel : XmlFormsOptionPanel
- {
- static readonly string showAttributesWhenFoldedCheckBoxName = "showAttributesWhenFoldedCheckBox";
- static readonly string showSchemaAnnotationCheckBoxName = "showSchemaAnnotationCheckBox";
-
- public XmlEditorOptionsPanel()
- {
- }
-
- ///
- /// Initialises the panel.
- ///
- public override void LoadPanelContents()
- {
- SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("ICSharpCode.XmlEditor.Resources.XmlEditorOptionsPanel.xfrm"));
-
- ((CheckBox)ControlDictionary[showAttributesWhenFoldedCheckBoxName]).Checked = XmlEditorAddInOptions.ShowAttributesWhenFolded;
- ((CheckBox)ControlDictionary[showSchemaAnnotationCheckBoxName]).Checked = XmlEditorAddInOptions.ShowSchemaAnnotation;
- }
-
- ///
- /// Saves any changes.
- ///
- public override bool StorePanelContents()
- {
- XmlEditorAddInOptions.ShowAttributesWhenFolded = ((CheckBox)ControlDictionary[showAttributesWhenFoldedCheckBoxName]).Checked;
- XmlEditorAddInOptions.ShowSchemaAnnotation = ((CheckBox)ControlDictionary[showSchemaAnnotationCheckBoxName]).Checked;
-
- return true;
- }
- }
-}
diff --git a/src/AddIns/BackendBindings/XmlBinding/Src/Src/XmlSchemaCompletionData.cs b/src/AddIns/BackendBindings/XmlBinding/Src/Src/XmlSchemaCompletionData.cs
index 1b763fd5b3..5f9e4c9304 100644
--- a/src/AddIns/BackendBindings/XmlBinding/Src/Src/XmlSchemaCompletionData.cs
+++ b/src/AddIns/BackendBindings/XmlBinding/Src/Src/XmlSchemaCompletionData.cs
@@ -152,7 +152,7 @@ namespace ICSharpCode.XmlEditor
///
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);
+ }
+ }
+}