Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1924 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
24 changed files with 810 additions and 10 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,59 @@
@@ -0,0 +1,59 @@
|
||||
<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}" /> |
||||
<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="Top, 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> |
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
// <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 ICSharpCode.Core; |
||||
using System; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Adds a new attribute to the XML Tree's attribute property grid.
|
||||
/// </summary>
|
||||
public class AddAttributeCommand : AbstractMenuCommand |
||||
{ |
||||
public override void Run() |
||||
{ |
||||
XmlTreeViewContainerControl view = Owner as XmlTreeViewContainerControl; |
||||
if (view != null) { |
||||
view.AddAttribute(); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,87 @@
@@ -0,0 +1,87 @@
|
||||
// <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 ICSharpCode.SharpDevelop.Gui.XmlForms; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Windows.Forms; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
public class AddAttributeDialog : BaseSharpDevelopForm |
||||
{ |
||||
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; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
// <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 ICSharpCode.Core; |
||||
using System; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Removes the selected attribute from the xml document being
|
||||
/// displayed in the XML tree.
|
||||
/// </summary>
|
||||
public class RemoveAttributeCommand : AbstractMenuCommand |
||||
{ |
||||
public override void Run() |
||||
{ |
||||
XmlTreeViewContainerControl view = Owner as XmlTreeViewContainerControl; |
||||
if (view != null) { |
||||
view.RemoveAttribute(); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,147 @@
@@ -0,0 +1,147 @@
|
||||
// <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 ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
using System.Xml; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.Tree |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that an attribute is added to the XML document by the
|
||||
/// XmlTreeEditor.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class AddAttributeTestFixture : XmlTreeViewTestFixtureBase |
||||
{ |
||||
XmlElement bodyElement; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
base.InitFixture(); |
||||
bodyElement = (XmlElement)editor.Document.SelectSingleNode("/html/body"); |
||||
mockXmlTreeView.SelectedElement = bodyElement; |
||||
mockXmlTreeView.SelectedNewAttributesToReturn.Add("id"); |
||||
|
||||
editor.AddAttribute(); |
||||
} |
||||
|
||||
[Test] |
||||
public void ViewAddAttributeCalled() |
||||
{ |
||||
Assert.IsTrue(mockXmlTreeView.IsSelectNewAttributesCalled); |
||||
} |
||||
|
||||
[Test] |
||||
public void IsDirty() |
||||
{ |
||||
Assert.IsTrue(mockXmlTreeView.IsDirty); |
||||
} |
||||
|
||||
[Test] |
||||
public void ShowAttributesCalled() |
||||
{ |
||||
XmlAttribute idAttribute = bodyElement.Attributes["id"]; |
||||
Assert.IsTrue(mockXmlTreeView.AttributesDisplayed.Contains(idAttribute)); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoElementSelected() |
||||
{ |
||||
mockXmlTreeView.SelectedElement = null; |
||||
mockXmlTreeView.IsSelectNewAttributesCalled = false; |
||||
editor.AddAttribute(); |
||||
Assert.IsFalse(mockXmlTreeView.IsSelectNewAttributesCalled); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoAttributeSelected() |
||||
{ |
||||
XmlElement headElement = (XmlElement)editor.Document.SelectSingleNode("/html/head"); |
||||
mockXmlTreeView.SelectedElement = headElement; |
||||
mockXmlTreeView.SelectedNewAttributesToReturn.Clear(); |
||||
|
||||
editor.AddAttribute(); |
||||
|
||||
Assert.IsFalse(headElement.HasAttribute("id")); |
||||
} |
||||
|
||||
[Test] |
||||
public void IdAttributeAdded() |
||||
{ |
||||
Assert.IsTrue(bodyElement.HasAttribute("id")); |
||||
} |
||||
|
||||
[Test] |
||||
public void AttributeListDoesNotContainExistingTitleAttribute() |
||||
{ |
||||
Assert.IsFalse(mockXmlTreeView.SelectNewAttributesList.Contains("title")); |
||||
} |
||||
|
||||
[Test] |
||||
public void AttributeListContainsId() |
||||
{ |
||||
Assert.IsTrue(mockXmlTreeView.SelectNewAttributesList.Contains("id")); |
||||
} |
||||
|
||||
[Test] |
||||
public void AddTwoAttributes() |
||||
{ |
||||
mockXmlTreeView.SelectedNewAttributesToReturn.Add("class"); |
||||
mockXmlTreeView.SelectedNewAttributesToReturn.Add("onclick"); |
||||
editor.AddAttribute(); |
||||
|
||||
XmlAttribute classAttribute = bodyElement.Attributes["class"]; |
||||
XmlAttribute onclickAttribute = bodyElement.Attributes["onclick"]; |
||||
Assert.IsNotNull(classAttribute); |
||||
Assert.IsNotNull(onclickAttribute); |
||||
Assert.IsTrue(mockXmlTreeView.AttributesDisplayed.Contains(classAttribute)); |
||||
Assert.IsTrue(mockXmlTreeView.AttributesDisplayed.Contains(onclickAttribute)); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that when all the attributes have been added the add
|
||||
/// attribute dialog is still displayed.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void AllAttributesAdded() |
||||
{ |
||||
XmlElement htmlElement = (XmlElement)editor.Document.SelectSingleNode("/html"); |
||||
mockXmlTreeView.SelectedElement = htmlElement; |
||||
mockXmlTreeView.SelectedNewAttributesToReturn.Clear(); |
||||
mockXmlTreeView.IsSelectNewAttributesCalled = false; |
||||
|
||||
editor.AddAttribute(); |
||||
Assert.IsTrue(mockXmlTreeView.IsSelectNewAttributesCalled); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the xhtml strict schema as the default schema.
|
||||
/// </summary>
|
||||
protected override XmlSchemaCompletionData DefaultSchemaCompletionData { |
||||
get { |
||||
XmlTextReader reader = ResourceManager.GetXhtmlStrictSchema(); |
||||
return new XmlSchemaCompletionData(reader); |
||||
} |
||||
} |
||||
|
||||
protected override string GetXml() |
||||
{ |
||||
return "<html dir='' id='' lang='' xml:lang=''>\r\n" + |
||||
"\t<head>\r\n" + |
||||
"\t\t<title></title>\r\n" + |
||||
"\t</head>\r\n" + |
||||
"\t<body title='body text'>\r\n" + |
||||
"\t</body>\r\n" + |
||||
"</html>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,56 @@
@@ -0,0 +1,56 @@
|
||||
// <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 ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
using System.Xml; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.Tree |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that no errors occur if there is no matching schema for the
|
||||
/// xml document being edited.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class NoMatchingSchemaTestFixture : XmlTreeViewTestFixtureBase |
||||
{ |
||||
XmlElement bodyElement; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
base.InitFixture(); |
||||
bodyElement = (XmlElement)editor.Document.SelectSingleNode("/html/body"); |
||||
mockXmlTreeView.SelectedElement = bodyElement; |
||||
|
||||
editor.AddAttribute(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Can still add a new attribute even if there is no associated schema.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void ViewAddAttributeCalled() |
||||
{ |
||||
Assert.IsTrue(mockXmlTreeView.IsSelectNewAttributesCalled); |
||||
} |
||||
|
||||
protected override string GetXml() |
||||
{ |
||||
return "<html>\r\n" + |
||||
"\t<head>\r\n" + |
||||
"\t\t<title></title>\r\n" + |
||||
"\t</head>\r\n" + |
||||
"\t<body>\r\n" + |
||||
"\t</body>\r\n" + |
||||
"</html>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,97 @@
@@ -0,0 +1,97 @@
|
||||
// <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 ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
using System.Xml; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.Tree |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that an attribute is removed from the XML document by the
|
||||
/// XmlTreeEditor.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class RemoveAttributeTestFixture : XmlTreeViewTestFixtureBase |
||||
{ |
||||
XmlElement bodyElement; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
base.InitFixture(); |
||||
bodyElement = (XmlElement)editor.Document.SelectSingleNode("/html/body"); |
||||
mockXmlTreeView.SelectedElement = bodyElement; |
||||
mockXmlTreeView.SelectedAttribute = "id"; |
||||
|
||||
editor.RemoveAttribute(); |
||||
} |
||||
|
||||
[Test] |
||||
public void AttributesRedisplayed() |
||||
{ |
||||
Assert.AreEqual(1, mockXmlTreeView.AttributesDisplayed.Count); |
||||
Assert.AreEqual("title", mockXmlTreeView.AttributesDisplayed[0].Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void IdAttributeRemoved() |
||||
{ |
||||
Assert.IsFalse(bodyElement.HasAttribute("id")); |
||||
} |
||||
|
||||
[Test] |
||||
public void IsDirty() |
||||
{ |
||||
Assert.IsTrue(mockXmlTreeView.IsDirty); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoAttributeSelected() |
||||
{ |
||||
mockXmlTreeView.SelectedElement = bodyElement; |
||||
mockXmlTreeView.SelectedAttribute = null; |
||||
mockXmlTreeView.IsDirty = false; |
||||
editor.RemoveAttribute(); |
||||
Assert.IsFalse(mockXmlTreeView.IsDirty); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoElementSelected() |
||||
{ |
||||
mockXmlTreeView.SelectedElement = null; |
||||
mockXmlTreeView.SelectedAttribute = "title"; |
||||
mockXmlTreeView.IsDirty = false; |
||||
editor.RemoveAttribute(); |
||||
Assert.IsFalse(mockXmlTreeView.IsDirty); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the xhtml strict schema as the default schema.
|
||||
/// </summary>
|
||||
protected override XmlSchemaCompletionData DefaultSchemaCompletionData { |
||||
get { |
||||
XmlTextReader reader = ResourceManager.GetXhtmlStrictSchema(); |
||||
return new XmlSchemaCompletionData(reader); |
||||
} |
||||
} |
||||
|
||||
protected override string GetXml() |
||||
{ |
||||
return "<html>\r\n" + |
||||
"\t<head>\r\n" + |
||||
"\t\t<title></title>\r\n" + |
||||
"\t</head>\r\n" + |
||||
"\t<body id='body' title='abc'>\r\n" + |
||||
"\t</body>\r\n" + |
||||
"</html>"; |
||||
} |
||||
} |
||||
} |
Binary file not shown.
Loading…
Reference in new issue