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