Browse Source

Python forms designer does not generate comments for a control if no property or event handler code was generated for that control.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4095 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 17 years ago
parent
commit
94718ae84b
  1. 16
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonCodeBuilder.cs
  2. 18
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerComponent.cs
  3. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonListViewComponent.cs
  4. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateSimpleFormTestFixture.cs
  5. 63
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateToolTipFormTestFixture.cs
  6. 28
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonCodeBuilderTests.cs
  7. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

16
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonCodeBuilder.cs

@ -20,6 +20,11 @@ namespace ICSharpCode.PythonBinding @@ -20,6 +20,11 @@ namespace ICSharpCode.PythonBinding
{
}
public PythonCodeBuilder(int initialIndent)
{
indent = initialIndent;
}
/// <summary>
/// Gets or sets the string used for indenting.
/// </summary>
@ -77,5 +82,16 @@ namespace ICSharpCode.PythonBinding @@ -77,5 +82,16 @@ namespace ICSharpCode.PythonBinding
{
indent--;
}
public int Indent {
get { return indent; }
}
/// <summary>
/// Gets the length of the current code string.
/// </summary>
public int Length {
get { return codeBuilder.Length; }
}
}
}

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

@ -240,7 +240,6 @@ namespace ICSharpCode.PythonBinding @@ -240,7 +240,6 @@ namespace ICSharpCode.PythonBinding
/// </summary>
public virtual void AppendComponent(PythonCodeBuilder codeBuilder)
{
AppendComment(codeBuilder);
AppendComponentProperties(codeBuilder);
AppendChildComponentProperties(codeBuilder);
}
@ -372,7 +371,7 @@ namespace ICSharpCode.PythonBinding @@ -372,7 +371,7 @@ namespace ICSharpCode.PythonBinding
/// </summary>
public void AppendComponentProperties(PythonCodeBuilder codeBuilder)
{
AppendComponentProperties(codeBuilder, true, false, false);
AppendComponentProperties(codeBuilder, true, false, true);
}
/// <summary>
@ -520,13 +519,18 @@ namespace ICSharpCode.PythonBinding @@ -520,13 +519,18 @@ namespace ICSharpCode.PythonBinding
/// </summary>
public void AppendComponentProperties(PythonCodeBuilder codeBuilder, bool addComponentNameToProperty, bool addChildComponentProperties, bool addComment)
{
if (addComment) {
PythonCodeBuilder propertiesBuilder = new PythonCodeBuilder(codeBuilder.Indent);
propertiesBuilder.IndentString = codeBuilder.IndentString;
AppendProperties(propertiesBuilder);
AppendEventHandlers(propertiesBuilder, eventBindingService);
// Add comment if we have added some properties or event handlers.
if (addComment && propertiesBuilder.Length > 0) {
AppendComment(codeBuilder);
}
AppendProperties(codeBuilder);
AppendEventHandlers(codeBuilder, eventBindingService);
codeBuilder.Append(propertiesBuilder.ToString());
if (addChildComponentProperties) {
AppendChildComponentProperties(codeBuilder);
}

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

@ -48,7 +48,7 @@ namespace ICSharpCode.PythonBinding @@ -48,7 +48,7 @@ namespace ICSharpCode.PythonBinding
{
AppendComment(codeBuilder);
AppendListViewItemProperties(codeBuilder);
AppendComponentProperties(codeBuilder);
AppendComponentProperties(codeBuilder, true, false, false);
AppendChildComponentProperties(codeBuilder);
}

2
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateSimpleFormTestFixture.cs

@ -44,7 +44,7 @@ namespace PythonBinding.Tests.Designer @@ -44,7 +44,7 @@ namespace PythonBinding.Tests.Designer
codeBuilder.IncreaseIndent();
PythonDesignerRootComponent designerRootComponent = new PythonDesignerRootComponent(form);
propertyOwnerName = designerRootComponent.GetPropertyOwnerName();
designerRootComponent.AppendComponentProperties(codeBuilder);
designerRootComponent.AppendComponentProperties(codeBuilder, true, false, false);
formPropertiesCode = codeBuilder.ToString();
}
}

63
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateToolTipFormTestFixture.cs

@ -0,0 +1,63 @@ @@ -0,0 +1,63 @@
// <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
{
[TestFixture]
public class GenerateToolTipFormTestFixture
{
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(284, 264);
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form);
PropertyDescriptor descriptor = descriptors.Find("Name", false);
descriptor.SetValue(form, "MainForm");
ToolTip toolTip = (ToolTip)host.CreateComponent(typeof(ToolTip), "toolTip1");
string indentString = " ";
PythonControl pythonForm = new PythonControl(indentString);
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
}
}
[Test]
public void GeneratedCode()
{
string expectedCode = "def InitializeComponent(self):\r\n" +
" self._components = System.ComponentModel.Container()\r\n" +
" self._toolTip1 = System.Windows.Forms.ToolTip(self._components)\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);
}
}
}

28
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonCodeBuilderTests.cs

@ -72,5 +72,33 @@ namespace PythonBinding.Tests.Designer @@ -72,5 +72,33 @@ namespace PythonBinding.Tests.Designer
codeBuilder.AppendIndentedLine("abc");
Assert.AreEqual("\tabc\r\n", codeBuilder.ToString());
}
[Test]
public void InitialIndentWhenCodeBuilderCreatedIsZero()
{
Assert.AreEqual(0, codeBuilder.Indent);
}
[Test]
public void IncreaseIndentByOne()
{
codeBuilder.IncreaseIndent();
Assert.AreEqual(1, codeBuilder.Indent);
}
[Test]
public void LengthAfterAddingText()
{
codeBuilder.Append("abc");
Assert.AreEqual(3, codeBuilder.Length);
}
[Test]
public void IndentPassedToConstructor()
{
codeBuilder = new PythonCodeBuilder(2);
codeBuilder.AppendIndented("abc");
Assert.AreEqual("\t\tabc", codeBuilder.ToString());
}
}
}

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

@ -190,6 +190,7 @@ @@ -190,6 +190,7 @@
<Compile Include="Designer\GenerateSimpleFormTestFixture.cs" />
<Compile Include="Designer\GenerateTextBoxFormTestFixture.cs" />
<Compile Include="Designer\GenerateTimerTestFixture.cs" />
<Compile Include="Designer\GenerateToolTipFormTestFixture.cs" />
<Compile Include="Designer\GeneratorMergeFindsInitializeComponentsTestFixture.cs" />
<Compile Include="Designer\GetComponentFromDesignerLoaderTestFixture.cs" />
<Compile Include="Designer\GetInstanceFromDesignerLoaderTestFixture.cs" />

Loading…
Cancel
Save