]> git.lyx.org Git - features.git/commitdiff
Display error/warning dialogs if possible.
authorAbdelrazak Younes <younes@lyx.org>
Wed, 24 Jan 2007 15:49:20 +0000 (15:49 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Wed, 24 Jan 2007 15:49:20 +0000 (15:49 +0000)
* ExceptionMessage: new exception based message for errors and warnings.

* package.C.in:
  - replace lyxerr based errors and warning with ExceptionMessage throwing.
  - bail_out(): erased!

* os_win32.C:
  - replace lyxerr based errors and warning with ExceptionMessage throwing.
  - bail_out(): erased!

* tex2lyx.C: catch any exception from Package class.

* lyx_main.C:  catch any exception from Package class and act accordingly.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16834 a592a061-630c-0410-9148-cb99ea01b6c8

development/scons/scons_manifest.py
src/lyx_main.C
src/support/ExceptionMessage.h [new file with mode: 0644]
src/support/Makefile.am
src/support/os_win32.C
src/support/package.C.in
src/tex2lyx/tex2lyx.C

index 51f1ff2fb2870ca485b500dfd998aa76689ef495..ca5317b55acc39091a47837a4d6532f468bb717e 100644 (file)
@@ -99,6 +99,7 @@ src_support_header_files = Split('''
     docstream.h
     docstring.h
     environment.h
+    ExceptionMessage.h
     filefilterlist.h
     filename.h
     filetools.h
index b0a6b1713ada4db0815b9b6014ee6c6ea47ee550..97f71100ff10ece894cf3e99837d70daf1cdbd23 100644 (file)
@@ -53,6 +53,7 @@
 #include "support/filetools.h"
 #include "support/lyxlib.h"
 #include "support/convert.h"
+#include "support/ExceptionMessage.h"
 #include "support/os.h"
 #include "support/package.h"
 #include "support/path.h"
@@ -395,9 +396,17 @@ int LyX::exec(int & argc, char * argv[])
        // we need to parse for "-dbg" and "-help"
        easyParse(argc, argv);
 
-       support::init_package(to_utf8(from_local8bit(argv[0])),
+       try { support::init_package(to_utf8(from_local8bit(argv[0])),
                              cl_system_support, cl_user_support,
                              support::top_build_dir_is_one_level_up);
+       } catch (support::ExceptionMessage const & message) {
+               if (message.type_ == support::ErrorException) {
+                       Alert::error(message.title_, message.details_);
+                       exit(1);
+               } else if (message.type_ == support::WarningException) {
+                       Alert::warning(message.title_, message.details_);
+               }
+       }
 
        if (!use_gui) {
                // FIXME: create a ConsoleApplication
diff --git a/src/support/ExceptionMessage.h b/src/support/ExceptionMessage.h
new file mode 100644 (file)
index 0000000..dc597c6
--- /dev/null
@@ -0,0 +1,49 @@
+// -*- C++ -*-
+/**
+ * \file ExceptionMessage.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ *
+ * A store of the paths to the various different directoies used
+ * by LyX. These paths differ markedly from one OS to another,
+ * following the local Windows, MacOS X or Posix conventions.
+ */
+#ifndef LYX_MESSAGE_H
+#define LYX_MESSAGE_H
+
+#include "support/docstring.h"
+
+#include <exception>
+
+namespace lyx {
+namespace support {
+
+
+enum ExceptionType {
+       ErrorException,
+       WarningException
+};
+
+
+class ExceptionMessage: public std::exception {
+public:
+       ExceptionMessage(ExceptionType type, docstring const & title,
+               docstring const & details)
+               : exception((to_utf8(title) + "\n" + to_utf8(details)).c_str()),
+       type_(type), title_(title), details_(details) {}
+
+       virtual ~ExceptionMessage() {}
+
+       ExceptionType type_;
+       docstring title_;
+       docstring details_;
+};
+
+} // namespace support
+} // namespace lyx
+
+#endif // LYX_MESSAGE_H
index 3ad9d9fc5fcf76cc2ffb716a38e2406cae9beba2..bb8e7a45c1263187a5966faeb9038db85f067884 100644 (file)
@@ -35,6 +35,7 @@ libsupport_la_SOURCES = \
        docstring.h \
        environment.h \
        environment.C \
+       ExceptionMessage.h \
        filefilterlist.C \
        filefilterlist.h \
        filename.C \
index daa977b73f8498211065b94aff36bee5efb21614..b5545b85e689db5926d21b8a7ac7e8198d2c6f10 100644 (file)
 #include "support/os_win32.h"
 #include "support/lstrings.h"
 #include "support/filetools.h"
+#include "support/ExceptionMessage.h"
 #include "support/package.h"
 #include "support/path.h"
 
 #include "debug.h"
+#include "gettext.h"
 
 #include <boost/assert.hpp>
 
@@ -324,36 +326,21 @@ void windows_style_tex_paths(bool use_windows_paths)
 }
 
 
-namespace {
-
-void bail_out()
-{
-#ifndef CXX_GLOBAL_CSTD
-       using std::exit;
-#endif
-       exit(1);
-}
-
-} // namespace anon
-
-
 GetFolderPath::GetFolderPath()
        : folder_module_(0),
          folder_path_func_(0)
 {
        folder_module_ = LoadLibrary("shfolder.dll");
        if (!folder_module_) {
-               lyxerr << "Unable to load shfolder.dll\nPlease install."
-                      << std::endl;
-               bail_out();
+               throw ExceptionMessage(ErrorException, _("System file not found"),
+                       _("Unable to load shfolder.dll\nPlease install."));
        }
 
        folder_path_func_ = reinterpret_cast<function_pointer>(::GetProcAddress(folder_module_, "SHGetFolderPathA"));
        if (folder_path_func_ == 0) {
-               lyxerr << "Unable to find SHGetFolderPathA in shfolder.dll\n"
-                         "Don't know how to proceed. Sorry."
-                      << std::endl;
-               bail_out();
+               throw ExceptionMessage(ErrorException, _("System function not found"),
+                       _("Unable to find SHGetFolderPathA in shfolder.dll\n"
+                         "Don't know how to proceed. Sorry."));
        }
 }
 
index 6edd7abde4470c8869571460440e1306c5780093..efe19c62727696173219dfe66d18032765d3f468 100644 (file)
@@ -22,6 +22,7 @@
 #include "support/environment.h"
 #include "support/filetools.h"
 #include "support/lstrings.h"
+#include "support/ExceptionMessage.h"
 #include "support/os.h"
 
 #if defined (USE_WINDOWS_PACKAGING)
@@ -369,15 +370,6 @@ string const get_temp_dir()
 }
 
 
-void bail_out()
-{
-#ifndef CXX_GLOBAL_CSTD
-       using std::exit;
-#endif
-       exit(1);
-}
-
-
 // Extracts the absolute path from the foo of "-sysdir foo" or "-userdir foo"
 string const abs_path_from_command_line(string const & command_line)
 {
@@ -440,11 +432,10 @@ string const abs_path_from_binary_name(string const & exe)
        string const abs_binary = get_binary_path(exe);
        if (abs_binary.empty()) {
                // FIXME UNICODE
-               lyxerr << lyx::to_utf8(bformat(_("Unable to determine the path to the "
-                                                "LyX binary from the command line %1$s"),
-                                                lyx::from_utf8(exe)))
-                      << std::endl;
-               bail_out();
+               throw ExceptionMessage(ErrorException,
+                       _("LyX binary not found"),
+                       bformat(_("Unable to determine the path to the LyX binary from the command line %1$s"),
+                               lyx::from_utf8(exe)));
        }
        return abs_binary;
 }
@@ -562,17 +553,16 @@ get_system_support_dir(string const & abs_binary,
        }
 
        // FIXME UNICODE
-       lyxerr << lyx::to_utf8(bformat(_("Unable to determine the system directory "
+       throw ExceptionMessage(ErrorException, _("No system directory"),
+               bformat(_("Unable to determine the system directory "
                                         "having searched\n"
                                         "\t%1$s\n"
                                         "Use the '-sysdir' command line parameter or "
                                         "set the environment variable LYX_DIR_15x to "
                                         "the LyX system directory containing the file "
                                         "`chkconfig.ltx'."),
-                         lyx::from_utf8(searched_dirs_str)))
-              << std::endl;
+                         lyx::from_utf8(searched_dirs_str)));
 
-       bail_out();
        // Keep the compiler happy.
        return string();
 }
@@ -648,11 +638,10 @@ bool check_command_line_dir(string const & dir,
        FileName const abs_path = fileSearch(dir, file);
        if (abs_path.empty()) {
                // FIXME UNICODE
-               lyxerr << lyx::to_utf8(bformat(_("Invalid %1$s switch.\n"
-                                                "Directory %2$s does not contain %3$s."),
-                                 lyx::from_utf8(command_line_switch), lyx::from_utf8(dir),
-                                 lyx::from_utf8(file)))
-                      << std::endl;
+               throw ExceptionMessage(WarningException, _("File not found"), bformat(
+                       _("Invalid %1$s switch.\nDirectory %2$s does not contain %3$s."),
+                       lyx::from_utf8(command_line_switch), lyx::from_utf8(dir),
+                       lyx::from_utf8(file)));
        }
 
        return !abs_path.empty();
@@ -676,10 +665,11 @@ bool check_env_var_dir(string const & dir,
        FileName const abs_path = fileSearch(dir, file);
        if (abs_path.empty()) {
                // FIXME UNICODE
-               lyxerr << lyx::to_utf8(bformat(_("Invalid %1$s environment variable.\n"
-                                                "Directory %2$s does not contain %3$s."),
-                                 lyx::from_utf8(env_var), lyx::from_utf8(dir), lyx::from_utf8(file)))
-                      << std::endl;
+               throw ExceptionMessage(WarningException, _("File not found"), bformat(
+                       _("Invalid %1$s environment variable.\n"
+                               "Directory %2$s does not contain %3$s."),
+                       lyx::from_utf8(env_var), lyx::from_utf8(dir),
+                       lyx::from_utf8(file)));
        }
 
        return !abs_path.empty();
@@ -703,8 +693,8 @@ bool check_env_var_dir(string const & dir,
                docstring const fmt =
                        _("Invalid %1$s environment variable.\n%2$s is not a directory.");
 
-               lyxerr << lyx::to_utf8(bformat(fmt, lyx::from_utf8(env_var), lyx::from_utf8(dir)))
-                      << std::endl;
+               throw ExceptionMessage(WarningException, _("Directory not found"), bformat(
+                       fmt, lyx::from_utf8(env_var), lyx::from_utf8(dir)));
        }
 
        return success;
index ac24bc5aa56c2d7e7bdba8f9805d1c6d8135ef99..2baf0e85506c731603bfc4519cb72a3b1e38a77d 100644 (file)
@@ -23,6 +23,7 @@
 #include "support/fs_extras.h"
 #include "support/lstrings.h"
 #include "support/lyxlib.h"
+#include "support/ExceptionMessage.h"
 #include "support/os.h"
 #include "support/package.h"
 #include "support/unicode.h"
@@ -518,9 +519,16 @@ int main(int argc, char * argv[])
        }
 
        lyx::support::os::init(argc, argv);
-       support::init_package(to_utf8(from_local8bit(argv[0])),
+
+       try { support::init_package(to_utf8(from_local8bit(argv[0])),
                cl_system_support, cl_user_support,
                support::top_build_dir_is_two_levels_up);
+       } catch (support::ExceptionMessage const & message) {
+               cerr << to_utf8(message.title_) << ':\n'
+                       << to_utf8(message.details_) << endl;
+               if (message.type_ == support::ErrorException)
+                       exit(1);
+       }
 
        // Now every known option is parsed. Look for input and output
        // file name (the latter is optional).