[MonoDevelop] Improvement on the Glade# 2.0 auto generated app
Victor Rafael Rivarola Soerensen (FANATICO y LOCO por Cristo)
vrrivaro at gmail.com
Sat Mar 4 10:52:36 EST 2006
Not having even the faintiest idea on where to make the editions on
SVN (and after I spent a good part of the day trying to figure it
out), I decided to send you the modified file instead of a patch.
Main.cs is the main file. It contains my proposed modifications like
they should appear in the built solution.
Test.cs is the name of a slightly modified Main.cs that contains a test case.
Finally, gui.glade is the glade file that corresponds to the test case.
You could create a new Glade# 2.0 solution (it might work with Glade#
solution to, but I haven't tested it). Then, replace its Main.cs with
Test.cs and its gui.glade with the one I provided (but save the
original), compile and run the solution. Click on the button, and an
ArithmeticException will be thrown (by "throw new
ArithmeticException();"). The program will then pop up a MessageBox
with the exception's type, its message and stack trace. Once the
dialog gets closed, the three pieces of data will be echoed on the
screen and thee app will terminate.
Just for fun, remove the OnButton1Clicked handler and see what happens.
Now, replace Main.cs with the one I provided, and the gui.glade with
your saved copy and you are ready to start coding your own app. Now,
every unhandled exception will pop up a dialog box on the screen just
before terminating the app. Very handy, specially if you started the
app by clicking on a menu or desktop icon. No more apps that
misteriously disappear from your screen! At least, you get an error
message now.
Please tell me if you like it, I can then modify the other project
types so they will behave like this. If you do like it, please tell me
where the templates are on SVN. I would love to hear how my error
message could be improved.
By the waya, some formatting got lost to Gmail. Paron me for not
sending the files as attachments. I did ar first, but the some VDS
(Virosic Defense System) bounced it back to me.
Jesus bless you,
Víctor Rivarola
// =======================================================================
// Main.cs
// =======================================================================
using System;
using Gtk;
using Glade;
public class GladeApp
{
private static Window window;
private static GladeApp singleton;
public static GladeApp Singleton
{
get
{
return singleton;
}
set
{
if (singleton == null)
{
singleton = value;
}
}
}
public static void Main (string[] args)
{
try
{
Singleton = new GladeApp (args);
}
catch (Exception e)
{
if (window != null)
{
window.Hide();
}
string ErrorText = e.GetType() + "\n"
+ e.Message + "\n\n"
+ e.StackTrace;
string markup = ErrorText;
markup = markup.Replace("<","<");
markup = markup.Replace(">",">");
MessageDialog error = new MessageDialog(null,
DialogFlags.DestroyWithParent,
MessageType.Error,
ButtonsType.Close,
markup);
int err = error.Run();
error.Dispose();
System.Console.WriteLine(ErrorText);
}
}
public GladeApp (string[] args)
{
Application.Init ();
Glade.XML gxml = new Glade.XML (null, "gui.glade", "window1", null);
gxml.Autoconnect (this);
Application.Run ();
}
// Connect the Signals defined in Glade
private void OnWindowDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}
}
// =======================================================================
// Test.cs
// =======================================================================
using System;
using Gtk;
using Glade;
public class GladeApp
{
private static Window window;
private static GladeApp singleton;
public static GladeApp Singleton
{
get
{
return singleton;
}
set
{
if (singleton == null)
{
singleton = value;
}
}
}
public static void Main (string[] args)
{
try
{
Singleton = new GladeApp (args);
}
catch (Exception e)
{
if (window != null)
{
window.Hide();
}
string ErrorText = e.GetType() + "\n"
+ e.Message + "\n\n"
+ e.StackTrace;
string markup = ErrorText;
markup = markup.Replace("<","<");
markup = markup.Replace(">",">");
MessageDialog error = new MessageDialog(null,
DialogFlags.DestroyWithParent,
MessageType.Error,
ButtonsType.Close,
markup);
int err = error.Run();
error.Dispose();
System.Console.WriteLine(ErrorText);
}
}
public GladeApp (string[] args)
{
Application.Init ();
Glade.XML gxml = new Glade.XML (null, "gui.glade", "window1", null);
gxml.Autoconnect (this);
Application.Run ();
}
// Connect the Signals defined in Glade
private void OnWindowDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}
private void OnButton1Clicked (object sender, EventArgs a)
{
throw new ArithmeticException();
}
}
// =======================================================================
// gui.glade
// =======================================================================
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
<glade-interface>
<requires lib="gnome"/>
<widget class="GtkWindow" id="window1">
<property name="visible">True</property>
<property name="title" translatable="yes">Glade Window</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_CENTER</property>
<property name="modal">False</property>
<property name="default_width">256</property>
<property name="default_height">256</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property>
<signal name="delete_event" handler="OnWindowDeleteEvent"/>
<child>
<widget class="GtkButton" id="button1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">button1</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="OnButton1Clicked"
last_modification_time="Sat, 04 Mar 2006 02:06:33 GMT"/>
</widget>
</child>
</widget>
</glade-interface>
------------------------------------------------------------------------------------------------------------------------------
FANÁTICO
"Por cuanto eres tibio, y no frío ni caliente, te vomitaré de mi boca."
Apocalipsis 3:16
LOCO
"Porque la Palabra de la Cruz es locura para los que se pierden; pero a
los que se salvan, esto es, a nosotros, es poder de Dios."
1 Corintios 1:18
More information about the Monodevelop-list
mailing list