]> git.lyx.org Git - lyx.git/blobdiff - src/LyX.cpp
remove reference to LaTeXStream
[lyx.git] / src / LyX.cpp
index 87d56f701c26e7317fd84b4717783072dab82f2e..c2b2b62845a7aa75f16a24a6cb16a3810afa5283 100644 (file)
 #include "ErrorList.h"
 #include "Format.h"
 #include "gettext.h"
-#include "kb_keymap.h"
+#include "KeyMap.h"
 #include "Language.h"
 #include "Session.h"
-#include "LColor.h"
-#include "lyx_cb.h"
+#include "Color.h"
+#include "callback.h"
 #include "LyXAction.h"
 #include "LyXFunc.h"
-#include "LyXLex.h"
+#include "Lexer.h"
 #include "LyXRC.h"
-#include "LyXServer.h"
-#include "LyXServerSocket.h"
-#include "LyXTextClassList.h"
+#include "Server.h"
+#include "ServerSocket.h"
+#include "TextClassList.h"
 #include "MenuBackend.h"
 #include "Messages.h"
 #include "Mover.h"
 #include "ToolbarBackend.h"
 
-#include "frontends/Alert.h"
+#include "frontends/alert.h"
 #include "frontends/Application.h"
+#include "frontends/Dialogs.h"
 #include "frontends/Gui.h"
 #include "frontends/LyXView.h"
 
@@ -62,6 +63,7 @@
 #include <boost/bind.hpp>
 #include <boost/filesystem/operations.hpp>
 
+#include <algorithm>
 #include <iostream>
 #include <csignal>
 #include <map>
@@ -107,7 +109,7 @@ using std::system;
 
 
 /// are we using the GUI at all?
-/** 
+/**
 * We default to true and this is changed to false when the export feature is used.
 */
 bool use_gui = true;
@@ -147,7 +149,7 @@ void reconfigureUserLyXDir()
 
 
 /// The main application class private implementation.
-struct LyX::Singletons 
+struct LyX::Singletons
 {
        Singletons()
        {
@@ -161,11 +163,11 @@ struct LyX::Singletons
        ///
        BufferList buffer_list_;
        ///
-       boost::scoped_ptr<kb_keymap> toplevel_keymap_;
+       boost::scoped_ptr<KeyMap> toplevel_keymap_;
        ///
-       boost::scoped_ptr<LyXServer> lyx_server_;
+       boost::scoped_ptr<Server> lyx_server_;
        ///
-       boost::scoped_ptr<LyXServerSocket> lyx_socket_;
+       boost::scoped_ptr<ServerSocket> lyx_socket_;
        ///
        boost::scoped_ptr<frontend::Application> application_;
        /// lyx session, containing lastfiles, lastfilepos, and lastopened
@@ -182,10 +184,10 @@ struct LyX::Singletons
 
        // The system converters copy after reading lyxrc.defaults.
        Converters system_converters_;
-       
+
        ///
        Movers movers_;
-       
+
        ///
        Movers system_movers_;
 };
@@ -265,28 +267,28 @@ LyXFunc const & LyX::lyxFunc() const
 }
 
 
-LyXServer & LyX::server()
+Server & LyX::server()
 {
        BOOST_ASSERT(pimpl_->lyx_server_.get());
-       return *pimpl_->lyx_server_.get(); 
+       return *pimpl_->lyx_server_.get();
 }
 
 
-LyXServer const & LyX::server() const 
+Server const & LyX::server() const
 {
        BOOST_ASSERT(pimpl_->lyx_server_.get());
-       return *pimpl_->lyx_server_.get(); 
+       return *pimpl_->lyx_server_.get();
 }
 
 
-LyXServerSocket & LyX::socket()
+ServerSocket & LyX::socket()
 {
        BOOST_ASSERT(pimpl_->lyx_socket_.get());
        return *pimpl_->lyx_socket_.get();
 }
 
 
-LyXServerSocket const & LyX::socket() const
+ServerSocket const & LyX::socket() const
 {
        BOOST_ASSERT(pimpl_->lyx_socket_.get());
        return *pimpl_->lyx_socket_.get();
@@ -307,7 +309,7 @@ frontend::Application const & LyX::application() const
 }
 
 
-kb_keymap & LyX::topLevelKeymap()
+KeyMap & LyX::topLevelKeymap()
 {
        BOOST_ASSERT(pimpl_->toplevel_keymap_.get());
        return *pimpl_->toplevel_keymap_.get();
@@ -326,7 +328,7 @@ Converters & LyX::systemConverters()
 }
 
 
-kb_keymap const & LyX::topLevelKeymap() const
+KeyMap const & LyX::topLevelKeymap() const
 {
        BOOST_ASSERT(pimpl_->toplevel_keymap_.get());
        return *pimpl_->toplevel_keymap_.get();
@@ -340,7 +342,7 @@ Messages & LyX::getMessages(std::string const & language)
        if (it != pimpl_->messages_.end())
                return it->second;
 
-       std::pair<map<string, Messages>::iterator, bool> result = 
+       std::pair<map<string, Messages>::iterator, bool> result =
                        pimpl_->messages_.insert(std::make_pair(language, Messages(language)));
 
        BOOST_ASSERT(result.second);
@@ -360,9 +362,9 @@ void LyX::setGuiLanguage(std::string const & language)
 }
 
 
-Buffer const * const LyX::updateInset(InsetBase const * inset) const
+Buffer const * const LyX::updateInset(Inset const * inset) const
 {
-       if (!inset)
+       if (quitting || !inset)
                return 0;
 
        Buffer const * buffer_ptr = 0;
@@ -379,6 +381,20 @@ Buffer const * const LyX::updateInset(InsetBase 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
@@ -386,8 +402,8 @@ int LyX::exec(int & argc, char * argv[])
        easyParse(argc, argv);
 
        try { support::init_package(to_utf8(from_local8bit(argv[0])),
-                             cl_system_support, cl_user_support,
-                             support::top_build_dir_is_one_level_up);
+                             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_);
@@ -397,6 +413,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);
@@ -420,7 +440,7 @@ int LyX::exec(int & argc, char * argv[])
                        Buffer * buf = *I;
                        bool success = false;
                        buf->dispatch(batch_command, &success);
-                       final_success |= success;                       
+                       final_success |= success;
                }
                prepareExit();
                return !final_success;
@@ -454,13 +474,13 @@ 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 LyXServer(&pimpl_->lyxfunc_, lyxrc.lyxpipes));
-       pimpl_->lyx_socket_.reset(new LyXServerSocket(&pimpl_->lyxfunc_, 
+       pimpl_->lyx_server_.reset(new Server(&pimpl_->lyxfunc_, lyxrc.lyxpipes));
+       pimpl_->lyx_socket_.reset(new ServerSocket(&pimpl_->lyxfunc_,
                        FileName(package().temp_dir().absFilename() + "/lyxsocket")));
 
        // Start the real execution loop.
        exit_status = pimpl_->application_->exec();
-       
+
        prepareExit();
 
        // Restore original font resources after Application is destroyed.
@@ -552,6 +572,17 @@ int LyX::init(int & argc, char * argv[])
 }
 
 
+void LyX::addFileToLoad(FileName const & fname)
+{
+       vector<FileName>::const_iterator cit = std::find(
+               pimpl_->files_to_load_.begin(), pimpl_->files_to_load_.end(),
+               fname);
+
+       if (cit == pimpl_->files_to_load_.end())
+               pimpl_->files_to_load_.push_back(fname);
+}
+
+
 void LyX::loadFiles()
 {
        vector<FileName>::const_iterator it = pimpl_->files_to_load_.begin();
@@ -601,7 +632,7 @@ void LyX::restoreGuiSession()
        if (!pimpl_->files_to_load_.empty()) {
                for_each(pimpl_->files_to_load_.begin(),
                        pimpl_->files_to_load_.end(),
-                       bind(&LyXView::loadLyXFile, view, _1, true));
+                       bind(&LyXView::loadLyXFile, view, _1, true, false, false));
                // clear this list to save a few bytes of RAM
                pimpl_->files_to_load_.clear();
                pimpl_->session_->lastOpened().clear();
@@ -616,7 +647,7 @@ void LyX::restoreGuiSession()
        // 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));
+               bind(&LyXView::loadLyXFile, view, _1, false, false, false));
 
        // clear this list to save a few bytes of RAM
        pimpl_->session_->lastOpened().clear();
@@ -668,7 +699,7 @@ LyXView * LyX::newLyXView()
                        posy = convert<int>(val);
        }
 
-       if (!geometryArg.empty()) 
+       if (!geometryArg.empty())
        {
                width = 0;
                height = 0;
@@ -796,7 +827,7 @@ void LyX::initGuiFont()
                lyxrc.sans_font_name = pimpl_->application_->sansFontName();
 
        if (lyxrc.typewriter_font_name.empty())
-               lyxrc.typewriter_font_name 
+               lyxrc.typewriter_font_name
                        = pimpl_->application_->typewriterFontName();
 }
 
@@ -885,7 +916,7 @@ bool LyX::init()
                //setGuiLanguage(lyxrc.gui_language);
 
                // Set up bindings
-               pimpl_->toplevel_keymap_.reset(new kb_keymap);
+               pimpl_->toplevel_keymap_.reset(new KeyMap);
                defaultKeyBindings(pimpl_->toplevel_keymap_.get());
                pimpl_->toplevel_keymap_->read(lyxrc.bind_file);
 
@@ -924,8 +955,8 @@ bool LyX::init()
        }
 
        LYXERR(Debug::INIT) << "LyX tmp dir: `"
-                           << package().temp_dir().absFilename()
-                           << '\'' << endl;
+                           << package().temp_dir().absFilename()
+                           << '\'' << endl;
 
        LYXERR(Debug::INIT) << "Reading session information '.lyx/session'..." << endl;
        pimpl_->session_.reset(new Session(lyxrc.num_lastfiles));
@@ -938,7 +969,7 @@ bool LyX::init()
 }
 
 
-void LyX::defaultKeyBindings(kb_keymap  * kbmap)
+void LyX::defaultKeyBindings(KeyMap  * kbmap)
 {
        kbmap->bind("Right", FuncRequest(LFUN_CHAR_FORWARD));
        kbmap->bind("Left", FuncRequest(LFUN_CHAR_BACKWARD));
@@ -1007,7 +1038,7 @@ void LyX::emergencyCleanup() const
 }
 
 
-void LyX::deadKeyBindings(kb_keymap * kbmap)
+void LyX::deadKeyBindings(KeyMap * kbmap)
 {
        // bindKeyings for transparent handling of deadkeys
        // The keysyms are gotten from XFree86 X11R6
@@ -1158,7 +1189,7 @@ bool LyX::readUIFile(string const & name, bool include)
 
        LYXERR(Debug::INIT) << "About to read " << name << "..." << endl;
 
-       
+
        FileName ui_path;
        if (include) {
                ui_path = libFileSearch("ui", name, "inc");
@@ -1168,7 +1199,7 @@ bool LyX::readUIFile(string const & name, bool include)
        }
        else
                ui_path = libFileSearch("ui", name, "ui");
-       
+
        if (ui_path.empty()) {
                LYXERR(Debug::INIT) << "Could not find " << name << endl;
                showFileError(name);
@@ -1179,7 +1210,7 @@ bool LyX::readUIFile(string const & name, bool include)
 
        LYXERR(Debug::INIT) << "Found " << name
                            << " in " << ui_path << endl;
-       LyXLex lex(uitags, ui_last - 1);
+       Lexer lex(uitags, ui_last - 1);
        lex.setFile(ui_path);
        if (!lex.isOK()) {
                lyxerr << "Unable to set LyXLeX for ui file: " << ui_path
@@ -1238,10 +1269,10 @@ bool LyX::readLanguagesFile(string const & name)
 
 // Read the encodings file `name'
 bool LyX::readEncodingsFile(string const & enc_name,
-                            string const & symbols_name)
+                           string const & symbols_name)
 {
        LYXERR(Debug::INIT) << "About to read " << enc_name << " and "
-                           << symbols_name << "..." << endl;
+                           << symbols_name << "..." << endl;
 
        FileName const symbols_path = libFileSearch(string(), symbols_name);
        if (symbols_path.empty()) {
@@ -1464,7 +1495,7 @@ LyXFunc & theLyXFunc()
 }
 
 
-LyXServer & theLyXServer()
+Server & theServer()
 {
        // FIXME: this should not be use_gui dependent
        BOOST_ASSERT(use_gui);
@@ -1472,7 +1503,7 @@ LyXServer & theLyXServer()
 }
 
 
-LyXServerSocket & theLyXServerSocket()
+ServerSocket & theServerSocket()
 {
        // FIXME: this should not be use_gui dependent
        BOOST_ASSERT(use_gui);
@@ -1480,7 +1511,7 @@ LyXServerSocket & theLyXServerSocket()
 }
 
 
-kb_keymap & theTopLevelKeymap()
+KeyMap & theTopLevelKeymap()
 {
        BOOST_ASSERT(use_gui);
        return LyX::ref().topLevelKeymap();