#include "debug.h"
#include "gettext.h"
-#include "LyXLex.h"
+#include "Lexer.h"
#include "support/ExceptionMessage.h"
#include "support/lstrings.h"
using support::ExceptionMessage;
using support::WarningException;
-InsetCommandParams::InsetCommandParams(string const & name)
- : name_(name), preview_(false)
+
+//FIXME There is no reason now for this to take a string argument.
+//It'd be much more robust if it took an Inset::Code, since then
+//the compiler would do some checking for us.
+InsetCommandParams::InsetCommandParams(string const & insetType)
+ : insetType_(insetType), preview_(false)
+{
+ cmdName_ = getDefaultCmd(insetType);
+ info_ = findInfo(insetType, cmdName_);
+ BOOST_ASSERT(info_);
+ params_.resize(info_->n);
+}
+
+
+InsetCommandParams::InsetCommandParams(string const & insetType,
+ string const & cmdName)
+ : insetType_(insetType), cmdName_(cmdName), preview_(false)
{
- info_ = findInfo(name);
+ info_ = findInfo(insetType, cmdName);
BOOST_ASSERT(info_);
params_.resize(info_->n);
}
+//FIXME This should go into the Insets themselves...so they will tell
+//us what parameters they want.
+//Should this just vanish in favor of the two arg version, or is there
+//a reason to use it in some cases? What should happen in the single
+//arg case, then? Maybe use the default? or leave that up to the inset?
InsetCommandParams::CommandInfo const *
-InsetCommandParams::findInfo(std::string const & name)
+InsetCommandParams::findInfo(std::string const & insetType)
{
// No parameter may be named "preview", because that is a required
// flag for all commands.
// InsetBibitem
- if (name == "bibitem") {
+ if (insetType == "bibitem") {
static const char * const paramnames[] = {"label", "key", ""};
static const bool isoptional[] = {true, false};
static const CommandInfo info = {2, paramnames, isoptional};
}
// InsetBibtex
- if (name == "bibtex") {
+ if (insetType == "bibtex") {
static const char * const paramnames[] =
{"options", "btprint", "bibfiles", ""};
static const bool isoptional[] = {true, true, false};
}
// InsetCitation
- // FIXME: Use is_possible_cite_command() in
- // src/frontends/controllers/frontend_helpers.cpp, see comment in src/factory.cpp.
- if (name == "cite" || name == "citet" || name == "citep" || name == "citealt" ||
- name == "citealp" || name == "citeauthor" || name == "citeyear" ||
- name == "citeyearpar" || name == "citet*" || name == "citep*" ||
- name == "citealt*" || name == "citealp*" ||
- name == "citeauthor*" || name == "Citet" || name == "Citep" ||
- name == "Citealt" || name == "Citealp" || name == "Citeauthor" ||
- name == "Citet*" || name == "Citep*" || name == "Citealt*" ||
- name == "Citealp*" || name == "Citeauthor*" ||
- name == "citefield" || name == "citetitle" || name == "cite*") {
+ if (insetType == "citation") {
// standard cite does only take one argument if jurabib is
// not used, but jurabib extends this to two arguments, so
// we have to allow both here. InsetCitation takes care that
}
// InsetFloatlist
- if (name == "floatlist") {
+ if (insetType == "floatlist") {
static const char * const paramnames[] = {"type", ""};
static const bool isoptional[] = {false};
static const CommandInfo info = {1, paramnames, isoptional};
}
// InsetHfill
- if (name == "hfill") {
+ if (insetType == "hfill") {
static const char * const paramnames[] = {""};
static const CommandInfo info = {0, paramnames, 0};
return &info;
}
// InsetInclude
- if (name == "include" || name == "input" || name == "verbatiminput" ||
- name == "verbatiminput*") {
- static const char * const paramnames[] = {"filename", ""};
- static const bool isoptional[] = {false};
- static const CommandInfo info = {1, paramnames, isoptional};
+ //FIXME This is really correct only for lstinputlistings, but it shouldn't
+ //cause a problem before we get things sorted out. Eventually, this calls
+ //InsetInclude::getParams(cmdName_), or something of the sort.
+ if (insetType == "include") {
+ static const char * const paramnames[] = {"filename", "lstparams", ""};
+ static const bool isoptional[] = {false, true};
+ static const CommandInfo info = {2, paramnames, isoptional};
return &info;
}
// InsetIndex, InsetPrintIndex, InsetLabel
- if (name == "index" || name == "printindex" || name == "label") {
+ if (insetType == "index" || insetType == "index_print" || insetType == "label") {
static const char * const paramnames[] = {"name", ""};
static const bool isoptional[] = {false};
static const CommandInfo info = {1, paramnames, isoptional};
}
// InsetNomencl
- if (name == "nomenclature") {
+ if (insetType == "nomenclature") {
static const char * const paramnames[] = {"prefix", "symbol", "description", ""};
static const bool isoptional[] = {true, false, false};
static const CommandInfo info = {3, paramnames, isoptional};
}
// InsetPrintNomencl
- if (name == "printnomenclature") {
+ if (insetType == "nomencl_print") {
static const char * const paramnames[] = {"labelwidth", ""};
static const bool isoptional[] = {true};
static const CommandInfo info = {1, paramnames, isoptional};
}
// InsetRef
- if (name == "eqref" || name == "pageref" || name == "vpageref" ||
- name == "vref" || name == "prettyref" || name == "ref") {
+ if (insetType == "ref") {
static const char * const paramnames[] =
{"name", "reference", ""};
static const bool isoptional[] = {true, false};
}
// InsetTOC
- if (name == "tableofcontents") {
+ if (insetType == "toc") {
static const char * const paramnames[] = {"type", ""};
static const bool isoptional[] = {false};
static const CommandInfo info = {1, paramnames, isoptional};
}
// InsetUrl
- if (name == "htmlurl" || name == "url") {
+ if (insetType == "url") {
static const char * const paramnames[] =
{"name", "target", ""};
static const bool isoptional[] = {true, false};
}
+//FIXME Will eventually call a static method, etc.
+InsetCommandParams::CommandInfo const *
+ InsetCommandParams::findInfo(std::string const & insetType,
+ std::string const & cmdName)
+{
+ return findInfo(insetType);
+}
+
+
+//FIXME Should call InsetBibitem::getDefaultCmd(), eg
+std::string InsetCommandParams::getDefaultCmd(std::string insetType) {
+ if (insetType == "bibitem")
+ return "bibitem";
+ if (insetType == "bibtex")
+ return "";
+ if (insetType == "citation")
+ return "cite";
+ if (insetType == "floatlist")
+ return "";
+ if (insetType == "hfill")
+ return "hfill";
+ if (insetType == "include")
+ return "include";
+ if (insetType == "index")
+ return "index";
+ if (insetType == "index_print")
+ return "print_index";
+ if (insetType == "label")
+ return "label";
+ if (insetType == "nomenclature")
+ return "nomenclature";
+ if (insetType == "nomencl_print")
+ return "printnomenclature";
+ if (insetType == "ref")
+ return "ref";
+ if (insetType == "toc")
+ return "tableofcontents";
+ if (insetType == "url")
+ return "url";
+ return "";
+}
+
+
void InsetCommandParams::setCmdName(string const & name)
{
- name_ = name;
- CommandInfo const * const info = findInfo(name);
+ //FIXME Check command compatibility
+ cmdName_ = name;
+ BOOST_ASSERT(!insetType_.empty());
+ CommandInfo const * const info = findInfo(insetType_, cmdName_);
BOOST_ASSERT(info);
ParamVector params(info->n);
// Overtake parameters with the same name
}
-void InsetCommandParams::read(LyXLex & lex)
+void InsetCommandParams::read(Lexer & lex)
{
+ //FIXME
if (lex.isOK()) {
lex.next();
- name_ = lex.getString();
- info_ = findInfo(name_);
- if (!info_) {
- lex.printError("InsetCommand: Unknown inset name `$$Token'");
- throw ExceptionMessage(WarningException,
- _("Unknown inset name: "),
- from_utf8(name_));
+ string insetType = lex.getString();
+ if (!insetType_.empty() && insetType != insetType_) {
+ lex.printError("InsetCommand: Attempt to change type of parameters.");
+ throw ExceptionMessage(WarningException, _("InsetCommand Error: "),
+ from_utf8("Attempt to change type of parameters."));
}
+ // OK, we survived...
+ insetType_ = insetType;
}
+ if (lex.isOK()) {
+ lex.next();
+ string test = lex.getString();
+ if (test != "LatexCommand") {
+ lex.printError("InsetCommand: no LatexCommand line found.");
+ throw ExceptionMessage(WarningException, _("InsetCommand error:"),
+ from_utf8("Can't find LatexCommand line."));
+ }
+ }
+ lex.next();
+ cmdName_ = lex.getString();
+ //FIXME
+ //check that this command is ok with the inset...
+ //so that'll be some kind of static call, depending
+ //upon what insetType_ is.
+ //it's possible that should go into InsetCommand.cpp,
+ //or maybe it's a standalone function.
+ info_ = findInfo(insetType_, cmdName_);
+ if (!info_) {
+ lex.printError("InsetCommand: Unknown inset name `$$Token'");
+ throw ExceptionMessage(WarningException,
+ _("Unknown inset name: "), from_utf8(insetType_));
+ }
+
string token;
while (lex.isOK()) {
lex.next();
lex.next(true);
params_[i] = lex.getDocString();
} else {
- lex.printError("Unknown parameter name `$$Token' for command " + name_);
+ lex.printError("Unknown parameter name `$$Token' for command " + cmdName_);
throw ExceptionMessage(WarningException,
- _("Inset Command: ") + from_ascii(name_),
+ _("Inset Command: ") + from_ascii(cmdName_),
_("Unknown parameter name: ") + from_utf8(token));
}
}
void InsetCommandParams::write(ostream & os) const
{
- os << "LatexCommand " << name_ << '\n';
+ os << "CommandInset " << insetType_ << '\n';
+ os << "LatexCommand " << cmdName_ << '\n';
for (size_t i = 0; i < info_->n; ++i)
if (!params_[i].empty())
// FIXME UNICODE
os << info_->paramnames[i] << ' '
- << LyXLex::quoteString(to_utf8(params_[i]))
+ << Lexer::quoteString(to_utf8(params_[i]))
<< '\n';
}
docstring const InsetCommandParams::getCommand() const
{
- docstring s = '\\' + from_ascii(name_);
+ docstring s = '\\' + from_ascii(cmdName_);
bool noparam = true;
for (size_t i = 0; i < info_->n; ++i) {
if (info_->optional[i]) {
if (info_->optional[i])
return to_utf8(params_[i]);
lyxerr << "Programming error: get nonexisting option in "
- << name_ << " inset." << endl;;
+ << insetType_ << " inset." << endl;
return string();
}
}
// Happens in InsetCitation
lyxerr << "Programming error: get nonexisting second option in "
- << name_ << " inset." << endl;;
+ << insetType_ << " inset." << endl;
return string();
}
return;
}
lyxerr << "Programming error: set nonexisting option in "
- << name_ << " inset." << endl;;
+ << insetType_ << " inset." << endl;
}
}
// Happens in InsetCitation
lyxerr << "Programming error: set nonexisting second option in "
- << name_ << " inset." << endl;;
+ << insetType_ << " inset." << endl;
}
bool operator==(InsetCommandParams const & o1,
InsetCommandParams const & o2)
{
- return o1.name_ == o2.name_ &&
+ return o1.insetType_ == o2.insetType_ &&
+ o1.cmdName_ == o2.cmdName_ &&
o1.info_ == o2.info_ &&
o1.params_ == o2.params_ &&
o1.preview_ == o2.preview_;