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