]> git.lyx.org Git - features.git/commitdiff
Remove methods marked for removal from InsetCommandParams. Yeah, we can do that now...
authorRichard Heck <rgheck@comcast.net>
Tue, 23 Oct 2007 18:51:04 +0000 (18:51 +0000)
committerRichard Heck <rgheck@comcast.net>
Tue, 23 Oct 2007 18:51:04 +0000 (18:51 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21154 a592a061-630c-0410-9148-cb99ea01b6c8

12 files changed:
src/Buffer.cpp
src/BufferView.cpp
src/Paragraph.cpp
src/frontends/qt4/GuiInclude.cpp
src/insets/InsetCitation.cpp
src/insets/InsetCitation.h
src/insets/InsetCommand.cpp
src/insets/InsetCommand.h
src/insets/InsetCommandParams.cpp
src/insets/InsetCommandParams.h
src/insets/InsetInclude.cpp
src/insets/InsetInclude.h

index 8e87ecbce23bf0ac8fd4677729b3a8219cdb739c..566105a12850182dfe52ce6ec4795edf8002ae30 100644 (file)
@@ -1806,6 +1806,7 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to,
        // Check if the label 'from' appears more than once
        vector<docstring> 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<InsetCommand &>(*it);
-                       inset.replaceContents(to_utf8(from), to_utf8(to));
+                       docstring const oldValue = inset.getParam(paramName);
+                       if (oldValue == from)
+                               inset.setParam(paramName, to);
                }
        }
 }
index 2b6820949c4ec46b6b44fc7e460fb1858ec11e3f..f3ec599b2ac5a48b03e2507741f4907b2ff88f1c 100644 (file)
@@ -131,7 +131,7 @@ bool findInset(DocIterator & dit, vector<InsetCode> const & codes,
        bool same_content);
 
 bool findNextInset(DocIterator & dit, vector<InsetCode> const & codes,
-       string const & contents)
+       docstring const & contents)
 {
        DocIterator tmpdit = dit;
 
@@ -140,7 +140,7 @@ bool findNextInset(DocIterator & dit, vector<InsetCode> const & codes,
                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;
                }
@@ -151,11 +151,11 @@ bool findNextInset(DocIterator & dit, vector<InsetCode> 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<InsetCode> 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<InsetCode> const & codes,
                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();
                }
        }
 
index fa8bb4140b6b53f786cfb97dd09f5b814b139687..bd368ef6c50ea3cf6a38f95ed764718425a423b5 100644 (file)
@@ -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<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)) + "'";
                        }
                }
 
index 66a49dfb8f007b300bc6dd8af0101e1375062457..0ea27fd3737ab88b618362bd83e685eb6dd6235d 100644 (file)
@@ -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<string> pars = getVectorFromString(par.separatedParams(), "\n");
                for (vector<string>::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*");
index 8b60d254f7f726b5408a1f28d8655877ac148754..d224c5dd4945af5d40feea79ad36dca325589aee 100644 (file)
@@ -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<string> items = getVectorFromString(getContents());
-               std::replace(items.begin(), items.end(), from, to);
-               setContents(getStringFromVector(items));
-       }
-}
-
-
 } // namespace lyx
index 0bc7ee0ab7848214f564ff4db73b75de0fba5035..937aa84b00ef8d7c5b2757f497e82c4d8e510820 100644 (file)
@@ -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
index c852c1c009c51f03b4e7afbae55f703a517295d9..d14d68c530229faaaec38a7e32bbbd20754059d9 100644 (file)
@@ -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)
index 84eb0d87d82ef2ad4ef2e9fe0b2146ce43e12d2c..204ae93a087ca76b60dd9a563d33d30f81dc5025 100644 (file)
@@ -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_; }
        ///
index b27821bcb05b9c7eaa4024402e0607f13c9165f7..5ac876a43824a58cf7cc8081dfc724944a965107 100644 (file)
@@ -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();
 }
 
 
index a5dd8c462f85b8b2d2ac0112a3ded088927599dc..3f010e3b3d0fe4ff77477e5a1913d940ef55c542 100644 (file)
@@ -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
index b7708c14fa048e9df0bcd5001f26fac252571ed6..0fc1549e40167f180884d351b17858a71bc2d11c 100644 (file)
@@ -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<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));
@@ -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 {
index 225bbd4bbef213b2b601707f3cd926badbdb1edc..c7ae18d2db0036f5fb047c27941d11f060fce11a 100644 (file)
@@ -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.
  */