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

Chris Howie cdhowie at gmail.com
Thu May 22 09:04:35 EDT 2008


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?

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();
    }
}

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();
}

(BTW, it should be PromptingDialog.)

-- 
Chris Howie
http://www.chrishowie.com
http://en.wikipedia.org/wiki/User:Crazycomputers


More information about the Monodevelop-list mailing list