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