]> git.lyx.org Git - lyx.git/blobdiff - src/insets/Inset.cpp
Stupid bug fix.
[lyx.git] / src / insets / Inset.cpp
index 1f2e2eefe41e504aa3e374db212776be3c6d0af6..095cdaa4823e1a5a7da021ffb0d730667118ae22 100644 (file)
@@ -18,6 +18,7 @@
 
 #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/assert.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>
 
@@ -93,7 +94,6 @@ 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("newline", NEWLINE_CODE),
                InsetName("line", LINE_CODE),
                InsetName("branch", BRANCH_CODE),
@@ -148,6 +148,12 @@ Buffer const & Inset::buffer() const
 }
 
 
+bool Inset::isBufferValid() const
+{
+       return buffer_ && theBufferList().isLoaded(buffer_);
+}
+
+
 docstring Inset::name() const
 {
        return from_ascii("unknown");
@@ -210,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;
+       }
 }
 
 
@@ -233,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;
 }