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