]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/Alert_pimpl.C
Display accelerator (binding) labels in menus.
[lyx.git] / src / frontends / gtk / Alert_pimpl.C
1 /**
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.
5  *
6  * \author Huang Ying
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "frontends/Alert.h"
14 #include "frontends/Alert_pimpl.h"
15
16 #include <gtkmm.h>
17
18 using std::string;
19
20
21 namespace {
22
23
24 string translateShortcut(string const & str)
25 {
26         string::size_type i = str.find_first_of("&");
27         if (i == string::npos || i == str.length() - 1)
28                 return str;
29         string tstr = str;
30         tstr[i] = '_';
31         return tstr;
32 }
33
34
35 }
36
37
38 void warning_pimpl(string const &, string const & message)
39 {
40         Gtk::MessageDialog dlg(Glib::locale_to_utf8(message),
41                                true, Gtk::MESSAGE_WARNING,
42                                Gtk::BUTTONS_CLOSE, true);
43         dlg.run();
44 }
45
46
47 void error_pimpl(string const &, string const & message)
48 {
49         Gtk::MessageDialog dlg(Glib::locale_to_utf8(message),
50                                true, Gtk::MESSAGE_ERROR,
51                                Gtk::BUTTONS_CLOSE, true);
52         dlg.run();
53 }
54
55
56 void information_pimpl(string const &, string const & message)
57 {
58         Gtk::MessageDialog dlg(Glib::locale_to_utf8(message),
59                                true, Gtk::MESSAGE_INFO,
60                                Gtk::BUTTONS_CLOSE, true);
61         dlg.run();
62 }
63
64
65 int prompt_pimpl(string const &, string const & question,
66                  int defaultButton, int /*escapeButton*/,
67                  string const & b1, string const & b2, string const & b3)
68 {
69         Glib::ustring gb1 = Glib::locale_to_utf8(translateShortcut(b1));
70         Glib::ustring gb2 = Glib::locale_to_utf8(translateShortcut(b2));
71         Glib::ustring gb3;
72         if (!b3.empty())
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);
79         if (!b3.empty())
80                 dlg.add_button(gb3, 2);
81         dlg.set_default_response(defaultButton);
82         return dlg.run();
83 }
84
85
86 std::pair<bool, string> const askForText_pimpl(string const & msg,
87                                                string const & dflt)
88 {
89         Gtk::MessageDialog dlg(Glib::locale_to_utf8(msg),
90                                true, Gtk::MESSAGE_QUESTION,
91                                Gtk::BUTTONS_OK_CANCEL,
92                                true);
93         Gtk::Entry entry;
94         entry.set_text(Glib::locale_to_utf8(dflt));
95         entry.set_position(-1);
96         entry.show();
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);
103         }
104         else
105                 return std::make_pair<bool, string>(false, string());
106 }