2008-07-19 17:23:13 +00:00
|
|
|
|
This is one of a series of patches that will merge the layout modules development in personal/branches/rgheck back into the tree.
Design goal: Allow the use of layout "modules", which are to LaTeX packages as layout files are to LaTeX document classes. Thus, one could have a module that defined certain character styles, environments, commands, or what have you, and include it in various documents, each of which uses a different document class, without having to modify the layout files themselves. For example, a theorems.module could be used with article.layout to provide support for theorem-type environments, without having to modify article.layout itself, and the same module could be used with book.layout, etc.
This third patch just re-factors some code presently in QCitation*. (It also incorporates some bug fixes that have been committed separately.) We're going to use essentially the same set of widgets for choosing modules that is used for choosing citation keys, so we pull the controlling logic out into a new class, QSelectionManager. I did not make this a QWidget. That seemed to me to be overkill, and it would have made things much more complicated, I think...and I'm not all that experienced with Qt, anyway. Anyone who wants to do that is of course welcome.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19860 a592a061-630c-0410-9148-cb99ea01b6c8
2007-08-28 16:49:40 +00:00
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiCitation.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Angus Leeming
|
|
|
|
* \author Kalle Dalheimer
|
2007-03-25 01:32:12 +00:00
|
|
|
* \author Abdelrazak Younes
|
2007-08-31 22:37:05 +00:00
|
|
|
* \author Richard Heck
|
2006-03-05 17:24:44 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiCitation.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-05-06 13:50:37 +00:00
|
|
|
#include "GuiSelectionManager.h"
|
2007-03-25 01:32:12 +00:00
|
|
|
#include "qt_helpers.h"
|
2008-05-06 13:50:37 +00:00
|
|
|
|
2007-10-06 11:33:33 +00:00
|
|
|
#include "Buffer.h"
|
2011-05-26 17:33:36 +00:00
|
|
|
#include "BufferView.h"
|
2008-05-06 13:50:37 +00:00
|
|
|
#include "BiblioInfo.h"
|
2007-10-06 11:33:33 +00:00
|
|
|
#include "BufferParams.h"
|
2008-04-20 09:24:14 +00:00
|
|
|
#include "FuncRequest.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-07 14:59:01 +00:00
|
|
|
#include "insets/InsetCommand.h"
|
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
|
|
|
#include "support/docstring.h"
|
|
|
|
#include "support/gettext.h"
|
|
|
|
#include "support/lstrings.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-08-31 22:37:05 +00:00
|
|
|
#include <QCloseEvent>
|
2008-05-14 14:37:33 +00:00
|
|
|
#include <QSettings>
|
2007-12-09 22:35:04 +00:00
|
|
|
#include <QShowEvent>
|
2008-05-14 14:37:33 +00:00
|
|
|
#include <QVariant>
|
2007-08-31 22:37:05 +00:00
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
2007-08-31 22:37:05 +00:00
|
|
|
#undef KeyPress
|
|
|
|
|
2010-06-29 17:09:40 +00:00
|
|
|
#include "support/regex.h"
|
2007-10-06 11:33:33 +00:00
|
|
|
|
2007-08-31 22:37:05 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 19:57:42 +00:00
|
|
|
using namespace lyx::support;
|
2006-04-11 08:26:43 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2013-10-07 22:59:05 +00:00
|
|
|
// FIXME THREAD
|
|
|
|
// I am guessing that it would not hurt to make these private members.
|
2012-03-01 00:41:30 +00:00
|
|
|
static vector<string> citeCmds_;
|
|
|
|
static vector<CitationStyle> citeStyles_;
|
2007-10-06 11:33:33 +00:00
|
|
|
|
|
|
|
|
2007-08-31 22:37:05 +00:00
|
|
|
template<typename String>
|
|
|
|
static QStringList to_qstring_list(vector<String> const & v)
|
2006-03-25 21:26:09 +00:00
|
|
|
{
|
2006-04-11 08:26:43 +00:00
|
|
|
QStringList qlist;
|
|
|
|
|
2007-04-25 16:39:21 +00:00
|
|
|
for (size_t i = 0; i != v.size(); ++i) {
|
2006-03-25 21:26:09 +00:00
|
|
|
if (v[i].empty())
|
|
|
|
continue;
|
2006-10-21 00:16:43 +00:00
|
|
|
qlist.append(lyx::toqstr(v[i]));
|
2006-03-25 21:26:09 +00:00
|
|
|
}
|
2006-04-11 08:26:43 +00:00
|
|
|
return qlist;
|
2006-03-25 21:26:09 +00:00
|
|
|
}
|
|
|
|
|
2007-03-25 01:32:12 +00:00
|
|
|
|
2007-08-31 22:37:05 +00:00
|
|
|
static vector<lyx::docstring> to_docstring_vector(QStringList const & qlist)
|
2007-03-25 01:32:12 +00:00
|
|
|
{
|
2007-08-20 16:30:02 +00:00
|
|
|
vector<lyx::docstring> v;
|
2007-03-25 10:32:22 +00:00
|
|
|
for (int i = 0; i != qlist.size(); ++i) {
|
2007-03-25 01:32:12 +00:00
|
|
|
if (qlist[i].isEmpty())
|
|
|
|
continue;
|
2007-08-20 16:30:02 +00:00
|
|
|
v.push_back(lyx::qstring_to_ucs4(qlist[i]));
|
2007-03-25 01:32:12 +00:00
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2006-04-11 08:26:43 +00:00
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
GuiCitation::GuiCitation(GuiView & lv)
|
2008-05-06 13:50:37 +00:00
|
|
|
: DialogView(lv, "citation", qt_("Citation")),
|
2008-04-20 09:24:14 +00:00
|
|
|
params_(insetCode("citation"))
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
|
|
|
connect(citationStyleCO, SIGNAL(activated(int)),
|
2007-12-20 15:46:14 +00:00
|
|
|
this, SLOT(on_citationStyleCO_currentIndexChanged(int)));
|
2007-08-31 22:37:05 +00:00
|
|
|
connect(fulllistCB, SIGNAL(clicked()),
|
|
|
|
this, SLOT(changed()));
|
|
|
|
connect(forceuppercaseCB, SIGNAL(clicked()),
|
|
|
|
this, SLOT(changed()));
|
2007-10-06 11:33:33 +00:00
|
|
|
connect(textBeforeED, SIGNAL(textChanged(QString)),
|
2012-03-01 00:41:30 +00:00
|
|
|
this, SLOT(updateStyles()));
|
2007-10-06 11:33:33 +00:00
|
|
|
connect(textAfterED, SIGNAL(textChanged(QString)),
|
2012-03-01 00:41:30 +00:00
|
|
|
this, SLOT(updateStyles()));
|
2011-12-03 22:15:11 +00:00
|
|
|
connect(findLE, SIGNAL(returnPressed()),
|
2008-04-24 18:30:31 +00:00
|
|
|
this, SLOT(on_searchPB_clicked()));
|
|
|
|
connect(textBeforeED, SIGNAL(returnPressed()),
|
|
|
|
this, SLOT(on_okPB_clicked()));
|
|
|
|
connect(textAfterED, SIGNAL(returnPressed()),
|
|
|
|
this, SLOT(on_okPB_clicked()));
|
2008-06-06 16:02:52 +00:00
|
|
|
|
2011-12-03 22:15:11 +00:00
|
|
|
selectionManager = new GuiSelectionManager(availableLV, selectedLV,
|
2008-05-06 14:33:38 +00:00
|
|
|
addPB, deletePB, upPB, downPB, &available_model_, &selected_model_);
|
2007-08-31 22:37:05 +00:00
|
|
|
connect(selectionManager, SIGNAL(selectionChanged()),
|
|
|
|
this, SLOT(setCitedKeys()));
|
|
|
|
connect(selectionManager, SIGNAL(updateHook()),
|
2008-05-06 13:50:37 +00:00
|
|
|
this, SLOT(updateControls()));
|
2007-08-31 22:37:05 +00:00
|
|
|
connect(selectionManager, SIGNAL(okHook()),
|
2007-10-06 11:33:33 +00:00
|
|
|
this, SLOT(on_okPB_clicked()));
|
2007-08-31 22:37:05 +00:00
|
|
|
|
2010-11-24 14:45:27 +00:00
|
|
|
setFocusProxy(availableLV);
|
2007-08-31 22:37:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-29 13:57:07 +00:00
|
|
|
GuiCitation::~GuiCitation()
|
|
|
|
{
|
|
|
|
delete selectionManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 11:33:33 +00:00
|
|
|
void GuiCitation::closeEvent(QCloseEvent * e)
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
clearSelection();
|
2008-06-06 15:53:02 +00:00
|
|
|
DialogView::closeEvent(e);
|
2007-08-31 22:37:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 11:33:33 +00:00
|
|
|
void GuiCitation::applyView()
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
2008-04-26 08:07:46 +00:00
|
|
|
int const choice = max(0, citationStyleCO->currentIndex());
|
2007-08-31 22:37:05 +00:00
|
|
|
style_ = choice;
|
|
|
|
bool const full = fulllistCB->isChecked();
|
|
|
|
bool const force = forceuppercaseCB->isChecked();
|
|
|
|
|
|
|
|
QString const before = textBeforeED->text();
|
|
|
|
QString const after = textAfterED->text();
|
|
|
|
|
2014-12-19 10:35:37 +00:00
|
|
|
applyParams(choice, full, force, before, after);
|
2007-08-31 22:37:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-09 22:35:04 +00:00
|
|
|
void GuiCitation::showEvent(QShowEvent * e)
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
|
|
|
findLE->clear();
|
|
|
|
availableLV->setFocus();
|
2008-05-06 13:50:37 +00:00
|
|
|
DialogView::showEvent(e);
|
2007-08-31 22:37:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-30 08:09:21 +00:00
|
|
|
void GuiCitation::on_citationTB_currentChanged(int i)
|
|
|
|
{
|
|
|
|
if (i == 0)
|
|
|
|
findLE->setFocus();
|
|
|
|
else if (citationStyleCO->isEnabled())
|
|
|
|
citationStyleCO->setFocus();
|
|
|
|
else
|
|
|
|
textAfterED->setFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 11:33:33 +00:00
|
|
|
void GuiCitation::on_okPB_clicked()
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
2007-09-03 20:28:26 +00:00
|
|
|
applyView();
|
2007-09-05 20:33:29 +00:00
|
|
|
clearSelection();
|
2007-12-09 22:35:04 +00:00
|
|
|
hide();
|
2007-08-31 22:37:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 11:33:33 +00:00
|
|
|
void GuiCitation::on_cancelPB_clicked()
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
clearSelection();
|
2007-12-09 22:35:04 +00:00
|
|
|
hide();
|
2007-08-31 22:37:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 11:33:33 +00:00
|
|
|
void GuiCitation::on_applyPB_clicked()
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
2007-09-03 20:28:26 +00:00
|
|
|
applyView();
|
2007-08-31 22:37:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 11:33:33 +00:00
|
|
|
void GuiCitation::on_restorePB_clicked()
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
init();
|
2007-08-31 22:37:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-19 17:23:13 +00:00
|
|
|
void GuiCitation::updateControls()
|
|
|
|
{
|
|
|
|
BiblioInfo const & bi = bibInfo();
|
|
|
|
updateControls(bi);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
// The main point of separating this out is that the fill*() methods
|
|
|
|
// called in update() do not need to be called for INTERNAL updates,
|
|
|
|
// such as when addPB is pressed, as the list of fields, entries, etc,
|
2012-03-01 00:41:30 +00:00
|
|
|
// will not have changed.
|
2008-07-19 17:23:13 +00:00
|
|
|
void GuiCitation::updateControls(BiblioInfo const & bi)
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
2010-03-24 12:04:24 +00:00
|
|
|
QModelIndex idx = selectionManager->getSelectedIndex();
|
|
|
|
updateInfo(bi, idx);
|
2012-03-01 00:41:30 +00:00
|
|
|
selectionManager->update();
|
2007-08-31 22:37:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-01 00:41:30 +00:00
|
|
|
void GuiCitation::updateFormatting(CitationStyle currentStyle)
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
2012-03-01 00:41:30 +00:00
|
|
|
bool const force = currentStyle.forceUpperCase;
|
|
|
|
bool const full = currentStyle.fullAuthorList &&
|
|
|
|
documentBuffer().params().fullAuthorList();
|
|
|
|
bool const textbefore = currentStyle.textBefore;
|
|
|
|
bool const textafter = currentStyle.textAfter;
|
2007-08-31 22:37:05 +00:00
|
|
|
|
2012-03-01 00:41:30 +00:00
|
|
|
bool const haveSelection =
|
2007-08-31 22:37:05 +00:00
|
|
|
selectedLV->model()->rowCount() > 0;
|
|
|
|
|
2012-03-01 00:41:30 +00:00
|
|
|
forceuppercaseCB->setEnabled(force && haveSelection);
|
|
|
|
fulllistCB->setEnabled(full && haveSelection);
|
|
|
|
textBeforeED->setEnabled(textbefore && haveSelection);
|
|
|
|
textBeforeLA->setEnabled(textbefore && haveSelection);
|
|
|
|
textAfterED->setEnabled(textafter && haveSelection);
|
|
|
|
textAfterLA->setEnabled(textafter && haveSelection);
|
2007-12-20 15:46:14 +00:00
|
|
|
citationStyleCO->setEnabled(haveSelection);
|
|
|
|
citationStyleLA->setEnabled(haveSelection);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-01 00:41:30 +00:00
|
|
|
// Update the styles for the style combo, citationStyleCO, and mark the
|
|
|
|
// settings as changed. Called upon changing the cited keys (including
|
|
|
|
// merely reordering the keys) or editing the text before/after fields.
|
|
|
|
void GuiCitation::updateStyles()
|
2007-12-20 15:46:14 +00:00
|
|
|
{
|
2012-03-01 00:41:30 +00:00
|
|
|
BiblioInfo const & bi = bibInfo();
|
|
|
|
updateStyles(bi);
|
|
|
|
changed();
|
2007-08-31 22:37:05 +00:00
|
|
|
}
|
|
|
|
|
2010-03-24 13:51:47 +00:00
|
|
|
|
2012-03-01 00:41:30 +00:00
|
|
|
// Update the styles for the style combo, citationStyleCO.
|
|
|
|
void GuiCitation::updateStyles(BiblioInfo const & bi)
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
2008-05-06 14:33:38 +00:00
|
|
|
QStringList selected_keys = selected_model_.stringList();
|
2010-03-24 13:51:47 +00:00
|
|
|
int curr = selectedLV->model()->rowCount() - 1;
|
|
|
|
|
|
|
|
if (curr < 0 || selected_keys.empty()) {
|
|
|
|
citationStyleCO->clear();
|
2007-08-31 22:37:05 +00:00
|
|
|
citationStyleCO->setEnabled(false);
|
|
|
|
citationStyleLA->setEnabled(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-23 14:59:12 +00:00
|
|
|
static const size_t max_length = 80;
|
|
|
|
QStringList sty = citationStyles(bi, max_length);
|
2007-08-31 22:37:05 +00:00
|
|
|
|
2011-12-03 22:15:11 +00:00
|
|
|
if (sty.isEmpty()) {
|
2010-03-24 13:51:47 +00:00
|
|
|
// some error
|
|
|
|
citationStyleCO->setEnabled(false);
|
|
|
|
citationStyleLA->setEnabled(false);
|
2010-03-24 14:50:20 +00:00
|
|
|
citationStyleCO->clear();
|
2007-08-31 22:37:05 +00:00
|
|
|
return;
|
2010-03-24 13:51:47 +00:00
|
|
|
}
|
2011-12-03 22:15:11 +00:00
|
|
|
|
2010-03-24 14:50:20 +00:00
|
|
|
citationStyleCO->blockSignals(true);
|
2011-12-03 22:15:11 +00:00
|
|
|
|
2010-03-24 14:50:20 +00:00
|
|
|
// save old index
|
|
|
|
int const oldIndex = citationStyleCO->currentIndex();
|
|
|
|
citationStyleCO->clear();
|
2007-08-31 22:37:05 +00:00
|
|
|
citationStyleCO->insertItems(0, sty);
|
2010-03-24 13:51:47 +00:00
|
|
|
citationStyleCO->setEnabled(true);
|
|
|
|
citationStyleLA->setEnabled(true);
|
2010-03-24 14:50:20 +00:00
|
|
|
// restore old index
|
2007-08-31 22:37:05 +00:00
|
|
|
if (oldIndex != -1 && oldIndex < citationStyleCO->count())
|
|
|
|
citationStyleCO->setCurrentIndex(oldIndex);
|
2010-03-24 14:50:20 +00:00
|
|
|
|
|
|
|
citationStyleCO->blockSignals(false);
|
2007-08-31 22:37:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-19 17:23:13 +00:00
|
|
|
void GuiCitation::fillFields(BiblioInfo const & bi)
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
|
|
|
fieldsCO->blockSignals(true);
|
|
|
|
int const oldIndex = fieldsCO->currentIndex();
|
|
|
|
fieldsCO->clear();
|
2008-07-19 17:23:13 +00:00
|
|
|
QStringList const fields = to_qstring_list(bi.getFields());
|
2010-01-24 19:16:44 +00:00
|
|
|
fieldsCO->insertItem(0, qt_("All fields"));
|
2007-08-31 22:37:05 +00:00
|
|
|
fieldsCO->insertItem(1, qt_("Keys"));
|
|
|
|
fieldsCO->insertItems(2, fields);
|
|
|
|
if (oldIndex != -1 && oldIndex < fieldsCO->count())
|
|
|
|
fieldsCO->setCurrentIndex(oldIndex);
|
|
|
|
fieldsCO->blockSignals(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-19 17:23:13 +00:00
|
|
|
void GuiCitation::fillEntries(BiblioInfo const & bi)
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
|
|
|
entriesCO->blockSignals(true);
|
|
|
|
int const oldIndex = entriesCO->currentIndex();
|
|
|
|
entriesCO->clear();
|
2008-07-19 17:23:13 +00:00
|
|
|
QStringList const entries = to_qstring_list(bi.getEntries());
|
2010-01-24 19:16:44 +00:00
|
|
|
entriesCO->insertItem(0, qt_("All entry types"));
|
2007-08-31 22:37:05 +00:00
|
|
|
entriesCO->insertItems(1, entries);
|
|
|
|
if (oldIndex != -1 && oldIndex < entriesCO->count())
|
|
|
|
entriesCO->setCurrentIndex(oldIndex);
|
|
|
|
entriesCO->blockSignals(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-24 12:04:24 +00:00
|
|
|
bool GuiCitation::isSelected(QModelIndex const & idx)
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
|
|
|
QString const str = idx.data().toString();
|
2008-05-06 14:33:38 +00:00
|
|
|
return selected_model_.stringList().contains(str);
|
2007-08-31 22:37:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 11:33:33 +00:00
|
|
|
void GuiCitation::setButtons()
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
|
|
|
int const srows = selectedLV->model()->rowCount();
|
|
|
|
applyPB->setEnabled(srows > 0);
|
|
|
|
okPB->setEnabled(srows > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-19 17:23:13 +00:00
|
|
|
void GuiCitation::updateInfo(BiblioInfo const & bi, QModelIndex const & idx)
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
2008-07-19 17:23:13 +00:00
|
|
|
if (!idx.isValid() || bi.empty()) {
|
2007-08-31 22:37:05 +00:00
|
|
|
infoML->document()->clear();
|
2008-05-06 14:33:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString const keytxt = toqstr(
|
2011-05-27 21:54:23 +00:00
|
|
|
bi.getInfo(qstring_to_ucs4(idx.data().toString()), documentBuffer(), true));
|
2010-03-27 13:54:14 +00:00
|
|
|
infoML->document()->setHtml(keytxt);
|
2007-08-31 22:37:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 11:33:33 +00:00
|
|
|
void GuiCitation::findText(QString const & text, bool reset)
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
|
|
|
//"All Fields" and "Keys" are the first two
|
2011-12-03 22:15:11 +00:00
|
|
|
int index = fieldsCO->currentIndex() - 2;
|
2008-07-19 17:23:13 +00:00
|
|
|
BiblioInfo const & bi = bibInfo();
|
|
|
|
vector<docstring> const & fields = bi.getFields();
|
2007-08-31 22:37:05 +00:00
|
|
|
docstring field;
|
2011-12-03 22:15:11 +00:00
|
|
|
|
2007-08-31 22:37:05 +00:00
|
|
|
if (index <= -1 || index >= int(fields.size()))
|
|
|
|
//either "All Fields" or "Keys" or an invalid value
|
|
|
|
field = from_ascii("");
|
|
|
|
else
|
|
|
|
field = fields[index];
|
2011-12-03 22:15:11 +00:00
|
|
|
|
2007-08-31 22:37:05 +00:00
|
|
|
//Was it "Keys"?
|
|
|
|
bool const onlyKeys = index == -1;
|
2011-12-03 22:15:11 +00:00
|
|
|
|
2007-08-31 22:37:05 +00:00
|
|
|
//"All Entry Types" is first.
|
2011-12-03 22:15:11 +00:00
|
|
|
index = entriesCO->currentIndex() - 1;
|
2008-07-19 17:23:13 +00:00
|
|
|
vector<docstring> const & entries = bi.getEntries();
|
2008-02-14 07:10:12 +00:00
|
|
|
docstring entry_type;
|
2007-08-31 22:37:05 +00:00
|
|
|
if (index < 0 || index >= int(entries.size()))
|
2008-02-14 07:10:12 +00:00
|
|
|
entry_type = from_ascii("");
|
2011-12-03 22:15:11 +00:00
|
|
|
else
|
2008-02-14 07:10:12 +00:00
|
|
|
entry_type = entries[index];
|
2011-12-03 22:15:11 +00:00
|
|
|
|
2007-08-31 22:37:05 +00:00
|
|
|
bool const case_sentitive = caseCB->checkState();
|
|
|
|
bool const reg_exp = regexCB->checkState();
|
2011-12-03 22:15:11 +00:00
|
|
|
findKey(bi, text, onlyKeys, field, entry_type,
|
2007-08-31 22:37:05 +00:00
|
|
|
case_sentitive, reg_exp, reset);
|
|
|
|
//FIXME
|
2011-12-03 22:15:11 +00:00
|
|
|
//It'd be nice to save and restore the current selection in
|
2007-08-31 22:37:05 +00:00
|
|
|
//availableLV. Currently, we get an automatic reset, since the
|
|
|
|
//model is reset.
|
2011-12-03 22:15:11 +00:00
|
|
|
|
2008-07-19 17:23:13 +00:00
|
|
|
updateControls(bi);
|
2007-08-31 22:37:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 11:33:33 +00:00
|
|
|
void GuiCitation::on_fieldsCO_currentIndexChanged(int /*index*/)
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
|
|
|
findText(findLE->text(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 11:33:33 +00:00
|
|
|
void GuiCitation::on_entriesCO_currentIndexChanged(int /*index*/)
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
|
|
|
findText(findLE->text(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-20 15:46:14 +00:00
|
|
|
void GuiCitation::on_citationStyleCO_currentIndexChanged(int index)
|
|
|
|
{
|
|
|
|
if (index >= 0 && index < citationStyleCO->count()) {
|
2012-03-01 00:41:30 +00:00
|
|
|
vector<CitationStyle> const & styles = citeStyles_;
|
2007-12-20 15:46:14 +00:00
|
|
|
updateFormatting(styles[index]);
|
2012-03-01 00:41:30 +00:00
|
|
|
changed();
|
2007-12-20 15:46:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 11:33:33 +00:00
|
|
|
void GuiCitation::on_findLE_textChanged(const QString & text)
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
2008-04-25 19:38:31 +00:00
|
|
|
bool const searchAsWeGo = (asTypeCB->checkState() == Qt::Checked);
|
|
|
|
searchPB->setDisabled(text.isEmpty() || searchAsWeGo);
|
|
|
|
if (!text.isEmpty()) {
|
|
|
|
if (searchAsWeGo)
|
|
|
|
findText(findLE->text());
|
2008-04-24 18:30:31 +00:00
|
|
|
return;
|
2008-04-25 19:38:31 +00:00
|
|
|
}
|
2008-04-24 18:30:31 +00:00
|
|
|
findText(findLE->text());
|
|
|
|
findLE->setFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiCitation::on_searchPB_clicked()
|
|
|
|
{
|
2008-04-25 19:38:31 +00:00
|
|
|
findText(findLE->text(), true);
|
2007-08-31 22:37:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 11:33:33 +00:00
|
|
|
void GuiCitation::on_caseCB_stateChanged(int)
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
|
|
|
findText(findLE->text());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 11:33:33 +00:00
|
|
|
void GuiCitation::on_regexCB_stateChanged(int)
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
|
|
|
findText(findLE->text());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-25 19:38:31 +00:00
|
|
|
void GuiCitation::on_asTypeCB_stateChanged(int)
|
|
|
|
{
|
|
|
|
bool const searchAsWeGo = (asTypeCB->checkState() == Qt::Checked);
|
|
|
|
searchPB->setDisabled(findLE->text().isEmpty() || searchAsWeGo);
|
|
|
|
if (searchAsWeGo)
|
|
|
|
findText(findLE->text(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 11:33:33 +00:00
|
|
|
void GuiCitation::changed()
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
|
|
|
setButtons();
|
|
|
|
}
|
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
|
2014-12-19 10:35:37 +00:00
|
|
|
void GuiCitation::applyParams(int const choice, bool full, bool force,
|
2007-09-05 20:33:29 +00:00
|
|
|
QString before, QString after)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-03-25 01:32:12 +00:00
|
|
|
if (cited_keys_.isEmpty())
|
2006-06-28 08:28:16 +00:00
|
|
|
return;
|
2006-04-11 08:26:43 +00:00
|
|
|
|
2012-03-01 00:41:30 +00:00
|
|
|
vector<CitationStyle> const & styles = citeStyles_;
|
|
|
|
|
|
|
|
CitationStyle cs = styles[choice];
|
|
|
|
|
|
|
|
if (!cs.textBefore)
|
2007-12-20 15:46:14 +00:00
|
|
|
before.clear();
|
2012-03-01 00:41:30 +00:00
|
|
|
if (!cs.textAfter)
|
2007-12-20 15:46:14 +00:00
|
|
|
after.clear();
|
2012-03-01 00:41:30 +00:00
|
|
|
|
|
|
|
cs.forceUpperCase &= force;
|
|
|
|
cs.fullAuthorList &= full;
|
|
|
|
string const command = citationStyleToString(cs);
|
2006-04-11 08:26:43 +00:00
|
|
|
|
2007-10-07 14:59:01 +00:00
|
|
|
params_.setCmdName(command);
|
|
|
|
params_["key"] = qstring_to_ucs4(cited_keys_.join(","));
|
|
|
|
params_["before"] = qstring_to_ucs4(before);
|
|
|
|
params_["after"] = qstring_to_ucs4(after);
|
2007-10-06 11:33:33 +00:00
|
|
|
dispatchParams();
|
2006-03-25 21:26:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 11:33:33 +00:00
|
|
|
void GuiCitation::clearSelection()
|
2006-12-15 09:58:44 +00:00
|
|
|
{
|
2007-03-25 01:32:12 +00:00
|
|
|
cited_keys_.clear();
|
|
|
|
selected_model_.setStringList(cited_keys_);
|
2006-12-15 09:58:44 +00:00
|
|
|
}
|
|
|
|
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2007-10-06 11:33:33 +00:00
|
|
|
void GuiCitation::init()
|
2006-04-11 08:26:43 +00:00
|
|
|
{
|
2006-03-25 21:26:09 +00:00
|
|
|
// Make the list of all available bibliography keys
|
2008-07-19 17:23:13 +00:00
|
|
|
BiblioInfo const & bi = bibInfo();
|
|
|
|
all_keys_ = to_qstring_list(bi.getKeys());
|
2007-03-25 01:32:12 +00:00
|
|
|
available_model_.setStringList(all_keys_);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
// Ditto for the keys cited in this inset
|
2007-10-07 14:59:01 +00:00
|
|
|
QString str = toqstr(params_["key"]);
|
2007-03-25 01:32:12 +00:00
|
|
|
if (str.isEmpty())
|
|
|
|
cited_keys_.clear();
|
|
|
|
else
|
|
|
|
cited_keys_ = str.split(",");
|
|
|
|
selected_model_.setStringList(cited_keys_);
|
2012-03-01 00:41:30 +00:00
|
|
|
|
|
|
|
// Initialize the drop downs
|
|
|
|
fillEntries(bi);
|
|
|
|
fillFields(bi);
|
|
|
|
|
|
|
|
// Initialize the citation formatting
|
|
|
|
string const & cmd = params_.getCmdName();
|
|
|
|
CitationStyle const cs = citationStyleFromString(cmd);
|
|
|
|
forceuppercaseCB->setChecked(cs.forceUpperCase);
|
|
|
|
fulllistCB->setChecked(cs.fullAuthorList &&
|
|
|
|
documentBuffer().params().fullAuthorList());
|
|
|
|
textBeforeED->setText(toqstr(params_["before"]));
|
|
|
|
textAfterED->setText(toqstr(params_["after"]));
|
|
|
|
|
|
|
|
// Update the interface
|
|
|
|
updateControls(bi);
|
|
|
|
updateStyles(bi);
|
2010-03-24 13:51:47 +00:00
|
|
|
if (selected_model_.rowCount()) {
|
|
|
|
selectedLV->blockSignals(true);
|
|
|
|
selectedLV->setFocus();
|
|
|
|
QModelIndex idx = selected_model_.index(0, 0);
|
2011-12-03 22:15:11 +00:00
|
|
|
selectedLV->selectionModel()->select(idx,
|
2010-03-24 13:51:47 +00:00
|
|
|
QItemSelectionModel::ClearAndSelect);
|
|
|
|
selectedLV->blockSignals(false);
|
2011-12-03 22:15:11 +00:00
|
|
|
|
2012-03-01 00:41:30 +00:00
|
|
|
// Find the citation style
|
|
|
|
vector<string> const & cmds = citeCmds_;
|
|
|
|
vector<string>::const_iterator cit =
|
|
|
|
std::find(cmds.begin(), cmds.end(), cs.cmd);
|
|
|
|
int i = 0;
|
|
|
|
if (cit != cmds.end())
|
|
|
|
i = int(cit - cmds.begin());
|
|
|
|
|
|
|
|
// Set the style combo appropriately
|
|
|
|
citationStyleCO->blockSignals(true);
|
|
|
|
citationStyleCO->setCurrentIndex(i);
|
|
|
|
citationStyleCO->blockSignals(false);
|
|
|
|
updateFormatting(citeStyles_[i]);
|
2010-03-24 13:51:47 +00:00
|
|
|
} else
|
|
|
|
availableLV->setFocus();
|
2012-03-01 00:41:30 +00:00
|
|
|
|
|
|
|
applyPB->setEnabled(false);
|
|
|
|
okPB->setEnabled(false);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-19 17:23:13 +00:00
|
|
|
void GuiCitation::findKey(BiblioInfo const & bi,
|
|
|
|
QString const & str, bool only_keys,
|
2008-02-14 07:10:12 +00:00
|
|
|
docstring field, docstring entry_type,
|
2007-08-20 16:30:02 +00:00
|
|
|
bool case_sensitive, bool reg_exp, bool reset)
|
2006-03-25 21:26:09 +00:00
|
|
|
{
|
2013-10-07 22:59:05 +00:00
|
|
|
// FIXME THREAD
|
2007-03-25 01:32:12 +00:00
|
|
|
// Used for optimisation: store last searched string.
|
|
|
|
static QString last_searched_string;
|
|
|
|
// Used to disable the above optimisation.
|
|
|
|
static bool last_case_sensitive;
|
|
|
|
static bool last_reg_exp;
|
|
|
|
// Reset last_searched_string in case of changed option.
|
|
|
|
if (last_case_sensitive != case_sensitive
|
|
|
|
|| last_reg_exp != reg_exp) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GUI, "GuiCitation::findKey: optimisation disabled!");
|
2007-03-25 01:32:12 +00:00
|
|
|
last_searched_string.clear();
|
|
|
|
}
|
|
|
|
// save option for next search.
|
|
|
|
last_case_sensitive = case_sensitive;
|
|
|
|
last_reg_exp = reg_exp;
|
|
|
|
|
2008-04-24 18:30:31 +00:00
|
|
|
Qt::CaseSensitivity qtcase = case_sensitive ?
|
2007-03-25 01:32:12 +00:00
|
|
|
Qt::CaseSensitive: Qt::CaseInsensitive;
|
|
|
|
QStringList keys;
|
|
|
|
// If new string (str) contains the last searched one...
|
2007-08-20 16:30:02 +00:00
|
|
|
if (!reset &&
|
|
|
|
!last_searched_string.isEmpty() &&
|
|
|
|
str.size() > 1 &&
|
|
|
|
str.contains(last_searched_string, qtcase))
|
2007-03-25 01:32:12 +00:00
|
|
|
// ... then only search within already found list.
|
|
|
|
keys = available_model_.stringList();
|
|
|
|
else
|
|
|
|
// ... else search all keys.
|
|
|
|
keys = all_keys_;
|
|
|
|
// save searched string for next search.
|
|
|
|
last_searched_string = str;
|
|
|
|
|
|
|
|
QStringList result;
|
2011-12-03 22:15:11 +00:00
|
|
|
|
|
|
|
// First, filter by entry_type, which will be faster than
|
2007-08-31 22:37:05 +00:00
|
|
|
// what follows, so we may get to do that on less.
|
2007-08-20 16:30:02 +00:00
|
|
|
vector<docstring> keyVector = to_docstring_vector(keys);
|
2008-07-19 17:23:13 +00:00
|
|
|
filterByEntryType(bi, keyVector, entry_type);
|
2011-12-03 22:15:11 +00:00
|
|
|
|
2007-08-20 16:30:02 +00:00
|
|
|
if (str.isEmpty())
|
|
|
|
result = to_qstring_list(keyVector);
|
2007-03-25 01:32:12 +00:00
|
|
|
else
|
2011-12-03 22:15:11 +00:00
|
|
|
result = to_qstring_list(searchKeys(bi, keyVector, only_keys,
|
2007-08-20 16:30:02 +00:00
|
|
|
qstring_to_ucs4(str), field, case_sensitive, reg_exp));
|
2011-12-03 22:15:11 +00:00
|
|
|
|
2007-03-25 01:32:12 +00:00
|
|
|
available_model_.setStringList(result);
|
2006-03-25 21:26:09 +00:00
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-04-11 08:26:43 +00:00
|
|
|
|
2014-05-23 14:59:12 +00:00
|
|
|
QStringList GuiCitation::citationStyles(BiblioInfo const & bi, size_t max_size)
|
2006-04-11 08:26:43 +00:00
|
|
|
{
|
2012-03-01 00:41:30 +00:00
|
|
|
docstring const before = qstring_to_ucs4(textBeforeED->text());
|
|
|
|
docstring const after = qstring_to_ucs4(textAfterED->text());
|
|
|
|
vector<docstring> const keys = to_docstring_vector(cited_keys_);
|
|
|
|
vector<CitationStyle> styles = citeStyles_;
|
|
|
|
// FIXME: pass a dictionary instead of individual before, after, dialog, etc.
|
|
|
|
vector<docstring> ret = bi.getCiteStrings(keys, styles, documentBuffer(),
|
2014-05-23 14:59:12 +00:00
|
|
|
before, after, from_utf8("dialog"), max_size);
|
2012-03-01 00:41:30 +00:00
|
|
|
return to_qstring_list(ret);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-06-28 08:28:16 +00:00
|
|
|
|
2011-12-03 22:15:11 +00:00
|
|
|
void GuiCitation::setCitedKeys()
|
This is one of a series of patches that will merge the layout modules development in personal/branches/rgheck back into the tree.
Design goal: Allow the use of layout "modules", which are to LaTeX packages as layout files are to LaTeX document classes. Thus, one could have a module that defined certain character styles, environments, commands, or what have you, and include it in various documents, each of which uses a different document class, without having to modify the layout files themselves. For example, a theorems.module could be used with article.layout to provide support for theorem-type environments, without having to modify article.layout itself, and the same module could be used with book.layout, etc.
This third patch just re-factors some code presently in QCitation*. (It also incorporates some bug fixes that have been committed separately.) We're going to use essentially the same set of widgets for choosing modules that is used for choosing citation keys, so we pull the controlling logic out into a new class, QSelectionManager. I did not make this a QWidget. That seemed to me to be overkill, and it would have made things much more complicated, I think...and I'm not all that experienced with Qt, anyway. Anyone who wants to do that is of course welcome.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19860 a592a061-630c-0410-9148-cb99ea01b6c8
2007-08-28 16:49:40 +00:00
|
|
|
{
|
|
|
|
cited_keys_ = selected_model_.stringList();
|
2012-03-01 00:41:30 +00:00
|
|
|
updateStyles();
|
This is one of a series of patches that will merge the layout modules development in personal/branches/rgheck back into the tree.
Design goal: Allow the use of layout "modules", which are to LaTeX packages as layout files are to LaTeX document classes. Thus, one could have a module that defined certain character styles, environments, commands, or what have you, and include it in various documents, each of which uses a different document class, without having to modify the layout files themselves. For example, a theorems.module could be used with article.layout to provide support for theorem-type environments, without having to modify article.layout itself, and the same module could be used with book.layout, etc.
This third patch just re-factors some code presently in QCitation*. (It also incorporates some bug fixes that have been committed separately.) We're going to use essentially the same set of widgets for choosing modules that is used for choosing citation keys, so we pull the controlling logic out into a new class, QSelectionManager. I did not make this a QWidget. That seemed to me to be overkill, and it would have made things much more complicated, I think...and I'm not all that experienced with Qt, anyway. Anyone who wants to do that is of course welcome.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19860 a592a061-630c-0410-9148-cb99ea01b6c8
2007-08-28 16:49:40 +00:00
|
|
|
}
|
|
|
|
|
2007-10-06 11:33:33 +00:00
|
|
|
|
|
|
|
bool GuiCitation::initialiseParams(string const & data)
|
|
|
|
{
|
2010-10-29 00:25:28 +00:00
|
|
|
InsetCommand::string2params(data, params_);
|
2012-03-01 00:41:30 +00:00
|
|
|
citeCmds_ = documentBuffer().params().citeCommands();
|
|
|
|
citeStyles_ = documentBuffer().params().citeStyles();
|
2008-05-06 13:50:37 +00:00
|
|
|
init();
|
2007-10-06 11:33:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiCitation::clearParams()
|
|
|
|
{
|
2007-10-07 14:59:01 +00:00
|
|
|
params_.clear();
|
2007-10-06 11:33:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-19 17:23:13 +00:00
|
|
|
void GuiCitation::filterByEntryType(BiblioInfo const & bi,
|
2011-12-03 22:15:11 +00:00
|
|
|
vector<docstring> & keyVector, docstring entry_type)
|
2007-10-06 11:33:33 +00:00
|
|
|
{
|
2008-02-14 07:10:12 +00:00
|
|
|
if (entry_type.empty())
|
2007-10-06 11:33:33 +00:00
|
|
|
return;
|
2011-12-03 22:15:11 +00:00
|
|
|
|
2007-10-06 11:33:33 +00:00
|
|
|
vector<docstring>::iterator it = keyVector.begin();
|
|
|
|
vector<docstring>::iterator end = keyVector.end();
|
2008-07-19 17:23:13 +00:00
|
|
|
|
2007-10-06 11:33:33 +00:00
|
|
|
vector<docstring> result;
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
docstring const key = *it;
|
2008-07-19 17:23:13 +00:00
|
|
|
BiblioInfo::const_iterator cit = bi.find(key);
|
|
|
|
if (cit == bi.end())
|
2007-10-06 11:33:33 +00:00
|
|
|
continue;
|
2008-02-14 07:10:12 +00:00
|
|
|
if (cit->second.entryType() == entry_type)
|
2007-10-06 11:33:33 +00:00
|
|
|
result.push_back(key);
|
|
|
|
}
|
|
|
|
keyVector = result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Escape special chars.
|
|
|
|
// All characters are literals except: '.|*?+(){}[]^$\'
|
|
|
|
// These characters are literals when preceded by a "\", which is done here
|
|
|
|
// @todo: This function should be moved to support, and then the test in tests
|
|
|
|
// should be moved there as well.
|
|
|
|
static docstring escape_special_chars(docstring const & expr)
|
|
|
|
{
|
|
|
|
// Search for all chars '.|*?+(){}[^$]\'
|
2015-11-16 22:40:52 +00:00
|
|
|
// Note that '[', ']', and '\' must be escaped.
|
|
|
|
static const lyx::regex reg("[.|*?+(){}^$\\[\\]\\\\]");
|
2007-10-06 11:33:33 +00:00
|
|
|
|
2015-11-16 22:40:52 +00:00
|
|
|
// $& is an ECMAScript format expression that expands to all
|
2007-10-06 11:33:33 +00:00
|
|
|
// of the current match
|
2015-11-24 19:31:14 +00:00
|
|
|
#if defined(LYX_USE_CXX11) && defined(LYX_USE_STD_REGEX)
|
|
|
|
// To prefix a matched expression with a single literal backslash, we
|
|
|
|
// need to escape it for the C++ compiler and use:
|
|
|
|
// FIXME: UNICODE
|
|
|
|
return from_utf8(lyx::regex_replace(to_utf8(expr), reg, string("\\$&")));
|
|
|
|
#else
|
|
|
|
// A backslash in the format string starts an escape sequence in boost.
|
|
|
|
// Thus, to prefix a matched expression with a single literal backslash,
|
|
|
|
// we need to give two backslashes to the regex engine, and escape both
|
|
|
|
// for the C++ compiler and use:
|
2007-10-06 11:33:33 +00:00
|
|
|
// FIXME: UNICODE
|
2010-06-29 17:09:40 +00:00
|
|
|
return from_utf8(lyx::regex_replace(to_utf8(expr), reg, string("\\\\$&")));
|
2015-11-24 19:31:14 +00:00
|
|
|
#endif
|
2007-10-06 11:33:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-03 22:15:11 +00:00
|
|
|
vector<docstring> GuiCitation::searchKeys(BiblioInfo const & bi,
|
2007-10-06 11:33:33 +00:00
|
|
|
vector<docstring> const & keys_to_search, bool only_keys,
|
|
|
|
docstring const & search_expression, docstring field,
|
|
|
|
bool case_sensitive, bool regex)
|
|
|
|
{
|
|
|
|
vector<docstring> foundKeys;
|
|
|
|
|
2007-12-12 19:57:42 +00:00
|
|
|
docstring expr = trim(search_expression);
|
2007-10-06 11:33:33 +00:00
|
|
|
if (expr.empty())
|
|
|
|
return foundKeys;
|
|
|
|
|
|
|
|
if (!regex)
|
|
|
|
// We must escape special chars in the search_expr so that
|
2010-06-29 17:09:40 +00:00
|
|
|
// it is treated as a simple string by lyx::regex.
|
2007-10-06 11:33:33 +00:00
|
|
|
expr = escape_special_chars(expr);
|
|
|
|
|
2010-06-29 17:09:40 +00:00
|
|
|
lyx::regex reg_exp;
|
2007-12-12 10:52:23 +00:00
|
|
|
try {
|
|
|
|
reg_exp.assign(to_utf8(expr), case_sensitive ?
|
2010-06-29 17:09:40 +00:00
|
|
|
lyx::regex_constants::ECMAScript : lyx::regex_constants::icase);
|
2012-09-17 08:01:26 +00:00
|
|
|
} catch (lyx::regex_error const & e) {
|
2010-06-29 17:09:40 +00:00
|
|
|
// lyx::regex throws an exception if the regular expression is not
|
2007-12-12 10:52:23 +00:00
|
|
|
// valid.
|
2007-12-12 10:53:44 +00:00
|
|
|
LYXERR(Debug::GUI, e.what());
|
2007-12-12 10:52:23 +00:00
|
|
|
return vector<docstring>();
|
|
|
|
}
|
2007-10-06 11:33:33 +00:00
|
|
|
|
|
|
|
vector<docstring>::const_iterator it = keys_to_search.begin();
|
|
|
|
vector<docstring>::const_iterator end = keys_to_search.end();
|
|
|
|
for (; it != end; ++it ) {
|
2008-07-19 17:23:13 +00:00
|
|
|
BiblioInfo::const_iterator info = bi.find(*it);
|
|
|
|
if (info == bi.end())
|
2007-10-06 11:33:33 +00:00
|
|
|
continue;
|
2011-12-03 22:15:11 +00:00
|
|
|
|
2007-10-06 11:33:33 +00:00
|
|
|
BibTeXInfo const & kvm = info->second;
|
|
|
|
string data;
|
|
|
|
if (only_keys)
|
|
|
|
data = to_utf8(*it);
|
|
|
|
else if (field.empty())
|
2008-02-14 05:00:54 +00:00
|
|
|
data = to_utf8(*it) + ' ' + to_utf8(kvm.allData());
|
2011-12-03 22:15:11 +00:00
|
|
|
else
|
2008-11-19 04:16:12 +00:00
|
|
|
data = to_utf8(kvm[field]);
|
2011-12-03 22:15:11 +00:00
|
|
|
|
2007-10-06 11:33:33 +00:00
|
|
|
if (data.empty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
try {
|
2010-06-29 17:09:40 +00:00
|
|
|
if (lyx::regex_search(data, reg_exp))
|
2007-10-06 11:33:33 +00:00
|
|
|
foundKeys.push_back(*it);
|
|
|
|
}
|
2012-09-17 08:01:26 +00:00
|
|
|
catch (lyx::regex_error const & e) {
|
2007-12-12 10:52:23 +00:00
|
|
|
LYXERR(Debug::GUI, e.what());
|
2007-10-06 11:33:33 +00:00
|
|
|
return vector<docstring>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return foundKeys;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-20 09:24:14 +00:00
|
|
|
void GuiCitation::dispatchParams()
|
|
|
|
{
|
2010-10-29 00:25:28 +00:00
|
|
|
std::string const lfun = InsetCommand::params2string(params_);
|
2008-04-20 09:24:14 +00:00
|
|
|
dispatch(FuncRequest(getLfun(), lfun));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-25 20:03:03 +00:00
|
|
|
BiblioInfo const & GuiCitation::bibInfo() const
|
|
|
|
{
|
2011-05-27 21:54:23 +00:00
|
|
|
Buffer const & buf = documentBuffer();
|
2010-12-03 19:00:55 +00:00
|
|
|
buf.reloadBibInfoCache();
|
|
|
|
return buf.masterBibInfo();
|
2008-04-25 20:03:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-14 14:37:33 +00:00
|
|
|
void GuiCitation::saveSession() const
|
|
|
|
{
|
|
|
|
Dialog::saveSession();
|
|
|
|
QSettings settings;
|
|
|
|
settings.setValue(
|
|
|
|
sessionKey() + "/regex", regexCB->isChecked());
|
|
|
|
settings.setValue(
|
|
|
|
sessionKey() + "/casesensitive", caseCB->isChecked());
|
|
|
|
settings.setValue(
|
|
|
|
sessionKey() + "/autofind", asTypeCB->isChecked());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiCitation::restoreSession()
|
|
|
|
{
|
|
|
|
Dialog::restoreSession();
|
|
|
|
QSettings settings;
|
|
|
|
regexCB->setChecked(
|
|
|
|
settings.value(sessionKey() + "/regex").toBool());
|
|
|
|
caseCB->setChecked(
|
|
|
|
settings.value(sessionKey() + "/casesensitive").toBool());
|
|
|
|
asTypeCB->setChecked(
|
|
|
|
settings.value(sessionKey() + "/autofind").toBool());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
Dialog * createGuiCitation(GuiView & lv) { return new GuiCitation(lv); }
|
2007-10-06 11:33:33 +00:00
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-08-31 22:37:05 +00:00
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_GuiCitation.cpp"
|
2007-08-31 22:37:05 +00:00
|
|
|
|