#include "frontends/Alert.h"
#include "frontends/lyx_gui.h"
+#include "frontends/LyXView.h"
#include "support/FileInfo.h"
#include "support/filetools.h"
namespace os = lyx::support::os;
using std::endl;
-
+using std::string;
using std::vector;
#ifndef CXX_GLOBAL_CSTD
extern LyXServer * lyxserver;
-boost::scoped_ptr<LastFiles> lastfiles;
-
// This is the global bufferlist object
BufferList bufferlist;
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(int & argc, char * 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;
+}
+
+
+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);
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
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 &&
signal(SIGSEGV, error_handler);
signal(SIGINT, error_handler);
signal(SIGTERM, error_handler);
+ signal(SIGPIPE, error_handler);
bool const explicit_userdir = setLyxPaths();
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));
}
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));
}
-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