From: André Pönitz Date: Mon, 17 Feb 2003 15:16:14 +0000 (+0000) Subject: remove the hardcoded bibkey from the paragraph X-Git-Tag: 1.6.10~17494 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=305c04ba8bf3dd6797da1adff4972c4f384c9071;p=features.git remove the hardcoded bibkey from the paragraph git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6186 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/lib/ChangeLog b/lib/ChangeLog index f7f99f27be..fd25104fab 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,8 @@ + +2003-02-17 André Pönitz + + * lauouts/*: Item_Environment -> Bib_Environment for Bibligraphy + 2003-02-14 Jean-Marc Lasgouttes * chkconfig.ltx: information is in LaTeXConfig.lyx, not diff --git a/lib/layouts/amsdefs.inc b/lib/layouts/amsdefs.inc index 9016a21138..2ac633f12e 100644 --- a/lib/layouts/amsdefs.inc +++ b/lib/layouts/amsdefs.inc @@ -337,7 +337,7 @@ End # Bibliography style definition Style Bibliography Margin First_Dynamic - LatexType Item_Environment + LatexType Bib_Environment LatexName thebibliography NextNoIndent 1 LeftMargin MM diff --git a/lib/layouts/cl2emult.layout b/lib/layouts/cl2emult.layout index f19d10cb66..098f786918 100644 --- a/lib/layouts/cl2emult.layout +++ b/lib/layouts/cl2emult.layout @@ -104,7 +104,7 @@ End # Bibliography style definition Style Bibliography Margin First_Dynamic - LatexType Item_Environment + LatexType Bib_Environment LatexName thebibliography NextNoIndent 1 LeftMargin MM diff --git a/lib/layouts/egs.layout b/lib/layouts/egs.layout index 3b85cec3d0..ab3e72fa8a 100644 --- a/lib/layouts/egs.layout +++ b/lib/layouts/egs.layout @@ -642,7 +642,7 @@ End # Bibliography style definition Style Bibliography Margin First_Dynamic - LatexType Item_Environment + LatexType Bib_Environment LatexName thebibliography NextNoIndent 1 LeftMargin MM diff --git a/lib/layouts/llncs.layout b/lib/layouts/llncs.layout index 098a5a7cff..cc3255f338 100644 --- a/lib/layouts/llncs.layout +++ b/lib/layouts/llncs.layout @@ -288,7 +288,7 @@ End # Bibliography style definition Style Bibliography Margin First_Dynamic - LatexType Item_Environment + LatexType Bib_Environment LatexName thebibliography NextNoIndent 1 LeftMargin MM diff --git a/lib/layouts/siamltex.layout b/lib/layouts/siamltex.layout index cdc570444a..902dd147d6 100644 --- a/lib/layouts/siamltex.layout +++ b/lib/layouts/siamltex.layout @@ -170,7 +170,7 @@ End Style Bibliography Margin Dynamic - LatexType Item_Environment + LatexType Bib_Environment LatexName thebibliography NextNoIndent 0 LeftMargin M diff --git a/lib/layouts/stdlists.inc b/lib/layouts/stdlists.inc index bac13bf5a4..1ec9ac8caf 100644 --- a/lib/layouts/stdlists.inc +++ b/lib/layouts/stdlists.inc @@ -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 diff --git a/lib/layouts/stdstruct.inc b/lib/layouts/stdstruct.inc index 864af1efa8..e3e8775a44 100644 --- a/lib/layouts/stdstruct.inc +++ b/lib/layouts/stdstruct.inc @@ -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 diff --git a/lib/layouts/svjour.inc b/lib/layouts/svjour.inc index aaf61738a4..aca732ed06 100644 --- a/lib/layouts/svjour.inc +++ b/lib/layouts/svjour.inc @@ -352,7 +352,7 @@ End # Bibliography style definition Style Bibliography Margin First_Dynamic - LatexType Item_Environment + LatexType Bib_Environment LatexName thebibliography NextNoIndent 1 LeftMargin MM diff --git a/lib/ui/default.ui b/lib/ui/default.ui index 82bd514003..35c4e0ac70 100644 --- a/lib/ui/default.ui +++ b/lib/ui/default.ui @@ -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" diff --git a/src/ChangeLog b/src/ChangeLog index 5da311d596..acf1324d92 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,7 +1,23 @@ + +2003-02-17 André Pönitz + + * LyXAction.C: + * commandtags.h: new LFUN_INSERT_BIBKEY + + * layout.h: + * lyxlayout.C: + * buffer.C: + * factory.C: + * text.C: + * text2.C: + * text3.C: + * paragraph.[Ch]: + * paragraph_func.C: remove special bibkey handling + 2003-02-17 John Levon * text.C (Delete): fix case where delete at the end of - the very first paragraph would not merge the pars + the very first paragraph would not merge the pars 2003-02-17 John Levon @@ -744,7 +760,7 @@ 2002-10-11 André Pönitz - * lytext.h: make some functions public to allow access + * lyxtext.h: make some functions public to allow access from inset/lyxtext for handling LFUN_PRIOR/NEXT 2002-10-09 Jean-Marc Lasgouttes diff --git a/src/LyXAction.C b/src/LyXAction.C index 2803a45457..47b279a57e 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -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 }, diff --git a/src/buffer.C b/src/buffer.C index 90c08043ca..53113abb48 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -956,6 +956,12 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par, 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; @@ -980,12 +986,6 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par, 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 { @@ -2034,6 +2034,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only) case LATEX_ENVIRONMENT: case LATEX_ITEM_ENVIRONMENT: + case LATEX_BIB_ENVIRONMENT: { string const & latexname = style->latexname(); @@ -2088,6 +2089,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only) break; case LATEX_ENVIRONMENT: case LATEX_ITEM_ENVIRONMENT: + case LATEX_BIB_ENVIRONMENT: if (style->latexparam() == "CDATA") ofs << "]]>"; break; @@ -2885,9 +2887,10 @@ vector > const Buffer::getBibkeyList() const 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; diff --git a/src/commandtags.h b/src/commandtags.h index 6fd422aee0..7ccc3ac889 100644 --- a/src/commandtags.h +++ b/src/commandtags.h @@ -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 */ }; diff --git a/src/factory.C b/src/factory.C index 3509bc8150..601f72684c 100644 --- a/src/factory.C +++ b/src/factory.C @@ -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" @@ -70,6 +71,9 @@ Inset * createInset(FuncRequest const & cmd) 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 if (params.getLyXTextClass().floats().typeExist(cmd.argument)) diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index f66d33b73e..2d76fbb2aa 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,8 @@ + +2003-02-17 André Pönitz + + * insetbib.[Ch]: Adjust access to bibkeys + 2003-02-14 Jean-Marc Lasgouttes * insetquotes.C (dispString): remove use of acute accent for "'" diff --git a/src/insets/insetbib.C b/src/insets/insetbib.C index 77ec9d52f6..e77956c59b 100644 --- a/src/insets/insetbib.C +++ b/src/insets/insetbib.C @@ -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, LyXFont const & font) 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 * buffer) 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(); } } } diff --git a/src/insets/insetbib.h b/src/insets/insetbib.h index 5c4b92ed99..d037e829a4 100644 --- a/src/insets/insetbib.h +++ b/src/insets/insetbib.h @@ -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); /// diff --git a/src/layout.h b/src/layout.h index 637a059a61..82ca677af3 100644 --- a/src/layout.h +++ b/src/layout.h @@ -76,6 +76,8 @@ enum LYX_LATEX_TYPES { /// LATEX_ITEM_ENVIRONMENT, /// + LATEX_BIB_ENVIRONMENT, + /// LATEX_LIST_ENVIRONMENT }; diff --git a/src/lyxlayout.C b/src/lyxlayout.C index 6533fe3051..80e280b157 100644 --- a/src/lyxlayout.C +++ b/src/lyxlayout.C @@ -680,6 +680,7 @@ void LyXLayout::readMargin(LyXLex & lexrc) 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 & lexrc) case LATEX_COMMAND: case LATEX_ENVIRONMENT: case LATEX_ITEM_ENVIRONMENT: + case LATEX_BIB_ENVIRONMENT: case LATEX_LIST_ENVIRONMENT: latextype = static_cast(le); break; diff --git a/src/lyxlayout.h b/src/lyxlayout.h index 7e1f10b808..1aafb4a114 100644 --- a/src/lyxlayout.h +++ b/src/lyxlayout.h @@ -177,6 +177,7 @@ public: /// bool isEnvironment() const { return (latextype == LATEX_ENVIRONMENT + || latextype == LATEX_BIB_ENVIRONMENT || latextype == LATEX_ITEM_ENVIRONMENT || latextype == LATEX_LIST_ENVIRONMENT); } diff --git a/src/paragraph.C b/src/paragraph.C index 4e99c73185..0a082a5eb2 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -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 & lp, bool same_ids) // follow footnotes layout_ = lp.layout(); - // ale970302 - if (lp.bibkey) { - bibkey = static_cast - (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, ostream & os, 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 const * inset) const // 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(it.getInset()); + return 0; +} + namespace { InsetOptArg * optArgInset(Paragraph const & par) @@ -1079,27 +1066,24 @@ Paragraph * Paragraph::TeXOnePar(Buffer const * buf, 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; } diff --git a/src/paragraph.h b/src/paragraph.h index 7b749821c5..75e8097f32 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -151,7 +151,7 @@ public: char itemdepth; /// - InsetBibKey * bibkey; // ale970302 + InsetBibKey * bibkey(); // ale970302 #ifndef NO_NEXT /// diff --git a/src/paragraph_funcs.C b/src/paragraph_funcs.C index 18e6855c76..d9a2a41835 100644 --- a/src/paragraph_funcs.C +++ b/src/paragraph_funcs.C @@ -97,9 +97,6 @@ void breakParagraph(BufferParams const & bparams, 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()); diff --git a/src/text.C b/src/text.C index 4113ae75ac..b8dae41293 100644 --- a/src/text.C +++ b/src/text.C @@ -3455,19 +3455,6 @@ void LyXText::paintFirstRow(DrawRowParams & p) str, font); } } - - if (layout->labeltype == LABEL_BIBLIO && par->bibkey) { - LyXFont font = getLayoutFont(buffer, par); - float x; - if (is_rtl) { - x = ww - leftMargin(p.bv, p.row) - + font_metrics::width(layout->labelsep, font); - } else { - x = p.x - font_metrics::width(layout->labelsep, font) - - par->bibkey->width(p.bv, font); - } - par->bibkey->draw(p.bv, font, p.yo + p.row->baseline(), x, p.cleared); - } } diff --git a/src/text2.C b/src/text2.C index e6b21acb19..50030c4d52 100644 --- a/src/text2.C +++ b/src/text2.C @@ -368,14 +368,11 @@ void LyXText::insertParagraph(BufferView * bview, Paragraph * par, 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(BufferView * bview, : 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 * buf, Paragraph * par) 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); + //if (!par->bibkey()) { + if (par->bibkey()) { + par->bibkey()->setCounter(number); + par->params().labelString(layout->labelstring()); } - 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(); diff --git a/src/text3.C b/src/text3.C index 0a0e083c8b..5dacb94186 100644 --- a/src/text3.C +++ b/src/text3.C @@ -1538,7 +1538,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd) } else { FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button()); inset_hit->localDispatch(cmd1); - // IMO this is a grosshack! Inset's should be changed so that + // IMO this is a gross hack! Insets should be changed so that // they call the actions they have to do with the insetButtonRel. // function and not in the edit(). This should be changed // (Jug 20020329) @@ -1550,17 +1550,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd) break; } - // 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); - int const width = - bibitemMaxWidth(bv, bv->buffer()->params.getLyXTextClass().defaultfont()); - if ((is_rtl && x > bv->text->workWidth(bv)-20-width) || - (!is_rtl && x < 20 + width)) { - bv->text->cursor.par()->bibkey->edit(bv, 0, 0, mouse_button::none); - } - } break; } @@ -1621,6 +1610,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd) 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: