]> git.lyx.org Git - features.git/blob - src/frontends/Alert.C
98c971c37a210d46451a59309a1ed9507511febd
[features.git] / src / frontends / Alert.C
1 /**
2  * \file Alert.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "Alert.h"
14 #include "Alert_pimpl.h"
15
16 #include "debug.h"
17 #include "lyx_gui.h"
18
19 using lyx::docstring;
20
21 using std::endl;
22 using std::make_pair;
23 using std::pair;
24 using std::string;
25
26
27 namespace lyx {
28 namespace frontend {
29
30 int Alert::prompt(docstring const & title, docstring const & question,
31                   int default_button, int escape_button,
32                   docstring const & b1, docstring const & b2, docstring const & b3)
33 {
34         if (!lyx_gui::use_gui || lyxerr.debugging()) {
35                 lyxerr << lyx::to_utf8(title) << '\n'
36                        << "----------------------------------------\n"
37                        << lyx::to_utf8(question) << endl;
38
39                 lyxerr << "Assuming answer is ";
40                 switch (default_button) {
41                 case 0: lyxerr << lyx::to_utf8(b1) << endl;
42                 case 1: lyxerr << lyx::to_utf8(b2) << endl;
43                 case 2: lyxerr << lyx::to_utf8(b3) << endl;
44                 }
45                 if (!lyx_gui::use_gui)
46                         return default_button;
47         }
48
49         return prompt_pimpl(title, question,
50                             default_button, escape_button, b1, b2, b3);
51
52 }
53
54
55 void Alert::warning(docstring const & title, docstring const & message)
56 {
57         if (!lyx_gui::use_gui || lyxerr.debugging())
58                 lyxerr << "Warning: " << lyx::to_utf8(title) << '\n'
59                        << "----------------------------------------\n"
60                        << lyx::to_utf8(message) << endl;
61         if (lyx_gui::use_gui)
62                 warning_pimpl(title, message);
63 }
64
65
66 void Alert::error(docstring const & title, docstring const & message)
67 {
68         if (!lyx_gui::use_gui || lyxerr.debugging())
69                 lyxerr << "Error: " << lyx::to_utf8(title) << '\n'
70                        << "----------------------------------------\n"
71                        << lyx::to_utf8(message) << endl;
72
73         if (lyx_gui::use_gui)
74                 error_pimpl(title, message);
75 }
76
77
78 void Alert::information(docstring const & title, docstring const & message)
79 {
80         if (!lyx_gui::use_gui || lyxerr.debugging())
81                 lyxerr << lyx::to_utf8(title) << '\n'
82                        << "----------------------------------------\n"
83                        << lyx::to_utf8(message) << endl;
84
85         if (lyx_gui::use_gui)
86                 information_pimpl(title, message);
87 }
88
89
90 pair<bool, docstring> const Alert::askForText(docstring const & msg,
91                                            docstring const & dflt)
92 {
93         if (!lyx_gui::use_gui || lyxerr.debugging()) {
94                 lyxerr << "----------------------------------------\n"
95                        << lyx::to_utf8(msg) << '\n'
96                        << "Assuming answer is " << lyx::to_utf8(dflt) << '\n'
97                        << "----------------------------------------" << endl;
98                 if (!lyx_gui::use_gui)
99                         return make_pair<bool, docstring>(true, dflt);
100         }
101
102         return askForText_pimpl(msg, dflt);
103 }
104
105 }
106 }