Browse Source

Ordering of controls in generated python forms designer code now matches the order of the standard forms designer.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4045 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 16 years ago
parent
commit
136edb3fd9
  1. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerComponent.cs
  2. 12
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerRootComponent.cs
  3. 100
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GeneratedControlOrderingTestFixture.cs
  4. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

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

@ -224,7 +224,7 @@ namespace ICSharpCode.PythonBinding @@ -224,7 +224,7 @@ namespace ICSharpCode.PythonBinding
/// For a MenuStrip the child components include the MenuStrip.Items.
/// For a Control the child components include the Control.Controls.
/// </remarks>
public object[] GetChildComponents()
public virtual object[] GetChildComponents()
{
List<object> childComponents = new List<object>();
foreach (PropertyDescriptor property in GetSerializableContentProperties(component)) {

12
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerRootComponent.cs

@ -37,7 +37,7 @@ namespace ICSharpCode.PythonBinding @@ -37,7 +37,7 @@ namespace ICSharpCode.PythonBinding
public override void AppendComponent(PythonCodeBuilder codeBuilder)
{
// Add the child component's first.
// Add the child components first.
foreach (IComponent component in GetChildComponents()) {
PythonDesignerComponentFactory.CreateDesignerComponent(component).AppendComponent(codeBuilder);
}
@ -45,5 +45,15 @@ namespace ICSharpCode.PythonBinding @@ -45,5 +45,15 @@ namespace ICSharpCode.PythonBinding
// Add root component
AppendComponentProperties(codeBuilder, false, false, true);
}
/// <summary>
/// Gets the child components in reverse order since the forms designer has them reversed.
/// </summary>
public override object[] GetChildComponents()
{
object[] components = base.GetChildComponents();
Array.Reverse(components);
return components;
}
}
}

100
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GeneratedControlOrderingTestFixture.cs

@ -0,0 +1,100 @@ @@ -0,0 +1,100 @@
// <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.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms;
using ICSharpCode.PythonBinding;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Designer
{
/// <summary>
/// Tests that the controls are initialized in the order they were put on the form.
/// The forms designer has them in reverse order in the Controls collection.
/// </summary>
[TestFixture]
public class GeneratedControlOrderingTestFixture
{
string generatedPythonCode;
[TestFixtureSetUp]
public void SetUpFixture()
{
using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
Form form = (Form)host.RootComponent;
form.ClientSize = new Size(284, 264);
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form);
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
namePropertyDescriptor.SetValue(form, "MainForm");
RadioButton radioButton = (RadioButton)host.CreateComponent(typeof(RadioButton), "radioButton1");
radioButton.Location = new Point(20, 0);
radioButton.Size = new Size(10, 10);
radioButton.Text = "radioButton1";
radioButton.TabIndex = 1;
radioButton.UseCompatibleTextRendering = false;
form.Controls.Add(radioButton);
// Add button after radio button to simulate the forms designer
// behaviour of adding the controls in reverse order to the Controls collection.
Button button = (Button)host.CreateComponent(typeof(Button), "button1");
button.Location = new Point(0, 0);
button.Size = new Size(10, 10);
button.Text = "button1";
button.TabIndex = 0;
button.UseCompatibleTextRendering = false;
form.Controls.Add(button);
string indentString = " ";
PythonControl pythonForm = new PythonControl(indentString);
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
}
}
[Test]
public void GeneratedCode()
{
string expectedCode = "def InitializeComponent(self):\r\n" +
" self._button1 = System.Windows.Forms.Button()\r\n" +
" self._radioButton1 = System.Windows.Forms.RadioButton()\r\n" +
" self.SuspendLayout()\r\n" +
" # \r\n" +
" # button1\r\n" +
" # \r\n" +
" self._button1.Location = System.Drawing.Point(0, 0)\r\n" +
" self._button1.Name = \"button1\"\r\n" +
" self._button1.Size = System.Drawing.Size(10, 10)\r\n" +
" self._button1.TabIndex = 0\r\n" +
" self._button1.Text = \"button1\"\r\n" +
" # \r\n" +
" # radioButton1\r\n" +
" # \r\n" +
" self._radioButton1.Location = System.Drawing.Point(20, 0)\r\n" +
" self._radioButton1.Name = \"radioButton1\"\r\n" +
" self._radioButton1.Size = System.Drawing.Size(10, 10)\r\n" +
" self._radioButton1.TabIndex = 1\r\n" +
" self._radioButton1.Text = \"radioButton1\"\r\n" +
" # \r\n" +
" # MainForm\r\n" +
" # \r\n" +
" self.ClientSize = System.Drawing.Size(284, 264)\r\n" +
" self.Controls.Add(self._radioButton1)\r\n" +
" self.Controls.Add(self._button1)\r\n" +
" self.Name = \"MainForm\"\r\n" +
" self.ResumeLayout(False)\r\n" +
" self.PerformLayout()\r\n";
Assert.AreEqual(expectedCode, generatedPythonCode, generatedPythonCode);
}
}
}

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

@ -164,6 +164,7 @@ @@ -164,6 +164,7 @@
<Compile Include="Designer\GenerateAutoScrollFormTestFixture.cs" />
<Compile Include="Designer\GenerateComboBoxItemsTestFixture.cs" />
<Compile Include="Designer\GenerateCursorFormTestFixture.cs" />
<Compile Include="Designer\GeneratedControlOrderingTestFixture.cs" />
<Compile Include="Designer\GenerateDoubleBufferedFormTestFixture.cs" />
<Compile Include="Designer\GenerateEventHandlerFormTestFixture.cs" />
<Compile Include="Designer\GenerateFormColorTestFixture.cs" />

Loading…
Cancel
Save