Discussion:
[Ardour-Dev] How to use "small" dialogs
Johannes Mueller
2017-08-19 14:43:39 UTC
Permalink
Hi,
One small comment on this. Not saying it should be reverted or anything
Dialog d;
....
int response = d.run();
...
this use of modal dialogs creates potential for many problems. newer GTK
versions have more or less removed it. the replacement is more complex -
you need a response handler method/function - but the design is much more
robust across platforms and contexts.
foo () { Dialog* d = new Dialog; d->signal_response().connect (bind
(handler, d)); /* set up d */ d->show (); }
handler (int response, Dialog* d) { /* handle response */;
delete_when_idle (d); }
How about small "Are you sure" dialogs? Like overwrite_file_dialog() in
gtk2_ardour/utils.h which uses Dialog::run().

It seems to me cumbersome to use a response handler function, when I just need
a simple yes/no dialog.

Let's say we have:

void Foo::bar()
{
// 50 lines of code establishing context

Dialog d; // simple yes/no dialog
int response = d.run();

// handle response (using the established context)
}

Using the response handler function concept I would need to transfer the
context into the handler function. Moreover I need to take extra care to free
any resources that belong to the context, as I can no longer rely on stack
unwinding.

I'm not talking of complex dialogs that might already do something while they
are running and that are the center of the action and can/need to have the
context on their own. They are better of with the response handler function.

Thanks

Johannes
--
https://github.com/johannes-mueller/
Loading...