]> git.lyx.org Git - lyx.git/blobdiff - src/LyX.cpp
Update the GuiLabel view when the document is read-only. Also disable the text field.
[lyx.git] / src / LyX.cpp
index 4038eae82d43d16aac99e3ff0db6d165e2fdac24..7b5c07636f00556e3b9fa21e5d44ecc3a9424b2c 100644 (file)
@@ -4,10 +4,10 @@
  * Licence details can be found in the file COPYING.
  *
  * \author Alfredo Braunstein
- * \author Lars Gullik Bjønnes
+ * \author Lars Gullik Bjønnes
  * \author Jean-Marc Lasgouttes
  * \author John Levon
- * \author André Pönitz
+ * \author André Pönitz
  *
  * Full author contact details are available in file CREDITS.
  */
 
 #include "LyX.h"
 
-#include "LayoutFile.h"
+#include "AspellChecker.h"
 #include "Buffer.h"
 #include "BufferList.h"
 #include "CmdDef.h"
-#include "Color.h"
+#include "ColorSet.h"
 #include "ConverterCache.h"
 #include "Converter.h"
 #include "CutAndPaste.h"
 #include "ErrorList.h"
 #include "Format.h"
 #include "FuncStatus.h"
+#include "HunspellChecker.h"
 #include "KeyMap.h"
 #include "Language.h"
+#include "LayoutFile.h"
 #include "Lexer.h"
 #include "LyXAction.h"
 #include "LyXFunc.h"
@@ -117,17 +119,23 @@ void reconfigureUserLyXDir()
 
 } // namespace anon
 
-
 /// The main application class private implementation.
 struct LyX::Impl
 {
-       Impl()
+       Impl() : spell_checker_(0), aspell_checker_(0), hunspell_checker_(0)
        {
                // Set the default User Interface language as soon as possible.
                // The language used will be derived from the environment
                // variables.
                messages_["GUI"] = Messages();
        }
+
+       ~Impl()
+       {
+               delete aspell_checker_;
+               delete hunspell_checker_;
+       }
+
        /// our function handler
        LyXFunc lyxfunc_;
        ///
@@ -169,6 +177,12 @@ struct LyX::Impl
 
        ///
        graphics::Previews preview_;
+       ///
+       SpellChecker * spell_checker_;
+       ///
+       SpellChecker * aspell_checker_;
+       ///
+       SpellChecker * hunspell_checker_;
 };
 
 ///
@@ -233,16 +247,19 @@ Messages & LyX::messages(string const & language)
 
 void setRcGuiLanguage()
 {
-       LASSERT(singleton_, "");
+       LASSERT(singleton_, /**/);
        if (lyxrc.gui_language == "auto")
                return;
        Language const * language = languages.getLanguage(lyxrc.gui_language);
-       LYXERR(Debug::LOCALE, "Setting LANGUAGE to " << language->code());
-       if (!setEnv("LANGUAGE", language->code()))
-               LYXERR(Debug::LOCALE, "\t... failed!");
+       if (language) {
+               LYXERR(Debug::LOCALE, "Setting LANGUAGE to " << language->code());
+               if (!setEnv("LANGUAGE", language->code()))
+                       LYXERR(Debug::LOCALE, "\t... failed!");
+       }
        LYXERR(Debug::LOCALE, "Setting LC_ALL to en_US");
        if (!setEnv("LC_ALL", "en_US"))
                LYXERR(Debug::LOCALE, "\t... failed!");
+       Messages::init();
        singleton_->pimpl_->messages_["GUI"] = Messages();
 }
 
@@ -293,12 +310,13 @@ int LyX::exec(int & argc, char * argv[])
                        Buffer * buf = *I;
                        if (buf != buf->masterBuffer())
                                continue;
-                       bool success = false;
                        vector<string>::const_iterator bcit  = pimpl_->batch_commands.begin();
                        vector<string>::const_iterator bcend = pimpl_->batch_commands.end();
+                       DispatchResult dr;
                        for (; bcit != bcend; bcit++) {
-                               buf->dispatch(*bcit, &success);
-                               final_success |= success;
+                               LYXERR(Debug::ACTION, "Buffer::dispatch: cmd: " << *bcit);
+                               buf->dispatch(*bcit, dr);
+                               final_success |= !dr.error();
                        }
                }
                prepareExit();
@@ -351,6 +369,9 @@ void LyX::prepareExit()
        cap::clearCutStack();
        cap::clearSelection();
 
+       // Write the index file of the converter cache
+       ConverterCache::get().writeIndex();
+
        // close buffers first
        pimpl_->buffer_list_.closeAll();
 
@@ -517,8 +538,7 @@ void LyX::execCommands()
                }
                // clear this list to save a few bytes of RAM
                pimpl_->files_to_load_.clear();
-       }
-       else
+       } else
                pimpl_->application_->restoreGuiSession();
 
        // Execute batch commands if available
@@ -541,7 +561,7 @@ The SIGHUP signal does not exist on Windows and does not need to be handled.
 
 Windows handles SIGFPE and SIGSEGV signals as expected.
 
-Cntl+C interrupts (mapped to SIGINT by Windows' POSIX compatability layer)
+Ctrl+C interrupts (mapped to SIGINT by Windows' POSIX compatability layer)
 cause a new thread to be spawned. This may well result in unexpected
 behaviour by the single-threaded LyX.
 
@@ -730,7 +750,7 @@ bool LyX::init()
        if (!LyXSetStyle())
                return false;
        //...and the modules
-       moduleList.load();
+       theModuleList.read();
 
        // read keymap and ui files in batch mode as well
        // because InsetInfo needs to know these to produce
@@ -743,9 +763,7 @@ bool LyX::init()
        pimpl_->toplevel_keymap_.read("site");
        pimpl_->toplevel_keymap_.read(lyxrc.bind_file);
        // load user bind file user.bind
-       pimpl_->toplevel_keymap_.read("user");
-
-       pimpl_->lyxfunc_.initKeySequences(&pimpl_->toplevel_keymap_);
+       pimpl_->toplevel_keymap_.read("user", 0, KeyMap::MissingOK);
 
        if (lyxerr.debugging(Debug::LYXRC))
                lyxrc.print();
@@ -939,7 +957,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;
 }
@@ -963,9 +981,11 @@ int parse_help(string const &, string const &, string &)
                  "                  where fmt is the export format of choice.\n"
                  "                  Look on Tools->Preferences->File formats->Format\n"
                  "                  to get an idea which parameters should be passed.\n"
+                 "                  Note that the order of -e and -x switches matters.\n"
                  "\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-version        summarize version and build info\n"
                               "Check the LyX man page for more details.")) << endl;
        exit(0);
@@ -1054,13 +1074,16 @@ int parse_import(string const & type, string const & file, string & batch)
 int parse_geometry(string const & arg1, string const &, string &)
 {
        geometryArg = arg1;
-#if defined(_WIN32) || (defined(__CYGWIN__) && defined(X_DISPLAY_MISSING))
-       // remove also the arg
-       return 1;
-#else
-       // don't remove "-geometry"
+       // don't remove "-geometry", it will be pruned out later in the
+       // frontend if need be.
        return -1;
-#endif
+}
+
+
+int parse_batch(string const &, string const &, string &) 
+{
+       use_gui = false;
+       return 0;
 }
 
 
@@ -1085,6 +1108,7 @@ void LyX::easyParse(int & argc, char * argv[])
        cmdmap["-i"] = parse_import;
        cmdmap["--import"] = parse_import;
        cmdmap["-geometry"] = parse_geometry;
+       cmdmap["--batch"] = parse_batch;
 
        for (int i = 1; i < argc; ++i) {
                map<string, cmd_helper>::const_iterator it
@@ -1245,4 +1269,34 @@ CmdDef & theTopLevelCmdDef()
        return singleton_->pimpl_->toplevel_cmddef_;
 }
 
+
+SpellChecker * theSpellChecker()
+{
+       if (!singleton_->pimpl_->spell_checker_)
+               setSpellChecker();
+       return singleton_->pimpl_->spell_checker_;
+}
+
+
+void setSpellChecker()
+{
+#if defined(USE_ASPELL)
+       if (lyxrc.spellchecker == "aspell") {
+               if (!singleton_->pimpl_->aspell_checker_)
+                       singleton_->pimpl_->aspell_checker_ = new AspellChecker();
+               singleton_->pimpl_->spell_checker_ = singleton_->pimpl_->aspell_checker_;
+               return;
+       }
+#endif
+#if defined(USE_HUNSPELL)
+       if (lyxrc.spellchecker == "hunspell") {
+               if (!singleton_->pimpl_->hunspell_checker_)
+                       singleton_->pimpl_->hunspell_checker_ = new HunspellChecker();
+               singleton_->pimpl_->spell_checker_ = singleton_->pimpl_->hunspell_checker_;
+               return;
+       }
+#endif
+       singleton_->pimpl_->spell_checker_ = 0;
+}
+
 } // namespace lyx