]> git.lyx.org Git - lyx.git/blob - src/frontends/Alert.C
move everything into namespace lyx
[lyx.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_main.h" // for lyx::use_gui
18
19 using std::endl;
20 using std::make_pair;
21 using std::pair;
22 using std::string;
23
24
25 namespace lyx {
26
27 namespace frontend {
28
29 int Alert::prompt(docstring const & title, docstring const & question,
30                   int default_button, int escape_button,
31                   docstring const & b1, docstring const & b2, docstring const & b3)
32 {
33         if (!use_gui || lyxerr.debugging()) {
34                 lyxerr << to_utf8(title) << '\n'
35                        << "----------------------------------------\n"
36                        << to_utf8(question) << endl;
37
38                 lyxerr << "Assuming answer is ";
39                 switch (default_button) {
40                 case 0: lyxerr << to_utf8(b1) << endl;
41                 case 1: lyxerr << to_utf8(b2) << endl;
42                 case 2: lyxerr << to_utf8(b3) << endl;
43                 }
44                 if (!use_gui)
45                         return default_button;
46         }
47
48         return prompt_pimpl(title, question,
49                             default_button, escape_button, b1, b2, b3);
50
51 }
52
53
54 void Alert::warning(docstring const & title, docstring const & message)
55 {
56         if (!use_gui || lyxerr.debugging())
57                 lyxerr << "Warning: " << to_utf8(title) << '\n'
58                        << "----------------------------------------\n"
59                        << to_utf8(message) << endl;
60         if (use_gui)
61                 warning_pimpl(title, message);
62 }
63
64
65 void Alert::error(docstring const & title, docstring const & message)
66 {
67         if (!use_gui || lyxerr.debugging())
68                 lyxerr << "Error: " << to_utf8(title) << '\n'
69                        << "----------------------------------------\n"
70                        << to_utf8(message) << endl;
71
72         if (use_gui)
73                 error_pimpl(title, message);
74 }
75
76
77 void Alert::information(docstring const & title, docstring const & message)
78 {
79         if (!use_gui || lyxerr.debugging())
80                 lyxerr << to_utf8(title) << '\n'
81                        << "----------------------------------------\n"
82                        << to_utf8(message) << endl;
83
84         if (use_gui)
85                 information_pimpl(title, message);
86 }
87
88
89 pair<bool, docstring> const Alert::askForText(docstring const & msg,
90                                            docstring const & dflt)
91 {
92         if (!use_gui || lyxerr.debugging()) {
93                 lyxerr << "----------------------------------------\n"
94                        << to_utf8(msg) << '\n'
95                        << "Assuming answer is " << to_utf8(dflt) << '\n'
96                        << "----------------------------------------" << endl;
97                 if (!use_gui)
98                         return make_pair<bool, docstring>(true, dflt);
99         }
100
101         return askForText_pimpl(msg, dflt);
102 }
103
104 } // namespace frontend
105 } // namespace lyx