]> git.lyx.org Git - lyx.git/blobdiff - src/insets/Inset.cpp
Stupid bug fix.
[lyx.git] / src / insets / Inset.cpp
index 8a028096deeb07c4e4321c8a16b8cce6b1e0456c..095cdaa4823e1a5a7da021ffb0d730667118ae22 100644 (file)
@@ -16,7 +16,9 @@
 
 #include "Inset.h"
 
+#include "buffer_funcs.h"
 #include "Buffer.h"
+#include "BufferList.h"
 #include "BufferParams.h"
 #include "BufferView.h"
 #include "CoordCache.h"
 #include "Text.h"
 #include "TextClass.h"
 
-#include "frontends/Painter.h"
 #include "frontends/Application.h"
+#include "frontends/Painter.h"
 
 #include "support/convert.h"
 #include "support/debug.h"
+#include "support/docstream.h"
+#include "support/ExceptionMessage.h"
 #include "support/gettext.h"
+#include "support/lassert.h"
 
 #include <map>
 
 using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 
@@ -88,19 +94,19 @@ static TranslatorMap const build_translator()
                InsetName("index_print", INDEX_PRINT_CODE),
                InsetName("nomencl_print", NOMENCL_PRINT_CODE),
                InsetName("optarg", OPTARG_CODE),
-               InsetName("environment", ENVIRONMENT_CODE),
-               InsetName("hfill", HFILL_CODE),
                InsetName("newline", NEWLINE_CODE),
                InsetName("line", LINE_CODE),
                InsetName("branch", BRANCH_CODE),
                InsetName("box", BOX_CODE),
                InsetName("flex", FLEX_CODE),
+               InsetName("space", SPACE_CODE),
                InsetName("vspace", VSPACE_CODE),
                InsetName("mathmacroarg", MATHMACROARG_CODE),
                InsetName("listings", LISTINGS_CODE),
                InsetName("info", INFO_CODE),
                InsetName("collapsable", COLLAPSABLE_CODE),
                InsetName("newpage", NEWPAGE_CODE),
+               InsetName("tablecell", CELL_CODE)
        };
 
        size_t const insetnames_size =
@@ -122,25 +128,29 @@ void Inset::setBuffer(Buffer & buffer)
 }
 
 
-static Buffer & theDummyBuffer()
+Buffer & Inset::buffer()
 {
-       static Buffer dummyBuffer("nobuffer.lyx", true);
-       return dummyBuffer;
+       if (!buffer_) {
+               odocstringstream s;
+               lyxerr << "LyX Code: " << lyxCode() << " name: " << name() << std::endl;
+               s << "LyX Code: " << lyxCode() << " name: " << name();
+               LASSERT(false, /**/);
+               throw ExceptionMessage(BufferException, 
+                       from_ascii("Inset::buffer_ member not initialized!"), s.str());
+       }
+       return *buffer_;
 }
 
 
-Buffer & Inset::buffer()
+Buffer const & Inset::buffer() const
 {
-       if (buffer_)
-               return *buffer_;
-       LYXERR0("DUMMYBUFFER FOR " << lyxCode());
-       return theDummyBuffer();
+       return const_cast<Inset *>(this)->buffer();
 }
 
 
-Buffer const & Inset::buffer() const
+bool Inset::isBufferValid() const
 {
-       return const_cast<Inset *>(this)->buffer();
+       return buffer_ && theBufferList().isLoaded(buffer_);
 }
 
 
@@ -150,6 +160,13 @@ docstring Inset::name() const
 }
 
 
+void Inset::initView()
+{
+       if (isLabeled())
+               lyx::updateLabels(buffer());
+}
+
+
 docstring Inset::toolTip(BufferView const &, int, int) const
 {
        return docstring();
@@ -199,10 +216,18 @@ void Inset::dispatch(Cursor & cur, FuncRequest & cmd)
 }
 
 
-void Inset::doDispatch(Cursor & cur, FuncRequest &)
+void Inset::doDispatch(Cursor & cur, FuncRequest &cmd)
 {
-       cur.noUpdate();
-       cur.undispatched();
+       switch (cmd.action) {
+       case LFUN_INSET_TOGGLE:
+               edit(cur, true);
+               cur.dispatched();
+               break;
+       default:
+               cur.noUpdate();
+               cur.undispatched();
+               break;
+       }
 }
 
 
@@ -222,19 +247,25 @@ bool Inset::getStatus(Cursor &, FuncRequest const & cmd,
                // Allow modification of our data.
                // This needs to be handled in the doDispatch method of our
                // instantiatable children.
-               flag.enabled(true);
+               flag.setEnabled(true);
                return true;
 
        case LFUN_INSET_INSERT:
                // Don't allow insertion of new insets.
                // Every inset that wants to allow new insets from open
                // dialogs needs to override this.
-               flag.enabled(false);
+               flag.setEnabled(false);
+               return true;
+
+       case LFUN_INSET_TOGGLE:
+               // remove this if we dissociate toggle from edit.
+               flag.setEnabled(editable() == IS_EDITABLE);
                return true;
 
        default:
-               return false;
+               break;
        }
+       return false;
 }
 
 
@@ -387,7 +418,7 @@ 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());  
 }
 
 
@@ -421,4 +452,10 @@ Buffer const * Inset::updateFrontend() const
        return theApp() ? theApp()->updateInset(this) : 0;
 }
 
+
+docstring Inset::completionPrefix(Cursor const &) const 
+{
+       return docstring();
+}
+
 } // namespace lyx