]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetcommandparams.C
* BufferParams:
[lyx.git] / src / insets / insetcommandparams.C
index 288f885609a806b0ebdfea88aa1ddd3f4564860a..bd0c208ef2a7603e4dbc9bb076e96821eb204fe7 100644 (file)
@@ -21,8 +21,9 @@
 #include <boost/assert.hpp>
 
 
-using lyx::docstring;
-using lyx::support::findToken;
+namespace lyx {
+
+using support::findToken;
 
 using std::string;
 using std::endl;
@@ -116,6 +117,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") {
@@ -228,7 +245,7 @@ void InsetCommandParams::scanCommand(string const & cmd)
 
        if (lyxerr.debugging(Debug::PARSER))
                lyxerr << "Command <" <<  cmd
-                      << "> == <" << lyx::to_utf8(getCommand())
+                      << "> == <" << to_utf8(getCommand())
                       << "> == <" << getCmdName()
                       << '|' << getContents()
                       << '|' << getOptions()
@@ -279,14 +296,15 @@ void InsetCommandParams::write(ostream & os) const
                if (!params_[i].empty())
                        // FIXME UNICODE
                        os << info_->paramnames[i] << ' '
-                          << LyXLex::quoteString(lyx::to_utf8(params_[i]))
+                          << LyXLex::quoteString(to_utf8(params_[i]))
                           << '\n';
 }
 
 
 docstring const InsetCommandParams::getCommand() const
 {
-       docstring s = '\\' + lyx::from_ascii(name_);
+       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()) {
@@ -298,14 +316,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;
 }
 
@@ -314,7 +341,7 @@ std::string const InsetCommandParams::getOptions() const
 {
        for (size_t i = 0; i < info_->n; ++i)
                if (info_->optional[i])
-                       return lyx::to_utf8(params_[i]);
+                       return to_utf8(params_[i]);
        lyxerr << "Programming error: get nonexisting option in "
               << name_ << " inset." << endl;; 
        return string();
@@ -329,7 +356,7 @@ std::string const InsetCommandParams::getSecOptions() const
                        if (first)
                                first = false;
                        else
-                               return lyx::to_utf8(params_[i]);
+                               return to_utf8(params_[i]);
                }
        // Happens in InsetCitation
        lyxerr << "Programming error: get nonexisting second option in "
@@ -342,7 +369,7 @@ std::string const InsetCommandParams::getContents() const
 {
        for (size_t i = 0; i < info_->n; ++i)
                if (!info_->optional[i])
-                       return lyx::to_utf8(params_[i]);
+                       return to_utf8(params_[i]);
        BOOST_ASSERT(false);
        return string();
 }
@@ -352,7 +379,7 @@ void InsetCommandParams::setOptions(std::string const & o)
 {
        for (size_t i = 0; i < info_->n; ++i)
                if (info_->optional[i]) {
-                       params_[i] = lyx::from_utf8(o);
+                       params_[i] = from_utf8(o);
                        return;
                }
        lyxerr << "Programming error: set nonexisting option in "
@@ -368,7 +395,7 @@ void InsetCommandParams::setSecOptions(std::string const & s)
                        if (first)
                                first = false;
                        else {
-                               params_[i] = lyx::from_utf8(s);
+                               params_[i] = from_utf8(s);
                                return;
                        }
                }
@@ -382,7 +409,7 @@ void InsetCommandParams::setContents(std::string const & c)
 {
        for (size_t i = 0; i < info_->n; ++i)
                if (!info_->optional[i]) {
-                       params_[i] = lyx::from_utf8(c);
+                       params_[i] = from_utf8(c);
                        return;
                }
        BOOST_ASSERT(false);
@@ -427,3 +454,6 @@ bool operator!=(InsetCommandParams const & o1,
 {
        return !(o1 == o2);
 }
+
+
+} // namespace lyx