]> git.lyx.org Git - features.git/commitdiff
Use the new InsetCommandParams interface (inset part), from Ugras and me
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Fri, 20 Oct 2006 16:12:49 +0000 (16:12 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Fri, 20 Oct 2006 16:12:49 +0000 (16:12 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15413 a592a061-630c-0410-9148-cb99ea01b6c8

14 files changed:
src/BufferView.C
src/factory.C
src/insets/insetbibitem.C
src/insets/insetbibtex.C
src/insets/insethfill.C
src/insets/insetinclude.C
src/insets/insetindex.C
src/insets/insetlabel.C
src/insets/insetref.C
src/insets/inseturl.C
src/mathed/InsetMathHull.C
src/support/convert.C
src/support/lstrings.C
src/support/lstrings.h

index 852af5807e6a26aaa4a16c34c55fdda8ea1c263e..ad86b9f9447182b3beb9eb05ca95922b6c8bcd77 100644 (file)
@@ -772,7 +772,7 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                                getInsetByCode<InsetRef>(cursor_,
                                                         InsetBase::REF_CODE);
                        if (inset) {
-                               label = lyx::from_utf8(inset->getContents());
+                               label = inset->getParam("reference");
                                savePosition(0);
                        }
                }
index 22f8fa9d57a8671f9b5677174ec9c4ccd88cc10a..229a15ddfe6f39e8b5f6e6ff7db34f241298cf4a 100644 (file)
@@ -162,10 +162,9 @@ InsetBase * createInset(BufferView * bv, FuncRequest const & cmd)
        case LFUN_INDEX_INSERT: {
                // Try and generate a valid index entry.
                InsetCommandParams icp("index");
-               string const contents = cmd.argument().empty() ?
-                       bv->getLyXText()->getStringToIndex(bv->cursor()) :
-                       lyx::to_utf8(cmd.argument());
-               icp.setContents(contents);
+               icp["name"] = cmd.argument().empty() ?
+                       lyx::from_utf8(bv->getLyXText()->getStringToIndex(bv->cursor())) :
+                       cmd.argument();
                return new InsetIndex(icp);
        }
 
@@ -380,8 +379,8 @@ InsetBase * readInset(LyXLex & lex, Buffer const & buf)
                           || cmdName == "vref"
                           || cmdName == "vpageref"
                           || cmdName == "prettyref") {
-                       if (!inscmd.getOptions().empty()
-                           || !inscmd.getContents().empty()) {
+                       if (!inscmd["name"].empty()
+                           || !inscmd["reference"].empty()) {
                                inset.reset(new InsetRef(inscmd, buf));
                        }
                } else if (cmdName == "tableofcontents") {
index 8939ff6dfa09110f7f17e34ad75f54bf1ed5cb54..88d1e8ae992620b15d533e561867e8b9af5abebf 100644 (file)
@@ -35,13 +35,13 @@ using std::auto_ptr;
 using std::ostream;
 
 int InsetBibitem::key_counter = 0;
-string const key_prefix = "key-";
+docstring const key_prefix = lyx::from_ascii("key-");
 
 InsetBibitem::InsetBibitem(InsetCommandParams const & p)
        : InsetCommand(p, "bibitem"), counter(1)
 {
-       if (getContents().empty())
-               setContents(key_prefix + convert<string>(++key_counter));
+       if (getParam("key").empty())
+               setParam("key", key_prefix + convert<docstring>(++key_counter));
 }
 
 
@@ -64,9 +64,10 @@ void InsetBibitem::doDispatch(LCursor & cur, FuncRequest & cmd)
                        cur.noUpdate();
                        break;
                }
-               if (p.getContents() != params().getContents()) 
-                       cur.bv().buffer()->changeRefsIfUnique(params().getContents(),
-                                                      p.getContents(), InsetBase::CITE_CODE);
+               if (p["key"] != params()["key"])
+                       // FIXME UNICODE
+                       cur.bv().buffer()->changeRefsIfUnique(lyx::to_utf8(params()["key"]),
+                                                      lyx::to_utf8(p["key"]), InsetBase::CITE_CODE);
                setParams(p);
        }
 
@@ -87,8 +88,8 @@ void InsetBibitem::read(Buffer const & buf, LyXLex & lex)
 {
        InsetCommand::read(buf, lex);
 
-       if (prefixIs(getContents(), key_prefix)) {
-               int const key = convert<int>(getContents().substr(key_prefix.length()));
+       if (prefixIs(getParam("key"), key_prefix)) {
+               int const key = convert<int>(getParam("key").substr(key_prefix.length()));
                key_counter = max(key_counter, key);
        }
 }
@@ -96,17 +97,14 @@ void InsetBibitem::read(Buffer const & buf, LyXLex & lex)
 
 docstring const InsetBibitem::getBibLabel() const
 {
-       // FIXME UNICODE
-       return getOptions().empty() ?
-               convert<docstring>(counter) :
-               lyx::from_utf8(getOptions());
+       docstring const & label = getParam("label");
+       return label.empty() ?  convert<docstring>(counter) : label;
 }
 
 
 docstring const InsetBibitem::getScreenLabel(Buffer const &) const
 {
-       // FIXME UNICODE
-       return lyx::from_utf8(getContents()) + " [" + getBibLabel() + ']';
+       return getParam("key") + " [" + getBibLabel() + ']';
 }
 
 
index ae89a8696a654050be337474c6328503cfd59fb2..b7098a8fea179d47b487b8156f2259f510eae253 100644 (file)
@@ -154,7 +154,7 @@ int InsetBibtex::latex(Buffer const & buffer, odocstream & os,
        typedef boost::tokenizer<Separator> Tokenizer;
 
        Separator const separator(",");
-       Tokenizer const tokens(getContents(), separator);
+       Tokenizer const tokens(lyx::to_utf8(getParam("bibfiles")), separator);
        Tokenizer::const_iterator const begin = tokens.begin();
        Tokenizer::const_iterator const end = tokens.end();
 
@@ -185,15 +185,15 @@ int InsetBibtex::latex(Buffer const & buffer, odocstream & os,
                        dbs << ',';
                dbs << latex_path(database);
        }
-       string const db_out = dbs.str();
+       // FIXME UNICODE
+       docstring const db_out = lyx::from_utf8(dbs.str());
 
        // Post this warning only once.
        static bool warned_about_spaces = false;
        if (!warned_about_spaces &&
-           runparams.nice && db_out.find(' ') != string::npos) {
+           runparams.nice && db_out.find(' ') != docstring::npos) {
                warned_about_spaces = true;
 
-               // FIXME UNICODE
                Alert::warning(_("Export Warning!"),
                               _("There are spaces in the paths to your BibTeX databases.\n"
                                              "BibTeX will be unable to find them."));
@@ -201,7 +201,7 @@ int InsetBibtex::latex(Buffer const & buffer, odocstream & os,
        }
 
        // Style-Options
-       string style = getOptions(); // maybe empty! and with bibtotoc
+       string style = lyx::to_utf8(getParam("options")); // maybe empty! and with bibtotoc
        string bibtotoc;
        if (prefixIs(style, "bibtotoc")) {
                bibtotoc = "bibtotoc";
@@ -252,8 +252,7 @@ int InsetBibtex::latex(Buffer const & buffer, odocstream & os,
        }
 
        if (!db_out.empty() && buffer.params().use_bibtopic){
-               // FIXME UNICODE
-               os << "\\begin{btSect}{" << lyx::from_utf8(db_out) << "}\n";
+               os << "\\begin{btSect}{" << db_out << "}\n";
                docstring btprint = getParam("btprint");
                if (btprint.empty())
                        // default
@@ -289,8 +288,7 @@ int InsetBibtex::latex(Buffer const & buffer, odocstream & os,
        }
 
        if (!db_out.empty() && !buffer.params().use_bibtopic){
-               // FIXME UNICODE
-               os << "\\bibliography{" << lyx::from_utf8(db_out) << "}\n";
+               os << "\\bibliography{" << db_out << "}\n";
                nlines += 1;
        }
 
@@ -305,7 +303,8 @@ vector<string> const InsetBibtex::getFiles(Buffer const & buffer) const
        vector<string> vec;
 
        string tmp;
-       string bibfiles = getContents();
+       // FIXME UNICODE
+       string bibfiles = lyx::to_utf8(getParam("bibfiles"));
        bibfiles = split(bibfiles, tmp, ',');
        while (!tmp.empty()) {
                string file = findtexfile(changeExtension(tmp, "bib"), "bib");
@@ -362,11 +361,12 @@ void InsetBibtex::fillWithBibKeys(Buffer const & buffer,
 
 bool InsetBibtex::addDatabase(string const & db)
 {
-       string contents(getContents());
-       if (tokenPos(contents, ',', db) == -1) {
-               if (!contents.empty())
-                       contents += ',';
-               setContents(contents + db);
+       // FIXME UNICODE
+       string bibfiles(lyx::to_utf8(getParam("bibfiles")));
+       if (tokenPos(bibfiles, ',', db) == -1) {
+               if (!bibfiles.empty())
+                       bibfiles += ',';
+               setParam("bibfiles", lyx::from_utf8(bibfiles + db));
                return true;
        }
        return false;
@@ -375,17 +375,18 @@ bool InsetBibtex::addDatabase(string const & db)
 
 bool InsetBibtex::delDatabase(string const & db)
 {
-       string contents(getContents());
-       if (contains(contents, db)) {
-               int const n = tokenPos(contents, ',', db);
+       // FIXME UNICODE
+       string bibfiles(lyx::to_utf8(getParam("bibfiles")));
+       if (contains(bibfiles, db)) {
+               int const n = tokenPos(bibfiles, ',', db);
                string bd = db;
                if (n > 0) {
                        // this is not the first database
                        string tmp = ',' + bd;
-                       setContents(subst(contents, tmp, ""));
+                       setParam("bibfiles", lyx::from_utf8(subst(bibfiles, tmp, string())));
                } else if (n == 0)
                        // this is the first (or only) database
-                       setContents(split(contents, bd, ','));
+                       setParam("bibfiles", lyx::from_utf8(split(bibfiles, bd, ',')));
                else
                        return false;
        }
index 159d6c81f19676be77418d6310742db3815f0d8c..18fbc104774a5440e39bf08aff91821e8aeed164 100644 (file)
@@ -12,6 +12,8 @@
 
 #include "insethfill.h"
 
+#include "gettext.h"
+
 #include "support/std_ostream.h"
 
 using lyx::docstring;
@@ -42,7 +44,7 @@ void InsetHFill::metrics(MetricsInfo &, Dimension & dim) const
 
 docstring const InsetHFill::getScreenLabel(Buffer const &) const
 {
-       return lyx::from_ascii(getContents());
+       return _("Horizontal Fill");
 }
 
 
index 451e0af66b93602f6c768ceb765e482bd56e49c2..bb5761433acec3cbe6ff04c90c5a09c054a9fa9e 100644 (file)
@@ -222,7 +222,7 @@ string const parentFilename(Buffer const & buffer)
 string const includedFilename(Buffer const & buffer,
                              InsetCommandParams const & params)
 {
-       return makeAbsPath(params.getContents(),
+       return makeAbsPath(lyx::to_utf8(params["filename"]),
                           onlyPath(parentFilename(buffer)));
 }
 
@@ -297,11 +297,11 @@ docstring const InsetInclude::getScreenLabel(Buffer const &) const
 
        temp += ": ";
 
-       if (params_.getContents().empty())
+       if (params_["filename"].empty())
                temp += "???";
        else
                // FIXME: We don't know the encoding of the filename
-               temp += lyx::from_ascii(onlyFilename(params_.getContents()));
+               temp += lyx::from_ascii(onlyFilename(lyx::to_utf8(params_["filename"])));
 
        return temp;
 }
@@ -354,7 +354,7 @@ bool loadIfNeeded(Buffer const & buffer, InsetCommandParams const & params)
 int InsetInclude::latex(Buffer const & buffer, odocstream & os,
                        OutputParams const & runparams) const
 {
-       string incfile(params_.getContents());
+       string incfile(lyx::to_utf8(params_["filename"]));
 
        // Do nothing if no file name has been specified
        if (incfile.empty())
@@ -491,7 +491,7 @@ int InsetInclude::plaintext(Buffer const & buffer, odocstream & os,
 int InsetInclude::docbook(Buffer const & buffer, odocstream & os,
                          OutputParams const & runparams) const
 {
-       string incfile(params_.getContents());
+       string incfile(lyx::to_utf8(params_["filename"]));
 
        // Do nothing if no file name has been specified
        if (incfile.empty())
@@ -538,7 +538,7 @@ int InsetInclude::docbook(Buffer const & buffer, odocstream & os,
 
 void InsetInclude::validate(LaTeXFeatures & features) const
 {
-       string incfile(params_.getContents());
+       string incfile(lyx::to_utf8(params_["filename"]));
        string writefile;
 
        Buffer const & buffer = features.buffer();
index 7190d23b76ee01135b91576c987d3c7080a8721e..38c37c39319a13a08149c6f9f0ebf0782f61bba4 100644 (file)
@@ -48,7 +48,7 @@ int InsetIndex::docbook(Buffer const &, odocstream & os,
 {
         // FIXME UNICODE
        os << "<indexterm><primary>"
-           << lyx::from_ascii(sgml::escapeString(getContents()))
+           << lyx::from_ascii(sgml::escapeString(lyx::to_ascii(getParam("name"))))
           << "</primary></indexterm>";
        return 0;
 }
index d782c23590b45f5a5c182197c9d172b6f00f5784..6a7db8d5c96b0838e3221cb13a0f82fb3afdba95 100644 (file)
@@ -48,15 +48,13 @@ std::auto_ptr<InsetBase> InsetLabel::doClone() const
 
 void InsetLabel::getLabelList(Buffer const &, std::vector<docstring> & list) const
 {
-       // FIXME UNICODE
-       list.push_back(lyx::from_utf8(getContents()));
+       list.push_back(getParam("name"));
 }
 
 
 docstring const InsetLabel::getScreenLabel(Buffer const &) const
 {
-       // FIXME UNICODE
-       return lyx::from_utf8(getContents());
+       return getParam("name");
 }
 
 
@@ -71,9 +69,10 @@ void InsetLabel::doDispatch(LCursor & cur, FuncRequest & cmd)
                        cur.noUpdate();
                        break;
                }
-               if (p.getContents() != params().getContents())
-                       cur.bv().buffer()->changeRefsIfUnique(params().getContents(),
-                                                      p.getContents(), InsetBase::REF_CODE);
+               if (p["name"] != params()["name"])
+                       // FIXME UNICODE
+                       cur.bv().buffer()->changeRefsIfUnique(lyx::to_utf8(params()["name"]),
+                                                      lyx::to_utf8(p["name"]), InsetBase::REF_CODE);
                setParams(p);
                break;
        }
@@ -96,8 +95,7 @@ int InsetLabel::latex(Buffer const &, odocstream & os,
 int InsetLabel::plaintext(Buffer const &, odocstream & os,
                      OutputParams const &) const
 {
-       // FIXME UNICODE
-       os << '<' << lyx::from_utf8(getContents()) << '>';
+       os << '<' << getParam("name") << '>';
        return 0;
 }
 
@@ -107,7 +105,7 @@ int InsetLabel::docbook(Buffer const & buf, odocstream & os,
 {
         // FIXME UNICODE
        os << "<!-- anchor id=\""
-           << lyx::from_ascii(sgml::cleanID(buf, runparams, getContents()))
+           << lyx::from_ascii(sgml::cleanID(buf, runparams, lyx::to_ascii(getParam("name"))))
            << "\" -->";
        return 0;
 }
index 4d7c472028e912a3d80ac8c52463d6cc9e475afe..3d80f05332d5a07018fd221cb512fd1390fc2c14 100644 (file)
@@ -48,7 +48,7 @@ void InsetRef::doDispatch(LCursor & cur, FuncRequest & cmd)
        case LFUN_MOUSE_PRESS:
                // Eventually trigger dialog with button 3 not 1
                if (cmd.button() == mouse_button::button3)
-                       lyx::dispatch(FuncRequest(LFUN_LABEL_GOTO, getContents()));
+                       lyx::dispatch(FuncRequest(LFUN_LABEL_GOTO, getParam("reference")));
                else {
                        InsetCommandMailer("ref", *this).showDialog(&cur.bv());
                        cur.undispatched();
@@ -73,13 +73,11 @@ docstring const InsetRef::getScreenLabel(Buffer const &) const
                        break;
                }
        }
-       // FIXME UNICODE
-       temp += lyx::from_utf8(getContents());
+       temp += getParam("reference");
 
-       if (!isLatex && !getOptions().empty()) {
+       if (!isLatex && !getParam("name").empty()) {
                temp += "||";
-               // FIXME UNICODE
-               temp += lyx::from_utf8(getOptions());
+               temp += getParam("name");
        }
        return temp;
 }
@@ -99,8 +97,7 @@ int InsetRef::latex(Buffer const &, odocstream & os,
 int InsetRef::plaintext(Buffer const &, odocstream & os,
                    OutputParams const &) const
 {
-       // FIXME UNICODE
-       os << '[' << lyx::from_utf8(getContents()) << ']';
+       os << '[' << getParam("reference") << ']';
        return 0;
 }
 
@@ -108,21 +105,23 @@ int InsetRef::plaintext(Buffer const &, odocstream & os,
 int InsetRef::docbook(Buffer const & buf, odocstream & os,
                      OutputParams const & runparams) const
 {
-        // FIXME UNICODE
-       if (getOptions().empty() && runparams.flavor == OutputParams::XML) {
-               os << "<xref linkend=\""
-                   << lyx::from_ascii(sgml::cleanID(buf, runparams, getContents()))
-                   << "\" />";
-       } else if (getOptions().empty()) {
-               os << "<xref linkend=\""
-                   << lyx::from_ascii(sgml::cleanID(buf, runparams, getContents()))
-                   << "\">";
+       docstring const & name = getParam("name");
+       if (name.empty()) {
+               if (runparams.flavor == OutputParams::XML) {
+                       os << "<xref linkend=\"" 
+                          << lyx::from_ascii(sgml::cleanID(buf, runparams, lyx::to_ascii(getParam("reference")))) 
+                          << "\" />";
+               } else {
+                       os << "<xref linkend=\"" 
+                          << lyx::from_ascii(sgml::cleanID(buf, runparams, lyx::to_ascii(getParam("reference")))) 
+                          << "\">";
+               }
        } else {
-               os << "<link linkend=\""
-                   << lyx::from_ascii(sgml::cleanID(buf, runparams, getContents()))
-                  << "\">"
-                   << lyx::from_ascii(getOptions())
-                   << "</link>";
+               os << "<link linkend=\"" 
+                  << lyx::from_ascii(sgml::cleanID(buf, runparams, lyx::to_ascii(getParam("reference"))))
+                  << "\">" 
+                  << getParam("name")
+                  << "</link>";
        }
 
        return 0;
index 564e61a3aba189827692463cebae4dc4db024aeb..023c281ae3e9efe6ff28800e936b586f09d38ae0 100644 (file)
@@ -40,20 +40,19 @@ docstring const InsetUrl::getScreenLabel(Buffer const &) const
        docstring const temp =
                (getCmdName() == "url") ? _("Url: ") : _("HtmlUrl: ");
 
-       string url;
+       docstring url;
 
-       if (!getOptions().empty())
-               url += getOptions();
+       if (!getParam("name").empty())
+               url += getParam("name");
        else
-               url += getContents();
+               url += getParam("target");
 
        // elide if long
        if (url.length() > 30) {
                url = url.substr(0, 10) + "..."
                        + url.substr(url.length() - 17, url.length());
        }
-       // FIXME UNICODE
-       return temp + lyx::from_utf8(url);
+       return temp + url;
 }
 
 
@@ -73,13 +72,11 @@ int InsetUrl::latex(Buffer const &, odocstream & os,
 int InsetUrl::plaintext(Buffer const &, odocstream & os,
                    OutputParams const &) const
 {
-       // FIXME UNICODE
-       os << '[' << lyx::from_utf8(getContents());
-       if (getOptions().empty())
+       os << '[' << getParam("target");
+       if (getParam("name").empty())
                os << ']';
        else
-               // FIXME UNICODE
-               os << "||" << lyx::from_utf8(getOptions()) << ']';
+               os << "||" << getParam("name") << ']';
        return 0;
 }
 
@@ -87,12 +84,11 @@ int InsetUrl::plaintext(Buffer const &, odocstream & os,
 int InsetUrl::docbook(Buffer const &, odocstream & os,
                      OutputParams const &) const
 {
-        // FIXME UNICODE
-       os << "<ulink url=\""
-           << lyx::from_ascii(subst(getContents(), "&", "&amp;"))
-          << "\">"
-           << lyx::from_ascii(getOptions())
-           << "</ulink>";
+       os << "<ulink url=\"" 
+          << subst(getParam("target"), lyx::from_ascii("&"), lyx::from_ascii("&amp;"))
+          << "\">" 
+          << getParam("name")
+          << "</ulink>";
        return 0;
 }
 
index c739b221320825a827843469ba757fecadc71735..712a9bcfe7fa7b845bc1d11f841f28460d6547aa 100644 (file)
@@ -1118,7 +1118,7 @@ void InsetMathHull::doDispatch(LCursor & cur, FuncRequest & cmd)
                if (name == "label") {
                        InsetCommandParams p("label");
                        InsetCommandMailer::string2params(name, lyx::to_utf8(cmd.argument()), p);
-                       string str = p.getContents();
+                       string str = lyx::to_utf8(p["name"]);
                        recordUndoInset(cur);
                        row_type const r = (type_ == hullMultline) ? nrows() - 1 : cur.row();
                        str = lyx::support::trim(str);
index a3014fe41864d7d77def4d9b56fd8ed00cfbcec9..0e34108beeac1dff3546a0eb26228b3afd1821ae 100644 (file)
@@ -124,6 +124,13 @@ int convert<int>(string const s)
 }
 
 
+template<>
+int convert<int>(docstring const s)
+{
+       return strtol(lyx::to_ascii(s).c_str(), 0, 10);
+}
+
+
 template<>
 unsigned int convert<unsigned int>(string const s)
 {
index 0036da8753450fe25a3c43883aea04b32ed9c303..f3023313325a4dc4c7321e778472c10d9d7c2f26 100644 (file)
@@ -329,6 +329,18 @@ bool prefixIs(string const & a, string const & pre)
 }
 
 
+bool prefixIs(docstring const & a, docstring const & pre)
+{
+       docstring::size_type const prelen = pre.length();
+       docstring::size_type const alen = a.length();
+
+       if (prelen > alen || a.empty())
+               return false;
+       else
+               return a.compare(0, prelen, pre) == 0;
+}
+
+
 bool suffixIs(string const & a, char c)
 {
        if (a.empty()) return false;
index 00016c3932c32e3259ab48a646ea985834d04404..a4e316300e0a98dc767a760e94ccbfaf163fc7f8 100644 (file)
@@ -91,6 +91,7 @@ std::string const uppercase(std::string const &);
 
 /// Does the std::string start with this prefix?
 bool prefixIs(std::string const &, std::string const &);
+bool prefixIs(lyx::docstring const &, lyx::docstring const &);
 
 /// Does the string end with this char?
 bool suffixIs(std::string const &, char);