This patch removes the hardcoded bibkey handling from paragraph and uses the bibkey inset "stand alone" in the paragraph itself (much like the OptArg inset).
Goal is to remove this hard coded stuff from paragraph.C, not to make bibkey handling nicer. I added a new lfun bibkey-insert and put a correponding item in the Insert Menu. Currently one has still to change the paragraph layout to "Bibliography" which is a nuisance UI-wise but I'd rather change this in a second patch. I think the way would be a proper Bibliography inset like Minipage etc, but I am not sure about it. This loses the ability to auto-number new bibentries, too, but this is easily fixed as far as I can tell. Comments? Andre' -- Those who desire to give up Freedom in order to gain Security, will not have, nor do they deserve, either one. (T. Jefferson)
Index: lib/layouts/scrreprt.layout =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/layouts/scrreprt.layout,v retrieving revision 1.1.1.1 diff -u -p -r1.1.1.1 scrreprt.layout --- lib/layouts/scrreprt.layout 27 Sep 1999 18:44:34 -0000 1.1.1.1 +++ lib/layouts/scrreprt.layout 14 Feb 2003 16:54:40 -0000 @@ -7,12 +7,13 @@ Input scrclass.inc # Modify bibliography -Style Bibliography - TopSep 4 - LabelString Bibliography - - LabelFont - Series Bold - Size Largest - EndFont -End +#NoStyle Bibliography +#Style Bibliography +# TopSep 4 +# LabelString Bibliography +# +# LabelFont +# Series Bold +# Size Largest +# EndFont +#End Index: lib/layouts/stdlists.inc =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/layouts/stdlists.inc,v retrieving revision 1.3 diff -u -p -r1.3 stdlists.inc --- lib/layouts/stdlists.inc 31 May 2000 17:08:11 -0000 1.3 +++ lib/layouts/stdlists.inc 14 Feb 2003 16:54:40 -0000 @@ -93,3 +93,22 @@ Style List EndPreamble End + + + +Style Bibliography + Margin Static + LatexType Bib_Environment + LatexName thebibliography + NextNoIndent 1 + LeftMargin MMN + LabelSep xx + ParSkip 0.0 + ItemSep 0.2 + TopSep 0.7 + BottomSep 0.7 + ParSep 0.3 + Align Block + AlignPossible Block, Left + LabelType Counter_EnumI +End Index: lib/layouts/stdstruct.inc =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/layouts/stdstruct.inc,v retrieving revision 1.2 diff -u -p -r1.2 stdstruct.inc --- lib/layouts/stdstruct.inc 20 Mar 2000 14:49:53 -0000 1.2 +++ lib/layouts/stdstruct.inc 14 Feb 2003 16:54:40 -0000 @@ -42,7 +42,7 @@ End # Bibliography style definition Style Bibliography Margin First_Dynamic - LatexType Item_Environment + LatexType Bib_Environment LatexName thebibliography NextNoIndent 1 LeftMargin MM Index: lib/ui/default.ui =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/ui/default.ui,v retrieving revision 1.108 diff -u -p -r1.108 default.ui --- lib/ui/default.ui 8 Feb 2003 19:17:41 -0000 1.108 +++ lib/ui/default.ui 14 Feb 2003 16:54:40 -0000 @@ -201,6 +201,7 @@ Menuset Item "Footnote|F" "footnote-insert" Item "Marginal Note|M" "marginalnote-insert" Item "Short Title" "optional-insert" + Item "Bibliography Key" "bibkey-insert" Item "Index Entry...|I" "index-insert" Item "URL...|U" "url-insert" Item "Note|N" "note-insert" Index: src/LyXAction.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/LyXAction.C,v retrieving revision 1.146 diff -u -p -r1.146 LyXAction.C --- src/LyXAction.C 13 Feb 2003 16:52:19 -0000 1.146 +++ src/LyXAction.C 14 Feb 2003 16:54:40 -0000 @@ -245,6 +245,8 @@ void LyXAction::init() Noop }, { LFUN_INSET_OPTARG, "optional-insert", N_("Insert Optional Argument"), Noop }, + { LFUN_INSERT_BIBKEY, "bibkey-insert", N_("Insert Bibliography Key"), + Noop }, { LFUN_LANGUAGE, "language", N_("Change language"), Noop }, { LFUN_LATEX_LOG, "latex-view-log", N_("View LaTeX log"), ReadOnly }, Index: src/buffer.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.C,v retrieving revision 1.405 diff -u -p -r1.405 buffer.C --- src/buffer.C 14 Feb 2003 02:20:59 -0000 1.405 +++ src/buffer.C 14 Feb 2003 16:54:40 -0000 @@ -959,6 +959,12 @@ Buffer::parseSingleLyXformat2Token(LyXLe inset->read(this, lex); par->insertInset(pos, inset, font, current_change); ++pos; + } else if (token == "\\bibitem") { // ale970302 + InsetCommandParams p("bibitem", "dummy"); + InsetBibKey * inset = new InsetBibKey(p); + inset->read(this, lex); + par->insertInset(pos, inset, font, current_change); + ++pos; } else if (token == "\\hfill") { par->insertChar(pos, Paragraph::META_HFILL, font, current_change); ++pos; @@ -983,12 +989,6 @@ Buffer::parseSingleLyXformat2Token(LyXLe istr >> aid; istr >> ct; current_change = Change(Change::DELETED, author_ids[aid], ct); - } else if (token == "\\bibitem") { // ale970302 - if (!par->bibkey) { - InsetCommandParams p("bibitem", "dummy"); - par->bibkey = new InsetBibKey(p); - } - par->bibkey->read(this, lex); } else if (token == "\\the_end") { the_end_read = true; } else { @@ -2419,6 +2419,7 @@ void Buffer::makeLinuxDocFile(string con case LATEX_ENVIRONMENT: case LATEX_ITEM_ENVIRONMENT: + case LATEX_BIB_ENVIRONMENT: { string const & latexname = style->latexname(); @@ -2473,6 +2474,7 @@ void Buffer::makeLinuxDocFile(string con break; case LATEX_ENVIRONMENT: case LATEX_ITEM_ENVIRONMENT: + case LATEX_BIB_ENVIRONMENT: if (style->latexparam() == "CDATA") ofs << "]]>"; break; @@ -3270,9 +3272,10 @@ vector<pair<string, string> > const Buff ParagraphList::iterator pit = paragraphs.begin(); ParagraphList::iterator pend = paragraphs.end(); for (; pit != pend; ++pit) { - if (pit->bibkey) { - string const key = pit->bibkey->getContents(); - string const opt = pit->bibkey->getOptions(); + InsetBibKey * bib = pit->bibkey(); + if (bib) { + string const key = bib->getContents(); + string const opt = bib->getOptions(); string const ref = pit->asString(this, false); string const info = opt + "TheBibliographyRef" + ref; Index: src/commandtags.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/commandtags.h,v retrieving revision 1.105 diff -u -p -r1.105 commandtags.h --- src/commandtags.h 8 Feb 2003 19:17:44 -0000 1.105 +++ src/commandtags.h 14 Feb 2003 16:54:40 -0000 @@ -296,6 +296,7 @@ enum kb_action { LFUN_REJECT_CHANGE, // Levon 20021016 LFUN_ACCEPT_ALL_CHANGES, // Levon 20021016 LFUN_REJECT_ALL_CHANGES, // Levon 20021016 + LFUN_INSERT_BIBKEY, // André 14 Feb 2003 LFUN_LASTACTION /* this marks the end of the table */ }; Index: src/factory.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/factory.C,v retrieving revision 1.10 diff -u -p -r1.10 factory.C --- src/factory.C 31 Jan 2003 13:50:20 -0000 1.10 +++ src/factory.C 14 Feb 2003 16:54:40 -0000 @@ -18,6 +18,7 @@ #include "BufferView.h" #include "lyxtext.h" +#include "insets/insetbib.h" #include "insets/insetcaption.h" #include "insets/insetert.h" #include "insets/insetexternal.h" @@ -69,6 +70,9 @@ Inset * createInset(FuncRequest const & case LFUN_INSET_OPTARG: return new InsetOptArg(params); + + case LFUN_INSERT_BIBKEY: + return new InsetBibKey(InsetCommandParams("bibkey")); case LFUN_INSET_FLOAT: // check if the float type exists Index: src/layout.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/layout.h,v retrieving revision 1.41 diff -u -p -r1.41 layout.h --- src/layout.h 13 Feb 2003 17:49:09 -0000 1.41 +++ src/layout.h 14 Feb 2003 16:54:40 -0000 @@ -76,6 +76,8 @@ enum LYX_LATEX_TYPES { /// LATEX_ITEM_ENVIRONMENT, /// + LATEX_BIB_ENVIRONMENT, + /// LATEX_LIST_ENVIRONMENT }; Index: src/lyxlayout.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxlayout.C,v retrieving revision 1.11 diff -u -p -r1.11 lyxlayout.C --- src/lyxlayout.C 13 Feb 2003 16:52:33 -0000 1.11 +++ src/lyxlayout.C 14 Feb 2003 16:54:40 -0000 @@ -680,6 +680,7 @@ void LyXLayout::readMargin(LyXLex & lexr void LyXLayout::readLatexType(LyXLex & lexrc) { keyword_item latexTypeTags[] = { + { "bib_environment", LATEX_BIB_ENVIRONMENT }, { "command", LATEX_COMMAND }, { "environment", LATEX_ENVIRONMENT }, { "item_environment", LATEX_ITEM_ENVIRONMENT }, @@ -697,6 +698,7 @@ void LyXLayout::readLatexType(LyXLex & l case LATEX_COMMAND: case LATEX_ENVIRONMENT: case LATEX_ITEM_ENVIRONMENT: + case LATEX_BIB_ENVIRONMENT: case LATEX_LIST_ENVIRONMENT: latextype = static_cast<LYX_LATEX_TYPES>(le); break; Index: src/lyxlayout.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxlayout.h,v retrieving revision 1.7 diff -u -p -r1.7 lyxlayout.h --- src/lyxlayout.h 13 Feb 2003 16:52:33 -0000 1.7 +++ src/lyxlayout.h 14 Feb 2003 16:54:40 -0000 @@ -177,6 +177,7 @@ public: /// bool isEnvironment() const { return (latextype == LATEX_ENVIRONMENT + || latextype == LATEX_BIB_ENVIRONMENT || latextype == LATEX_ITEM_ENVIRONMENT || latextype == LATEX_LIST_ENVIRONMENT); } Index: src/paragraph.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.C,v retrieving revision 1.240 diff -u -p -r1.240 paragraph.C --- src/paragraph.C 14 Feb 2003 02:20:59 -0000 1.240 +++ src/paragraph.C 14 Feb 2003 16:54:41 -0000 @@ -78,7 +78,6 @@ Paragraph::Paragraph() #endif enumdepth = 0; itemdepth = 0; - bibkey = 0; // ale970302 params().clear(); } @@ -99,7 +98,6 @@ Paragraph::Paragraph(Paragraph * par) previous_->next_ = this; // end - bibkey = 0; // ale970302 params().clear(); } #endif @@ -118,14 +116,6 @@ Paragraph::Paragraph(Paragraph const & l // follow footnotes layout_ = lp.layout(); - // ale970302 - if (lp.bibkey) { - bibkey = static_cast<InsetBibKey *> - (lp.bibkey->clone(*current_view->buffer())); - } else { - bibkey = 0; - } - // copy everything behind the break-position to the new paragraph insetlist = lp.insetlist; InsetList::iterator it = insetlist.begin(); @@ -149,9 +139,6 @@ Paragraph::~Paragraph() next_->previous_ = previous_; #endif - // ale970302 - delete bibkey; - delete pimpl_; // //lyxerr << "Paragraph::paragraph_id = " @@ -234,10 +221,6 @@ void Paragraph::write(Buffer const * buf os << "\\align " << string_align[h] << ' '; } - // bibitem ale970302 - if (bibkey) - bibkey->write(buf, os); - LyXFont font1(LyXFont::ALL_INHERIT, bparams.language); Change running_change = Change(Change::UNCHANGED); @@ -952,17 +935,21 @@ int Paragraph::getPositionOfInset(Inset // Find the entry. InsetList::iterator it = insetlist.begin(); InsetList::iterator end = insetlist.end(); - for (; it != end; ++it) { - if (it.getInset() == inset) { + for (; it != end; ++it) + if (it.getInset() == inset) return it.getPos(); - } - } - if (inset == bibkey) - return 0; - return -1; } + +InsetBibKey * Paragraph::bibkey() +{ + InsetList::iterator it = insetlist.begin(); + if (it != insetlist.end() && it.getInset()->lyxCode() == Inset::BIBTEX_CODE) + return static_cast<InsetBibKey *>(it.getInset()); + return 0; +} + namespace { InsetOptArg * optArgInset(Paragraph const & par) @@ -1079,26 +1066,23 @@ Paragraph * Paragraph::TeXOnePar(Buffer switch (style->latextype) { case LATEX_COMMAND: - os << '\\' - << style->latexname(); + os << '\\' << style->latexname(); // Separate handling of optional argument inset. if (style->optionalargs == 1) { InsetOptArg * it = optArgInset(*this); - if (it != 0) + if (it) it->latexOptional(buf, os, false, false); } else os << style->latexparam(); break; case LATEX_ITEM_ENVIRONMENT: - if (bibkey) { - bibkey->latex(buf, os, false, false); - } else - os << "\\item "; - break; case LATEX_LIST_ENVIRONMENT: os << "\\item "; + break; + case LATEX_BIB_ENVIRONMENT: + // ignore this, the inset will write itself break; default: break; Index: src/paragraph.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.h,v retrieving revision 1.54 diff -u -p -r1.54 paragraph.h --- src/paragraph.h 14 Feb 2003 02:21:00 -0000 1.54 +++ src/paragraph.h 14 Feb 2003 16:54:41 -0000 @@ -151,7 +151,7 @@ public: char itemdepth; /// - InsetBibKey * bibkey; // ale970302 + InsetBibKey * bibkey(); // ale970302 #ifndef NO_NEXT /// Index: src/paragraph_funcs.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph_funcs.C,v retrieving revision 1.8 diff -u -p -r1.8 paragraph_funcs.C --- src/paragraph_funcs.C 8 Feb 2003 19:17:47 -0000 1.8 +++ src/paragraph_funcs.C 14 Feb 2003 16:54:41 -0000 @@ -97,9 +97,6 @@ void breakParagraph(BufferParams const & tmp->params().lineTop(par->params().lineTop()); tmp->params().pagebreakTop(par->params().pagebreakTop()); tmp->params().spaceTop(par->params().spaceTop()); - tmp->bibkey = par->bibkey; - - par->bibkey = 0; par->params().clear(); par->layout(bparams.getLyXTextClass().defaultLayout()); Index: src/text.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v retrieving revision 1.287 diff -u -p -r1.287 text.C --- src/text.C 14 Feb 2003 00:41:40 -0000 1.287 +++ src/text.C 14 Feb 2003 16:54:41 -0000 @@ -3462,6 +3462,7 @@ void LyXText::paintFirstRow(DrawRowParam } } +#if 0 if (layout->labeltype == LABEL_BIBLIO && par->bibkey) { LyXFont font = getLayoutFont(buffer, par); float x; @@ -3474,6 +3475,7 @@ void LyXText::paintFirstRow(DrawRowParam } par->bibkey->draw(p.bv, font, p.yo + p.row->baseline(), x, p.cleared); } +#endif } Index: src/text2.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v retrieving revision 1.273 diff -u -p -r1.273 text2.C --- src/text2.C 14 Feb 2003 00:41:43 -0000 1.273 +++ src/text2.C 14 Feb 2003 16:54:41 -0000 @@ -368,14 +368,11 @@ void LyXText::insertParagraph(BufferView Inset * LyXText::getInset() const { - Inset * inset = 0; - if (cursor.pos() == 0 && cursor.par()->bibkey) { - inset = cursor.par()->bibkey; - } else if (cursor.pos() < cursor.par()->size() + if (cursor.pos() < cursor.par()->size() && cursor.par()->isInset(cursor.pos())) { - inset = cursor.par()->getInset(cursor.pos()); + return cursor.par()->getInset(cursor.pos()); } - return inset; + return 0; } @@ -471,11 +468,6 @@ Paragraph * LyXText::setLayout(BufferVie : VSpace(VSpace::NONE)); if (lyxlayout->margintype == MARGIN_MANUAL) par->setLabelWidthString(lyxlayout->labelstring()); - if (lyxlayout->labeltype != LABEL_BIBLIO - && fppar->bibkey) { - delete fppar->bibkey; - fppar->bibkey = 0; - } cur.par(par); par = par->next(); } while (par != epar); @@ -1271,13 +1263,15 @@ void LyXText::setCounter(Buffer const * } else if (layout->labeltype == LABEL_BIBLIO) {// ale970302 textclass.counters().step("bibitem"); int number = textclass.counters().value("bibitem"); - if (!par->bibkey) { - InsetCommandParams p("bibitem"); - par->bibkey = new InsetBibKey(p); - } - par->bibkey->setCounter(number); - par->params().labelString(layout->labelstring()); - + //if (!par->bibkey()) { + 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(); Index: src/text3.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v retrieving revision 1.30 diff -u -p -r1.30 text3.C --- src/text3.C 14 Feb 2003 00:41:43 -0000 1.30 +++ src/text3.C 14 Feb 2003 16:54:41 -0000 @@ -1551,6 +1551,7 @@ Inset::RESULT LyXText::dispatch(FuncRequ } // Maybe we want to edit a bibitem ale970302 +/* if (bv->text->cursor.par()->bibkey) { bool const is_rtl = bv->text->cursor.par()->isRightToLeftPar(bv->buffer()->params); @@ -1561,6 +1562,7 @@ Inset::RESULT LyXText::dispatch(FuncRequ bv->text->cursor.par()->bibkey->edit(bv, 0, 0, mouse_button::none); } } +*/ break; } @@ -1621,6 +1623,7 @@ Inset::RESULT LyXText::dispatch(FuncRequ case LFUN_INSET_CAPTION: #endif case LFUN_INSERT_NOTE: + case LFUN_INSERT_BIBKEY: case LFUN_INSET_ERT: case LFUN_INSET_FLOAT: case LFUN_INSET_FOOTNOTE: Index: src/insets/insetbib.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetbib.C,v retrieving revision 1.98 diff -u -p -r1.98 insetbib.C --- src/insets/insetbib.C 13 Feb 2003 16:53:01 -0000 1.98 +++ src/insets/insetbib.C 14 Feb 2003 16:54:41 -0000 @@ -76,11 +76,9 @@ void InsetBibKey::setCounter(int c) // of time cause LyX3 won't use lyxlex anyway. (ale) void InsetBibKey::write(Buffer const *, ostream & os) const { - os << "\\bibitem "; - if (! getOptions().empty()) { - os << '[' - << getOptions() << ']'; - } + os << "\n\\layout Bibliography\n\\bibitem "; + if (! getOptions().empty()) + os << '[' << getOptions() << ']'; os << '{' << getContents() << "}\n"; } @@ -336,8 +334,8 @@ int bibitemMaxWidth(BufferView * bv, LyX ParagraphList::iterator it = bv->buffer()->paragraphs.begin(); ParagraphList::iterator end = bv->buffer()->paragraphs.end(); for (; it != end; ++it) { - if (it->bibkey) { - int const wx = it->bibkey->width(bv, font); + if (it->bibkey()) { + int const wx = it->bibkey()->width(bv, font); if (wx > w) w = wx; } @@ -358,13 +356,13 @@ string const bibitemWidest(Buffer const ParagraphList::iterator it = buffer->paragraphs.begin(); ParagraphList::iterator end = buffer->paragraphs.end(); for (; it != end; ++it) { - if (it->bibkey) { + if (it->bibkey()) { int const wx = - font_metrics::width(it->bibkey->getBibLabel(), + font_metrics::width(it->bibkey()->getBibLabel(), font); if (wx > w) { w = wx; - bkey = it->bibkey; + bkey = it->bibkey(); } } } Index: src/insets/insetbib.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetbib.h,v retrieving revision 1.48 diff -u -p -r1.48 insetbib.h --- src/insets/insetbib.h 13 Feb 2003 16:53:01 -0000 1.48 +++ src/insets/insetbib.h 14 Feb 2003 16:54:41 -0000 @@ -46,9 +46,11 @@ public: /// EDITABLE editable() const { return IS_EDITABLE; } /// A user can't neither insert nor delete this inset - bool deletable() const { - return false; - } + //bool deletable() const { + // return false; + //} + /// keep .lyx format compatible + bool directWrite() const { return true; } /// void setCounter(int); /// Index: src/mathed/math_parser.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_parser.C,v retrieving revision 1.260 diff -u -p -r1.260 math_parser.C --- src/mathed/math_parser.C 13 Feb 2003 16:53:12 -0000 1.260 +++ src/mathed/math_parser.C 14 Feb 2003 16:54:41 -0000 @@ -744,11 +744,6 @@ void Parser::parse1(MathGridInset & grid else cell->back() = MathAtom(new MathScriptInset(cell->back(), up)); MathScriptInset * p = cell->back().nucleus()->asScriptInset(); - // special handling of {}-bases - // is this always correct? - if (p->nuc().size() == 1 && p->nuc().back()->asNestInset() && - p->nuc().back()->extraBraces()) - p->nuc() = p->nuc().back()->asNestInset()->cell(0); parse(p->cell(up), FLAG_ITEM, mode); if (limits) { p->limits(limits);