]> git.lyx.org Git - lyx.git/blobdiff - src/insets/Inset.cpp
Introduce BufferException so that we don't crash if a problem affects only current...
[lyx.git] / src / insets / Inset.cpp
index 3bfd0a4aed2735028f58ced4a0c1db3403941697..b82f264874319cce97d63cbaccb1b46f616b38f9 100644 (file)
 
 #include "support/convert.h"
 #include "support/debug.h"
+#include "support/docstream.h"
+#include "support/ExceptionMessage.h"
 #include "support/gettext.h"
 
 #include <map>
 
 using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 
@@ -116,6 +119,30 @@ static TranslatorMap const build_translator()
 }
 
 
+void Inset::setBuffer(Buffer & buffer)
+{
+       buffer_ = &buffer;
+}
+
+
+Buffer & Inset::buffer()
+{
+       if (!buffer_) {
+               odocstringstream s;
+               s << "LyX Code: " << lyxCode() << " name: " << name();
+               throw ExceptionMessage(BufferException, 
+                       from_ascii("Inset::buffer_ member not initialized!"), s.str());
+       }
+       return *buffer_;
+}
+
+
+Buffer const & Inset::buffer() const
+{
+       return const_cast<Inset *>(this)->buffer();
+}
+
+
 docstring Inset::name() const
 {
        return from_ascii("unknown");
@@ -245,8 +272,7 @@ bool Inset::idxUpDown(Cursor &, bool) const
 }
 
 
-int Inset::docbook(Buffer const &,
-       odocstream &, OutputParams const &) const
+int Inset::docbook(odocstream &, OutputParams const &) const
 {
        return 0;
 }
@@ -270,7 +296,7 @@ bool Inset::autoDelete() const
 }
 
 
-docstring const Inset::editMessage() const
+docstring Inset::editMessage() const
 {
        return _("Opened inset");
 }
@@ -360,14 +386,13 @@ bool Inset::covers(BufferView const & bv, int x, int y) const
 
 InsetLayout const & Inset::getLayout(BufferParams const & bp) const
 {
-       return bp.textClass().insetLayout(name());  
+       return bp.documentClass().insetLayout(name());  
 }
 
 
 void Inset::dump() const
 {
-       Buffer buf("foo", 1);
-       write(buf, lyxerr);
+       write(lyxerr);
 }
 
 
@@ -392,7 +417,7 @@ void Inset::setDimCache(MetricsInfo const & mi, Dimension const & dim) const
 
 Buffer const * Inset::updateFrontend() const
 {
-       return theApp()? theApp()->updateInset(this) : 0;
+       return theApp() ? theApp()->updateInset(this) : 0;
 }
 
 } // namespace lyx