diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj b/src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj
index 60791adb91..86908624fc 100644
--- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj
+++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj
@@ -80,6 +80,7 @@
+
@@ -87,15 +88,19 @@
+
+
+
+
diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonCodeBuilder.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonCodeBuilder.cs
new file mode 100644
index 0000000000..7cb790dc88
--- /dev/null
+++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonCodeBuilder.cs
@@ -0,0 +1,81 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+using System;
+using System.Text;
+
+namespace ICSharpCode.PythonBinding
+{
+ public class PythonCodeBuilder
+ {
+ StringBuilder codeBuilder = new StringBuilder();
+ string indentString = "\t";
+ int indent;
+
+ public PythonCodeBuilder()
+ {
+ }
+
+ ///
+ /// Gets or sets the string used for indenting.
+ ///
+ public string IndentString {
+ get { return indentString; }
+ set { indentString = value; }
+ }
+
+ ///
+ /// Returns the code.
+ ///
+ public override string ToString()
+ {
+ return codeBuilder.ToString();
+ }
+
+ ///
+ /// Appends text at the end of the current code.
+ ///
+ public void Append(string text)
+ {
+ codeBuilder.Append(text);
+ }
+
+ ///
+ /// Appends carriage return and line feed to the existing text.
+ ///
+ public void AppendLine()
+ {
+ Append("\r\n");
+ }
+
+ ///
+ /// Appends the text indented.
+ ///
+ public void AppendIndented(string text)
+ {
+ for (int i = 0; i < indent; ++i) {
+ codeBuilder.Append(indentString);
+ }
+ codeBuilder.Append(text);
+ }
+
+ public void AppendIndentedLine(string text)
+ {
+ AppendIndented(text + "\r\n");
+ }
+
+ public void IncreaseIndent()
+ {
+ indent++;
+ }
+
+ public void DecreaseIndent()
+ {
+ indent--;
+ }
+ }
+}
diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControl.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControl.cs
index ada249bcaf..47ab6f0cad 100644
--- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControl.cs
+++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControl.cs
@@ -25,65 +25,17 @@ namespace ICSharpCode.PythonBinding
///
public class PythonControl
{
- StringBuilder codeBuilder;
+ PythonCodeBuilder codeBuilder;
string indentString = String.Empty;
- int indent;
- IEventBindingService eventBindingService;
- static readonly Attribute[] notDesignOnlyFilter = new Attribute[] { DesignOnlyAttribute.No };
- static readonly DesignerSerializationVisibility[] notHiddenDesignerVisibility = new DesignerSerializationVisibility[] { DesignerSerializationVisibility.Content, DesignerSerializationVisibility.Visible };
- static readonly DesignerSerializationVisibility[] contentDesignerVisibility = new DesignerSerializationVisibility[] { DesignerSerializationVisibility.Content };
-
- ///
- /// Used so the EventBindingService.GetEventProperty method can be called to get the property descriptor
- /// for an event.
- ///
- class PythonFormEventBindingService : EventBindingService
- {
- public PythonFormEventBindingService()
- : base(new ServiceContainer())
- {
- }
-
- protected override string CreateUniqueMethodName(IComponent component, EventDescriptor e)
- {
- return String.Empty;
- }
-
- protected override ICollection GetCompatibleMethods(EventDescriptor e)
- {
- return new ArrayList();
- }
-
- protected override bool ShowCode()
- {
- return false;
- }
-
- protected override bool ShowCode(int lineNumber)
- {
- return false;
- }
-
- protected override bool ShowCode(IComponent component, EventDescriptor e, string methodName)
- {
- return false;
- }
- }
public PythonControl()
: this("\t")
{
}
- public PythonControl(string indentString)
- : this(indentString, new PythonFormEventBindingService())
- {
- }
-
- PythonControl(string indentString, IEventBindingService eventBindingService)
+ public PythonControl(string indentString)
{
this.indentString = indentString;
- this.eventBindingService = eventBindingService;
}
///
@@ -91,10 +43,11 @@ namespace ICSharpCode.PythonBinding
///
public string GenerateInitializeComponentMethod(Control control)
{
- codeBuilder = new StringBuilder();
+ codeBuilder = new PythonCodeBuilder();
+ codeBuilder.IndentString = indentString;
- AppendIndentedLine("def InitializeComponent(self):");
- IncreaseIndent();
+ codeBuilder.AppendIndentedLine("def InitializeComponent(self):");
+ codeBuilder.IncreaseIndent();
GenerateInitializeComponentMethodBodyInternal(control);
@@ -106,498 +59,26 @@ namespace ICSharpCode.PythonBinding
///
public string GenerateInitializeComponentMethodBody(Control control, int initialIndent)
{
- codeBuilder = new StringBuilder();
+ codeBuilder = new PythonCodeBuilder();
+ codeBuilder.IndentString = indentString;
- indent = initialIndent;
+ for (int i = 0; i < initialIndent; ++i) {
+ codeBuilder.IncreaseIndent();
+ }
GenerateInitializeComponentMethodBodyInternal(control);
return codeBuilder.ToString();
- }
-
- ///
- /// Gets a list of properties that should be serialized for the specified form.
- ///
- public static PropertyDescriptorCollection GetSerializableProperties(object obj)
- {
- return GetSerializableProperties(obj, notHiddenDesignerVisibility);
- }
-
- ///
- /// Gets a list of properties that should have their content serialized for the specified form.
- ///
- public static PropertyDescriptorCollection GetSerializableContentProperties(object obj)
- {
- return GetSerializableProperties(obj, contentDesignerVisibility);
- }
-
- ///
- /// Gets the serializable properties with the specified designer serialization visibility.
- ///
- public static PropertyDescriptorCollection GetSerializableProperties(object obj, DesignerSerializationVisibility[] visibility)
- {
- List requiredVisibility = new List(visibility);
- List properties = new List();
- foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(obj, notDesignOnlyFilter).Sort()) {
- if (requiredVisibility.Contains(property.SerializationVisibility)) {
- if (property.ShouldSerializeValue(obj)) {
- properties.Add(property);
- }
- }
- }
- return new PropertyDescriptorCollection(properties.ToArray());
- }
-
- ///
- /// Determines whether the object is an IComponent and has a non-null ISite.
- ///
- public static bool IsSitedComponent(object obj)
- {
- IComponent component = obj as IComponent;
- if (component != null) {
- return component.Site != null;
- }
- return false;
- }
-
- ///
- /// Gets the AddRange method on the object that is not hidden from the designer.
- ///
- public static MethodInfo GetAddRangeSerializationMethod(object obj)
- {
- foreach (MethodInfo methodInfo in obj.GetType().GetMethods()) {
- if (methodInfo.Name == "AddRange") {
- ParameterInfo[] parameters = methodInfo.GetParameters();
- if (parameters.Length == 1) {
- if (parameters[0].ParameterType.IsArray) {
- if (!IsHiddenFromDesignerSerializer(methodInfo)) {
- return methodInfo;
- }
- }
- }
- }
- }
- return null;
- }
-
- ///
- /// Gets the Add serialization method that is not hidden from the designer.
- ///
- public static MethodInfo GetAddSerializationMethod(object obj)
- {
- foreach (MethodInfo methodInfo in obj.GetType().GetMethods()) {
- if (methodInfo.Name == "Add") {
- return methodInfo;
- }
- }
- return null;
- }
-
- ///
- /// Gets the type used in the array for the first parameter to the method.
- ///
- public static Type GetArrayParameterType(MethodInfo methodInfo)
- {
- if (methodInfo != null) {
- ParameterInfo[] parameters = methodInfo.GetParameters();
- if (parameters.Length > 0) {
- Type arrayType = parameters[0].ParameterType;
- return arrayType.GetElementType();
- }
- }
- return null;
- }
-
- ///
- /// Checks whether the method is marked with the DesignerSerializationVisibility.Hidden attribute.
- ///
- public static bool IsHiddenFromDesignerSerializer(MethodInfo methodInfo)
- {
- foreach (DesignerSerializationVisibilityAttribute attribute in methodInfo.GetCustomAttributes(typeof(DesignerSerializationVisibilityAttribute), true)) {
- if (attribute.Visibility == DesignerSerializationVisibility.Hidden) {
- return true;
- }
- }
- return false;
- }
-
- ///
- /// Gets the child objects that need to be stored in the generated designer code on the specified object.
- ///
- ///
- /// For a MenuStrip the child components include the MenuStrip.Items.
- /// For a Control the child components include the Control.Controls.
- ///
- public static object[] GetChildComponents(object obj)
- {
- List