From 2f4d0ae27ed43f639c75ad8b42abcfe920604eeb Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Tue, 23 Oct 2007 18:51:04 +0000 Subject: [PATCH] Remove methods marked for removal from InsetCommandParams. Yeah, we can do that now. ;-) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21154 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 10 +- src/BufferView.cpp | 10 +- src/Paragraph.cpp | 6 +- src/frontends/qt4/GuiInclude.cpp | 5 +- src/insets/InsetCitation.cpp | 10 -- src/insets/InsetCitation.h | 2 - src/insets/InsetCommand.cpp | 9 +- src/insets/InsetCommand.h | 19 +--- src/insets/InsetCommandParams.cpp | 150 +----------------------------- src/insets/InsetCommandParams.h | 17 +--- src/insets/InsetInclude.cpp | 27 +++--- src/insets/InsetInclude.h | 1 + 12 files changed, 48 insertions(+), 218 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 8e87ecbce2..566105a128 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -1806,6 +1806,7 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to, // Check if the label 'from' appears more than once vector labels; + string paramName; if (code == CITE_CODE) { BiblioInfo keys; keys.fillWithBibKeys(this); @@ -1815,8 +1816,11 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to, 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; @@ -1824,7 +1828,9 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to, for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) { if (it->lyxCode() == code) { InsetCommand & inset = static_cast(*it); - inset.replaceContents(to_utf8(from), to_utf8(to)); + docstring const oldValue = inset.getParam(paramName); + if (oldValue == from) + inset.setParam(paramName, to); } } } diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 2b6820949c..f3ec599b2a 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -131,7 +131,7 @@ bool findInset(DocIterator & dit, vector const & codes, bool same_content); bool findNextInset(DocIterator & dit, vector const & codes, - string const & contents) + docstring const & contents) { DocIterator tmpdit = dit; @@ -140,7 +140,7 @@ bool findNextInset(DocIterator & dit, vector const & codes, if (inset && find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() && (contents.empty() || - static_cast(inset)->getContents() == contents)) { + static_cast(inset)->getFirstNonOptParam() == contents)) { dit = tmpdit; return true; } @@ -151,11 +151,11 @@ bool findNextInset(DocIterator & dit, vector const & codes, } -/// 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 const & codes, bool same_content) { - string contents; + docstring contents; DocIterator tmpdit = dit; tmpdit.forwardInset(); if (!tmpdit) @@ -165,7 +165,7 @@ bool findInset(DocIterator & dit, vector const & codes, Inset const * inset = tmpdit.nextInset(); if (inset && find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()) { - contents = static_cast(inset)->getContents(); + contents = static_cast(inset)->getFirstNonOptParam(); } } diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index fa8bb4140b..bd368ef6c5 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -48,6 +48,7 @@ #include "frontends/FontMetrics.h" #include "insets/InsetBibitem.h" +#include "insets/InsetLabel.h" #include "insets/InsetOptArg.h" #include "support/lstrings.h" @@ -2149,8 +2150,9 @@ string Paragraph::getID(Buffer const & buf, OutputParams const & runparams) cons Inset const * inset = getInset(i); InsetCode lyx_code = inset->lyxCode(); if (lyx_code == LABEL_CODE) { - string const id = static_cast(inset)->getContents(); - return "id='" + to_utf8(sgml::cleanID(buf, runparams, from_utf8(id))) + "'"; + InsetLabel const * const il = static_cast(inset); + docstring const & id = il->getParam("name"); + return "id='" + to_utf8(sgml::cleanID(buf, runparams, id)) + "'"; } } diff --git a/src/frontends/qt4/GuiInclude.cpp b/src/frontends/qt4/GuiInclude.cpp index 66a49dfb8f..0ea27fd373 100644 --- a/src/frontends/qt4/GuiInclude.cpp +++ b/src/frontends/qt4/GuiInclude.cpp @@ -235,7 +235,7 @@ void GuiInclude::updateContents() 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 pars = getVectorFromString(par.separatedParams(), "\n"); for (vector::iterator it = pars.begin(); @@ -281,7 +281,8 @@ void GuiInclude::applyView() 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*"); diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp index 8b60d254f7..d224c5dd49 100644 --- a/src/insets/InsetCitation.cpp +++ b/src/insets/InsetCitation.cpp @@ -536,14 +536,4 @@ void InsetCitation::validate(LaTeXFeatures & features) const } -void InsetCitation::replaceContents(string const & from, string const & to) -{ - if (tokenPos(getContents(), ',', from) != -1) { - vector items = getVectorFromString(getContents()); - std::replace(items.begin(), items.end(), from, to); - setContents(getStringFromVector(items)); - } -} - - } // namespace lyx diff --git a/src/insets/InsetCitation.h b/src/insets/InsetCitation.h index 0bc7ee0ab7..937aa84b00 100644 --- a/src/insets/InsetCitation.h +++ b/src/insets/InsetCitation.h @@ -49,8 +49,6 @@ public: OutputParams const &) const; /// void validate(LaTeXFeatures &) const; - /// - void replaceContents(std::string const & from, std::string const & to); private: virtual Inset * clone() const diff --git a/src/insets/InsetCommand.cpp b/src/insets/InsetCommand.cpp index c852c1c009..d14d68c530 100644 --- a/src/insets/InsetCommand.cpp +++ b/src/insets/InsetCommand.cpp @@ -32,6 +32,8 @@ using std::istringstream; 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), @@ -168,13 +170,6 @@ void InsetCommand::edit(Cursor & cur, bool) } -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) diff --git a/src/insets/InsetCommand.h b/src/insets/InsetCommand.h index 84eb0d87d8..204ae93a08 100644 --- a/src/insets/InsetCommand.h +++ b/src/insets/InsetCommand.h @@ -24,10 +24,7 @@ namespace lyx { // 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. */ /// @@ -57,18 +54,10 @@ public: 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; } @@ -85,8 +74,6 @@ public: } /// void edit(Cursor & cur, bool left); - /// FIXME remove - virtual void replaceContents(std::string const & from, std::string const & to); /// RenderButton & button() const { return button_; } /// diff --git a/src/insets/InsetCommandParams.cpp b/src/insets/InsetCommandParams.cpp index b27821bcb0..5ac876a438 100644 --- a/src/insets/InsetCommandParams.cpp +++ b/src/insets/InsetCommandParams.cpp @@ -226,80 +226,8 @@ void InsetCommandParams::setCmdName(string const & name) } -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(); @@ -341,7 +269,6 @@ void InsetCommandParams::read(Lexer & lex) token = lex.getString(); if (token == "\\end_inset") break; - // FIXME Why is preview_ read but not written? if (token == "preview") { lex.next(); preview_ = lex.getBool(); @@ -372,6 +299,8 @@ void InsetCommandParams::write(ostream & os) const { 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 @@ -417,82 +346,13 @@ docstring const InsetCommandParams::getCommand() const } -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(); } diff --git a/src/insets/InsetCommandParams.h b/src/insets/InsetCommandParams.h index a5dd8c462f..3f010e3b3d 100644 --- a/src/insets/InsetCommandParams.h +++ b/src/insets/InsetCommandParams.h @@ -39,26 +39,19 @@ public: /// 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 @@ -71,10 +64,6 @@ public: void clear(); private: - /// FIXME remove - std::string const getSecOptions() const; - /// FIXME remove - void setSecOptions(std::string const &); /// struct CommandInfo { /// Number of parameters diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index b7708c14fa..0fc1549e40 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -4,6 +4,7 @@ * 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. */ @@ -96,10 +97,10 @@ docstring const uniqueID() /// the type of inclusion enum Types { INCLUDE = 0, - VERB = 1, - INPUT = 2, - VERBAST = 3, - LISTINGS = 4, + VERB = 1, + INPUT = 2, + VERBAST = 3, + LISTINGS = 4, }; @@ -128,14 +129,14 @@ bool isListings(InsetCommandParams const & params) 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 @@ -166,8 +167,8 @@ void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd) 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()) @@ -483,7 +484,7 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os, } } 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()) @@ -585,7 +586,7 @@ int InsetInclude::docbook(Buffer const & buffer, odocstream & os, 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(); @@ -636,7 +637,7 @@ void InsetInclude::getLabelList(Buffer const & buffer, std::vector & 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)); @@ -814,7 +815,7 @@ void InsetInclude::addToToc(TocList & toclist, Buffer const & buffer, 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; @@ -845,7 +846,7 @@ void InsetInclude::updateLabels(Buffer const & buffer, ParIterator const &) 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 { diff --git a/src/insets/InsetInclude.h b/src/insets/InsetInclude.h index 225bbd4bbe..c7ae18d2db 100644 --- a/src/insets/InsetInclude.h +++ b/src/insets/InsetInclude.h @@ -5,6 +5,7 @@ * 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. */ -- 2.39.2