* Licence details can be found in the file COPYING.
*
* \author Lars Gullik Bjønnes
+ * \author Richard Heck (conversion to InsetCommand)
*
* Full author contact details are available in file CREDITS.
*/
#include "insets/RenderPreview.h"
#include "insets/InsetListingsParams.h"
+#include "support/docstream.h"
#include "support/filetools.h"
#include "support/lstrings.h" // contains
#include "support/lyxalgo.h"
/// the type of inclusion
enum Types {
- INCLUDE = 0,
- VERB = 1,
- INPUT = 2,
- VERBAST = 3,
- LISTINGS = 4,
+ INCLUDE, VERB, INPUT, VERBAST, LISTINGS, NONE
};
-Types type(InsetCommandParams const & params)
-{
- string const command_name = params.getCmdName();
-
- if (command_name == "input")
+Types type(std::string const & s) {
+ if (s == "input")
return INPUT;
- if (command_name == "verbatiminput")
+ if (s == "verbatiminput")
return VERB;
- if (command_name == "verbatiminput*")
+ if (s == "verbatiminput*")
return VERBAST;
- if (command_name == "lstinputlisting")
+ if (s == "lstinputlisting")
return LISTINGS;
- return INCLUDE;
+ if (s == "include")
+ return INCLUDE;
+ return NONE;
+}
+
+
+Types type(InsetCommandParams const & params)
+{
+ string const command_name = params.getCmdName();
+ return type(command_name);
}
bool isVerbatim(InsetCommandParams const & params)
{
Types const t = type(params);
- return (t == VERB) || (t == VERBAST);
+ return t == VERB || t == VERBAST;
}
bool isInputOrInclude(InsetCommandParams const & params)
{
Types const t = type(params);
- return (t == INPUT) || (t == INCLUDE);
+ return t == INPUT || t == INCLUDE;
}
} // namespace anon
}
+CommandInfo const * InsetInclude::findInfo(std::string const & /* cmdName */)
+{
+ //This is only correct for the case of listings, but it'll do for now.
+ //In the other cases, this second parameter should just be empty.
+ static const char * const paramnames[] = {"filename", "lstparams", ""};
+ static const bool isoptional[] = {false, true};
+ static const CommandInfo info = {2, paramnames, isoptional};
+ return &info;
+}
+
+
+bool InsetInclude::isCompatibleCommand(std::string const & s) {
+ return type(s) != NONE;
+}
+
+
void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd)
{
switch (cmd.action) {
InsetCommandMailer::string2params("include", to_utf8(cmd.argument()), p);
if (!p.getCmdName().empty()) {
if (isListings(p)){
- InsetListingsParams par_old(params().getOptions());
- InsetListingsParams par_new(p.getOptions());
+ InsetListingsParams par_old(to_utf8(params()["lstparams"]));
+ InsetListingsParams par_new(to_utf8(p["lstparams"]));
if (par_old.getParamValue("label") !=
par_new.getParamValue("label")
&& !par_new.getParamValue("label").empty())
case INCLUDE:
temp = buf.B_("Include");
break;
- case LISTINGS: {
+ case LISTINGS:
temp = listings_label_;
- }
+ case NONE:
+ BOOST_ASSERT(false);
}
temp += ": ";
}
} else if (type(params()) == LISTINGS) {
os << '\\' << from_ascii(params().getCmdName());
- string opt = params().getOptions();
+ string const opt = to_utf8(params()["lstparams"]);
// opt is set in QInclude dialog and should have passed validation.
InsetListingsParams params(opt);
if (!params.params().empty())
void InsetInclude::validate(LaTeXFeatures & features) const
{
- string incfile(to_utf8(params()["filename"]));
+ string incfile = to_utf8(params()["filename"]);
string writefile;
Buffer const & buffer = features.buffer();
std::vector<docstring> & list) const
{
if (isListings(params())) {
- InsetListingsParams p(params().getOptions());
+ InsetListingsParams p(to_utf8(params()["lstparams"]));
string label = p.getParamValue("label");
if (!label.empty())
list.push_back(from_utf8(label));
ParConstIterator const & pit) const
{
if (isListings(params())) {
- InsetListingsParams p(params().getOptions());
+ InsetListingsParams p(to_utf8(params()["lstparams"]));
string caption = p.getParamValue("caption");
if (caption.empty())
return;
if (childbuffer)
lyx::updateLabels(*childbuffer, true);
else if (isListings(params())) {
- InsetListingsParams const par = params().getOptions();
+ InsetListingsParams const par(to_utf8(params()["lstparams"]));
if (par.getParamValue("caption").empty())
listings_label_.clear();
else {