Browse Source

Child tree nodes now added on loading a form in the python forms designer.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4393 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 17 years ago
parent
commit
4b1a54a220
  1. 22
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlFieldExpression.cs
  2. 85
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadTreeViewTestFixture.cs
  3. 18
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonControlFieldExpressionTests.cs
  4. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj
  5. 7
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockComponentCreator.cs

22
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlFieldExpression.cs

@ -192,11 +192,19 @@ namespace ICSharpCode.PythonBinding @@ -192,11 +192,19 @@ namespace ICSharpCode.PythonBinding
{
object obj = componentCreator.GetComponent(variableName);
if (obj == null) {
return null;
obj = componentCreator.GetInstance(variableName);
}
string[] memberNames = fullMemberName.Split('.');
return GetMember(obj, memberNames, 2, memberNames.Length - 1);
if (obj != null) {
string[] memberNames = fullMemberName.Split('.');
int startIndex = 2;
if (!ContainsSelfReference(memberNames)) {
// No self to skip over when searching for member.
startIndex = 1;
}
return GetMember(obj, memberNames, startIndex, memberNames.Length - 1);
}
return null;
}
/// <summary>
@ -281,5 +289,13 @@ namespace ICSharpCode.PythonBinding @@ -281,5 +289,13 @@ namespace ICSharpCode.PythonBinding
{
return name.StartsWith("self.", StringComparison.InvariantCultureIgnoreCase);
}
static bool ContainsSelfReference(string[] members)
{
if (members.Length > 0) {
return "self".Equals(members[0], StringComparison.InvariantCultureIgnoreCase);
}
return false;
}
}
}

85
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadTreeViewTestFixture.cs

@ -0,0 +1,85 @@ @@ -0,0 +1,85 @@
// <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.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using ICSharpCode.PythonBinding;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Designer
{
[TestFixture]
public class LoadTreeViewTestFixture : LoadFormTestFixtureBase
{
public override string PythonCode {
get {
return "class MainForm(System.Windows.Forms.Form):\r\n" +
" def InitializeComponent(self):\r\n" +
" treeNode1 = System.Windows.Forms.TreeNode()\r\n" +
" treeNode2 = System.Windows.Forms.TreeNode()\r\n" +
" treeNode3 = System.Windows.Forms.TreeNode()\r\n" +
" self._treeView1 = System.Windows.Forms.TreeView()\r\n" +
" self.SuspendLayout()\r\n" +
" # \r\n" +
" # treeView1\r\n" +
" # \r\n" +
" treeNode1.Name = \"RootNode0\"\r\n" +
" treeNode1.Text = \"RootNode0.Text\"\r\n" +
" treeNode1.Nodes.AddRange(System.Array[System.Windows.Forms.TreeNode](\r\n" +
" [treeNode2]))\r\n" +
" treeNode2.Name = \"ChildNode0\"\r\n" +
" treeNode2.Text = \"ChildNode0.Text\"\r\n" +
" treeNode2.Nodes.AddRange(System.Array[System.Windows.Forms.TreeNode](\r\n" +
" [treeNode3]))\r\n" +
" treeNode3.Name = \"ChildNode1\"\r\n" +
" treeNode3.Text = \"ChildNode1.Text\"\r\n" +
" self._treeView1.Location = System.Drawing.Point(0, 0)\r\n" +
" self._treeView1.Name = \"treeView1\"\r\n" +
" self._treeView1.Nodes.AddRange(System.Array[System.Windows.Forms.TreeNode](\r\n" +
" [treeNode1]))\r\n" +
" self._treeView1.Size = System.Drawing.Size(100, 100)\r\n" +
" self._treeView1.TabIndex = 0\r\n" +
" # \r\n" +
" # MainForm\r\n" +
" # \r\n" +
" self.ClientSize = System.Drawing.Size(200, 300)\r\n" +
" self.Controls.Add(self._treeView1)\r\n" +
" self.Name = \"MainForm\"\r\n" +
" self.ResumeLayout(False)\r\n" +
" self.PerformLayout()\r\n";
}
}
public TreeView TreeView {
get { return Form.Controls[0] as TreeView; }
}
[Test]
public void OneRootNode()
{
Assert.AreEqual(1, TreeView.Nodes.Count);
}
[Test]
public void RootNodeHasOneChildNode()
{
Assert.AreEqual(1, TreeView.Nodes[0].Nodes.Count);
}
[Test]
public void ChildNodeHasOneChildNode()
{
Assert.AreEqual(1, TreeView.Nodes[0].Nodes[0].Nodes.Count);
}
}
}

18
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonControlFieldExpressionTests.cs

@ -146,6 +146,24 @@ namespace PythonBinding.Tests.Designer @@ -146,6 +146,24 @@ namespace PythonBinding.Tests.Designer
Assert.IsNull(field.GetMember(creator));
}
}
[Test]
public void GetInstanceObjectInMethodCall()
{
string pythonCode = "treeNode1.Nodes.AddRange(System.Array[System.Windows.Forms.TreeNode](\r\n" +
" [treeNode2]))";
CallExpression callExpression = PythonParserHelper.GetCallExpression(pythonCode);
PythonControlFieldExpression field = PythonControlFieldExpression.Create(callExpression);
TreeNode treeNode1 = new TreeNode();
TreeNode treeNode2 = new TreeNode();
MockComponentCreator creator = new MockComponentCreator();
creator.AddInstance(treeNode1, "treeNode1");
creator.AddInstance(treeNode2, "treeNode2");
object member = field.GetMember(creator);
Assert.AreSame(treeNode1.Nodes, member);
}
[Test]
public void GetObjectInMethodCallFromSpecifiedObject()

1
src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

@ -238,6 +238,7 @@ @@ -238,6 +238,7 @@
<Compile Include="Designer\LoadTextBoxTestFixture.cs" />
<Compile Include="Designer\LoadTimerTestFixture.cs" />
<Compile Include="Designer\LoadToolTipTestFixture.cs" />
<Compile Include="Designer\LoadTreeViewTestFixture.cs" />
<Compile Include="Designer\MergeFormTestFixture.cs" />
<Compile Include="Designer\MissingInitializeComponentMethodTestFixture.cs" />
<Compile Include="Designer\NoNewLineAfterInitializeComponentTestFixture.cs" />

7
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockComponentCreator.cs

@ -83,6 +83,13 @@ namespace PythonBinding.Tests.Utils @@ -83,6 +83,13 @@ namespace PythonBinding.Tests.Utils
}
return null;
}
public void AddInstance(object obj, string name)
{
CreatedInstance createdInstance = new CreatedInstance(obj.GetType(), new object[0], name, false);
createdInstance.Object = obj;
createdInstances.Add(createdInstance);
}
public object CreateInstance(Type type, ICollection arguments, string name, bool addToContainer)
{

Loading…
Cancel
Save