]> git.lyx.org Git - features.git/commitdiff
Turn LyX into a singleton class. Kill the BufferView cache.
authorAngus Leeming <leeming@lyx.org>
Tue, 14 Oct 2003 21:30:23 +0000 (21:30 +0000)
committerAngus Leeming <leeming@lyx.org>
Tue, 14 Oct 2003 21:30:23 +0000 (21:30 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7922 a592a061-630c-0410-9148-cb99ea01b6c8

34 files changed:
src/BufferView_pimpl.C
src/ChangeLog
src/MenuBackend.C
src/boost.C
src/bufferlist.C
src/frontends/ChangeLog
src/frontends/LyXView.C
src/frontends/LyXView.h
src/frontends/gtk/ChangeLog
src/frontends/gtk/lyx_gui.C
src/frontends/qt2/ChangeLog
src/frontends/qt2/lyx_gui.C
src/frontends/xforms/ChangeLog
src/frontends/xforms/lyx_gui.C
src/insets/ChangeLog
src/insets/insetexternal.C
src/insets/insetexternal.h
src/insets/insetgraphics.C
src/insets/insetgraphics.h
src/insets/insetinclude.C
src/insets/insetinclude.h
src/insets/insetlabel.h
src/lyx_cb.C
src/lyx_main.C
src/lyx_main.h
src/main.C
src/mathed/ChangeLog
src/mathed/formula.C
src/mathed/formulabase.C
src/mathed/formulabase.h
src/tex2lyx/ChangeLog
src/tex2lyx/Makefile.am
src/tex2lyx/boost.C [new file with mode: 0644]
src/tex2lyx/tex2lyx.C

index b51094424bd7cc531c9cc0f96b6bb2a3b87db08b..4e917e76f5206d64c14e94f448b67ef5f5b3cc8a 100644 (file)
@@ -255,7 +255,7 @@ bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles)
        bv_->showErrorList(_("Parse"));
 
        if (tolastfiles)
-               lastfiles->newFile(b->fileName());
+               LyX::ref().lastfiles().newFile(b->fileName());
 
        return true;
 }
index 62ba735680b307a875a367a61ff585efe8a08c92..88bc9e7823c9b9e7f75a403bbaa9145dbc398563 100644 (file)
@@ -1,4 +1,20 @@
+2003-10-14  Angus Leeming  <leeming@lyx.org>
 
+       * lyx_main.[Ch]: make LyX a singleton class, accessible though the new
+       static member functions LyX::ref() and LyX::cref.
+       (lastfiles): new accessor functions for the new lastfiles_ member var.
+       (addLyXView, views_): add a new LyXView to the list of views_.
+       (updateInset): loop over all LyXViews to call their own updateInset
+       member function, returning a pointer to the Buffer owning the inset.
+
+       * BufferView_pimpl.C (loadLyXFile):
+       * MenuBackend.C (expandLastfiles):
+       * bufferlist.C (MenuWrite, QuitLyX):
+       lastfiles is no longer a global variable.
+       Access through LyX::ref().lastfiles(), LyX::cref().lastfiles().
+
+       * boost.C (emergencyCleanup): LyX::emergencyCleanup is no longer a
+       static function. Access through LyX::cref().emergencyCleanup().
 
 2003-10-14  André Pönitz  <poenitz@gmx.net>
 
index 9614260e58fbd2ee23a89815e100bc50f793d6df..dcd90ba51766c5603a04fe3b3772dd5187fbf129 100644 (file)
@@ -375,9 +375,11 @@ string const limit_string_length(string const & str)
 
 void expandLastfiles(Menu & tomenu, LyXView const * view)
 {
+       LastFiles const & lastfiles = LyX::cref().lastfiles();
+
        int ii = 1;
-       LastFiles::const_iterator lfit = lastfiles->begin();
-       LastFiles::const_iterator end = lastfiles->end();
+       LastFiles::const_iterator lfit = lastfiles.begin();
+       LastFiles::const_iterator end = lastfiles.end();
 
        for (; lfit != end && ii < 10; ++lfit, ++ii) {
                string const label = tostr(ii) + ". "
index 440b4ffd931aa6cd99d44b0e8c1d370b5eab121a..2a6570d8818b1a68762942651e2da52556f99d16 100644 (file)
@@ -40,7 +40,7 @@ void emergencyCleanup()
 
         didCleanup = true;
 
-        LyX::emergencyCleanup();
+        LyX::cref().emergencyCleanup();
 }
 
 }
index 0bd23d364d9472b1c9fdb87ac06981b0a9097414..aeb2d32a0c998cf2d7967af0a0080bcda745e9fe 100644 (file)
@@ -179,7 +179,7 @@ bool BufferList::close(Buffer * buf, bool ask)
                        if (!WriteAs(buf))
                                return false;
                } else if (buf->save()) {
-                       lastfiles->newFile(buf->fileName());
+                       LyX::ref().lastfiles().newFile(buf->fileName());
                } else {
                        return false;
                }
index cf56889bf2e6ab2a2f63cce0a7f61170ecce8817..fc2d2c30a9d04b4467677e56baec4a79cd755679 100644 (file)
@@ -1,3 +1,8 @@
+2003-10-14  Angus Leeming  <leeming@lyx.org>
+
+       * LyXView.[Ch] (updateInset): invoke BufferView::updateInset, returning
+       a pointer to the Buffer owning the inset.
+
 2003-10-13  Joao Luis Meloni Assirati <assirati@fma.if.usp.br>
 
        * lyx_gui.h (set_datasocket_callback, set_serversocket_callback,
index b05c6a4a6d66a5ee9b1abd72a36c74f75861415a..658a4a25f7812f03c6641d8e25cea3e9cbe2f3fa 100644 (file)
@@ -192,3 +192,14 @@ void LyXView::dispatch(FuncRequest const & req)
        r.setView(view().get());
        getLyXFunc().dispatch(r);
 }
+
+
+Buffer const * const LyXView::updateInset(InsetOld const * inset) const
+{
+       Buffer const * buffer_ptr = 0;
+       if (inset) {
+               buffer_ptr = bufferview_->buffer();
+               bufferview_->updateInset(inset);
+       }
+       return buffer_ptr;
+}
index 08a094539a4b1e9bcd64dc8ca31a34256ff055fb..c16c7a9a331eefc2ce48ec0f7e3a0b4e0680acf3 100644 (file)
@@ -21,6 +21,7 @@
 
 class Buffer;
 class Toolbar;
+class InsetOld;
 class Intl;
 class Menubar;
 class ControlCommandBuffer;
@@ -131,6 +132,11 @@ public:
        /// dispatch to current BufferView
        void dispatch(FuncRequest const & req);
 
+       /** redraw \c inset in all the BufferViews in which it is currently
+        *  visible. If successful return a pointer to the owning Buffer.
+        */
+       Buffer const * const updateInset(InsetOld const *) const;
+
 protected:
        /// view of a buffer. Eventually there will be several.
        boost::shared_ptr<BufferView> bufferview_;
index 40c3c5834d769c8ace0cd8d377d06345d2d8f4bd..773bddf88665f12bc36bd90efe7a101a3cee4b54 100644 (file)
@@ -1,3 +1,7 @@
+2003-10-14  Angus Leeming  <leeming@lyx.org>
+
+       * lyx_gui.C (start): store the LyXView in the LyX list of all LyXViews.
+
 2003-10-13  José Matos  <jamatos@lyx.org>
 
        * lyx_gui.C (set_datasocket_callback, set_serversocket_callback,
index 20a620b305cad67783e4b1a7bb90829e0b6a3fe5..99aeab74458163b7221600bee02103024616bd1d 100644 (file)
@@ -313,7 +313,11 @@ void lyx_gui::start(string const & batch, std::vector<string> const & files)
        start_xforms();
        // just for debug
        XSynchronize(getDisplay(), true);
-       GView view;
+
+       boost::shared_ptr<GView> view_ptr(new GView);
+       LyX::ref().addLyXView(view_ptr);
+
+       GView & view = *view_ptr.get();
        view.show();
        view.init();
 
index 6f8faa2525266c4813ecac29bed9f0e2d40c70a3..6de9680e83ab74083bc7de651247d6773e9ef451 100644 (file)
@@ -1,3 +1,7 @@
+2003-10-14  Angus Leeming  <leeming@lyx.org>
+
+       * lyx_gui.C (start): store the LyXView in the LyX list of all LyXViews.
+
 2003-10-13  João Luis Meloni Assirati  <assirati@fma.if.usp.br>
 
        * lyx_gui.C: Declared and allocated lyxsocket.
index d470bdad209e359f22553876f696d18c4ae716b7..5c7132f533ee5798455831bc8144d3d792213b3f 100644 (file)
@@ -22,6 +22,7 @@
 
 // FIXME: move this stuff out again
 #include "bufferlist.h"
+#include "lyx_main.h"
 #include "LyXAction.h"
 #include "lyxfunc.h"
 #include "lyxrc.h"
@@ -136,7 +137,10 @@ void start(string const & batch, vector<string> const & files)
        unsigned int width = 690;
        unsigned int height = 510;
 
-       QtView view(width, height);
+       boost::shared_ptr<QtView> view_ptr(new QtView(width, height));
+       LyX::ref().addLyXView(view_ptr);
+
+       QtView & view = *view_ptr.get();
        view.show();
        view.init();
 
index d9801ed0d1015eaeb75a66cf8aaf16a5cea5c03a..05149c6a37f0d7838cfbc6eaf1154b3d0987442e 100644 (file)
@@ -1,3 +1,9 @@
+2003-10-14  Angus Leeming  <leeming@lyx.org>
+
+       * lyx_gui.C (start): store the LyXView in the LyX list of all LyXViews.
+       (LyX_XErrHandler): LyX::emergencyCleanup is no longer a static function.
+       Access through LyX::cref().emergencyCleanup().
+
 2003-10-13  Joao Luis Meloni Assirati <assirati@fma.if.usp.br>
 
        * lyx_gui.C (set_datasocket_callback, set_serversocket_callback,
index bf3bb46e479c8b2dfa8a82f910a9c1d175c037b9..aff77003535e53a18f9a05f3b6f86268f84ff8d6 100644 (file)
@@ -121,7 +121,7 @@ int LyX_XErrHandler(Display * display, XErrorEvent * xeev) {
        }
 
        // emergency cleanup
-       LyX::emergencyCleanup();
+       LyX::cref().emergencyCleanup();
 
        // Get the reason for the crash.
        char etxt[513];
@@ -284,7 +284,10 @@ void start(string const & batch, vector<string> const & files)
        lyxerr[Debug::GUI] << "Creating view: " << width << 'x' << height
                           << '+' << xpos << '+' << ypos << endl;
 
-       XFormsView view(width, height);
+       boost::shared_ptr<XFormsView> view_ptr(new XFormsView(width, height));
+       LyX::ref().addLyXView(view_ptr);
+
+       XFormsView & view = *view_ptr.get();
        view.show(xpos, ypos, "LyX");
        view.init();
 
index c8fe12abc03a5172d1655a2871a166c8b3a23047..1959ddc91fb1dc8f9bd1e0aac5f2c6136defceb3 100644 (file)
@@ -1,3 +1,16 @@
+2003-10-14  Angus Leeming  <leeming@lyx.org>
+
+       * insetexternal.[Ch] (view, cache, view_):
+       * insetgraphics.[Ch] (view, cache, view_):
+       * insetinclude.[Ch] (view, cache, view_): remove the BufferView cache.
+       (statusChanged): call LyX::cref().updateInset.
+
+       * insetinclude.C (fileChanged): use LyX::cref().updateInset rather than
+       the BufferView cache.
+
+       * insetlabel.h: remove #include <boost/weak_ptr.hpp>. Cruft from an
+       earlier clean-up.
+
 2003-10-14  Angus Leeming  <leeming@lyx.org>
 
        * insetinclude.C (metrics, draw): only draw the preview when previews
index 14b95c7fdee304bc7dceffb00d619bdb15cfc9fc..479fa9e08b704cccbcbd7a346ce992db94ea9f3d 100644 (file)
@@ -23,6 +23,7 @@
 #include "gettext.h"
 #include "LaTeXFeatures.h"
 #include "latexrunparams.h"
+#include "lyx_main.h"
 #include "lyxlex.h"
 #include "lyxrc.h"
 #include "metricsinfo.h"
@@ -380,23 +381,9 @@ InsetExternal::~InsetExternal()
 }
 
 
-void InsetExternal::cache(BufferView * view) const
-{
-       BOOST_ASSERT(view);
-       view_ = view->owner()->view();
-}
-
-BufferView * InsetExternal::view() const
-{
-       return view_.lock().get();
-}
-
-
 void InsetExternal::statusChanged() const
 {
-       BufferView * const bv = view();
-       if (bv)
-               bv->updateInset(this);
+       LyX::cref().updateInset(this);
 }
 
 
@@ -449,7 +436,6 @@ void InsetExternal::metrics(MetricsInfo & mi, Dimension & dim) const
 
 void InsetExternal::draw(PainterInfo & pi, int x, int y) const
 {
-       cache(pi.base.bv);
        renderer_->draw(pi, x, y);
 }
 
index 31d2b9ae330af3627a17f2271c17ea74277980cc..93d0e678c075fffde003f5a689a184c063b3aff8 100644 (file)
@@ -21,7 +21,6 @@
 
 #include <boost/scoped_ptr.hpp>
 #include <boost/signals/trackable.hpp>
-#include <boost/weak_ptr.hpp>
 
 
 /** No two InsetExternalParams variables can have the same temporary file.
@@ -129,8 +128,6 @@ public:
        void setParams(InsetExternalParams const &, Buffer const &);
 
 private:
-       void cache(BufferView *) const;
-       BufferView * view() const;
        /** This method is connected to the graphics loader, so we are
         *  informed when the image has been loaded.
         */
@@ -140,9 +137,6 @@ private:
        InsetExternalParams params_;
        /// The thing that actually draws the image on LyX's screen.
        boost::scoped_ptr<RenderBase> renderer_;
-
-       /// Cached
-       mutable boost::weak_ptr<BufferView> view_;
 };
 
 
index 43128342690f21076c3a5ac11d9cf0ae9afff393..a54703a921fb0b04bde4e7b16414337abbd7f20b 100644 (file)
@@ -64,6 +64,7 @@ TODO
 #include "gettext.h"
 #include "LaTeXFeatures.h"
 #include "latexrunparams.h"
+#include "lyx_main.h"
 #include "lyxlex.h"
 #include "lyxrc.h"
 #include "metricsinfo.h"
@@ -183,23 +184,9 @@ InsetGraphics::~InsetGraphics()
 }
 
 
-void InsetGraphics::cache(BufferView * view) const
-{
-       BOOST_ASSERT(view);
-       view_ = view->owner()->view();
-}
-
-BufferView * InsetGraphics::view() const
-{
-       return view_.lock().get();
-}
-
-
 void InsetGraphics::statusChanged() const
 {
-       BufferView * bv = view();
-       if (bv)
-               bv->updateInset(this);
+       LyX::cref().updateInset(this);
 }
 
 
@@ -241,7 +228,6 @@ void InsetGraphics::metrics(MetricsInfo & mi, Dimension & dim) const
 
 void InsetGraphics::draw(PainterInfo & pi, int x, int y) const
 {
-       cache(pi.base.bv);
        graphic_->draw(pi, x, y);
 }
 
index 2ac1afc35b75fe2fe44f4cfa5b2631b61d867cef..65597521424efd6c046942af26da74583ebdaa3b 100644 (file)
@@ -18,8 +18,6 @@
 
 #include <boost/scoped_ptr.hpp>
 #include <boost/signals/trackable.hpp>
-#include <boost/weak_ptr.hpp>
-
 
 class Dialogs;
 class RenderGraphic;
@@ -83,9 +81,6 @@ private:
        ///
        friend class InsetGraphicsMailer;
 
-       void cache(BufferView *) const;
-       BufferView * view() const;
-
        /** This method is connected to the graphics loader, so we are
         *  informed when the image has been loaded.
         */
@@ -109,9 +104,6 @@ private:
 
        /// The thing that actually draws the image on LyX's screen.
        boost::scoped_ptr<RenderGraphic> const graphic_;
-
-       /// Cached
-       mutable boost::weak_ptr<BufferView> view_;
 };
 
 
index 1a3a5090c25235864d7ec78b21d8d830d717e627..3a5cbda59785d1984791b28be346c16e61a4afa3 100644 (file)
@@ -22,6 +22,7 @@
 #include "gettext.h"
 #include "LaTeXFeatures.h"
 #include "latexrunparams.h"
+#include "lyx_main.h"
 #include "lyxlex.h"
 #include "metricsinfo.h"
 
@@ -540,16 +541,15 @@ void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
 
 void InsetInclude::draw(PainterInfo & pi, int x, int y) const
 {
-       cache(pi.base.bv);
-
        if (!RenderPreview::activated() || !preview_->previewReady()) {
                button_.draw(pi, x + button_.box().x1, y);
                return;
        }
 
-       if (!preview_->monitoring()) {
-               string const included_file =
-                       includedFilename(*view()->buffer(), params_);
+       BOOST_ASSERT(pi.base.bv);
+       Buffer const * const buffer = pi.base.bv->buffer();
+       if (!preview_->monitoring() && buffer) {
+               string const included_file = includedFilename(*buffer, params_);
                preview_->startMonitoring(included_file);
        }
 
@@ -557,40 +557,23 @@ void InsetInclude::draw(PainterInfo & pi, int x, int y) const
 }
 
 
-void InsetInclude::cache(BufferView * view) const
-{
-       BOOST_ASSERT(view);
-       view_ = view->owner()->view();
-}
-
-BufferView * InsetInclude::view() const
-{
-       return view_.lock().get();
-}
-
-
 //
 // preview stuff
 //
 
 void InsetInclude::statusChanged() const
 {
-       if (view())
-               view()->updateInset(this);
+       LyX::cref().updateInset(this);
 }
 
 
 void InsetInclude::fileChanged() const
 {
-       BufferView * const bv = view();
-       if (!bv)
-               return;
-       bv->updateInset(this);
-
-       if (!bv->buffer())
+       Buffer const * const buffer_ptr = LyX::cref().updateInset(this);
+       if (!buffer_ptr)
                return;
-       Buffer const & buffer = *bv->buffer();
 
+       Buffer const & buffer = *buffer_ptr;
        preview_->removePreview(buffer);
        generate_preview(*preview_.get(), *this, buffer);
 }
index 9fda837950f9518eb284da4648b61f7e719a6882..5e96daea3211a7b16cb7b38ded1a3cb085a8e482 100644 (file)
@@ -16,8 +16,6 @@
 #include "insetcommandparams.h"
 #include "render_button.h"
 #include <boost/scoped_ptr.hpp>
-#include <boost/weak_ptr.hpp>
-
 
 class Buffer;
 class Dimension;
@@ -82,9 +80,6 @@ public:
        void addPreview(lyx::graphics::PreviewLoader &) const;
 
 private:
-       void cache(BufferView *) const;
-       BufferView * view() const;
-
        /// Slot receiving a signal that the preview is ready to display.
        void statusChanged() const;
        /** Slot receiving a signal that the external file has changed
@@ -112,7 +107,6 @@ private:
        boost::scoped_ptr<RenderMonitoredPreview> const preview_;
 
        /// cache
-       mutable boost::weak_ptr<BufferView> view_;
        mutable bool set_label_;
        mutable RenderButton button_;
 };
index c9db1eea302c6ef34df34707cc0932a3d5feb22e..d42255e93bc9e62e4ce50ea924a8858fcb2d24ad 100644 (file)
@@ -12,9 +12,7 @@
 #ifndef INSET_LABEL_H
 #define INSET_LABEL_H
 
-
 #include "insetcommand.h"
-#include <boost/weak_ptr.hpp>
 
 class InsetLabel : public InsetCommand {
 public:
index e9dbaccf92657c23fd00e66f46378a697148dbc9..ca6afd6dcce8fcaa15627199e9d5fd2043e95a31 100644 (file)
@@ -90,7 +90,7 @@ bool quitting;        // flag, that we are quitting the program
 bool MenuWrite(Buffer * buffer)
 {
        if (buffer->save()) {
-               lastfiles->newFile(buffer->fileName());
+               LyX::ref().lastfiles().newFile(buffer->fileName());
                return true;
        }
 
@@ -184,7 +184,7 @@ void QuitLyX()
                if (!bufferlist.quitWriteAll())
                        return;
 
-               lastfiles->writeFile(lyxrc.lastfiles);
+               LyX::cref().lastfiles().writeFile(lyxrc.lastfiles);
        }
 
        // Set a flag that we do quitting from the program,
index a96bf63db3efe4b8735fd53e63f777dfc933dc62..eb5d7b0289d18ad3d593a9d5fab056cf04c095fd 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,9 +104,80 @@ 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::LyX(int & argc, char * argv[])
+
+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"
@@ -226,7 +296,7 @@ static void error_handler(int err_sig)
        signal(SIGTERM, SIG_DFL);
        signal(SIGPIPE, SIG_DFL);
 
-       LyX::emergencyCleanup();
+       LyX::cref().emergencyCleanup();
 
        lyxerr << "Bye." << endl;
        if (err_sig!= SIGHUP &&
@@ -327,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));
 }
 
 
@@ -391,7 +461,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
index c9cdf781bf96875eccc1c651b02a82a508131a41..4929f141f1bf738d9b956124bc7813c4d843c1a3 100644 (file)
 #define LYX_MAIN_H
 
 #include <boost/scoped_ptr.hpp>
+#include <boost/shared_ptr.hpp>
 #include <boost/utility.hpp>
 
+#include <list>
 #include <string>
 
-
+class Buffer;
 class ErrorItem;
-class LyXRC;
+class InsetOld;
 class LastFiles;
-class Buffer;
+class LyXView;
 class kb_keymap;
 
 
-/// last files loaded
-extern boost::scoped_ptr<LastFiles> lastfiles;
-
-
 /// initial startup
 class LyX : boost::noncopyable {
 public:
-       LyX(int & argc, char * argv[]);
+       static void exec(int & argc, char * argv[]);
+       static LyX & ref();
+       static LyX const & cref();
 
        /// in the case of failure
-       static void emergencyCleanup();
+       void emergencyCleanup() const;
+
+       LastFiles & lastfiles();
+       LastFiles const & lastfiles() const;
+
+       void addLyXView(boost::shared_ptr<LyXView> const & lyxview);
+
+       /** redraw \c inset in all the BufferViews in which it is currently
+        *  visible. If successful return a pointer to the owning Buffer.
+        */
+       Buffer const * const updateInset(InsetOld const *) const;
 
 private:
+       static boost::scoped_ptr<LyX> singleton_;
+
+       LyX();
+       void priv_exec(int & argc, char * argv[]);
+
        /// initial LyX set up
        void init(bool);
        /// set up the default key bindings
@@ -65,6 +80,12 @@ private:
        bool first_start;
        /// the parsed command line batch command if any
        std::string batch_command;
+
+       /// last files loaded
+       boost::scoped_ptr<LastFiles> lastfiles_;
+       ///
+       typedef std::list<boost::shared_ptr<LyXView> > ViewList;
+       ViewList views_;
 };
 
 #endif // LYX_MAIN_H
index 3dbd1ea06704cb1b8ba63fd1425119328e3e9b2a..b6366d73e61a797190c9463111e2ca03f50ec66a 100644 (file)
@@ -34,6 +34,6 @@ int main(int argc, char * argv[])
        // initialize for internationalized version *EK*
        locale_init();
 
-       LyX lyx(argc, argv);
+       LyX::exec(argc, argv);
        return 0;
 }
index f015e047068c5a097837e26c59de42b6751e938d..d2f91ba06a94ecbb93c3093be52794b0f2482073 100644 (file)
@@ -1,3 +1,9 @@
+2003-10-14  Angus Leeming  <leeming@lyx.org>
+
+       * insetformulabase.[Ch] (view, cache, view_): remove the BufferView cache.
+
+       * insetformula.C (statusChanged): call LyX::cref().updateInset.
+
 2003-10-14  Angus Leeming  <leeming@lyx.org>
 
        * formula.C (metrics, draw): only draw the preview when previews
index fb2f0a96ce0cb02cf4094245a1b482960b0f76ba..e6c7cf1939b6943953da6831336744079b8e0ef4 100644 (file)
@@ -22,6 +22,7 @@
 #include "debug.h"
 #include "latexrunparams.h"
 #include "LColor.h"
+#include "lyx_main.h"
 
 #include "frontends/Painter.h"
 
@@ -191,8 +192,6 @@ bool editing_inset(InsetFormula const * inset)
 
 void InsetFormula::draw(PainterInfo & pi, int x, int y) const
 {
-       cache(pi.base.bv);
-
        // The previews are drawn only when we're not editing the inset.
        bool const use_preview = (!editing_inset(this) &&
                                  RenderPreview::activated() &&
@@ -300,8 +299,7 @@ void InsetFormula::mutate(string const & type)
 
 void InsetFormula::statusChanged() const
 {
-       if (view())
-               view()->updateInset(this);
+       LyX::cref().updateInset(this);
 }
 
 
index 15331df22b02f1e9d8dfd6558df2d2e1e0074639..25c3bc8a269816e1f9d765cc99e1ce7661ea1360 100644 (file)
 #include "formulabase.h"
 #include "formula.h"
 #include "formulamacro.h"
-#include "funcrequest.h"
-#include "BufferView.h"
-#include "bufferview_funcs.h"
-#include "lyxtext.h"
-#include "gettext.h"
-#include "debug.h"
 #include "math_support.h"
 #include "math_arrayinset.h"
 #include "math_deliminset.h"
 #include "math_hullinset.h"
 #include "math_parser.h"
 #include "math_spaceinset.h"
-#include "undo.h"
 #include "ref_inset.h"
+
+#include "BufferView.h"
+#include "bufferview_funcs.h"
+#include "debug.h"
+#include "funcrequest.h"
+#include "gettext.h"
 #include "LColor.h"
+#include "lyxtext.h"
+#include "undo.h"
+
+#include "frontends/LyXView.h"
+#include "frontends/Dialogs.h"
 
 #include "support/std_sstream.h"
 #include "support/lstrings.h"
 #include "support/lyxlib.h"
 
-#include "frontends/LyXView.h"
-#include "frontends/Dialogs.h"
-
 using lyx::support::atoi;
 using lyx::support::split;
 using lyx::support::token;
@@ -139,18 +140,6 @@ void InsetFormulaBase::handleFont2(BufferView * bv, string const & arg)
 
 
 
-void InsetFormulaBase::cache(BufferView * view) const
-{
-       BOOST_ASSERT(view);
-       view_ = view->owner()->view();
-}
-
-BufferView * InsetFormulaBase::view() const
-{
-       return view_.lock().get();
-}
-
-
 void InsetFormulaBase::validate(LaTeXFeatures &) const
 {}
 
index c00a9a4da0b7380c4449cfc1fbfaaa44c8a7d9f2..904f46e18ba69a332ac0e7d9b533422aead9ec35 100644 (file)
@@ -15,8 +15,6 @@
 #define INSET_FORMULABASE_H
 
 #include "insets/updatableinset.h"
-#include <boost/weak_ptr.hpp>
-
 
 class Buffer;
 class BufferView;
@@ -98,10 +96,6 @@ private:
        ///
        dispatch_result lfunMouseMotion(FuncRequest const &);
 
-protected:
-       void cache(BufferView *) const;
-       BufferView * view() const;
-
 protected:
 
        /** Find the PreviewLoader, add a LaTeX snippet to it and
@@ -121,9 +115,6 @@ protected:
        mutable int xo_;
        ///
        mutable int yo_;
-private:
-       // Cache
-       mutable boost::weak_ptr<BufferView> view_;
 };
 
 // We don't really mess want around with mathed stuff outside mathed.
index 545f64fb7a809982501dc3293d127f4986d6deff..e307beb66f572e18a2f283d9cec0bd5d5039afb2 100644 (file)
@@ -1,3 +1,13 @@
+2003-10-14  Angus Leeming  <leeming@lyx.org>
+
+       * Makefile.am: move boost.C from the linked_files section
+       to the tex2lyx_SOURCES section.
+
+       * boost.C: new file. Simpler than the version in the main lyx source.
+       No reference to the emergencyCleanup stuff.
+
+       * tex2lyx.C: remove emergencyCleanup() stuff.
+
 2003-10-08  Angus Leeming  <leeming@lyx.org>
 
        Fix doxygen warnings.
index 8eb294b56d673906cf2714ce0bc236900215fcbc..ffa371e66b379001ddc4eb0815b425c6d30af2ee 100644 (file)
@@ -16,7 +16,6 @@ bin_PROGRAMS = tex2lyx
 linked_files = \
        FloatList.C \
        Floating.C \
-       boost.C \
        counters.C \
        lyxlayout.h \
        lyxlayout.C \
@@ -28,6 +27,7 @@ linked_files = \
 tex2lyx_SOURCES = \
        $(linked_files) \
        Spacing.h \
+       boost.C \
        context.C \
        context.h \
        gettext.C \
diff --git a/src/tex2lyx/boost.C b/src/tex2lyx/boost.C
new file mode 100644 (file)
index 0000000..f923302
--- /dev/null
@@ -0,0 +1,41 @@
+/**
+ * \file boost.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Lars Gullik Bjønnes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "debug.h"
+
+#include <boost/assert.hpp>
+
+#include <cstdlib>
+#include <exception>
+
+using std::endl;
+
+namespace boost {
+
+void throw_exception(std::exception const & e)
+{
+       lyxerr << "Exception caught:\n"
+              << e.what() << endl;
+       BOOST_ASSERT(false);
+}
+
+
+void assertion_failed(char const * expr, char const * function,
+                     char const * file, long line)
+{
+       lyxerr << "Assertion triggered in " << function
+              << " by failing check \"" << expr << "\""
+              << " in file " << file << ":" << line << endl;
+       ::abort();
+}
+
+} // namespace boost
index c59ae906259755e1f35947d55ff47bc749fc270f..da40cb21cdfbd0cbc9ad1cc3617156004191e6d8 100644 (file)
@@ -16,7 +16,6 @@
 #include "context.h"
 
 #include "debug.h"
-#include "lyx_main.h"
 #include "lyxtextclass.h"
 #include "support/path_defines.h"
 #include "support/os.h"
@@ -43,8 +42,6 @@ using std::vector;
 // Hacks to allow the thing to link in the lyxlayout stuff
 LyXErr lyxerr(std::cerr.rdbuf());
 
-void LyX::emergencyCleanup() {}
-
 void handle_comment(Parser & p)
 {
        string s;