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
|
|
|
|
2016-09-16 07:21:04 +00:00
|
|
|
#include "GuiApplication.h"
|
2008-05-06 13:50:37 +00:00
|
|
|
#include "GuiSelectionManager.h"
|
2016-03-22 21:57:17 +00:00
|
|
|
#include "LyXToolBox.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"
|
2017-01-03 16:25:41 +00:00
|
|
|
#include "TextClass.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>
|
2016-09-16 07:21:04 +00:00
|
|
|
#include <QMenu>
|
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")),
|
2016-06-12 03:39:45 +00:00
|
|
|
style_(0), params_(insetCode("citation"))
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
2016-09-16 07:21:04 +00:00
|
|
|
// The filter bar
|
|
|
|
filter_ = new FancyLineEdit(this);
|
|
|
|
filter_->setButtonPixmap(FancyLineEdit::Right, getPixmap("images/", "editclear", "svgz,png"));
|
|
|
|
filter_->setButtonVisible(FancyLineEdit::Right, true);
|
|
|
|
filter_->setButtonToolTip(FancyLineEdit::Right, qt_("Clear text"));
|
|
|
|
filter_->setAutoHideButton(FancyLineEdit::Right, true);
|
2016-09-16 11:47:26 +00:00
|
|
|
filter_->setPlaceholderText(qt_("All avail. citations"));
|
2016-09-16 07:21:04 +00:00
|
|
|
|
|
|
|
filterBarL->addWidget(filter_, 0);
|
|
|
|
findKeysLA->setBuddy(filter_);
|
|
|
|
|
|
|
|
// Add search options as button menu
|
|
|
|
regexp_ = new QAction(qt_("Regular e&xpression"), this);
|
|
|
|
regexp_->setCheckable(true);
|
|
|
|
casesense_ = new QAction(qt_("Case se&nsitive"), this);
|
|
|
|
casesense_->setCheckable(true);
|
|
|
|
instant_ = new QAction(qt_("Search as you &type"), this);
|
|
|
|
instant_->setCheckable(true);
|
2016-09-18 07:10:24 +00:00
|
|
|
instant_->setChecked(true);
|
2016-09-16 07:21:04 +00:00
|
|
|
|
|
|
|
QMenu * searchOpts = new QMenu(this);
|
|
|
|
searchOpts->addAction(regexp_);
|
|
|
|
searchOpts->addAction(casesense_);
|
|
|
|
searchOpts->addAction(instant_);
|
|
|
|
searchOptionsPB->setMenu(searchOpts);
|
|
|
|
|
2007-08-31 22:37:05 +00:00
|
|
|
connect(citationStyleCO, SIGNAL(activated(int)),
|
2007-12-20 15:46:14 +00:00
|
|
|
this, SLOT(on_citationStyleCO_currentIndexChanged(int)));
|
2017-01-03 16:25:41 +00:00
|
|
|
connect(starredCB, SIGNAL(clicked()),
|
2017-01-07 16:32:45 +00:00
|
|
|
this, SLOT(updateStyles()));
|
2007-08-31 22:37:05 +00:00
|
|
|
connect(forceuppercaseCB, SIGNAL(clicked()),
|
2017-01-07 16:21:41 +00:00
|
|
|
this, SLOT(updateStyles()));
|
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()));
|
2008-04-24 18:30:31 +00:00
|
|
|
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
|
|
|
|
2016-09-16 07:21:04 +00:00
|
|
|
connect(filter_, SIGNAL(rightButtonClicked()),
|
|
|
|
this, SLOT(resetFilter()));
|
|
|
|
connect(filter_, SIGNAL(textEdited(QString)),
|
|
|
|
this, SLOT(filterChanged(QString)));
|
|
|
|
connect(filter_, SIGNAL(returnPressed()),
|
|
|
|
this, SLOT(filterPressed()));
|
|
|
|
connect(regexp_, SIGNAL(triggered()),
|
|
|
|
this, SLOT(regexChanged()));
|
|
|
|
connect(casesense_, SIGNAL(triggered()),
|
|
|
|
this, SLOT(caseChanged()));
|
|
|
|
connect(instant_, SIGNAL(triggered(bool)),
|
|
|
|
this, SLOT(instantChanged(bool)));
|
|
|
|
|
|
|
|
setFocusProxy(filter_);
|
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;
|
2017-01-03 16:25:41 +00:00
|
|
|
bool const full = starredCB->isChecked();
|
2007-08-31 22:37:05 +00:00
|
|
|
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
|
|
|
{
|
2016-09-16 07:21:04 +00:00
|
|
|
filter_->clear();
|
2007-08-31 22:37:05 +00:00
|
|
|
availableLV->setFocus();
|
2008-05-06 13:50:37 +00:00
|
|
|
DialogView::showEvent(e);
|
2007-08-31 22:37:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
2016-09-16 07:21:04 +00:00
|
|
|
updateFilterHint();
|
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
|
|
|
{
|
2017-01-03 16:25:41 +00:00
|
|
|
BufferParams const bp = documentBuffer().params();
|
2012-03-01 00:41:30 +00:00
|
|
|
bool const force = currentStyle.forceUpperCase;
|
2017-01-03 16:25:41 +00:00
|
|
|
bool const starred = currentStyle.hasStarredVersion;
|
|
|
|
bool const full = starred && bp.fullAuthorList();
|
2012-03-01 00:41:30 +00:00
|
|
|
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);
|
2017-01-03 16:25:41 +00:00
|
|
|
starredCB->setEnabled(full && haveSelection);
|
2012-03-01 00:41:30 +00:00
|
|
|
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);
|
2017-01-03 16:25:41 +00:00
|
|
|
|
|
|
|
// Check if we have a custom string/tooltip for the starred version
|
|
|
|
if (starred && !currentStyle.stardesc.empty()) {
|
|
|
|
string val =
|
|
|
|
bp.documentClass().getCiteMacro(bp.citeEngineType(), currentStyle.stardesc);
|
2017-01-04 12:29:57 +00:00
|
|
|
docstring guistring;
|
2017-01-03 16:25:41 +00:00
|
|
|
if (!val.empty()) {
|
2017-01-04 12:29:57 +00:00
|
|
|
guistring = translateIfPossible(from_utf8(val));
|
|
|
|
starredCB->setText(toqstr(guistring));
|
2017-01-03 16:25:41 +00:00
|
|
|
starredCB->setEnabled(haveSelection);
|
|
|
|
}
|
|
|
|
if (!currentStyle.startooltip.empty()) {
|
|
|
|
val = bp.documentClass().getCiteMacro(bp.citeEngineType(),
|
|
|
|
currentStyle.startooltip);
|
2017-01-04 12:29:57 +00:00
|
|
|
if (!val.empty())
|
|
|
|
guistring = translateIfPossible(from_utf8(val));
|
2017-01-03 16:25:41 +00:00
|
|
|
}
|
2017-01-04 12:29:57 +00:00
|
|
|
// Tooltip might also be empty
|
|
|
|
starredCB->setToolTip(toqstr(guistring));
|
2017-01-03 16:25:41 +00:00
|
|
|
} else {
|
|
|
|
// This is the default meaning of the starred commands
|
|
|
|
starredCB->setText(qt_("All aut&hors"));
|
|
|
|
starredCB->setToolTip(qt_("Always list all authors (rather than using \"et al.\")"));
|
|
|
|
}
|
2007-12-20 15:46:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
2016-09-16 17:39:53 +00:00
|
|
|
int const curindex = citationStyleCO->currentIndex();
|
|
|
|
int const oldIndex = (curindex < 0) ? style_ : curindex;
|
2010-03-24 14:50:20 +00:00
|
|
|
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();
|
2016-09-16 11:47:26 +00:00
|
|
|
infoML->setToolTip(qt_("Displays a sketchy preview if a citation is selected above"));
|
2008-05-06 14:33:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-16 11:47:26 +00:00
|
|
|
infoML->setToolTip(qt_("Sketchy preview of the selected citation"));
|
2017-01-07 16:12:08 +00:00
|
|
|
CiteItem ci;
|
|
|
|
ci.richtext = true;
|
2008-05-06 14:33:38 +00:00
|
|
|
QString const keytxt = toqstr(
|
2017-01-07 16:12:08 +00:00
|
|
|
bi.getInfo(qstring_to_ucs4(idx.data().toString()), documentBuffer(), ci));
|
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
|
|
|
|
2016-09-16 07:21:04 +00:00
|
|
|
bool const case_sentitive = casesense_->isChecked();
|
|
|
|
bool const reg_exp = regexp_->isChecked();
|
|
|
|
|
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
|
|
|
{
|
2016-09-16 07:21:04 +00:00
|
|
|
findText(filter_->text(), true);
|
2007-08-31 22:37:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 11:33:33 +00:00
|
|
|
void GuiCitation::on_entriesCO_currentIndexChanged(int /*index*/)
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
2016-09-16 07:21:04 +00:00
|
|
|
findText(filter_->text(), true);
|
2007-08-31 22:37:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-16 07:21:04 +00:00
|
|
|
void GuiCitation::filterChanged(const QString & text)
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
2008-04-25 19:38:31 +00:00
|
|
|
if (!text.isEmpty()) {
|
2016-09-16 07:21:04 +00:00
|
|
|
if (instant_->isChecked())
|
|
|
|
findText(filter_->text());
|
2008-04-24 18:30:31 +00:00
|
|
|
return;
|
2008-04-25 19:38:31 +00:00
|
|
|
}
|
2016-09-16 07:21:04 +00:00
|
|
|
findText(filter_->text());
|
|
|
|
filter_->setFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiCitation::filterPressed()
|
|
|
|
{
|
|
|
|
findText(filter_->text(), true);
|
2008-04-24 18:30:31 +00:00
|
|
|
}
|
|
|
|
|
2016-09-16 07:21:04 +00:00
|
|
|
|
|
|
|
void GuiCitation::resetFilter()
|
|
|
|
{
|
|
|
|
filter_->setText(QString());
|
|
|
|
findText(filter_->text(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiCitation::caseChanged()
|
2008-04-24 18:30:31 +00:00
|
|
|
{
|
2016-09-16 07:21:04 +00:00
|
|
|
findText(filter_->text());
|
2007-08-31 22:37:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-16 07:21:04 +00:00
|
|
|
void GuiCitation::regexChanged()
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
2016-09-16 07:21:04 +00:00
|
|
|
findText(filter_->text());
|
2007-08-31 22:37:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-16 07:21:04 +00:00
|
|
|
void GuiCitation::updateFilterHint()
|
2007-08-31 22:37:05 +00:00
|
|
|
{
|
2016-09-16 07:21:04 +00:00
|
|
|
QString const hint = instant_->isChecked() ?
|
2016-09-16 11:47:26 +00:00
|
|
|
qt_("Enter string to filter the list of available citations") :
|
|
|
|
qt_("Enter string to filter the list of available citations and press <Enter>");
|
2016-09-16 07:21:04 +00:00
|
|
|
filter_->setToolTip(hint);
|
2007-08-31 22:37:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-16 07:21:04 +00:00
|
|
|
void GuiCitation::instantChanged(bool checked)
|
2008-04-25 19:38:31 +00:00
|
|
|
{
|
2016-09-16 07:21:04 +00:00
|
|
|
if (checked)
|
|
|
|
findText(filter_->text(), true);
|
|
|
|
|
|
|
|
updateFilterHint();
|
2008-04-25 19:38:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2017-01-03 16:25:41 +00:00
|
|
|
cs.hasStarredVersion &= full;
|
2012-03-01 00:41:30 +00:00
|
|
|
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();
|
2017-01-03 12:11:11 +00:00
|
|
|
CitationStyle const cs =
|
|
|
|
citationStyleFromString(cmd, documentBuffer().params());
|
2012-03-01 00:41:30 +00:00
|
|
|
forceuppercaseCB->setChecked(cs.forceUpperCase);
|
2017-01-03 16:25:41 +00:00
|
|
|
starredCB->setChecked(cs.hasStarredVersion &&
|
2012-03-01 00:41:30 +00:00
|
|
|
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 =
|
2017-01-03 12:11:11 +00:00
|
|
|
std::find(cmds.begin(), cmds.end(), cs.name);
|
2012-03-01 00:41:30 +00:00
|
|
|
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
|
2016-07-30 23:42:51 +00:00
|
|
|
// This should be moved to a class member.
|
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
|
|
|
vector<docstring> const keys = to_docstring_vector(cited_keys_);
|
|
|
|
vector<CitationStyle> styles = citeStyles_;
|
2017-01-07 16:12:08 +00:00
|
|
|
CiteItem ci;
|
|
|
|
ci.textBefore = qstring_to_ucs4(textBeforeED->text());
|
|
|
|
ci.textAfter = qstring_to_ucs4(textAfterED->text());
|
2017-01-07 16:21:41 +00:00
|
|
|
ci.forceUpperCase = forceuppercaseCB->isChecked();
|
2017-01-07 16:32:45 +00:00
|
|
|
ci.Starred = starredCB->isChecked();
|
2017-01-07 16:12:08 +00:00
|
|
|
ci.context = CiteItem::Dialog;
|
|
|
|
ci.max_size = max_size;
|
|
|
|
vector<docstring> ret = bi.getCiteStrings(keys, styles, documentBuffer(), ci);
|
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
|
2016-06-07 18:33:06 +00:00
|
|
|
#ifdef LYX_USE_STD_REGEX
|
2015-11-24 19:31:14 +00:00
|
|
|
// 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(
|
2016-09-16 07:21:04 +00:00
|
|
|
sessionKey() + "/regex", regexp_->isChecked());
|
2008-05-14 14:37:33 +00:00
|
|
|
settings.setValue(
|
2016-09-16 07:21:04 +00:00
|
|
|
sessionKey() + "/casesensitive", casesense_->isChecked());
|
2008-05-14 14:37:33 +00:00
|
|
|
settings.setValue(
|
2016-09-16 07:21:04 +00:00
|
|
|
sessionKey() + "/autofind", instant_->isChecked());
|
2016-09-16 17:39:53 +00:00
|
|
|
settings.setValue(
|
|
|
|
sessionKey() + "/citestyle", style_);
|
2008-05-14 14:37:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiCitation::restoreSession()
|
|
|
|
{
|
|
|
|
Dialog::restoreSession();
|
|
|
|
QSettings settings;
|
2016-09-16 07:21:04 +00:00
|
|
|
regexp_->setChecked(settings.value(sessionKey() + "/regex").toBool());
|
|
|
|
casesense_->setChecked(settings.value(sessionKey() + "/casesensitive").toBool());
|
|
|
|
instant_->setChecked(settings.value(sessionKey() + "/autofind").toBool());
|
2016-09-16 17:39:53 +00:00
|
|
|
style_ = settings.value(sessionKey() + "/citestyle").toInt();
|
2016-09-16 07:21:04 +00:00
|
|
|
updateFilterHint();
|
2008-05-14 14:37:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|