]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/QCitation.C
rename LFUN enum values according to their command (as used in th minibuffer/bind...
[lyx.git] / src / frontends / qt4 / QCitation.C
index 17e31a7019695f597af5649a2080d2fadc259879..22f53ce09410afd0855de2908e7aec4a41e4c55e 100644 (file)
@@ -11,8 +11,8 @@
 
 #include <config.h>
 
+#include "ControlCitation.h"
 #include "QCitation.h"
-#include "QCitationDialog.h"
 #include "Qt2BC.h"
 #include "qt_helpers.h"
 
@@ -32,16 +32,20 @@ using std::endl;
 using std::vector;
 using std::string;
 
-void toQStringList(QStringList & qlist, vector<string> const & v)
+
+QStringList toQStringList(vector<string> const & v)
 {
-       qlist.clear();
+       QStringList qlist;
+
        for (size_t i=0; i != v.size(); ++i) {
                if (v[i].empty())
                        continue;
                qlist.append(toqstr(v[i]));
        }
+       return qlist;
 }
 
+
 void toVector(vector<string> & v, const QStringList & qlist)
 {
        v.clear();
@@ -50,64 +54,84 @@ void toVector(vector<string> & v, const QStringList & qlist)
                v.push_back(fromqstr(qlist[i]));
 }
 
+
 namespace lyx {
 namespace frontend {
 
-typedef QController<ControlCitation, QView<QCitationDialog> > base_class;
-
 
 QCitation::QCitation(Dialog & parent)
-       : base_class(parent, _("Citation"))
+       : ControlCitation(parent)
 {
 }
 
 
-void QCitation::apply()
+void QCitation::apply(int const choice, bool const full, bool const force,
+                                         QString before, QString after)
 {
-       InsetCommandParams & params = controller().params();
-       dialog_->update(params);
+//     InsetCommandParams & params = params();
+
+       vector<biblio::CiteStyle> const & styles =
+               ControlCitation::getCiteStyles();
+
+       string const command =
+               biblio::CitationStyle(styles[choice], full, force)
+               .asLatexStr();
+
+       params().setContents(fromqstr(selected_keys_.stringList().join(",")));
+       params().setSecOptions(fromqstr(before));
+       params().setOptions(fromqstr(after));
+       dispatchParams();
+
+/*
+       if (dialog().controller().isBufferDependent()) {
+               if (!dialog().kernel().isBufferAvailable() ||
+                   dialog().kernel().isBufferReadonly())
+                       return;
+       }
+       dialog().controller().dispatchParams();
 
-       params.setContents(fromqstr(selected_keys_.stringList().join("'")));
+       if (dialog().controller().disconnectOnApply()) {
+               dialog().kernel().disconnect(name());
+               dialog().controller().initialiseParams(string());
+               dialog().view().update();
+       }
+*/
 }
 
 
-void QCitation::build_dialog()
+QString QCitation::textBefore()
 {
-       dialog_.reset(new QCitationDialog(this));
+       return toqstr(params().getSecOptions());
 }
 
 
-void QCitation::update_contents()
+QString QCitation::textAfter()
+{
+       return toqstr(params().getOptions());
+}
+
+
+void QCitation::updateModel()
 {
-       QStringList keys;
-       
        // Make the list of all available bibliography keys
-       toQStringList(keys,
-               biblio::getKeys(controller().bibkeysInfo()));
+       QStringList keys = toQStringList(biblio::getKeys(bibkeysInfo()));
        available_keys_.setStringList(keys);
 
        // Ditto for the keys cited in this inset
-       QString str = toqstr(controller().params().getContents());
+       QString str = toqstr(params().getContents());
        if (!str.isEmpty()) {
                keys = str.split(",");
                selected_keys_.setStringList(keys);
        }
-
-       dialog_->update(controller().params());
-
-       bc().valid(isValid());
 }
 
-void QCitation::hide()
-{
-       QDialogView::hide();
-}
 
 bool QCitation::isValid()
 {
        return selected_keys_.rowCount() > 0;
 }
 
+
 QModelIndex QCitation::findKey(QString const & str, QModelIndex const & index) const
 {
        QStringList const avail = available_keys_.stringList();
@@ -117,36 +141,41 @@ QModelIndex QCitation::findKey(QString const & str, QModelIndex const & index) c
        return available_keys_.index(pos);
 }
 
+
 QModelIndex QCitation::findKey(QString const & str) const
 {
+       cout << "Find text " << fromqstr(str) << endl;
+
        QStringList const avail = available_keys_.stringList();
-       int const pos = avail.indexOf(str);
+       QRegExp reg_exp(str);
+
+       int const pos = avail.indexOf(reg_exp);
        if (pos == -1)
                return QModelIndex();
+
+       cout << "found key " << fromqstr(avail[pos]) << " at pos " << pos << endl;
        return available_keys_.index(pos);
 }
 
+
 void QCitation::addKeys(QModelIndexList const & indexes)
 {
-       // = selectionModel->selectedIndexes();
-
        QModelIndex index;
 
        if (indexes.empty())
                return;
 
        QStringList keys = selected_keys_.stringList();
-       
+
        foreach(index, indexes) {
                if (keys.indexOf(index.data().toString()) == -1)
                        keys.append(index.data().toString());
        }
 
        selected_keys_.setStringList(keys);
-       
-       changed();
 }
 
+
 void QCitation::deleteKeys(QModelIndexList const & indexes)
 {
        QModelIndex index;
@@ -155,7 +184,7 @@ void QCitation::deleteKeys(QModelIndexList const & indexes)
                return;
 
        QStringList keys = selected_keys_.stringList();
-       
+
        foreach(index, indexes) {
                int const pos = keys.indexOf(index.data().toString());
                if (pos != -1)
@@ -163,10 +192,9 @@ void QCitation::deleteKeys(QModelIndexList const & indexes)
        }
 
        selected_keys_.setStringList(keys);
-       
-       changed();
 }
 
+
 void QCitation::upKey(QModelIndexList const & indexes)
 {
        if (indexes.empty() || indexes.size() > 1)
@@ -179,10 +207,9 @@ void QCitation::upKey(QModelIndexList const & indexes)
        QStringList keys = selected_keys_.stringList();
        keys.swap(pos, pos-1);
        selected_keys_.setStringList(keys);
-       
-       changed();
 }
 
+
 void QCitation::downKey(QModelIndexList const & indexes)
 {
        if (indexes.empty() || indexes.size() > 1)
@@ -195,14 +222,15 @@ void QCitation::downKey(QModelIndexList const & indexes)
        QStringList keys = selected_keys_.stringList();
        keys.swap(pos, pos+1);
        selected_keys_.setStringList(keys);
-       
-       changed();
 }
 
 
+QStringList QCitation::citationStyles(int sel)
+{
+       string key = fromqstr(selected_keys_.stringList()[sel]);
 
-
-
+       return toQStringList(getCiteStrings(key));
+}
 
 } // namespace frontend
 } // namespace lyx