Browse Source

Python forms designer now generating the correct code when assigning a DataSet to a DataGridView's DataSource.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4359 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 17 years ago
parent
commit
608e01af81
  1. 25
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerComponent.cs
  2. 89
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateDataSetTestFixture.cs
  3. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

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

@ -489,11 +489,11 @@ namespace ICSharpCode.PythonBinding @@ -489,11 +489,11 @@ namespace ICSharpCode.PythonBinding
AppendExtenderProperty(codeBuilder, propertyOwnerName, extender, propertyDescriptor, propertyValue);
} else if (propertyDescriptor.SerializationVisibility == DesignerSerializationVisibility.Visible) {
string propertyName = propertyOwnerName + "." + propertyDescriptor.Name;
Control control = propertyValue as Control;
if (control != null) {
string controlRef = GetControlReference(control);
if (controlRef != null) {
codeBuilder.AppendIndentedLine(propertyName + " = " + controlRef);
IComponent component = propertyValue as IComponent;
if (component != null) {
string componentRef = GetComponentReference(component);
if (componentRef != null) {
codeBuilder.AppendIndentedLine(propertyName + " = " + componentRef);
}
} else if (IsResourcePropertyValue(propertyValue)) {
AppendResourceProperty(codeBuilder, propertyName, propertyValue);
@ -756,12 +756,17 @@ namespace ICSharpCode.PythonBinding @@ -756,12 +756,17 @@ namespace ICSharpCode.PythonBinding
return parent.IsRootComponent(component);
}
string GetControlReference(Control control)
{
if (IsRootComponent(control)) {
string GetComponentReference(IComponent component)
{
if (IsRootComponent(component)) {
return "self";
} else if (!String.IsNullOrEmpty(control.Name)) {
return "self._" + control.Name;
} else {
foreach (PythonDesignerComponent designerComponent in GetContainerComponents()) {
string name = component.Site.Name;
if ((designerComponent.component == component) && (!String.IsNullOrEmpty(name))) {
return "self._" + name;
}
}
}
return null;
}

89
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateDataSetTestFixture.cs

@ -0,0 +1,89 @@ @@ -0,0 +1,89 @@
// <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.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using ICSharpCode.PythonBinding;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Designer
{
[TestFixture]
public class GenerateDataSetTestFixture
{
string generatedPythonCode;
[TestFixtureSetUp]
public void SetUpFixture()
{
using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
IEventBindingService eventBindingService = new MockEventBindingService(host);
Form form = (Form)host.RootComponent;
form.ClientSize = new Size(200, 300);
DataGridView dataGridView = (DataGridView)host.CreateComponent(typeof(DataGridView), "dataGridView1");
dataGridView.Location = new Point(0, 0);
dataGridView.Size = new Size(100, 100);
form.Controls.Add(dataGridView);
DataSet dataSet = (DataSet)host.CreateComponent(typeof(DataSet), "dataSet1");
dataGridView.DataSource = dataSet;
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form);
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
namePropertyDescriptor.SetValue(form, "MainForm");
PythonControl pythonForm = new PythonControl(" ");
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
}
}
[Test]
public void GeneratedCode()
{
string expectedCode = "def InitializeComponent(self):\r\n" +
" self._dataGridView1 = System.Windows.Forms.DataGridView()\r\n" +
" self._dataSet1 = System.Data.DataSet()\r\n" +
" self._dataGridView1.BeginInit()\r\n" +
" self._dataSet1.BeginInit()\r\n" +
" self.SuspendLayout()\r\n" +
" # \r\n" +
" # dataGridView1\r\n" +
" # \r\n" +
" self._dataGridView1.AutoGenerateColumns = False\r\n" +
" self._dataGridView1.DataSource = self._dataSet1\r\n" +
" self._dataGridView1.Location = System.Drawing.Point(0, 0)\r\n" +
" self._dataGridView1.Name = \"dataGridView1\"\r\n" +
" self._dataGridView1.Size = System.Drawing.Size(100, 100)\r\n" +
" self._dataGridView1.TabIndex = 0\r\n" +
" # \r\n" +
" # dataSet1\r\n" +
" # \r\n" +
" self._dataSet1.DataSetName = \"NewDataSet\"\r\n" +
" # \r\n" +
" # MainForm\r\n" +
" # \r\n" +
" self.ClientSize = System.Drawing.Size(200, 300)\r\n" +
" self.Controls.Add(self._dataGridView1)\r\n" +
" self.Name = \"MainForm\"\r\n" +
" self._dataGridView1.EndInit()\r\n" +
" self._dataSet1.EndInit()\r\n" +
" self.ResumeLayout(False)\r\n" +
" self.PerformLayout()\r\n";
Assert.AreEqual(expectedCode, generatedPythonCode, generatedPythonCode);
}
}
}

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

@ -58,6 +58,7 @@ @@ -58,6 +58,7 @@
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Design" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
@ -181,6 +182,7 @@ @@ -181,6 +182,7 @@
<Compile Include="Designer\GenerateComboBoxItemsTestFixture.cs" />
<Compile Include="Designer\GenerateContextMenuStripTestFixture.cs" />
<Compile Include="Designer\GenerateCursorFormTestFixture.cs" />
<Compile Include="Designer\GenerateDataSetTestFixture.cs" />
<Compile Include="Designer\GeneratedControlOrderingTestFixture.cs" />
<Compile Include="Designer\GenerateDoubleBufferedFormTestFixture.cs" />
<Compile Include="Designer\GenerateEventHandlerFormTestFixture.cs" />

Loading…
Cancel
Save