From ff1355a08a80e51a6f667a98d0193b2da9250f5a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 18 Feb 2003 13:25:18 +0000 Subject: [PATCH] fix bibkey writing, avoid a few copies, whitespace changes.. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6196 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 6 ++-- src/buffer.C | 37 +++++++++------------ src/buffer.h | 4 +-- src/frontends/controllers/ControlCitation.C | 3 +- src/insets/insetbib.C | 19 ++++------- src/insets/insetbib.h | 3 +- src/insets/insetcite.C | 3 +- src/insets/insetinclude.C | 8 ++--- src/insets/insetinclude.h | 2 +- src/text2.C | 7 ++-- 10 files changed, 39 insertions(+), 53 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index dd3ab58ad9..e654a63eac 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -865,12 +865,12 @@ bool BufferView::ChangeRefsIfUnique(string const & from, string const & to) } -bool BufferView::ChangeCitationsIfUnique(string const & from, - string const & to) +bool BufferView::ChangeCitationsIfUnique(string const & from, string const & to) { typedef pair StringPair; - vector keys = buffer()->getBibkeyList(); + vector keys; + buffer()->fillWithBibKeys(keys); if (count_if(keys.begin(), keys.end(), lyx::equal_1st_in_pair(from)) > 1) diff --git a/src/buffer.C b/src/buffer.C index 26a813cd82..06ae1d8380 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -130,7 +130,6 @@ using std::pair; using std::make_pair; using std::vector; using std::map; -using std::max; using std::stack; using std::list; using std::for_each; @@ -923,7 +922,8 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par, params.float_placement = lex.getString(); } else if (token == "\\align") { int tmpret = lex.findToken(string_align); - if (tmpret == -1) ++tmpret; + if (tmpret == -1) + ++tmpret; int const tmpret2 = int(pow(2.0, tmpret)); par->params().align(LyXAlignment(tmpret2)); } else if (token == "\\added_space_top") { @@ -1586,7 +1586,7 @@ string const Buffer::asciiParagraph(Paragraph const & par, // this is to change the linebreak to do it by word a bit more // intelligent hopefully! (only in the case where we have a - // max linelenght!) (Jug) + // max linelength!) (Jug) string word; @@ -2872,40 +2872,33 @@ vector const Buffer::getLabelList() const // This is also a buffer property (ale) -vector > const Buffer::getBibkeyList() const +void Buffer::fillWithBibKeys(vector > & keys) const { - typedef pair StringPair; /// if this is a child document and the parent is already loaded - /// Use the parent's list instead [ale990412] + /// use the parent's list instead [ale990412] if (!params.parentname.empty() && bufferlist.exists(params.parentname)) { Buffer const * tmp = bufferlist.getBuffer(params.parentname); - if (tmp) - return tmp->getBibkeyList(); + if (tmp) { + tmp->fillWithBibKeys(keys); + return; + } } - vector keys; for (inset_iterator it = inset_const_iterator_begin(); it != inset_const_iterator_end(); ++it) { - // Search for Bibtex or Include inset - if (it->lyxCode() == Inset::BIBTEX_CODE) { - vector tmp = - static_cast(*it).getKeys(this); - keys.insert(keys.end(), tmp.begin(), tmp.end()); - } else if (it->lyxCode() == Inset::INCLUDE_CODE) { - vector const tmp = - static_cast(*it).getKeys(); - keys.insert(keys.end(), tmp.begin(), tmp.end()); - } else if (it->lyxCode() == Inset::BIBKEY_CODE) { + if (it->lyxCode() == Inset::BIBTEX_CODE) + static_cast(*it).fillWithBibKeys(this, keys); + else if (it->lyxCode() == Inset::INCLUDE_CODE) + static_cast(*it).fillWithBibKeys(keys); + else if (it->lyxCode() == Inset::BIBKEY_CODE) { InsetBibKey & bib = static_cast(*it); string const key = bib.getContents(); string const opt = bib.getOptions(); string const ref; // = pit->asString(this, false); string const info = opt + "TheBibliographyRef" + ref; - keys.push_back(StringPair(key, info)); + keys.push_back(pair(key, info)); } } - - return keys; } diff --git a/src/buffer.h b/src/buffer.h index 19c6680a7e..ad57b1ef39 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -247,8 +247,8 @@ public: */ void validate(LaTeXFeatures &) const; - /// - std::vector > const getBibkeyList() const; + /// return all bibkeys from buffer and its childs + void fillWithBibKeys(vector > & keys) const; /// std::vector const getLabelList() const; diff --git a/src/frontends/controllers/ControlCitation.C b/src/frontends/controllers/ControlCitation.C index b691ca8de2..4d0f1c42bd 100644 --- a/src/frontends/controllers/ControlCitation.C +++ b/src/frontends/controllers/ControlCitation.C @@ -34,7 +34,8 @@ void ControlCitation::clearDaughterParams() void ControlCitation::setDaughterParams() { - vector > blist = buffer()->getBibkeyList(); + vector > blist; + buffer()->fillWithBibKeys(blist); typedef std::map::value_type InfoMapValue; diff --git a/src/insets/insetbib.C b/src/insets/insetbib.C index 2fdee1a160..084deead79 100644 --- a/src/insets/insetbib.C +++ b/src/insets/insetbib.C @@ -71,11 +71,10 @@ void InsetBibKey::setCounter(int c) // of time cause LyX3 won't use lyxlex anyway. (ale) void InsetBibKey::write(Buffer const *, ostream & os) const { - os << "\n\\layout Bibliography\n\\bibitem "; - if (! getOptions().empty()) + os << "\n\\bibitem "; + if (!getOptions().empty()) os << '[' << getOptions() << ']'; - os << '{' - << getContents() << "}\n"; + os << '{' << getContents() << "}\n"; } @@ -84,8 +83,7 @@ void InsetBibKey::write(Buffer const *, ostream & os) const void InsetBibKey::read(Buffer const *, LyXLex & lex) { if (lex.eatLine()) { - string const token = lex.getString(); - scanCommand(token); + scanCommand(lex.getString()); } else { lex.printError("InsetCommand: Parse error: `$$Token'"); } @@ -200,7 +198,7 @@ int InsetBibtex::latex(Buffer const * buffer, ostream & os, adb = os::external_path(MakeAbsPath(adb, buffer->filePath())); db_out += adb; db_out += ','; - db_in= split(db_in, adb,','); + db_in = split(db_in, adb,','); } db_out = rtrim(db_out, ","); os << "\\bibliography{" << db_out << "}\n"; @@ -235,11 +233,9 @@ vector const InsetBibtex::getFiles(Buffer const & buffer) const // This method returns a comma separated list of Bibtex entries -vector > const - InsetBibtex::getKeys(Buffer const * buffer) const +void InsetBibtex::fillWithBibKeys + (Buffer const * buffer, vector > & keys) const { - vector > keys; - lyx::Assert(buffer); vector const files = getFiles(*buffer); for (vector::const_iterator it = files.begin(); @@ -271,7 +267,6 @@ vector > const } } } - return keys; } diff --git a/src/insets/insetbib.h b/src/insets/insetbib.h index c407c8c79c..7a76f01f83 100644 --- a/src/insets/insetbib.h +++ b/src/insets/insetbib.h @@ -93,7 +93,8 @@ public: int latex(Buffer const *, std::ostream &, bool fragile, bool freespace) const; /// - std::vector > const getKeys(Buffer const *) const; + void fillWithBibKeys(Buffer const *, + std::vector > &) const; /// std::vector const getFiles(Buffer const &) const; /// diff --git a/src/insets/insetcite.C b/src/insets/insetcite.C index d7b7206cd3..9df8737b02 100644 --- a/src/insets/insetcite.C +++ b/src/insets/insetcite.C @@ -66,7 +66,8 @@ string const getNatbibLabel(Buffer const * buffer, if (loadkeys) { // build the keylist typedef vector > InfoType; - InfoType bibkeys = buffer->getBibkeyList(); + InfoType bibkeys; + buffer->fillWithBibKeys(bibkeys); InfoType::const_iterator bit = bibkeys.begin(); InfoType::const_iterator bend = bibkeys.end(); diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 58d2827f5b..2b0b6bb6f2 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -483,18 +483,14 @@ vector const InsetInclude::getLabelList() const } -vector > const InsetInclude::getKeys() const +void InsetInclude::fillWithBibKeys(vector > & keys) const { - vector > keys; - if (loadIfNeeded()) { Buffer * tmp = bufferlist.getBuffer(getFileName()); tmp->setParentName(""); - keys = tmp->getBibkeyList(); + tmp->fillWithBibKeys(keys); tmp->setParentName(getMasterFilename()); } - - return keys; } diff --git a/src/insets/insetinclude.h b/src/insets/insetinclude.h index b2e8443a96..f926c42d56 100644 --- a/src/insets/insetinclude.h +++ b/src/insets/insetinclude.h @@ -79,7 +79,7 @@ public: /// This returns the list of labels on the child buffer std::vector const getLabelList() const; /// This returns the list of bibkeys on the child buffer - std::vector< std::pair > const getKeys() const; + void fillWithBibKeys(vector > & keys) const; /// void edit(BufferView *, int x, int y, mouse_button::state button); /// diff --git a/src/text2.C b/src/text2.C index 50030c4d52..f8b6104d84 100644 --- a/src/text2.C +++ b/src/text2.C @@ -1264,14 +1264,13 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const textclass.counters().step("bibitem"); int number = textclass.counters().value("bibitem"); //if (!par->bibkey()) { + // Inset * inset = new InsetBibKey(InsetCommandParams("bibitem")); + // //par->insertInset(0, inset); + //} if (par->bibkey()) { par->bibkey()->setCounter(number); par->params().labelString(layout->labelstring()); } - // else { - // InsetCommandParams p("bibitem"); - // par->bibkey() = new InsetBibKey(p); - //} // In biblio should't be following counters but... } else { string s = layout->labelstring(); -- 2.39.2