]> git.lyx.org Git - lyx.git/blobdiff - src/LyX.cpp
adjust
[lyx.git] / src / LyX.cpp
index 9acbceb541357f655f11792cbec5867ce2fa9558..81acf9f6cf3f5ae5423d3a3c59898fa27f58aaa6 100644 (file)
@@ -22,6 +22,7 @@
 #include "buffer_funcs.h"
 #include "BufferList.h"
 #include "Converter.h"
+#include "CutAndPaste.h"
 #include "debug.h"
 #include "Encoding.h"
 #include "ErrorList.h"
 #include "Language.h"
 #include "Session.h"
 #include "Color.h"
-#include "callback.h"
 #include "LyXAction.h"
 #include "LyXFunc.h"
 #include "Lexer.h"
 #include "LyXRC.h"
+#include "ModuleList.h"
 #include "Server.h"
 #include "ServerSocket.h"
 #include "TextClassList.h"
@@ -116,6 +117,7 @@ namespace os = support::os;
 */
 bool use_gui = true;
 
+bool quitting; // flag, that we are quitting the program
 
 namespace {
 
@@ -364,7 +366,7 @@ void LyX::setGuiLanguage(std::string const & language)
 }
 
 
-Buffer const * const LyX::updateInset(Inset const * inset) const
+Buffer const * LyX::updateInset(Inset const * inset) const
 {
        if (quitting || !inset)
                return 0;
@@ -403,7 +405,8 @@ int LyX::exec(int & argc, char * argv[])
        // we need to parse for "-dbg" and "-help"
        easyParse(argc, argv);
 
-       try { 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) {
@@ -449,9 +452,6 @@ int LyX::exec(int & argc, char * argv[])
                return !final_success;
        }
 
-       // Force adding of font path _before_ Application is initialized
-       support::os::addFontResources();
-
        // Let the frontend parse and remove all arguments that it knows
        pimpl_->application_.reset(createApplication(argc, argv));
 
@@ -486,15 +486,16 @@ int LyX::exec(int & argc, char * argv[])
 
        prepareExit();
 
-       // Restore original font resources after Application is destroyed.
-       support::os::restoreFontResources();
-
        return exit_status;
 }
 
 
 void LyX::prepareExit()
 {
+       // Clear the clipboard and selection stack:
+       cap::clearCutStack();
+       cap::clearSelection();
+
        // Set a flag that we do quitting from the program,
        // so no refreshes are necessary.
        quitting = true;
@@ -615,6 +616,32 @@ void LyX::execBatchCommands()
        // aknowledged.
        restoreGuiSession();
 
+       // if reconfiguration is needed.
+       if (textclasslist.empty()) {
+           switch (Alert::prompt(
+                   _("No textclass is found"),
+                   _("LyX cannot continue because no textclass is found. "
+                     "You can either reconfigure normally, or reconfigure using "
+                     "default textclasses, or quit LyX."),
+                   0, 2,
+                   _("&Reconfigure"),
+                   _("&Use Default"),
+                   _("&Exit LyX")))
+               {
+               case 0:
+                       // regular reconfigure
+                       pimpl_->lyxfunc_.dispatch(FuncRequest(LFUN_RECONFIGURE, ""));
+                       break;
+               case 1:
+                       // reconfigure --without-latex-config
+                       pimpl_->lyxfunc_.dispatch(FuncRequest(LFUN_RECONFIGURE,
+                               " --without-latex-config"));
+                       break;
+               }
+               pimpl_->lyxfunc_.dispatch(FuncRequest(LFUN_LYX_QUIT));
+               return;
+       }
+       
        // Execute batch commands if available
        if (batch_command.empty())
                return;
@@ -630,6 +657,10 @@ void LyX::restoreGuiSession()
 {
        LyXView * view = newLyXView();
 
+       // if there is no valid class list, do not load any file. 
+       if (textclasslist.empty())
+               return;
+
        // if some files were specified at command-line we assume that the
        // user wants to edit *these* files and not to restore the session.
        if (!pimpl_->files_to_load_.empty()) {
@@ -664,7 +695,8 @@ void LyX::restoreGuiSession()
        // FIXME: Switch to the last loaded Buffer. This must not be the first one
        // because the Buffer won't be connected in this case. The correct solution
        // would be to avoid the manual connection of the current Buffer in LyXView.
-       view->setBuffer(pimpl_->buffer_list_.last());
+       if (!pimpl_->buffer_list_.empty())
+               view->setBuffer(pimpl_->buffer_list_.last());
 }
 
 
@@ -924,22 +956,26 @@ bool LyX::init()
        LYXERR(Debug::INIT) << "Reading layouts..." << endl;
        if (!LyXSetStyle())
                return false;
+       //...and the modules
+       moduleList.load();
 
-       if (use_gui) {
-               // Set the language defined by the user.
-               //setGuiLanguage(lyxrc.gui_language);
+       // read keymap and ui files in batch mode as well
+       // because InsetInfo needs to know these to produce
+       // the correct output
 
-               // Set up bindings
-               pimpl_->toplevel_keymap_.reset(new KeyMap);
-               defaultKeyBindings(pimpl_->toplevel_keymap_.get());
-               pimpl_->toplevel_keymap_->read(lyxrc.bind_file);
+       // Set the language defined by the user.
+       //setGuiLanguage(lyxrc.gui_language);
 
-               pimpl_->lyxfunc_.initKeySequences(pimpl_->toplevel_keymap_.get());
+       // Set up bindings
+       pimpl_->toplevel_keymap_.reset(new KeyMap);
+       defaultKeyBindings(pimpl_->toplevel_keymap_.get());
+       pimpl_->toplevel_keymap_->read(lyxrc.bind_file);
 
-               // Read menus
-               if (!readUIFile(lyxrc.ui_file))
-                       return false;
-       }
+       pimpl_->lyxfunc_.initKeySequences(pimpl_->toplevel_keymap_.get());
+
+       // Read menus
+       if (!readUIFile(lyxrc.ui_file))
+               return false;
 
        if (lyxerr.debugging(Debug::LYXRC))
                lyxrc.print();
@@ -1113,6 +1149,7 @@ bool LyX::queryUserLyXDir(bool explicit_userdir)
                first_start = false;
 
                return needsUpdate("lyxrc.defaults")
+                       || needsUpdate("lyxmodules.lst")
                        || needsUpdate("textclass.lst")
                        || needsUpdate("packages.lst");
        }
@@ -1527,7 +1564,6 @@ ServerSocket & theServerSocket()
 
 KeyMap & theTopLevelKeymap()
 {
-       BOOST_ASSERT(use_gui);
        return LyX::ref().topLevelKeymap();
 }