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