]> git.lyx.org Git - lyx.git/blobdiff - src/LyX.cpp
* BufferView::updateMetrics(): split up the method in two for the SinglePar case.
[lyx.git] / src / LyX.cpp
index 9bbf03faea9aa5a9fd58ef816eb31dfd7bffab94..922cffba22e6f9272e4f7727981d1c9d6df0bb3a 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"
@@ -36,6 +37,7 @@
 #include "LyXFunc.h"
 #include "Lexer.h"
 #include "LyXRC.h"
+#include "ModuleList.h"
 #include "Server.h"
 #include "ServerSocket.h"
 #include "TextClassList.h"
@@ -46,6 +48,7 @@
 
 #include "frontends/alert.h"
 #include "frontends/Application.h"
+#include "frontends/Dialogs.h"
 #include "frontends/Gui.h"
 #include "frontends/LyXView.h"
 
 #include <string>
 #include <vector>
 
+using std::endl;
+using std::for_each;
+using std::map;
+using std::make_pair;
+using std::string;
+using std::vector;
+
+#ifndef CXX_GLOBAL_CSTD
+using std::exit;
+using std::signal;
+using std::system;
+#endif
+
+namespace fs = boost::filesystem;
 
 namespace lyx {
 
@@ -88,23 +105,11 @@ using support::package;
 using support::prependEnvPath;
 using support::rtrim;
 using support::Systemcall;
+using frontend::LyXView;
 
 namespace Alert = frontend::Alert;
 namespace os = support::os;
-namespace fs = boost::filesystem;
-
-using std::endl;
-using std::for_each;
-using std::map;
-using std::make_pair;
-using std::string;
-using std::vector;
 
-#ifndef CXX_GLOBAL_CSTD
-using std::exit;
-using std::signal;
-using std::system;
-#endif
 
 
 /// are we using the GUI at all?
@@ -361,9 +366,9 @@ 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 (!inset)
+       if (quitting || !inset)
                return 0;
 
        Buffer const * buffer_ptr = 0;
@@ -380,6 +385,20 @@ Buffer const * const LyX::updateInset(Inset const * inset) const
 }
 
 
+void LyX::hideDialogs(std::string const & name, Inset * inset) const
+{
+       if (quitting || !use_gui)
+               return;
+
+       vector<int> const & view_ids = pimpl_->application_->gui().viewIds();
+       vector<int>::const_iterator it = view_ids.begin();
+       vector<int>::const_iterator const end = view_ids.end();
+       for (; it != end; ++it)
+               pimpl_->application_->gui().view(*it).getDialogs().
+                       hide(name, inset);
+}
+
+
 int LyX::exec(int & argc, char * argv[])
 {
        // Here we need to parse the command line. At least
@@ -398,6 +417,10 @@ int LyX::exec(int & argc, char * argv[])
                }
        }
 
+       // Reinit the messages machinery in case package() knows
+       // something interesting about the locale directory.
+       Messages::init();
+
        if (!use_gui) {
                // FIXME: create a ConsoleApplication
                int exit_status = init(argc, argv);
@@ -414,11 +437,12 @@ int LyX::exec(int & argc, char * argv[])
                }
 
                BufferList::iterator begin = pimpl_->buffer_list_.begin();
-               BufferList::iterator end = pimpl_->buffer_list_.end();
 
                bool final_success = false;
-               for (BufferList::iterator I = begin; I != end; ++I) {
+               for (BufferList::iterator I = begin; I != pimpl_->buffer_list_.end(); ++I) {
                        Buffer * buf = *I;
+                       if (buf != buf->getMasterBuffer())
+                               continue;
                        bool success = false;
                        buf->dispatch(batch_command, &success);
                        final_success |= success;
@@ -427,9 +451,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));
 
@@ -464,15 +485,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;
@@ -593,6 +615,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;
@@ -608,30 +656,46 @@ 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()) {
                for_each(pimpl_->files_to_load_.begin(),
                        pimpl_->files_to_load_.end(),
-                       bind(&LyXView::loadLyXFile, view, _1, true, false, false));
+                       bind(&LyXView::loadLyXFile, view, _1, true));
                // clear this list to save a few bytes of RAM
                pimpl_->files_to_load_.clear();
                pimpl_->session_->lastOpened().clear();
-               return;
-       }
 
-       if (!lyxrc.load_session)
-               return;
+       } else if (lyxrc.load_session) {
+               vector<FileName> const & lastopened = pimpl_->session_->lastOpened().getfiles();
+               // do not add to the lastfile list since these files are restored from
+               // last session, and should be already there (regular files), or should
+               // not be added at all (help files).
+               for_each(lastopened.begin(), lastopened.end(),
+                       bind(&LyXView::loadLyXFile, view, _1, false));
 
-       vector<FileName> const & lastopened = pimpl_->session_->lastOpened().getfiles();
-       // do not add to the lastfile list since these files are restored from
-       // last session, and should be already there (regular files), or should
-       // not be added at all (help files).
-       for_each(lastopened.begin(), lastopened.end(),
-               bind(&LyXView::loadLyXFile, view, _1, false, false, false));
+               // clear this list to save a few bytes of RAM
+               pimpl_->session_->lastOpened().clear();
+       }
+
+       BufferList::iterator I = pimpl_->buffer_list_.begin();
+       BufferList::iterator end = pimpl_->buffer_list_.end();
+       for (; I != end; ++I) {
+               Buffer * buf = *I;
+               if (buf != buf->getMasterBuffer())
+                       continue;
+               updateLabels(*buf);
+       }
 
-       // clear this list to save a few bytes of RAM
-       pimpl_->session_->lastOpened().clear();
+       // 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.
+       if (!pimpl_->buffer_list_.empty())
+               view->setBuffer(pimpl_->buffer_list_.last());
 }
 
 
@@ -891,6 +955,8 @@ 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.
@@ -1080,6 +1146,7 @@ bool LyX::queryUserLyXDir(bool explicit_userdir)
                first_start = false;
 
                return needsUpdate("lyxrc.defaults")
+                       || needsUpdate("lyxmodules.lst")
                        || needsUpdate("textclass.lst")
                        || needsUpdate("packages.lst");
        }