Browse Source

Extender provider properties set for other controls now appear in properties window in the python form designer.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4137 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 17 years ago
parent
commit
b2c6344367
  1. 5
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/IComponentCreator.cs
  2. 22
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonCodeDeserializer.cs
  3. 4
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonComponentWalker.cs
  4. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlFieldExpression.cs
  5. 7
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerLoader.cs
  6. 50
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadToolTipTestFixture.cs
  7. 4
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/MissingInitializeComponentMethodTestFixture.cs
  8. 13
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonControlFieldExpressionTests.cs
  9. 8
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonDesignerLoaderTestFixture.cs
  10. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj
  11. 11
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockComponentCreator.cs

5
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/IComponentCreator.cs

@ -41,6 +41,11 @@ namespace ICSharpCode.PythonBinding @@ -41,6 +41,11 @@ namespace ICSharpCode.PythonBinding
/// <returns>Null if the component cannot be found.</returns>
IComponent GetComponent(string name);
/// <summary>
/// Gets the RootComponent.
/// </summary>
IComponent RootComponent { get; }
/// <summary>
/// Creates a new instance of the object given its type.
/// </summary>

22
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonCodeDeserializer.cs

@ -36,12 +36,15 @@ namespace ICSharpCode.PythonBinding @@ -36,12 +36,15 @@ namespace ICSharpCode.PythonBinding
ConstantExpression constantExpression = a.Expression as ConstantExpression;
MemberExpression memberExpression = a.Expression as MemberExpression;
CallExpression callExpression = a.Expression as CallExpression;
NameExpression nameExpression = a.Expression as NameExpression;
if (constantExpression != null) {
args.Add(constantExpression.Value);
} else if (memberExpression != null) {
args.Add(Deserialize(memberExpression));
} else if(callExpression != null) {
} else if (callExpression != null) {
args.Add(Deserialize(callExpression));
} else if (nameExpression != null) {
args.Add(Deserialize(nameExpression));
}
}
return args;
@ -71,7 +74,7 @@ namespace ICSharpCode.PythonBinding @@ -71,7 +74,7 @@ namespace ICSharpCode.PythonBinding
}
return null;
}
/// <summary>
/// Deserializes expressions of the form:
///
@ -85,7 +88,7 @@ namespace ICSharpCode.PythonBinding @@ -85,7 +88,7 @@ namespace ICSharpCode.PythonBinding
int value = Convert.ToInt32(lhs) | Convert.ToInt32(rhs);
return Enum.ToObject(lhs.GetType(), value);
}
/// <summary>
/// Deserializes expressions of the form:
///
@ -127,6 +130,19 @@ namespace ICSharpCode.PythonBinding @@ -127,6 +130,19 @@ namespace ICSharpCode.PythonBinding
return componentCreator.GetInstance(PythonControlFieldExpression.GetVariableName(field.MemberName));
}
/// <summary>
/// Deserializes expressions of the form:
///
/// 1) self
/// </summary>
object Deserialize(NameExpression nameExpression)
{
if ("self" == nameExpression.Name.ToString().ToLowerInvariant()) {
return componentCreator.RootComponent;
}
return null;
}
Type GetType(PythonControlFieldExpression field)
{
return componentCreator.GetType(PythonControlFieldExpression.GetPrefix(field.FullMemberName));

4
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonComponentWalker.cs

@ -358,8 +358,8 @@ namespace ICSharpCode.PythonBinding @@ -358,8 +358,8 @@ namespace ICSharpCode.PythonBinding
// Execute the method on the object.
if (member != null) {
object parameter = deserializer.Deserialize(node.Args[0].Expression);
member.GetType().InvokeMember(field.MethodName, BindingFlags.InvokeMethod, Type.DefaultBinder, member, new object[] {parameter});
object[] args = deserializer.GetArguments(node).ToArray();
member.GetType().InvokeMember(field.MethodName, BindingFlags.InvokeMethod, Type.DefaultBinder, member, args);
}
}

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

@ -261,6 +261,8 @@ namespace ICSharpCode.PythonBinding @@ -261,6 +261,8 @@ namespace ICSharpCode.PythonBinding
int endIndex = name.IndexOf('.');
if (endIndex > 0) {
return GetVariableName(name.Substring(0, endIndex));
} else if (name.StartsWith("_")) {
return GetVariableName(name);
}
return String.Empty;
}

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

@ -77,6 +77,13 @@ namespace ICSharpCode.PythonBinding @@ -77,6 +77,13 @@ namespace ICSharpCode.PythonBinding
return component;
}
/// <summary>
/// Gets the root component.
/// </summary>
public IComponent RootComponent {
get { return base.LoaderHost.RootComponent; }
}
/// <summary>
/// Creates a new instance of the specified type.
/// </summary>

50
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadToolTipTestFixture.cs

@ -0,0 +1,50 @@ @@ -0,0 +1,50 @@
// <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.Drawing;
using System.IO;
using System.Windows.Forms;
using ICSharpCode.PythonBinding;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Designer
{
[TestFixture]
public class LoadToolTipTestFixture : LoadFormTestFixtureBase
{
public override string PythonCode {
get {
return "class TestForm(System.Windows.Forms.Form):\r\n" +
" 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._toolTip1.SetToolTip(self, \"test\")\r\n" +
" self.ResumeLayout(False)\r\n" +
" self.PerformLayout()\r\n";
}
}
[Test]
public void FormHasToolTip()
{
ToolTip toolTip = (ToolTip)base.ComponentCreator.GetComponent("toolTip1");
Assert.AreEqual("test",toolTip.GetToolTip(Form));
}
}
}

4
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/MissingInitializeComponentMethodTestFixture.cs

@ -84,6 +84,10 @@ namespace PythonBinding.Tests.Designer @@ -84,6 +84,10 @@ namespace PythonBinding.Tests.Designer
return null;
}
public IComponent RootComponent {
get { return null; }
}
public object CreateInstance(Type type, ICollection arguments, string name, bool addToContainer)
{
throw new NotImplementedException();

13
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonControlFieldExpressionTests.cs

@ -95,7 +95,16 @@ namespace PythonBinding.Tests.Designer @@ -95,7 +95,16 @@ namespace PythonBinding.Tests.Designer
CallExpression expression = PythonParserHelper.GetCallExpression(code);
PythonControlFieldExpression field = PythonControlFieldExpression.Create(expression);
AssertAreEqual(field, String.Empty, "Items", "Add", "self.Items");
}
}
[Test]
public void SetToolTipMethodCall()
{
string code = "self._toolTip1.SetToolTip(self, \"Test\")";
CallExpression expression = PythonParserHelper.GetCallExpression(code);
PythonControlFieldExpression field = PythonControlFieldExpression.Create(expression);
AssertAreEqual(field, "toolTip1", "_toolTip1", "SetToolTip", "self._toolTip1");
}
[Test]
public void GetMemberNames()
@ -182,7 +191,7 @@ namespace PythonBinding.Tests.Designer @@ -182,7 +191,7 @@ namespace PythonBinding.Tests.Designer
{
string expected = "Variable: " + variableName + " Member: " + memberName + " Method: " + methodName + " FullMemberName: " + fullMemberName;
string actual = "Variable: " + field.VariableName + " Member: " + field.MemberName + " Method: " + field.MethodName + " FullMemberName: " + field.FullMemberName;
Assert.AreEqual(expected, actual);
Assert.AreEqual(expected, actual, actual);
}
}
}

8
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonDesignerLoaderTestFixture.cs

@ -67,7 +67,7 @@ namespace PythonBinding.Tests.Designer @@ -67,7 +67,7 @@ namespace PythonBinding.Tests.Designer
designedForm = new Form();
designedForm.Name = "NewMainForm";
mockDesignerLoaderHost.RootComponent = designedForm;
mockDesignerLoaderHost.RootComponent = designedForm;
loader.CallPerformFlush();
}
@ -137,6 +137,12 @@ namespace PythonBinding.Tests.Designer @@ -137,6 +137,12 @@ namespace PythonBinding.Tests.Designer
Assert.AreEqual(expectedProperty, loader.GetEventProperty(e));
}
[Test]
public void GetRootComponentFromLoader()
{
Assert.AreEqual(designedForm, loader.RootComponent);
}
/// <summary>
/// The code that the designer loader will parse.
/// </summary>

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

@ -218,6 +218,7 @@ @@ -218,6 +218,7 @@
<Compile Include="Designer\LoadTextBoxOnPanelTestFixture.cs" />
<Compile Include="Designer\LoadTextBoxTestFixture.cs" />
<Compile Include="Designer\LoadTimerTestFixture.cs" />
<Compile Include="Designer\LoadToolTipTestFixture.cs" />
<Compile Include="Designer\MergeFormTestFixture.cs" />
<Compile Include="Designer\MissingInitializeComponentMethodTestFixture.cs" />
<Compile Include="Designer\NoNewLineAfterInitializeComponentTestFixture.cs" />

11
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockComponentCreator.cs

@ -25,14 +25,23 @@ namespace PythonBinding.Tests.Utils @@ -25,14 +25,23 @@ namespace PythonBinding.Tests.Utils
List<string> typeNames = new List<string>();
PropertyDescriptor propertyDescriptor;
EventDescriptor eventDescriptor;
IComponent rootComponent;
public MockComponentCreator()
{
}
public IComponent RootComponent {
get { return rootComponent; }
}
public IComponent CreateComponent(Type componentClass, string name)
{
object instance = componentClass.Assembly.CreateInstance(componentClass.FullName);
if (rootComponent == null) {
rootComponent = instance as IComponent;
}
CreatedComponent c = new CreatedComponent(componentClass.FullName, name, (IComponent)instance);
createdComponents.Add(c);

Loading…
Cancel
Save