]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetbibtex.C
Enable convertDefault.sh to run even if its executable bit is not set.
[lyx.git] / src / insets / insetbibtex.C
index dc35dcc2361e75932a48dbfe8acf83f528aa150f..80d2cd832c942a129df44fc1f7924fd641b2b839 100644 (file)
@@ -5,12 +5,13 @@
  *
  * \author Alejandro Aguilar Sierra
  *
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
  */
-#include <config.h>
 
+#include <config.h>
 
 #include "insetbibtex.h"
+#include "metricsinfo.h"
 #include "buffer.h"
 #include "BufferView.h"
 #include "debug.h"
@@ -27,6 +28,8 @@
 #include <fstream>
 #include <cstdlib>
 
+using namespace lyx::support;
+
 using std::ostream;
 using std::ifstream;
 using std::getline;
@@ -40,15 +43,29 @@ InsetBibtex::InsetBibtex(InsetCommandParams const & p)
 {}
 
 
-// InsetBibtex::InsetBibtex(InsetCommandParams const & p, bool)
-//     : InsetCommand(p, false)
-// {}
+InsetBibtex::~InsetBibtex()
+{
+       InsetCommandMailer("bibtex", *this).hideDialog();
+}
 
 
-InsetBibtex::~InsetBibtex()
+std::auto_ptr<InsetBase> InsetBibtex::clone() const
 {
-       InsetCommandMailer mailer("bibtex", *this);
-       mailer.hideDialog();
+       return std::auto_ptr<InsetBase>(new InsetBibtex(*this));
+}
+
+void InsetBibtex::metrics(MetricsInfo & mi, Dimension & dim) const
+{
+       InsetCommand::metrics(mi, dim);
+       center_indent_ = (mi.base.textwidth - dim.wid) / 2;
+       dim.wid = mi.base.textwidth;
+       dim_ = dim;
+}
+
+
+void InsetBibtex::draw(PainterInfo & pi, int x, int y) const
+{
+       InsetCommand::draw(pi, x + center_indent_, y);
 }
 
 
@@ -65,14 +82,7 @@ dispatch_result InsetBibtex::localDispatch(FuncRequest const & cmd)
                InsetCommandMailer::string2params(cmd.argument, p);
                if (p.getCmdName().empty())
                        return DISPATCHED;
-
-               if (view() && p.getContents() != params().getContents()) {
-                       view()->ChangeCitationsIfUnique(params().getContents(),
-                                                       p.getContents());
-               }
-
                setParams(p);
-               cmd.view()->updateInset(this);
                return  DISPATCHED;
        }
 
@@ -82,13 +92,13 @@ dispatch_result InsetBibtex::localDispatch(FuncRequest const & cmd)
 
 }
 
-string const InsetBibtex::getScreenLabel(Buffer const *) const
+string const InsetBibtex::getScreenLabel(Buffer const &) const
 {
        return _("BibTeX Generated References");
 }
 
 
-int InsetBibtex::latex(Buffer const * buffer, ostream & os,
+int InsetBibtex::latex(Buffer const & buffer, ostream & os,
                       LatexRunParams const & runparams) const
 {
        // changing the sequence of the commands
@@ -110,8 +120,8 @@ int InsetBibtex::latex(Buffer const * buffer, ostream & os,
        }
 
        if (!runparams.nice
-           && IsFileReadable(MakeAbsPath(style, buffer->filePath()) + ".bst")) {
-               style = MakeAbsPath(style, buffer->filePath());
+           && IsFileReadable(MakeAbsPath(style, buffer.filePath()) + ".bst")) {
+               style = MakeAbsPath(style, buffer.filePath());
        }
 
        if (!style.empty()) { // we want no \biblio...{}
@@ -124,9 +134,9 @@ int InsetBibtex::latex(Buffer const * buffer, ostream & os,
                // 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(),
+               if (!contains(buffer.params.getLyXTextClass().name(),
                              "art")) {
-                       if (buffer->params.sides == LyXTextClass::OneSide) {
+                       if (buffer.params.sides == LyXTextClass::OneSide) {
                                // oneside
                                os << "\\clearpage";
                        } else {
@@ -150,8 +160,8 @@ int InsetBibtex::latex(Buffer const * buffer, ostream & os,
        string db_out;
        while (!adb.empty()) {
                if (!runparams.nice &&
-                   IsFileReadable(MakeAbsPath(adb, buffer->filePath())+".bib"))
-                        adb = os::external_path(MakeAbsPath(adb, buffer->filePath()));
+                   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,',');
@@ -164,7 +174,6 @@ int InsetBibtex::latex(Buffer const * buffer, ostream & os,
 
 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;
@@ -189,11 +198,10 @@ vector<string> const InsetBibtex::getFiles(Buffer const & buffer) const
 
 
 // This method returns a comma separated list of Bibtex entries
-void InsetBibtex::fillWithBibKeys
-       (Buffer const * buffer, vector<pair<string, string> > & keys) const
+void InsetBibtex::fillWithBibKeys(Buffer const & buffer,
+                                 std::vector<std::pair<string, string> > & keys) const
 {
-       lyx::Assert(buffer);
-       vector<string> const files = getFiles(*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