Browse Source

Added support for icon resources in python forms designer.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4367 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 16 years ago
parent
commit
1ed615860b
  1. 47
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerComponent.cs
  2. 44
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerRootComponent.cs
  3. BIN
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/App.ico
  4. 18
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateFormResourcesTestFixture.cs
  5. 4
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateLocalImageResourceTestFixture.cs
  6. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

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

@ -543,7 +543,7 @@ namespace ICSharpCode.PythonBinding @@ -543,7 +543,7 @@ namespace ICSharpCode.PythonBinding
/// </summary>
public static bool IsResourcePropertyValue(object propertyValue)
{
return propertyValue is Image;
return (propertyValue is Image) || (propertyValue is Icon);
}
/// <summary>
@ -580,12 +580,7 @@ namespace ICSharpCode.PythonBinding @@ -580,12 +580,7 @@ namespace ICSharpCode.PythonBinding
// Add comment if we have added some properties or event handlers.
if (addComment && propertiesBuilder.Length > 0) {
AppendComment(codeBuilder);
}
if (resources.Count > 0) {
InsertCreateResourceManagerLine(codeBuilder);
}
}
codeBuilder.Append(propertiesBuilder.ToString());
}
@ -651,6 +646,20 @@ namespace ICSharpCode.PythonBinding @@ -651,6 +646,20 @@ namespace ICSharpCode.PythonBinding
}
}
/// <summary>
/// Returns true if this component has any properties that are resources.
/// </summary>
public bool HasResources {
get { return resources.Count > 0; }
}
/// <summary>
/// Gets the parent of this component.
/// </summary>
public PythonDesignerComponent Parent {
get { return parent; }
}
protected IComponent Component {
get { return component; }
}
@ -791,28 +800,6 @@ namespace ICSharpCode.PythonBinding @@ -791,28 +800,6 @@ namespace ICSharpCode.PythonBinding
}
reversedCollection.Reverse();
return reversedCollection;
}
void InsertCreateResourceManagerLine(PythonCodeBuilder codeBuilder)
{
StringBuilder line = new StringBuilder();
line.Append("resources = System.Resources.ResourceManager(\"");
line.Append(GetRootComponentRootResourceName());
line.Append("\", System.Reflection.Assembly.GetEntryAssembly())");
codeBuilder.InsertIndentedLine(line.ToString());
}
string GetRootComponentRootResourceName()
{
PythonDesignerComponent component = this;
while (component != null) {
if (component.parent == null) {
PythonDesignerRootComponent rootComponent = component as PythonDesignerRootComponent;
return rootComponent.GetResourceRootName();
}
component = component.parent;
}
return String.Empty;
}
}
}
}

44
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerRootComponent.cs

@ -12,6 +12,7 @@ using System.ComponentModel.Design; @@ -12,6 +12,7 @@ using System.ComponentModel.Design;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Text;
using System.Windows.Forms;
namespace ICSharpCode.PythonBinding
@ -58,6 +59,9 @@ namespace ICSharpCode.PythonBinding @@ -58,6 +59,9 @@ namespace ICSharpCode.PythonBinding
// Add root component
AppendComponentProperties(codeBuilder, false, true);
if (HasAddedResources()) {
InsertCreateResourceManagerLine(codeBuilder);
}
}
/// <summary>
@ -121,5 +125,45 @@ namespace ICSharpCode.PythonBinding @@ -121,5 +125,45 @@ namespace ICSharpCode.PythonBinding
}
return componentName;
}
void InsertCreateResourceManagerLine(PythonCodeBuilder codeBuilder)
{
StringBuilder line = new StringBuilder();
line.Append("resources = System.Resources.ResourceManager(\"");
line.Append(GetRootComponentRootResourceName());
line.Append("\", System.Reflection.Assembly.GetEntryAssembly())");
codeBuilder.InsertIndentedLine(line.ToString());
}
string GetRootComponentRootResourceName()
{
PythonDesignerComponent component = this;
while (component != null) {
if (component.Parent == null) {
PythonDesignerRootComponent rootComponent = component as PythonDesignerRootComponent;
return rootComponent.GetResourceRootName();
}
component = component.Parent;
}
return String.Empty;
}
/// <summary>
/// Returns true if a resource has been added to any of the form components.
/// </summary>
bool HasAddedResources()
{
if (HasResources) {
return true;
}
foreach (PythonDesignerComponent component in GetContainerComponents()) {
if (component.HasResources) {
return true;
}
}
return false;
}
}
}

BIN
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/App.ico

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

18
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateFormResourcesTestFixture.cs

@ -26,6 +26,7 @@ namespace PythonBinding.Tests.Designer @@ -26,6 +26,7 @@ namespace PythonBinding.Tests.Designer
MockComponentCreator componentCreator;
string generatedPythonCode;
Bitmap bitmap;
Icon icon;
[TestFixtureSetUp]
public void SetUpFixture()
@ -48,11 +49,21 @@ namespace PythonBinding.Tests.Designer @@ -48,11 +49,21 @@ namespace PythonBinding.Tests.Designer
bitmap = new Bitmap(10, 10);
form.BackgroundImage = bitmap;
icon = new Icon(typeof(GenerateFormResourceTestFixture), "App.ico");
form.Icon = icon;
PythonControl pythonControl = new PythonControl(" ", componentCreator);
generatedPythonCode = pythonControl.GenerateInitializeComponentMethod(form, "RootNamespace");
}
}
[Test]
public void TearDownFixture()
{
bitmap.Dispose();
icon.Dispose();
}
[Test]
public void GeneratedCode()
{
@ -64,6 +75,7 @@ namespace PythonBinding.Tests.Designer @@ -64,6 +75,7 @@ namespace PythonBinding.Tests.Designer
" # \r\n" +
" self.BackgroundImage = resources.GetObject(\"$this.BackgroundImage\")\r\n" +
" self.ClientSize = System.Drawing.Size(200, 300)\r\n" +
" self.Icon = resources.GetObject(\"$this.Icon\")\r\n" +
" self.Name = \"MainForm\"\r\n" +
" self.ResumeLayout(False)\r\n" +
" self.PerformLayout()\r\n";
@ -76,5 +88,11 @@ namespace PythonBinding.Tests.Designer @@ -76,5 +88,11 @@ namespace PythonBinding.Tests.Designer
{
Assert.IsTrue(Object.ReferenceEquals(bitmap, resourceWriter.GetResource("$this.BackgroundImage")));
}
[Test]
public void IconAddedToResourceWriter()
{
Assert.IsTrue(Object.ReferenceEquals(icon, resourceWriter.GetResource("$this.Icon")));
}
}
}

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

@ -61,6 +61,9 @@ namespace PythonBinding.Tests.Designer @@ -61,6 +61,9 @@ namespace PythonBinding.Tests.Designer
pictureBox.TabIndex = 0;
form.Controls.Add(pictureBox);
// Add bitmap to form.
form.BackgroundImage = new Bitmap(10, 10);
PythonControl pythonControl = new PythonControl(" ", componentCreator);
generatedPythonCode = pythonControl.GenerateInitializeComponentMethod(form, "RootNamespace");
@ -96,6 +99,7 @@ namespace PythonBinding.Tests.Designer @@ -96,6 +99,7 @@ namespace PythonBinding.Tests.Designer
" # \r\n" +
" # MainForm\r\n" +
" # \r\n" +
" self.BackgroundImage = resources.GetObject(\"$this.BackgroundImage\")\r\n" +
" self.ClientSize = System.Drawing.Size(200, 300)\r\n" +
" self.Controls.Add(self._pictureBox1)\r\n" +
" self.Name = \"MainForm\"\r\n" +

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

@ -346,6 +346,7 @@ @@ -346,6 +346,7 @@
<None Include="app.config" />
<Compile Include="Parsing\AddInvalidSourceSpanToErrorSinkTestFixture.cs" />
<Compile Include="Utils\PythonParserHelper.cs" />
<EmbeddedResource Include="Designer\App.ico" />
<None Include="TODO.txt" />
</ItemGroup>
<ItemGroup>

Loading…
Cancel
Save