bv_->showErrorList(_("Parse"));
if (tolastfiles)
- lastfiles->newFile(b->fileName());
+ LyX::ref().lastfiles().newFile(b->fileName());
return true;
}
+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>
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) + ". "
didCleanup = true;
- LyX::emergencyCleanup();
+ LyX::cref().emergencyCleanup();
}
}
if (!WriteAs(buf))
return false;
} else if (buf->save()) {
- lastfiles->newFile(buf->fileName());
+ LyX::ref().lastfiles().newFile(buf->fileName());
} else {
return false;
}
+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,
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;
+}
class Buffer;
class Toolbar;
+class InsetOld;
class Intl;
class Menubar;
class ControlCommandBuffer;
/// 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_;
+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,
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();
+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.
// FIXME: move this stuff out again
#include "bufferlist.h"
+#include "lyx_main.h"
#include "LyXAction.h"
#include "lyxfunc.h"
#include "lyxrc.h"
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();
+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,
}
// emergency cleanup
- LyX::emergencyCleanup();
+ LyX::cref().emergencyCleanup();
// Get the reason for the crash.
char etxt[513];
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();
+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
#include "gettext.h"
#include "LaTeXFeatures.h"
#include "latexrunparams.h"
+#include "lyx_main.h"
#include "lyxlex.h"
#include "lyxrc.h"
#include "metricsinfo.h"
}
-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);
}
void InsetExternal::draw(PainterInfo & pi, int x, int y) const
{
- cache(pi.base.bv);
renderer_->draw(pi, x, y);
}
#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.
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.
*/
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_;
};
#include "gettext.h"
#include "LaTeXFeatures.h"
#include "latexrunparams.h"
+#include "lyx_main.h"
#include "lyxlex.h"
#include "lyxrc.h"
#include "metricsinfo.h"
}
-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);
}
void InsetGraphics::draw(PainterInfo & pi, int x, int y) const
{
- cache(pi.base.bv);
graphic_->draw(pi, x, y);
}
#include <boost/scoped_ptr.hpp>
#include <boost/signals/trackable.hpp>
-#include <boost/weak_ptr.hpp>
-
class Dialogs;
class RenderGraphic;
///
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.
*/
/// The thing that actually draws the image on LyX's screen.
boost::scoped_ptr<RenderGraphic> const graphic_;
-
- /// Cached
- mutable boost::weak_ptr<BufferView> view_;
};
#include "gettext.h"
#include "LaTeXFeatures.h"
#include "latexrunparams.h"
+#include "lyx_main.h"
#include "lyxlex.h"
#include "metricsinfo.h"
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);
}
}
-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);
}
#include "insetcommandparams.h"
#include "render_button.h"
#include <boost/scoped_ptr.hpp>
-#include <boost/weak_ptr.hpp>
-
class Buffer;
class Dimension;
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
boost::scoped_ptr<RenderMonitoredPreview> const preview_;
/// cache
- mutable boost::weak_ptr<BufferView> view_;
mutable bool set_label_;
mutable RenderButton button_;
};
#ifndef INSET_LABEL_H
#define INSET_LABEL_H
-
#include "insetcommand.h"
-#include <boost/weak_ptr.hpp>
class InsetLabel : public InsetCommand {
public:
bool MenuWrite(Buffer * buffer)
{
if (buffer->save()) {
- lastfiles->newFile(buffer->fileName());
+ LyX::ref().lastfiles().newFile(buffer->fileName());
return true;
}
if (!bufferlist.quitWriteAll())
return;
- lastfiles->writeFile(lyxrc.lastfiles);
+ LyX::cref().lastfiles().writeFile(lyxrc.lastfiles);
}
// Set a flag that we do quitting from the program,
#include "frontends/Alert.h"
#include "frontends/lyx_gui.h"
+#include "frontends/LyXView.h"
#include "support/FileInfo.h"
#include "support/filetools.h"
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::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"
signal(SIGTERM, SIG_DFL);
signal(SIGPIPE, SIG_DFL);
- LyX::emergencyCleanup();
+ LyX::cref().emergencyCleanup();
lyxerr << "Bye." << endl;
if (err_sig!= SIGHUP &&
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));
}
}
-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
#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
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
// initialize for internationalized version *EK*
locale_init();
- LyX lyx(argc, argv);
+ LyX::exec(argc, argv);
return 0;
}
+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
#include "debug.h"
#include "latexrunparams.h"
#include "LColor.h"
+#include "lyx_main.h"
#include "frontends/Painter.h"
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() &&
void InsetFormula::statusChanged() const
{
- if (view())
- view()->updateInset(this);
+ LyX::cref().updateInset(this);
}
#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;
-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
{}
#define INSET_FORMULABASE_H
#include "insets/updatableinset.h"
-#include <boost/weak_ptr.hpp>
-
class Buffer;
class BufferView;
///
dispatch_result lfunMouseMotion(FuncRequest const &);
-protected:
- void cache(BufferView *) const;
- BufferView * view() const;
-
protected:
/** Find the PreviewLoader, add a LaTeX snippet to it and
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.
+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.
linked_files = \
FloatList.C \
Floating.C \
- boost.C \
counters.C \
lyxlayout.h \
lyxlayout.C \
tex2lyx_SOURCES = \
$(linked_files) \
Spacing.h \
+ boost.C \
context.C \
context.h \
gettext.C \
--- /dev/null
+/**
+ * \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
#include "context.h"
#include "debug.h"
-#include "lyx_main.h"
#include "lyxtextclass.h"
#include "support/path_defines.h"
#include "support/os.h"
// 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;