]> 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 c30a1048ebcc28c0565e5f2b4b3572eb3165f86c..80d2cd832c942a129df44fc1f7924fd641b2b839 100644 (file)
@@ -5,17 +5,19 @@
  *
  * \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"
 #include "funcrequest.h"
 #include "gettext.h"
+#include "latexrunparams.h"
 
 #include "support/filetools.h"
 #include "support/path.h"
@@ -26,6 +28,8 @@
 #include <fstream>
 #include <cstdlib>
 
+using namespace lyx::support;
+
 using std::ostream;
 using std::ifstream;
 using std::getline;
@@ -34,48 +38,68 @@ using std::vector;
 using std::pair;
 
 
-InsetBibtex::InsetBibtex(InsetCommandParams const & p, bool)
+InsetBibtex::InsetBibtex(InsetCommandParams const & p)
        : InsetCommand(p)
 {}
 
 
 InsetBibtex::~InsetBibtex()
 {
-       InsetCommandMailer mailer("bibtex", *this);
-       mailer.hideDialog();
+       InsetCommandMailer("bibtex", *this).hideDialog();
 }
 
 
-dispatch_result InsetBibtex::localDispatch(FuncRequest const & cmd)
+std::auto_ptr<InsetBase> InsetBibtex::clone() const
+{
+       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
 {
-       if (cmd.action != LFUN_BIBTEX_APPLY)
-               return UNDISPATCHED;
+       InsetCommand::draw(pi, x + center_indent_, y);
+}
 
-       InsetCommandParams p;
-       InsetCommandMailer::string2params(cmd.argument, p);
-       if (p.getCmdName().empty())
-               return UNDISPATCHED;
 
-       if (view() && p.getContents() != params().getContents()) {
-               view()->ChangeCitationsIfUnique(params().getContents(),
-                                               p.getContents());
+dispatch_result InsetBibtex::localDispatch(FuncRequest const & cmd)
+{
+       switch (cmd.action) {
+
+       case LFUN_INSET_EDIT:
+               InsetCommandMailer("bibtex", *this).showDialog(cmd.view());
+               return DISPATCHED;
+
+       case LFUN_INSET_MODIFY: {
+               InsetCommandParams p;
+               InsetCommandMailer::string2params(cmd.argument, p);
+               if (p.getCmdName().empty())
+                       return DISPATCHED;
+               setParams(p);
+               return  DISPATCHED;
        }
 
-       setParams(p);
-       if (view())
-               view()->updateInset(this, true);
+       default:
+               return InsetCommand::localDispatch(cmd);
+       }
 
-       return DISPATCHED;
 }
 
-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,
-                      bool /*fragile*/, bool/*fs*/) const
+int InsetBibtex::latex(Buffer const & buffer, ostream & os,
+                      LatexRunParams const & runparams) const
 {
        // changing the sequence of the commands
        // 1. \bibliographystyle{style}
@@ -95,9 +119,9 @@ int InsetBibtex::latex(Buffer const * buffer, ostream & os,
                }
        }
 
-       if (!buffer->niceFile
-           && IsFileReadable(MakeAbsPath(style, buffer->filePath()) + ".bst")) {
-               style = MakeAbsPath(style, buffer->filePath());
+       if (!runparams.nice
+           && IsFileReadable(MakeAbsPath(style, buffer.filePath()) + ".bst")) {
+               style = MakeAbsPath(style, buffer.filePath());
        }
 
        if (!style.empty()) { // we want no \biblio...{}
@@ -110,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 {
@@ -135,9 +159,9 @@ int InsetBibtex::latex(Buffer const * buffer, ostream & os,
        // 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()));
+               if (!runparams.nice &&
+                   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,',');
@@ -150,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;
@@ -175,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
@@ -212,19 +234,6 @@ void InsetBibtex::fillWithBibKeys
 }
 
 
-void InsetBibtex::edit(BufferView *, int, int, mouse_button::state)
-{
-       InsetCommandMailer mailer("bibtex", *this);
-       mailer.showDialog();
-}
-
-
-void InsetBibtex::edit(BufferView * bv, bool)
-{
-       edit(bv, 0, 0, mouse_button::none);
-}
-
-
 bool InsetBibtex::addDatabase(string const & db)
 {
        string contents(getContents());