[Gtk-sharp-list] A simple xsl stylsheet to help glade users
with the required c# code
Timohy Parez
tpsoftware@users.sourceforge.net
Fri, 21 Nov 2003 11:35:29 +0100
--=-HMtmoZR1+q/k0TTMC7gz
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Oh :-)
I'll include it as an attachment.
Timothy.
--=-HMtmoZR1+q/k0TTMC7gz
Content-Disposition: attachment; filename=glade2csharp.xsl
Content-Type: text/xml; name=glade2csharp.xsl; charset=
Content-Transfer-Encoding: 7bit
<?xml version='1.0'?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--
GLADEC#Sheet v1.0.0.0, Copyright Timothy Parez (c) 2003
A xsl stylesheet to generate C# code from glade files.
This program is free software
You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation
Either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY
Without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
TODO: Add support for gnome widgets
-->
<xsl:template match="/">
<b>// GladeApp.cs</b><br/><br/>
<table border="0">
<tr>
<td width="70px"></td>
<td width="70px"></td>
<td width="70px"></td>
<td width="270px"></td>
<td width="270px"></td>
</tr>
<tr>
<td colspan="5">namespace GladeApp</td>
</tr>
<tr>
<td colspan="5">{</td>
</tr>
<tr>
<td></td>
<td colspan="4">using System;</td>
</tr>
<tr>
<td></td>
<td colspan="4">using Gtk;</td>
</tr>
<!-- No Support for Gnome Widgets yet
<tr>
<td></td>
<td colspan="4">using Gnome;</td>
</tr>
-->
<tr>
<td></td>
<td colspan="4">using Glade;</td>
</tr>
<tr>
<td></td>
<td colspan="4">using GtkSharp;</td>
</tr>
<tr>
<td></td>
<td colspan="4"><br/>public class MyApplication<br/>{</td>
</tr>
<tr>
<td/>
<td/>
<td colspan="3">static void Main()</td>
</tr>
<tr>
<td/>
<td/>
<td colspan="3">{</td>
</tr>
<tr>
<td/>
<td/>
<td/>
<td colspan="2">MyApplication MyApp = new MyApplication();
</td>
</tr>
<tr>
<td/>
<td/>
<td colspan="3">}</td>
</tr>
<tr>
<td colspan="5"><br/></td>
</tr>
<!-- Constructor -->
<tr>
<td/>
<td/>
<td colspan="3">public MyApplication()</td>
</tr>
<tr>
<td/>
<td/>
<td colspan="3">{</td>
</tr>
<tr>
<td/>
<td/>
<td/>
<td colspan="2">Application.Init();<br/><br/>
<xsl:for-each select="//widget[@class='GtkWindow']">
<xsl:value-of select="@id"/><xsl:text> </xsl:text>window<xsl:number/><xsl:text> </xsl:text>=<xsl:text> </xsl:text>new<xsl:text> </xsl:text><xsl:value-of select="@id"/>();<br/><br/>
</xsl:for-each>
Application.Run();
</td>
</tr>
<tr>
<td/>
<td/>
<td colspan="3">}</td>
</tr>
<tr>
<td></td>
<td colspan="4">}</td>
</tr>
<tr>
<td colspan="4">}</td>
</tr>
</table>
<br/>
<hr/>
<br/>
<!-- The GTK windows -->
<xsl:for-each select="//widget[@class='GtkWindow']">
<b>// <xsl:value-of select="@id"/>.cs</b><br/>
<table border="0">
<tr>
<td width="70px"></td>
<td width="70px"></td>
<td width="70px"></td>
<td width="270px"></td>
<td width="270px"></td>
</tr>
<tr>
<td colspan="5">namespace GladeApp</td>
</tr>
<tr>
<td colspan="5">{</td>
</tr>
<tr>
<td></td>
<td colspan="4">using System;</td>
</tr>
<tr>
<td></td>
<td colspan="4">using Gtk;</td>
</tr>
<!-- No support for Gnome Widgets yet
<tr>
<td></td>
<td colspan="4">using Gnome;</td>
</tr>
-->
<tr>
<td></td>
<td colspan="4">using Glade;</td>
</tr>
<tr>
<td></td>
<td colspan="4">using GtkSharp;</td>
</tr>
<tr>
<td></td>
<td colspan="4"><br/>public class <xsl:value-of select="@id"/><br/>{</td>
</tr>
<tr>
<td></td>
<td></td>
<td colspan="3">
<xsl:variable name="test-value" select="substring(@class,4,string-length(@class) - 3)"/>
[Glade.Widget]<br/>
<xsl:if test="$test-value='Window'">
Window<xsl:text> </xsl:text>Inner<xsl:value-of select="@id"/>;
</xsl:if>
<xsl:if test="not($test-value='Window')">
<xsl:value-of select="$test-value"/><xsl:text> </xsl:text><xsl:value-of select="@id"/>;
</xsl:if>
<br/><xsl:apply-templates select="child"/>
</td>
</tr>
<!-- Constructor -->
<tr>
<td></td>
<td></td>
<td colspan="3"><br/>public <xsl:value-of select="@id"/>()<br/>{</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td colspan="2">
Glade.XML gxml<xsl:number/> = new Glade.XML("gladeapp.glade","<xsl:value-of select="@id"/>",null);<br/>
gxml<xsl:number/>.Autoconnect(this);
</td>
</tr>
<tr>
<td></td>
<td></td>
<td colspan="3">}</td>
</tr>
<tr>
<td></td>
<td></td>
<td colspan="3"><xsl:apply-templates select=".//signal"/></td>
</tr>
<tr>
<td></td>
<td colspan="3">}</td>
</tr>
<tr>
<td colspan="4">}</td>
</tr>
</table>
<br/>
<hr/>
<br/>
</xsl:for-each>
</xsl:template>
<xsl:template match="child"><xsl:apply-templates select="widget"/></xsl:template>
<xsl:template match="widget"><br/>
[Glade.Widget]<br/>
<xsl:value-of select="substring(@class,4,string-length(@class) - 3)"/><xsl:text> </xsl:text><xsl:value-of select="@id"/>;<br/>
<xsl:apply-templates select="child"/>
</xsl:template>
<xsl:template match="signal">
<br/>public void <xsl:value-of select="@handler"/>(System.Object obj, EventArgs e)<br/>
{<br/><br/>
}<br/>
</xsl:template>
</xsl:stylesheet>
--=-HMtmoZR1+q/k0TTMC7gz--