]> git.lyx.org Git - features.git/commitdiff
more Alert:: work
authorJohn Levon <levon@movementarian.org>
Sat, 29 Mar 2003 09:02:08 +0000 (09:02 +0000)
committerJohn Levon <levon@movementarian.org>
Sat, 29 Mar 2003 09:02:08 +0000 (09:02 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6625 a592a061-630c-0410-9148-cb99ea01b6c8

16 files changed:
src/BufferView.C
src/ChangeLog
src/buffer.C
src/frontends/Alert.C
src/frontends/Alert.h
src/frontends/Alert_pimpl.h
src/frontends/ChangeLog
src/frontends/qt2/Alert_pimpl.C
src/frontends/qt2/ChangeLog
src/frontends/xforms/Alert_pimpl.C
src/frontends/xforms/ChangeLog
src/frontends/xforms/FormFiledialog.C
src/lyx_cb.C
src/support/ChangeLog
src/support/filetools.C
src/support/filetools.h

index f78eab403d1509b7c216660dabc49344ac53e5f4..c0656c26314828d1d6fb7785b97e968e656748e2 100644 (file)
@@ -43,6 +43,7 @@
 #include "support/lyxfunctional.h" // equal_1st_in_pair
 #include "support/types.h"
 #include "support/lyxalgo.h" // lyx_count
+#include "BoostFormat.h"
 
 #include <fstream>
 
@@ -312,8 +313,19 @@ bool BufferView::insertLyXFile(string const & filen)
 
        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;
        }
 
index 3405e11785f6c88210f598d19256baf4635d56e2..2dbf519ca2703d21cca42c421b165a85f16e65c2 100644 (file)
@@ -1,3 +1,10 @@
+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)
index d0f44366737f1d7eae977a03cfaa02d741b46365..486bb4c14030d476e6fe46af3cebd6c28d364dae 100644 (file)
@@ -149,8 +149,15 @@ Buffer::~Buffer()
        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();
@@ -954,7 +961,19 @@ void Buffer::writeFileAscii(string const & fname, int linelen)
 {
        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);
@@ -982,7 +1001,19 @@ void Buffer::makeLaTeXFile(string const & fname,
 
        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;
        }
 
index 334e8d103ba84879a4de915378e71e2e0b3db763..5b39e2e5bcfeea29e3a460972a05fea8b237a11f 100644 (file)
 
 #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) {
@@ -40,12 +33,6 @@ void Alert::alert(string const & s1, string const & s2, string const & s3)
 }
 
 
-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)
@@ -66,6 +53,39 @@ int Alert::prompt(string const & title, string const & question,
 }
 
 
+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)
 {
index 0e235546a4a63feb80be761785f3ef8d2f1e1d5d..ead44a879d92026975b35b4190973d0188532937 100644 (file)
@@ -32,14 +32,31 @@ int prompt(string const & title, string const & question,
            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());
index b29d1fd9e014bd335137c2d5df3725fa45e44107..f9c587d5875acdfe3b4bb99761d1bbd9efbadf1d 100644 (file)
@@ -18,4 +18,8 @@ int prompt_pimpl(string const & title, string const & question,
            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);
index bc3802240eadc76e7d818b32a45b88b8d5114709..9ecdbe65308c55233afe67bbb71b4a7c45be1d90 100644 (file)
@@ -1,3 +1,10 @@
+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:
index b63b5805854d6126476a947afeabac64831679a9..ad38db003fe5dd632b5c41899ca9319ffacca29a 100644 (file)
@@ -55,6 +55,45 @@ int prompt_pimpl(string const & tit, string const & question,
 }
 
 
+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)
 {
index 5038e8191c7faaf209bea9c7f4242077c5946a61..df5f88d8541e3f1f0e6b26aaa1632eba091c006d 100644 (file)
@@ -1,3 +1,7 @@
+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()
index eed7b52495c4c5bc6d0779e25f550e372dca6375..298b4dfc1a13931f833d3b500113c6403bca2dde 100644 (file)
@@ -32,6 +32,24 @@ void alert_pimpl(string const & s1, string const & s2, string const & s3)
 }
 
 
+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)
index 0e95aa159174b58093f1eabf535679d6f18105b8..65103fcf7850d139e2488b3b47ed5cf8d10263c9 100644 (file)
@@ -1,3 +1,7 @@
+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:
index 0e9120de3eebb1a2cc0da3cadefeee22d678dfbb..a8fe2ec9c97c18af138b4cae80a1cd420af7ca8d 100644 (file)
@@ -188,8 +188,11 @@ void FileDialog::Private::Reread()
        // 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());
        }
@@ -357,7 +360,10 @@ void FileDialog::Private::SetDirectory(string const & path)
        // 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;
index f47700b01b843f6eb162ad2e6d7457eb2596829d..4230954a60bc6ad0ba3bda3ba032f1f79fcf962c 100644 (file)
@@ -229,7 +229,16 @@ void QuitLyX()
        // 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();
 }
@@ -426,15 +435,37 @@ string getContentsOfAsciiFile(BufferView * bv, string const & f, bool asParagrap
        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();
        }
 
@@ -513,7 +544,9 @@ void Reconfigure(BufferView * bv)
        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."));
 }
index 1b018abfa2a82fdb1fed18d3257fbed0a8a37024..8d847b017f3875b267afddabc6cf617da9119400 100644 (file)
@@ -1,3 +1,8 @@
+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
index 5a2f3f3dabf63822c04033fa9f1304104f1f652a..51ac03f9d0a9f23930663934dec268dec1c3147b 100644 (file)
 #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"
@@ -379,7 +379,6 @@ int DeleteAllFilesInDir(string const & path)
        // directory_iterator dit(path);
        // directory_iterator dend;
        // if (dit == dend) {
-       //         Alert::err_alert(_("Error! Cannot open directory:"), path);
        //         return -1;
        // }
        // for (; dit != dend; ++dit) {
@@ -387,16 +386,13 @@ int DeleteAllFilesInDir(string const & path)
        //         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))) {
@@ -413,11 +409,8 @@ int DeleteAllFilesInDir(string const & path)
                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;
@@ -437,33 +430,29 @@ string const CreateTmpDir(string const & tempdir, string const & mask)
        // 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)
 {
@@ -474,20 +463,12 @@ 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")) {
@@ -507,28 +488,15 @@ string const CreateLyXTmpDir(string const & deflt)
 }
 
 
-// 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;
 }
 
@@ -1303,11 +1271,8 @@ void removeAutosaveFile(string const & filename)
        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);
 }
 
 
index 35f4badfc91f04c013e64bb7a9d76431e451f24b..21e09e47d6e2d3314be943189a3557e56a20c005 100644 (file)
 #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.