]> git.lyx.org Git - lyx.git/blobdiff - src/lyx_main.C
more cursor dispatch
[lyx.git] / src / lyx_main.C
index f9b845e70e8852e5461f0d74c17a96600f44d387..53f614750ee59a75907cf2487365eb43b95093ec 100644 (file)
@@ -40,6 +40,7 @@
 
 #include "frontends/Alert.h"
 #include "frontends/lyx_gui.h"
+#include "frontends/LyXView.h"
 
 #include "support/FileInfo.h"
 #include "support/filetools.h"
@@ -87,8 +88,6 @@ extern void QuitLyX();
 
 extern LyXServer * lyxserver;
 
-boost::scoped_ptr<LastFiles> lastfiles;
-
 // This is the global bufferlist object
 BufferList bufferlist;
 
@@ -105,19 +104,85 @@ void showFileError(string const & error)
        exit(EXIT_FAILURE);
 }
 
+} // namespace anon
+
+
+boost::scoped_ptr<LyX> LyX::singleton_;
+
+void LyX::exec(int & argc, char * argv[])
+{
+       BOOST_ASSERT(!singleton_.get());
+       // We must return from this before launching the gui so that
+       // other parts of the code can access singleton_ through
+       // LyX::ref and LyX::cref.
+       singleton_.reset(new LyX);
+       // Start the real execution loop.
+       singleton_->priv_exec(argc, argv);
+}
+
+LyX & LyX::ref()
+{
+       BOOST_ASSERT(singleton_.get());
+       return *singleton_.get();
+}
+
+
+LyX const & LyX::cref()
+{
+       BOOST_ASSERT(singleton_.get());
+       return *singleton_.get();
+}
+
+
+LyX::LyX()
+       : first_start(false)
+{}
+
+
+LastFiles & LyX::lastfiles()
+{
+       BOOST_ASSERT(lastfiles_.get());
+       return *lastfiles_.get();
+}
+
+
+LastFiles const & LyX::lastfiles() const
+{
+       BOOST_ASSERT(lastfiles_.get());
+       return *lastfiles_.get();
+}
+
+
+void LyX::addLyXView(boost::shared_ptr<LyXView> const & lyxview)
+{
+       views_.push_back(lyxview);
+}
+
+
+Buffer const * const LyX::updateInset(InsetOld const * inset) const
+{
+       if (!inset)
+               return 0;
+
+       Buffer const * buffer_ptr = 0;
+       ViewList::const_iterator it = views_.begin();
+       ViewList::const_iterator const end = views_.end();
+       for (; it != end; ++it) {
+               Buffer const * ptr = (*it)->updateInset(inset);
+               if (ptr)
+                       buffer_ptr = ptr;
+       }
+       return buffer_ptr;
 }
 
-LyX::LyX(int & argc, char * argv[])
+
+void LyX::priv_exec(int & argc, char * argv[])
 {
        // Here we need to parse the command line. At least
        // we need to parse for "-dbg" and "-help"
        bool const want_gui = easyParse(argc, argv);
 
-       // set the DisplayTranslator only once; should that be done here??
-       // if this should not be in this file, please also remove
-       // #include "graphics/GraphicsTypes.h" at the top -- Rob Lahaye.
-       lyx::graphics::setDisplayTranslator();
-
        if (want_gui)
                lyx_gui::parse_init(argc, argv);
 
@@ -214,6 +279,13 @@ static void error_handler(int err_sig)
        case SIGTERM:
                // no comments
                break;
+       case SIGPIPE:
+               // This will be received if lyx tries to write to a socket
+               // whose reading end was closed. It can safely be ignored,
+               // as in this case the ::write() system call will return -1
+               // and errno will be set to EPIPE
+               return;
+               //break;
        }
 
        // Deinstall the signal handlers
@@ -222,8 +294,9 @@ static void error_handler(int err_sig)
        signal(SIGFPE, SIG_DFL);
        signal(SIGSEGV, SIG_DFL);
        signal(SIGTERM, SIG_DFL);
+       signal(SIGPIPE, SIG_DFL);
 
-       LyX::emergencyCleanup();
+       LyX::cref().emergencyCleanup();
 
        lyxerr << "Bye." << endl;
        if (err_sig!= SIGHUP &&
@@ -250,6 +323,7 @@ void LyX::init(bool gui)
        signal(SIGSEGV, error_handler);
        signal(SIGINT, error_handler);
        signal(SIGTERM, error_handler);
+       signal(SIGPIPE, error_handler);
 
        bool const explicit_userdir = setLyxPaths();
 
@@ -323,9 +397,9 @@ void LyX::init(bool gui)
 
        lyxerr[Debug::INIT] << "Reading lastfiles `"
                            << lyxrc.lastfiles << "'..." << endl;
-       lastfiles.reset(new LastFiles(lyxrc.lastfiles,
-                                     lyxrc.check_lastfiles,
-                                     lyxrc.num_lastfiles));
+       lastfiles_.reset(new LastFiles(lyxrc.lastfiles,
+                                      lyxrc.check_lastfiles,
+                                      lyxrc.num_lastfiles));
 }
 
 
@@ -350,10 +424,6 @@ void LyX::defaultKeyBindings(kb_keymap  * kbmap)
        kbmap->bind("Delete", FuncRequest(LFUN_DELETE));
        kbmap->bind("BackSpace", FuncRequest(LFUN_BACKSPACE));
 
-       // sub- and superscript -MV
-       kbmap->bind("~S-underscore", FuncRequest(LFUN_SUBSCRIPT));
-       kbmap->bind("~S-asciicircum", FuncRequest(LFUN_SUPERSCRIPT));
-
        // kbmap->bindings to enable the use of the numeric keypad
        // e.g. Num Lock set
        //kbmap->bind("KP_0", FuncRequest(LFUN_SELFINSERT));
@@ -387,7 +457,7 @@ void LyX::defaultKeyBindings(kb_keymap  * kbmap)
 }
 
 
-void LyX::emergencyCleanup()
+void LyX::emergencyCleanup() const
 {
        // what to do about tmpfiles is non-obvious. we would
        // like to delete any we find, but our lyxdir might