Browse Source

- 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
shortcuts
Siegfried Pammer 17 years ago
parent
commit
176bd92662
  1. 30
      src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCodeCompletionBinding.cs
  2. 288
      src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCompletionDataCollection.cs
  3. 33
      src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCompletionItem.cs
  4. 117
      src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCompletionItemCollection.cs
  5. 6
      src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/SelectXmlSchema.xaml
  6. 61
      src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/SelectXmlSchema.xaml.cs
  7. 14
      src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/XmlEditorOptionsPanel.xaml
  8. 21
      src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/XmlEditorOptionsPanel.xaml.cs
  9. 81
      src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/XmlSchemasPanel.xaml
  10. 329
      src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/XmlSchemasPanel.xaml.cs
  11. 90
      src/AddIns/BackendBindings/XmlBinding/Src/Gui/SelectXmlSchemaForm.cs
  12. 49
      src/AddIns/BackendBindings/XmlBinding/Src/Src/XmlEditorOptionsPanel.cs
  13. 112
      src/AddIns/BackendBindings/XmlBinding/Src/Src/XmlSchemaCompletionData.cs
  14. 2
      src/AddIns/BackendBindings/XmlBinding/Src/Src/XmlSchemaListBoxItem.cs
  15. 412
      src/AddIns/BackendBindings/XmlBinding/Src/Src/XmlSchemasPanel.cs
  16. 11
      src/AddIns/BackendBindings/XmlBinding/XmlBinding.csproj
  17. 46
      src/Main/Base/Project/Src/Gui/Dialogs/AbstractOptionPanel.cs
  18. 3
      src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj
  19. 24
      src/Main/ICSharpCode.Core.Presentation/IOptionBindingContainer.cs
  20. 25
      src/Main/ICSharpCode.Core.Presentation/LocalizeExtension.cs
  21. 111
      src/Main/ICSharpCode.Core.Presentation/OptionBinding.cs
  22. 34
      src/Main/ICSharpCode.Core.Presentation/StringParseExtension.cs

30
src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCodeCompletionBinding.cs

@ -18,6 +18,17 @@ namespace ICSharpCode.XmlBinding @@ -18,6 +18,17 @@ namespace ICSharpCode.XmlBinding
/// </summary>
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 @@ -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;
}
}

288
src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCompletionDataCollection.cs

@ -1,288 +0,0 @@ @@ -1,288 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision: 1965 $</version>
// </file>
using ICSharpCode.SharpDevelop.Editor;
using System;
using System.Collections;
namespace ICSharpCode.XmlEditor
{
/// <summary>
/// A collection that stores <see cref='XmlCompletionData'/> objects.
/// </summary>
[Serializable()]
public class XmlCompletionDataCollection : CollectionBase {
/// <summary>
/// Initializes a new instance of <see cref='XmlCompletionDataCollection'/>.
/// </summary>
public XmlCompletionDataCollection()
{
}
/// <summary>
/// Initializes a new instance of <see cref='XmlCompletionDataCollection'/> based on another <see cref='XmlCompletionDataCollection'/>.
/// </summary>
/// <param name='val'>
/// A <see cref='XmlCompletionDataCollection'/> from which the contents are copied
/// </param>
public XmlCompletionDataCollection(XmlCompletionDataCollection val)
{
this.AddRange(val);
}
/// <summary>
/// Initializes a new instance of <see cref='XmlCompletionDataCollection'/> containing any array of <see cref='XmlCompletionData'/> objects.
/// </summary>
/// <param name='val'>
/// A array of <see cref='XmlCompletionData'/> objects with which to intialize the collection
/// </param>
public XmlCompletionDataCollection(XmlCompletionItem[] val)
{
this.AddRange(val);
}
/// <summary>
/// Represents the entry at the specified index of the <see cref='XmlCompletionData'/>.
/// </summary>
/// <param name='index'>The zero-based index of the entry to locate in the collection.</param>
/// <value>The entry at the specified index of the collection.</value>
/// <exception cref='ArgumentOutOfRangeException'><paramref name='index'/> is outside the valid range of indexes for the collection.</exception>
public XmlCompletionItem this[int index] {
get {
return ((XmlCompletionItem)(List[index]));
}
set {
List[index] = value;
}
}
/// <summary>
/// Adds a <see cref='XmlCompletionData'/> with the specified value to the
/// <see cref='XmlCompletionDataCollection'/>.
/// </summary>
/// <remarks>
/// If the completion data already exists in the collection it is not added.
/// </remarks>
/// <param name='val'>The <see cref='XmlCompletionData'/> to add.</param>
/// <returns>The index at which the new element was inserted.</returns>
/// <seealso cref='XmlCompletionDataCollection.AddRange'/>
public int Add(XmlCompletionItem val)
{
int index = -1;
if (!Contains(val)) {
index = List.Add(val);
}
return index;
}
/// <summary>
/// Copies the elements of an array to the end of the <see cref='XmlCompletionDataCollection'/>.
/// </summary>
/// <param name='val'>
/// An array of type <see cref='XmlCompletionData'/> containing the objects to add to the collection.
/// </param>
/// <seealso cref='XmlCompletionDataCollection.Add'/>
public void AddRange(XmlCompletionItem[] val)
{
for (int i = 0; i < val.Length; i++) {
this.Add(val[i]);
}
}
/// <summary>
/// Adds the contents of another <see cref='XmlCompletionDataCollection'/> to the end of the collection.
/// </summary>
/// <param name='val'>
/// A <see cref='XmlCompletionDataCollection'/> containing the objects to add to the collection.
/// </param>
/// <seealso cref='XmlCompletionDataCollection.Add'/>
public void AddRange(XmlCompletionDataCollection val)
{
for (int i = 0; i < val.Count; i++)
{
this.Add(val[i]);
}
}
/// <summary>
/// Gets a value indicating whether the
/// <see cref='XmlCompletionDataCollection'/> contains the specified <see cref='XmlCompletionData'/>.
/// </summary>
/// <param name='val'>The <see cref='XmlCompletionData'/> to locate.</param>
/// <returns>
/// <see langword='true'/> if the <see cref='XmlCompletionData'/> is contained in the collection;
/// otherwise, <see langword='false'/>.
/// </returns>
/// <seealso cref='XmlCompletionDataCollection.IndexOf'/>
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;
}
/// <summary>
/// Copies the <see cref='XmlCompletionDataCollection'/> values to a one-dimensional <see cref='Array'/> instance at the
/// specified index.
/// </summary>
/// <param name='array'>The one-dimensional <see cref='Array'/> that is the destination of the values copied from <see cref='XmlCompletionDataCollection'/>.</param>
/// <param name='index'>The index in <paramref name='array'/> where copying begins.</param>
/// <exception cref='ArgumentException'>
/// <para><paramref name='array'/> is multidimensional.</para>
/// <para>-or-</para>
/// <para>The number of elements in the <see cref='XmlCompletionDataCollection'/> is greater than
/// the available space between <paramref name='arrayIndex'/> and the end of
/// <paramref name='array'/>.</para>
/// </exception>
/// <exception cref='ArgumentNullException'><paramref name='array'/> is <see langword='null'/>. </exception>
/// <exception cref='ArgumentOutOfRangeException'><paramref name='arrayIndex'/> is less than <paramref name='array'/>'s lowbound. </exception>
/// <seealso cref='Array'/>
public void CopyTo(XmlCompletionItem[] array, int index)
{
List.CopyTo(array, index);
}
/// <summary>
/// Copies the <see cref='XmlCompletionDataCollection'/> values to a one-dimensional <see cref='Array'/> instance at the
/// specified index.
/// </summary>
public void CopyTo(ICompletionItem[] array, int index)
{
List.CopyTo(array, index);
}
/// <summary>
/// Returns the index of a <see cref='XmlCompletionData'/> in
/// the <see cref='XmlCompletionDataCollection'/>.
/// </summary>
/// <param name='val'>The <see cref='XmlCompletionData'/> to locate.</param>
/// <returns>
/// The index of the <see cref='XmlCompletionData'/> of <paramref name='val'/> in the
/// <see cref='XmlCompletionDataCollection'/>, if found; otherwise, -1.
/// </returns>
/// <seealso cref='XmlCompletionDataCollection.Contains'/>
public int IndexOf(XmlCompletionItem val)
{
return List.IndexOf(val);
}
/// <summary>
/// Inserts a <see cref='XmlCompletionData'/> into the <see cref='XmlCompletionDataCollection'/> at the specified index.
/// </summary>
/// <param name='index'>The zero-based index where <paramref name='val'/> should be inserted.</param>
/// <param name='val'>The <see cref='XmlCompletionData'/> to insert.</param>
/// <seealso cref='XmlCompletionDataCollection.Add'/>
public void Insert(int index, XmlCompletionItem val)
{
List.Insert(index, val);
}
/// <summary>
/// Returns an array of <see cref="ICompletionData"/> items.
/// </summary>
/// <returns></returns>
public ICompletionItem[] ToArray()
{
XmlCompletionItem[] data = new XmlCompletionItem[Count];
CopyTo(data, 0);
return data;
}
/// <summary>
/// Returns an enumerator that can iterate through the <see cref='XmlCompletionDataCollection'/>.
/// </summary>
/// <seealso cref='IEnumerator'/>
public new XmlCompletionDataEnumerator GetEnumerator()
{
return new XmlCompletionDataEnumerator(this);
}
/// <summary>
/// Removes a specific <see cref='XmlCompletionData'/> from the <see cref='XmlCompletionDataCollection'/>.
/// </summary>
/// <param name='val'>The <see cref='XmlCompletionData'/> to remove from the <see cref='XmlCompletionDataCollection'/>.</param>
/// <exception cref='ArgumentException'><paramref name='val'/> is not found in the Collection.</exception>
public void Remove(XmlCompletionItem val)
{
List.Remove(val);
}
/// <summary>
/// Enumerator that can iterate through a XmlCompletionDataCollection.
/// </summary>
/// <seealso cref='IEnumerator'/>
/// <seealso cref='XmlCompletionDataCollection'/>
/// <seealso cref='XmlCompletionData'/>
public class XmlCompletionDataEnumerator : IEnumerator
{
IEnumerator baseEnumerator;
IEnumerable temp;
/// <summary>
/// Initializes a new instance of <see cref='XmlCompletionDataEnumerator'/>.
/// </summary>
public XmlCompletionDataEnumerator(XmlCompletionDataCollection mappings)
{
this.temp = ((IEnumerable)(mappings));
this.baseEnumerator = temp.GetEnumerator();
}
/// <summary>
/// Gets the current <see cref='XmlCompletionData'/> in the <seealso cref='XmlCompletionDataCollection'/>.
/// </summary>
public XmlCompletionItem Current {
get {
return ((XmlCompletionItem)(baseEnumerator.Current));
}
}
object IEnumerator.Current {
get {
return baseEnumerator.Current;
}
}
/// <summary>
/// Advances the enumerator to the next <see cref='XmlCompletionData'/> of the <see cref='XmlCompletionDataCollection'/>.
/// </summary>
public bool MoveNext()
{
return baseEnumerator.MoveNext();
}
/// <summary>
/// Sets the enumerator to its initial position, which is before the first element in the <see cref='XmlCompletionDataCollection'/>.
/// </summary>
public void Reset()
{
baseEnumerator.Reset();
}
}
}
}

33
src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCompletionData.cs → src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCompletionItem.cs

@ -5,13 +5,13 @@ @@ -5,13 +5,13 @@
// <version>$Revision: 2932 $</version>
// </file>
using ICSharpCode.SharpDevelop.Editor;
using System;
using ICSharpCode.SharpDevelop.Editor;
namespace ICSharpCode.XmlEditor
namespace ICSharpCode.XmlBinding
{
/// <summary>
/// Holds the text for namespace, child element or attribute
/// Holds the text for namespace, child element or attribute
/// autocomplete (intellisense).
/// </summary>
public class XmlCompletionItem : DefaultCompletionItem
@ -42,14 +42,14 @@ namespace ICSharpCode.XmlEditor @@ -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;
}
/// <summary>
/// Returns the xml item's documentation as retrieved from
@ -65,16 +65,17 @@ namespace ICSharpCode.XmlEditor @@ -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;
}
}
}
}

117
src/AddIns/BackendBindings/XmlBinding/Src/CodeCompletion/XmlCompletionItemCollection.cs

@ -0,0 +1,117 @@ @@ -0,0 +1,117 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision: 1965 $</version>
// </file>
using ICSharpCode.XmlBinding;
using System;
using System.Collections;
using System.Collections.ObjectModel;
using ICSharpCode.SharpDevelop.Editor;
namespace ICSharpCode.XmlEditor
{
/// <summary>
/// A collection that stores <see cref='XmlCompletionData'/> objects.
/// </summary>
[Serializable()]
public class XmlCompletionItemCollection : Collection<XmlCompletionItem> {
/// <summary>
/// Initializes a new instance of <see cref='XmlCompletionDataCollection'/>.
/// </summary>
public XmlCompletionItemCollection()
{
}
/// <summary>
/// Initializes a new instance of <see cref='XmlCompletionDataCollection'/> based on another <see cref='XmlCompletionDataCollection'/>.
/// </summary>
/// <param name='val'>
/// A <see cref='XmlCompletionDataCollection'/> from which the contents are copied
/// </param>
public XmlCompletionItemCollection(XmlCompletionItemCollection val)
{
this.AddRange(val);
}
/// <summary>
/// Initializes a new instance of <see cref='XmlCompletionDataCollection'/> containing any array of <see cref='XmlCompletionData'/> objects.
/// </summary>
/// <param name='val'>
/// A array of <see cref='XmlCompletionData'/> objects with which to intialize the collection
/// </param>
public XmlCompletionItemCollection(XmlCompletionItem[] val)
{
this.AddRange(val);
}
/// <summary>
/// Copies the elements of an array to the end of the <see cref='XmlCompletionDataCollection'/>.
/// </summary>
/// <param name='val'>
/// An array of type <see cref='XmlCompletionData'/> containing the objects to add to the collection.
/// </param>
/// <seealso cref='XmlCompletionDataCollection.Add'/>
public void AddRange(XmlCompletionItem[] val)
{
for (int i = 0; i < val.Length; i++) {
this.Add(val[i]);
}
}
/// <summary>
/// Adds the contents of another <see cref='XmlCompletionDataCollection'/> to the end of the collection.
/// </summary>
/// <param name='val'>
/// A <see cref='XmlCompletionDataCollection'/> containing the objects to add to the collection.
/// </param>
/// <seealso cref='XmlCompletionDataCollection.Add'/>
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;
}
/// <summary>
/// Copies the <see cref='XmlCompletionDataCollection'/> values to a one-dimensional <see cref='Array'/> instance at the
/// specified index.
/// </summary>
public void CopyTo(ICompletionItem[] array, int index)
{
for (int i = index; i < this.Count; i++)
array[i] = this[i - index];
}
/// <summary>
/// Returns an array of <see cref="ICompletionData"/> items.
/// </summary>
/// <returns></returns>
public ICompletionItem[] ToArray()
{
XmlCompletionItem[] data = new XmlCompletionItem[Count];
CopyTo(data, 0);
return data;
}
}
}

6
src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/SelectXmlSchema.xaml

@ -6,9 +6,9 @@ @@ -6,9 +6,9 @@
>
<DockPanel>
<StackPanel DockPanel.Dock="Bottom" Height="25" Orientation="Horizontal" HorizontalAlignment="Right">
<Button Margin="3,0" Content="{sd:Localize Global.OKButtonText}" />
<Button Margin="3,0" Content="{sd:Localize Global.CancelButtonText}" />
<Button Margin="3,0" Name="btnOK" Content="{sd:Localize Global.OKButtonText}" Click="BtnOKClick" />
<Button Margin="3,0" Name="btnCancel" Content="{sd:Localize Global.CancelButtonText}" Click="BtnCancelClick" />
</StackPanel>
<ListBox Margin="5" />
<ListBox Margin="5" Name="schemaListBox" />
</DockPanel>
</Window>

61
src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/SelectXmlSchema.xaml.cs

@ -1,5 +1,7 @@ @@ -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; @@ -10,7 +12,6 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace ICSharpCode.XmlBinding.Gui.Dialogs
{
/// <summary>
@ -18,10 +19,62 @@ namespace ICSharpCode.XmlBinding.Gui.Dialogs @@ -18,10 +19,62 @@ namespace ICSharpCode.XmlBinding.Gui.Dialogs
/// </summary>
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;
}
/// <summary>
/// Gets or sets the selected schema namesace.
/// </summary>
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);
}
}
}

14
src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/XmlEditorOptionsPanel.xaml

@ -1,13 +1,19 @@ @@ -1,13 +1,19 @@
<UserControl x:Class="ICSharpCode.XmlBinding.Gui.Dialogs.XmlEditorOptionsPanel"
<gui:AbstractOptionPanel x:Class="ICSharpCode.XmlBinding.Gui.Dialogs.XmlEditorOptionsPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:sd="http://icsharpcode.net/sharpdevelop/core"
xmlns:gui="clr-namespace:ICSharpCode.SharpDevelop.Gui;assembly=ICSharpCode.SharpDevelop"
xmlns:addin="clr-namespace:ICSharpCode.XmlEditor"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel>
<GroupBox Margin="5" Header="{sd:Localize ICSharpCode.XmlEditor.XmlEditorOptionsPanel.FoldingGroupLabel}">
<CheckBox x:Name="chkShowAttributesWhenFolded" Content="{sd:Localize ICSharpCode.XmlEditor.XmlEditorOptionsPanel.ShowAttributesWhenFoldedLabel}" />
<CheckBox x:Name="chkShowAttributesWhenFolded"
Content="{sd:Localize ICSharpCode.XmlEditor.XmlEditorOptionsPanel.ShowAttributesWhenFoldedLabel}"
IsChecked="{sd:OptionBinding addin:XmlEditorAddInOptions.ShowAttributesWhenFolded}" />
</GroupBox>
<GroupBox Margin="5" Header="{sd:Localize ICSharpCode.XmlEditor.XmlEditorOptionsPanel.XmlCompletionGroupLabel}">
<CheckBox x:Name="chkShowSchemaAnnotation" Content="{sd:Localize ICSharpCode.XmlEditor.XmlEditorOptionsPanel.ShowSchemaAnnotationLabel}" />
<CheckBox x:Name="chkShowSchemaAnnotation"
Content="{sd:Localize ICSharpCode.XmlEditor.XmlEditorOptionsPanel.ShowSchemaAnnotationLabel}"
IsChecked="{sd:OptionBinding addin:XmlEditorAddInOptions.ShowSchemaAnnotation}" />
</GroupBox>
</StackPanel>
</UserControl>
</gui:AbstractOptionPanel>

21
src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/XmlEditorOptionsPanel.xaml.cs

@ -1,4 +1,4 @@ @@ -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; @@ -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
{
/// <summary>
/// Interaction logic for XmlEditorOptionsPanel.xaml
/// </summary>
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;

81
src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/XmlSchemasPanel.xaml

@ -1,38 +1,47 @@ @@ -1,38 +1,47 @@
<UserControl x:Class="ICSharpCode.XmlBinding.Gui.Dialogs.XmlSchemasPanel"
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">
<StackPanel>
<GroupBox Header="{sd:Localize ICSharpCode.XmlEditor.XmlSchemaPanel.SchemasGroupBoxText}">
<DockPanel>
<StackPanel Orientation="Horizontal" DockPanel.Dock="Bottom" HorizontalAlignment="Right">
<Button Margin="3,0" Content="{sd:StringParse ${res:Global.AddButtonText}...}" />
<Button Margin="3,0" Content="{sd:Localize Global.RemoveButtonText}" />
</StackPanel>
<ListBox Height="100" Margin="5" />
</DockPanel>
</GroupBox>
<GroupBox Header="{sd:Localize ICSharpCode.XmlEditor.XmlSchemaPanel.FileExtensionsGroupBoxText}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Grid.Row="0" Content="{sd:Localize ICSharpCode.XmlEditor.XmlSchemaPanel.FileExtensionLabelText}" />
<Label Grid.Column="0" Grid.Row="1" Content="{sd:Localize ICSharpCode.XmlEditor.XmlSchemaPanel.SchemaLabelText}" />
<Label Grid.Column="0" Grid.Row="2" Content="{sd:Localize ICSharpCode.XmlEditor.XmlSchemaPanel.NamespacePrefixLabelText}" />
<ComboBox Grid.Column="1" Grid.Row="0" />
<DockPanel Grid.Column="1" Grid.Row="1">
<Button DockPanel.Dock="Right" Margin="3,0,0,0" Padding="5,0" Content="..." />
<TextBox />
</DockPanel>
<TextBox Grid.Column="1" Grid.Row="2" />
</Grid>
</GroupBox>
</StackPanel>
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">
<UserControl.Resources>
<Style TargetType="{x:Type ListBoxItem}">
<Style.Triggers>
<DataTrigger Binding="{Binding ReadOnly}" Value="True">
<Setter Property="Foreground" Value="Gray" />
</DataTrigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
<StackPanel>
<GroupBox Header="{sd:Localize ICSharpCode.XmlEditor.XmlSchemaPanel.SchemasGroupBoxText}">
<DockPanel>
<StackPanel Orientation="Horizontal" DockPanel.Dock="Bottom" HorizontalAlignment="Right">
<Button Margin="3,0" Name="btnAdd" Content="{sd:StringParse ${res:Global.AddButtonText}...}" Click="BtnAddClick" />
<Button Margin="3,0" Name="btnRemove" IsEnabled="False" Content="{sd:Localize Global.RemoveButtonText}" Click="BtnRemoveClick" />
</StackPanel>
<ListBox Name="schemaListBox" Height="100" Margin="5" SelectionChanged="SchemaListBoxSelectionChanged" />
</DockPanel>
</GroupBox>
<GroupBox Header="{sd:Localize ICSharpCode.XmlEditor.XmlSchemaPanel.FileExtensionsGroupBoxText}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Grid.Row="0" Content="{sd:Localize ICSharpCode.XmlEditor.XmlSchemaPanel.FileExtensionLabelText}" />
<Label Grid.Column="0" Grid.Row="1" Content="{sd:Localize ICSharpCode.XmlEditor.XmlSchemaPanel.SchemaLabelText}" />
<Label Grid.Column="0" Grid.Row="2" Content="{sd:Localize ICSharpCode.XmlEditor.XmlSchemaPanel.NamespacePrefixLabelText}" />
<ComboBox Name="fileExtensionComboBox" Grid.Column="1" Grid.Row="0" Margin="3" SelectionChanged="FileExtensionComboBoxSelectionChanged" />
<DockPanel Grid.Column="1" Grid.Row="1">
<Button Name="ChangeSchema" DockPanel.Dock="Right" Margin="3" Content="..." Click="BtnChangeSchemaClick" />
<TextBox Name="schemaTextBox" Margin="3" />
</DockPanel>
<TextBox Name="namespacePrefixTextBox" Grid.Column="1" Grid.Row="2" Margin="3" TextChanged="NamespacePrefixTextBoxTextChanged" />
</Grid>
</GroupBox>
</StackPanel>
</UserControl>

329
src/AddIns/BackendBindings/XmlBinding/Src/Gui/Dialogs/XmlSchemasPanel.xaml.cs

@ -1,21 +1,14 @@ @@ -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 @@ -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 @@ -39,11 +37,320 @@ namespace ICSharpCode.XmlBinding.Gui.Dialogs
public void LoadOptions()
{
PopulateSchemaListBox();
PopulateFileExtensionComboBox();
}
/// <summary>
/// Saves any changes to the configured schemas.
/// </summary>
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;
}
/// <summary>
/// Updates the configured file extension to namespace mappings.
/// </summary>
void UpdateSchemaAssociations()
{
foreach (XmlSchemaAssociationListBoxItem item in fileExtensionComboBox.Items) {
if (item.IsDirty) {
XmlSchemaAssociation association = new XmlSchemaAssociation(item.Extension, item.NamespaceUri, item.NamespacePrefix);
XmlEditorAddInOptions.SetSchemaAssociation(association);
}
}
}
/// <summary>
/// Adds the schema namespaces to the list.
/// </summary>
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));
}
/// <summary>
/// Reads the configured xml file extensions and their associated namespaces.
/// </summary>
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);
}
}
/// <summary>
/// Shows the namespace associated with the selected xml file extension.
/// </summary>
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;
}
}
/// <summary>
/// Enables the remove button if a list box item is selected.
/// </summary>
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;
}
}
/// <summary>
/// Saves any changes to the configured schemas.
/// </summary>
/// <returns></returns>
bool SaveSchemaChanges()
{
RemoveUserSchemas();
AddUserSchemas();
return true;
}
/// <summary>
/// Allows the user to browse the file system for a schema.
/// </summary>
/// <returns>The schema file name the user selected; otherwise an
/// empty string.</returns>
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;
}
/// <summary>
/// Loads the specified schema and adds it to an internal collection.
/// </summary>
/// <remarks>The schema file is not copied to the user's schema folder
/// until they click the OK button.</remarks>
/// <returns><see langword="true"/> if the schema namespace
/// does not already exist; otherwise <see langword="false"/>
/// </returns>
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;
}
/// <summary>
/// Checks that the schema namespace does not already exist.
/// </summary>
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;
}
/// <summary>
/// Schedules the schema for removal.
/// </summary>
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;
}
}
}
/// <summary>
/// Removes the schemas from the schema manager.
/// </summary>
void RemoveUserSchemas()
{
while (removedSchemaNamespaces.Count > 0) {
XmlSchemaManager.RemoveUserSchema(removedSchemaNamespaces[0]);
removedSchemaNamespaces.RemoveAt(0);
}
}
/// <summary>
/// Adds the schemas to the schema manager.
/// </summary>
void AddUserSchemas()
{
while (addedSchemas.Count > 0) {
XmlSchemaManager.AddUserSchema(addedSchemas[0]);
addedSchemas.RemoveAt(0);
}
}
/// <summary>
/// User has changed the namespace prefix.
/// </summary>
void NamespacePrefixTextBoxTextChanged(object sender, TextChangedEventArgs e)
{
if (!ignoreNamespacePrefixTextChanges) {
XmlSchemaAssociationListBoxItem item = fileExtensionComboBox.SelectedItem as XmlSchemaAssociationListBoxItem;
if (item != null) {
item.NamespacePrefix = namespacePrefixTextBox.Text;
item.IsDirty = true;
}
}
}
/// <summary>
/// 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.
/// </summary>
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;
}
/// <summary>
/// Allows the user to change the schema associated with an xml file
/// extension.
/// </summary>
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;
}
}
}
}

90
src/AddIns/BackendBindings/XmlBinding/Src/Gui/SelectXmlSchemaForm.cs

@ -1,90 +0,0 @@ @@ -1,90 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision: -1 $</version>
// </file>
using System;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui.XmlForms;
namespace ICSharpCode.XmlEditor
{
/// <summary>
/// Allows the use to choose a schema from the schemas that SharpDevelop
/// knows about.
/// </summary>
public class SelectXmlSchemaForm : XmlForm
{
ListBox schemaListBox;
string NoSchemaSelectedText = String.Empty;
public SelectXmlSchemaForm(string[] namespaces)
{
Initialize();
PopulateListBox(namespaces);
}
/// <summary>
/// Gets or sets the selected schema namesace.
/// </summary>
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);
}
}
}

49
src/AddIns/BackendBindings/XmlBinding/Src/Src/XmlEditorOptionsPanel.cs

@ -1,49 +0,0 @@ @@ -1,49 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision: 3568 $</version>
// </file>
using ICSharpCode.SharpDevelop.Gui.OptionPanels;
using System;
using System.Windows.Forms;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.XmlEditor
{
/// <summary>
/// Configuration settings for the xml editor.
/// </summary>
public class XmlEditorOptionsPanel : XmlFormsOptionPanel
{
static readonly string showAttributesWhenFoldedCheckBoxName = "showAttributesWhenFoldedCheckBox";
static readonly string showSchemaAnnotationCheckBoxName = "showSchemaAnnotationCheckBox";
public XmlEditorOptionsPanel()
{
}
/// <summary>
/// Initialises the panel.
/// </summary>
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;
}
/// <summary>
/// Saves any changes.
/// </summary>
public override bool StorePanelContents()
{
XmlEditorAddInOptions.ShowAttributesWhenFolded = ((CheckBox)ControlDictionary[showAttributesWhenFoldedCheckBoxName]).Checked;
XmlEditorAddInOptions.ShowSchemaAnnotation = ((CheckBox)ControlDictionary[showSchemaAnnotationCheckBoxName]).Checked;
return true;
}
}
}

112
src/AddIns/BackendBindings/XmlBinding/Src/Src/XmlSchemaCompletionData.cs

@ -152,7 +152,7 @@ namespace ICSharpCode.XmlEditor @@ -152,7 +152,7 @@ namespace ICSharpCode.XmlEditor
/// </summary>
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 @@ -175,7 +175,7 @@ namespace ICSharpCode.XmlEditor
/// </summary>
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 @@ -195,7 +195,7 @@ namespace ICSharpCode.XmlEditor
/// </summary>
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 @@ -213,7 +213,7 @@ namespace ICSharpCode.XmlEditor
/// </summary>
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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -607,7 +607,7 @@ namespace ICSharpCode.XmlEditor
/// Adds an element completion data to the collection if it does not
/// already exist.
/// </summary>
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 @@ -622,7 +622,7 @@ namespace ICSharpCode.XmlEditor
/// Adds an element completion data to the collection if it does not
/// already exist.
/// </summary>
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 @@ -633,7 +633,7 @@ namespace ICSharpCode.XmlEditor
/// <summary>
/// Adds elements to the collection if it does not already exist.
/// </summary>
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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -811,7 +811,7 @@ namespace ICSharpCode.XmlEditor
/// <remarks>
/// Note the special handling of xml:lang attributes.
/// </remarks>
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 @@ -830,9 +830,9 @@ namespace ICSharpCode.XmlEditor
/// <summary>
/// Gets attribute completion data from a group ref.
/// </summary>
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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -1169,9 +1169,9 @@ namespace ICSharpCode.XmlEditor
/// <summary>
/// Gets the set of attribute values for an xs:boolean type.
/// </summary>
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 @@ -1273,7 +1273,7 @@ namespace ICSharpCode.XmlEditor
/// <summary>
/// Adds an attribute value to the completion data collection.
/// </summary>
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 @@ -1282,7 +1282,7 @@ namespace ICSharpCode.XmlEditor
/// <summary>
/// Adds an attribute value to the completion data collection.
/// </summary>
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 @@ -1292,7 +1292,7 @@ namespace ICSharpCode.XmlEditor
/// <summary>
/// Adds an attribute value to the completion data collection.
/// </summary>
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 @@ -1318,7 +1318,7 @@ namespace ICSharpCode.XmlEditor
/// <summary>
/// Adds any elements that have the specified substitution group.
/// </summary>
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) {

2
src/AddIns/BackendBindings/XmlBinding/Src/Src/XmlSchemaListBoxItem.cs

@ -6,6 +6,8 @@ @@ -6,6 +6,8 @@
// </file>
using System;
using System.Windows.Controls;
using System.Windows.Media;
namespace ICSharpCode.XmlEditor
{

412
src/AddIns/BackendBindings/XmlBinding/Src/Src/XmlSchemasPanel.cs

@ -1,412 +0,0 @@ @@ -1,412 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision: 3568 $</version>
// </file>
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
{
/*
/// <summary>
/// Shows the xml schemas that SharpDevelop knows about.
/// </summary>
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);
/// <summary>
/// Initialises the panel.
/// </summary>
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);
}
/// <summary>
/// Saves any changes to the configured schemas.
/// </summary>
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;
}
}
/// <summary>
/// Enables the remove button if a list box item is selected.
/// </summary>
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;
}
}
/// <summary>
/// Adds the schema namespaces to the list.
/// </summary>
void PopulateSchemaListBox()
{
foreach (XmlSchemaCompletionData schema in XmlSchemaManager.SchemaCompletionDataItems) {
XmlSchemaListBoxItem item = new XmlSchemaListBoxItem(schema.NamespaceUri, schema.ReadOnly);
schemaListBox.Items.Add(item);
}
}
/// <summary>
/// Saves any changes to the configured schemas.
/// </summary>
/// <returns></returns>
bool SaveSchemaChanges()
{
RemoveUserSchemas();
AddUserSchemas();
return true;
}
/// <summary>
/// Allows the user to browse the file system for a schema.
/// </summary>
/// <returns>The schema file name the user selected; otherwise an
/// empty string.</returns>
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;
}
/// <summary>
/// Loads the specified schema and adds it to an internal collection.
/// </summary>
/// <remarks>The schema file is not copied to the user's schema folder
/// until they click the OK button.</remarks>
/// <returns><see langword="true"/> if the schema namespace
/// does not already exist; otherwise <see langword="false"/>
/// </returns>
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;
}
/// <summary>
/// Checks that the schema namespace does not already exist.
/// </summary>
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;
}
/// <summary>
/// Schedules the schema for removal.
/// </summary>
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;
}
}
}
/// <summary>
/// Removes the schemas from the schema manager.
/// </summary>
void RemoveUserSchemas()
{
while (removedSchemaNamespaces.Count > 0) {
XmlSchemaManager.RemoveUserSchema(removedSchemaNamespaces[0]);
removedSchemaNamespaces.RemoveAt(0);
}
}
/// <summary>
/// Adds the schemas to the schema manager.
/// </summary>
void AddUserSchemas()
{
while (addedSchemas.Count > 0) {
XmlSchemaManager.AddUserSchema(addedSchemas[0]);
addedSchemas.RemoveAt(0);
}
}
/// <summary>
/// Draws the list box items so we can show the read only schemas in
/// a different colour.
/// </summary>
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);
}
/// <summary>
/// Shows the namespace associated with the selected xml file extension.
/// </summary>
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;
}
}
/// <summary>
/// Allows the user to change the schema associated with an xml file
/// extension.
/// </summary>
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;
}
}
}
/// <summary>
/// Reads the configured xml file extensions and their associated namespaces.
/// </summary>
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());
}
}
/// <summary>
/// Updates the configured file extension to namespace mappings.
/// </summary>
void UpdateSchemaAssociations()
{
foreach (XmlSchemaAssociationListBoxItem item in fileExtensionComboBox.Items) {
if (item.IsDirty) {
XmlSchemaAssociation association = new XmlSchemaAssociation(item.Extension, item.NamespaceUri, item.NamespacePrefix);
XmlEditorAddInOptions.SetSchemaAssociation(association);
}
}
}
/// <summary>
/// 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.
/// </summary>
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;
}
/// <summary>
/// User has changed the namespace prefix.
/// </summary>
void NamespacePrefixTextBoxTextChanged(object source, EventArgs e)
{
if (!ignoreNamespacePrefixTextChanges) {
XmlSchemaAssociationListBoxItem item = fileExtensionComboBox.SelectedItem as XmlSchemaAssociationListBoxItem;
if (item != null) {
item.NamespacePrefix = namespacePrefixTextBox.Text;
item.IsDirty = true;
}
}
}
}
* */
}

11
src/AddIns/BackendBindings/XmlBinding/XmlBinding.csproj

@ -85,8 +85,8 @@ @@ -85,8 +85,8 @@
</Compile>
<Compile Include="Src\XmlFormattingStrategy.cs">
</Compile>
<Compile Include="Src\CodeCompletion\XmlCompletionData.cs" />
<Compile Include="Src\CodeCompletion\XmlCompletionDataCollection.cs" />
<Compile Include="Src\CodeCompletion\XmlCompletionItem.cs" />
<Compile Include="Src\CodeCompletion\XmlCompletionItemCollection.cs" />
<Compile Include="Src\CodeCompletion\XmlCompletionDataImageList.cs" />
<Compile Include="Src\CodeCompletion\XmlCompletionDataProvider.cs" />
<Compile Include="Src\Commands\AddAttributeCommand.cs" />
@ -115,8 +115,6 @@ @@ -115,8 +115,6 @@
<Compile Include="Src\Gui\GoToSchemaDefinitionEditAction.cs" />
<Compile Include="Src\Gui\IAddXmlNodeDialog.cs" />
<Compile Include="Src\Gui\IXmlTreeView.cs" />
<Compile Include="Src\Gui\SelectXmlSchemaForm.cs">
</Compile>
<Compile Include="Src\Gui\XmlDisplayBinding.cs" />
<Compile Include="Src\Gui\XmlTreeView.cs" />
<Compile Include="Src\Gui\XPathQueryControl.cs">
@ -135,8 +133,6 @@ @@ -135,8 +133,6 @@
<Compile Include="Src\Src\XmlCharacterDataTreeNode.cs" />
<Compile Include="Src\Src\XmlCommentTreeNode.cs" />
<Compile Include="Src\Src\XmlEditorAddInOptions.cs" />
<Compile Include="Src\Src\XmlEditorOptionsPanel.cs">
</Compile>
<Compile Include="Src\Src\XmlElementTreeNode.cs" />
<Compile Include="Src\Src\XmlSchemaAssociation.cs" />
<Compile Include="Src\Src\XmlSchemaAssociationListBoxItem.cs" />
@ -144,9 +140,6 @@ @@ -144,9 +140,6 @@
<Compile Include="Src\Src\XmlSchemaCompletionDataCollection.cs" />
<Compile Include="Src\Src\XmlSchemaListBoxItem.cs" />
<Compile Include="Src\Src\XmlSchemaManager.cs" />
<Compile Include="Src\Src\XmlSchemasPanel.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Src\Src\XmlTextTreeNode.cs" />
<Compile Include="Src\Src\XmlTreeEditor.cs">
</Compile>

46
src/Main/Base/Project/Src/Gui/Dialogs/AbstractOptionPanel.cs

@ -1,20 +1,58 @@ @@ -1,20 +1,58 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
// <owner name="Siegfried Pammer" email="sie_pam@gmx.at"/>
// <version>$Revision$</version>
// </file>
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<OptionBinding> bindings;
public IList<OptionBinding> 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<OptionBinding>();
}
public void AddBinding(OptionBinding binding)
{
this.bindings.Add(binding);
}
}
}

3
src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj

@ -65,6 +65,7 @@ @@ -65,6 +65,7 @@
</Compile>
<Compile Include="ConditionalSeparator.cs" />
<Compile Include="GetBitmapExtension.cs" />
<Compile Include="IOptionBindingContainer.cs" />
<Compile Include="IStatusUpdate.cs" />
<Compile Include="LocalizeExtension.cs" />
<Compile Include="Menu\IMenuItemBuilder.cs" />
@ -72,10 +73,12 @@ @@ -72,10 +73,12 @@
<Compile Include="Menu\MenuService.cs" />
<Compile Include="Menu\CoreMenuItem.cs" />
<Compile Include="NativeMethods.cs" />
<Compile Include="OptionBinding.cs" />
<Compile Include="PixelSnapper.cs" />
<Compile Include="PresentationResourceService.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SplitButton.cs" />
<Compile Include="StringParseExtension.cs" />
<Compile Include="ToolBar\ToolBarButton.cs" />
<Compile Include="ToolBar\ToolBarComboBox.cs" />
<Compile Include="ToolBar\ToolBarService.cs" />

24
src/Main/ICSharpCode.Core.Presentation/IOptionBindingContainer.cs

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Siegfried Pammer" email="sie_pam@gmx.at" />
// <version>$Revision$</version>
// </file>
using System;
using System.ComponentModel;
using System.Reflection;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;
namespace ICSharpCode.Core.Presentation
{
/// <summary>
/// Provides access to objects containing OptionBindings, such as OptionPanels.
/// </summary>
public interface IOptionBindingContainer
{
void AddBinding(OptionBinding binding);
}
}

25
src/Main/ICSharpCode.Core.Presentation/LocalizeExtension.cs

@ -6,6 +6,10 @@ @@ -6,6 +6,10 @@
// </file>
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 @@ -28,21 +32,8 @@ namespace ICSharpCode.Core.Presentation
}
}
/// <summary>
/// Markup extension that works like StringParser.Parse
/// </summary>
public class StringParseExtension : MarkupExtension
{
protected string text;
public StringParseExtension(string text)
{
this.text = text;
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return StringParser.Parse(text);
}
}
}

111
src/Main/ICSharpCode.Core.Presentation/OptionBinding.cs

@ -0,0 +1,111 @@ @@ -0,0 +1,111 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Siegfried Pammer" email="sie_pam@gmx.at" />
// <version>$Revision$</version>
// </file>
using System;
using System.ComponentModel;
using System.Reflection;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;
namespace ICSharpCode.Core.Presentation
{
/// <summary>
/// Custom binding to allow direct bindings of option properties to WPF controls.
/// </summary>
/// <remarks>
/// Properties accessed by this binding have to be managed by a custom<br />
/// settings class, which contains all settings as static properties or fields.<br />
/// Do not use PropertyService directly!<br />
/// This markup extension can only be used in OptionPanels or other <br />classes implementing IOptionBindingContainer!
/// <br />
/// Example:
/// <code>
/// {sd:OptionBinding addin:XmlEditorAddInOptions.ShowAttributesWhenFolded}
/// </code>
/// <br />
/// Whereas 'sd' is the xml namespace of ICSharpCode.Core.Presentation.OptionBinding and 'addin'<br />
/// is the xml namespace, in which your settings class is defined.
/// </remarks>
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;
}
}
}

34
src/Main/ICSharpCode.Core.Presentation/StringParseExtension.cs

@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Siegfried Pammer" email="sie_pam@gmx.at" />
// <version>$Revision$</version>
// </file>
using System;
using System.ComponentModel;
using System.Reflection;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;
namespace ICSharpCode.Core.Presentation
{
/// <summary>
/// Markup extension that works like StringParser.Parse
/// </summary>
public class StringParseExtension : MarkupExtension
{
protected string text;
public StringParseExtension(string text)
{
this.text = text;
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return StringParser.Parse(text);
}
}
}
Loading…
Cancel
Save