Author: danw
Date: 2005-07-08 13:17:14 -0400 (Fri, 08 Jul 2005)
New Revision: 47113
Removed:
trunk/stetic/libstetic/wrapper/ButtonBox.cs
Modified:
trunk/stetic/ChangeLog
trunk/stetic/libstetic/GladeUtils.cs
trunk/stetic/libstetic/Makefile.am
trunk/stetic/libstetic/Registry.cs
trunk/stetic/libstetic/wrapper/Container.cs
trunk/stetic/libstetic/wrapper/Table.cs
trunk/stetic/libstetic/wrapper/objects.xml
trunk/stetic/stetic/Glade.cs
Log:
* libstetic/wrapper/objects.xml: add <glade-transform> nodes with
XSL transformations to fix some oddities in the glade file format.
(GtkHButtonBox): set the "secondary" property on a Help button
child. Use Gtk.Box as a wrapper now, since we don't need a
ButtonBox wrapper any more.
(GtkButtonBox, GtkVButtonBox): use Gtk.Box as a wrapper.
(GtkMenuItem): a menuitem with no label should be a
SeparatorMenuItem.
(GtkTable): fix/break the non-standard "x_options" and "y_options"
(GtkWidget): remove/add the extraneous spaces in "events"
* libstetic/wrapper/ButtonBox.cs: gone
* libstetic/wrapper/Container.cs (GladeImport): Sync() at the end.
* libstetic/wrapper/Table.cs (GladeImportChild, GladeExportChild):
gone, handled by xsl now.
(GladeImport): gone, Container does the Sync() for us now.
* libstetic/GladeUtils.cs (ParseFlags): remove special case for
Widget.Events
* libstetic/Registry.cs: handle the <glade-transform> nodes.
(GladeImportXsl, GladeExportXsl): properties to return
XslTransforms for glade import and export.
* stetic/Glade.cs: use Registry.GladeImportXsl and GladeExportXsl.
Modified: trunk/stetic/ChangeLog
===================================================================
--- trunk/stetic/ChangeLog 2005-07-08 16:45:30 UTC (rev 47112)
+++ trunk/stetic/ChangeLog 2005-07-08 17:17:14 UTC (rev 47113)
@@ -1,5 +1,35 @@
2005-07-08 Dan Winship <[EMAIL PROTECTED]>
+ * libstetic/wrapper/objects.xml: add <glade-transform> nodes with
+ XSL transformations to fix some oddities in the glade file format.
+ (GtkHButtonBox): set the "secondary" property on a Help button
+ child. Use Gtk.Box as a wrapper now, since we don't need a
+ ButtonBox wrapper any more.
+ (GtkButtonBox, GtkVButtonBox): use Gtk.Box as a wrapper.
+ (GtkMenuItem): a menuitem with no label should be a
+ SeparatorMenuItem.
+ (GtkTable): fix/break the non-standard "x_options" and "y_options"
+ (GtkWidget): remove/add the extraneous spaces in "events"
+
+ * libstetic/wrapper/ButtonBox.cs: gone
+
+ * libstetic/wrapper/Container.cs (GladeImport): Sync() at the end.
+
+ * libstetic/wrapper/Table.cs (GladeImportChild, GladeExportChild):
+ gone, handled by xsl now.
+ (GladeImport): gone, Container does the Sync() for us now.
+
+ * libstetic/GladeUtils.cs (ParseFlags): remove special case for
+ Widget.Events
+
+ * libstetic/Registry.cs: handle the <glade-transform> nodes.
+ (GladeImportXsl, GladeExportXsl): properties to return
+ XslTransforms for glade import and export.
+
+ * stetic/Glade.cs: use Registry.GladeImportXsl and GladeExportXsl.
+
+2005-07-08 Dan Winship <[EMAIL PROTECTED]>
+
Rework the glade import/export framework to pass XmlElements
directly to the wrapper import/export methods, rather than trying
to parse out the "relevant" parts into Hashtables, etc. This makes
Modified: trunk/stetic/libstetic/GladeUtils.cs
===================================================================
--- trunk/stetic/libstetic/GladeUtils.cs 2005-07-08 16:45:30 UTC (rev
47112)
+++ trunk/stetic/libstetic/GladeUtils.cs 2005-07-08 17:17:14 UTC (rev
47113)
@@ -106,11 +106,10 @@
uint fval = 0;
try {
- // The Trim() is needed for Widget.Events.
foreach (string flag in strval.Split ('|')) {
if (flag == "")
continue;
- IntPtr flags_value =
g_flags_get_value_by_name (flags_class, flag.Trim ());
+ IntPtr flags_value =
g_flags_get_value_by_name (flags_class, flag);
if (flags_value == IntPtr.Zero)
throw new GladeException
("Could not parse");
Modified: trunk/stetic/libstetic/Makefile.am
===================================================================
--- trunk/stetic/libstetic/Makefile.am 2005-07-08 16:45:30 UTC (rev 47112)
+++ trunk/stetic/libstetic/Makefile.am 2005-07-08 17:17:14 UTC (rev 47113)
@@ -39,7 +39,6 @@
wrapper/Bin.cs \
wrapper/Box.cs \
wrapper/Button.cs \
- wrapper/ButtonBox.cs \
wrapper/CheckButton.cs \
wrapper/ColorButton.cs \
wrapper/ComboBox.cs \
Modified: trunk/stetic/libstetic/Registry.cs
===================================================================
--- trunk/stetic/libstetic/Registry.cs 2005-07-08 16:45:30 UTC (rev 47112)
+++ trunk/stetic/libstetic/Registry.cs 2005-07-08 17:17:14 UTC (rev 47113)
@@ -1,8 +1,8 @@
using System;
using System.Collections;
using System.Reflection;
-using System.Runtime.InteropServices;
using System.Xml;
+using System.Xml.Xsl;
namespace Stetic {
public static class Registry {
@@ -11,6 +11,8 @@
static Hashtable classes_by_cname = new Hashtable ();
static Hashtable classes_by_csname = new Hashtable ();
+ static XslTransform gladeImport, gladeExport;
+
static Registry ()
{
Assembly libstetic = Assembly.GetExecutingAssembly ();
@@ -25,14 +27,56 @@
classes_by_cname[klass.CName] = klass;
classes_by_csname[klass.WrappedType.FullName] =
klass;
}
+
+ XmlDocument doc = CreateGladeTransformBase ();
+ XmlNamespaceManager nsm = new XmlNamespaceManager
(doc.NameTable);
+ nsm.AddNamespace ("xsl",
"http://www.w3.org/1999/XSL/Transform");
+
+ foreach (XmlElement elem in objects.SelectNodes
("/objects/object/glade-transform/import/xsl:*", nsm))
+ doc.FirstChild.PrependChild (doc.ImportNode
(elem, true));
+ gladeImport = new XslTransform ();
+ gladeImport.Load (doc, null, null);
+
+ doc = CreateGladeTransformBase ();
+ foreach (XmlElement elem in objects.SelectNodes
("/objects/object/glade-transform/export/xsl:*", nsm))
+ doc.FirstChild.PrependChild (doc.ImportNode
(elem, true));
+ gladeExport = new XslTransform ();
+ gladeExport.Load (doc, null, null);
}
+ static XmlDocument CreateGladeTransformBase ()
+ {
+ XmlDocument doc = new XmlDocument ();
+ doc.LoadXml (
+ "<xsl:stylesheet version='1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>" +
+ " <xsl:template match='@*|node()'>" +
+ " <xsl:copy>" +
+ " <xsl:apply-templates select='@*|node()'
/>" +
+ " </xsl:copy>" +
+ " </xsl:template>" +
+ "</xsl:stylesheet>"
+ );
+ return doc;
+ }
+
public static IEnumerable AllClasses {
get {
return classes_by_type.Values;
}
}
+ public static XslTransform GladeImportXsl {
+ get {
+ return gladeImport;
+ }
+ }
+
+ public static XslTransform GladeExportXsl {
+ get {
+ return gladeExport;
+ }
+ }
+
public static ClassDescriptor LookupClass (Type type)
{
return (ClassDescriptor)classes_by_type[type];
Deleted: trunk/stetic/libstetic/wrapper/ButtonBox.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/ButtonBox.cs 2005-07-08 16:45:30 UTC (rev
47112)
+++ trunk/stetic/libstetic/wrapper/ButtonBox.cs 2005-07-08 17:17:14 UTC (rev
47113)
@@ -1,20 +0,0 @@
-using System;
-using System.Xml;
-
-namespace Stetic.Wrapper {
-
- public class ButtonBox : Box {
-
- public override Widget GladeImportChild (XmlElement child_elem)
- {
- Widget wrapper = base.GladeImportChild (child_elem);
- Button button = wrapper as Stetic.Wrapper.Button;
- if (button != null && button.ResponseId ==
(int)Gtk.ResponseType.Help) {
- Gtk.ButtonBox.ButtonBoxChild bbc =
((Gtk.Container)Wrapped)[((Gtk.Widget)wrapper.Wrapped)] as
Gtk.ButtonBox.ButtonBoxChild;
- bbc.Secondary = true;
- }
-
- return wrapper;
- }
- }
-}
Modified: trunk/stetic/libstetic/wrapper/Container.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/Container.cs 2005-07-08 16:45:30 UTC (rev
47112)
+++ trunk/stetic/libstetic/wrapper/Container.cs 2005-07-08 17:17:14 UTC (rev
47113)
@@ -67,6 +67,8 @@
Console.Error.WriteLine (ge.Message);
}
}
+
+ Sync ();
}
public virtual Widget GladeImportChild (XmlElement child_elem)
Modified: trunk/stetic/libstetic/wrapper/Table.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/Table.cs 2005-07-08 16:45:30 UTC (rev
47112)
+++ trunk/stetic/libstetic/wrapper/Table.cs 2005-07-08 17:17:14 UTC (rev
47113)
@@ -21,38 +21,6 @@
Sync ();
}
- public override void GladeImport (XmlElement elem)
- {
- base.GladeImport (elem);
- Sync ();
- }
-
- public override Widget GladeImportChild (XmlElement child_elem)
- {
- string opts = (string)GladeUtils.ExtractChildProperty
(child_elem, "x_options", "expand|fill");
- GladeUtils.SetChildProperty (child_elem, "x_options",
Regex.Replace (opts.ToUpper (), @"(?<!\w)(\w)", "GTK_$1"));
-
- opts = (string)GladeUtils.ExtractChildProperty
(child_elem, "y_options", "expand|fill");
- GladeUtils.SetChildProperty (child_elem, "y_options",
Regex.Replace (opts.ToUpper (), @"(?<!\w)(\w)", "GTK_$1"));
-
- return base.GladeImportChild (child_elem);
- }
-
- public override XmlElement GladeExportChild (Widget wrapper,
XmlDocument doc)
- {
- XmlElement child_elem = base.GladeExportChild (wrapper,
doc);
-
- string opts = (string)GladeUtils.ExtractChildProperty
(child_elem, "x_options", "");
- if (opts != "")
- GladeUtils.SetChildProperty (child_elem,
"x_options", Regex.Replace (opts.ToLower (), "gtk_", ""));
-
- opts = (string)GladeUtils.ExtractChildProperty
(child_elem, "y_options", "");
- if (opts != "")
- GladeUtils.SetChildProperty (child_elem,
"y_options", Regex.Replace (opts.ToLower (), "gtk_", ""));
-
- return child_elem;
- }
-
private Gtk.Table table {
get {
return (Gtk.Table)Wrapped;
Modified: trunk/stetic/libstetic/wrapper/objects.xml
===================================================================
--- trunk/stetic/libstetic/wrapper/objects.xml 2005-07-08 16:45:30 UTC (rev
47112)
+++ trunk/stetic/libstetic/wrapper/objects.xml 2005-07-08 17:17:14 UTC (rev
47113)
@@ -1,4 +1,5 @@
-<objects>
+<?xml version="1.0" encoding="utf-8" ?>
+<objects xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<object type="Gtk.Widget,gtk-sharp" wrapper="Stetic.Wrapper.Widget">
<internal-properties>
@@ -18,6 +19,54 @@
<property name="ExtensionEvents" />
</itemgroup>
</itemgroups>
+
+ <glade-transform>
+ <!-- "events" property has extra spaces around "|"s -->
+ <import>
+ <xsl:template match="widget/[EMAIL PROTECTED]'events']/text()">
+ <xsl:call-template name="GtkWidget_fixevents">
+ <xsl:with-param name="string" select="." />
+ </xsl:call-template>
+ </xsl:template>
+ <xsl:template name="GtkWidget_fixevents">
+ <xsl:param name="string"/>
+ <xsl:choose>
+ <xsl:when test="contains($string, ' | ')">
+ <xsl:value-of select="substring-before($string, ' |
')"/>
+ <xsl:text>|</xsl:text>
+ <xsl:call-template name="GtkWidget_fixevents">
+ <xsl:with-param name="string"
select="substring-after($string, ' | ')"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$string" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+ </import>
+ <export>
+ <xsl:template match="widget/[EMAIL PROTECTED]'events']/text()">
+ <xsl:call-template name="GtkWidget_breakevents">
+ <xsl:with-param name="string" select="." />
+ </xsl:call-template>
+ </xsl:template>
+ <xsl:template name="GtkWidget_breakevents">
+ <xsl:param name="string"/>
+ <xsl:choose>
+ <xsl:when test="contains($string, '|')">
+ <xsl:value-of select="substring-before($string,
'|')"/>
+ <xsl:text> | </xsl:text>
+ <xsl:call-template name="GtkWidget_breakevents">
+ <xsl:with-param name="string"
select="substring-after($string, '|')"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$string" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+ </export>
+ </glade-transform>
</object>
<object type="Gtk.Container,gtk-sharp" wrapper="Stetic.Wrapper.Container"
/>
@@ -187,7 +236,7 @@
</itemgroups>
</object>
- <object type="Gtk.ButtonBox,gtk-sharp" wrapper="Stetic.Wrapper.ButtonBox">
+ <object type="Gtk.ButtonBox,gtk-sharp" wrapper="Stetic.Wrapper.Box">
<itemgroups>
<itemgroup label="Button Box Properties">
<property name="LayoutStyle" />
@@ -336,6 +385,27 @@
</itemgroup>
<itemgroup ref="Gtk.Widget" />
</itemgroups>
+
+ <glade-transform>
+ <!-- A regular MenuItem with no label is really a SeparatorMenuItem
-->
+ <import>
+ <xsl:template match="[EMAIL PROTECTED]'GtkMenuItem']">
+ <xsl:choose>
+ <xsl:when test="not([EMAIL PROTECTED]'label']) and
not([EMAIL PROTECTED]'stock_item'])">
+ <widget class="GtkSeparatorMenuItem">
+ <xsl:attribute name="id"><xsl:value-of
select="@id" /></xsl:attribute>
+ <xsl:apply-templates select="node()" />
+ </widget>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:copy>
+ <xsl:apply-templates select="@*|node()" />
+ </xsl:copy>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+ </import>
+ </glade-transform>
</object>
<object type="Gtk.CheckMenuItem,gtk-sharp"
wrapper="Stetic.Wrapper.MenuItem"
@@ -521,7 +591,7 @@
<contextmenu ref="Gtk.Box" />
</object>
- <object type="Gtk.HButtonBox,gtk-sharp" wrapper="Stetic.Wrapper.ButtonBox"
+ <object type="Gtk.HButtonBox,gtk-sharp" wrapper="Stetic.Wrapper.Box"
label="HButtonBox" icon="hbuttonbox.png"
palette-category="container"
hexpandable="true">
<itemgroups>
@@ -529,6 +599,22 @@
<itemgroup ref="Gtk.Widget" />
</itemgroups>
<contextmenu ref="Gtk.Box" />
+
+ <glade-transform>
+ <!-- If a child has a "response_id" of -11 (GTK_RESPONSE_HELP), it
should be packed with the "secondary" property -->
+ <import>
+ <xsl:template match="[EMAIL
PROTECTED]'GtkHButtonBox']/child/[EMAIL PROTECTED]'GtkButton']">
+ <xsl:copy>
+ <xsl:apply-templates select="@*|node()"/>
+ </xsl:copy>
+ <xsl:if test="number ([EMAIL PROTECTED]'response_id']) =
-11">
+ <packing>
+ <property name="secondary">True</property>
+ </packing>
+ </xsl:if>
+ </xsl:template>
+ </import>
+ </glade-transform>
</object>
<object type="Gtk.HPaned,gtk-sharp" wrapper="Stetic.Wrapper.Paned"
@@ -883,6 +969,59 @@
<command name="DeleteColumn" label="Delete Column"
description="Delete the selected column" />
</contextmenu>
+
+ <glade-transform>
+ <!-- Child packing options are non-standard ("expand" instead of
"GTK_EXPAND") -->
+ <import>
+ <xsl:template match="[EMAIL
PROTECTED]'GtkTable']/child/packing/[EMAIL PROTECTED]'x_options' or
@name='y_options']/text()">
+ <xsl:call-template name="GtkTable_fixoptions">
+ <xsl:with-param name="string" select="." />
+ </xsl:call-template>
+ </xsl:template>
+ <xsl:template name="GtkTable_fixoptions">
+ <xsl:param name="string"/>
+ <xsl:choose>
+ <xsl:when test="contains($string, '|')">
+ <xsl:call-template name="GtkTable_fixoptions">
+ <xsl:with-param name="string"
select="substring-before($string, '|')"/>
+ </xsl:call-template>
+ <xsl:text>|</xsl:text>
+ <xsl:call-template name="GtkTable_fixoptions">
+ <xsl:with-param name="string"
select="substring-after($string, '|')"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>GTK_</xsl:text>
+ <xsl:value-of
select="translate($string,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+ </import>
+ <export>
+ <xsl:template match="[EMAIL
PROTECTED]'GtkTable']/child/packing/[EMAIL PROTECTED]'x_options' or
@name='y_options']/text()">
+ <xsl:call-template name="GtkTable_breakoptions">
+ <xsl:with-param name="options" select="." />
+ </xsl:call-template>
+ </xsl:template>
+ <xsl:template name="GtkTable_breakoptions">
+ <xsl:param name="string"/>
+ <xsl:choose>
+ <xsl:when test="contains($string, '|')">
+ <xsl:call-template name="GtkTable_breakoptions">
+ <xsl:with-param name="string"
select="substring-before($string, '|')"/>
+ </xsl:call-template>
+ <xsl:text>|</xsl:text>
+ <xsl:call-template name="GtkTable_breakoptions">
+ <xsl:with-param name="string"
select="substring-after($string, '|')"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of
select="translate(substring-after($string,
'GTK_'),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+ </export>
+ </glade-transform>
</object>
<object type="Gtk.Table+TableChild,gtk-sharp"
wrapper="Stetic.Wrapper.Table+TableChild">
<internal-properties>
@@ -1052,7 +1191,7 @@
<contextmenu ref="Gtk.Box" />
</object>
- <object type="Gtk.VButtonBox,gtk-sharp" wrapper="Stetic.Wrapper.ButtonBox"
+ <object type="Gtk.VButtonBox,gtk-sharp" wrapper="Stetic.Wrapper.Box"
label="VButtonBox" icon="vbuttonbox.png"
palette-category="container"
vexpandable="true">
<itemgroups>
Modified: trunk/stetic/stetic/Glade.cs
===================================================================
--- trunk/stetic/stetic/Glade.cs 2005-07-08 16:45:30 UTC (rev 47112)
+++ trunk/stetic/stetic/Glade.cs 2005-07-08 17:17:14 UTC (rev 47113)
@@ -24,9 +24,11 @@
doctype.SystemId != Glade20SystemId)
throw new ApplicationException ("Not a glade
file according to doctype");
- XmlNode node;
+ XmlReader reader = Registry.GladeImportXsl.Transform
(doc, null, (XmlResolver)null);
+ doc = new XmlDocument ();
+ doc.Load (reader);
- node = doc.SelectSingleNode ("/glade-interface");
+ XmlNode node = doc.SelectSingleNode
("/glade-interface");
if (node == null)
throw new ApplicationException ("Not a glade
file according to node name");
@@ -63,7 +65,7 @@
// FIXME; if you use UTF8, it starts with a BOM???
XmlTextWriter writer = new XmlTextWriter (filename,
System.Text.Encoding.ASCII);
writer.Formatting = Formatting.Indented;
- doc.Save (writer);
+ Registry.GladeExportXsl.Transform (doc, null, writer,
null);
writer.Close ();
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches