Browse Source

Python forms designer now generates code for the content of nested custom collections.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4642 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 16 years ago
parent
commit
630f20cf9a
  1. 16
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerComponent.cs
  2. 9
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateCustomCollectionItemsTestFixture.cs
  3. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj
  4. 58
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/BarItemCollection.cs
  5. 6
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/CustomUserControl.cs
  6. 12
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/FooItemCollection.cs

16
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerComponent.cs

@ -617,11 +617,7 @@ namespace ICSharpCode.PythonBinding @@ -617,11 +617,7 @@ namespace ICSharpCode.PythonBinding
/// Appends the properties of the object to the code builder.
/// </summary>
public void AppendProperties(PythonCodeBuilder codeBuilder, string propertyOwnerName, object obj)
{
if (ShouldAppendCollectionContent) {
AppendForEachCollectionContent(codeBuilder, obj, AppendCollectionContentProperties);
}
{
foreach (PropertyDescriptor property in GetSerializableProperties(obj)) {
if (!IgnoreProperty(property)) {
AppendProperty(codeBuilder, propertyOwnerName, obj, property);
@ -634,6 +630,10 @@ namespace ICSharpCode.PythonBinding @@ -634,6 +630,10 @@ namespace ICSharpCode.PythonBinding
/// </summary>
public void AppendProperties(PythonCodeBuilder codeBuilder)
{
if (ShouldAppendCollectionContent) {
AppendForEachCollectionContent(codeBuilder, component, AppendCollectionContentProperties);
}
AppendProperties(codeBuilder, GetPropertyOwnerName(), component);
}
@ -932,7 +932,8 @@ namespace ICSharpCode.PythonBinding @@ -932,7 +932,8 @@ namespace ICSharpCode.PythonBinding
void AppendForEachCollectionContent(PythonCodeBuilder codeBuilder, object component, AppendCollectionContent appendCollectionContent)
{
foreach (PropertyDescriptor propertyDescriptor in GetSerializableContentProperties(component)) {
ICollection collection = propertyDescriptor.GetValue(component) as ICollection;
object propertyValue = propertyDescriptor.GetValue(component);
ICollection collection = propertyValue as ICollection;
if (collection != null) {
int count = 1;
foreach (object item in collection) {
@ -943,6 +944,9 @@ namespace ICSharpCode.PythonBinding @@ -943,6 +944,9 @@ namespace ICSharpCode.PythonBinding
}
++count;
}
} else {
// Try child collections.
AppendForEachCollectionContent(codeBuilder, propertyValue, appendCollectionContent);
}
}
}

9
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateCustomCollectionItemsTestFixture.cs

@ -47,6 +47,8 @@ namespace PythonBinding.Tests.Designer @@ -47,6 +47,8 @@ namespace PythonBinding.Tests.Designer
userControl.ClientSize = new Size(200, 100);
userControl.FooItems.Add(new FooItem("aa"));
userControl.FooItems.Add(new FooItem("bb"));
userControl.ParentComponent.ParentBarItems.Add(new BarItem("cc"));
userControl.ParentComponent.ParentBarItems.Add(new BarItem("dd"));
form.Controls.Add(userControl);
PythonControl pythonForm = new PythonControl(" ");
@ -60,6 +62,8 @@ namespace PythonBinding.Tests.Designer @@ -60,6 +62,8 @@ namespace PythonBinding.Tests.Designer
string expectedCode = "def InitializeComponent(self):\r\n" +
" fooItem1 = PythonBinding.Tests.Utils.FooItem()\r\n" +
" fooItem2 = PythonBinding.Tests.Utils.FooItem()\r\n" +
" barItem1 = PythonBinding.Tests.Utils.BarItem()\r\n" +
" barItem2 = PythonBinding.Tests.Utils.BarItem()\r\n" +
" self._userControl1 = PythonBinding.Tests.Utils.CustomUserControl()\r\n" +
" self.SuspendLayout()\r\n" +
" # \r\n" +
@ -67,11 +71,16 @@ namespace PythonBinding.Tests.Designer @@ -67,11 +71,16 @@ namespace PythonBinding.Tests.Designer
" # \r\n" +
" fooItem1.Text = \"aa\"\r\n" +
" fooItem2.Text = \"bb\"\r\n" +
" barItem1.Text = \"cc\"\r\n" +
" barItem2.Text = \"dd\"\r\n" +
" self._userControl1.FooItems.AddRange(System.Array[PythonBinding.Tests.Utils.FooItem](\r\n" +
" [fooItem1,\r\n" +
" fooItem2]))\r\n" +
" self._userControl1.Location = System.Drawing.Point(0, 0)\r\n" +
" self._userControl1.Name = \"userControl1\"\r\n" +
" self._userControl1.ParentComponent.ParentBarItems.AddRange(System.Array[PythonBinding.Tests.Utils.BarItem](\r\n" +
" [barItem1,\r\n" +
" barItem2]))\r\n" +
" self._userControl1.Size = System.Drawing.Size(200, 100)\r\n" +
" self._userControl1.TabIndex = 0\r\n" +
" # \r\n" +

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

@ -323,6 +323,7 @@ @@ -323,6 +323,7 @@
<Compile Include="RunPythonCommandTestFixture.cs" />
<Compile Include="Utils\AddedComponent.cs" />
<Compile Include="Utils\AddInHelper.cs" />
<Compile Include="Utils\BarItemCollection.cs" />
<Compile Include="Utils\BrowseButtonInfo.cs" />
<Compile Include="Utils\BrowseFolderButtonInfo.cs" />
<Compile Include="Utils\ConvertedFile.cs" />

58
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/BarItemCollection.cs

@ -0,0 +1,58 @@ @@ -0,0 +1,58 @@
// <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.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Forms;
namespace PythonBinding.Tests.Utils
{
public class BarItem
{
string text = String.Empty;
public BarItem()
{
}
public BarItem(string text)
{
this.text = text;
}
public string Text {
get { return text; }
set { text = value; }
}
}
public class BarItemCollection : Collection<BarItem>
{
public BarItemCollection()
{
}
public void AddRange(BarItem[] items)
{
foreach (BarItem item in items) {
Add(item);
}
}
}
public class BarItemCollectionParentComponent : Component
{
BarItemCollection barItems = new BarItemCollection();
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public BarItemCollection ParentBarItems {
get { return barItems; }
}
}
}

6
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/CustomUserControl.cs

@ -14,6 +14,7 @@ namespace PythonBinding.Tests.Utils @@ -14,6 +14,7 @@ namespace PythonBinding.Tests.Utils
public class CustomUserControl : UserControl
{
FooItemCollection fooItems = new FooItemCollection();
BarItemCollectionParentComponent component = new BarItemCollectionParentComponent();
public CustomUserControl()
{
@ -23,5 +24,10 @@ namespace PythonBinding.Tests.Utils @@ -23,5 +24,10 @@ namespace PythonBinding.Tests.Utils
public FooItemCollection FooItems {
get { return fooItems; }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public BarItemCollectionParentComponent ParentComponent {
get { return component; }
}
}
}

12
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/FooItemCollection.cs

@ -8,6 +8,8 @@ @@ -8,6 +8,8 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Forms;
namespace PythonBinding.Tests.Utils
{
@ -43,4 +45,14 @@ namespace PythonBinding.Tests.Utils @@ -43,4 +45,14 @@ namespace PythonBinding.Tests.Utils
}
}
}
public class FooItemCollectionParentComponent : Component
{
FooItemCollection fooItems = new FooItemCollection();
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public FooItemCollection ParentFooItems {
get { return fooItems; }
}
}
}

Loading…
Cancel
Save