From ffe7cb1b780e763a35d46c3fc07183a5359a36a9 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Fri, 20 Oct 2006 16:12:49 +0000 Subject: [PATCH] Use the new InsetCommandParams interface (inset part), from Ugras and me git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15413 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 2 +- src/factory.C | 11 +++++----- src/insets/insetbibitem.C | 26 +++++++++++------------ src/insets/insetbibtex.C | 41 ++++++++++++++++++------------------ src/insets/insethfill.C | 4 +++- src/insets/insetinclude.C | 12 +++++------ src/insets/insetindex.C | 2 +- src/insets/insetlabel.C | 18 +++++++--------- src/insets/insetref.C | 43 +++++++++++++++++++------------------- src/insets/inseturl.C | 30 ++++++++++++-------------- src/mathed/InsetMathHull.C | 2 +- src/support/convert.C | 7 +++++++ src/support/lstrings.C | 12 +++++++++++ src/support/lstrings.h | 1 + 14 files changed, 112 insertions(+), 99 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index 852af5807e..ad86b9f944 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -772,7 +772,7 @@ bool BufferView::dispatch(FuncRequest const & cmd) getInsetByCode(cursor_, InsetBase::REF_CODE); if (inset) { - label = lyx::from_utf8(inset->getContents()); + label = inset->getParam("reference"); savePosition(0); } } diff --git a/src/factory.C b/src/factory.C index 22f8fa9d57..229a15ddfe 100644 --- a/src/factory.C +++ b/src/factory.C @@ -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") { diff --git a/src/insets/insetbibitem.C b/src/insets/insetbibitem.C index 8939ff6dfa..88d1e8ae99 100644 --- a/src/insets/insetbibitem.C +++ b/src/insets/insetbibitem.C @@ -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(++key_counter)); + if (getParam("key").empty()) + setParam("key", key_prefix + convert(++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(getContents().substr(key_prefix.length())); + if (prefixIs(getParam("key"), key_prefix)) { + int const key = convert(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(counter) : - lyx::from_utf8(getOptions()); + docstring const & label = getParam("label"); + return label.empty() ? convert(counter) : label; } docstring const InsetBibitem::getScreenLabel(Buffer const &) const { - // FIXME UNICODE - return lyx::from_utf8(getContents()) + " [" + getBibLabel() + ']'; + return getParam("key") + " [" + getBibLabel() + ']'; } diff --git a/src/insets/insetbibtex.C b/src/insets/insetbibtex.C index ae89a8696a..b7098a8fea 100644 --- a/src/insets/insetbibtex.C +++ b/src/insets/insetbibtex.C @@ -154,7 +154,7 @@ int InsetBibtex::latex(Buffer const & buffer, odocstream & os, typedef boost::tokenizer 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 const InsetBibtex::getFiles(Buffer const & buffer) const vector 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; } diff --git a/src/insets/insethfill.C b/src/insets/insethfill.C index 159d6c81f1..18fbc10477 100644 --- a/src/insets/insethfill.C +++ b/src/insets/insethfill.C @@ -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"); } diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 451e0af66b..bb5761433a 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -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(); diff --git a/src/insets/insetindex.C b/src/insets/insetindex.C index 7190d23b76..38c37c3931 100644 --- a/src/insets/insetindex.C +++ b/src/insets/insetindex.C @@ -48,7 +48,7 @@ int InsetIndex::docbook(Buffer const &, odocstream & os, { // FIXME UNICODE os << "" - << lyx::from_ascii(sgml::escapeString(getContents())) + << lyx::from_ascii(sgml::escapeString(lyx::to_ascii(getParam("name")))) << ""; return 0; } diff --git a/src/insets/insetlabel.C b/src/insets/insetlabel.C index d782c23590..6a7db8d5c9 100644 --- a/src/insets/insetlabel.C +++ b/src/insets/insetlabel.C @@ -48,15 +48,13 @@ std::auto_ptr InsetLabel::doClone() const void InsetLabel::getLabelList(Buffer const &, std::vector & 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 << ""; return 0; } diff --git a/src/insets/insetref.C b/src/insets/insetref.C index 4d7c472028..3d80f05332 100644 --- a/src/insets/insetref.C +++ b/src/insets/insetref.C @@ -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 << ""; - } else if (getOptions().empty()) { - os << ""; + docstring const & name = getParam("name"); + if (name.empty()) { + if (runparams.flavor == OutputParams::XML) { + os << ""; + } else { + os << ""; + } } else { - os << "" - << lyx::from_ascii(getOptions()) - << ""; + os << "" + << getParam("name") + << ""; } return 0; diff --git a/src/insets/inseturl.C b/src/insets/inseturl.C index 564e61a3ab..023c281ae3 100644 --- a/src/insets/inseturl.C +++ b/src/insets/inseturl.C @@ -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 << "" - << lyx::from_ascii(getOptions()) - << ""; + os << "" + << getParam("name") + << ""; return 0; } diff --git a/src/mathed/InsetMathHull.C b/src/mathed/InsetMathHull.C index c739b22132..712a9bcfe7 100644 --- a/src/mathed/InsetMathHull.C +++ b/src/mathed/InsetMathHull.C @@ -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); diff --git a/src/support/convert.C b/src/support/convert.C index a3014fe418..0e34108bee 100644 --- a/src/support/convert.C +++ b/src/support/convert.C @@ -124,6 +124,13 @@ int convert(string const s) } +template<> +int convert(docstring const s) +{ + return strtol(lyx::to_ascii(s).c_str(), 0, 10); +} + + template<> unsigned int convert(string const s) { diff --git a/src/support/lstrings.C b/src/support/lstrings.C index 0036da8753..f302331332 100644 --- a/src/support/lstrings.C +++ b/src/support/lstrings.C @@ -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; diff --git a/src/support/lstrings.h b/src/support/lstrings.h index 00016c3932..a4e316300e 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -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); -- 2.39.2