Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
dialog-run.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2
3#include <optional>
4
5#include <glibmm/main.h>
6#include <gtkmm/dialog.h>
7#include <gtkmm/window.h>
8
9#include "dialog-run.h"
10
11namespace Inkscape::UI {
12
13int dialog_run(Gtk::Dialog &dialog)
14{
15 std::optional<int> result;
16
17 auto response_conn = dialog.signal_response().connect([&] (int response) {
18 result = response;
19 });
20
21 auto hide_conn = dialog.signal_hide().connect([&] {
22 result = Gtk::ResponseType::NONE;
23 });
24
25 dialog.set_modal();
26 dialog.set_visible(true);
27
28 auto main_context = Glib::MainContext::get_default();
29 while (!result) {
30 main_context->iteration(true);
31 }
32
33 response_conn.disconnect();
34 hide_conn.disconnect();
35
36 dialog.set_visible(false);
37
38 return *result;
39}
40
41void dialog_show_modal_and_selfdestruct(std::unique_ptr<Gtk::Dialog> dialog, Gtk::Root *root)
42{
43 if (auto const window = dynamic_cast<Gtk::Window *>(root)) {
44 dialog->set_transient_for(*window);
45 }
46 dialog->set_modal();
47 dialog->signal_response().connect([d = dialog.get()] (auto) { delete d; });
48 dialog->set_visible(true);
49 dialog.release(); // deleted by signal_response handler
50}
51
52} // namespace Inkscape::UI
RootCluster root
Css & result
User interface code.
Definition desktop.h:113
void dialog_show_modal_and_selfdestruct(std::unique_ptr< Gtk::Dialog > dialog, Gtk::Root *root)
Show a dialog modally, destroying it when the user dismisses it.
int dialog_run(Gtk::Dialog &dialog)
This is a GTK4 porting aid meant to replace the removal of the Gtk::Dialog synchronous API.