diff --git a/ChangeLog b/ChangeLog index ed97c2aa2..7b826c9ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2002-09-15 Ricardo Fernández Pascual + + * glade/XML.custom: Added a constructor to read the glade file + from a stream and to read it from a resource in an assembly. + * sample/Makefile.in + * sample/GladeTest.cs: Embed the glade file as a resource and use + the new constructor. + 2002-09-13 Ricardo Fernández Pascual * glade/HandlerNotFoundExeception.cs: Added. diff --git a/glade/XML.custom b/glade/XML.custom index ada4536d8..a8857a72f 100644 --- a/glade/XML.custom +++ b/glade/XML.custom @@ -45,6 +45,41 @@ return ret; } + /* a constructor that reads the XML from a Stream */ + + [DllImport("glade-2.0")] + static extern IntPtr glade_xml_new_from_buffer(byte[] buffer, int size, string root, string domain); + + /// Creates a Glade.XML object from a Stream + /// Reads the contents of the stream and parses it. It must be in + /// correct Glade format + public XML (System.IO.Stream s, string root, string domain) + { + int size = (int) s.Length; + byte[] buffer = new byte[size]; + s.Read (buffer, 0, size); + Raw = glade_xml_new_from_buffer(buffer, size, root, domain); + } + + /// Creates a Glade.XML object from a resource + /// Reads the contents of the resource in the + /// given assembly and parses it. If the assembly is null, + /// the current assembly will be used. It must be in + /// correct Glade format + public XML (System.Reflection.Assembly assembly, string resource_name, string root, string domain) + { + if (assembly == null) + { + assembly = System.Reflection.Assembly.GetCallingAssembly (); + } + System.IO.Stream s = assembly.GetManifestResourceStream (resource_name); + int size = (int) s.Length; + byte[] buffer = new byte[size]; + s.Read (buffer, 0, size); + s.Close (); + Raw = glade_xml_new_from_buffer(buffer, size, root, domain); + } + /* signal autoconnection using reflection */ /// Automatically connect signals diff --git a/sample/GladeTest.cs b/sample/GladeTest.cs index 19c78eae5..7b21e5795 100644 --- a/sample/GladeTest.cs +++ b/sample/GladeTest.cs @@ -11,6 +11,8 @@ namespace GladeSamples { using Gnome; using Glade; using GtkSharp; + using System.IO; + using System.Reflection; public class GladeTest : Program { @@ -21,9 +23,12 @@ namespace GladeSamples { public GladeTest (string[] args, params object[] props) : base ("GladeTest", "0.1", Modules.UI, args, props) { - Glade.XML gxml = new Glade.XML ("test.glade", "main_window", null); + /* Note that we load the XML info from the assembly instead of using + an external file. You don't have to distribute the .glade file if + you don't want */ + Glade.XML gxml = new Glade.XML (null, "test.glade", "main_window", null); gxml.Autoconnect (this); - } + } public void OnWindowDeleteEvent (object o, DeleteEventArgs args) { diff --git a/sample/Makefile.in b/sample/Makefile.in index a020543ea..28f5c8f10 100755 --- a/sample/Makefile.in +++ b/sample/Makefile.in @@ -50,8 +50,8 @@ treeviewdemo.exe: TreeViewDemo.cs glade-viewer.exe: GladeViewer.cs $(MCS) --unsafe -o glade-viewer.exe $(local_paths) $(all_assemblies) GladeViewer.cs -glade-test.exe: GladeTest.cs - $(MCS) --unsafe -o glade-test.exe $(local_paths) $(all_assemblies) GladeTest.cs +glade-test.exe: GladeTest.cs test.glade + $(MCS) --unsafe -resource:test.glade -o glade-test.exe $(local_paths) $(all_assemblies) GladeTest.cs clean: rm -f *.exe