A slightly improved version:
public bool show_question(string primary_markup,
string? secondary_markup = null,
Gtk.Window? parent = null,
Gtk.MessageType message_type = Gtk.MessageType.QUESTION)
{
var m = new Gtk.MessageDialog.with_markup(parent,
Gtk.DialogFlags.MODAL,
message_type,
Gtk.ButtonsType.OK_CANCEL,
primary_markup);
m.format_secondary_markup(secondary_markup);
var result = (Gtk.ResponseType) m.run();
m.destroy();
return (result == Gtk.ResponseType.OK);
}
This new version takes advantage of Vala's default parameters, so in the simplest case you can just call show_question("Is this OK?");
. Furthermore, you can also now use Pango Markup to generate much nicer looking dialogs, for example:
show_question("<b><big>Overwrite File?</big></b>",
"<small>The file <i>\"%s\"</i> will be overwritten if you proceed</small>".printf(my_filename),
parent_window,
Gtk.MessageType.WARNING);
It's worth noting however that in GTK, using plain "OK/CANCEL" responses like this is generally frowned upon. Instead the recommendation is to use button labels that contain verbs pertaining to the action in question; so in the above example, "Cancel" and "Overwrite" would be much better options (defaulting to Cancel, of course). This takes a little but more work for the programmer, but provides a better user experience.