Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4145 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
26 changed files with 363 additions and 208 deletions
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
// <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; |
||||
|
||||
namespace ICSharpCode.PythonBinding |
||||
{ |
||||
public class PythonContextMenuComponent : PythonDesignerComponent |
||||
{ |
||||
public PythonContextMenuComponent(PythonDesignerComponent parent, IComponent component) |
||||
: base(parent, component) |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Always ignore the OwnerItem property. This is set if the context menu is open and displayed in
|
||||
/// the designer when the user switches to the source tab. This method works around the problem by
|
||||
/// ignoring the OwnerItem property when generating the form designer code.
|
||||
/// </summary>
|
||||
protected override bool IgnoreProperty(PropertyDescriptor property) |
||||
{ |
||||
return property.Name == "OwnerItem"; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,105 @@
@@ -0,0 +1,105 @@
|
||||
// <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 GenerateContextMenuStripTestFixture |
||||
{ |
||||
string generatedPythonCode; |
||||
string createContextMenuStripCode; |
||||
Size menuStripSize; |
||||
PythonDesignerComponent contextMenuDesignerComponent; |
||||
|
||||
[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 timer. This checks that the components Container is only created once in the
|
||||
// generated code.
|
||||
Timer timer = (Timer)host.CreateComponent(typeof(Timer), "timer1"); |
||||
|
||||
// Add menu strip.
|
||||
ContextMenuStrip menuStrip = (ContextMenuStrip)host.CreateComponent(typeof(ContextMenuStrip), "contextMenuStrip1"); |
||||
|
||||
// Set the context menu strip OwnerItem to simulate leaving the context menu
|
||||
// open in the designer before generating the source code. We do not want the
|
||||
// OwnerItem to be serialized.
|
||||
menuStrip.OwnerItem = new DerivedToolStripMenuItem(); |
||||
menuStrip.RightToLeft = RightToLeft.No; |
||||
menuStripSize = menuStrip.Size; |
||||
|
||||
PythonControl pythonForm = new PythonControl(" "); |
||||
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); |
||||
|
||||
PythonCodeBuilder codeBuilder = new PythonCodeBuilder(); |
||||
contextMenuDesignerComponent = PythonDesignerComponentFactory.CreateDesignerComponent(menuStrip); |
||||
contextMenuDesignerComponent.AppendCreateInstance(codeBuilder); |
||||
|
||||
createContextMenuStripCode = codeBuilder.ToString(); |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void GeneratedCode() |
||||
{ |
||||
string expectedCode = "def InitializeComponent(self):\r\n" + |
||||
" self._components = System.ComponentModel.Container()\r\n" + |
||||
" self._timer1 = System.Windows.Forms.Timer(self._components)\r\n" + |
||||
" self._contextMenuStrip1 = System.Windows.Forms.ContextMenuStrip(self._components)\r\n" + |
||||
" self.SuspendLayout()\r\n" + |
||||
" # \r\n" + |
||||
" # contextMenuStrip1\r\n" + |
||||
" # \r\n" + |
||||
" self._contextMenuStrip1.Name = \"contextMenuStrip1\"\r\n" + |
||||
" self._contextMenuStrip1.Size = " + PythonPropertyValueAssignment.ToString(menuStripSize) + "\r\n" + |
||||
" # \r\n" + |
||||
" # MainForm\r\n" + |
||||
" # \r\n" + |
||||
" self.ClientSize = System.Drawing.Size(200, 300)\r\n" + |
||||
" self.Name = \"MainForm\"\r\n" + |
||||
" self.ResumeLayout(False)\r\n" + |
||||
" self.PerformLayout()\r\n"; |
||||
|
||||
Assert.AreEqual(expectedCode, generatedPythonCode, generatedPythonCode); |
||||
} |
||||
|
||||
[Test] |
||||
public void CreateContextMenuStripCodeUsesIContainerConstructor() |
||||
{ |
||||
string expectedCode = "self._components = System.ComponentModel.Container()\r\n" + |
||||
"self._contextMenuStrip1 = System.Windows.Forms.ContextMenuStrip(self._components)\r\n"; |
||||
Assert.AreEqual(expectedCode, createContextMenuStripCode); |
||||
} |
||||
|
||||
[Test] |
||||
public void ContextMenuDesignerComponentCreatedFromFactory() |
||||
{ |
||||
Assert.IsInstanceOf(typeof(PythonContextMenuComponent), contextMenuDesignerComponent); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
// <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.Windows.Forms; |
||||
|
||||
namespace PythonBinding.Tests.Utils |
||||
{ |
||||
public class DerivedToolStripMenuItem : ToolStripMenuItem |
||||
{ |
||||
public DerivedToolStripMenuItem() : base() |
||||
{ |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue