+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:
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"
#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/insetfloatlist.h"
#include "insets/insetgraphics.h"
+#include "insets/insetinclude.h"
+#include "insets/insetindex.h"
+#include "insets/insetlatexaccent.h"
#include "insets/insetmarginal.h"
-#include "insets/insetfloatlist.h"
+#include "insets/insetref.h"
+#include "insets/insettext.h"
+#include "insets/insettoc.h"
#include "mathed/formulabase.h"
+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
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"),
#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"
++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;
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") {
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);
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 */
};
#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"
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
+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)
#include <boost/signals/signal1.hpp>
class LyXView;
-class InsetBibKey;
-class InsetBibtex;
class InsetCommand;
class InsetError;
class InsetERT;
inset.h \
insetbase.h \
insetbase.C \
- insetbib.C \
- insetbib.h \
+ insetbibitem.C \
+ insetbibitem.h \
+ insetbibtex.C \
+ insetbibtex.h \
insetbutton.C \
insetbutton.h \
insetcaption.C \
///
PARENT_CODE,
///
+ BIBITEM_CODE,
+ ///
BIBTEX_CODE,
///
TEXT_CODE,
///
INDEX_PRINT_CODE,
///
- OPTARG_CODE,
- ///
- BIBKEY_CODE
+ OPTARG_CODE
};
///
+++ /dev/null
-/**
- * \file insetbib.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 "insetbib.h"
-#include "buffer.h"
-#include "debug.h"
-#include "BufferView.h"
-#include "gettext.h"
-#include "lyxtext.h"
-#include "lyxrc.h"
-#include "lyxlex.h"
-#include "frontends/font_metrics.h"
-#include "frontends/LyXView.h"
-
-#include "frontends/Dialogs.h"
-
-#include "support/filetools.h"
-#include "support/path.h"
-#include "support/os.h"
-#include "support/lstrings.h"
-#include "support/LAssert.h"
-
-#include <fstream>
-#include <cstdlib>
-
-using std::ostream;
-using std::ifstream;
-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)
- : InsetCommand(p)
-{}
-
-
-string const InsetBibtex::getScreenLabel(Buffer const *) const
-{
- return _("BibTeX Generated References");
-}
-
-
-int InsetBibtex::latex(Buffer const * buffer, ostream & os,
- bool /*fragile*/, bool/*fs*/) const
-{
- // changing the sequence of the commands
- // 1. \bibliographystyle{style}
- // 2. \addcontentsline{...} - if option bibtotoc set
- // 3. \bibliography{database}
- string adb;
- string db_in = getContents();
- db_in = split(db_in, adb, ',');
-
- // Style-Options
- string style = getOptions(); // maybe empty! and with bibtotoc
- string bibtotoc;
- if (prefixIs(style, "bibtotoc")) {
- bibtotoc = "bibtotoc";
- if (contains(style, ',')) {
- style = split(style, bibtotoc, ',');
- }
- }
-
- if (!buffer->niceFile
- && IsFileReadable(MakeAbsPath(style, buffer->filePath()) + ".bst")) {
- style = MakeAbsPath(style, buffer->filePath());
- }
-
- if (!style.empty()) { // we want no \biblio...{}
- os << "\\bibliographystyle{" << style << "}\n";
- }
-
- // bibtotoc-Option
- if (!bibtotoc.empty()) {
- // maybe a problem when a textclass has no "art" as
- // part of its name, because it's than book.
- // For the "official" lyx-layouts it's no problem to support
- // all well
- if (!contains(buffer->params.getLyXTextClass().name(),
- "art")) {
- if (buffer->params.sides == LyXTextClass::OneSide) {
- // oneside
- os << "\\clearpage";
- } else {
- // twoside
- os << "\\cleardoublepage";
- }
-
- // bookclass
- os << "\\addcontentsline{toc}{chapter}{\\bibname}";
-
- } else {
- // article class
- os << "\\addcontentsline{toc}{section}{\\refname}";
- }
- }
-
- // database
- // If we generate in a temp dir, we might need to give an
- // absolute path there. This is a bit complicated since we can
- // have a comma-separated list of bibliographies
- string db_out;
- while (!adb.empty()) {
- if (!buffer->niceFile &&
- IsFileReadable(MakeAbsPath(adb, buffer->filePath())+".bib"))
- adb = os::external_path(MakeAbsPath(adb, buffer->filePath()));
- db_out += adb;
- db_out += ',';
- db_in = split(db_in, adb,',');
- }
- db_out = rtrim(db_out, ",");
- os << "\\bibliography{" << db_out << "}\n";
- return 2;
-}
-
-
-vector<string> const InsetBibtex::getFiles(Buffer const & buffer) const
-{
- // Doesn't appear to be used (Angus, 31 July 2001)
- Path p(buffer.filePath());
-
- vector<string> vec;
-
- string tmp;
- string bibfiles = getContents();
- bibfiles = split(bibfiles, tmp, ',');
- while (!tmp.empty()) {
- string file = findtexfile(ChangeExtension(tmp, "bib"), "bib");
- lyxerr[Debug::LATEX] << "Bibfile: " << file << endl;
-
- // If we didn't find a matching file name just fail silently
- if (!file.empty())
- vec.push_back(file);
-
- // Get next file name
- bibfiles = split(bibfiles, tmp, ',');
- }
-
- return vec;
-}
-
-
-// This method returns a comma separated list of Bibtex entries
-void InsetBibtex::fillWithBibKeys
- (Buffer const * buffer, vector<pair<string, string> > & keys) const
-{
- lyx::Assert(buffer);
- vector<string> const files = getFiles(*buffer);
- for (vector<string>::const_iterator it = files.begin();
- it != files.end(); ++ it) {
- // This is a _very_ simple parser for Bibtex database
- // files. All it does is to look for lines starting
- // in @ and not being @preamble and @string entries.
- // It does NOT do any syntax checking!
- ifstream ifs(it->c_str());
- string linebuf0;
- while (getline(ifs, linebuf0)) {
- string linebuf = trim(linebuf0);
- if (linebuf.empty()) continue;
- if (prefixIs(linebuf, "@")) {
- linebuf = subst(linebuf, '{', '(');
- string tmp;
- linebuf = split(linebuf, tmp, '(');
- tmp = ascii_lowercase(tmp);
- if (!prefixIs(tmp, "@string")
- && !prefixIs(tmp, "@preamble")) {
- linebuf = split(linebuf, tmp, ',');
- tmp = ltrim(tmp, " \t");
- if (!tmp.empty()) {
- keys.push_back(pair<string,string>(tmp,string()));
- }
- }
- } else if (!keys.empty()) {
- keys.back().second += linebuf + "\n";
- }
- }
- }
-}
-
-
-void InsetBibtex::edit(BufferView * bv, int, int, mouse_button::state)
-{
- bv->owner()->getDialogs().showBibtex(this);
-}
-
-
-void InsetBibtex::edit(BufferView * bv, bool)
-{
- edit(bv, 0, 0, mouse_button::none);
-}
-
-
-bool InsetBibtex::addDatabase(string const & db)
-{
- string contents(getContents());
- if (!contains(contents, db)) {
- if (!contents.empty())
- contents += ',';
- setContents(contents + db);
- return true;
- }
- return false;
-}
-
-
-bool InsetBibtex::delDatabase(string const & db)
-{
- if (contains(getContents(), db)) {
- string bd = db;
- int const n = tokenPos(getContents(), ',', bd);
- if (n > 0) {
- // Weird code, would someone care to explain this?(Lgb)
- string tmp(", ");
- tmp += bd;
- setContents(subst(getContents(), tmp, ", "));
- } else if (n == 0)
- setContents(split(getContents(), bd, ','));
- else
- return false;
- }
- 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";
-}
+++ /dev/null
-// -*- C++ -*-
-/**
- * \file insetbib.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_BIB_H
-#define INSET_BIB_H
-
-
-#include <vector>
-#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 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 {
-public:
- ///
- InsetBibtex(InsetCommandParams const &, bool same_id = false);
- ///
- Inset * clone(Buffer const &, bool same_id = false) const {
- return new InsetBibtex(params(), same_id);
- }
- ///
- string const getScreenLabel(Buffer const *) const;
- ///
- EDITABLE editable() const { return IS_EDITABLE; }
- ///
- Inset::Code lyxCode() const { return Inset::BIBTEX_CODE; }
- ///
- void edit(BufferView *, int x, int y, mouse_button::state button);
- ///
- void edit(BufferView * bv, bool front = true);
- ///
- int latex(Buffer const *, std::ostream &,
- bool fragile, bool freespace) const;
- ///
- void fillWithBibKeys(Buffer const *,
- std::vector<std::pair<string,string> > &) const;
- ///
- std::vector<string> const getFiles(Buffer const &) const;
- ///
- bool addDatabase(string const &);
- ///
- bool delDatabase(string const &);
- ///
- bool display() const { return true; }
- ///
- struct Holder {
- InsetBibtex * inset;
- BufferView * view;
- };
-
-private:
- ///
- Holder holder;
-};
-
-#endif
--- /dev/null
+/**
+ * \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";
+}
--- /dev/null
+// -*- 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
--- /dev/null
+/**
+ * \file insetbibtex.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 "insetbibtex.h"
+#include "buffer.h"
+#include "BufferView.h"
+#include "debug.h"
+#include "gettext.h"
+
+#include "frontends/LyXView.h"
+#include "frontends/Dialogs.h"
+
+#include "support/filetools.h"
+#include "support/path.h"
+#include "support/os.h"
+#include "support/lstrings.h"
+#include "support/LAssert.h"
+
+#include <fstream>
+#include <cstdlib>
+
+using std::ostream;
+using std::ifstream;
+using std::getline;
+using std::endl;
+using std::vector;
+using std::pair;
+
+
+InsetBibtex::InsetBibtex(InsetCommandParams const & p, bool)
+ : InsetCommand(p)
+{}
+
+
+string const InsetBibtex::getScreenLabel(Buffer const *) const
+{
+ return _("BibTeX Generated References");
+}
+
+
+int InsetBibtex::latex(Buffer const * buffer, ostream & os,
+ bool /*fragile*/, bool/*fs*/) const
+{
+ // changing the sequence of the commands
+ // 1. \bibliographystyle{style}
+ // 2. \addcontentsline{...} - if option bibtotoc set
+ // 3. \bibliography{database}
+ string adb;
+ string db_in = getContents();
+ db_in = split(db_in, adb, ',');
+
+ // Style-Options
+ string style = getOptions(); // maybe empty! and with bibtotoc
+ string bibtotoc;
+ if (prefixIs(style, "bibtotoc")) {
+ bibtotoc = "bibtotoc";
+ if (contains(style, ',')) {
+ style = split(style, bibtotoc, ',');
+ }
+ }
+
+ if (!buffer->niceFile
+ && IsFileReadable(MakeAbsPath(style, buffer->filePath()) + ".bst")) {
+ style = MakeAbsPath(style, buffer->filePath());
+ }
+
+ if (!style.empty()) { // we want no \biblio...{}
+ os << "\\bibliographystyle{" << style << "}\n";
+ }
+
+ // bibtotoc-Option
+ if (!bibtotoc.empty()) {
+ // maybe a problem when a textclass has no "art" as
+ // part of its name, because it's than book.
+ // For the "official" lyx-layouts it's no problem to support
+ // all well
+ if (!contains(buffer->params.getLyXTextClass().name(),
+ "art")) {
+ if (buffer->params.sides == LyXTextClass::OneSide) {
+ // oneside
+ os << "\\clearpage";
+ } else {
+ // twoside
+ os << "\\cleardoublepage";
+ }
+
+ // bookclass
+ os << "\\addcontentsline{toc}{chapter}{\\bibname}";
+
+ } else {
+ // article class
+ os << "\\addcontentsline{toc}{section}{\\refname}";
+ }
+ }
+
+ // database
+ // If we generate in a temp dir, we might need to give an
+ // absolute path there. This is a bit complicated since we can
+ // have a comma-separated list of bibliographies
+ string db_out;
+ while (!adb.empty()) {
+ if (!buffer->niceFile &&
+ IsFileReadable(MakeAbsPath(adb, buffer->filePath())+".bib"))
+ adb = os::external_path(MakeAbsPath(adb, buffer->filePath()));
+ db_out += adb;
+ db_out += ',';
+ db_in = split(db_in, adb,',');
+ }
+ db_out = rtrim(db_out, ",");
+ os << "\\bibliography{" << db_out << "}\n";
+ return 2;
+}
+
+
+vector<string> const InsetBibtex::getFiles(Buffer const & buffer) const
+{
+ // Doesn't appear to be used (Angus, 31 July 2001)
+ Path p(buffer.filePath());
+
+ vector<string> vec;
+
+ string tmp;
+ string bibfiles = getContents();
+ bibfiles = split(bibfiles, tmp, ',');
+ while (!tmp.empty()) {
+ string file = findtexfile(ChangeExtension(tmp, "bib"), "bib");
+ lyxerr[Debug::LATEX] << "Bibfile: " << file << endl;
+
+ // If we didn't find a matching file name just fail silently
+ if (!file.empty())
+ vec.push_back(file);
+
+ // Get next file name
+ bibfiles = split(bibfiles, tmp, ',');
+ }
+
+ return vec;
+}
+
+
+// This method returns a comma separated list of Bibtex entries
+void InsetBibtex::fillWithBibKeys
+ (Buffer const * buffer, vector<pair<string, string> > & keys) const
+{
+ lyx::Assert(buffer);
+ vector<string> const files = getFiles(*buffer);
+ for (vector<string>::const_iterator it = files.begin();
+ it != files.end(); ++ it) {
+ // This is a _very_ simple parser for Bibtex database
+ // files. All it does is to look for lines starting
+ // in @ and not being @preamble and @string entries.
+ // It does NOT do any syntax checking!
+ ifstream ifs(it->c_str());
+ string linebuf0;
+ while (getline(ifs, linebuf0)) {
+ string linebuf = trim(linebuf0);
+ if (linebuf.empty()) continue;
+ if (prefixIs(linebuf, "@")) {
+ linebuf = subst(linebuf, '{', '(');
+ string tmp;
+ linebuf = split(linebuf, tmp, '(');
+ tmp = ascii_lowercase(tmp);
+ if (!prefixIs(tmp, "@string")
+ && !prefixIs(tmp, "@preamble")) {
+ linebuf = split(linebuf, tmp, ',');
+ tmp = ltrim(tmp, " \t");
+ if (!tmp.empty()) {
+ keys.push_back(pair<string,string>(tmp,string()));
+ }
+ }
+ } else if (!keys.empty()) {
+ keys.back().second += linebuf + "\n";
+ }
+ }
+ }
+}
+
+
+void InsetBibtex::edit(BufferView * bv, int, int, mouse_button::state)
+{
+ bv->owner()->getDialogs().showBibtex(this);
+}
+
+
+void InsetBibtex::edit(BufferView * bv, bool)
+{
+ edit(bv, 0, 0, mouse_button::none);
+}
+
+
+bool InsetBibtex::addDatabase(string const & db)
+{
+ string contents(getContents());
+ if (!contains(contents, db)) {
+ if (!contents.empty())
+ contents += ',';
+ setContents(contents + db);
+ return true;
+ }
+ return false;
+}
+
+
+bool InsetBibtex::delDatabase(string const & db)
+{
+ if (contains(getContents(), db)) {
+ string bd = db;
+ int const n = tokenPos(getContents(), ',', bd);
+ if (n > 0) {
+ // Weird code, would someone care to explain this?(Lgb)
+ string tmp(", ");
+ tmp += bd;
+ setContents(subst(getContents(), tmp, ", "));
+ } else if (n == 0)
+ setContents(split(getContents(), bd, ','));
+ else
+ return false;
+ }
+ return true;
+}
--- /dev/null
+// -*- C++ -*-
+/**
+ * \file insetbibtex.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_BIBTEX_H
+#define INSET_BIBTEX_H
+
+
+#include <vector>
+#include "insetcommand.h"
+
+class Buffer;
+
+/** Used to insert BibTeX's information
+ */
+class InsetBibtex : public InsetCommand {
+public:
+ ///
+ InsetBibtex(InsetCommandParams const &, bool same_id = false);
+ ///
+ Inset * clone(Buffer const &, bool same_id = false) const {
+ return new InsetBibtex(params(), same_id);
+ }
+ ///
+ string const getScreenLabel(Buffer const *) const;
+ ///
+ EDITABLE editable() const { return IS_EDITABLE; }
+ ///
+ Inset::Code lyxCode() const { return Inset::BIBTEX_CODE; }
+ ///
+ void edit(BufferView *, int x, int y, mouse_button::state button);
+ ///
+ void edit(BufferView * bv, bool front = true);
+ ///
+ int latex(Buffer const *, std::ostream &,
+ bool fragile, bool freespace) const;
+ ///
+ void fillWithBibKeys(Buffer const *,
+ std::vector<std::pair<string,string> > &) const;
+ ///
+ std::vector<string> const getFiles(Buffer const &) const;
+ ///
+ bool addDatabase(string const &);
+ ///
+ bool delDatabase(string const &);
+ ///
+ bool display() const { return true; }
+ ///
+ struct Holder {
+ InsetBibtex * inset;
+ BufferView * view;
+ };
+
+private:
+ ///
+ Holder holder;
+};
+
+#endif // INSET_BIBTEX_H
#include "gettext.h"
#include "changes.h"
-#include "insets/insetbib.h"
+#include "insets/insetbibitem.h"
#include "insets/insetoptarg.h"
#include "support/filetools.h"
}
-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;
}
class BufferParams;
class BufferView;
class Counters;
-class InsetBibKey;
+class InsetBibitem;
class Language;
class LaTeXFeatures;
class ParagraphParameters;
char itemdepth;
///
- InsetBibKey * bibkey(); // ale970302
+ InsetBibitem * bibitem(); // ale970302
#ifndef NO_NEXT
///
#include "WordLangTuple.h"
#include "paragraph_funcs.h"
-#include "insets/insetbib.h"
#include "insets/insettext.h"
#include "support/textutils.h"
#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"
} 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...
#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"
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: