]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetcommandparams.C
* In the process of fixing the math background color bug, this commit transfer backgr...
[lyx.git] / src / insets / insetcommandparams.C
index ab61de201cf8ce23cbf4d6255a176e8488f9c3eb..fd1f9a8a47c620c3166ae71a5dee811bc27b5d45 100644 (file)
 #include "insetcommandparams.h"
 
 #include "debug.h"
+#include "gettext.h"
 #include "lyxlex.h"
 
+#include "support/ExceptionMessage.h"
 #include "support/lstrings.h"
 
 #include <boost/assert.hpp>
@@ -29,6 +31,8 @@ using std::string;
 using std::endl;
 using std::ostream;
 
+using support::ExceptionMessage;
+using support::WarningException;
 
 InsetCommandParams::InsetCommandParams(string const & name)
        : name_(name), preview_(false)
@@ -117,6 +121,22 @@ InsetCommandParams::findInfo(std::string const & name)
                return &info;
        }
 
+       // InsetNomencl
+       if (name == "nomenclature") {
+               static const char * const paramnames[] = {"prefix", "symbol", "description", ""};
+               static const bool isoptional[] = {true, false, false};
+               static const CommandInfo info = {3, paramnames, isoptional};
+               return &info;
+       }
+
+       // InsetPrintNomencl
+       if (name == "printnomenclature") {
+               static const char * const paramnames[] = {"labelwidth", ""};
+               static const bool isoptional[] = {true};
+               static const CommandInfo info = {1, paramnames, isoptional};
+               return &info;
+       }
+
        // InsetRef
        if (name == "eqref" || name == "pageref" || name == "vpageref" ||
            name == "vref" || name == "prettyref" || name == "ref") {
@@ -227,13 +247,12 @@ void InsetCommandParams::scanCommand(string const & cmd)
        if (!tsecoptions.empty())  setSecOptions(tsecoptions);
        if (!tcontents.empty()) setContents(tcontents);
 
-       if (lyxerr.debugging(Debug::PARSER))
-               lyxerr << "Command <" <<  cmd
-                      << "> == <" << to_utf8(getCommand())
-                      << "> == <" << getCmdName()
-                      << '|' << getContents()
-                      << '|' << getOptions()
-                      << '|' << getSecOptions() << '>' << endl;
+       LYXERR(Debug::PARSER) << "Command <" <<  cmd
+               << "> == <" << to_utf8(getCommand())
+               << "> == <" << getCmdName()
+               << '|' << getContents()
+               << '|' << getOptions()
+               << '|' << getSecOptions() << '>' << endl;
 }
 
 
@@ -243,8 +262,12 @@ void InsetCommandParams::read(LyXLex & lex)
                lex.next();
                name_ = lex.getString();
                info_ = findInfo(name_);
-               if (!info_)
+               if (!info_) {
                        lex.printError("InsetCommand: Unknown inset name `$$Token'");
+                       throw ExceptionMessage(WarningException,
+                               _("Unknown inset name: "),
+                               from_utf8(name_));
+               }
        }
 
        string token;
@@ -263,12 +286,19 @@ void InsetCommandParams::read(LyXLex & lex)
                if (i >= 0) {
                        lex.next(true);
                        params_[i] = lex.getDocString();
-               } else
+               } else {
                        lex.printError("Unknown parameter name `$$Token' for command " + name_);
+                       throw ExceptionMessage(WarningException,
+                               _("Inset Command :") + from_ascii(name_),
+                               _("Unknown parameter name: ") + from_utf8(token));
+               }
        }
        if (token != "\\end_inset") {
                lex.printError("Missing \\end_inset at this point. "
                               "Read: `$$Token'");
+               throw ExceptionMessage(WarningException,
+                       _("Missing \\end_inset at this point."),
+                       from_utf8(token));
        }
 }
 
@@ -288,6 +318,7 @@ void InsetCommandParams::write(ostream & os) const
 docstring const InsetCommandParams::getCommand() const
 {
        docstring s = '\\' + from_ascii(name_);
+       bool noparam = true;
        for (size_t i = 0; i < info_->n; ++i) {
                if (info_->optional[i]) {
                        if (params_[i].empty()) {
@@ -299,14 +330,23 @@ docstring const InsetCommandParams::getCommand() const
                                                break;
                                        if (!params_[j].empty()) {
                                                s += "[]";
+                                               noparam = false;
                                                break;
                                        }
                                }
-                       } else
+                       } else {
                                s += '[' + params_[i] + ']';
-               } else
+                               noparam = false;
+                       }
+               } else {
                        s += '{' + params_[i] + '}';
+                       noparam = false;
+               }
        }
+       if (noparam)
+               // Make sure that following stuff does not change the
+               // command name.
+               s += "{}";
        return s;
 }