Browse Source

Added support for ISupportInitialize in the python forms designer.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4084 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 16 years ago
parent
commit
a61ee5f32d
  1. 4
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControl.cs
  2. 71
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerComponent.cs
  3. 12
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerComponentFactory.cs
  4. 31
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerRootComponent.cs
  5. 9
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonListViewComponent.cs
  6. 70
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateEventLogTestFixture.cs
  7. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

4
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControl.cs

@ -76,6 +76,7 @@ namespace ICSharpCode.PythonBinding @@ -76,6 +76,7 @@ namespace ICSharpCode.PythonBinding
if (rootDesignerComponent.HasNonVisualChildComponents()) {
rootDesignerComponent.AppendCreateComponentsContainer(codeBuilder);
rootDesignerComponent.AppendCreateNonVisualComponents(codeBuilder);
rootDesignerComponent.AppendNonVisualComponentsBeginInit(codeBuilder);
}
rootDesignerComponent.AppendCreateChildComponents(codeBuilder);
rootDesignerComponent.AppendChildComponentsSuspendLayout(codeBuilder);
@ -83,6 +84,9 @@ namespace ICSharpCode.PythonBinding @@ -83,6 +84,9 @@ namespace ICSharpCode.PythonBinding
rootDesignerComponent.AppendNonVisualComponents(codeBuilder);
rootDesignerComponent.AppendComponent(codeBuilder);
rootDesignerComponent.AppendChildComponentsResumeLayout(codeBuilder);
if (rootDesignerComponent.HasNonVisualChildComponents()) {
rootDesignerComponent.AppendNonVisualComponentsEndInit(codeBuilder);
}
rootDesignerComponent.AppendResumeLayout(codeBuilder);
}
}

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

@ -26,7 +26,8 @@ namespace ICSharpCode.PythonBinding @@ -26,7 +26,8 @@ namespace ICSharpCode.PythonBinding
static readonly DesignerSerializationVisibility[] notHiddenDesignerVisibility = new DesignerSerializationVisibility[] { DesignerSerializationVisibility.Content, DesignerSerializationVisibility.Visible };
static readonly DesignerSerializationVisibility[] contentDesignerVisibility = new DesignerSerializationVisibility[] { DesignerSerializationVisibility.Content };
IEventBindingService eventBindingService;
PythonDesignerComponent parent;
protected static readonly string[] suspendLayoutMethods = new string[] {"SuspendLayout()"};
protected static readonly string[] resumeLayoutMethods = new string[] {"ResumeLayout(False)", "PerformLayout()"};
@ -66,14 +67,20 @@ namespace ICSharpCode.PythonBinding @@ -66,14 +67,20 @@ namespace ICSharpCode.PythonBinding
return false;
}
}
public PythonDesignerComponent(IComponent component)
: this(component, new PythonEventBindingService())
: this(null, component)
{
}
PythonDesignerComponent(IComponent component, IEventBindingService eventBindingService)
public PythonDesignerComponent(PythonDesignerComponent parent, IComponent component)
: this(parent, component, new PythonEventBindingService())
{
}
PythonDesignerComponent(PythonDesignerComponent parent, IComponent component, IEventBindingService eventBindingService)
{
this.parent = parent;
this.component = component;
this.eventBindingService = eventBindingService;
}
@ -273,7 +280,7 @@ namespace ICSharpCode.PythonBinding @@ -273,7 +280,7 @@ namespace ICSharpCode.PythonBinding
foreach (object childObject in collection) {
IComponent childComponent = childObject as IComponent;
if (childComponent != null) {
PythonDesignerComponent designerComponent = PythonDesignerComponentFactory.CreateDesignerComponent(childComponent);
PythonDesignerComponent designerComponent = PythonDesignerComponentFactory.CreateDesignerComponent(this, childComponent);
if (designerComponent.IsSited) {
components.Add(designerComponent);
}
@ -314,19 +321,7 @@ namespace ICSharpCode.PythonBinding @@ -314,19 +321,7 @@ namespace ICSharpCode.PythonBinding
{
AppendChildComponentsMethodCalls(codeBuilder, resumeLayoutMethods);
}
void AppendChildComponentsMethodCalls(PythonCodeBuilder codeBuilder, string[] methods)
{
foreach (PythonDesignerComponent designerComponent in GetChildComponents()) {
if (typeof(Control).IsAssignableFrom(designerComponent.GetComponentType())) {
if (designerComponent.HasSitedChildComponents()) {
designerComponent.AppendMethodCalls(codeBuilder, methods);
}
}
designerComponent.AppendChildComponentsMethodCalls(codeBuilder, methods);
}
}
/// <summary>
/// Appends the code to create the specified object.
/// </summary>
@ -393,7 +388,7 @@ namespace ICSharpCode.PythonBinding @@ -393,7 +388,7 @@ namespace ICSharpCode.PythonBinding
foreach (object childObject in collection) {
IComponent childComponent = childObject as IComponent;
if (childComponent != null) {
PythonDesignerComponent designerComponent = PythonDesignerComponentFactory.CreateDesignerComponent(childComponent);
PythonDesignerComponent designerComponent = PythonDesignerComponentFactory.CreateDesignerComponent(this, childComponent);
if (designerComponent.IsSited) {
designerComponent.AppendComponentProperties(codeBuilder, true, true, true);
}
@ -427,7 +422,7 @@ namespace ICSharpCode.PythonBinding @@ -427,7 +422,7 @@ namespace ICSharpCode.PythonBinding
}
/// <summary>
/// Appends the method calls if this component.
/// Appends the method calls for this component.
/// </summary>
public void AppendMethodCalls(PythonCodeBuilder codeBuilder, string[] methods)
{
@ -481,7 +476,7 @@ namespace ICSharpCode.PythonBinding @@ -481,7 +476,7 @@ namespace ICSharpCode.PythonBinding
/// <summary>
/// Appends a property.
/// </summary>
public static void AppendProperty(PythonCodeBuilder codeBuilder, string propertyOwnerName, object obj, PropertyDescriptor propertyDescriptor)
public void AppendProperty(PythonCodeBuilder codeBuilder, string propertyOwnerName, object obj, PropertyDescriptor propertyDescriptor)
{
object propertyValue = propertyDescriptor.GetValue(obj);
if (propertyValue == null) {
@ -492,7 +487,7 @@ namespace ICSharpCode.PythonBinding @@ -492,7 +487,7 @@ namespace ICSharpCode.PythonBinding
string propertyName = propertyOwnerName + "." + propertyDescriptor.Name;
Control control = propertyValue as Control;
if (control != null) {
codeBuilder.AppendIndentedLine(propertyName + " = self._" + control.Name);
codeBuilder.AppendIndentedLine(propertyName + " = " + GetControlReference(control));
} else {
codeBuilder.AppendIndentedLine(propertyName + " = " + PythonPropertyValueAssignment.ToString(propertyValue));
}
@ -505,7 +500,7 @@ namespace ICSharpCode.PythonBinding @@ -505,7 +500,7 @@ namespace ICSharpCode.PythonBinding
/// <summary>
/// Appends the properties of the object to the code builder.
/// </summary>
public static void AppendProperties(PythonCodeBuilder codeBuilder, string propertyOwnerName, object obj)
public void AppendProperties(PythonCodeBuilder codeBuilder, string propertyOwnerName, object obj)
{
foreach (PropertyDescriptor property in GetSerializableProperties(obj)) {
AppendProperty(codeBuilder, propertyOwnerName, obj, property);
@ -666,6 +661,34 @@ namespace ICSharpCode.PythonBinding @@ -666,6 +661,34 @@ namespace ICSharpCode.PythonBinding
}
codeBuilder.Append("])");
}
}
}
void AppendChildComponentsMethodCalls(PythonCodeBuilder codeBuilder, string[] methods)
{
foreach (PythonDesignerComponent designerComponent in GetChildComponents()) {
if (typeof(Control).IsAssignableFrom(designerComponent.GetComponentType())) {
if (designerComponent.HasSitedChildComponents()) {
designerComponent.AppendMethodCalls(codeBuilder, methods);
}
}
designerComponent.AppendChildComponentsMethodCalls(codeBuilder, methods);
}
}
bool IsRootComponent(IComponent component)
{
if (parent == null) {
return this.component == component;
}
return parent.IsRootComponent(component);
}
string GetControlReference(Control control)
{
if (IsRootComponent(control)) {
return "self";
}
return "self._" + control.Name;
}
}
}

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

@ -21,11 +21,19 @@ namespace ICSharpCode.PythonBinding @@ -21,11 +21,19 @@ namespace ICSharpCode.PythonBinding
/// Creates a PythonDesignerComponent class for the specified component.
/// </summary>
public static PythonDesignerComponent CreateDesignerComponent(IComponent component)
{
return CreateDesignerComponent(null, component);
}
/// <summary>
/// Creates a PythonDesignerComponent class for the specified component.
/// </summary>
public static PythonDesignerComponent CreateDesignerComponent(PythonDesignerComponent parent, IComponent component)
{
if (component is ListView) {
return new PythonListViewComponent(component);
return new PythonListViewComponent(parent,component);
}
return new PythonDesignerComponent(component);
return new PythonDesignerComponent(parent, component);
}
public static PythonDesignerRootComponent CreateDesignerRootComponent(IComponent component)

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

@ -19,7 +19,7 @@ namespace ICSharpCode.PythonBinding @@ -19,7 +19,7 @@ namespace ICSharpCode.PythonBinding
public class PythonDesignerRootComponent : PythonDesignerComponent
{
public PythonDesignerRootComponent(IComponent component)
: base(component)
: base(null, component)
{
}
@ -76,7 +76,7 @@ namespace ICSharpCode.PythonBinding @@ -76,7 +76,7 @@ namespace ICSharpCode.PythonBinding
{
List<PythonDesignerComponent> components = new List<PythonDesignerComponent>();
foreach (IComponent containerComponent in Component.Site.Container.Components) {
PythonDesignerComponent designerComponent = PythonDesignerComponentFactory.CreateDesignerComponent(containerComponent);
PythonDesignerComponent designerComponent = PythonDesignerComponentFactory.CreateDesignerComponent(this, containerComponent);
if (designerComponent.IsNonVisual) {
components.Add(designerComponent);
}
@ -115,5 +115,32 @@ namespace ICSharpCode.PythonBinding @@ -115,5 +115,32 @@ namespace ICSharpCode.PythonBinding
component.AppendComponent(codeBuilder);
}
}
/// <summary>
/// Adds BeginInit method call for any non-visual components that implement the
/// System.ComponentModel.ISupportInitialize interface.
/// </summary>
public void AppendNonVisualComponentsBeginInit(PythonCodeBuilder codeBuilder)
{
AppendNonVisualComponentsMethodCalls(codeBuilder, new string[] {"BeginInit()"});
}
/// <summary>
/// Adds EndInit method call for any non-visual components that implement the
/// System.ComponentModel.ISupportInitialize interface.
/// </summary>
public void AppendNonVisualComponentsEndInit(PythonCodeBuilder codeBuilder)
{
AppendNonVisualComponentsMethodCalls(codeBuilder, new string[] {"EndInit()"});
}
public void AppendNonVisualComponentsMethodCalls(PythonCodeBuilder codeBuilder, string[] methods)
{
foreach (PythonDesignerComponent component in GetNonVisualChildComponents()) {
if (typeof(ISupportInitialize).IsAssignableFrom(component.GetComponentType())) {
component.AppendMethodCalls(codeBuilder, methods);
}
}
}
}
}

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

@ -15,8 +15,13 @@ namespace ICSharpCode.PythonBinding @@ -15,8 +15,13 @@ namespace ICSharpCode.PythonBinding
/// Used to generate code for a ListView component currently being designed.
/// </summary>
public class PythonListViewComponent : PythonDesignerComponent
{
public PythonListViewComponent(IComponent component) : base(component)
{
public PythonListViewComponent(IComponent component) : this(null, component)
{
}
public PythonListViewComponent(PythonDesignerComponent parent, IComponent component)
: base(parent, component)
{
}

70
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateEventLogTestFixture.cs

@ -0,0 +1,70 @@ @@ -0,0 +1,70 @@
// <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.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using ICSharpCode.PythonBinding;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Designer
{
[TestFixture]
public class GenerateEventLogTestFixture
{
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");
EventLog eventLog = (EventLog)host.CreateComponent(typeof(EventLog), "eventLog1");
string indentString = " ";
PythonControl pythonControl = new PythonControl(indentString);
generatedPythonCode = pythonControl.GenerateInitializeComponentMethod(form);
}
}
[Test]
public void GeneratedCode()
{
string expectedCode = "def InitializeComponent(self):\r\n" +
" self._components = System.ComponentModel.Container()\r\n" +
" self._eventLog1 = System.Diagnostics.EventLog()\r\n" +
" self._eventLog1.BeginInit()\r\n" +
" self.SuspendLayout()\r\n" +
" # \r\n" +
" # eventLog1\r\n" +
" # \r\n" +
" self._eventLog1.SynchronizingObject = self\r\n" +
" # \r\n" +
" # MainForm\r\n" +
" # \r\n" +
" self.ClientSize = System.Drawing.Size(284, 264)\r\n" +
" self.Name = \"MainForm\"\r\n" +
" self._eventLog1.EndInit()\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

@ -174,6 +174,7 @@ @@ -174,6 +174,7 @@
<Compile Include="Designer\GeneratedControlOrderingTestFixture.cs" />
<Compile Include="Designer\GenerateDoubleBufferedFormTestFixture.cs" />
<Compile Include="Designer\GenerateEventHandlerFormTestFixture.cs" />
<Compile Include="Designer\GenerateEventLogTestFixture.cs" />
<Compile Include="Designer\GenerateFormColorTestFixture.cs" />
<Compile Include="Designer\GenerateFormLocationTestFixture.cs" />
<Compile Include="Designer\GenerateFormPaddingTestFixture.cs" />

Loading…
Cancel
Save