lyx_mirror/src/frontends/Alert.C
Lars Gullik Bjønnes 13349032cb ws changes
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5758 a592a061-630c-0410-9148-cb99ea01b6c8
2002-12-01 22:59:25 +00:00

109 lines
2.4 KiB
C

/**
* \file Alert.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author John Levon
*
* Full author contact details are available in file CREDITS
*/
#include <config.h>
#include "Alert.h"
#include "debug.h"
#include "lyxrc.h"
#include "Alert_pimpl.h"
#include <cerrno>
#ifndef CXX_GLOBAL_CSTD
using std::strerror;
#endif
using std::endl;
using std::pair;
using std::make_pair;
void Alert::alert(string const & s1, string const & s2, string const & s3)
{
if (!lyxrc.use_gui) {
lyxerr << "------------------------------" << endl
<< s1 << endl << s2 << endl << s3 << endl
<< "------------------------------" << endl;
} else {
alert_pimpl(s1, s2, s3);
}
}
void Alert::err_alert(string const & s1, string const & s2)
{
alert(s1, s2, strerror(errno));
}
bool Alert::askQuestion(string const & s1, string const & s2,
string const & s3, bool default_value)
{
if (!lyxrc.use_gui) {
lyxerr << "----------------------------------------" << endl
<< s1 << endl;
if (!s2.empty())
lyxerr << s2 << endl;
if (!s3.empty())
lyxerr << s3 << endl;
lyxerr << "Assuming answer is "
<< (default_value ? "yes" : "no")
<< endl
<< "----------------------------------------" << endl;
return default_value;
} else {
return askQuestion_pimpl(s1, s2, s3);
}
}
int Alert::askConfirmation(string const & s1, string const & s2,
string const & s3, int default_value)
{
if (!lyxrc.use_gui) {
lyxerr << "----------------------------------------" << endl
<< s1 << endl;
if (!s2.empty())
lyxerr << s2 << endl;
if (!s3.empty())
lyxerr << s3 << endl;
lyxerr << "Assuming answer is ";
if (default_value == 1)
lyxerr << "yes";
else if (default_value == 2)
lyxerr << "no";
else
lyxerr << "cancel";
lyxerr << endl
<< "----------------------------------------" << endl;
return default_value;
} else {
return askConfirmation_pimpl(s1, s2, s3);
}
}
pair<bool, string> const Alert::askForText(string const & msg,
string const & dflt)
{
if (!lyxrc.use_gui) {
lyxerr << "----------------------------------------" << endl
<< msg << endl
<< "Assuming answer is " << dflt
<< "----------------------------------------" << endl;
return make_pair<bool, string>(true, dflt);
} else {
return askForText_pimpl(msg, dflt);
}
}