]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetbibtex.C
prevent crash when inserting minipage in table cell,
[lyx.git] / src / insets / insetbibtex.C
index da263a49698795cd9bf4247ea6e3043f0026e00a..f016af125cdb1bb223bf769cbf47506afba7c7f0 100644 (file)
@@ -7,17 +7,16 @@
  *
  * Full author contact details are available in file CREDITS
  */
-#include <config.h>
 
+#include <config.h>
 
 #include "insetbibtex.h"
 #include "buffer.h"
 #include "BufferView.h"
 #include "debug.h"
+#include "funcrequest.h"
 #include "gettext.h"
-
-#include "frontends/LyXView.h"
-#include "frontends/Dialogs.h"
+#include "latexrunparams.h"
 
 #include "support/filetools.h"
 #include "support/path.h"
@@ -28,6 +27,8 @@
 #include <fstream>
 #include <cstdlib>
 
+using namespace lyx::support;
+
 using std::ostream;
 using std::ifstream;
 using std::getline;
@@ -36,11 +37,46 @@ using std::vector;
 using std::pair;
 
 
-InsetBibtex::InsetBibtex(InsetCommandParams const & p, bool)
+InsetBibtex::InsetBibtex(InsetCommandParams const & p)
        : InsetCommand(p)
 {}
 
 
+InsetBibtex::~InsetBibtex()
+{
+       InsetCommandMailer("bibtex", *this).hideDialog();
+}
+
+
+std::auto_ptr<InsetBase> InsetBibtex::clone() const
+{
+       return std::auto_ptr<InsetBase>(new InsetBibtex(*this));
+}
+
+
+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;
+       }
+
+       default:
+               return InsetCommand::localDispatch(cmd);
+       }
+
+}
+
 string const InsetBibtex::getScreenLabel(Buffer const *) const
 {
        return _("BibTeX Generated References");
@@ -48,7 +84,7 @@ string const InsetBibtex::getScreenLabel(Buffer const *) const
 
 
 int InsetBibtex::latex(Buffer const * buffer, ostream & os,
-                      bool /*fragile*/, bool/*fs*/) const
+                      LatexRunParams const & runparams) const
 {
        // changing the sequence of the commands
        // 1. \bibliographystyle{style}
@@ -68,7 +104,7 @@ int InsetBibtex::latex(Buffer const * buffer, ostream & os,
                }
        }
 
-       if (!buffer->niceFile
+       if (!runparams.nice
            && IsFileReadable(MakeAbsPath(style, buffer->filePath()) + ".bst")) {
                style = MakeAbsPath(style, buffer->filePath());
        }
@@ -108,7 +144,7 @@ int InsetBibtex::latex(Buffer const * buffer, ostream & os,
        // have a comma-separated list of bibliographies
        string db_out;
        while (!adb.empty()) {
-               if (!buffer->niceFile &&
+               if (!runparams.nice &&
                    IsFileReadable(MakeAbsPath(adb, buffer->filePath())+".bib"))
                         adb = os::external_path(MakeAbsPath(adb, buffer->filePath()));
                db_out += adb;
@@ -123,7 +159,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;
@@ -148,10 +183,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);
+       Assert(buffer);
        vector<string> const files = getFiles(*buffer);
        for (vector<string>::const_iterator it = files.begin();
             it != files.end(); ++ it) {
@@ -185,18 +220,6 @@ void InsetBibtex::fillWithBibKeys
 }
 
 
-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());