2002-09-15 Ricardo Fernndez Pascual <ric@users.sourceforge.net>

* 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.

svn path=/trunk/gtk-sharp/; revision=7482
This commit is contained in:
Ricardo Fernández Pascual 2002-09-15 19:40:46 +00:00
parent f1011f687e
commit 0998fd871a
4 changed files with 52 additions and 4 deletions

View file

@ -1,3 +1,11 @@
2002-09-15 Ricardo Fern<72>ndez Pascual <ric@users.sourceforge.net>
* 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<72>ndez Pascual <ric@users.sourceforge.net>
* glade/HandlerNotFoundExeception.cs: Added.

View file

@ -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);
/// <summary>Creates a Glade.XML object from a Stream</sumary>
/// <remarks>Reads the contents of the stream and parses it. It must be in
/// correct Glade format</remarks>
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);
}
/// <summary>Creates a Glade.XML object from a resource</sumary>
/// <remarks>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</remarks>
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 */
/// <summary>Automatically connect signals</summary>

View file

@ -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)
{

View file

@ -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