]> git.lyx.org Git - features.git/commitdiff
* Split insetbib.[Ch] into insetbibitem.[Ch] and insetbibtex.[Ch].
authorAngus Leeming <leeming@lyx.org>
Fri, 21 Feb 2003 09:20:18 +0000 (09:20 +0000)
committerAngus Leeming <leeming@lyx.org>
Fri, 21 Feb 2003 09:20:18 +0000 (09:20 +0000)
* Rename bibkey as bibitem.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6217 a592a061-630c-0410-9148-cb99ea01b6c8

23 files changed:
lib/ChangeLog
lib/ui/default.ui
src/BufferView_pimpl.C
src/ChangeLog
src/LyXAction.C
src/buffer.C
src/commandtags.h
src/factory.C
src/frontends/ChangeLog
src/frontends/Dialogs.h
src/insets/Makefile.am
src/insets/inset.h
src/insets/insetbib.C [deleted file]
src/insets/insetbib.h [deleted file]
src/insets/insetbibitem.C [new file with mode: 0644]
src/insets/insetbibitem.h [new file with mode: 0644]
src/insets/insetbibtex.C [new file with mode: 0644]
src/insets/insetbibtex.h [new file with mode: 0644]
src/paragraph.C
src/paragraph.h
src/text.C
src/text2.C
src/text3.C

index 0248bdd9f0e29b3f197d9c5766fa493dd73fbfe0..375f2d80b5936c33d5ed62d772de37fffa888e0c 100644 (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:
index 35c4e0ac701277e3f6cdb1bd92ef994e640f4362..aa2a3639529471de5f69919d9f942de8c4114d15 100644 (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"
index 34b5a478e357034a93c92d4a0ff62c214eb557a7..b974d55d478f30e40dbd7e5fb864654d41f87f50 100644 (file)
 #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"
 
index e4774b93466136c80e8625ef09ceef38509f9378..954c50d7d72f223bcaba970160a443575a5d18b1 100644 (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
index 47b279a57e909e107702c5080408bf5f3aff15c2..a1dca28948bb7e6c64bc12d0fa2c25a22782293f 100644 (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"),
index 06ae1d838012c65f4511d27feb7d147de8552440..24f0dbaa4468e8cf56394cf27036c497931f9f3f 100644 (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);
index 7ccc3ac88978caa7a0a91fc6516d49f182f2d40c..1216e494d342b210bc88b4c2d0eaf830176e8208 100644 (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 */
 };
 
index 601f72684cffd60f90b9aa7eaad54360137e3fe9..8e032cf51f052b7223ab652af041000967d51b9b 100644 (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
index 22d38f127f3579f4ffcb51098b99460aeffa1a12..a95b92dea16e7fc2cfe64fa93da8d79c08806fcc 100644 (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)
index 717e42afc9a121f58a6bed439b2a246fed920beb..dbb20e76451cbde8357df8c8d37dfd000751df40 100644 (file)
@@ -20,8 +20,6 @@
 #include <boost/signals/signal1.hpp>
 
 class LyXView;
-class InsetBibKey;
-class InsetBibtex;
 class InsetCommand;
 class InsetError;
 class InsetERT;
index 071957cc6086afd8c4a51a66344db7bda76a5c1c..98871f3f6b3be7fdbb681096abc07867fa84d103 100644 (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 \
index 8cc9fa5df85fcbbda214b11669ef22ebc118e0e3..3734f691420e4a9dc2a5210d6604ab9a829cae8b 100644 (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
        };
 
        ///
diff --git a/src/insets/insetbib.C b/src/insets/insetbib.C
deleted file mode 100644 (file)
index 084deea..0000000
+++ /dev/null
@@ -1,363 +0,0 @@
-/**
- * \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";
-}
diff --git a/src/insets/insetbib.h b/src/insets/insetbib.h
deleted file mode 100644 (file)
index 7a76f01..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-// -*- 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
diff --git a/src/insets/insetbibitem.C b/src/insets/insetbibitem.C
new file mode 100644 (file)
index 0000000..2e569cd
--- /dev/null
@@ -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";
+}
diff --git a/src/insets/insetbibitem.h b/src/insets/insetbibitem.h
new file mode 100644 (file)
index 0000000..62408b6
--- /dev/null
@@ -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
diff --git a/src/insets/insetbibtex.C b/src/insets/insetbibtex.C
new file mode 100644 (file)
index 0000000..da263a4
--- /dev/null
@@ -0,0 +1,229 @@
+/**
+ * \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;
+}
diff --git a/src/insets/insetbibtex.h b/src/insets/insetbibtex.h
new file mode 100644 (file)
index 0000000..0efae32
--- /dev/null
@@ -0,0 +1,66 @@
+// -*- 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
index 0a082a5eb2fcb32c9ea922bff8d5e3bb0ce4a07d..0f848a48df03eca04438be6f9784c0a615a93b1b 100644 (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;
 }
 
index 75e8097f32932419ae7eb55dcfffff8e2d8e2bb5..17a14511cee6f690f6dc979193d73fc7f7f9ed4b 100644 (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
        ///
index 388b5f92c00841c1091d1056bd0705cbc59d6d0a..dbc2432193355f995f0a7beb1ee1e5a5125c9135 100644 (file)
@@ -33,7 +33,6 @@
 #include "WordLangTuple.h"
 #include "paragraph_funcs.h"
 
-#include "insets/insetbib.h"
 #include "insets/insettext.h"
 
 #include "support/textutils.h"
index f8b6104d841dee5ca202ca21e53920e7996de9fb..d54274f4472e1314413302fb451430947a127e3f 100644 (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...
index 3fcc37dfa4e714157ba4b4f5c303fe5362067853..9de9251e6fb0d7e80dc726001a777c7eeefb98ae 100644 (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: