]> git.lyx.org Git - lyx.git/blobdiff - src/LyX.cpp
A little more lv cleanup.
[lyx.git] / src / LyX.cpp
index e2e5b0c925a9ab378eafcebc947449a845c0a93a..2fe6b90f8edca70d19ffbf2a6d4fee203f405939 100644 (file)
@@ -25,6 +25,7 @@
 #include "ConverterCache.h"
 #include "Converter.h"
 #include "CutAndPaste.h"
+#include "EnchantChecker.h"
 #include "Encoding.h"
 #include "ErrorList.h"
 #include "Format.h"
@@ -34,8 +35,8 @@
 #include "Language.h"
 #include "LayoutFile.h"
 #include "Lexer.h"
+#include "LyX.h"
 #include "LyXAction.h"
-#include "LyXFunc.h"
 #include "LyXRC.h"
 #include "ModuleList.h"
 #include "Mover.h"
@@ -122,7 +123,7 @@ void reconfigureUserLyXDir()
 /// The main application class private implementation.
 struct LyX::Impl
 {
-       Impl() : spell_checker_(0), aspell_checker_(0), hunspell_checker_(0)
+       Impl() : spell_checker_(0), aspell_checker_(0), enchant_checker_(0), hunspell_checker_(0)
        {
                // Set the default User Interface language as soon as possible.
                // The language used will be derived from the environment
@@ -133,11 +134,10 @@ struct LyX::Impl
        ~Impl()
        {
                delete aspell_checker_;
+               delete enchant_checker_;
                delete hunspell_checker_;
        }
 
-       /// our function handler
-       LyXFunc lyxfunc_;
        ///
        BufferList buffer_list_;
        ///
@@ -182,6 +182,8 @@ struct LyX::Impl
        ///
        SpellChecker * aspell_checker_;
        ///
+       SpellChecker * enchant_checker_;
+       ///
        SpellChecker * hunspell_checker_;
 };
 
@@ -271,7 +273,7 @@ int LyX::exec(int & argc, char * argv[])
        easyParse(argc, argv);
 
        try {
-               init_package(to_utf8(from_local8bit(argv[0])),
+               init_package(os::utf8_argv(0),
                              cl_system_support, cl_user_support,
                              top_build_dir_is_one_level_up);
        } catch (ExceptionMessage const & message) {
@@ -350,8 +352,8 @@ int LyX::exec(int & argc, char * argv[])
        */
        // Note: socket callback must be registered after init(argc, argv)
        // such that package().temp_dir() is properly initialized.
-       pimpl_->lyx_server_.reset(new Server(&pimpl_->lyxfunc_, lyxrc.lyxpipes));
-       pimpl_->lyx_socket_.reset(new ServerSocket(&pimpl_->lyxfunc_,
+       pimpl_->lyx_server_.reset(new Server(lyxrc.lyxpipes));
+       pimpl_->lyx_socket_.reset(new ServerSocket(
                        FileName(package().temp_dir().absFilename() + "/lyxsocket")));
 
        // Start the real execution loop.
@@ -429,7 +431,7 @@ int LyX::init(int & argc, char * argv[])
                if (argv[argi][0] == '-') {
                        lyxerr << to_utf8(
                                bformat(_("Wrong command line option `%1$s'. Exiting."),
-                               from_utf8(argv[argi]))) << endl;
+                               from_utf8(os::utf8_argv(argi)))) << endl;
                        return EXIT_FAILURE;
                }
        }
@@ -443,7 +445,7 @@ int LyX::init(int & argc, char * argv[])
 
        // Remaining arguments are assumed to be files to load.
        for (int argi = argc - 1; argi >= 1; --argi)
-               pimpl_->files_to_load_.push_back(to_utf8(from_local8bit(argv[argi])));
+               pimpl_->files_to_load_.push_back(os::utf8_argv(argi));
 
        if (first_start) {
                pimpl_->files_to_load_.push_back(
@@ -513,27 +515,27 @@ void LyX::execCommands()
                {
                case 0:
                        // regular reconfigure
-                       pimpl_->lyxfunc_.dispatch(FuncRequest(LFUN_RECONFIGURE, ""));
+                       lyx::dispatch(FuncRequest(LFUN_RECONFIGURE, ""));
                        break;
                case 1:
                        // reconfigure --without-latex-config
-                       pimpl_->lyxfunc_.dispatch(FuncRequest(LFUN_RECONFIGURE,
+                       lyx::dispatch(FuncRequest(LFUN_RECONFIGURE,
                                " --without-latex-config"));
                        break;
                default:
-                       pimpl_->lyxfunc_.dispatch(FuncRequest(LFUN_LYX_QUIT));
+                       lyx::dispatch(FuncRequest(LFUN_LYX_QUIT));
                        return;
                }
        }
        
        // create the first main window
-       pimpl_->lyxfunc_.dispatch(FuncRequest(LFUN_WINDOW_NEW, geometryArg));
+       lyx::dispatch(FuncRequest(LFUN_WINDOW_NEW, geometryArg));
 
        if (!pimpl_->files_to_load_.empty()) {
                // if some files were specified at command-line we assume that the
                // user wants to edit *these* files and not to restore the session.
                for (size_t i = 0; i != pimpl_->files_to_load_.size(); ++i) {
-                       pimpl_->lyxfunc_.dispatch(
+                       lyx::dispatch(
                                FuncRequest(LFUN_FILE_OPEN, pimpl_->files_to_load_[i]));
                }
                // clear this list to save a few bytes of RAM
@@ -549,7 +551,7 @@ void LyX::execCommands()
        vector<string>::const_iterator bcend = pimpl_->batch_commands.end();
        for (; bcit != bcend; bcit++) {
                LYXERR(Debug::INIT, "About to handle -x '" << *bcit << '\'');
-               pimpl_->lyxfunc_.dispatch(lyxaction.lookupFunc(*bcit));
+               lyx::dispatch(lyxaction.lookupFunc(*bcit));
        }
 }
 
@@ -609,21 +611,23 @@ static void error_handler(int err_sig)
 
        // This shouldn't matter here, however, as we've already invoked
        // emergencyCleanup.
+       docstring msg;
        switch (err_sig) {
 #ifdef SIGHUP
        case SIGHUP:
-               lyxerr << "\nlyx: SIGHUP signal caught\nBye." << endl;
+               msg = _("SIGHUP signal caught!\nBye.");
                break;
 #endif
        case SIGFPE:
-               lyxerr << "\nlyx: SIGFPE signal caught\nBye." << endl;
+               msg = _("SIGFPE signal caught!\nBye.");
                break;
        case SIGSEGV:
-               lyxerr << "\nlyx: SIGSEGV signal caught\n"
-                         "Sorry, you have found a bug in LyX. "
+               msg = _("SIGSEGV signal caught!\n"
+                         "Sorry, you have found a bug in LyX, "
+                         "hope you have not lost any data.\n"
                          "Please read the bug-reporting instructions "
-                         "in Help->Introduction and send us a bug report, "
-                         "if necessary. Thanks !\nBye." << endl;
+                         "in 'Help->Introduction' and send us a bug report, "
+                         "if necessary. Thanks !\nBye.");
                break;
        case SIGINT:
        case SIGTERM:
@@ -631,6 +635,12 @@ static void error_handler(int err_sig)
                break;
        }
 
+       if (!msg.empty()) {
+               lyxerr << "\nlyx: " << msg << endl;
+               // try to make a GUI message
+               Alert::error(_("LyX crashed!"), msg);
+       }
+
        // Deinstall the signal handlers
 #ifdef SIGHUP
        signal(SIGHUP, SIG_DFL);
@@ -642,11 +652,18 @@ static void error_handler(int err_sig)
 
 #ifdef SIGHUP
        if (err_sig == SIGSEGV ||
-           (err_sig != SIGHUP && !getEnv("LYXDEBUG").empty()))
+               (err_sig != SIGHUP && !getEnv("LYXDEBUG").empty())) {
+#else
+       if (err_sig == SIGSEGV || !getEnv("LYXDEBUG").empty()) {
+#endif 
+#ifdef _MSC_VER
+               // with abort() it crashes again.
+               exit(err_sig);
 #else
-       if (err_sig == SIGSEGV || !getEnv("LYXDEBUG").empty())
-#endif
                abort();
+#endif
+       }
+
        exit(0);
 }
 
@@ -750,7 +767,7 @@ bool LyX::init()
        if (!LyXSetStyle())
                return false;
        //...and the modules
-       moduleList.read();
+       theModuleList.read();
 
        // read keymap and ui files in batch mode as well
        // because InsetInfo needs to know these to produce
@@ -765,8 +782,6 @@ bool LyX::init()
        // load user bind file user.bind
        pimpl_->toplevel_keymap_.read("user", 0, KeyMap::MissingOK);
 
-       pimpl_->lyxfunc_.initKeySequences(&pimpl_->toplevel_keymap_);
-
        if (lyxerr.debugging(Debug::LYXRC))
                lyxrc.print();
 
@@ -959,7 +974,7 @@ int parse_dbg(string const & arg, string const &, string &)
        }
        lyxerr << to_utf8(bformat(_("Setting debug level to %1$s"), from_utf8(arg))) << endl;
 
-       lyxerr.level(Debug::value(arg));
+       lyxerr.setLevel(Debug::value(arg));
        Debug::showLevel(lyxerr, lyxerr.level());
        return 1;
 }
@@ -987,7 +1002,7 @@ int parse_help(string const &, string const &, string &)
                  "\t-i [--import] fmt file.xxx\n"
                  "                  where fmt is the import format of choice\n"
                  "                  and file.xxx is the file to be imported.\n"
-                 "\t--batch         execute commands and exit\n"
+                 "\t-batch          execute commands without launching GUI and exit.\n"
                  "\t-version        summarize version and build info\n"
                               "Check the LyX man page for more details.")) << endl;
        exit(0);
@@ -1110,7 +1125,7 @@ void LyX::easyParse(int & argc, char * argv[])
        cmdmap["-i"] = parse_import;
        cmdmap["--import"] = parse_import;
        cmdmap["-geometry"] = parse_geometry;
-       cmdmap["--batch"] = parse_batch;
+       cmdmap["-batch"] = parse_batch;
 
        for (int i = 1; i < argc; ++i) {
                map<string, cmd_helper>::const_iterator it
@@ -1121,9 +1136,9 @@ void LyX::easyParse(int & argc, char * argv[])
                        continue;
 
                string const arg =
-                       (i + 1 < argc) ? to_utf8(from_local8bit(argv[i + 1])) : string();
+                       (i + 1 < argc) ? os::utf8_argv(i + 1) : string();
                string const arg2 =
-                       (i + 2 < argc) ? to_utf8(from_local8bit(argv[i + 2])) : string();
+                       (i + 2 < argc) ? os::utf8_argv(i + 2) : string();
 
                string batch;
                int const remove = 1 + it->second(arg, arg2, batch);
@@ -1133,6 +1148,7 @@ void LyX::easyParse(int & argc, char * argv[])
                // Now, remove used arguments by shifting
                // the following ones remove places down.
                if (remove > 0) {
+                       os::remove_internal_args(i, remove);
                        argc -= remove;
                        for (int j = i; j < argc; ++j)
                                argv[j] = argv[j + remove];
@@ -1144,29 +1160,29 @@ void LyX::easyParse(int & argc, char * argv[])
 
 FuncStatus getStatus(FuncRequest const & action)
 {
-       LASSERT(singleton_, /**/);
-       return singleton_->pimpl_->lyxfunc_.getStatus(action);
+       LASSERT(theApp(), /**/);
+       return theApp()->getStatus(action);
 }
 
 
 void dispatch(FuncRequest const & action)
 {
-       LASSERT(singleton_, /**/);
-       singleton_->pimpl_->lyxfunc_.dispatch(action);
+       LASSERT(theApp(), /**/);
+       return theApp()->dispatch(action);
 }
 
 
-BufferList & theBufferList()
+void dispatch(FuncRequest const & action, DispatchResult & dr)
 {
-       LASSERT(singleton_, /**/);
-       return singleton_->pimpl_->buffer_list_;
+       LASSERT(theApp(), /**/);
+       return theApp()->dispatch(action, dr);
 }
 
 
-LyXFunc & theLyXFunc()
+BufferList & theBufferList()
 {
        LASSERT(singleton_, /**/);
-       return singleton_->pimpl_->lyxfunc_;
+       return singleton_->pimpl_->buffer_list_;
 }
 
 
@@ -1237,14 +1253,14 @@ Movers & theSystemMovers()
 }
 
 
-Messages & getMessages(string const & language)
+Messages const & getMessages(string const & language)
 {
        LASSERT(singleton_, /**/);
        return singleton_->messages(language);
 }
 
 
-Messages & getGuiMessages()
+Messages const & getGuiMessages()
 {
        LASSERT(singleton_, /**/);
        return singleton_->pimpl_->messages_["GUI"];
@@ -1290,6 +1306,14 @@ void setSpellChecker()
                return;
        }
 #endif
+#if defined(USE_ENCHANT)
+       if (lyxrc.spellchecker == "enchant") {
+               if (!singleton_->pimpl_->enchant_checker_)
+                       singleton_->pimpl_->enchant_checker_ = new EnchantChecker();
+               singleton_->pimpl_->spell_checker_ = singleton_->pimpl_->enchant_checker_;
+               return;
+       }
+#endif
 #if defined(USE_HUNSPELL)
        if (lyxrc.spellchecker == "hunspell") {
                if (!singleton_->pimpl_->hunspell_checker_)