]> git.lyx.org Git - features.git/blob - src/frontends/gtk/Alert_pimpl.C
Fix a bunch of doxygen warnings.
[features.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 #include <gtkmm.h>
13
14 #include "frontends/Alert.h"
15 #include "frontends/Alert_pimpl.h"
16
17 using std::string;
18
19
20 namespace {
21
22
23 string translateShortcut(string const & str)
24 {
25         string::size_type i = str.find_first_of("&");
26         if (i == string::npos || i == str.length() - 1)
27                 return str;
28         string tstr = str;
29         tstr[i] = '_';
30         return tstr;
31 }
32
33
34 }
35
36
37 void warning_pimpl(string const &, string const & message)
38 {
39         Gtk::MessageDialog dlg(Glib::locale_to_utf8(message),
40                                Gtk::MESSAGE_WARNING,
41                                Gtk::BUTTONS_CLOSE, true, true);
42         dlg.run();
43 }
44
45
46 void error_pimpl(string const &, string const & message)
47 {
48         Gtk::MessageDialog dlg(Glib::locale_to_utf8(message),
49                                Gtk::MESSAGE_ERROR,
50                                Gtk::BUTTONS_CLOSE, true, true);
51         dlg.run();
52 }
53
54
55 void information_pimpl(string const &, string const & message)
56 {
57         Gtk::MessageDialog dlg(Glib::locale_to_utf8(message),
58                                Gtk::MESSAGE_INFO,
59                                Gtk::BUTTONS_CLOSE, true, true);
60         dlg.run();
61 }
62
63
64 int prompt_pimpl(string const &, string const & question,
65                  int defaultButton, int /*escapeButton*/,
66                  string const & b1, string const & b2, string const & b3)
67 {
68         Glib::ustring gb1 = Glib::locale_to_utf8(translateShortcut(b1));
69         Glib::ustring gb2 = Glib::locale_to_utf8(translateShortcut(b2));
70         Glib::ustring gb3;
71         if (!b3.empty())
72                 gb3 = Glib::locale_to_utf8(translateShortcut(b3));
73         Gtk::MessageDialog dlg(Glib::locale_to_utf8(question),
74                                Gtk::MESSAGE_QUESTION,
75                                Gtk::BUTTONS_NONE, true, true);
76         dlg.add_button(gb1, 0);
77         dlg.add_button(gb2, 1);
78         if (!b3.empty())
79                 dlg.add_button(gb3, 2);
80         dlg.set_default_response(defaultButton);
81         return dlg.run();
82 }
83
84
85 std::pair<bool, string> const askForText_pimpl(string const & msg,
86                                                string const & dflt)
87 {
88         Gtk::MessageDialog dlg(Glib::locale_to_utf8(msg),
89                                Gtk::MESSAGE_QUESTION,
90                                Gtk::BUTTONS_OK_CANCEL,
91                                true, true);
92         Gtk::Entry entry;
93         entry.set_text(Glib::locale_to_utf8(dflt));
94         entry.set_position(-1);
95         entry.show();
96         dlg.get_vbox()->children().push_back(
97                 Gtk::Box_Helpers::Element(entry));
98         int response = dlg.run();
99         if (response == Gtk::RESPONSE_OK) {
100                 string str = Glib::locale_from_utf8(entry.get_text());
101                 return std::make_pair<bool, string>(true, str);
102         }
103         else
104                 return std::make_pair<bool, string>(false, string());
105 }