Browse Source

Python forms designer no longer generates code for the form's MainMenuStrip property after the menu strip has been removed.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4171 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 17 years ago
parent
commit
9f1c668e8e
  1. 9
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerComponent.cs
  2. 77
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/RemoveMainMenuStripFromFormTestFixture.cs
  3. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

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

@ -500,7 +500,10 @@ namespace ICSharpCode.PythonBinding @@ -500,7 +500,10 @@ namespace ICSharpCode.PythonBinding
string propertyName = propertyOwnerName + "." + propertyDescriptor.Name;
Control control = propertyValue as Control;
if (control != null) {
codeBuilder.AppendIndentedLine(propertyName + " = " + GetControlReference(control));
string controlRef = GetControlReference(control);
if (controlRef != null) {
codeBuilder.AppendIndentedLine(propertyName + " = " + controlRef);
}
} else {
codeBuilder.AppendIndentedLine(propertyName + " = " + PythonPropertyValueAssignment.ToString(propertyValue));
}
@ -726,8 +729,10 @@ namespace ICSharpCode.PythonBinding @@ -726,8 +729,10 @@ namespace ICSharpCode.PythonBinding
{
if (IsRootComponent(control)) {
return "self";
} else if (!String.IsNullOrEmpty(control.Name)) {
return "self._" + control.Name;
}
return "self._" + control.Name;
return null;
}
static ExtenderProvidedPropertyAttribute GetExtenderAttribute(PropertyDescriptor property)

77
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/RemoveMainMenuStripFromFormTestFixture.cs

@ -0,0 +1,77 @@ @@ -0,0 +1,77 @@
// <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.Drawing;
using System.Windows.Forms;
using ICSharpCode.PythonBinding;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Designer
{
/// <summary>
/// When a MenuStrip is added to a form and then removed the python designer generates code
/// for the form's MainMenuStrip property even though the MenuStrip has been removed.
/// </summary>
[TestFixture]
public class RemoveMainMenuStripFromFormTestFixture
{
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);
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form);
PropertyDescriptor descriptor = descriptors.Find("Name", false);
descriptor.SetValue(form, "MainForm");
// Add menu strip.
MenuStrip menuStrip = (MenuStrip)host.CreateComponent(typeof(MenuStrip), "menuStrip1");
menuStrip.Text = "menuStrip1";
menuStrip.TabIndex = 0;
menuStrip.Location = new Point(0, 0);
form.Controls.Add(menuStrip);
descriptor = descriptors.Find("MainMenuStrip", false);
descriptor.SetValue(form, menuStrip);
form.Controls.Remove(menuStrip);
host.Container.Remove(menuStrip);
PythonControl pythonForm = new PythonControl(" ");
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
}
}
[Test]
public void GeneratedCode()
{
string expectedCode = "def InitializeComponent(self):\r\n" +
" self.SuspendLayout()\r\n" +
" # \r\n" +
" # MainForm\r\n" +
" # \r\n" +
" self.ClientSize = System.Drawing.Size(200, 300)\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

@ -237,6 +237,7 @@ @@ -237,6 +237,7 @@
<Compile Include="Designer\PythonDesignerLoaderProviderTestFixture.cs" />
<Compile Include="Designer\PythonDesignerLoaderTestFixture.cs" />
<Compile Include="Designer\PythonPropertyAssignmentToStringTests.cs" />
<Compile Include="Designer\RemoveMainMenuStripFromFormTestFixture.cs" />
<Compile Include="Designer\TextBoxNotAddedToFormTestFixture.cs" />
<Compile Include="Designer\TextEditorIndentPassedToGeneratorTestFixture.cs" />
<Compile Include="Designer\UnknownTypeTestFixture.cs" />

Loading…
Cancel
Save