How do I keep main window from closing?

View: New views
7 Messages — Rating Filter:   Alert me  

How do I keep main window from closing?

by bdubu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have a TextView on my main window.  I don't want to be able to close the main window if the text in this TextView has been modified but not yet saved to disk.  I realize I can check the control's Buffer.Modified property and that this should likely be done in the main windows's OnDeleteEvent handler but I don't know how to make this work.  I took a WAG and tried this...

        protected void OnDeleteEvent (object sender, DeleteEventArgs a)
        {
                MessageDialog WarningMesgDlg = new MessageDialog (this,
                DialogFlags.DestroyWithParent, MessageType.Warning,
                ButtonsType.YesNo, "Abandon changes?");

                try
                {
                        if ((!docTextView.Buffer.Modified) || (WarningMesgDlg.Run() == (int) ResponseType.Yes))
                        {
                                Application.Quit ();
                                a.RetVal = true;
                        }
                }
                finally
                {
                        WarningMesgDlg.Destroy();
                }
        }

... but the main window closes even though the Modified property is true and I answer "no" to the dialog's question, "Abandon changes?".  Can someone shed some light on how I should go about this?  Thanks!


Re: How do I keep main window from closing?

by Adam Tauno Williams :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, 2009-07-20 at 15:51 -0700, bdubu wrote:
> I have a TextView on my main window.  I don't want to be able to close the
> main window if the text in this TextView has been modified but not yet saved
> to disk.  I realize I can check the control's Buffer.Modified property and
> that this should likely be done in the main windows's OnDeleteEvent handler
> but I don't know how to make this work.  I took a WAG and tried this...

Try

[GLib.ConnectBefore]
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{

then interrupt the callback chain by setting a.RetVal = false; [ or is
it a.RetVal = true; ]  one of those.  Those should make your callback
first and stop the default callback from executing.

I think.

> ... but the main window closes even though the Modified property is true and
> I answer "no" to the dialog's question, "Abandon changes?".  Can someone
> shed some light on how I should go about this?  Thanks!



--
OpenGroupware developer: awilliam@...
<http://whitemiceconsulting.blogspot.com/>
OpenGroupare & Cyrus IMAPd documenation @
<http://docs.opengroupware.org/Members/whitemice/wmogag/file_view>

_______________________________________________
Gtk-sharp-list maillist  -  Gtk-sharp-list@...
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

Re: How do I keep main window from closing?

by Jiří Zárevúcky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/7/21 bdubu <bwb@...>:
>
> I have a TextView on my main window.  I don't want to be able to close the
> main window if the text in this TextView has been modified but not yet saved
> to disk.  I realize I can check the control's Buffer.Modified property and
> that this should likely be done in the main windows's OnDeleteEvent handler
> but I don't know how to make this work.  I took a WAG and tried this...
>

Your problem is that RetVal set to true prevents closing, not the
other way around. When you leave the default false, it will close as
normally.
_______________________________________________
Gtk-sharp-list maillist  -  Gtk-sharp-list@...
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

Re: How do I keep main window from closing?

by bdubu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Adam Tauno Williams wrote:
Try

[GLib.ConnectBefore]
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{

then interrupt the callback chain by setting a.RetVal = false; [ or is
it a.RetVal = true; ]  one of those.  Those should make your callback
first and stop the default callback from executing.

I think.
Thanks for responding.  Ok, I tried this but unfortunately the window still closes.  : (  

Re: How do I keep main window from closing?

by bdubu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Jiří Zárevúcky wrote:
Your problem is that RetVal set to true prevents closing, not the
other way around. When you leave the default false, it will close as
normally.
Thanks for responding.  That's weird.  Prior to my fiddling around with the OnDeleteEvent handler, a.RetVal was being set to true (and of course, the window was closing normally).  At this point I've tried setting it both to true and to false and neither way seems to help -- the window still closes.  : (   Would my running under monodevelop be inhibiting the desired behaviour perhaps?  I've noticed that if I set a.RetVal to false, run my program and then close it, in monodevelop the "Debug" (run) toolbar button remains disabled and I have to shut down monodevelop to make this toolbar button re-enable.  Is this telling me something but I'm just too dense to get it?  Also, if I'm supposed to set a.RetVal a particular way in order to cause the window to stay open, I assume that I shouldn't be calling Application.Quit, or should I?  Thanks!


Re: How do I keep main window from closing?

by Chris Howie :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I did some testing on this and determined the following:

* [GLib.ConnectBefore] is not necessary to disallow closing of the window.

* In order to properly continue with destruction of the window, do this:

args.RetVal = false;
Application.Quit();

* In order to disallow closing of the window, do this:

args.RetVal = true;
// Do *not* call Application.Quit()

On Tue, Jul 21, 2009 at 1:41 PM, bdubu<bwb@...> wrote:

>
>
>
> Jiří Zárevúcky wrote:
>>
>> Your problem is that RetVal set to true prevents closing, not the
>> other way around. When you leave the default false, it will close as
>> normally.
>>
>
> Thanks for responding.  That's weird.  Prior to my fiddling around with the
> OnDeleteEvent handler, a.RetVal was being set to true (and of course, the
> window was closing normally).  At this point I've tried setting it both to
> true and to false and neither way seems to help -- the window still closes.
> : (   Would my running under monodevelop be inhibiting the desired behaviour
> perhaps?  I've noticed that if I set a.RetVal to false, run my program and
> then close it, in monodevelop the "Debug" (run) toolbar button remains
> disabled and I have to shut down monodevelop to make this toolbar button
> re-enable.  Is this telling me something but I'm just too dense to get it?
> Also, if I'm supposed to set a.RetVal a particular way in order to cause the
> window to stay open, I assume that I shouldn't be calling Application.Quit,
> or should I?  Thanks!
>
>
> --
> View this message in context: http://www.nabble.com/How-do-I-keep-main-window-from-closing--tp24578770p24592149.html
> Sent from the Mono - Gtk# mailing list archive at Nabble.com.
>
> _______________________________________________
> Gtk-sharp-list maillist  -  Gtk-sharp-list@...
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
>



--
Chris Howie
http://www.chrishowie.com
http://en.wikipedia.org/wiki/User:Crazycomputers
_______________________________________________
Gtk-sharp-list maillist  -  Gtk-sharp-list@...
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

Re: How do I keep main window from closing?

by bdubu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Chris Howie wrote:
I did some testing on this and determined the following:

* [GLib.ConnectBefore] is not necessary to disallow closing of the window.

* In order to properly continue with destruction of the window, do this:

args.RetVal = false;
Application.Quit();

* In order to disallow closing of the window, do this:

args.RetVal = true;
// Do *not* call Application.Quit()
Yahoo!  That did it for me.  I was really stuck on that one.  Hey, thanks a million to each of you for helping me out here.