]> git.lyx.org Git - lyx.git/blob - src/frontends/Alert.C
Really dull and boring header shit
[lyx.git] / src / frontends / Alert.C
1 /**
2  * \file Alert.C
3  * Read the file COPYING
4  *
5  * \author John Levon 
6  *
7  * Full author contact details are available in file CREDITS
8  */
9
10 #include <config.h>
11
12 #include "Alert.h"
13
14 #include "debug.h"
15 #include "lyxrc.h"
16
17 #include "Alert_pimpl.h"
18
19 #include <cerrno>
20
21 #ifndef CXX_GLOBAL_CSTD
22 using std::strerror;
23 #endif
24
25 using std::endl;
26 using std::pair;
27 using std::make_pair;
28
29
30 void Alert::alert(string const & s1, string const & s2, string const & s3)
31 {
32         if (!lyxrc.use_gui) {
33                 lyxerr << "------------------------------" << endl
34                        << s1 << endl << s2 << endl << s3 << endl
35                        << "------------------------------" << endl;
36         } else {
37                 alert_pimpl(s1, s2, s3);
38         }
39 }
40
41
42 void Alert::err_alert(string const & s1, string const & s2)
43 {
44         alert(s1, s2, strerror(errno));
45 }
46
47
48 bool Alert::askQuestion(string const & s1, string const & s2,
49                         string const & s3, bool default_value)
50 {
51         if (!lyxrc.use_gui) {
52                 lyxerr << "----------------------------------------" << endl
53                        << s1 << endl;
54                 if (!s2.empty())
55                         lyxerr << s2 << endl;
56                 if (!s3.empty())
57                         lyxerr << s3 << endl;
58                 lyxerr << "Assuming answer is "
59                        << (default_value ? "yes" : "no")
60                        << endl
61                        << "----------------------------------------" << endl;
62                 return default_value;
63         } else {
64                 return askQuestion_pimpl(s1, s2, s3);
65         }
66 }
67
68
69 int Alert::askConfirmation(string const & s1, string const & s2,
70                            string const & s3, int default_value)
71 {
72         if (!lyxrc.use_gui) {
73                 lyxerr << "----------------------------------------" << endl
74                        << s1 << endl;
75                 if (!s2.empty())
76                         lyxerr << s2 << endl;
77                 if (!s3.empty())
78                         lyxerr << s3 << endl;
79                 lyxerr << "Assuming answer is ";
80                 if (default_value == 1)
81                         lyxerr << "yes";
82                 else if (default_value == 2)
83                         lyxerr << "no";
84                 else
85                         lyxerr << "cancel";
86                 lyxerr << endl
87                        << "----------------------------------------" << endl;
88                 return default_value;
89         } else {
90                 return askConfirmation_pimpl(s1, s2, s3);
91         }
92 }
93
94
95 pair<bool, string> const Alert::askForText(string const & msg,
96                                            string const & dflt)
97 {
98         if (!lyxrc.use_gui) {
99                 lyxerr << "----------------------------------------" << endl
100                        << msg << endl
101                        << "Assuming answer is " << dflt
102                        << "----------------------------------------" << endl;
103                 return make_pair<bool, string>(true, dflt);
104         } else {
105                 return askForText_pimpl(msg, dflt);
106         }
107 }