Browse Source

Python forms designer now generates a multline string for the RichTextBox.Text property.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4624 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 16 years ago
parent
commit
e66da5b9ad
  1. 7
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonPropertyValueAssignment.cs
  2. 84
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateRichTextBoxTestFixture.cs
  3. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

7
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonPropertyValueAssignment.cs

@ -80,10 +80,15 @@ namespace ICSharpCode.PythonBinding @@ -80,10 +80,15 @@ namespace ICSharpCode.PythonBinding
/// <summary>
/// Returns the string enclosed by double quotes.
/// Escapes any double quotes or backslashes in the string itself.
/// If the string is multline triple quotes used.
/// </summary>
static string GetQuotedString(string text)
{
return "\"" + text.Replace(@"\", @"\\").Replace("\"", "\\\"") + "\"";
string quotes = "\"";
if (text.Contains("\n")) {
quotes = "\"\"\"";
}
return quotes + text.Replace(@"\", @"\\").Replace("\"", "\\\"") + quotes;
}
/// <summary>

84
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateRichTextBoxTestFixture.cs

@ -0,0 +1,84 @@ @@ -0,0 +1,84 @@
// <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
{
/// <summary>
/// Tests that multiline text is correctly generated for the RichTextBox.
/// </summary>
[TestFixture]
public class GenerateRichTextBoxTestFixture
{
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");
RichTextBox textBox = (RichTextBox)host.CreateComponent(typeof(RichTextBox), "richTextBox1");
textBox.Size = new Size(110, 20);
textBox.TabIndex = 1;
textBox.Location = new Point(10, 10);
textBox.Text = "abc\r\n" +
"def\r\n" +
"ghi\r\n";
form.Controls.Add(textBox);
string indentString = " ";
PythonControl pythonForm = new PythonControl(indentString);
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
}
}
[Test]
public void GeneratedCode()
{
string expectedCode = "def InitializeComponent(self):\r\n" +
" self._richTextBox1 = System.Windows.Forms.RichTextBox()\r\n" +
" self.SuspendLayout()\r\n" +
" # \r\n" +
" # richTextBox1\r\n" +
" # \r\n" +
" self._richTextBox1.Location = System.Drawing.Point(10, 10)\r\n" +
" self._richTextBox1.Name = \"richTextBox1\"\r\n" +
" self._richTextBox1.Size = System.Drawing.Size(110, 20)\r\n" +
" self._richTextBox1.TabIndex = 1\r\n" +
" self._richTextBox1.Text = \"\"\"abc\n" +
"def\n" +
"ghi\n" +
"\"\"\"\r\n" +
" # \r\n" +
" # MainForm\r\n" +
" # \r\n" +
" self.ClientSize = System.Drawing.Size(284, 264)\r\n" +
" self.Controls.Add(self._richTextBox1)\r\n" +
" self.Name = \"MainForm\"\r\n" +
" self.ResumeLayout(False)\r\n" +
" self.PerformLayout()\r\n";
Assert.AreEqual(expectedCode, generatedPythonCode);
}
}
}

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

@ -213,6 +213,7 @@ @@ -213,6 +213,7 @@
<Compile Include="Designer\GenerateMonthCalendarTestFixture.cs" />
<Compile Include="Designer\GenerateNestedPanelFormTestFixture.cs" />
<Compile Include="Designer\GeneratePanelFormTestFixture.cs" />
<Compile Include="Designer\GenerateRichTextBoxTestFixture.cs" />
<Compile Include="Designer\GenerateRightToLeftFormTestFixture.cs" />
<Compile Include="Designer\GenerateSimpleFormTestFixture.cs" />
<Compile Include="Designer\GenerateTextBoxFormTestFixture.cs" />

Loading…
Cancel
Save