]> git.lyx.org Git - lyx.git/blobdiff - src/Text3.cpp
Fix broken layout file syntax
[lyx.git] / src / Text3.cpp
index ecb5d257641f21c049e6ab4ae7c44d2ff08ae6a0..9cace0df53822176dcb873b498035eb62c2c6712 100644 (file)
@@ -51,6 +51,7 @@
 #include "frontends/Clipboard.h"
 #include "frontends/Selection.h"
 
+#include "insets/InsetArgument.h"
 #include "insets/InsetCollapsable.h"
 #include "insets/InsetCommand.h"
 #include "insets/InsetExternal.h"
@@ -2320,6 +2321,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
 
        FontInfo const & fontinfo = cur.real_current_font.fontInfo();
        bool enable = true;
+       bool allow_in_passthru = false;
        InsetCode code = NO_CODE;
 
        switch (cmd.action()) {
@@ -2516,9 +2518,33 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                break;
        case LFUN_ARGUMENT_INSERT: {
                code = ARG_CODE;
+               allow_in_passthru = true;
+               string const arg = cmd.getArg(0);
+               if (arg.empty()) {
+                       enable = false;
+                       break;
+               }
                Layout const & lay = cur.paragraph().layout();
-               int const numargs = lay.reqargs + lay.optargs;
-               enable = cur.paragraph().insetList().count(ARG_CODE) < numargs;
+               Layout::LaTeXArgMap args = lay.latexargs();
+               Layout::LaTeXArgMap::const_iterator const lait =
+                               args.find(convert<unsigned int>(arg));
+               if (lait != args.end()) {
+                       enable = true;
+                       InsetList::const_iterator it = cur.paragraph().insetList().begin();
+                       InsetList::const_iterator const end = cur.paragraph().insetList().end();
+                       for (; it != end; ++it) {
+                               if (it->inset->lyxCode() == ARG_CODE) {
+                                       InsetArgument const * ins =
+                                               static_cast<InsetArgument const *>(it->inset);
+                                       if (ins->name() == arg) {
+                                               // we have this already
+                                               enable = false;
+                                               break;
+                                       }
+                               }
+                       }
+               } else
+                       enable = false;
                break;
        }
        case LFUN_INDEX_INSERT:
@@ -2889,7 +2915,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
        if (code != NO_CODE
            && (cur.empty() 
                || !cur.inset().insetAllowed(code)
-               || cur.paragraph().layout().pass_thru))
+               || (cur.paragraph().layout().pass_thru && !allow_in_passthru)))
                enable = false;
 
        flag.setEnabled(enable);