#include <config.h>
+#include "ControlCitation.h"
#include "QCitation.h"
-#include "QCitationDialog.h"
#include "Qt2BC.h"
#include "qt_helpers.h"
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();
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_->apply(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();
- params.setContents(fromqstr(selected_keys_.stringList().join("'")));
/*
if (dialog().controller().isBufferDependent()) {
if (!dialog().kernel().isBufferAvailable() ||
dialog().kernel().isBufferReadonly())
return;
}
-
- dialog().view().apply();
dialog().controller().dispatchParams();
if (dialog().controller().disconnectOnApply()) {
dialog().view().update();
}
*/
-// dialog().ApplyButton();
-// dialog().apply();
}
-void QCitation::build_dialog()
+QString QCitation::textBefore()
{
- dialog_.reset(new QCitationDialog(this));
+ return toqstr(params().getSecOptions());
}
-void QCitation::update_contents()
+QString QCitation::textAfter()
{
- QStringList keys;
+ return toqstr(params().getOptions());
+}
+
+void QCitation::updateModel()
+{
// 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();
return available_keys_.index(pos);
}
+
QModelIndex QCitation::findKey(QString const & str) const
{
cout << "Find text " << fromqstr(str) << endl;
return available_keys_.index(pos);
}
+
void QCitation::addKeys(QModelIndexList const & indexes)
{
- // = selectionModel->selectedIndexes();
-
QModelIndex index;
if (indexes.empty())
}
selected_keys_.setStringList(keys);
-
- changed();
}
+
void QCitation::deleteKeys(QModelIndexList const & indexes)
{
QModelIndex index;
}
selected_keys_.setStringList(keys);
-
- changed();
}
+
void QCitation::upKey(QModelIndexList const & indexes)
{
if (indexes.empty() || indexes.size() > 1)
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)
QStringList keys = selected_keys_.stringList();
keys.swap(pos, pos+1);
selected_keys_.setStringList(keys);
+}
+
+
+QStringList QCitation::citationStyles(int sel)
+{
+ string key = fromqstr(selected_keys_.stringList()[sel]);
- changed();
+ return toQStringList(getCiteStrings(key));
}
} // namespace frontend
#ifndef QCITATION_H
#define QCITATION_H
-#include "QDialogView.h"
+#include "ControlCitation.h"
#include <QStringListModel>
namespace lyx {
namespace frontend {
-class ControlCitation;
-class QCitationDialog;
-
-
-class QCitation : public QController<ControlCitation, QView<QCitationDialog> >
+class QCitation : public ControlCitation
{
public:
- friend class QCitationDialog;
///
QCitation(Dialog &);
QStringListModel * found()
{ return &found_keys_; }
+ QString textBefore();
+ QString textAfter();
+
QModelIndex findKey(QString const & str, QModelIndex const & index) const;
QModelIndex findKey(QString const & str) const;
void upKey(QModelIndexList const & indexes);
void downKey(QModelIndexList const & indexes);
-protected:
- virtual bool isValid();
+ QStringList citationStyles(int sel);
-private:
+
+ virtual bool isValid();
/// Set the Params variable for the Controller.
- virtual void apply();
- /// Build the dialog.
- virtual void build_dialog();
- /// Hide the dialog.
- virtual void hide();
+ virtual void apply(int const choice, bool const full, bool const force,
+ QString before, QString After);
+
/// Update dialog before/whilst showing it.
- virtual void update_contents();
+ virtual void updateModel();
+private:
/// available keys
QStringListModel available_keys_;
QStringListModel found_keys_;
};
+
+/** A controller for Citation dialogs.
+ */
+/*
+class Citation {
+public:
+ ///
+ Citation();
+
+ ///
+ virtual bool initialiseParams(std::string const & data);
+
+ /// clean-up on hide.
+ virtual void clearParams();
+
+ /** Disconnect from the inset when the Apply button is pressed.
+ * Allows easy insertion of multiple citations.
+ */
+/* virtual bool disconnectOnApply() const { return true; }
+
+ /// Returns a reference to the map of stored keys
+ biblio::InfoMap const & bibkeysInfo() const;
+
+ ///
+ biblio::CiteEngine_enum getEngine() const;
+
+ /// Possible citations based on this key
+ std::vector<std::string> const getCiteStrings(std::string const & key) const;
+
+ /// available CiteStyle-s (depends on availability of Natbib/Jurabib)
+ static std::vector<biblio::CiteStyle> const & getCiteStyles() {
+ return citeStyles_;
+ }
+private:
+ /// The info associated with each key
+ biblio::InfoMap bibkeysInfo_;
+
+ ///
+ static std::vector<biblio::CiteStyle> citeStyles_;
+};
+*/
} // namespace frontend
} // namespace lyx
namespace frontend {
-void updateBrowser(Q3ListBox * browser,
- vector<string> const & keys)
-{
- browser->clear();
- for (vector<string>::const_iterator it = keys.begin();
- it < keys.end(); ++it) {
- string const key = trim(*it);
- // FIXME: why the .empty() test ?
- if (!key.empty())
- browser->insertItem(toqstr(key));
- }
-}
-
-QCitationDialog::QCitationDialog(QCitation * form)
- : form_(form)
+QCitationDialog::QCitationDialog(Dialog & dialog, QCitation * form)
+ : Dialog::View(dialog, "Citation"), form_(form)
{
setupUi(this);
-/* connect(restorePB, SIGNAL(clicked()),
- form, SLOT(slotRestore()));
- connect(okPB, SIGNAL(clicked()),
- form, SLOT(slotOK()));
- connect(applyPB, SIGNAL(clicked()),
- form, SLOT(slotApply()));
- connect(closePB, SIGNAL(clicked()),
- form, SLOT(slotClose()));
-*/
+ setCaption(toqstr("LyX: " + getTitle()));
+
+/*
+
// Manage the ok, apply, restore and cancel/close buttons
- form_->bcview().setOK(okPB);
- form_->bcview().setApply(applyPB);
- form_->bcview().setCancel(closePB);
- form_->bcview().setRestore(restorePB);
-
- form_->bcview().addReadOnly(addPB);
- form_->bcview().addReadOnly(deletePB);
- form_->bcview().addReadOnly(upPB);
- form_->bcview().addReadOnly(downPB);
- form_->bcview().addReadOnly(citationStyleCO);
- form_->bcview().addReadOnly(forceuppercaseCB);
- form_->bcview().addReadOnly(fulllistCB);
- form_->bcview().addReadOnly(textBeforeED);
- form_->bcview().addReadOnly(textAfterED);
+ bcview().setOK(okPB);
+ bcview().setApply(applyPB);
+ bcview().setCancel(closePB);
+ bcview().setRestore(restorePB);
+
+ bcview().addReadOnly(addPB);
+ bcview().addReadOnly(deletePB);
+ bcview().addReadOnly(upPB);
+ bcview().addReadOnly(downPB);
+ bcview().addReadOnly(citationStyleCO);
+ bcview().addReadOnly(forceuppercaseCB);
+ bcview().addReadOnly(fulllistCB);
+ bcview().addReadOnly(textBeforeED);
+ bcview().addReadOnly(textAfterED);
+*/
selectedLV->setModel(form_->selected());
availableLV->setModel(form_->available());
// find_ = new QCitationFind(form_, this);
-
+
// connect(selectedLV, SIGNAL(doubleClicked(const QModelIndex & index)),
// form_, SLOT(on_okPB_clicked()));//SLOT(slotOK()));
}
{
}
+void QCitationDialog::apply()
+{
+ int const choice = std::max(0, citationStyleCO->currentItem());
+ bool const full = fulllistCB->isChecked();
+ bool const force = forceuppercaseCB->isChecked();
+
+ QString const before = textBeforeED->text();
+ QString const after = textAfterED->text();
+
+ form_->apply(choice, full, force, before, after);
+}
+
-void QCitationDialog::on_okPB_clicked()
+void QCitationDialog::hide()
{
- form_->apply();
accept();
}
-void QCitationDialog::on_cancelPB_clicked()
+
+void QCitationDialog::show()
{
- reject();
+ QDialog::show();
}
-void QCitationDialog::on_applyPB_clicked()
+
+bool QCitationDialog::isVisible() const
{
- form_->apply();
+ return QDialog::isVisible();
}
+
-void QCitationDialog::on_restorePB_clicked()
+void QCitationDialog::on_okPB_clicked()
{
- form_->update_contents();
+ apply();
+ accept();
}
-void QCitationDialog::apply(InsetCommandParams & params)
+void QCitationDialog::on_cancelPB_clicked()
{
- vector<biblio::CiteStyle> const & styles =
- ControlCitation::getCiteStyles();
-
- int const choice = std::max(0, citationStyleCO->currentItem());
- bool const full = fulllistCB->isChecked();
- bool const force = forceuppercaseCB->isChecked();
-
- string const command =
- biblio::CitationStyle(styles[choice], full, force)
- .asLatexStr();
-
- params.setCmdName(command);
-
- string const before = fromqstr(textBeforeED->text());
- params.setSecOptions(before);
-
- string const after = fromqstr(textAfterED->text());
- params.setOptions(after);
+ accept();
+// reject();
+}
- style_ = choice;
+void QCitationDialog::on_applyPB_clicked()
+{
+ apply();
}
+void QCitationDialog::on_restorePB_clicked()
+{
+ update();
+ bc().valid(form_->isValid() );
+}
-void QCitationDialog::update(InsetCommandParams const & params)
+void QCitationDialog::update()
{
+ form_->updateModel();
+
// No keys have been selected yet, so...
infoML->document()->clear();
setButtons();
- textBeforeED->setText(
- toqstr(params.getSecOptions()));
- textAfterED->setText(
- toqstr(params.getOptions()));
+ textBeforeED->setText(form_->textBefore());
+ textAfterED->setText(form_->textAfter());
fillStyles();
updateStyle();
-
-// find_->update();
}
void QCitationDialog::updateStyle()
{
- biblio::CiteEngine const engine = form_->controller().getEngine();
+ biblio::CiteEngine const engine = form_->getEngine();
bool const natbib_engine =
engine == biblio::ENGINE_NATBIB_AUTHORYEAR ||
engine == biblio::ENGINE_NATBIB_NUMERICAL;
forceuppercaseCB->setEnabled(natbib_engine);
textBeforeED->setEnabled(!basic_engine);
- string const & command = form_->controller().params().getCmdName();
+ string const & command = form_->params().getCmdName();
// Find the style of the citekeys
vector<biblio::CiteStyle> const & styles =
citationStyleCO->setCurrentItem(style_);
else
citationStyleCO->setCurrentItem(0);
+
fulllistCB->setChecked(false);
forceuppercaseCB->setChecked(false);
void QCitationDialog::fillStyles()
{
- if (citekeys.empty()) {
- citationStyleCO->setEnabled(false);
- citationStyleLA->setEnabled(false);
- return;
- }
-
int const orig = citationStyleCO->currentItem();
citationStyleCO->clear();
QStringList selected_keys = form_->selected()->stringList();
- if (selected_keys.empty())
+ if (selected_keys.empty()) {
+ citationStyleCO->setEnabled(false);
+ citationStyleLA->setEnabled(false);
return;
+ }
if (selectedLV->selectionModel()->selectedIndexes().empty())
return;
-
+
int curr = selectedLV->selectionModel()->selectedIndexes()[0].row();//selectedLV->currentItem();
- string key = fromqstr(selected_keys[curr]);
-
- vector<string> const & sty = form_->controller().getCiteStrings(key);
+ QStringList sty = form_->citationStyles(curr);
- biblio::CiteEngine const engine = form_->controller().getEngine();
- bool const basic_engine = engine == biblio::ENGINE_BASIC;
+ bool const basic_engine =
+ (form_->getEngine() == biblio::ENGINE_BASIC);
- citationStyleCO->setEnabled(!sty.empty() && !basic_engine);
- citationStyleLA->setEnabled(!sty.empty() && !basic_engine);
+ citationStyleCO->setEnabled(!sty.isEmpty() && !basic_engine);
+ citationStyleLA->setEnabled(!sty.isEmpty() && !basic_engine);
- for (vector<string>::const_iterator it = sty.begin();
- it != sty.end(); ++it) {
- citationStyleCO->insertItem(toqstr(*it));
- }
+ citationStyleCO->insertItems(0, sty);
if (orig != -1 && orig < citationStyleCO->count())
citationStyleCO->setCurrentItem(orig);
void QCitationDialog::setButtons()
{
- if (form_->readOnly())
- return;
+// if (form_->readOnly())
+// return;
int const row_count = selectedLV->model()->rowCount();
int sel_nr=-1;
if (! selectedLV->selectionModel()->selectedIndexes().empty()) {
- sel_nr =
+ sel_nr =
selectedLV->selectionModel()->selectedIndexes()[0].row();
}
void QCitationDialog::on_addPB_clicked()
{
form_->addKeys(availableLV->selectionModel()->selectedIndexes());
+ changed();
}
void QCitationDialog::on_deletePB_clicked()
{
- form_->addKeys(selectedLV->selectionModel()->selectedIndexes());
+ form_->deleteKeys(selectedLV->selectionModel()->selectedIndexes());
changed();
}
}
+void updateBrowser(Q3ListBox * browser,
+ vector<string> const & keys)
+{
+ browser->clear();
+
+ for (vector<string>::const_iterator it = keys.begin();
+ it < keys.end(); ++it) {
+ string const key = trim(*it);
+ // FIXME: why the .empty() test ?
+ if (!key.empty())
+ browser->insertItem(toqstr(key));
+ }
+}
+
QCitationFind::QCitationFind(QCitation * form, QWidget * parent, Qt::WFlags f)
: form_(form), QDialog(parent, f)
{
/* QStringList bibkeys = form_->available()->stringList();
- biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
+ biblio::InfoMap const & theMap = form_->bibkeysInfo();
biblio::Search const type = searchTypeCB->isChecked()
? biblio::REGEX : biblio::SIMPLE;