]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetcite.C
fix #832
[lyx.git] / src / insets / insetcite.C
index 1be81b58d24850d173602d5823fb9d7de621212d..419cf6f21958eb1613de8510f1b2a9d9919cbe7d 100644 (file)
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
 #include "insetcite.h"
+#include "funcrequest.h"
 #include "buffer.h"
 #include "BufferView.h"
 #include "LaTeXFeatures.h"
-#include "frontends/LyXView.h"
-#include "debug.h"
-#include "gettext.h"
 
 #include "frontends/controllers/biblio.h"
-#include "frontends/Dialogs.h"
 
-#include "support/filetools.h"
 #include "support/lstrings.h"
-#include "support/path.h"
-#include "support/os.h"
-#include "support/lstrings.h"
-#include "support/LAssert.h"
 
 #include <map>
 
@@ -69,7 +57,8 @@ string const getNatbibLabel(Buffer const * buffer,
        if (loadkeys) {
                // build the keylist
                typedef vector<std::pair<string, string> > InfoType;
-               InfoType bibkeys = buffer->getBibkeyList();
+               InfoType bibkeys;
+               buffer->fillWithBibKeys(bibkeys);
 
                InfoType::const_iterator bit  = bibkeys.begin();
                InfoType::const_iterator bend = bibkeys.end();
@@ -130,9 +119,9 @@ string const getNatbibLabel(Buffer const * buffer,
        // puctuation mark separating citation entries.
        char const * const sep = ";";
 
-       string const op_str(string(1, ' ')  + string(1, op));
-       string const cp_str(string(1, cp)   + string(1, ' '));
-       string const sep_str(string(sep) + " ");
+       string const op_str(' ' + string(1, op));
+       string const cp_str(string(1, cp) + ' ');
+       string const sep_str(string(sep) + ' ');
 
        string label;
        vector<string> keys = getVectorFromString(keyList);
@@ -214,7 +203,7 @@ string const getBasicLabel(string const & keyList, string const & after)
 
        if (contains(keys, ",")) {
                // Final comma allows while loop to cover all keys
-               keys = ltrim(split(keys, label, ',')) + ",";
+               keys = ltrim(split(keys, label, ',')) + ',';
                while (contains(keys, ",")) {
                        string key;
                        keys = ltrim(split(keys, key, ','));
@@ -226,7 +215,7 @@ string const getBasicLabel(string const & keyList, string const & after)
        if (!after.empty())
                label += ", " + after;
 
-       return "[" + label + "]";
+       return '[' + label + ']';
 }
 
 } // anon namespace
@@ -237,6 +226,13 @@ InsetCitation::InsetCitation(InsetCommandParams const & p, bool)
 {}
 
 
+InsetCitation::~InsetCitation()
+{
+       InsetCommandMailer mailer("citation", *this);
+       mailer.hideDialog();
+}
+
+
 string const InsetCitation::generateLabel(Buffer const * buffer) const
 {
        string const before = string();
@@ -322,19 +318,20 @@ void InsetCitation::setLoadingBuffer(Buffer const * buffer, bool state) const
 }
 
 
-void InsetCitation::edit(BufferView * bv, int, int, mouse_button::state)
+dispatch_result InsetCitation::localDispatch(FuncRequest const & cmd)
 {
-       // A call to edit() indicates that we're no longer loading the
-       // buffer but doing some real work.
-       setLoadingBuffer(bv->buffer(), false);
-
-       bv->owner()->getDialogs().showCitation(this);
-}
-
-
-void InsetCitation::edit(BufferView * bv, bool)
-{
-       edit(bv, 0, 0, mouse_button::none);
+       switch (cmd.action) {
+               case LFUN_INSET_EDIT:
+                       // A call to edit indicates that we're no longer loading the
+                       // buffer but doing some real work.
+                       setLoadingBuffer(cmd.view()->buffer(), false);
+                       InsetCommandMailer("citation", *this).showDialog(cmd.view());
+                       break;
+
+               default:
+                       return UNDISPATCHED;
+       }
+       return DISPATCHED;
 }
 
 
@@ -375,14 +372,14 @@ int InsetCitation::latex(Buffer const * buffer, ostream & os,
        string const before = string();
        string const after  = getOptions();
        if (!before.empty() && buffer->params.use_natbib)
-               os << "[" << before << "][" << after << "]";
+               os << '[' << before << "][" << after << ']';
        else if (!after.empty())
-               os << "[" << after << "]";
+               os << '[' << after << ']';
 #else
        // and the cleaned up equvalent, should it just be changed? (Lgb)
        string const after  = getOptions();
        if (!after.empty())
-               os << "[" << after << "]";
+               os << '[' << after << ']';
 #endif
        string::const_iterator it  = getContents().begin();
        string::const_iterator end = getContents().end();
@@ -396,7 +393,7 @@ int InsetCitation::latex(Buffer const * buffer, ostream & os,
                        content += *it;
        }
 
-       os << "{" << content << "}";
+       os << '{' << content << '}';
 
        return 0;
 }