Browse Source
- Implemented XML option panels in WPF git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/XmlEditor@4148 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
22 changed files with 886 additions and 1013 deletions
@ -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(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -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; |
||||
} |
||||
} |
||||
} |
||||
@ -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> |
||||
@ -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> |
||||
@ -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); |
||||
} |
||||
} |
||||
} |
||||
@ -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; |
||||
} |
||||
} |
||||
} |
||||
@ -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; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
* */ |
||||
} |
||||
@ -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); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@ -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); |
||||
} |
||||
} |
||||
@ -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; |
||||
} |
||||
} |
||||
} |
||||
@ -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…
Reference in new issue