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