Browse Source

Added support for list view groups in Python forms designer.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4595 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 17 years ago
parent
commit
f793b3715f
  1. 23
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonListViewComponent.cs
  2. 108
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateListViewGroupsTestFixture.cs
  3. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

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

@ -37,6 +37,13 @@ namespace ICSharpCode.PythonBinding @@ -37,6 +37,13 @@ namespace ICSharpCode.PythonBinding
++count;
}
// Append list view group creation.
count = 1;
foreach (ListViewGroup group in GetListViewGroups(Component)) {
AppendCreateInstance(codeBuilder, group, count, new object[0]);
++count;
}
// Append list view creation.
base.AppendCreateInstance(codeBuilder);
}
@ -48,6 +55,7 @@ namespace ICSharpCode.PythonBinding @@ -48,6 +55,7 @@ namespace ICSharpCode.PythonBinding
{
AppendComment(codeBuilder);
AppendListViewItemProperties(codeBuilder);
AppendListViewGroupProperties(codeBuilder);
AppendComponentProperties(codeBuilder, true, false);
}
@ -104,6 +112,12 @@ namespace ICSharpCode.PythonBinding @@ -104,6 +112,12 @@ namespace ICSharpCode.PythonBinding
ListView listView = (ListView)component;
return listView.Items;
}
static ListViewGroupCollection GetListViewGroups(IComponent component)
{
ListView listView = (ListView)component;
return listView.Groups;
}
void AppendListViewItemProperties(PythonCodeBuilder codeBuilder)
{
@ -113,5 +127,14 @@ namespace ICSharpCode.PythonBinding @@ -113,5 +127,14 @@ namespace ICSharpCode.PythonBinding
++count;
}
}
void AppendListViewGroupProperties(PythonCodeBuilder codeBuilder)
{
int count = 1;
foreach (ListViewGroup item in GetListViewGroups(Component)) {
AppendObjectProperties(codeBuilder, item, count);
++count;
}
}
}
}

108
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateListViewGroupsTestFixture.cs

@ -0,0 +1,108 @@ @@ -0,0 +1,108 @@
// <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.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Drawing;
using System.Windows.Forms;
using ICSharpCode.PythonBinding;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Designer
{
[TestFixture]
public class GenerateListViewGroupsTestFixture
{
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(200, 300);
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form);
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
namePropertyDescriptor.SetValue(form, "MainForm");
// Add list view.
ListView listView = (ListView)host.CreateComponent(typeof(ListView), "listView1");
listView.TabIndex = 0;
listView.Location = new Point(0, 0);
listView.ClientSize = new Size(200, 100);
descriptors = TypeDescriptor.GetProperties(listView);
PropertyDescriptor descriptor = descriptors.Find("UseCompatibleStateImageBehavior", false);
descriptor.SetValue(listView, true);
descriptor = descriptors.Find("View", false);
descriptor.SetValue(listView, View.Details);
form.Controls.Add(listView);
// Add groups.
ListViewGroup group1 = new ListViewGroup();
group1.Header = "ListViewGroup";
group1.HeaderAlignment = HorizontalAlignment.Right;
group1.Name = "defaultGroup";
group1.Tag = "tag1";
listView.Groups.Add(group1);
ListViewGroup group2 = new ListViewGroup();
group2.Header = "ListViewGroup";
group2.HeaderAlignment = HorizontalAlignment.Center;
group2.Name = "listViewGroup2";
listView.Groups.Add(group2);
PythonControl pythonForm = new PythonControl(" ");
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
}
}
[Test]
public void GeneratedCode()
{
string expectedCode = "def InitializeComponent(self):\r\n" +
" listViewGroup1 = System.Windows.Forms.ListViewGroup()\r\n" +
" listViewGroup2 = System.Windows.Forms.ListViewGroup()\r\n" +
" self._listView1 = System.Windows.Forms.ListView()\r\n" +
" self.SuspendLayout()\r\n" +
" # \r\n" +
" # listView1\r\n" +
" # \r\n" +
" listViewGroup1.Header = \"ListViewGroup\"\r\n" +
" listViewGroup1.HeaderAlignment = System.Windows.Forms.HorizontalAlignment.Right\r\n" +
" listViewGroup1.Name = \"defaultGroup\"\r\n" +
" listViewGroup1.Tag = \"tag1\"\r\n" +
" listViewGroup2.Header = \"ListViewGroup\"\r\n" +
" listViewGroup2.HeaderAlignment = System.Windows.Forms.HorizontalAlignment.Center\r\n" +
" listViewGroup2.Name = \"listViewGroup2\"\r\n" +
" self._listView1.Groups.AddRange(System.Array[System.Windows.Forms.ListViewGroup](\r\n" +
" [listViewGroup1,\r\n" +
" listViewGroup2]))\r\n" +
" self._listView1.Location = System.Drawing.Point(0, 0)\r\n" +
" self._listView1.Name = \"listView1\"\r\n" +
" self._listView1.Size = System.Drawing.Size(204, 104)\r\n" +
" self._listView1.TabIndex = 0\r\n" +
" self._listView1.View = System.Windows.Forms.View.Details\r\n" +
" # \r\n" +
" # MainForm\r\n" +
" # \r\n" +
" self.ClientSize = System.Drawing.Size(200, 300)\r\n" +
" self.Controls.Add(self._listView1)\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

@ -201,6 +201,7 @@ @@ -201,6 +201,7 @@
<Compile Include="Designer\GenerateInheritedFormTestFixture.cs" />
<Compile Include="Designer\GenerateInheritedProtectedPanelFormTestFixture.cs" />
<Compile Include="Designer\GenerateInheritedToolTipTestFixture.cs" />
<Compile Include="Designer\GenerateListViewGroupsTestFixture.cs" />
<Compile Include="Designer\GenerateListViewItemTestFixture.cs" />
<Compile Include="Designer\GenerateListViewSubItemsTestFixture.cs" />
<Compile Include="Designer\GenerateListViewWithImageListTestFixture.cs" />

Loading…
Cancel
Save