mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
This is the first part of a cleanup of how we handle the InsetCommand hierarchy. This part starts to disentangle the type of the inset from the command that a single instance of the inset represents. This involves two sorts of changes:
(i) The file format is changed, so that command insets are represented as: \begin_inset CommandInset insetype LatexCommand command ... \end_inset This involves some lyx2lyx and changes to the readInset() routine in factory.cpp (ii) The InsetCommand and InsetCommandParams classes also have to be changed, as the command name was used in these classes for various purposes for which the inset type ought really to be used. Further clean-up to come. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20544 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
cd56d44a69
commit
0787ade6c0
@ -1,6 +1,10 @@
|
||||
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.
|
||||
|
@ -80,7 +80,7 @@ format_relation = [("0_06", [200], minor_versions("0.6" , 4)),
|
||||
("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():
|
||||
|
@ -256,6 +256,67 @@ def remove_inzip_options(document):
|
||||
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"
|
||||
@ -308,10 +369,12 @@ convert = [
|
||||
[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]],
|
||||
|
@ -143,7 +143,7 @@ namespace fs = boost::filesystem;
|
||||
|
||||
namespace {
|
||||
|
||||
int const LYX_FORMAT = 287;
|
||||
int const LYX_FORMAT = 288; //RGH, command insets
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
@ -1430,7 +1430,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
|
||||
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);
|
||||
@ -1510,7 +1510,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
|
||||
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);
|
||||
|
@ -216,13 +216,13 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
|
||||
}
|
||||
|
||||
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());
|
||||
@ -251,7 +251,7 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
|
||||
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);
|
||||
@ -314,7 +314,7 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
|
||||
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);
|
||||
@ -393,62 +393,47 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
|
||||
string tmptok = lex.getString();
|
||||
|
||||
// test the different insets
|
||||
if (tmptok == "LatexCommand") {
|
||||
if (tmptok == "CommandInset") {
|
||||
lex.next();
|
||||
string const cmdName = lex.getString();
|
||||
lex.pushToken(cmdName);
|
||||
string const insetType = lex.getString();
|
||||
lex.pushToken(insetType);
|
||||
|
||||
InsetCommandParams inscmd(cmdName);
|
||||
//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();
|
||||
|
@ -42,7 +42,7 @@ namespace frontend {
|
||||
|
||||
|
||||
ControlBibtex::ControlBibtex(Dialog & d)
|
||||
: ControlCommand(d, "bibtex", "bibtex")
|
||||
: ControlCommand(d, "bibtex")
|
||||
{}
|
||||
|
||||
|
||||
|
@ -34,7 +34,7 @@ vector<biblio::CiteStyle> ControlCitation::citeStyles_;
|
||||
|
||||
|
||||
ControlCitation::ControlCitation(Dialog & d)
|
||||
: ControlCommand(d, "cite", "citation")
|
||||
: ControlCommand(d, "citation")
|
||||
{}
|
||||
|
||||
|
||||
|
@ -21,10 +21,8 @@ using std::string;
|
||||
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)
|
||||
{}
|
||||
|
||||
|
||||
@ -48,8 +46,8 @@ void ControlCommand::dispatchParams()
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -24,13 +24,8 @@ namespace frontend {
|
||||
|
||||
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() {}
|
||||
///
|
||||
@ -49,6 +44,9 @@ public:
|
||||
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_;
|
||||
};
|
||||
|
@ -33,7 +33,7 @@ using support::makeDisplayPath;
|
||||
namespace frontend {
|
||||
|
||||
ControlRef::ControlRef(Dialog & d)
|
||||
: ControlCommand(d, "ref", "ref")
|
||||
: ControlCommand(d, "ref")
|
||||
{}
|
||||
|
||||
|
||||
|
@ -32,7 +32,7 @@ namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
ControlToc::ControlToc(Dialog & d)
|
||||
: ControlCommand(d, "tableofcontents", "toc")
|
||||
: ControlCommand(d, "toc")
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -77,6 +77,9 @@ namespace frontend {
|
||||
|
||||
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",
|
||||
|
@ -28,7 +28,7 @@ GuiBibitemDialog::GuiBibitemDialog(LyXView & lv)
|
||||
{
|
||||
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()));
|
||||
|
@ -41,7 +41,7 @@ GuiIndexDialogBase::GuiIndexDialogBase(LyXView & lv,
|
||||
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()));
|
||||
|
@ -33,7 +33,7 @@ GuiNomenclDialog::GuiNomenclDialog(LyXView & lv)
|
||||
: 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()));
|
||||
|
@ -29,7 +29,7 @@ GuiURLDialog::GuiURLDialog(LyXView & lv)
|
||||
{
|
||||
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()));
|
||||
|
@ -88,8 +88,8 @@ static TranslatorMap const build_translator()
|
||||
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),
|
||||
|
@ -63,7 +63,7 @@ private:
|
||||
class Cache {
|
||||
public:
|
||||
///
|
||||
Cache() : engine(biblio::ENGINE_BASIC), params("cite") {}
|
||||
Cache() : engine(biblio::ENGINE_BASIC), params("citation") {}
|
||||
///
|
||||
biblio::CiteEngine engine;
|
||||
///
|
||||
|
@ -208,7 +208,7 @@ void InsetCommandMailer::string2params(string const & name,
|
||||
// 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);
|
||||
|
@ -34,23 +34,43 @@ using std::ostream;
|
||||
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)
|
||||
{
|
||||
info_ = findInfo(name);
|
||||
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(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};
|
||||
@ -58,7 +78,7 @@ InsetCommandParams::findInfo(std::string const & name)
|
||||
}
|
||||
|
||||
// InsetBibtex
|
||||
if (name == "bibtex") {
|
||||
if (insetType == "bibtex") {
|
||||
static const char * const paramnames[] =
|
||||
{"options", "btprint", "bibfiles", ""};
|
||||
static const bool isoptional[] = {true, true, false};
|
||||
@ -67,17 +87,7 @@ InsetCommandParams::findInfo(std::string const & name)
|
||||
}
|
||||
|
||||
// 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
|
||||
@ -90,7 +100,7 @@ InsetCommandParams::findInfo(std::string const & name)
|
||||
}
|
||||
|
||||
// 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};
|
||||
@ -98,22 +108,17 @@ InsetCommandParams::findInfo(std::string const & name)
|
||||
}
|
||||
|
||||
// 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};
|
||||
@ -121,7 +126,7 @@ InsetCommandParams::findInfo(std::string const & name)
|
||||
}
|
||||
|
||||
// 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};
|
||||
@ -129,7 +134,7 @@ InsetCommandParams::findInfo(std::string const & name)
|
||||
}
|
||||
|
||||
// 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};
|
||||
@ -137,7 +142,7 @@ InsetCommandParams::findInfo(std::string const & name)
|
||||
}
|
||||
|
||||
// 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};
|
||||
@ -145,8 +150,7 @@ InsetCommandParams::findInfo(std::string const & name)
|
||||
}
|
||||
|
||||
// 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};
|
||||
@ -155,7 +159,7 @@ InsetCommandParams::findInfo(std::string const & name)
|
||||
}
|
||||
|
||||
// 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};
|
||||
@ -163,7 +167,7 @@ InsetCommandParams::findInfo(std::string const & name)
|
||||
}
|
||||
|
||||
// InsetUrl
|
||||
if (name == "htmlurl" || name == "url") {
|
||||
if (insetType == "url") {
|
||||
static const char * const paramnames[] =
|
||||
{"name", "target", ""};
|
||||
static const bool isoptional[] = {true, false};
|
||||
@ -175,10 +179,55 @@ InsetCommandParams::findInfo(std::string const & name)
|
||||
}
|
||||
|
||||
|
||||
//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
|
||||
@ -265,18 +314,43 @@ void InsetCommandParams::scanCommand(string const & cmd)
|
||||
|
||||
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();
|
||||
@ -294,9 +368,9 @@ void InsetCommandParams::read(Lexer & lex)
|
||||
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));
|
||||
}
|
||||
}
|
||||
@ -312,7 +386,8 @@ void InsetCommandParams::read(Lexer & lex)
|
||||
|
||||
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
|
||||
@ -324,7 +399,7 @@ void InsetCommandParams::write(ostream & os) const
|
||||
|
||||
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]) {
|
||||
@ -364,7 +439,7 @@ std::string const InsetCommandParams::getOptions() const
|
||||
if (info_->optional[i])
|
||||
return to_utf8(params_[i]);
|
||||
lyxerr << "Programming error: get nonexisting option in "
|
||||
<< name_ << " inset." << endl;;
|
||||
<< insetType_ << " inset." << endl;
|
||||
return string();
|
||||
}
|
||||
|
||||
@ -381,7 +456,7 @@ std::string const InsetCommandParams::getSecOptions() const
|
||||
}
|
||||
// Happens in InsetCitation
|
||||
lyxerr << "Programming error: get nonexisting second option in "
|
||||
<< name_ << " inset." << endl;;
|
||||
<< insetType_ << " inset." << endl;
|
||||
return string();
|
||||
}
|
||||
|
||||
@ -404,7 +479,7 @@ void InsetCommandParams::setOptions(std::string const & o)
|
||||
return;
|
||||
}
|
||||
lyxerr << "Programming error: set nonexisting option in "
|
||||
<< name_ << " inset." << endl;;
|
||||
<< insetType_ << " inset." << endl;
|
||||
}
|
||||
|
||||
|
||||
@ -422,7 +497,7 @@ void InsetCommandParams::setSecOptions(std::string const & s)
|
||||
}
|
||||
// Happens in InsetCitation
|
||||
lyxerr << "Programming error: set nonexisting second option in "
|
||||
<< name_ << " inset." << endl;;
|
||||
<< insetType_ << " inset." << endl;
|
||||
}
|
||||
|
||||
|
||||
@ -463,7 +538,8 @@ void InsetCommandParams::clear()
|
||||
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_;
|
||||
|
@ -25,8 +25,15 @@ class Lexer;
|
||||
|
||||
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
|
||||
@ -37,13 +44,9 @@ public:
|
||||
/// 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
|
||||
@ -52,10 +55,6 @@ public:
|
||||
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
|
||||
@ -70,6 +69,10 @@ public:
|
||||
void clear();
|
||||
|
||||
private:
|
||||
/// FIXME remove
|
||||
std::string const getSecOptions() const;
|
||||
/// FIXME remove
|
||||
void setSecOptions(std::string const &);
|
||||
///
|
||||
struct CommandInfo {
|
||||
/// Number of parameters
|
||||
@ -79,13 +82,23 @@ private:
|
||||
/// 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
|
||||
|
@ -82,8 +82,9 @@ docstring const InsetRef::getScreenLabel(Buffer const &) const
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user