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
This commit is contained in:
André Pönitz 2003-02-18 13:25:18 +00:00
parent 2b99c9b189
commit ff1355a08a
10 changed files with 39 additions and 53 deletions

View File

@ -865,12 +865,12 @@ bool BufferView::ChangeRefsIfUnique(string const & from, string const & to)
} }
bool BufferView::ChangeCitationsIfUnique(string const & from, bool BufferView::ChangeCitationsIfUnique(string const & from, string const & to)
string const & to)
{ {
typedef pair<string, string> StringPair; typedef pair<string, string> StringPair;
vector<StringPair> keys = buffer()->getBibkeyList(); vector<StringPair> keys;
buffer()->fillWithBibKeys(keys);
if (count_if(keys.begin(), keys.end(), if (count_if(keys.begin(), keys.end(),
lyx::equal_1st_in_pair<StringPair>(from)) lyx::equal_1st_in_pair<StringPair>(from))
> 1) > 1)

View File

@ -130,7 +130,6 @@ using std::pair;
using std::make_pair; using std::make_pair;
using std::vector; using std::vector;
using std::map; using std::map;
using std::max;
using std::stack; using std::stack;
using std::list; using std::list;
using std::for_each; using std::for_each;
@ -923,7 +922,8 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
params.float_placement = lex.getString(); params.float_placement = lex.getString();
} else if (token == "\\align") { } else if (token == "\\align") {
int tmpret = lex.findToken(string_align); int tmpret = lex.findToken(string_align);
if (tmpret == -1) ++tmpret; if (tmpret == -1)
++tmpret;
int const tmpret2 = int(pow(2.0, tmpret)); int const tmpret2 = int(pow(2.0, tmpret));
par->params().align(LyXAlignment(tmpret2)); par->params().align(LyXAlignment(tmpret2));
} else if (token == "\\added_space_top") { } 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 // this is to change the linebreak to do it by word a bit more
// intelligent hopefully! (only in the case where we have a // intelligent hopefully! (only in the case where we have a
// max linelenght!) (Jug) // max linelength!) (Jug)
string word; string word;
@ -2872,40 +2872,33 @@ vector<string> const Buffer::getLabelList() const
// This is also a buffer property (ale) // This is also a buffer property (ale)
vector<pair<string, string> > const Buffer::getBibkeyList() const void Buffer::fillWithBibKeys(vector<pair<string, string> > & keys) const
{ {
typedef pair<string, string> StringPair;
/// if this is a child document and the parent is already loaded /// 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)) { if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
Buffer const * tmp = bufferlist.getBuffer(params.parentname); Buffer const * tmp = bufferlist.getBuffer(params.parentname);
if (tmp) if (tmp) {
return tmp->getBibkeyList(); tmp->fillWithBibKeys(keys);
return;
}
} }
vector<StringPair> keys;
for (inset_iterator it = inset_const_iterator_begin(); for (inset_iterator it = inset_const_iterator_begin();
it != inset_const_iterator_end(); ++it) { it != inset_const_iterator_end(); ++it) {
// Search for Bibtex or Include inset if (it->lyxCode() == Inset::BIBTEX_CODE)
if (it->lyxCode() == Inset::BIBTEX_CODE) { static_cast<InsetBibtex &>(*it).fillWithBibKeys(this, keys);
vector<StringPair> tmp = else if (it->lyxCode() == Inset::INCLUDE_CODE)
static_cast<InsetBibtex &>(*it).getKeys(this); static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
keys.insert(keys.end(), tmp.begin(), tmp.end()); else if (it->lyxCode() == Inset::BIBKEY_CODE) {
} else if (it->lyxCode() == Inset::INCLUDE_CODE) {
vector<StringPair> const tmp =
static_cast<InsetInclude &>(*it).getKeys();
keys.insert(keys.end(), tmp.begin(), tmp.end());
} else if (it->lyxCode() == Inset::BIBKEY_CODE) {
InsetBibKey & bib = static_cast<InsetBibKey &>(*it); InsetBibKey & bib = static_cast<InsetBibKey &>(*it);
string const key = bib.getContents(); string const key = bib.getContents();
string const opt = bib.getOptions(); string const opt = bib.getOptions();
string const ref; // = pit->asString(this, false); string const ref; // = pit->asString(this, false);
string const info = opt + "TheBibliographyRef" + ref; string const info = opt + "TheBibliographyRef" + ref;
keys.push_back(StringPair(key, info)); keys.push_back(pair<string, string>(key, info));
} }
} }
return keys;
} }

View File

@ -247,8 +247,8 @@ public:
*/ */
void validate(LaTeXFeatures &) const; void validate(LaTeXFeatures &) const;
/// /// return all bibkeys from buffer and its childs
std::vector<std::pair<string, string> > const getBibkeyList() const; void fillWithBibKeys(vector<pair<string, string> > & keys) const;
/// ///
std::vector<string> const getLabelList() const; std::vector<string> const getLabelList() const;

View File

@ -34,7 +34,8 @@ void ControlCitation::clearDaughterParams()
void ControlCitation::setDaughterParams() void ControlCitation::setDaughterParams()
{ {
vector<pair<string,string> > blist = buffer()->getBibkeyList(); vector<pair<string,string> > blist;
buffer()->fillWithBibKeys(blist);
typedef std::map<string, string>::value_type InfoMapValue; typedef std::map<string, string>::value_type InfoMapValue;

View File

@ -71,11 +71,10 @@ void InsetBibKey::setCounter(int c)
// of time cause LyX3 won't use lyxlex anyway. (ale) // of time cause LyX3 won't use lyxlex anyway. (ale)
void InsetBibKey::write(Buffer const *, ostream & os) const void InsetBibKey::write(Buffer const *, ostream & os) const
{ {
os << "\n\\layout Bibliography\n\\bibitem "; os << "\n\\bibitem ";
if (!getOptions().empty()) if (!getOptions().empty())
os << '[' << getOptions() << ']'; os << '[' << getOptions() << ']';
os << '{' os << '{' << getContents() << "}\n";
<< getContents() << "}\n";
} }
@ -84,8 +83,7 @@ void InsetBibKey::write(Buffer const *, ostream & os) const
void InsetBibKey::read(Buffer const *, LyXLex & lex) void InsetBibKey::read(Buffer const *, LyXLex & lex)
{ {
if (lex.eatLine()) { if (lex.eatLine()) {
string const token = lex.getString(); scanCommand(lex.getString());
scanCommand(token);
} else { } else {
lex.printError("InsetCommand: Parse error: `$$Token'"); lex.printError("InsetCommand: Parse error: `$$Token'");
} }
@ -235,11 +233,9 @@ vector<string> const InsetBibtex::getFiles(Buffer const & buffer) const
// This method returns a comma separated list of Bibtex entries // This method returns a comma separated list of Bibtex entries
vector<pair<string, string> > const void InsetBibtex::fillWithBibKeys
InsetBibtex::getKeys(Buffer const * buffer) const (Buffer const * buffer, vector<pair<string, string> > & keys) const
{ {
vector<pair<string,string> > keys;
lyx::Assert(buffer); lyx::Assert(buffer);
vector<string> const files = getFiles(*buffer); vector<string> const files = getFiles(*buffer);
for (vector<string>::const_iterator it = files.begin(); for (vector<string>::const_iterator it = files.begin();
@ -271,7 +267,6 @@ vector<pair<string, string> > const
} }
} }
} }
return keys;
} }

View File

@ -93,7 +93,8 @@ public:
int latex(Buffer const *, std::ostream &, int latex(Buffer const *, std::ostream &,
bool fragile, bool freespace) const; bool fragile, bool freespace) const;
/// ///
std::vector<std::pair<string,string> > const getKeys(Buffer const *) const; void fillWithBibKeys(Buffer const *,
std::vector<std::pair<string,string> > &) const;
/// ///
std::vector<string> const getFiles(Buffer const &) const; std::vector<string> const getFiles(Buffer const &) const;
/// ///

View File

@ -66,7 +66,8 @@ string const getNatbibLabel(Buffer const * buffer,
if (loadkeys) { if (loadkeys) {
// build the keylist // build the keylist
typedef vector<std::pair<string, string> > InfoType; typedef vector<std::pair<string, string> > InfoType;
InfoType bibkeys = buffer->getBibkeyList(); InfoType bibkeys;
buffer->fillWithBibKeys(bibkeys);
InfoType::const_iterator bit = bibkeys.begin(); InfoType::const_iterator bit = bibkeys.begin();
InfoType::const_iterator bend = bibkeys.end(); InfoType::const_iterator bend = bibkeys.end();

View File

@ -483,18 +483,14 @@ vector<string> const InsetInclude::getLabelList() const
} }
vector<pair<string,string> > const InsetInclude::getKeys() const void InsetInclude::fillWithBibKeys(vector<pair<string,string> > & keys) const
{ {
vector<pair<string,string> > keys;
if (loadIfNeeded()) { if (loadIfNeeded()) {
Buffer * tmp = bufferlist.getBuffer(getFileName()); Buffer * tmp = bufferlist.getBuffer(getFileName());
tmp->setParentName(""); tmp->setParentName("");
keys = tmp->getBibkeyList(); tmp->fillWithBibKeys(keys);
tmp->setParentName(getMasterFilename()); tmp->setParentName(getMasterFilename());
} }
return keys;
} }

View File

@ -79,7 +79,7 @@ public:
/// This returns the list of labels on the child buffer /// This returns the list of labels on the child buffer
std::vector<string> const getLabelList() const; std::vector<string> const getLabelList() const;
/// This returns the list of bibkeys on the child buffer /// This returns the list of bibkeys on the child buffer
std::vector< std::pair<string,string> > const getKeys() const; void fillWithBibKeys(vector<pair<string,string> > & keys) const;
/// ///
void edit(BufferView *, int x, int y, mouse_button::state button); void edit(BufferView *, int x, int y, mouse_button::state button);
/// ///

View File

@ -1264,14 +1264,13 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
textclass.counters().step("bibitem"); textclass.counters().step("bibitem");
int number = textclass.counters().value("bibitem"); int number = textclass.counters().value("bibitem");
//if (!par->bibkey()) { //if (!par->bibkey()) {
// Inset * inset = new InsetBibKey(InsetCommandParams("bibitem"));
// //par->insertInset(0, inset);
//}
if (par->bibkey()) { if (par->bibkey()) {
par->bibkey()->setCounter(number); par->bibkey()->setCounter(number);
par->params().labelString(layout->labelstring()); par->params().labelString(layout->labelstring());
} }
// else {
// InsetCommandParams p("bibitem");
// par->bibkey() = new InsetBibKey(p);
//}
// In biblio should't be following counters but... // In biblio should't be following counters but...
} else { } else {
string s = layout->labelstring(); string s = layout->labelstring();