// Check if the label 'from' appears more than once
vector<docstring> labels;
+ string paramName;
if (code == CITE_CODE) {
BiblioInfo keys;
keys.fillWithBibKeys(this);
for (; bit != bend; ++bit)
// FIXME UNICODE
labels.push_back(bit->first);
- } else
+ paramName = "key";
+ } else {
getLabelList(labels);
+ paramName = "reference";
+ }
if (std::count(labels.begin(), labels.end(), from) > 1)
return;
for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) {
if (it->lyxCode() == code) {
InsetCommand & inset = static_cast<InsetCommand &>(*it);
- inset.replaceContents(to_utf8(from), to_utf8(to));
+ docstring const oldValue = inset.getParam(paramName);
+ if (oldValue == from)
+ inset.setParam(paramName, to);
}
}
}
bool same_content);
bool findNextInset(DocIterator & dit, vector<InsetCode> const & codes,
- string const & contents)
+ docstring const & contents)
{
DocIterator tmpdit = dit;
if (inset
&& find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()
&& (contents.empty() ||
- static_cast<InsetCommand const *>(inset)->getContents() == contents)) {
+ static_cast<InsetCommand const *>(inset)->getFirstNonOptParam() == contents)) {
dit = tmpdit;
return true;
}
}
-/// Looks for next inset with one of the the given code
+/// Looks for next inset with one of the given codes.
bool findInset(DocIterator & dit, vector<InsetCode> const & codes,
bool same_content)
{
- string contents;
+ docstring contents;
DocIterator tmpdit = dit;
tmpdit.forwardInset();
if (!tmpdit)
Inset const * inset = tmpdit.nextInset();
if (inset
&& find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()) {
- contents = static_cast<InsetCommand const *>(inset)->getContents();
+ contents = static_cast<InsetCommand const *>(inset)->getFirstNonOptParam();
}
}
#include "frontends/FontMetrics.h"
#include "insets/InsetBibitem.h"
+#include "insets/InsetLabel.h"
#include "insets/InsetOptArg.h"
#include "support/lstrings.h"
Inset const * inset = getInset(i);
InsetCode lyx_code = inset->lyxCode();
if (lyx_code == LABEL_CODE) {
- string const id = static_cast<InsetCommand const *>(inset)->getContents();
- return "id='" + to_utf8(sgml::cleanID(buf, runparams, from_utf8(id))) + "'";
+ InsetLabel const * const il = static_cast<InsetLabel const *>(inset);
+ docstring const & id = il->getParam("name");
+ return "id='" + to_utf8(sgml::cleanID(buf, runparams, id)) + "'";
}
}
typeCO->setCurrentIndex(3);
listingsGB->setEnabled(true);
listingsED->setEnabled(true);
- InsetListingsParams par(params_.getOptions());
+ InsetListingsParams par(to_utf8(params_["lstparams"]));
// extract caption and label and put them into their respective editboxes
vector<string> pars = getVectorFromString(par.separatedParams(), "\n");
for (vector<string>::iterator it = pars.begin();
par.addParam("caption", "{" + caption + "}");
if (!label.empty())
par.addParam("label", "{" + label + "}");
- params_.setOptions(par.params());
+ string const listparams = par.params();
+ params_["lstparams"] = from_ascii(listparams);
} else {
if (visiblespaceCB->isChecked())
params_.setCmdName("verbatiminput*");
}
-void InsetCitation::replaceContents(string const & from, string const & to)
-{
- if (tokenPos(getContents(), ',', from) != -1) {
- vector<string> items = getVectorFromString(getContents());
- std::replace(items.begin(), items.end(), from, to);
- setContents(getStringFromVector(items));
- }
-}
-
-
} // namespace lyx
OutputParams const &) const;
///
void validate(LaTeXFeatures &) const;
- ///
- void replaceContents(std::string const & from, std::string const & to);
private:
virtual Inset * clone() const
using std::ostringstream;
+// FIXME Would it now be possible to use the InsetCode in
+// place of the mailer name and recover that information?
InsetCommand::InsetCommand(InsetCommandParams const & p,
string const & mailer_name)
: p_(p),
}
-void InsetCommand::replaceContents(std::string const & from, string const & to)
-{
- if (getContents() == from)
- setContents(to);
-}
-
-
InsetCommandMailer::InsetCommandMailer(
string const & name, InsetCommand & inset)
: name_(name), inset_(inset)
// Created by Alejandro 970222
-/** Used to insert a LaTeX command automatically
- *
- * Similar to InsetLaTeX but having control of the basic structure of a
- * LaTeX command: \name[options]{contents}.
+/** Used to insert a LaTeX command automatically.
*/
///
int docbook(Buffer const &, odocstream &, OutputParams const & runparams) const;
///
InsetCode lyxCode() const { return NO_CODE; }
-
///
InsetCommandParams const & params() const { return p_; }
- /// FIXME remove
- std::string const getContents() const { return p_.getContents(); }
-protected:
- /// FIXME remove
- void setContents(std::string const & c)
- {
- updateButtonLabel_ = true;
- p_.setContents(c);
- }
+ /// FIXME Remove
+ docstring const getFirstNonOptParam() const { return p_.getFirstNonOptParam(); }
public:
/// tell that the button label should be recomputed.
void refresh() { updateButtonLabel_ = true; }
}
///
void edit(Cursor & cur, bool left);
- /// FIXME remove
- virtual void replaceContents(std::string const & from, std::string const & to);
///
RenderButton & button() const { return button_; }
///
}
-void InsetCommandParams::scanCommand(string const & cmd)
-{
- string tcmdname, toptions, tsecoptions, tcontents;
-
- if (cmd.empty()) return;
-
- enum { WS, CMDNAME, OPTION, SECOPTION, CONTENT } state = WS;
-
- // Used to handle things like \command[foo[bar]]{foo{bar}}
- int nestdepth = 0;
-
- for (string::size_type i = 0; i < cmd.length(); ++i) {
- char const c = cmd[i];
- if ((state == CMDNAME && c == ' ') ||
- (state == CMDNAME && c == '[') ||
- (state == CMDNAME && c == '{')) {
- state = WS;
- }
- if ((state == OPTION && c == ']') ||
- (state == SECOPTION && c == ']') ||
- (state == CONTENT && c == '}')) {
- if (nestdepth == 0) {
- state = WS;
- } else {
- --nestdepth;
- }
- }
- if ((state == OPTION && c == '[') ||
- (state == SECOPTION && c == '[') ||
- (state == CONTENT && c == '{')) {
- ++nestdepth;
- }
- switch (state) {
- case CMDNAME: tcmdname += c; break;
- case OPTION: toptions += c; break;
- case SECOPTION: tsecoptions += c; break;
- case CONTENT: tcontents += c; break;
- case WS: {
- char const b = i? cmd[i-1]: 0;
- if (c == '\\') {
- state = CMDNAME;
- } else if (c == '[' && b != ']') {
- state = OPTION;
- nestdepth = 0; // Just to be sure
- } else if (c == '[' && b == ']') {
- state = SECOPTION;
- nestdepth = 0; // Just to be sure
- } else if (c == '{') {
- state = CONTENT;
- nestdepth = 0; // Just to be sure
- }
- break;
- }
- }
- }
-
- // Don't mess with this.
- if (!tcmdname.empty()) setCmdName(tcmdname);
- if (!toptions.empty()) setOptions(toptions);
- if (!tsecoptions.empty()) setSecOptions(tsecoptions);
- if (!tcontents.empty()) setContents(tcontents);
-
- LYXERR(Debug::PARSER) << "Command <" << cmd
- << "> == <" << to_utf8(getCommand())
- << "> == <" << getCmdName()
- << '|' << getContents()
- << '|' << getOptions()
- << '|' << getSecOptions() << '>' << endl;
-}
-
-
void InsetCommandParams::read(Lexer & lex)
{
- //FIXME
if (lex.isOK()) {
lex.next();
string const insetType = lex.getString();
token = lex.getString();
if (token == "\\end_inset")
break;
- // FIXME Why is preview_ read but not written?
if (token == "preview") {
lex.next();
preview_ = lex.getBool();
{
os << "CommandInset " << insetType() << '\n';
os << "LatexCommand " << cmdName_ << '\n';
+ if (preview_)
+ os << "preview true\n";
for (size_t i = 0; i < info_->n; ++i)
if (!params_[i].empty())
// FIXME UNICODE
}
-std::string const InsetCommandParams::getOptions() const
-{
- for (size_t i = 0; i < info_->n; ++i)
- if (info_->optional[i])
- return to_utf8(params_[i]);
- lyxerr << "Programming error: get nonexisting option in "
- << insetType() << " inset." << endl;
- return string();
-}
-
-
-std::string const InsetCommandParams::getSecOptions() const
-{
- bool first = true;
- for (size_t i = 0; i < info_->n; ++i)
- if (info_->optional[i]) {
- if (first)
- first = false;
- else
- return to_utf8(params_[i]);
- }
- // Happens in InsetCitation
- lyxerr << "Programming error: get nonexisting second option in "
- << insetType() << " inset." << endl;
- return string();
-}
-
-
-std::string const InsetCommandParams::getContents() const
+docstring const InsetCommandParams::getFirstNonOptParam() const
{
for (size_t i = 0; i < info_->n; ++i)
if (!info_->optional[i])
- return to_utf8(params_[i]);
- BOOST_ASSERT(false);
- return string();
-}
-
-
-void InsetCommandParams::setOptions(std::string const & o)
-{
- for (size_t i = 0; i < info_->n; ++i)
- if (info_->optional[i]) {
- params_[i] = from_utf8(o);
- return;
- }
- lyxerr << "Programming error: set nonexisting option in "
- << insetType() << " inset." << endl;
-}
-
-
-void InsetCommandParams::setSecOptions(std::string const & s)
-{
- bool first = true;
- for (size_t i = 0; i < info_->n; ++i)
- if (info_->optional[i]) {
- if (first)
- first = false;
- else {
- params_[i] = from_utf8(s);
- return;
- }
- }
- // Happens in InsetCitation
- lyxerr << "Programming error: set nonexisting second option in "
- << insetType() << " inset." << endl;
-}
-
-
-void InsetCommandParams::setContents(std::string const & c)
-{
- for (size_t i = 0; i < info_->n; ++i)
- if (!info_->optional[i]) {
- params_[i] = from_utf8(c);
- return;
- }
+ return params_[i];
BOOST_ASSERT(false);
+ return docstring();
}
///
void read(Lexer &);
/// Parse the command
- /// FIXME remove
- void scanCommand(std::string const &);
///
void write(std::ostream &) const;
/// Build the complete LaTeX command
docstring const getCommand() const;
/// Return the command name
std::string const & getCmdName() const { return cmdName_; }
- /// this is used by listings package.
- std::string const getOptions() const;
- /// FIXME remove
- std::string const getContents() const;
/// Set the name to \p n. This must be a known name. All parameters
/// are cleared except those that exist also in the new command.
/// What matters here is the parameter name, not position.
void setCmdName(std::string const & n);
- /// this is used by the listings package
- void setOptions(std::string const &);
- /// FIXME remove
- void setContents(std::string const &);
+ /// FIXME Would be better removed, but is used in BufferView.cpp in
+ /// ways that make removal hard.
+ docstring const getFirstNonOptParam() const;
/// get parameter \p name
docstring const & operator[](std::string const & name) const;
/// set 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
* 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.
*/
/// the type of inclusion
enum Types {
INCLUDE = 0,
- VERB = 1,
- INPUT = 2,
- VERBAST = 3,
- LISTINGS = 4,
+ VERB = 1,
+ INPUT = 2,
+ VERBAST = 3,
+ LISTINGS = 4,
};
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
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())
}
} 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 {
* 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.
*/