LyX file-format changes
-----------------------
+2007-09-25 Richard Heck <rgheck@bobjweil.com>
+ * Format incremented to 288: Change how command insets are
+ represented in LyX files.
+
2007-09-24 Uwe Stöhr <uwestoehr@web.de>
* Format incremented to 287: Add missing optional parameters
for wrapped figures.
("1_3", [221], minor_versions("1.3" , 7)),
("1_4", range(222,246), minor_versions("1.4" , 5)),
("1_5", range(246,277), minor_versions("1.5" , 1)),
- ("1_6", range(277,288), minor_versions("1.6" , 0))]
+ ("1_6", range(277,289), minor_versions("1.6" , 0))] #RGH, command insets
def formats_list():
i = i + 1
+def convert_inset_command(document):
+ """
+ Convert:
+ \begin_inset LatexCommand cmd
+ to
+ \begin_inset CommandInset InsetType
+ LatexCommand cmd
+ """
+ i = 0
+ while 1:
+ i = find_token(document.body, "\\begin_inset LatexCommand", i)
+ if i == -1:
+ return
+ line = document.body[i]
+ r = re.compile(r'\\begin_inset LatexCommand (.*)$')
+ m = r.match(line)
+ cmdName = m.group(1)
+ insetName = ""
+ #this is adapted from factory.cpp
+ if cmdName[0:4].lower() == "cite":
+ insetName = "citation"
+ elif cmdName == "url" or cmdName == "htmlurl":
+ insetName = "url"
+ elif cmdName[-3:] == "ref":
+ insetName = "ref"
+ elif cmdName == "tableofcontents":
+ insetName = "toc"
+ elif cmdName == "printnomenclature":
+ insetName = "nomencl_print"
+ elif cmdName == "printindex":
+ insetName = "index_print"
+ else:
+ insetName = cmdName
+ insertion = ["\\begin_inset CommandInset " + insetName, "LatexCommand " + cmdName]
+ document.body[i : i+1] = insertion
+
+
+def revert_inset_command(document):
+ """
+ Convert:
+ \begin_inset CommandInset InsetType
+ LatexCommand cmd
+ to
+ \begin_inset LatexCommand cmd
+ Some insets may end up being converted to insets earlier versions of LyX
+ will not be able to recognize. Not sure what to do about that.
+ """
+ i = 0
+ while 1:
+ i = find_token(document.body, "\\begin_inset CommandInset", i)
+ nextline = document.body[i+1]
+ r = re.compile(r'LatexCommand\s+(.*)$')
+ m = r.match(nextline)
+ if not m:
+ document.warning("Malformed LyX document: Missing LatexCommand in " + document.body[i] + ".")
+ continue
+ cmdName = m.group(1)
+ insertion = ["\\begin_inset LatexCommand " + cmdName]
+ document.body[i : i+2] = insertion
+
+
def convert_wrapfig_options(document):
"Convert optional options for wrap floats (wrapfig)."
# adds the tokens "lines", "placement", and "overhang"
[284, []],
[285, []], # an empty manifest is automatically added
[286, []],
- [287, [convert_wrapfig_options]]
+ [287, [convert_wrapfig_options]],
+ [288, [convert_inset_command]]
]
revert = [
+ [287, [revert_inset_command]],
[286, [revert_wrapfig_options]],
[285, [revert_pdf_options]],
[284, [remove_manifest, remove_inzip_options]],
namespace {
-int const LYX_FORMAT = 287;
+int const LYX_FORMAT = 288; //RGH, command insets
} // namespace anon
InsetBranchParams p;
data = InsetBranchMailer::params2string(p);
} else if (name == "citation") {
- InsetCommandParams p("cite");
+ InsetCommandParams p("citation");
data = InsetCommandMailer::params2string(name, p);
} else if (name == "ert") {
data = InsetERTMailer::params2string(InsetCollapsable::Open);
arg = token(argument, '|', 0);
opt1 = token(argument, '|', 1);
}
- InsetCommandParams icp("cite");
+ InsetCommandParams icp("citation");
icp["key"] = from_utf8(arg);
if (!opt1.empty())
icp["before"] = from_utf8(opt1);
}
case LFUN_INDEX_PRINT:
- return new InsetPrintIndex(InsetCommandParams("printindex"));
+ return new InsetPrintIndex(InsetCommandParams("index_print"));
case LFUN_NOMENCL_PRINT:
- return new InsetPrintNomencl(InsetCommandParams("printnomenclature"));
+ return new InsetPrintNomencl(InsetCommandParams("nomencl_print"));
case LFUN_TOC_INSERT:
- return new InsetTOC(InsetCommandParams("tableofcontents"));
+ return new InsetTOC(InsetCommandParams("toc"));
case LFUN_ENVIRONMENT_INSERT:
return new InsetEnvironment(params, cmd.argument());
return new InsetBibtex(icp);
} else if (name == "citation") {
- InsetCommandParams icp("cite");
+ InsetCommandParams icp("citation");
InsetCommandMailer::string2params(name, to_utf8(cmd.argument()),
icp);
return new InsetCitation(icp);
return new InsetRef(icp, bv->buffer());
} else if (name == "toc") {
- InsetCommandParams icp("tableofcontents");
+ InsetCommandParams icp("toc");
InsetCommandMailer::string2params(name, to_utf8(cmd.argument()),
icp);
return new InsetTOC(icp);
string tmptok = lex.getString();
// test the different insets
- if (tmptok == "LatexCommand") {
+ if (tmptok == "CommandInset") {
lex.next();
- string const cmdName = lex.getString();
- lex.pushToken(cmdName);
-
- InsetCommandParams inscmd(cmdName);
+ string const insetType = lex.getString();
+ lex.pushToken(insetType);
+
+ //FIXME
+ //Inset::Code const code = Inset::translate(insetType);
+ //if (code == Inset::NO_CODE) { choke as below; }
+ //InsetCommandParams inscmd();
+ InsetCommandParams inscmd(insetType);
inscmd.read(lex);
- // This strange command allows LyX to recognize "natbib" style
- // citations: citet, citep, Citet etc.
- // FIXME: We already have partial support for \\fullcite and
- // the various \\footcite commands. We should increase the
- // file format number and read these commands here, too.
- // Then we should use is_possible_cite_command() in
- // InsetCitation to test for valid cite commands.
- if (compare_ascii_no_case(cmdName.substr(0,4), "cite") == 0) {
+ if (insetType == "citation") {
inset.reset(new InsetCitation(inscmd));
- } else if (cmdName == "bibitem") {
+ } else if (insetType == "bibitem") {
inset.reset(new InsetBibitem(inscmd));
- } else if (cmdName == "bibtex") {
+ } else if (insetType == "bibtex") {
inset.reset(new InsetBibtex(inscmd));
- } else if (cmdName == "index") {
+ } else if (insetType == "index") {
inset.reset(new InsetIndex(inscmd));
- } else if (cmdName == "nomenclature") {
+ } else if (insetType == "nomenclature") {
inset.reset(new InsetNomencl(inscmd));
- } else if (cmdName == "include") {
+ } else if (insetType == "include") {
inset.reset(new InsetInclude(inscmd));
- } else if (cmdName == "label") {
+ } else if (insetType == "label") {
inset.reset(new InsetLabel(inscmd));
- } else if (cmdName == "url"
- || cmdName == "htmlurl") {
+ } else if (insetType == "url") {
inset.reset(new InsetUrl(inscmd));
- } else if (cmdName == "ref"
- || cmdName == "eqref"
- || cmdName == "pageref"
- || cmdName == "vref"
- || cmdName == "vpageref"
- || cmdName == "prettyref") {
+ } else if (insetType == "ref") {
if (!inscmd["name"].empty()
|| !inscmd["reference"].empty()) {
inset.reset(new InsetRef(inscmd, buf));
}
- } else if (cmdName == "tableofcontents") {
+ } else if (insetType == "toc") {
inset.reset(new InsetTOC(inscmd));
- } else if (cmdName == "listofalgorithms") {
- inset.reset(new InsetFloatList("algorithm"));
- } else if (cmdName == "listoffigures") {
- inset.reset(new InsetFloatList("figure"));
- } else if (cmdName == "listoftables") {
- inset.reset(new InsetFloatList("table"));
- } else if (cmdName == "printindex") {
+ } else if (insetType == "index_print") {
inset.reset(new InsetPrintIndex(inscmd));
- } else if (cmdName == "printnomenclature") {
+ } else if (insetType == "nomencl_print") {
inset.reset(new InsetPrintNomencl(inscmd));
} else {
- lyxerr << "unknown CommandInset '" << cmdName
+ lyxerr << "unknown CommandInset '" << insetType
<< "'" << std::endl;
while (lex.isOK() && lex.getString() != "\\end_inset")
lex.next();
ControlBibtex::ControlBibtex(Dialog & d)
- : ControlCommand(d, "bibtex", "bibtex")
+ : ControlCommand(d, "bibtex")
{}
ControlCitation::ControlCitation(Dialog & d)
- : ControlCommand(d, "cite", "citation")
+ : ControlCommand(d, "citation")
{}
namespace lyx {
namespace frontend {
-ControlCommand::ControlCommand(Dialog & dialog, string const & command_name,
- string const & lfun_name)
- : Controller(dialog), params_(command_name),
- lfun_name_(lfun_name)
+ControlCommand::ControlCommand(Dialog & dialog, string const & insetType)
+ : Controller(dialog), params_(insetType), lfun_name_(insetType)
{}
if (lfun_name_.empty())
return;
- string const lfun = InsetCommandMailer::params2string(lfun_name_,
- params_);
+ string const lfun =
+ InsetCommandMailer::params2string(lfun_name_, params_);
dispatch(FuncRequest(getLfun(), lfun));
}
class ControlCommand : public Controller {
public:
- /** LFUN_INSET_APPLY requires a name, "citation", "ref" etc so that
- it knows what to do with the rest of the contents.
- An empty \p lfun_name indicates that no action will occur on
- 'Apply'.
- */
- ControlCommand(Dialog &, std::string const & command_name,
- std::string const & lfun_name);
+ /// We need to know with what sort of inset we're associated.
+ ControlCommand(Dialog &, std::string const & insetType);
///
virtual ~ControlCommand() {}
///
private:
///
InsetCommandParams params_;
+ //FIXME It should be possible to eliminate lfun_name_
+ //now and recover that information from params().insetType().
+ //But let's not do that quite yet.
/// Flags what action is taken by Kernel::dispatch()
std::string const lfun_name_;
};
namespace frontend {
ControlRef::ControlRef(Dialog & d)
- : ControlCommand(d, "ref", "ref")
+ : ControlCommand(d, "ref")
{}
namespace frontend {
ControlToc::ControlToc(Dialog & d)
- : ControlCommand(d, "tableofcontents", "toc")
+ : ControlCommand(d, "toc")
{
}
namespace {
+//This list should be kept in sync with the list of insets in src/insets/Inset.cpp.
+//I.e., if a dialog goes with an inset, the dialog should have the same name as the
+//inset.
char const * const dialognames[] = {
"aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character",
"citation", "document", "embedding", "errorlist", "ert", "external", "file",
{
setupUi(this);
setViewTitle(_("Bibliography Entry Settings"));
- setController(new ControlCommand(*this, "bibitem", "bibitem"));
+ setController(new ControlCommand(*this, "bibitem"));
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
label_ = label;
setupUi(this);
setViewTitle(title);
- setController(new ControlCommand(*this, name, name));
+ setController(new ControlCommand(*this, name));
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
: GuiDialog(lv, "nomenclature")
{
setupUi(this);
- setController(new ControlCommand(*this, "nomenclature", "nomenclature"));
+ setController(new ControlCommand(*this, "nomenclature"));
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
{
setupUi(this);
setViewTitle( _("URL"));
- setController(new ControlCommand(*this, "url", "url"));
+ setController(new ControlCommand(*this, "url"));
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
InsetName("external", Inset::EXTERNAL_CODE),
InsetName("caption", Inset::CAPTION_CODE),
InsetName("mathmacro", Inset::MATHMACRO_CODE),
- InsetName("cite", Inset::CITE_CODE),
- InsetName("float_list", Inset::FLOAT_LIST_CODE),
+ InsetName("citation", Inset::CITE_CODE),
+ InsetName("floatlist", Inset::FLOAT_LIST_CODE),
InsetName("index_print", Inset::INDEX_PRINT_CODE),
InsetName("nomencl_print", Inset::NOMENCL_PRINT_CODE),
InsetName("optarg", Inset::OPTARG_CODE),
class Cache {
public:
///
- Cache() : engine(biblio::ENGINE_BASIC), params("cite") {}
+ Cache() : engine(biblio::ENGINE_BASIC), params("citation") {}
///
biblio::CiteEngine engine;
///
// by Text::readInset
string id;
lex >> id;
- if (!lex || id != "LatexCommand")
+ if (!lex || id != "CommandInset")
return print_mailer_error("InsetCommandMailer", in, 2, "LatexCommand");
params.read(lex);
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
- // InsetCitation, 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};
- return &info;
- }
-
- if (name == "lstinputlisting") {
+ //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};
}
// 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(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
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_;
class InsetCommandParams {
public:
- /// Construct parameters for command \p name. \p name must be known.
- explicit InsetCommandParams(std::string const & name);
+ /// Construct parameters for inset \p insetType, using
+ /// \p insetType as default for \p cmdName_.
+ explicit InsetCommandParams(std::string const & insetType);
+ /// Construct parameters for inset \p insetType with
+ /// command name \p cmdName.
+ explicit InsetCommandParams(std::string const & insetType,
+ std::string const & cmdName);
+ ///
+ std::string insetType() { return insetType_; }
///
void read(Lexer &);
/// Parse the command
/// Build the complete LaTeX command
docstring const getCommand() const;
/// Return the command name
- std::string const & getCmdName() const { return name_; }
+ std::string const & getCmdName() const { return cmdName_; }
/// this is used by listings package.
std::string const getOptions() const;
-private:
- /// FIXME remove
- std::string const getSecOptions() const;
-public:
/// FIXME remove
std::string const getContents() const;
/// Set the name to \p n. This must be a known name. All parameters
void setCmdName(std::string const & n);
/// this is used by the listings package
void setOptions(std::string const &);
-private:
- /// FIXME remove
- void setSecOptions(std::string const &);
-public:
/// FIXME remove
void setContents(std::string const &);
/// get parameter \p name
void clear();
private:
+ /// FIXME remove
+ std::string const getSecOptions() const;
+ /// FIXME remove
+ void setSecOptions(std::string const &);
///
struct CommandInfo {
/// Number of parameters
/// Tells whether a parameter is optional
bool const * optional;
};
- /// Get information for command \p name.
- /// Returns 0 if the command is not known.
- static CommandInfo const * findInfo(std::string const & name);
+ /// Get information for inset type \p insetType.
+ /// Returns 0 if the inset is not known.
+ static CommandInfo const * findInfo(std::string const & insetType);
+ /// Get information for \p insetType and command \p cmdName.
+ /// Returns 0 if the combination is not known.
+ /// Don't call this without first making sure the command name is
+ /// acceptable to the inset.
+ static CommandInfo const * findInfo(std::string const & insetType,
+ std::string const & cmdName);
+ ///
+ std::string getDefaultCmd(std::string insetType);
/// Description of all command properties
CommandInfo const * info_;
+ /// what kind of inset we're the parameters for
+ std::string insetType_;
/// The name of this command as it appears in .lyx and .tex files
- std::string name_;
+ std::string cmdName_;
///
typedef std::vector<docstring> ParamVector;
/// The parameters (both optional and required ones). The order is
int InsetRef::latex(Buffer const &, odocstream & os,
OutputParams const &) const
{
- // Don't output p_["name"], this is only used in docbook
- InsetCommandParams p(getCmdName());
+ // We don't want to output p_["name"], since that is only used
+ // in docbook. So we construct new params, without it, and use that.
+ InsetCommandParams p("ref", getCmdName());
p["reference"] = getParam("reference");
os << escape(p.getCommand());
return 0;