* Split insetbib.[Ch] into insetbibitem.[Ch] and insetbibtex.[Ch].

* Rename bibkey as bibitem.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6217 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2003-02-21 09:20:18 +00:00
parent c527376d4f
commit 759dcbb427
21 changed files with 294 additions and 235 deletions

View File

@ -1,3 +1,7 @@
2003-02-21 Angus Leeming <leeming@lyx.org>
* ui/default.ui: change bibkey-insert to bibtem-insert.
2003-02-18 Juergen Spitzmueller <j.spitzmueller@gmx.de>
* layouts/scrclass.inc:

View File

@ -201,7 +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 "Bibliography Key" "bibitem-insert"
Item "Index Entry...|I" "index-insert"
Item "URL...|U" "url-insert"
Item "Note|N" "note-insert"

View File

@ -40,17 +40,17 @@
#include "iterators.h"
#include "lyxfind.h"
#include "insets/insetbib.h"
#include "insets/insettext.h"
#include "insets/insetlatexaccent.h"
#include "insets/insettoc.h"
#include "insets/insetindex.h"
#include "insets/insetref.h"
#include "insets/insetinclude.h"
#include "insets/insetbibtex.h"
#include "insets/insetcite.h"
#include "insets/insetgraphics.h"
#include "insets/insetmarginal.h"
#include "insets/insetfloatlist.h"
#include "insets/insetgraphics.h"
#include "insets/insetinclude.h"
#include "insets/insetindex.h"
#include "insets/insetlatexaccent.h"
#include "insets/insetmarginal.h"
#include "insets/insetref.h"
#include "insets/insettext.h"
#include "insets/insettoc.h"
#include "mathed/formulabase.h"

View File

@ -1,3 +1,22 @@
2003-02-21 Angus Leeming <leeming@lyx.org>
* BufferView_pimpl.C: replace insetbib.h with insetbibtex.h.
* LyXAction.C: change, BIBKEY to BIBITEM.
* buffer.C: replace insetbib.h with insetbibitem.h and insetbibtex.h.
Change InsetBibKey to InsetBibitem.
Change BIBKEY_CODE to BIBITEM_CODE.
* commandtags.h: change LFUN_INSERT_BIBKEY to LFUN_INSERT_BIBITEM.
* factory.C: replace insetbib.h with insetbibitem.h.
Change LFUN_INSERT_BIBKEY to LFUN_INSERT_BIBITEM.
* paragraph.C: replace insetbib.h with insetbibitem.h.
* paragraph.[Ch]: change InsetBibKey to InsetBibitem.
Change bibkey() to bibitem().
* text.C: remove insetbib.h.
* text2.C: replace insetbib.h with insetbibitem.h.
change bibkey() to bibitem().
* text3.C: remove insetbib.h.
change LFUN_INSERT_BIBKEY to LFUN_INSERT_BIBITEM.
2003-02-18 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* lyxrc.C (output): enclose user email in quotes (in case there are

View File

@ -245,7 +245,7 @@ void LyXAction::init()
Noop },
{ LFUN_INSET_OPTARG, "optional-insert", N_("Insert Optional Argument"),
Noop },
{ LFUN_INSERT_BIBKEY, "bibkey-insert", N_("Insert Bibliography Key"),
{ LFUN_INSERT_BIBITEM, "bibitem-insert", N_("Insert Bibliography Key"),
Noop },
{ LFUN_LANGUAGE, "language", N_("Change language"), Noop },
{ LFUN_LATEX_LOG, "latex-view-log", N_("View LaTeX log"),

View File

@ -55,7 +55,8 @@
#include "insets/insetnote.h"
#include "insets/insetquotes.h"
#include "insets/insetlatexaccent.h"
#include "insets/insetbib.h"
#include "insets/insetbibitem.h"
#include "insets/insetbibtex.h"
#include "insets/insetcite.h"
#include "insets/insetexternal.h"
#include "insets/insetindex.h"
@ -958,7 +959,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
++pos;
} else if (token == "\\bibitem") { // ale970302
InsetCommandParams p("bibitem", "dummy");
InsetBibKey * inset = new InsetBibKey(p);
InsetBibitem * inset = new InsetBibitem(p);
inset->read(this, lex);
par->insertInset(pos, inset, font, current_change);
++pos;
@ -1099,7 +1100,7 @@ void Buffer::readInset(LyXLex & lex, Paragraph *& par,
inset = new InsetCitation(inscmd);
} else if (cmdName == "bibitem") {
lex.printError("Wrong place for bibitem");
inset = new InsetBibKey(inscmd);
inset = new InsetBibitem(inscmd);
} else if (cmdName == "BibTeX") {
inset = new InsetBibtex(inscmd);
} else if (cmdName == "index") {
@ -2890,8 +2891,8 @@ void Buffer::fillWithBibKeys(vector<pair<string, string> > & keys) const
static_cast<InsetBibtex &>(*it).fillWithBibKeys(this, keys);
else if (it->lyxCode() == Inset::INCLUDE_CODE)
static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
else if (it->lyxCode() == Inset::BIBKEY_CODE) {
InsetBibKey & bib = static_cast<InsetBibKey &>(*it);
else if (it->lyxCode() == Inset::BIBITEM_CODE) {
InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
string const key = bib.getContents();
string const opt = bib.getOptions();
string const ref; // = pit->asString(this, false);

View File

@ -296,7 +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_INSERT_BIBITEM, // André 14 Feb 2003
LFUN_LASTACTION /* this marks the end of the table */
};

View File

@ -18,7 +18,7 @@
#include "BufferView.h"
#include "lyxtext.h"
#include "insets/insetbib.h"
#include "insets/insetbibitem.h"
#include "insets/insetcaption.h"
#include "insets/insetert.h"
#include "insets/insetexternal.h"
@ -71,8 +71,8 @@ Inset * createInset(FuncRequest const & cmd)
case LFUN_INSET_OPTARG:
return new InsetOptArg(params);
case LFUN_INSERT_BIBKEY:
return new InsetBibKey(InsetCommandParams("bibkey"));
case LFUN_INSERT_BIBITEM:
return new InsetBibitem(InsetCommandParams("bibitem"));
case LFUN_INSET_FLOAT:
// check if the float type exists

View File

@ -1,3 +1,7 @@
2003-02-21 Angus Leeming <leeming@lyx.org>
* Dialogs.h: remove forward declarations of InsetBibKey, InsetBibtex.
2003-02-14 John Levon <levon@movementarian.org>
* LyXView.h: prohibit/allowInput() -> busy(bool)

View File

@ -20,8 +20,6 @@
#include <boost/signals/signal1.hpp>
class LyXView;
class InsetBibKey;
class InsetBibtex;
class InsetCommand;
class InsetError;
class InsetERT;

View File

@ -19,8 +19,10 @@ libinsets_la_SOURCES = \
inset.h \
insetbase.h \
insetbase.C \
insetbib.C \
insetbib.h \
insetbibitem.C \
insetbibitem.h \
insetbibtex.C \
insetbibtex.h \
insetbutton.C \
insetbutton.h \
insetcaption.C \

View File

@ -84,6 +84,8 @@ public:
///
PARENT_CODE,
///
BIBITEM_CODE,
///
BIBTEX_CODE,
///
TEXT_CODE,
@ -122,9 +124,7 @@ public:
///
INDEX_PRINT_CODE,
///
OPTARG_CODE,
///
BIBKEY_CODE
OPTARG_CODE
};
///

152
src/insets/insetbibitem.C Normal file
View File

@ -0,0 +1,152 @@
/**
* \file insetbibitem.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Alejandro Aguilar Sierra
*
* Full author contact details are available in file CREDITS
*/
#include <config.h>
#include "insetbibitem.h"
#include "buffer.h"
#include "BufferView.h"
#include "lyxlex.h"
#include "frontends/font_metrics.h"
#include "frontends/LyXView.h"
#include "frontends/Dialogs.h"
#include "support/lstrings.h"
using std::max;
int InsetBibitem::key_counter = 0;
const string key_prefix = "key-";
InsetBibitem::InsetBibitem(InsetCommandParams const & p)
: InsetCommand(p), counter(1)
{
if (getContents().empty())
setContents(key_prefix + tostr(++key_counter));
}
Inset * InsetBibitem::clone(Buffer const &, bool) const
{
InsetBibitem * b = new InsetBibitem(params());
b->setCounter(counter);
return b;
}
void InsetBibitem::setCounter(int c)
{
counter = c;
}
// I'm sorry but this is still necessary because \bibitem is used also
// as a LyX 2.x command, and lyxlex is not enough smart to understand
// real LaTeX commands. Yes, that could be fixed, but would be a waste
// of time cause LyX3 won't use lyxlex anyway. (ale)
void InsetBibitem::write(Buffer const *, std::ostream & os) const
{
os << "\n\\bibitem ";
if (!getOptions().empty())
os << '[' << getOptions() << ']';
os << '{' << getContents() << "}\n";
}
// This is necessary here because this is written without begin_inset
// This should be changed!!! (Jug)
void InsetBibitem::read(Buffer const *, LyXLex & lex)
{
if (lex.eatLine()) {
scanCommand(lex.getString());
} else {
lex.printError("InsetCommand: Parse error: `$$Token'");
}
if (prefixIs(getContents(), key_prefix)) {
int key = strToInt(getContents().substr(key_prefix.length()));
key_counter = max(key_counter, key);
}
}
string const InsetBibitem::getBibLabel() const
{
return getOptions().empty() ? tostr(counter) : getOptions();
}
string const InsetBibitem::getScreenLabel(Buffer const *) const
{
return getContents() + " [" + getBibLabel() + ']';
}
void InsetBibitem::edit(BufferView * bv, int, int, mouse_button::state)
{
bv->owner()->getDialogs().showBibitem(this);
}
void InsetBibitem::edit(BufferView * bv, bool)
{
edit(bv, 0, 0, mouse_button::none);
}
// ale070405 This function maybe shouldn't be here. We'll fix this at 0.13.
int bibitemMaxWidth(BufferView * bv, LyXFont const & font)
{
int w = 0;
// Ha, now we are mainly at 1.2.0 and it is still here (Jug)
// Does look like a hack? It is! (but will change at 0.13)
ParagraphList::iterator it = bv->buffer()->paragraphs.begin();
ParagraphList::iterator end = bv->buffer()->paragraphs.end();
for (; it != end; ++it) {
if (it->bibitem()) {
int const wx = it->bibitem()->width(bv, font);
if (wx > w)
w = wx;
}
}
return w;
}
// ale070405
string const bibitemWidest(Buffer const * buffer)
{
int w = 0;
// Does look like a hack? It is! (but will change at 0.13)
InsetBibitem * bitem = 0;
LyXFont font;
ParagraphList::iterator it = buffer->paragraphs.begin();
ParagraphList::iterator end = buffer->paragraphs.end();
for (; it != end; ++it) {
if (it->bibitem()) {
int const wx =
font_metrics::width(it->bibitem()->getBibLabel(),
font);
if (wx > w) {
w = wx;
bitem = it->bibitem();
}
}
}
if (bitem && !bitem->getBibLabel().empty())
return bitem->getBibLabel();
return "99";
}

70
src/insets/insetbibitem.h Normal file
View File

@ -0,0 +1,70 @@
// -*- C++ -*-
/**
* \file insetbibitem.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Alejandro Aguilar Sierra
*
* Full author contact details are available in file CREDITS
*/
#ifndef INSET_BIBITEM_H
#define INSET_BIBITEM_H
#include "insetcommand.h"
class Buffer;
/** Used to insert bibitem's information (key and label)
Must be automatically inserted as the first object in a
bibliography paragraph.
*/
class InsetBibitem : public InsetCommand {
public:
///
InsetBibitem(InsetCommandParams const &);
///
Inset * clone(Buffer const &, bool same_id = false) const;
/** Currently \bibitem is used as a LyX2.x command,
so we need this method.
*/
void write(Buffer const *, std::ostream &) const;
///
void read(Buffer const *, LyXLex & lex);
///
virtual string const getScreenLabel(Buffer const *) const;
///
void edit(BufferView *, int x, int y, mouse_button::state button);
///
void edit(BufferView * bv, bool front = true);
///
EDITABLE editable() const { return IS_EDITABLE; }
///
Inset::Code lyxCode() const { return Inset::BIBITEM_CODE; }
/// keep .lyx format compatible
bool directWrite() const { return true; }
///
void setCounter(int);
///
int getCounter() const { return counter; }
///
string const getBibLabel() const;
///
struct Holder {
InsetBibitem * inset;
BufferView * view;
};
private:
///
int counter;
///
Holder holder;
///
static int key_counter;
};
#endif // INSET_BIBITEM_H

View File

@ -1,5 +1,5 @@
/**
* \file insetbib.C
* \file insetbibtex.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
@ -10,17 +10,13 @@
#include <config.h>
#include "insetbib.h"
#include "insetbibtex.h"
#include "buffer.h"
#include "debug.h"
#include "BufferView.h"
#include "debug.h"
#include "gettext.h"
#include "lyxtext.h"
#include "lyxrc.h"
#include "lyxlex.h"
#include "frontends/font_metrics.h"
#include "frontends/LyXView.h"
#include "frontends/LyXView.h"
#include "frontends/Dialogs.h"
#include "support/filetools.h"
@ -38,87 +34,6 @@ using std::getline;
using std::endl;
using std::vector;
using std::pair;
using std::max;
int InsetBibKey::key_counter = 0;
const string key_prefix = "key-";
InsetBibKey::InsetBibKey(InsetCommandParams const & p)
: InsetCommand(p), counter(1)
{
if (getContents().empty())
setContents(key_prefix + tostr(++key_counter));
}
Inset * InsetBibKey::clone(Buffer const &, bool) const
{
InsetBibKey * b = new InsetBibKey(params());
b->setCounter(counter);
return b;
}
void InsetBibKey::setCounter(int c)
{
counter = c;
}
// I'm sorry but this is still necessary because \bibitem is used also
// as a LyX 2.x command, and lyxlex is not enough smart to understand
// real LaTeX commands. Yes, that could be fixed, but would be a waste
// of time cause LyX3 won't use lyxlex anyway. (ale)
void InsetBibKey::write(Buffer const *, ostream & os) const
{
os << "\n\\bibitem ";
if (!getOptions().empty())
os << '[' << getOptions() << ']';
os << '{' << getContents() << "}\n";
}
// This is necessary here because this is written without begin_inset
// This should be changed!!! (Jug)
void InsetBibKey::read(Buffer const *, LyXLex & lex)
{
if (lex.eatLine()) {
scanCommand(lex.getString());
} else {
lex.printError("InsetCommand: Parse error: `$$Token'");
}
if (prefixIs(getContents(), key_prefix)) {
int key = strToInt(getContents().substr(key_prefix.length()));
key_counter = max(key_counter, key);
}
}
string const InsetBibKey::getBibLabel() const
{
return getOptions().empty() ? tostr(counter) : getOptions();
}
string const InsetBibKey::getScreenLabel(Buffer const *) const
{
return getContents() + " [" + getBibLabel() + ']';
}
void InsetBibKey::edit(BufferView * bv, int, int, mouse_button::state)
{
bv->owner()->getDialogs().showBibitem(this);
}
void InsetBibKey::edit(BufferView * bv, bool)
{
edit(bv, 0, 0, mouse_button::none);
}
InsetBibtex::InsetBibtex(InsetCommandParams const & p, bool)
@ -312,52 +227,3 @@ bool InsetBibtex::delDatabase(string const & db)
}
return true;
}
// ale070405 This function maybe shouldn't be here. We'll fix this at 0.13.
int bibitemMaxWidth(BufferView * bv, LyXFont const & font)
{
int w = 0;
// Ha, now we are mainly at 1.2.0 and it is still here (Jug)
// Does look like a hack? It is! (but will change at 0.13)
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 (wx > w)
w = wx;
}
}
return w;
}
// ale070405
string const bibitemWidest(Buffer const * buffer)
{
int w = 0;
// Does look like a hack? It is! (but will change at 0.13)
InsetBibKey * bkey = 0;
LyXFont font;
ParagraphList::iterator it = buffer->paragraphs.begin();
ParagraphList::iterator end = buffer->paragraphs.end();
for (; it != end; ++it) {
if (it->bibkey()) {
int const wx =
font_metrics::width(it->bibkey()->getBibLabel(),
font);
if (wx > w) {
w = wx;
bkey = it->bibkey();
}
}
}
if (bkey && !bkey->getBibLabel().empty())
return bkey->getBibLabel();
return "99";
}

View File

@ -1,6 +1,6 @@
// -*- C++ -*-
/**
* \file insetbib.h
* \file insetbibtex.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
@ -9,8 +9,8 @@
* Full author contact details are available in file CREDITS
*/
#ifndef INSET_BIB_H
#define INSET_BIB_H
#ifndef INSET_BIBTEX_H
#define INSET_BIBTEX_H
#include <vector>
@ -18,57 +18,6 @@
class Buffer;
/** Used to insert bibitem's information (key and label)
Must be automatically inserted as the first object in a
bibliography paragraph.
*/
class InsetBibKey : public InsetCommand {
public:
///
InsetBibKey(InsetCommandParams const &);
///
Inset * clone(Buffer const &, bool same_id = false) const;
/** Currently \bibitem is used as a LyX2.x command,
so we need this method.
*/
void write(Buffer const *, std::ostream &) const;
///
void read(Buffer const *, LyXLex & lex);
///
virtual string const getScreenLabel(Buffer const *) const;
///
void edit(BufferView *, int x, int y, mouse_button::state button);
///
void edit(BufferView * bv, bool front = true);
///
EDITABLE editable() const { return IS_EDITABLE; }
///
Inset::Code lyxCode() const { return Inset::BIBKEY_CODE; }
/// keep .lyx format compatible
bool directWrite() const { return true; }
///
void setCounter(int);
///
int getCounter() const { return counter; }
///
string const getBibLabel() const;
///
struct Holder {
InsetBibKey * inset;
BufferView * view;
};
private:
///
int counter;
///
Holder holder;
///
static int key_counter;
};
/** Used to insert BibTeX's information
*/
class InsetBibtex : public InsetCommand {
@ -114,4 +63,4 @@ private:
Holder holder;
};
#endif
#endif // INSET_BIBTEX_H

View File

@ -26,7 +26,7 @@
#include "gettext.h"
#include "changes.h"
#include "insets/insetbib.h"
#include "insets/insetbibitem.h"
#include "insets/insetoptarg.h"
#include "support/filetools.h"
@ -942,11 +942,11 @@ int Paragraph::getPositionOfInset(Inset const * inset) const
}
InsetBibKey * Paragraph::bibkey()
InsetBibitem * Paragraph::bibitem()
{
InsetList::iterator it = insetlist.begin();
if (it != insetlist.end() && it.getInset()->lyxCode() == Inset::BIBTEX_CODE)
return static_cast<InsetBibKey *>(it.getInset());
return static_cast<InsetBibitem *>(it.getInset());
return 0;
}

View File

@ -23,7 +23,7 @@
class BufferParams;
class BufferView;
class Counters;
class InsetBibKey;
class InsetBibitem;
class Language;
class LaTeXFeatures;
class ParagraphParameters;
@ -151,7 +151,7 @@ public:
char itemdepth;
///
InsetBibKey * bibkey(); // ale970302
InsetBibitem * bibitem(); // ale970302
#ifndef NO_NEXT
///

View File

@ -33,7 +33,6 @@
#include "WordLangTuple.h"
#include "paragraph_funcs.h"
#include "insets/insetbib.h"
#include "insets/insettext.h"
#include "support/textutils.h"

View File

@ -31,7 +31,7 @@
#include "counters.h"
#include "insets/inseterror.h"
#include "insets/insetbib.h"
#include "insets/insetbibitem.h"
#include "insets/insetspecialchar.h"
#include "insets/insettext.h"
#include "insets/insetfloat.h"
@ -1263,12 +1263,8 @@ 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()) {
// Inset * inset = new InsetBibKey(InsetCommandParams("bibitem"));
// //par->insertInset(0, inset);
//}
if (par->bibkey()) {
par->bibkey()->setCounter(number);
if (par->bibitem()) {
par->bibitem()->setCounter(number);
par->params().labelString(layout->labelstring());
}
// In biblio should't be following counters but...

View File

@ -31,7 +31,6 @@
#include "frontends/Dialogs.h"
#include "insets/insetspecialchar.h"
#include "insets/insettext.h"
#include "insets/insetbib.h"
#include "insets/insetquotes.h"
#include "insets/insetcommand.h"
#include "undo_funcs.h"
@ -1610,7 +1609,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
case LFUN_INSET_CAPTION:
#endif
case LFUN_INSERT_NOTE:
case LFUN_INSERT_BIBKEY:
case LFUN_INSERT_BIBITEM:
case LFUN_INSET_ERT:
case LFUN_INSET_FLOAT:
case LFUN_INSET_FOOTNOTE: