[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 12:35:28 EDT 2008
tor 2008-05-22 klockan 11:25 -0400 skrev Chris Howie:
> On Thu, May 22, 2008 at 9:35 AM, simon.n.lindgren at gmail.com
> <simon.n.lindgren at gmail.com> wrote:
> >> 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?
>
> I believe you would use Dialog.Respond(ResponseType.Accept). (Or Cancel etc.)
Yes. That's the one.
>
> >> 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 :).
>
> Yeah, the read/write thing is another advantage of this approach.
>
> >> (BTW, it should be PromptingDialog.)
> >>
> > ?
> >
> > Did you mean PromtDialog?
>
> No. Promt is not an English word -- you mean prompt.
Ah! I can't read it seems!
--
Simon Lindgren
http://simonlindgren.pcriot.com
More information about the Monodevelop-list
mailing list