Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2229 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
43 changed files with 2025 additions and 1221 deletions
@ -0,0 +1,190 @@
@@ -0,0 +1,190 @@
|
||||
<?xml version="1.0"?> |
||||
<Template originator = "Daniel Grunwald"> |
||||
|
||||
<!-- Template Header --> |
||||
<TemplateConfiguration> |
||||
<Name>Custom Tool</Name> |
||||
<Category>C#</Category> |
||||
<Subcategory>SharpDevelop</Subcategory> |
||||
<Icon>C#.Project.ControlLibrary</Icon> |
||||
<Description>A custom tool that implements a code generator transforming a source file into an output file whenever the source is changed inside SharpDevelop</Description> |
||||
</TemplateConfiguration> |
||||
|
||||
<!-- Actions --> |
||||
<Actions> |
||||
<Open filename = "${ProjectName}.addin"/> |
||||
</Actions> |
||||
|
||||
<Project language="C#"> |
||||
<ProjectItems> |
||||
<Reference Include="System" /> |
||||
<Reference Include="System.Data" /> |
||||
<Reference Include="System.Drawing" /> |
||||
<Reference Include="System.Windows.Forms" /> |
||||
<Reference Include="System.Xml" /> |
||||
</ProjectItems> |
||||
|
||||
<PropertyGroup> |
||||
<OutputType>Library</OutputType> |
||||
</PropertyGroup> |
||||
|
||||
<Files> |
||||
<File name="${ProjectName}.addin" CopyToOutputDirectory="Always"><![CDATA[<AddIn name = "${ProjectName}" |
||||
author = "${USER}" |
||||
url = "" |
||||
description = "TODO: Put description here"> |
||||
|
||||
<Runtime> |
||||
<Import assembly = "${ProjectName}.dll"/> |
||||
</Runtime> |
||||
|
||||
<!-- make SharpDevelop look for file templates in your AddIn's directory --> |
||||
<Path name = "/SharpDevelop/BackendBindings/Templates"> |
||||
<Directory id = "${ProjectName}Template" path = "." /> |
||||
</Path> |
||||
|
||||
<Path name = "/SharpDevelop/CustomTools"> |
||||
<!-- |
||||
Register the custom tool. |
||||
id: ID used to identify the custom tool. This ID will be used in project files to reference your generator. |
||||
class: fully qualified name of a class in your assembly that implements ICustomTool |
||||
fileNamePattern: a regular expression. For file names matched by this regex, SharpDevelop will display |
||||
your custom tool in the drop down box of the property grid when a file with that extension |
||||
is selected. |
||||
--> |
||||
<CustomTool id = "${ProjectName}Generator" |
||||
class = "${StandardNamespace}.${ProjectName}Tool" |
||||
fileNamePattern = "\.xml$"/> |
||||
</Path> |
||||
</AddIn> |
||||
]]></File> |
||||
<File name="${ProjectName}Tool.cs"> |
||||
<![CDATA[${StandardHeader.C#} |
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.CodeDom; |
||||
using System.Xml; |
||||
using ICSharpCode.EasyCodeDom; // defined in ICSharpCode.SharpDevelop.Dom.dll |
||||
using ICSharpCode.SharpDevelop.Project; // defined in ICSharpCode.SharpDevelop.dll |
||||
|
||||
namespace ${StandardNamespace} |
||||
{ |
||||
/// <summary> |
||||
/// Description of CustomTool. |
||||
/// </summary> |
||||
public class ${ProjectName}Tool : ICustomTool |
||||
{ |
||||
/// <summary> |
||||
/// Called by SharpDevelop when your tool has to generate code. |
||||
/// </summary> |
||||
/// <param name="item"> |
||||
/// The file for which your tool should generate code. |
||||
/// </param> |
||||
public void GenerateCode(FileProjectItem item, CustomToolContext context) |
||||
{ |
||||
// make SharpDevelop generate a name for the output file |
||||
string outputFileName = context.GetOutputFileName(item, ".Generated"); |
||||
// if item.FileName is "C:\somedir\SomeName.xml" and is inside a C# project, |
||||
// the output name will be "C:\somedir\SomeName.Generated.cs". |
||||
// context.GetOutputFileName will always append the extension for compilable files in |
||||
// the current project type, so if you want to always output xml, you could use |
||||
// string outputFileName = Path.ChangeExtension(item.FileName, ".Generated.xml"); |
||||
|
||||
// now read the input file: |
||||
XmlDocument doc = new XmlDocument(); |
||||
doc.Load(item.FileName); |
||||
|
||||
// and generate the code using System.CodeDom: |
||||
CodeCompileUnit ccu = GenerateCode(doc, context.OutputNamespace, Path.GetFileNameWithoutExtension(item.FileName)); |
||||
|
||||
// Finally save our generated CodeDom compile unit. SharpDevelop will take care of generating |
||||
// the code using the correct CodeDomProvider for the project type. This means code-generating |
||||
// custom tools are completely language-independent |
||||
context.WriteCodeDomToFile(item, outputFileName, ccu); |
||||
// If you don't want to generate code, you'll have to write the output file yourself and then use |
||||
// context.EnsureOutputFileIsInProject to add the generated file to the project if it isn't already |
||||
// part of it. |
||||
} |
||||
|
||||
CodeCompileUnit GenerateCode(XmlDocument doc, string targetNamespace, string className) |
||||
{ |
||||
// This method does the actual code generation. |
||||
|
||||
// This sample accepts an object graph as XmlDocument and outputs a class with a static method |
||||
// constructing that object graph. |
||||
|
||||
// We'll use ICSharpCode.EasyCodeDom for code generation. This is a small wrapper around CodeDom |
||||
// that provides convenience methods that create new objects and add them to the parent simultaniously. |
||||
// This makes the generation code much more concise. |
||||
// EasyCodeDom classes derive from the System.CodeDom types or have an implicit conversion operator, so |
||||
// use can use EasyCodeDom objects whereever CodeDom is expected. |
||||
EasyCompileUnit ccu = new EasyCompileUnit(); |
||||
EasyTypeDeclaration generatedClass = ccu.AddNamespace(targetNamespace).AddType(className); |
||||
EasyMethod m = generatedClass.AddMethod("Create"); |
||||
m.ReturnType = Easy.TypeRef(doc.DocumentElement.Name); |
||||
m.Attributes = MemberAttributes.Static | MemberAttributes.Public; |
||||
|
||||
// now generate code. helper variables will be named "v#" |
||||
int helperVariableCounter = 0; |
||||
string rootVariableName = GenerateCodeForObject(m.Body, doc.DocumentElement, ref helperVariableCounter); |
||||
|
||||
// generate "return v0;" |
||||
m.Body.Return(Easy.Var(rootVariableName)); |
||||
|
||||
return ccu; |
||||
} |
||||
|
||||
string GenerateCodeForObject(EasyBlock block, XmlElement objectElement, ref int helperVariableCounter) |
||||
{ |
||||
// generate code to create the object represented by "objectElement" and add it to the block |
||||
|
||||
// generate "VarType v#;" |
||||
CodeVariableDeclarationStatement varDecl; |
||||
varDecl = block.DeclareVariable(Easy.TypeRef(objectElement.Name), "v" + helperVariableCounter); |
||||
helperVariableCounter += 1; |
||||
|
||||
// generate "VarType v# = new VarType();" |
||||
varDecl.InitExpression = Easy.New(Easy.TypeRef(objectElement.Name)); |
||||
|
||||
// translate XML attribute to assignments to properties |
||||
foreach (XmlAttribute attribute in objectElement.Attributes) { |
||||
// generate 'v#.attributeName = "attributeValue";' |
||||
// attribute.Value is a string, thus Easy.Prim creates a string literal. |
||||
// This simple code generator does not support using other types for attributes. |
||||
block.Assign(Easy.Var(varDecl.Name).Property(attribute.Name), |
||||
Easy.Prim(attribute.Value)); |
||||
} |
||||
|
||||
foreach (XmlNode collectionNode in objectElement.ChildNodes) { |
||||
XmlElement collectionElement = collectionNode as XmlElement; |
||||
if (collectionElement != null) { |
||||
foreach (XmlNode itemNode in collectionElement.ChildNodes) { |
||||
XmlElement itemElement = itemNode as XmlElement; |
||||
if (itemElement != null) { |
||||
// add the object represented by "itemElement" to the collection represented by |
||||
// "collectionElement". |
||||
|
||||
// generate code to create child object |
||||
string childVariableName = GenerateCodeForObject(block, itemElement, ref helperVariableCounter); |
||||
|
||||
// generate 'v#.collectionName.Add(v##)' |
||||
block.InvokeMethod(Easy.Var(varDecl.Name).Property(collectionElement.Name), |
||||
"Add", |
||||
Easy.Var(childVariableName)); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
return varDecl.Name; |
||||
} |
||||
} |
||||
} |
||||
|
||||
]]></File> |
||||
<File name="FileTemplate.xft" src="SharpDevelopCustomToolTemplate.xft.xml" binary="true" CopyToOutputDirectory="Always"/> |
||||
<File name="AssemblyInfo.cs" src="DefaultAssemblyInfo.cs"/> |
||||
</Files> |
||||
</Project> |
||||
</Template> |
||||
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0"?> |
||||
<Template author="-" version="1.0"> |
||||
<Config |
||||
name = "CustomTool Template" |
||||
icon = "Icons.32x32.XMLFileIcon" |
||||
category = "${res:Templates.File.Categories.Misc}" |
||||
defaultname = "CustomToolTemplate${Number}.xml" |
||||
language = "XML"/> |
||||
|
||||
<Description>A file template for ${ProjectName}</Description> |
||||
|
||||
<Files> |
||||
<File name="${FullName}" language="XML"><![CDATA[<?xml version="1.0"?> |
||||
<Form Text = "Form title"> |
||||
<Controls> |
||||
<Button Text = "Click me"/> |
||||
<Panel> |
||||
<Controls> |
||||
<Label Text = "A Label"/> |
||||
<Button Text = "Another button"/> |
||||
</Controls> |
||||
</Panel> |
||||
</Controls> |
||||
</Form>]]> |
||||
</File> |
||||
</Files> |
||||
</Template> |
||||
@ -1,60 +0,0 @@
@@ -1,60 +0,0 @@
|
||||
<Components version="1.0"> |
||||
<System.Windows.Forms.Form> |
||||
<Name value="AddAttributeDialog" /> |
||||
<MinimizeBox value="False" /> |
||||
<StartPosition value="CenterParent" /> |
||||
<MinimumSize value="191, 155" /> |
||||
<ShowInTaskbar value="False" /> |
||||
<Text value="${res:ICSharpCode.XmlEditor.AddAttributeDialog.Title}" /> |
||||
<MaximizeBox value="False" /> |
||||
<ClientSize value="{Width=289, Height=244}" /> |
||||
<ShowIcon value="False" /> |
||||
<Controls> |
||||
<System.Windows.Forms.Label> |
||||
<Name value="label1" /> |
||||
<Location value="5, 179" /> |
||||
<Text value="${res:ICSharpCode.XmlEditor.AddAttributeDialog.CustomAttributeLabel}" /> |
||||
<Anchor value="Bottom, Left" /> |
||||
<Size value="82, 23" /> |
||||
<TabIndex value="1" /> |
||||
</System.Windows.Forms.Label> |
||||
<System.Windows.Forms.TextBox> |
||||
<Name value="attributeTextBox" /> |
||||
<TabIndex value="2" /> |
||||
<Size value="183, 21" /> |
||||
<Location value="100, 179" /> |
||||
<Anchor value="Bottom, Left, Right" /> |
||||
</System.Windows.Forms.TextBox> |
||||
<System.Windows.Forms.Button> |
||||
<Name value="okButton" /> |
||||
<DialogResult value="OK" /> |
||||
<Location value="121, 209" /> |
||||
<Text value="${res:Global.OKButtonText}" /> |
||||
<Anchor value="Bottom, Right" /> |
||||
<UseVisualStyleBackColor value="True" /> |
||||
<Size value="75, 23" /> |
||||
<TabIndex value="3" /> |
||||
</System.Windows.Forms.Button> |
||||
<System.Windows.Forms.Button> |
||||
<Name value="cancelButton" /> |
||||
<DialogResult value="Cancel" /> |
||||
<Location value="202, 209" /> |
||||
<Text value="${res:Global.CancelButtonText}" /> |
||||
<Anchor value="Bottom, Right" /> |
||||
<UseVisualStyleBackColor value="True" /> |
||||
<Size value="75, 23" /> |
||||
<TabIndex value="4" /> |
||||
</System.Windows.Forms.Button> |
||||
<System.Windows.Forms.ListBox> |
||||
<Name value="attributesListBox" /> |
||||
<Size value="289, 173" /> |
||||
<TabIndex value="0" /> |
||||
<Sorted value="True" /> |
||||
<SelectionMode value="MultiExtended" /> |
||||
<FormattingEnabled value="True" /> |
||||
<Location value="0, 0" /> |
||||
<Anchor value="Top, Bottom, Left, Right" /> |
||||
</System.Windows.Forms.ListBox> |
||||
</Controls> |
||||
</System.Windows.Forms.Form> |
||||
</Components> |
||||
@ -1,60 +0,0 @@
@@ -1,60 +0,0 @@
|
||||
<Components version="1.0"> |
||||
<System.Windows.Forms.Form> |
||||
<Name value="AddElementDialog" /> |
||||
<MinimizeBox value="False" /> |
||||
<StartPosition value="CenterParent" /> |
||||
<MinimumSize value="191, 155" /> |
||||
<ShowInTaskbar value="False" /> |
||||
<Text value="${res:ICSharpCode.XmlEditor.AddElementDialog.Title}" /> |
||||
<MaximizeBox value="False" /> |
||||
<ClientSize value="{Width=289, Height=244}" /> |
||||
<ShowIcon value="False" /> |
||||
<Controls> |
||||
<System.Windows.Forms.Label> |
||||
<Name value="customElementLabel" /> |
||||
<Location value="5, 179" /> |
||||
<Text value="${res:ICSharpCode.XmlEditor.AddElementDialog.CustomElementLabel}" /> |
||||
<Anchor value="Bottom, Left" /> |
||||
<Size value="82, 23" /> |
||||
<TabIndex value="1" /> |
||||
</System.Windows.Forms.Label> |
||||
<System.Windows.Forms.TextBox> |
||||
<Name value="elementTextBox" /> |
||||
<TabIndex value="2" /> |
||||
<Size value="183, 21" /> |
||||
<Location value="100, 179" /> |
||||
<Anchor value="Bottom, Left, Right" /> |
||||
</System.Windows.Forms.TextBox> |
||||
<System.Windows.Forms.Button> |
||||
<Name value="okButton" /> |
||||
<DialogResult value="OK" /> |
||||
<Location value="121, 209" /> |
||||
<Text value="${res:Global.OKButtonText}" /> |
||||
<Anchor value="Bottom, Right" /> |
||||
<UseVisualStyleBackColor value="True" /> |
||||
<Size value="75, 23" /> |
||||
<TabIndex value="3" /> |
||||
</System.Windows.Forms.Button> |
||||
<System.Windows.Forms.Button> |
||||
<Name value="cancelButton" /> |
||||
<DialogResult value="Cancel" /> |
||||
<Location value="202, 209" /> |
||||
<Text value="${res:Global.CancelButtonText}" /> |
||||
<Anchor value="Bottom, Right" /> |
||||
<UseVisualStyleBackColor value="True" /> |
||||
<Size value="75, 23" /> |
||||
<TabIndex value="4" /> |
||||
</System.Windows.Forms.Button> |
||||
<System.Windows.Forms.ListBox> |
||||
<Name value="elementsListBox" /> |
||||
<Size value="289, 173" /> |
||||
<TabIndex value="0" /> |
||||
<Sorted value="True" /> |
||||
<SelectionMode value="MultiExtended" /> |
||||
<FormattingEnabled value="True" /> |
||||
<Location value="0, 0" /> |
||||
<Anchor value="Top, Bottom, Left, Right" /> |
||||
</System.Windows.Forms.ListBox> |
||||
</Controls> |
||||
</System.Windows.Forms.Form> |
||||
</Components> |
||||
@ -1,88 +0,0 @@
@@ -1,88 +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$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Windows.Forms; |
||||
|
||||
using ICSharpCode.SharpDevelop.Gui.XmlForms; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
public class AddAttributeDialog : BaseSharpDevelopForm, IAddAttributeDialog |
||||
{ |
||||
ListBox attributesListBox; |
||||
Button okButton; |
||||
TextBox attributeTextBox; |
||||
|
||||
public AddAttributeDialog(string[] attributeNames) |
||||
{ |
||||
SetupFromXmlStream(GetType().Assembly.GetManifestResourceStream("ICSharpCode.XmlEditor.Resources.AddAttributeDialog.xfrm")); |
||||
|
||||
okButton = (Button)ControlDictionary["okButton"]; |
||||
okButton.Enabled = false; |
||||
AcceptButton = okButton; |
||||
CancelButton = (Button)ControlDictionary["cancelButton"]; |
||||
|
||||
attributeTextBox = (TextBox)ControlDictionary["attributeTextBox"]; |
||||
attributeTextBox.TextChanged += AttributeTextBoxTextChanged; |
||||
|
||||
attributesListBox = (ListBox)ControlDictionary["attributesListBox"]; |
||||
attributesListBox.SelectedIndexChanged += AttributesListBoxSelectedIndexChanged; |
||||
foreach (string name in attributeNames) { |
||||
attributesListBox.Items.Add(name); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the attribute names selected.
|
||||
/// </summary>
|
||||
public string[] AttributeNames { |
||||
get { |
||||
List<string> attributeNames = new List<string>(); |
||||
if (IsAttributeSelected) { |
||||
foreach (string attributeName in attributesListBox.SelectedItems) { |
||||
attributeNames.Add(attributeName); |
||||
} |
||||
} |
||||
string customAttributeName = attributeTextBox.Text.Trim(); |
||||
if (customAttributeName.Length > 0) { |
||||
attributeNames.Add(customAttributeName); |
||||
} |
||||
return attributeNames.ToArray(); |
||||
} |
||||
} |
||||
|
||||
void AttributesListBoxSelectedIndexChanged(object source, EventArgs e) |
||||
{ |
||||
okButton.Enabled = IsOkButtonEnabled; |
||||
} |
||||
|
||||
void AttributeTextBoxTextChanged(object source, EventArgs e) |
||||
{ |
||||
okButton.Enabled = IsOkButtonEnabled; |
||||
} |
||||
|
||||
bool IsAttributeSelected { |
||||
get { |
||||
return attributesListBox.SelectedIndex >= 0; |
||||
} |
||||
} |
||||
|
||||
bool IsOkButtonEnabled { |
||||
get { |
||||
return IsAttributeSelected || IsAttributeNameEntered; |
||||
} |
||||
} |
||||
|
||||
bool IsAttributeNameEntered { |
||||
get { |
||||
return attributeTextBox.Text.Trim().Length > 0; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -1,88 +0,0 @@
@@ -1,88 +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$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Windows.Forms; |
||||
|
||||
using ICSharpCode.SharpDevelop.Gui.XmlForms; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
public class AddElementDialog : BaseSharpDevelopForm, IAddElementDialog |
||||
{ |
||||
ListBox elementsListBox; |
||||
Button okButton; |
||||
TextBox elementTextBox; |
||||
|
||||
public AddElementDialog(string[] elementNames) |
||||
{ |
||||
SetupFromXmlStream(GetType().Assembly.GetManifestResourceStream("ICSharpCode.XmlEditor.Resources.AddElementDialog.xfrm")); |
||||
|
||||
okButton = (Button)ControlDictionary["okButton"]; |
||||
okButton.Enabled = false; |
||||
AcceptButton = okButton; |
||||
CancelButton = (Button)ControlDictionary["cancelButton"]; |
||||
|
||||
elementTextBox = (TextBox)ControlDictionary["elementTextBox"]; |
||||
elementTextBox.TextChanged += ElementTextBoxTextChanged; |
||||
|
||||
elementsListBox = (ListBox)ControlDictionary["elementsListBox"]; |
||||
elementsListBox.SelectedIndexChanged += ElementsListBoxSelectedIndexChanged; |
||||
foreach (string name in elementNames) { |
||||
elementsListBox.Items.Add(name); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the element names selected.
|
||||
/// </summary>
|
||||
public string[] ElementNames { |
||||
get { |
||||
List<string> elementNames = new List<string>(); |
||||
if (IsElementSelected) { |
||||
foreach (string elementName in elementsListBox.SelectedItems) { |
||||
elementNames.Add(elementName); |
||||
} |
||||
} |
||||
string customElementName = elementTextBox.Text.Trim(); |
||||
if (customElementName.Length > 0) { |
||||
elementNames.Add(customElementName); |
||||
} |
||||
return elementNames.ToArray(); |
||||
} |
||||
} |
||||
|
||||
void ElementsListBoxSelectedIndexChanged(object source, EventArgs e) |
||||
{ |
||||
okButton.Enabled = IsOkButtonEnabled; |
||||
} |
||||
|
||||
void ElementTextBoxTextChanged(object source, EventArgs e) |
||||
{ |
||||
okButton.Enabled = IsOkButtonEnabled; |
||||
} |
||||
|
||||
bool IsElementSelected { |
||||
get { |
||||
return elementsListBox.SelectedIndex >= 0; |
||||
} |
||||
} |
||||
|
||||
bool IsOkButtonEnabled { |
||||
get { |
||||
return IsElementSelected || IsElementNameEntered; |
||||
} |
||||
} |
||||
|
||||
bool IsElementNameEntered { |
||||
get { |
||||
return elementTextBox.Text.Trim().Length > 0; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,339 @@
@@ -0,0 +1,339 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Drawing; |
||||
using System.Windows.Forms; |
||||
using System.Xml; |
||||
using ICSharpCode.Core; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Base class for the AddElementDialog and AddAttributeDialog. This
|
||||
/// dialog presents a list of names and an extra text box for entering
|
||||
/// a custom name. It is used to add a new node to the XML tree. It
|
||||
/// contains all the core logic for the AddElementDialog and
|
||||
/// AddAttributeDialog classes.
|
||||
/// </summary>
|
||||
public class AddXmlNodeDialog : System.Windows.Forms.Form, IAddXmlNodeDialog |
||||
{ |
||||
public AddXmlNodeDialog() : this(new string[0]) |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates the dialog and adds the specified names to the
|
||||
/// list box.
|
||||
/// </summary>
|
||||
public AddXmlNodeDialog(string[] names) |
||||
{ |
||||
InitializeComponent(); |
||||
InitStrings(); |
||||
if (names.Length > 0) { |
||||
AddNames(names); |
||||
} else { |
||||
RemoveNamesListBox(); |
||||
} |
||||
RightToLeftConverter.ConvertRecursive(this); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the selected names in the list box together with the
|
||||
/// custom name entered in the text box.
|
||||
/// </summary>
|
||||
public string[] GetNames() |
||||
{ |
||||
// Add items selected in list box.
|
||||
List<string> names = new List<string>(); |
||||
foreach (string name in namesListBox.SelectedItems) { |
||||
names.Add(name); |
||||
} |
||||
|
||||
// Add the custom name if entered.
|
||||
string customName = customNameTextBox.Text.Trim(); |
||||
if (customName.Length > 0) { |
||||
names.Add(customName); |
||||
} |
||||
return names.ToArray(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the text from the error provider.
|
||||
/// </summary>
|
||||
public string GetError() |
||||
{ |
||||
return errorProvider.GetError(customNameTextBox); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the custom name label's text.
|
||||
/// </summary>
|
||||
public string CustomNameLabelText { |
||||
get { |
||||
return customNameTextBoxLabel.Text; |
||||
} |
||||
set { |
||||
customNameTextBoxLabel.Text = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Disposes resources used by the form.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing) |
||||
{ |
||||
if (disposing) { |
||||
if (components != null) { |
||||
components.Dispose(); |
||||
} |
||||
} |
||||
base.Dispose(disposing); |
||||
} |
||||
|
||||
protected void NamesListBoxSelectedIndexChanged(object sender, EventArgs e) |
||||
{ |
||||
UpdateOkButtonState(); |
||||
} |
||||
|
||||
protected void CustomNameTextBoxTextChanged(object sender, EventArgs e) |
||||
{ |
||||
UpdateOkButtonState(); |
||||
} |
||||
|
||||
#region Windows Forms Designer generated code
|
||||
|
||||
void InitializeComponent() |
||||
{ |
||||
this.components = new System.ComponentModel.Container(); |
||||
this.namesListBox = new System.Windows.Forms.ListBox(); |
||||
this.errorProvider = new System.Windows.Forms.ErrorProvider(this.components); |
||||
this.bottomPanel = new System.Windows.Forms.Panel(); |
||||
this.customNameTextBoxLabel = new System.Windows.Forms.Label(); |
||||
this.customNameTextBox = new System.Windows.Forms.TextBox(); |
||||
this.cancelButton = new System.Windows.Forms.Button(); |
||||
this.okButton = new System.Windows.Forms.Button(); |
||||
((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); |
||||
this.bottomPanel.SuspendLayout(); |
||||
this.SuspendLayout(); |
||||
//
|
||||
// namesListBox
|
||||
//
|
||||
this.namesListBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) |
||||
| System.Windows.Forms.AnchorStyles.Left) |
||||
| System.Windows.Forms.AnchorStyles.Right))); |
||||
this.namesListBox.FormattingEnabled = true; |
||||
this.namesListBox.Location = new System.Drawing.Point(0, 0); |
||||
this.namesListBox.Name = "namesListBox"; |
||||
this.namesListBox.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended; |
||||
this.namesListBox.Size = new System.Drawing.Size(289, 173); |
||||
this.namesListBox.Sorted = true; |
||||
this.namesListBox.TabIndex = 1; |
||||
this.namesListBox.SelectedIndexChanged += new System.EventHandler(this.NamesListBoxSelectedIndexChanged); |
||||
//
|
||||
// errorProvider
|
||||
//
|
||||
this.errorProvider.ContainerControl = this; |
||||
//
|
||||
// bottomPanel
|
||||
//
|
||||
this.bottomPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) |
||||
| System.Windows.Forms.AnchorStyles.Right))); |
||||
this.bottomPanel.Controls.Add(this.customNameTextBoxLabel); |
||||
this.bottomPanel.Controls.Add(this.customNameTextBox); |
||||
this.bottomPanel.Controls.Add(this.cancelButton); |
||||
this.bottomPanel.Controls.Add(this.okButton); |
||||
this.bottomPanel.Location = new System.Drawing.Point(0, 173); |
||||
this.bottomPanel.Name = "bottomPanel"; |
||||
this.bottomPanel.Size = new System.Drawing.Size(289, 73); |
||||
this.bottomPanel.TabIndex = 2; |
||||
//
|
||||
// customNameTextBoxLabel
|
||||
//
|
||||
this.customNameTextBoxLabel.Location = new System.Drawing.Point(3, 10); |
||||
this.customNameTextBoxLabel.Name = "customNameTextBoxLabel"; |
||||
this.customNameTextBoxLabel.Size = new System.Drawing.Size(82, 23); |
||||
this.customNameTextBoxLabel.TabIndex = 3; |
||||
this.customNameTextBoxLabel.Text = "Custom:"; |
||||
//
|
||||
// customNameTextBox
|
||||
//
|
||||
this.customNameTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) |
||||
| System.Windows.Forms.AnchorStyles.Right))); |
||||
this.customNameTextBox.Location = new System.Drawing.Point(107, 10); |
||||
this.customNameTextBox.Name = "customNameTextBox"; |
||||
this.customNameTextBox.Size = new System.Drawing.Size(167, 20); |
||||
this.customNameTextBox.TabIndex = 4; |
||||
this.customNameTextBox.TextChanged += new System.EventHandler(this.CustomNameTextBoxTextChanged); |
||||
//
|
||||
// cancelButton
|
||||
//
|
||||
this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); |
||||
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; |
||||
this.cancelButton.Location = new System.Drawing.Point(199, 40); |
||||
this.cancelButton.Name = "cancelButton"; |
||||
this.cancelButton.Size = new System.Drawing.Size(75, 23); |
||||
this.cancelButton.TabIndex = 6; |
||||
this.cancelButton.Text = "Cancel"; |
||||
this.cancelButton.UseVisualStyleBackColor = true; |
||||
//
|
||||
// okButton
|
||||
//
|
||||
this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); |
||||
this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK; |
||||
this.okButton.Enabled = false; |
||||
this.okButton.Location = new System.Drawing.Point(118, 40); |
||||
this.okButton.Name = "okButton"; |
||||
this.okButton.Size = new System.Drawing.Size(75, 23); |
||||
this.okButton.TabIndex = 5; |
||||
this.okButton.Text = "OK"; |
||||
this.okButton.UseVisualStyleBackColor = true; |
||||
//
|
||||
// AddXmlNodeDialog
|
||||
//
|
||||
this.AcceptButton = this.okButton; |
||||
this.CancelButton = this.cancelButton; |
||||
this.ClientSize = new System.Drawing.Size(289, 244); |
||||
this.Controls.Add(this.bottomPanel); |
||||
this.Controls.Add(this.namesListBox); |
||||
this.MaximizeBox = false; |
||||
this.MinimizeBox = false; |
||||
this.MinimumSize = new System.Drawing.Size(289, 143); |
||||
this.Name = "AddXmlNodeDialog"; |
||||
this.ShowIcon = false; |
||||
this.ShowInTaskbar = false; |
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; |
||||
((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit(); |
||||
this.bottomPanel.ResumeLayout(false); |
||||
this.bottomPanel.PerformLayout(); |
||||
this.ResumeLayout(false); |
||||
} |
||||
private System.Windows.Forms.Panel bottomPanel; |
||||
private System.ComponentModel.IContainer components; |
||||
private System.Windows.Forms.ErrorProvider errorProvider; |
||||
private System.Windows.Forms.Button cancelButton; |
||||
private System.Windows.Forms.Button okButton; |
||||
private System.Windows.Forms.TextBox customNameTextBox; |
||||
private System.Windows.Forms.Label customNameTextBoxLabel; |
||||
private System.Windows.Forms.ListBox namesListBox; |
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Adds the names to the list box.
|
||||
/// </summary>
|
||||
void AddNames(string[] names) |
||||
{ |
||||
foreach (string name in names) { |
||||
namesListBox.Items.Add(name); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Enables or disables the ok button depending on whether any list
|
||||
/// item is selected or a custom name has been entered.
|
||||
/// </summary>
|
||||
void UpdateOkButtonState() |
||||
{ |
||||
okButton.Enabled = IsOkButtonEnabled; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns whether any items are selected in the list box.
|
||||
/// </summary>
|
||||
bool IsItemSelected { |
||||
get { |
||||
return namesListBox.SelectedIndex >= 0; |
||||
} |
||||
} |
||||
|
||||
bool IsOkButtonEnabled { |
||||
get { |
||||
return IsItemSelected || ValidateCustomName(); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns whether there is a valid string in the custom
|
||||
/// name text box. The string must be a name that can be used to
|
||||
/// create an xml element or attribute.
|
||||
/// </summary>
|
||||
bool ValidateCustomName() |
||||
{ |
||||
string name = customNameTextBox.Text.Trim(); |
||||
if (name.Length > 0) { |
||||
try { |
||||
VerifyName(name); |
||||
errorProvider.Clear(); |
||||
return true; |
||||
} catch (XmlException ex) { |
||||
errorProvider.SetError(customNameTextBox, ex.Message); |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Checks that the name would make a valid element name or
|
||||
/// attribute name. Trying to use XmlConvert and its Verify methods
|
||||
/// so the validation is not done ourselves. XmlDocument has a
|
||||
/// CheckName method but this is not public.
|
||||
/// </summary>
|
||||
void VerifyName(string name) |
||||
{ |
||||
// Check the qualification is valid.
|
||||
string[] parts = name.Split(new char[] {':'}, 2); |
||||
if (parts.Length == 1) { |
||||
// No colons.
|
||||
XmlConvert.VerifyName(name); |
||||
return; |
||||
} |
||||
|
||||
string firstPart = parts[0].Trim(); |
||||
string secondPart = parts[1].Trim(); |
||||
if (firstPart.Length > 0 && secondPart.Length > 0) { |
||||
XmlConvert.VerifyNCName(firstPart); |
||||
XmlConvert.VerifyNCName(secondPart); |
||||
} else { |
||||
// Throw an error using VerifyNCName since the
|
||||
// qualified name parts have no strings.
|
||||
XmlConvert.VerifyNCName(name); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Sets the control's text using string resources.
|
||||
/// </summary>
|
||||
void InitStrings() |
||||
{ |
||||
okButton.Text = StringParser.Parse("${res:Global.OKButtonText}"); |
||||
cancelButton.Text = StringParser.Parse("${res:Global.CancelButtonText}"); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes the names list box from the dialog, re-positions the
|
||||
/// remaining controls and resizes the dialog to fit.
|
||||
/// </summary>
|
||||
void RemoveNamesListBox() |
||||
{ |
||||
using (namesListBox) { |
||||
Controls.Remove(namesListBox); |
||||
|
||||
// Reset the dialog's minimum size first so setting the
|
||||
// ClientSize to something smaller works as expected.
|
||||
MinimumSize = Size.Empty; |
||||
ClientSize = bottomPanel.Size; |
||||
MinimumSize = Size; |
||||
|
||||
// Make sure bottom panel fills the dialog when it is resized.
|
||||
bottomPanel.Dock = DockStyle.Fill; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -1,30 +0,0 @@
@@ -1,30 +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$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Windows.Forms; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Interface for the AddAttributeDialog.
|
||||
/// </summary>
|
||||
public interface IAddAttributeDialog : IDisposable |
||||
{ |
||||
/// <summary>
|
||||
/// The attribute names that should be added. These are the
|
||||
/// attribute names that the user selected in the dialog when
|
||||
/// it was closed.
|
||||
/// </summary>
|
||||
string[] AttributeNames {get;} |
||||
|
||||
/// <summary>
|
||||
/// Shows the dialog.
|
||||
/// </summary>
|
||||
DialogResult ShowDialog(); |
||||
} |
||||
} |
||||
@ -0,0 +1,325 @@
@@ -0,0 +1,325 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Drawing; |
||||
using System.Threading; |
||||
using System.Windows.Forms; |
||||
using System.Xml; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.Tree |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the AddXmlNodeDialog which is the base class for the
|
||||
/// AddElementDialog and the AddAttributeDialog classes. All the
|
||||
/// core logic for the two add dialogs is located in the AddXmlNodeDialog
|
||||
/// since their behaviour is the same.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class AddNewNodeDialogTestFixture |
||||
{ |
||||
DerivedAddXmlNodeDialog dialog; |
||||
ListBox namesListBox; |
||||
string[] names; |
||||
Button okButton; |
||||
Button cancelButton; |
||||
TextBox customNameTextBox; |
||||
Label customNameTextBoxLabel; |
||||
Panel bottomPanel; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void SetUpFixture() |
||||
{ |
||||
if (!PropertyService.Initialized) { |
||||
PropertyService.InitializeService(String.Empty, String.Empty, String.Empty); |
||||
} |
||||
} |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
names = new string[] {"Chimpanzee", "Monkey"}; |
||||
dialog = new DerivedAddXmlNodeDialog(names); |
||||
|
||||
// Get the various dialog controls that are to be used in this
|
||||
// test fixture.
|
||||
bottomPanel = (Panel)dialog.Controls["bottomPanel"]; |
||||
namesListBox = (ListBox)dialog.Controls["namesListBox"]; |
||||
okButton = (Button)bottomPanel.Controls["okButton"]; |
||||
cancelButton = (Button)bottomPanel.Controls["cancelButton"]; |
||||
customNameTextBox = (TextBox)bottomPanel.Controls["customNameTextBox"]; |
||||
customNameTextBoxLabel = (Label)bottomPanel.Controls["customNameTextBoxLabel"]; |
||||
} |
||||
|
||||
[TearDown] |
||||
public void TearDown() |
||||
{ |
||||
dialog.Dispose(); |
||||
} |
||||
|
||||
[Test] |
||||
public void TwoNamesAddedToListBox() |
||||
{ |
||||
Assert.AreEqual(2, namesListBox.Items.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void NamesAddedToListBox() |
||||
{ |
||||
Assert.Contains("Chimpanzee", namesListBox.Items); |
||||
Assert.Contains("Monkey", namesListBox.Items); |
||||
} |
||||
|
||||
[Test] |
||||
public void OkButtonInitiallyDisabled() |
||||
{ |
||||
Assert.IsFalse(okButton.Enabled); |
||||
} |
||||
|
||||
[Test] |
||||
public void OkButtonIsDialogAcceptButton() |
||||
{ |
||||
Assert.AreSame(okButton, dialog.AcceptButton); |
||||
} |
||||
|
||||
[Test] |
||||
public void CancelButtonIsDialogCancelButton() |
||||
{ |
||||
Assert.AreSame(cancelButton, dialog.CancelButton); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The dialog's Names property should not return any items
|
||||
/// when nothing is selected in the list box or added to the
|
||||
/// custom name text box.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void NoNamesInitiallySelected() |
||||
{ |
||||
Assert.AreEqual(0, dialog.GetNames().Length); |
||||
} |
||||
|
||||
[Test] |
||||
public void NamesSelectedAfterSelectingOneListBoxItem() |
||||
{ |
||||
namesListBox.SelectedIndex = 0; |
||||
string[] expectedNames = new string[] {(string)namesListBox.Items[0]}; |
||||
string[] names = dialog.GetNames(); |
||||
|
||||
Assert.AreEqual(expectedNames, names); |
||||
} |
||||
|
||||
[Test] |
||||
public void NamesSelectedAfterSelectingTwoListBoxItems() |
||||
{ |
||||
namesListBox.SelectedIndices.Add(0); |
||||
namesListBox.SelectedIndices.Add(1); |
||||
string[] expectedNames = new string[] {(string)namesListBox.Items[0], (string)namesListBox.Items[1]}; |
||||
string[] names = dialog.GetNames(); |
||||
|
||||
Assert.AreEqual(expectedNames, names); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that the returned names from the dialog includes any
|
||||
/// text in the custom name text box. Also check that the text box's
|
||||
/// text is trimmed.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void NamesSelectedAfterEnteringCustomName() |
||||
{ |
||||
string customName = " customname "; |
||||
customNameTextBox.Text = customName; |
||||
string[] expectedNames = new string[] {customName.Trim()}; |
||||
string[] names = dialog.GetNames(); |
||||
|
||||
Assert.AreEqual(expectedNames, names); |
||||
} |
||||
|
||||
[Test] |
||||
public void OkButtonEnabledWhenListItemSelected() |
||||
{ |
||||
namesListBox.SelectedIndex = 0; |
||||
dialog.CallNamesListBoxSelectedIndexChanged(); |
||||
|
||||
Assert.IsTrue(okButton.Enabled); |
||||
} |
||||
|
||||
[Test] |
||||
public void OkButtonEnabledWhenCustomNameEntered() |
||||
{ |
||||
customNameTextBox.Text = "Custom"; |
||||
dialog.CallCustomNameTextBoxTextChanged(); |
||||
|
||||
Assert.IsTrue(okButton.Enabled); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that a custom name string that contains spaces does not
|
||||
/// cause the OK button to be enabled.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void OkButtonDisabledWhenEmptyCustomNameStringEntered() |
||||
{ |
||||
customNameTextBox.Text = " "; |
||||
dialog.CallCustomNameTextBoxTextChanged(); |
||||
|
||||
Assert.IsFalse(okButton.Enabled); |
||||
} |
||||
|
||||
[Test] |
||||
public void InvalidCustomNameEntered() |
||||
{ |
||||
customNameTextBox.Text = "<element>"; |
||||
dialog.CallCustomNameTextBoxTextChanged(); |
||||
|
||||
string error = dialog.GetError(); |
||||
string expectedError = null; |
||||
|
||||
try { |
||||
XmlConvert.VerifyName(customNameTextBox.Text); |
||||
Assert.Fail("XmlConvert.VerifyName should have failed."); |
||||
} catch (Exception ex) { |
||||
expectedError = ex.Message; |
||||
} |
||||
Assert.IsFalse(okButton.Enabled); |
||||
Assert.AreEqual(expectedError, error); |
||||
} |
||||
|
||||
[Test] |
||||
public void CustomNameWithTwoColonCharsEntered() |
||||
{ |
||||
customNameTextBox.Text = "xsl:test:this"; |
||||
dialog.CallCustomNameTextBoxTextChanged(); |
||||
|
||||
string error = dialog.GetError(); |
||||
Assert.IsFalse(okButton.Enabled); |
||||
Assert.IsTrue(error.Length > 0); |
||||
} |
||||
|
||||
[Test] |
||||
public void CustomNameWithOneColonCharEntered() |
||||
{ |
||||
customNameTextBox.Text = "xsl:test"; |
||||
dialog.CallCustomNameTextBoxTextChanged(); |
||||
|
||||
string error = dialog.GetError(); |
||||
Assert.IsTrue(okButton.Enabled); |
||||
Assert.AreEqual(0, error.Length); |
||||
} |
||||
|
||||
[Test] |
||||
public void CustomNameWithOneColonCharAtStart() |
||||
{ |
||||
customNameTextBox.Text = ":test"; |
||||
dialog.CallCustomNameTextBoxTextChanged(); |
||||
|
||||
string error = dialog.GetError(); |
||||
Assert.IsFalse(okButton.Enabled); |
||||
Assert.IsTrue(error.Length > 0); |
||||
} |
||||
|
||||
[Test] |
||||
public void ErrorClearedAfterTextChanged() |
||||
{ |
||||
InvalidCustomNameEntered(); |
||||
customNameTextBox.Text = "element"; |
||||
dialog.CallCustomNameTextBoxTextChanged(); |
||||
|
||||
Assert.IsTrue(okButton.Enabled); |
||||
Assert.AreEqual(0, dialog.GetError().Length); |
||||
} |
||||
|
||||
[Test] |
||||
public void StartPositionIsCenterParent() |
||||
{ |
||||
Assert.AreEqual(FormStartPosition.CenterParent, dialog.StartPosition); |
||||
} |
||||
|
||||
[Test] |
||||
public void OkButtonDialogResult() |
||||
{ |
||||
Assert.AreEqual(DialogResult.OK, okButton.DialogResult); |
||||
} |
||||
|
||||
[Test] |
||||
public void CancelButtonDialogResult() |
||||
{ |
||||
Assert.AreEqual(DialogResult.Cancel, cancelButton.DialogResult); |
||||
} |
||||
|
||||
[Test] |
||||
public void ShowInTaskBar() |
||||
{ |
||||
Assert.IsFalse(dialog.ShowInTaskbar); |
||||
} |
||||
|
||||
[Test] |
||||
public void MinimizeBox() |
||||
{ |
||||
Assert.IsFalse(dialog.MinimizeBox); |
||||
} |
||||
|
||||
[Test] |
||||
public void MaximizeBox() |
||||
{ |
||||
Assert.IsFalse(dialog.MaximizeBox); |
||||
} |
||||
|
||||
[Test] |
||||
public void ShowIcon() |
||||
{ |
||||
Assert.IsFalse(dialog.ShowIcon); |
||||
} |
||||
|
||||
[Test] |
||||
public void SetCustomNameLabel() |
||||
{ |
||||
dialog.CustomNameLabelText = "test"; |
||||
Assert.AreEqual("test", dialog.CustomNameLabelText); |
||||
Assert.AreEqual("test", customNameTextBoxLabel.Text); |
||||
} |
||||
|
||||
[Test] |
||||
public void RightToLeftConversion() |
||||
{ |
||||
try { |
||||
PropertyService.Set("CoreProperties.UILanguage", RightToLeftConverter.RightToLeftLanguages[0]); |
||||
using (AddXmlNodeDialog dialog = new AddXmlNodeDialog()) { |
||||
Assert.AreEqual(RightToLeft.Yes, dialog.RightToLeft); |
||||
} |
||||
} finally { |
||||
PropertyService.Set("CoreProperties.UILanguage", Thread.CurrentThread.CurrentUICulture.Name); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Check that the list box is not on the form when there are no
|
||||
/// names passed to the constructor of AddXmlNodeDialog.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void NoListBoxShownWhenNoNames() |
||||
{ |
||||
using (AddXmlNodeDialog dialog = new AddXmlNodeDialog(new string[0])) { |
||||
Size expectedClientSize = this.bottomPanel.Size; |
||||
Size expectedMinSize = dialog.Size; |
||||
|
||||
Panel bottomPanel = (Panel)dialog.Controls["bottomPanel"]; |
||||
|
||||
Assert.IsFalse(dialog.Controls.ContainsKey("namesListBox")); |
||||
Assert.AreEqual(DockStyle.Fill, bottomPanel.Dock); |
||||
Assert.AreEqual(expectedClientSize, dialog.ClientSize); |
||||
Assert.AreEqual(expectedMinSize, dialog.MinimumSize); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.XmlEditor; |
||||
|
||||
namespace XmlEditor.Tests.Utils |
||||
{ |
||||
/// <summary>
|
||||
/// Derived version of the AddXmlNodeDialog which allows us to test
|
||||
/// various protected methods.
|
||||
/// </summary>
|
||||
public class DerivedAddXmlNodeDialog : AddXmlNodeDialog |
||||
{ |
||||
public DerivedAddXmlNodeDialog(string[] names) : base(names) |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Calls the base class's NamesListBoxSelectedIndexChanged method.
|
||||
/// </summary>
|
||||
public void CallNamesListBoxSelectedIndexChanged() |
||||
{ |
||||
base.NamesListBoxSelectedIndexChanged(this, new EventArgs()); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Calls the base class's CustomNameTextBoxTextChanged method.
|
||||
/// </summary>
|
||||
public void CallCustomNameTextBoxTextChanged() |
||||
{ |
||||
base.CustomNameTextBoxTextChanged(this, new EventArgs()); |
||||
} |
||||
} |
||||
} |
||||
@ -1,65 +0,0 @@
@@ -1,65 +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$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Windows.Forms; |
||||
using ICSharpCode.XmlEditor; |
||||
|
||||
namespace XmlEditor.Tests.Utils |
||||
{ |
||||
/// <summary>
|
||||
/// Mocks the AddAttributeDialog so we can test the
|
||||
/// XmlTreeViewContainerControl class when it displays
|
||||
/// the AddAttributeDialog.
|
||||
/// </summary>
|
||||
public class MockAddAttributeDialog : IAddAttributeDialog |
||||
{ |
||||
DialogResult dialogResult = DialogResult.OK; |
||||
List<string> attributeNames = new List<string>(); |
||||
|
||||
/// <summary>
|
||||
/// Specifies the attribute names to return from the
|
||||
/// IAddAttributeDialog.AttributeNames property.
|
||||
/// </summary>
|
||||
public void SetAttributeNamesToReturn(string[] names) |
||||
{ |
||||
attributeNames.Clear(); |
||||
foreach (string name in names) { |
||||
attributeNames.Add(name); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Specifies the dialog result to return from the
|
||||
/// IAddAttributeDialog.ShowDialog method.
|
||||
/// </summary>
|
||||
public void SetDialogResult(DialogResult result) |
||||
{ |
||||
dialogResult = result; |
||||
} |
||||
|
||||
#region IAddAttributeDialog implementation
|
||||
|
||||
public string[] AttributeNames { |
||||
get { |
||||
return attributeNames.ToArray(); |
||||
} |
||||
} |
||||
|
||||
public DialogResult ShowDialog() |
||||
{ |
||||
return dialogResult; |
||||
} |
||||
|
||||
public void Dispose() |
||||
{ |
||||
} |
||||
|
||||
#endregion
|
||||
} |
||||
} |
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Dom.Refactoring |
||||
{ |
||||
public class CodeGeneratorOptions |
||||
{ |
||||
public bool BracesOnSameLine = true; |
||||
public bool EmptyLinesBetweenMembers = true; |
||||
string indentString; |
||||
|
||||
public string IndentString { |
||||
get { return indentString; } |
||||
set { |
||||
if (string.IsNullOrEmpty(value)) { |
||||
throw new ArgumentNullException("value"); |
||||
} |
||||
indentString = value; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue