Browse Source

Python forms designer no longer generates code for controls in inherited base class.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4563 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 16 years ago
parent
commit
f2f7704f3d
  1. 31
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerComponent.cs
  2. 76
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateInheritedFormTestFixture.cs
  3. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

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

@ -247,7 +247,10 @@ namespace ICSharpCode.PythonBinding
designerContainerComponents = new List<PythonDesignerComponent>(); designerContainerComponents = new List<PythonDesignerComponent>();
ComponentCollection components = Component.Site.Container.Components; ComponentCollection components = Component.Site.Container.Components;
for (int i = 1; i < components.Count; ++i) { for (int i = 1; i < components.Count; ++i) {
designerContainerComponents.Add(PythonDesignerComponentFactory.CreateDesignerComponent(this, components[i])); PythonDesignerComponent designerComponent = PythonDesignerComponentFactory.CreateDesignerComponent(this, components[i]);
if (!designerComponent.IsInheritedReadOnly) {
designerContainerComponents.Add(designerComponent);
}
} }
} }
return designerContainerComponents.ToArray(); return designerContainerComponents.ToArray();
@ -279,6 +282,28 @@ namespace ICSharpCode.PythonBinding
public bool IsSited { public bool IsSited {
get { return IsSitedComponent(component); } get { return IsSitedComponent(component); }
} }
/// <summary>
/// Returns true if the component has an InheritanceAttribute set to InheritanceLevel.InheritedReadOnly
/// </summary>
public static bool IsInheritedReadOnlyComponent(object component)
{
if (component != null) {
AttributeCollection attributes = TypeDescriptor.GetAttributes(component);
InheritanceAttribute attribute = (InheritanceAttribute)attributes[typeof(InheritanceAttribute)];
if (attribute != null) {
return attribute.InheritanceLevel == InheritanceLevel.InheritedReadOnly;
}
}
return false;
}
/// <summary>
/// Returns true if the component has an InheritanceAttribute set to InheritanceLevel.InheritedReadOnly
/// </summary>
public bool IsInheritedReadOnly {
get { return IsInheritedReadOnlyComponent(component); }
}
/// <summary> /// <summary>
/// Gets the child objects that need to be stored in the generated designer code on the specified object. /// Gets the child objects that need to be stored in the generated designer code on the specified object.
@ -470,7 +495,7 @@ namespace ICSharpCode.PythonBinding
} }
foreach (object item in collectionProperty) { foreach (object item in collectionProperty) {
IComponent collectionComponent = item as IComponent; IComponent collectionComponent = item as IComponent;
if (PythonDesignerComponent.IsSitedComponent(collectionComponent)) { if (PythonDesignerComponent.IsSitedComponent(collectionComponent) && !PythonDesignerComponent.IsInheritedReadOnlyComponent(collectionComponent)) {
codeBuilder.AppendIndentedLine(propertyOwnerName + "." + propertyDescriptor.Name + "." + addMethod.Name + "(self._" + collectionComponent.Site.Name + ")"); codeBuilder.AppendIndentedLine(propertyOwnerName + "." + propertyDescriptor.Name + "." + addMethod.Name + "(self._" + collectionComponent.Site.Name + ")");
} }
} }
@ -726,7 +751,7 @@ namespace ICSharpCode.PythonBinding
void AppendCreateChildComponents(PythonCodeBuilder codeBuilder, PythonDesignerComponent[] childComponents) void AppendCreateChildComponents(PythonCodeBuilder codeBuilder, PythonDesignerComponent[] childComponents)
{ {
foreach (PythonDesignerComponent designerComponent in childComponents) { foreach (PythonDesignerComponent designerComponent in childComponents) {
if (designerComponent.IsSited) { if (designerComponent.IsSited) {
designerComponent.AppendCreateInstance(codeBuilder); designerComponent.AppendCreateInstance(codeBuilder);
} }
} }

76
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateInheritedFormTestFixture.cs

@ -0,0 +1,76 @@
// <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
{
class BaseForm : Form
{
Button button1 = new Button();
public BaseForm()
{
button1.Name = "button1";
Controls.Add(button1);
}
}
class DerivedForm : BaseForm
{
}
/// <summary>
/// Tests that no code is generated for controls that are inherited from the base class.
/// </summary>
[TestFixture]
public class GenerateInheritedFormTestFixture
{
string generatedPythonCode;
[TestFixtureSetUp]
public void SetUpFixture()
{
using (DesignSurface designSurface = new DesignSurface(typeof(DerivedForm))) {
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");
string indentString = " ";
PythonControl pythonForm = new PythonControl(indentString);
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(284, 264)\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

@ -196,6 +196,7 @@
<Compile Include="Designer\GenerateFormResourcesTestFixture.cs" /> <Compile Include="Designer\GenerateFormResourcesTestFixture.cs" />
<Compile Include="Designer\GenerateImageListResourcesTestFixture.cs" /> <Compile Include="Designer\GenerateImageListResourcesTestFixture.cs" />
<Compile Include="Designer\GenerateImeModeFormTestFixture.cs" /> <Compile Include="Designer\GenerateImeModeFormTestFixture.cs" />
<Compile Include="Designer\GenerateInheritedFormTestFixture.cs" />
<Compile Include="Designer\GenerateListViewItemTestFixture.cs" /> <Compile Include="Designer\GenerateListViewItemTestFixture.cs" />
<Compile Include="Designer\GenerateListViewSubItemsTestFixture.cs" /> <Compile Include="Designer\GenerateListViewSubItemsTestFixture.cs" />
<Compile Include="Designer\GenerateListViewWithImageListTestFixture.cs" /> <Compile Include="Designer\GenerateListViewWithImageListTestFixture.cs" />

Loading…
Cancel
Save