[MonoDevelop] What is the correct way of closing a Gtk dialog?

simon.n.lindgren at gmail.com simon.n.lindgren at gmail.com
Thu May 22 09:35:26 EDT 2008


tor 2008-05-22 klockan 09:04 -0400 skrev Chris Howie:
> On Thu, May 22, 2008 at 8:55 AM, simon.n.lindgren at gmail.com
> <simon.n.lindgren at gmail.com> wrote:
> > Ah, I think you misunderstood a bit(or maybe I didn't explain that
> > good). I have made new stetic dialog and I use an overloaded Run() to
> > display it. When the user presses any of the two buttons, buttonOk and
> > buttonCancel, the dialog should close i.e. the Run method should return
> > to the caller again. How do I do that? here's the current eventhandling
> > code:
> >
> > [snip]
> 
> Aha, I see.  Depending on how you created the buttons this may be OK,
> and it may not.  Do you get a different return value from your Run
> method depending on which button you clicked?

Yes. All seems to be working fine. The buttons are the standard buttons
from the "Dialog" template.

> 
> Also, I would not have the dialog destroy itself.  The caller should
> be responsible for that, since it created it.  What you may want to do
> instead is have a static method:
> 
> public static int Run(string title, string message, out result) {
>     PromtingDialog pd = new PromtingDialog(title, message);
>     try {
>         int retval = pd.Run();
>         result = pd.response;
>         return retval;
>     } finally {
>         pd.Destroy();
>     }
> }

This was the reason I wanted to know whether there is a better way to
make Run() return. I think I read somewhere about an event that would
make it return. Is there such an event and how would one trigger it?

> 
> Usually the pattern you would use if you were going to create and use
> this dialog from other code without using a static method would be to
> make the "result" field accessible by a public property and let the
> dependent code check it directly:
> 
> PromtingDialog pd = new PromtingDialog(title, message);
> try {
>     if (pd.Run() == (int) ResponseType.Accept) {
>         // do something with pd.Response
>     }
> } finally {
>     pd.Destroy();
> }

I think I will do it this way. With a Read-Write property the calling
code could set the default value this way as well. I think I got this
pretty much worked out now. When I tested previously the buttons didn't
close the dialog if I didn't add the Destroy() calls, but now it does
close without the calls. So I no longer have this problem :).

> 
> (BTW, it should be PromptingDialog.)
> 
?

Did you mean PromtDialog?

-- 
Simon Lindgren
http://simonlindgren.pcriot.com



More information about the Monodevelop-list mailing list