[Gtk-sharp-list] [Patch] gnome/Program.custom

Charles Iliya Krempeaux charles@reptile.ca
15 Mar 2003 13:15:27 -0800


--=-Od4XKKaW4PgFK0wC82ig
Content-Type: multipart/alternative; boundary="=-s2jnaNsQW8/5KHWbZiTy"


--=-s2jnaNsQW8/5KHWbZiTy
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hello,

OK, how's this Patch.

The Patch makes it so, by default, using Gnome.Program.Run(Gnome.App)
will NOT have it so the program will quit when you generate a
DeleteEvent.  (Which is the way you wanted it.)

However, (as the way I wanted it) I still tried to make things easy for
new developers.  So, I made a property (of Gnome.Program) that you can
use to make it so the program will infact Quit, when a DeleteEvent is
generated.)

The code below shows how it would be done.

    class HelloWorld
    {
            static void Main(string[] args)
            {
                    Gnome.Program program =
                    new Gnome.Program("Hello World", "1.0",
Gnome.Modules.UI, args);

                    Gnome.App app = new Gnome.App("Hello World", "Hello
World");
 
                    program.QuitOnDeleteEvent = true;
                    program.Run(app);
            }
    }

By default, the QuitOnDeleteEvent property is set to false... so it will
behave as you wanted it.  But if the user sets QuitOnDeleteEvent to
true, as in the code above, then it

(Setting QuitOnDeleteEvent to false, anywhere in the program, stops the
Quiting behaviour, as is expected.)


On Fri, 2003-03-14 at 18:19, Mike Kestner wrote:

> On Fri, 2003-03-14 at 14:54, Charles Iliya Krempeaux wrote:
>  
> > > Basically, it makes it so, if you want to write a simple Gnome
> > > application, you don't have to do through all the complexities of
> > > connecting Gnome.App's DeleteEvent event to a method or procedure that
> > > quits the program.  And don't have to do a ShowAll().  (This is a
> > > WinForms style thing.)
> 
> I like the idea of a Run(App) overload, but I think you throw away some
> utility by also hooking up to DeleteEvent.  Most real apps are going to
> want to react to DeleteEvent with something other than a simple Quit().
> Any document-based app will want to warn for dirty docs, and any
> multi-window app will not want to quit the app if another window is
> open. 
> 
> I also am not charged about the naming choice for the
> DeleteEventHandler.  Naming it Quit makes it look like an overload for
> the public function, which it is not. It's an event handler.  Besides,
> this helper method is in the wrong place.  It should be on Gnome.App if
> anywhere.  I suppose you could add a DefaultDeleteEventHandler() method 
> to Gnome.App if you really want to provide a shorthand for this, but I
> doubt it is going to be used enough to warrant adding it.
> 
> Feel free to commit the Run(App) overload, without the event handler
> hookup.
> 
> Thanks, 

-- 
     Charles Iliya Krempeaux, BSc
     charles@reptile.ca

________________________________________________________________________
 Reptile Consulting & Services    604-REPTILE    http://www.reptile.ca/

--=-s2jnaNsQW8/5KHWbZiTy
Content-Type: text/html; charset=utf-8

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/1.1.8">
</HEAD>
<BODY>
Hello,<BR>
<BR>
OK, how's this Patch.<BR>
<BR>
The Patch makes it so, by default, using <TT>Gnome.Program.Run(Gnome.App)</TT> will NOT have it so the program will quit when you generate a <TT>DeleteEvent</TT>.&nbsp; (Which is the way you wanted it.)<BR>
<BR>
However, (as the way I wanted it) I still tried to make things easy for new developers.&nbsp; So, I made a property (of <TT>Gnome.Program)</TT> that you can use to make it so the program will infact Quit, when a <TT>DeleteEvent</TT> is generated.)<BR>
<BR>
The code below shows how it would be done.<BR>
<BR>
<FONT SIZE="2"><TT>&nbsp;&nbsp;&nbsp; class HelloWorld<BR>
&nbsp;&nbsp;&nbsp; {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static void Main(string[] args)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Gnome.Program program =<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new Gnome.Program(&quot;Hello World&quot;, &quot;1.0&quot;, Gnome.Modules.UI, args);<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Gnome.App app = new Gnome.App(&quot;Hello World&quot;, &quot;Hello World&quot;);<BR>
 <BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; program.QuitOnDeleteEvent = true;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; program.Run(app);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>
&nbsp;&nbsp;&nbsp; }</TT></FONT><BR>
<BR>
By default, the <TT>QuitOnDeleteEvent</TT> property is set to <TT>false</TT>... so it will behave as you wanted it.&nbsp; But if the user sets <TT>QuitOnDeleteEvent</TT> to true, as in the code above, then it<BR>
<BR>
(Setting <TT>QuitOnDeleteEvent</TT> to false, anywhere in the program, stops the Quiting behaviour, as is expected.)<BR>
<BR>
<BR>
On Fri, 2003-03-14 at 18:19, Mike Kestner wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE><FONT COLOR="#737373" SIZE="3"><I>On Fri, 2003-03-14 at 14:54, Charles Iliya Krempeaux wrote:
 
&gt; &gt; Basically, it makes it so, if you want to write a simple Gnome
&gt; &gt; application, you don't have to do through all the complexities of
&gt; &gt; connecting Gnome.App's DeleteEvent event to a method or procedure that
&gt; &gt; quits the program.  And don't have to do a ShowAll().  (This is a
&gt; &gt; WinForms style thing.)

I like the idea of a Run(App) overload, but I think you throw away some
utility by also hooking up to DeleteEvent.  Most real apps are going to
want to react to DeleteEvent with something other than a simple Quit().
Any document-based app will want to warn for dirty docs, and any
multi-window app will not want to quit the app if another window is
open. 

I also am not charged about the naming choice for the
DeleteEventHandler.  Naming it Quit makes it look like an overload for
the public function, which it is not. It's an event handler.  Besides,
this helper method is in the wrong place.  It should be on Gnome.App if
anywhere.  I suppose you could add a DefaultDeleteEventHandler() method 
to Gnome.App if you really want to provide a shorthand for this, but I
doubt it is going to be used enough to warrant adding it.

Feel free to commit the Run(App) overload, without the event handler
hookup.

Thanks, </I></FONT></PRE>
</BLOCKQUOTE>
<PRE><TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
<PRE>-- 
     Charles Iliya Krempeaux, BSc
     charles@reptile.ca

________________________________________________________________________
 Reptile Consulting &amp; Services    604-REPTILE    http://www.reptile.ca/</PRE>
</TD>
</TR>
</TABLE>
</PRE>
</BODY>
</HTML>

--=-s2jnaNsQW8/5KHWbZiTy--

--=-Od4XKKaW4PgFK0wC82ig
Content-Disposition: attachment; filename=gtk-sharp-New_Gnome.App.Run-Procedure-Version-3.diff
Content-Type: text/x-patch; name=gtk-sharp-New_Gnome.App.Run-Procedure-Version-3.diff; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Index: ChangeLog
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/public/gtk-sharp/ChangeLog,v
retrieving revision 1.356
diff -u -r1.356 ChangeLog
--- ChangeLog	15 Mar 2003 19:09:52 -0000	1.356
+++ ChangeLog	15 Mar 2003 21:13:37 -0000
@@ -1,3 +1,16 @@
+2003-03-15  Charles Iliya Krempeaux  <charles@reptile.ca>
+
+	* gnome/Program.custom : Added a WinForms style
+	  Run() procedure.  (This Run() procedure takes
+	  Gnome.App as a parameter, and takes care of all
+	  the dirty work of calling the ShowAll() method
+	  and [potentially] connecting the event DeleteEvent
+	  to a handler that will close the program.)  Also
+	  added a QuitOnDeleteEvent property to specify if
+	  the Gnome.App passed to Run() will Quit (by
+	  Gnome.Program's hands) when the DeleteEvent is
+	  generated.
+
 2003-03-14  Charles Iliya Krempeaux  <charles@reptile.ca>
=20
 	* sources/makefile : Added a "distclean" rule, so
Index: gnome/Program.custom
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/public/gtk-sharp/gnome/Program.custom,v
retrieving revision 1.5
diff -u -r1.5 Program.custom
--- gnome/Program.custom	15 Oct 2002 21:46:33 -0000	1.5
+++ gnome/Program.custom	15 Mar 2003 21:13:41 -0000
@@ -70,6 +70,34 @@
 	Gtk.Application.Run ();
 }
=20
+public void Run(Gnome.App app)
+{
+        app.DeleteEvent +=3D new GtkSharp.DeleteEventHandler(this.MyDelete=
EventHandler);
+
+        app.ShowAll();
+
+        this.Run();
+}
+
+private bool quit_on_delete_event =3D false;
+
+public bool QuitOnDeleteEvent {
+        get {
+                return this.quit_on_delete_event;
+        }
+
+        set {
+                this.quit_on_delete_event =3D value;
+        }
+}
+
+private void MyDeleteEventHandler(object obj, GtkSharp.DeleteEventArgs arg=
s)
+{
+        if (this.QuitOnDeleteEvent) {
+                this.Quit();
+        }
+}
+
 public void Quit ()
 {
 	Gtk.Application.Quit ();

--=-Od4XKKaW4PgFK0wC82ig--