#include "support/lyxfunctional.h" // equal_1st_in_pair
#include "support/types.h"
#include "support/lyxalgo.h" // lyx_count
+#include "BoostFormat.h"
#include <fstream>
ifstream ifs(fname.c_str());
if (!ifs) {
- Alert::err_alert(_("Error! Cannot open specified file:"),
- MakeDisplayPath(fname, 50));
+ string const error = strerror(errno);
+ string const file = MakeDisplayPath(fname, 50);
+#if USE_BOOST_FORMAT
+ boost::format fmt(_("Could not open the specified document\n%1$s\ndue to the error: %2$s"));
+ fmt % file;
+ fmt % error;
+ string text = fmt.str();
+#else
+ string text = _("Could not open the specified document\n");
+ text += file + _(" due to the error: ");
+ text += error;
+#endif
+ Alert::error(_("Could not open file"), text);
return false;
}
+2003-03-29 John Levon <levon@movementarian.org>
+
+ * lyx_cb.C:
+ * BufferView.C:
+ * buffer.C: warnings pushed down from support/,
+ kill err_alert
+
2003-03-29 John Levon <levon@movementarian.org>
* lyxfunc.C: safety check for C-r (revert)
if (users)
users->buffer(0);
- if (!tmppath.empty()) {
- DestroyBufferTmpDir(tmppath);
+ if (!tmppath.empty() && destroyDir(tmppath) != 0) {
+#if USE_BOOST_FORMAT
+ boost::format fmt = _("Could not remove the temporary directory %1$s");
+ fmt % tmppath;
+ string msg = fmt.str();
+#else
+ string msg = _("Could not remove the temporary directory ") + tmppath;
+#endif
+ Alert::warning(_("Could not remove temporary directory"), msg);
}
paragraphs.clear();
{
ofstream ofs(fname.c_str());
if (!ofs) {
- Alert::err_alert(_("Error: Cannot write file:"), fname);
+ string const error = strerror(errno);
+ string const file = MakeDisplayPath(fname, 50);
+#if USE_BOOST_FORMAT
+ boost::format fmt(_("Could not save the document\n%1$s\ndue to the error: %2$s"));
+ fmt % file;
+ fmt % error;
+ string text = fmt.str();
+#else
+ string text = _("Could not save the document\n");
+ text += file + _(" due to the error: ");
+ text += error;
+#endif
+ Alert::error(_("Could not save document"), text);
return;
}
writeFileAscii(ofs, linelen);
ofstream ofs(fname.c_str());
if (!ofs) {
- Alert::err_alert(_("Error: Cannot open file: "), fname);
+ string const error = strerror(errno);
+ string const file = MakeDisplayPath(fname, 50);
+#if USE_BOOST_FORMAT
+ boost::format fmt(_("Could not open the specified document\n%1$s\ndue to the error: %2$s"));
+ fmt % file;
+ fmt % error;
+ string text = fmt.str();
+#else
+ string text = _("Could not open the specified document\n");
+ text += file + _(" due to the error: ");
+ text += error;
+#endif
+ Alert::error(_("Could not open file"), text);
return;
}
#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) {
}
-void Alert::err_alert(string const & s1, string const & s2)
-{
- alert(s1, s2, strerror(errno));
-}
-
-
int Alert::prompt(string const & title, string const & question,
int default_button,
string const & b1, string const & b2, string const & b3)
}
+void Alert::warning(string const & title, string const & message)
+{
+ if (lyxrc.use_gui)
+ return warning_pimpl(title, message);
+
+ lyxerr << "Warning: " << title << endl;
+ lyxerr << "----------------------------------------" << endl;
+ lyxerr << message << endl;
+}
+
+
+void Alert::error(string const & title, string const & message)
+{
+ if (lyxrc.use_gui)
+ return error_pimpl(title, message);
+
+ lyxerr << "Error: " << title << endl;
+ lyxerr << "----------------------------------------" << endl;
+ lyxerr << message << endl;
+}
+
+
+void Alert::information(string const & title, string const & message)
+{
+ if (lyxrc.use_gui)
+ return information_pimpl(title, message);
+
+ lyxerr << title << endl;
+ lyxerr << "----------------------------------------" << endl;
+ lyxerr << message << endl;
+}
+
+
pair<bool, string> const Alert::askForText(string const & msg,
string const & dflt)
{
int default_button,
string const & b1, string const & b2, string const & b3 = string());
-/// show an alert message
+/**
+ * Display a warning to the user. Title should be a short summary.
+ * Only use this if the user cannot perform some remedial action.
+ */
+void warning(string const & title, string const & message);
+
+/**
+ * Display a warning to the user. Title should be a short summary.
+ * Only use this if the user cannot perform some remedial action.
+ */
+void error(string const & title, string const & message);
+
+/**
+ * Informational message. Use very very sparingly. That is, you must
+ * apply to me, in triplicate, under the sea, breathing in petrol
+ * and reciting the Nicene Creed, whilst running uphill and also
+ * eating.
+ */
+void information(string const & title, string const & message);
+
+/// show an alert message. DO NOT USE !!
void alert(string const & title, string const & s1 = string(),
string const & s2 = string());
-/// show an alert message and strerror(errno)
-void err_alert(string const & s1, string const & s2 = string());
-
-/// Asks for a text
+/// Asks for a text. DO NOT USE !!
std::pair<bool, string> const
askForText(string const & msg,
string const & dflt = string());
int default_button,
string const & b1, string const & b2, string const & b3);
+void warning_pimpl(string const & title, string const & warning);
+void error_pimpl(string const & title, string const & warning);
+void information_pimpl(string const & title, string const & warning);
+
std::pair<bool, string> const askForText_pimpl(string const & msg, string const & dflt);
+2003-03-29 John Levon <levon@movementarian.org>
+
+ * Alert.h:
+ * Alert.C:
+ * Alert_pimpl.h: kill err_alert. Add information(),
+ warning(), error()
+
2003-03-29 John Levon <levon@movementarian.org>
* Alert.h:
}
+void warning_pimpl(string const & tit, string const & message)
+{
+#if USE_BOOST_FORMAT
+ boost::format fmt(_("LyX: %1$s"));
+ fmt % tit;
+ string const title = fmt.str();
+#else
+ string const title = _("LyX: ") + tit;
+#endif
+ QMessageBox::warning(0, toqstr(title), toqstr(formatted(message)));
+}
+
+
+void error_pimpl(string const & tit, string const & message)
+{
+#if USE_BOOST_FORMAT
+ boost::format fmt(_("LyX: %1$s"));
+ fmt % tit;
+ string const title = fmt.str();
+#else
+ string const title = _("LyX: ") + tit;
+#endif
+ QMessageBox::critical(0, toqstr(title), toqstr(formatted(message)));
+}
+
+
+void information_pimpl(string const & tit, string const & message)
+{
+#if USE_BOOST_FORMAT
+ boost::format fmt(_("LyX: %1$s"));
+ fmt % tit;
+ string const title = fmt.str();
+#else
+ string const title = _("LyX: ") + tit;
+#endif
+ QMessageBox::information(0, toqstr(title), toqstr(formatted(message)));
+}
+
+
pair<bool, string> const
askForText_pimpl(string const & msg, string const & dflt)
{
+2003-03-29 John Levon <levon@movementarian.org>
+
+ * Alert_pimpl.C: implement warning(), information(), error()
+
2003-03-29 John Levon <levon@movementarian.org>
* Alert_pimpl.C: implement prompt()
}
+void warning_pimpl(string const &, string const & message)
+{
+ fl_show_messages(message.c_str());
+}
+
+
+void error_pimpl(string const &, string const & message)
+{
+ fl_show_messages(message.c_str());
+}
+
+
+void information_pimpl(string const &, string const & message)
+{
+ fl_show_messages(message.c_str());
+}
+
+
int prompt_pimpl(string const &, string const & question,
int default_button,
string const & b1, string const & b2, string const & b3)
+2003-03-29 John Levon <levon@movementarian.org>
+
+ * Alert_pimpl.C: implement information(), warning(), error()
+
2003-03-29 John Levon <levon@movementarian.org>
* xforms_helpers.h:
// Opens directory
DIR * dir = ::opendir(directory_.c_str());
if (!dir) {
+// FIXME: re-add ...
+#if 0
Alert::err_alert(_("Warning! Couldn't open directory."),
directory_);
+#endif
directory_ = lyx::getcwd();
dir = ::opendir(directory_.c_str());
}
// must check the directory exists
DIR * dir = ::opendir(tmp.c_str());
if (!dir) {
+// FIXME: re-add ...
+#if 0
Alert::err_alert(_("Warning! Couldn't open directory."), tmp);
+#endif
} else {
::closedir(dir);
directory_ = tmp;
// do any other cleanup procedures now
lyxerr[Debug::INFO] << "Deleting tmp dir " << system_tempdir << endl;
- DestroyLyXTmpDir(system_tempdir);
+ if (destroyDir(system_tempdir) != 0) {
+#if USE_BOOST_FORMAT
+ boost::format fmt = _("Could not remove the temporary directory %1$s");
+ fmt % system_tempdir;
+ string msg = fmt.str();
+#else
+ string msg = _("Could not remove the temporary directory ") + system_tempdir;
+#endif
+ Alert::warning(_("Could not remove temporary directory"), msg);
+ }
lyx_gui::exit();
}
FileInfo fi(fname);
if (!fi.readable()) {
- Alert::err_alert(_("Error! Specified file is unreadable: "),
- MakeDisplayPath(fname, 50));
+ string const error = strerror(errno);
+ string const file = MakeDisplayPath(fname, 50);
+#if USE_BOOST_FORMAT
+ boost::format fmt(_("Could not read the specified document\n%1$s\ndue to the error: %2$s"));
+ fmt % file;
+ fmt % error;
+ string text = fmt.str();
+#else
+ string text = _("Could not read the specified document\n");
+ text += file + _(" due to the error: ");
+ text += error;
+#endif
+ Alert::error(_("Could not read file"), text);
return string();
}
ifstream ifs(fname.c_str());
if (!ifs) {
- Alert::err_alert(_("Error! Cannot open specified file:"),
- MakeDisplayPath(fname, 50));
+ string const error = strerror(errno);
+ string const file = MakeDisplayPath(fname, 50);
+#if USE_BOOST_FORMAT
+ boost::format fmt(_("Could not open the specified document\n%1$s\ndue to the error: %2$s"));
+ fmt % file;
+ fmt % error;
+ string text = fmt.str();
+#else
+ string text = _("Could not open the specified document\n");
+ text += file + _(" due to the error: ");
+ text += error;
+#endif
+ Alert::error(_("Could not open file"), text);
return string();
}
p.pop();
bv->owner()->message(_("Reloading configuration..."));
lyxrc.read(LibFileSearch(string(), "lyxrc.defaults"));
- Alert::alert(_("The system has been reconfigured."),
- _("You need to restart LyX to make use of any"),
- _("updated document class specifications."));
+
+ Alert::information(_("System reconfigured"),
+ _("The system has been reconfigured.\n"
+ "You need to restart LyX to make use of any \n"
+ "updated document class specifications."));
}
+2003-03-29 John Levon <levon@movementarian.org>
+
+ * filetools.h:
+ * filetools.C: never call Alert directly from here
+
2003-03-12 John Levon <levon@movementarian.org>
* textutils.h: remove META_NEWLINE
#include "debug.h"
#include "support/lstrings.h"
#include "support/systemcall.h"
+#include "support/LAssert.h"
#include "filetools.h"
#include "lstrings.h"
-#include "frontends/Alert.h"
#include "FileInfo.h"
#include "support/path.h" // I know it's OS/2 specific (SMiyata)
#include "gettext.h"
// directory_iterator dit(path);
// directory_iterator dend;
// if (dit == dend) {
- // Alert::err_alert(_("Error! Cannot open directory:"), path);
// return -1;
// }
// for (; dit != dend; ++dit) {
// if (filename == "." || filename == "..")
// continue;
// string unlinkpath(AddName(path, filename));
- // if (lyx::unlink(unlinkpath))
- // Alert::err_alert(_("Error! Could not remove file:"),
- // unlinkpath);
+ // lyx::unlink(unlinkpath);
// }
// return 0;
DIR * dir = ::opendir(path.c_str());
- if (!dir) {
- Alert::err_alert (_("Error! Cannot open directory:"), path);
+ if (!dir)
return -1;
- }
+
struct dirent * de;
int return_value = 0;
while ((de = readdir(dir))) {
if (fi.isOK() && fi.isDir())
deleted = (DeleteAllFilesInDir(unlinkpath) == 0);
deleted &= (lyx::unlink(unlinkpath) == 0);
- if (!deleted) {
- Alert::err_alert(_("Error! Could not remove file:"),
- unlinkpath);
+ if (!deleted)
return_value = -1;
- }
}
closedir(dir);
return return_value;
// safe because of the gap between unlink and mkdir. (Lgb)
lyx::unlink(tmpfl.c_str());
- if (tmpfl.empty() || lyx::mkdir(tmpfl, 0700)) {
- Alert::err_alert(_("Error! Couldn't create temporary directory:"),
- tempdir);
+ if (tmpfl.empty() || lyx::mkdir(tmpfl, 0700))
return string();
- }
+
return MakeAbsPath(tmpfl);
}
+} // namespace anon
+
-int DestroyTmpDir(string const & tmpdir, bool Allfiles)
+int destroyDir(string const & tmpdir)
{
#ifdef __EMX__
Path p(user_lyxdir);
#endif
- if (Allfiles && DeleteAllFilesInDir(tmpdir)) {
+ if (DeleteAllFilesInDir(tmpdir))
return -1;
- }
- if (lyx::rmdir(tmpdir)) {
- Alert::err_alert(_("Error! Couldn't delete temporary directory:"),
- tmpdir);
+
+ if (lyx::rmdir(tmpdir))
return -1;
- }
+
return 0;
}
-} // namespace anon
-
string const CreateBufferTmpDir(string const & pathfor)
{
// of EMX mkstemp().
string const tmpfl = tmpdir + "/lyx_tmpbuf" + tostr(count++);
if (lyx::mkdir(tmpfl, 0777)) {
- Alert::err_alert(_("Error! Couldn't create temporary directory:"),
- tmpdir);
return string();
}
return tmpfl;
}
-int DestroyBufferTmpDir(string const & tmpdir)
-{
- return DestroyTmpDir(tmpdir, true);
-}
-
-
string const CreateLyXTmpDir(string const & deflt)
{
if ((!deflt.empty()) && (deflt != "/tmp")) {
}
-// FIXME: no need for separate method like this ...
-int DestroyLyXTmpDir(string const & tmpdir)
-{
- return DestroyTmpDir(tmpdir, true);
-}
-
-
-// Creates directory. Returns true if succesfull
bool createDirectory(string const & path, int permission)
{
string temp(rtrim(os::slashify_path(path), "/"));
- if (temp.empty()) {
- Alert::alert(_("Internal error!"),
- _("Call to createDirectory with invalid name"));
- return false;
- }
+ lyx::Assert(!temp.empty());
- if (lyx::mkdir(temp, permission)) {
- Alert::err_alert (_("Error! Couldn't create directory:"), temp);
+ if (lyx::mkdir(temp, permission))
return false;
- }
+
return true;
}
a += OnlyFilename(filename);
a += '#';
FileInfo const fileinfo(a);
- if (fileinfo.exist()) {
- if (lyx::unlink(a) != 0) {
- Alert::err_alert(_("Could not delete auto-save file!"), a);
- }
- }
+ if (fileinfo.exist())
+ lyx::unlink(a);
}
#include "LString.h"
+/// remove directory and all contents, returns 0 on success
+int destroyDir(string const & tmpdir);
+
///
string const CreateBufferTmpDir(string const & pathfor = string());
-/// Creates directory. Returns true on succes.
+/// Creates directory. Returns true on success
bool createDirectory(string const & name, int permissions);
///
string const CreateLyXTmpDir(string const & deflt);
-///
-int DestroyBufferTmpDir(string const & tmpdir);
-
-///
-int DestroyLyXTmpDir(string const & tmpdir);
-
/** Find file by searching several directories.
Uses a string of paths separated by ";"s to find a file to open.
Can't cope with pathnames with a ';' in them. Returns full path to file.