2 * \file gtk/Alert_pimpl.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "frontends/Alert.h"
14 #include "frontends/Alert_pimpl.h"
24 string translateShortcut(string const & str)
26 string::size_type i = str.find_first_of("&");
27 if (i == string::npos || i == str.length() - 1)
38 void warning_pimpl(string const &, string const & message)
40 Gtk::MessageDialog dlg(Glib::locale_to_utf8(message),
41 true, Gtk::MESSAGE_WARNING,
42 Gtk::BUTTONS_CLOSE, true);
47 void error_pimpl(string const &, string const & message)
49 Gtk::MessageDialog dlg(Glib::locale_to_utf8(message),
50 true, Gtk::MESSAGE_ERROR,
51 Gtk::BUTTONS_CLOSE, true);
56 void information_pimpl(string const &, string const & message)
58 Gtk::MessageDialog dlg(Glib::locale_to_utf8(message),
59 true, Gtk::MESSAGE_INFO,
60 Gtk::BUTTONS_CLOSE, true);
65 int prompt_pimpl(string const &, string const & question,
66 int defaultButton, int /*escapeButton*/,
67 string const & b1, string const & b2, string const & b3)
69 Glib::ustring gb1 = Glib::locale_to_utf8(translateShortcut(b1));
70 Glib::ustring gb2 = Glib::locale_to_utf8(translateShortcut(b2));
73 gb3 = Glib::locale_to_utf8(translateShortcut(b3));
74 Gtk::MessageDialog dlg(Glib::locale_to_utf8(question),
75 true, Gtk::MESSAGE_QUESTION,
76 Gtk::BUTTONS_NONE, true);
77 dlg.add_button(gb1, 0);
78 dlg.add_button(gb2, 1);
80 dlg.add_button(gb3, 2);
81 dlg.set_default_response(defaultButton);
86 std::pair<bool, string> const askForText_pimpl(string const & msg,
89 Gtk::MessageDialog dlg(Glib::locale_to_utf8(msg),
90 true, Gtk::MESSAGE_QUESTION,
91 Gtk::BUTTONS_OK_CANCEL,
94 entry.set_text(Glib::locale_to_utf8(dflt));
95 entry.set_position(-1);
97 dlg.get_vbox()->children().push_back(
98 Gtk::Box_Helpers::Element(entry));
99 int response = dlg.run();
100 if (response == Gtk::RESPONSE_OK) {
101 string str = Glib::locale_from_utf8(entry.get_text());
102 return std::make_pair<bool, string>(true, str);
105 return std::make_pair<bool, string>(false, string());