somewhat more uniform naming

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19962 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-08-31 22:37:05 +00:00
parent fc36725282
commit d5483e3551
15 changed files with 534 additions and 597 deletions

View File

@ -30,12 +30,11 @@ HPP += GuiBranches.h
HPP += GuiBranch.h
HPP += GuiChanges.h
HPP += GuiCharacter.h
HPP += GuiCitationDialog.h
HPP += GuiCitation.h
HPP += GuiClipboard.h
HPP += GuiCommandBuffer.h
HPP += GuiCommandEdit.h
HPP += GuiDelimiterDialog.h
HPP += GuiDelimiter.h
HPP += GuiDialogView.h
HPP += GuiDocument.h
HPP += GuiErrorList.h
@ -53,7 +52,7 @@ HPP += GuiIndex.h
HPP += GuiKeySymbol.h
HPP += GuiListings.h
HPP += GuiLog.h
HPP += GuiMathMatrixDialog.h
HPP += GuiMathMatrix.h
HPP += GuiMenubar.h
HPP += GuiNomencl.h
HPP += GuiNote.h
@ -61,7 +60,6 @@ HPP += GuiPainter.h
HPP += GuiParagraph.h
HPP += GuiPopupMenu.h
HPP += GuiPrefs.h
HPP += GuiPrintDialog.h
HPP += GuiPrint.h
HPP += GuiRef.h
HPP += GuiSearch.h
@ -77,7 +75,7 @@ HPP += GuiTexinfo.h
HPP += GuiThesaurus.h
HPP += GuiToc.h
HPP += GuiToolbar.h
HPP += GuiURLDialog.h
HPP += GuiURL.h
HPP += GuiView.h
HPP += GuiViewSource.h
HPP += GuiVSpace.h
@ -115,11 +113,10 @@ CPP += GuiBranches.cpp
CPP += GuiChanges.cpp
CPP += GuiCharacter.cpp
CPP += GuiCitation.cpp
CPP += GuiCitationDialog.cpp
CPP += GuiClipboard.cpp
CPP += GuiCommandBuffer.cpp
CPP += GuiCommandEdit.cpp
CPP += GuiDelimiterDialog.cpp
CPP += GuiDelimiter.cpp
CPP += GuiDialogView.cpp
CPP += GuiDocument.cpp
CPP += GuiErrorList.cpp
@ -137,7 +134,7 @@ CPP += GuiIndex.cpp
CPP += GuiKeySymbol.cpp
CPP += GuiListings.cpp
CPP += GuiLog.cpp
CPP += GuiMathMatrixDialog.cpp
CPP += GuiMathMatrix.cpp
CPP += GuiMenubar.cpp
CPP += GuiNomencl.cpp
CPP += GuiNote.cpp
@ -146,7 +143,6 @@ CPP += GuiParagraph.cpp
CPP += GuiPopupMenu.cpp
CPP += GuiPrefs.cpp
CPP += GuiPrint.cpp
CPP += GuiPrintDialog.cpp
CPP += GuiRef.cpp
CPP += GuiSearch.cpp
CPP += GuiSelection.cpp
@ -161,7 +157,7 @@ CPP += GuiTexinfo.cpp
CPP += GuiThesaurus.cpp
CPP += GuiToc.cpp
CPP += GuiToolbar.cpp
CPP += GuiURLDialog.cpp
CPP += GuiURL.cpp
CPP += GuiView.cpp
CPP += GuiViewSource.cpp
CPP += GuiVSpace.cpp

View File

@ -859,12 +859,11 @@ src_frontends_qt4_header_files = Split('''
GuiChanges.h
GuiCharacter.h
GuiCharacter.h
GuiCitationDialog.h
GuiCitation.h
GuiClipboard.h
GuiCommandBuffer.h
GuiCommandEdit.h
GuiDelimiterDialog.h
GuiDelimiter.h
GuiDialogView.h
GuiDocument.h
GuiEmbeddedFiles.h
@ -883,7 +882,7 @@ src_frontends_qt4_header_files = Split('''
GuiKeySymbol.h
GuiListings.h
GuiLog.h
GuiMathMatrixDialog.h
GuiMathMatrix.h
GuiMenubar.h
GuiNomencl.h
GuiNote.h
@ -891,7 +890,6 @@ src_frontends_qt4_header_files = Split('''
GuiParagraph.h
GuiPopupMenu.h
GuiPrefs.h
GuiPrintDialog.h
GuiPrint.h
GuiRef.h
GuiSearch.h
@ -907,7 +905,7 @@ src_frontends_qt4_header_files = Split('''
GuiThesaurus.h
GuiToc.h
GuiToolbar.h
GuiURLDialog.h
GuiURL.h
GuiView.h
GuiViewSource.h
GuiVSpace.h
@ -947,11 +945,10 @@ src_frontends_qt4_files = Split('''
GuiChanges.cpp
GuiCharacter.cpp
GuiCitation.cpp
GuiCitationDialog.cpp
GuiClipboard.cpp
GuiCommandBuffer.cpp
GuiCommandEdit.cpp
GuiDelimiterDialog.cpp
GuiDelimiter.cpp
GuiDialogView.cpp
GuiDocument.cpp
GuiEmbeddedFiles.cpp
@ -970,7 +967,7 @@ src_frontends_qt4_files = Split('''
GuiKeySymbol.cpp
GuiListings.cpp
GuiLog.cpp
GuiMathMatrixDialog.cpp
GuiMathMatrix.cpp
GuiMenubar.cpp
GuiNomencl.cpp
GuiNote.cpp
@ -979,7 +976,6 @@ src_frontends_qt4_files = Split('''
GuiPopupMenu.cpp
GuiPrefs.cpp
GuiPrint.cpp
GuiPrintDialog.cpp
GuiRef.cpp
GuiSearch.cpp
GuiSelection.cpp
@ -994,7 +990,7 @@ src_frontends_qt4_files = Split('''
GuiThesaurus.cpp
GuiToc.cpp
GuiToolbar.cpp
GuiURLDialog.cpp
GuiURL.cpp
GuiView.cpp
GuiViewSource.cpp
GuiVSpace.cpp

View File

@ -59,9 +59,9 @@ src/frontends/qt4/GuiBranch.cpp
src/frontends/qt4/GuiBranches.cpp
src/frontends/qt4/GuiChanges.cpp
src/frontends/qt4/GuiCharacter.cpp
src/frontends/qt4/GuiCitationDialog.cpp
src/frontends/qt4/GuiCitation.cpp
src/frontends/qt4/GuiCommandBuffer.cpp
src/frontends/qt4/GuiDelimiterDialog.cpp
src/frontends/qt4/GuiDelimiter.cpp
src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/GuiERT.cpp
src/frontends/qt4/GuiExternal.cpp
@ -69,7 +69,7 @@ src/frontends/qt4/GuiFloat.cpp
src/frontends/qt4/GuiGraphics.cpp
src/frontends/qt4/GuiInclude.cpp
src/frontends/qt4/GuiListings.cpp
src/frontends/qt4/GuiMathMatrixDialog.cpp
src/frontends/qt4/GuiMathMatrix.cpp
src/frontends/qt4/GuiNote.cpp
src/frontends/qt4/GuiParagraph.cpp
src/frontends/qt4/GuiPrefs.cpp
@ -83,12 +83,12 @@ src/frontends/qt4/GuiTabular.cpp
src/frontends/qt4/GuiTabularCreate.cpp
src/frontends/qt4/GuiTexinfo.cpp
src/frontends/qt4/GuiThesaurus.cpp
src/frontends/qt4/GuiUrl.cpp
src/frontends/qt4/GuiVSpace.cpp
src/frontends/qt4/GuiView.cpp
src/frontends/qt4/GuiWrap.cpp
src/frontends/qt4/IconPalette.cpp
src/frontends/qt4/Qt2BC.h
src/frontends/qt4/UrlView.cpp
src/frontends/qt4/Validator.cpp
src/frontends/qt4/alert_pimpl.cpp
src/gettext.h

View File

@ -56,8 +56,7 @@
#include "GuiChanges.h"
#include "GuiCharacter.h"
#include "GuiCitation.h"
#include "GuiCitationDialog.h"
#include "GuiDelimiterDialog.h"
#include "GuiDelimiter.h"
#include "GuiDocument.h"
#include "GuiEmbeddedFiles.h"
#include "GuiErrorList.h"
@ -67,7 +66,7 @@
#include "GuiGraphics.h"
#include "GuiInclude.h"
#include "GuiIndex.h"
#include "GuiMathMatrixDialog.h"
#include "GuiMathMatrix.h"
#include "GuiNomencl.h"
#include "GuiListings.h"
#include "GuiLog.h"
@ -86,7 +85,7 @@
#include "GuiTexinfo.h"
#include "GuiToc.h"
#include "TocWidget.h"
#include "GuiURLDialog.h"
#include "GuiURL.h"
#include "GuiVSpace.h"
#include "GuiWrap.h"

View File

@ -6,7 +6,7 @@
* \author Angus Leeming
* \author Kalle Dalheimer
* \author Abdelrazak Younes
* \author Richard Heck (adapted to QSelectionManager)
* \author Richard Heck
*
* Full author contact details are available in file CREDITS.
*/
@ -15,21 +15,31 @@
#include "GuiCitation.h"
#include "debug.h"
#include "gettext.h"
#include "frontend_helpers.h"
#include "qt_helpers.h"
#include "support/lstrings.h"
#include "support/docstring.h"
#include "debug.h"
#include <vector>
#include <string>
#include <QCloseEvent>
#undef KeyPress
#include <algorithm>
#include <string>
#include <vector>
using std::vector;
using std::string;
template<typename String> static QStringList to_qstring_list(vector<String> const & v)
template<typename String>
static QStringList to_qstring_list(vector<String> const & v)
{
QStringList qlist;
@ -42,7 +52,7 @@ template<typename String> static QStringList to_qstring_list(vector<String> cons
}
static vector<lyx::docstring> const to_docstring_vector(QStringList const & qlist)
static vector<lyx::docstring> to_docstring_vector(QStringList const & qlist)
{
vector<lyx::docstring> v;
for (int i = 0; i != qlist.size(); ++i) {
@ -57,6 +67,400 @@ static vector<lyx::docstring> const to_docstring_vector(QStringList const & qlis
namespace lyx {
namespace frontend {
///////////////////////////////////////////////////////////////////////
//
// GuiCitationDialog
//
///////////////////////////////////////////////////////////////////////
GuiCitationDialog::GuiCitationDialog(Dialog & dialog, GuiCitation * form)
: Dialog::View(dialog, _("Citation")), form_(form)
{
setupUi(this);
setWindowTitle(toqstr("LyX: " + getTitle()));
connect(citationStyleCO, SIGNAL(activated(int)),
this, SLOT(changed()));
connect(fulllistCB, SIGNAL(clicked()),
this, SLOT(changed()));
connect(forceuppercaseCB, SIGNAL(clicked()),
this, SLOT(changed()));
connect(textBeforeED, SIGNAL(textChanged(const QString&)),
this, SLOT(changed()));
connect(textAfterED, SIGNAL(textChanged(const QString&)),
this, SLOT(changed()));
connect(clearPB, SIGNAL(clicked()),
findLE, SLOT(clear()));
connect(this, SIGNAL(rejected()), this, SLOT(cleanUp()));
selectionManager =
new GuiSelectionManager(availableLV, selectedLV,
addPB, deletePB, upPB, downPB,
form_->available(), form_->selected());
connect(selectionManager, SIGNAL(selectionChanged()),
this, SLOT(setCitedKeys()));
connect(selectionManager, SIGNAL(updateHook()),
this, SLOT(updateDialog()));
connect(selectionManager, SIGNAL(okHook()),
this, SLOT(on_okPB_clicked()));
}
GuiCitationDialog::~GuiCitationDialog()
{}
void GuiCitationDialog::cleanUp()
{
form_->clearSelection();
form_->clearParams();
close();
}
void GuiCitationDialog::closeEvent(QCloseEvent * e)
{
form_->clearSelection();
form_->clearParams();
e->accept();
}
void GuiCitationDialog::apply()
{
int const choice = std::max(0, citationStyleCO->currentIndex());
style_ = choice;
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 GuiCitationDialog::hide()
{
form_->clearParams();
accept();
}
void GuiCitationDialog::show()
{
findLE->clear();
availableLV->setFocus();
QDialog::show();
raise();
activateWindow();
}
bool GuiCitationDialog::isVisible() const
{
return QDialog::isVisible();
}
void GuiCitationDialog::on_okPB_clicked()
{
apply();
form_->clearSelection();
hide();
}
void GuiCitationDialog::on_cancelPB_clicked()
{
form_->clearSelection();
hide();
}
void GuiCitationDialog::on_applyPB_clicked()
{
apply();
}
void GuiCitationDialog::on_restorePB_clicked()
{
form_->init();
update();
}
void GuiCitationDialog::update()
{
fillFields();
fillEntries();
updateDialog();
}
//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,
//will not have changed. At the moment, however, the division between
//fillStyles() and updateStyles() doesn't lend itself to dividing the
//two methods, though they should be divisible.
void GuiCitationDialog::updateDialog()
{
if (selectionManager->selectedFocused()) {
if (selectedLV->selectionModel()->selectedIndexes().isEmpty())
updateInfo(availableLV->currentIndex());
else
updateInfo(selectedLV->currentIndex());
} else {
if (availableLV->selectionModel()->selectedIndexes().isEmpty())
updateInfo(QModelIndex());
else
updateInfo(availableLV->currentIndex());
}
setButtons();
textBeforeED->setText(form_->textBefore());
textAfterED->setText(form_->textAfter());
fillStyles();
updateStyle();
}
void GuiCitationDialog::updateStyle()
{
biblio::CiteEngine const engine = form_->getEngine();
bool const natbib_engine =
engine == biblio::ENGINE_NATBIB_AUTHORYEAR ||
engine == biblio::ENGINE_NATBIB_NUMERICAL;
bool const basic_engine = engine == biblio::ENGINE_BASIC;
bool const haveSelection =
selectedLV->model()->rowCount() > 0;
fulllistCB->setEnabled(natbib_engine && haveSelection);
forceuppercaseCB->setEnabled(natbib_engine && haveSelection);
textBeforeED->setEnabled(!basic_engine && haveSelection);
textBeforeLA->setEnabled(!basic_engine && haveSelection);
textAfterED->setEnabled(haveSelection);
textAfterLA->setEnabled(haveSelection);
citationStyleCO->setEnabled(!basic_engine && haveSelection);
citationStyleLA->setEnabled(!basic_engine && haveSelection);
string const & command = form_->params().getCmdName();
// Find the style of the citekeys
vector<biblio::CiteStyle> const & styles =
ControlCitation::getCiteStyles();
biblio::CitationStyle const cs(command);
vector<biblio::CiteStyle>::const_iterator cit =
std::find(styles.begin(), styles.end(), cs.style);
// restore the latest natbib style
if (style_ >= 0 && style_ < citationStyleCO->count())
citationStyleCO->setCurrentIndex(style_);
else
citationStyleCO->setCurrentIndex(0);
if (cit != styles.end()) {
int const i = int(cit - styles.begin());
citationStyleCO->setCurrentIndex(i);
fulllistCB->setChecked(cs.full);
forceuppercaseCB->setChecked(cs.forceUCase);
} else {
fulllistCB->setChecked(false);
forceuppercaseCB->setChecked(false);
}
}
//This one needs to be called whenever citationStyleCO needs
//to be updated---and this would be on anything that changes the
//selection in selectedLV, or on a general update.
void GuiCitationDialog::fillStyles()
{
int const oldIndex = citationStyleCO->currentIndex();
citationStyleCO->clear();
QStringList selected_keys = form_->selected()->stringList();
if (selected_keys.empty()) {
citationStyleCO->setEnabled(false);
citationStyleLA->setEnabled(false);
return;
}
int curr = selectedLV->model()->rowCount() - 1;
if (curr < 0)
return;
if (!selectedLV->selectionModel()->selectedIndexes().empty())
curr = selectedLV->selectionModel()->selectedIndexes()[0].row();
QStringList sty = form_->citationStyles(curr);
bool const basic_engine =
(form_->getEngine() == biblio::ENGINE_BASIC);
citationStyleCO->setEnabled(!sty.isEmpty() && !basic_engine);
citationStyleLA->setEnabled(!sty.isEmpty() && !basic_engine);
if (sty.isEmpty() || basic_engine)
return;
citationStyleCO->insertItems(0, sty);
if (oldIndex != -1 && oldIndex < citationStyleCO->count())
citationStyleCO->setCurrentIndex(oldIndex);
}
void GuiCitationDialog::fillFields()
{
fieldsCO->blockSignals(true);
int const oldIndex = fieldsCO->currentIndex();
fieldsCO->clear();
QStringList const & fields = form_->getFieldsAsQStringList();
fieldsCO->insertItem(0, qt_("All Fields"));
fieldsCO->insertItem(1, qt_("Keys"));
fieldsCO->insertItems(2, fields);
if (oldIndex != -1 && oldIndex < fieldsCO->count())
fieldsCO->setCurrentIndex(oldIndex);
fieldsCO->blockSignals(false);
}
void GuiCitationDialog::fillEntries()
{
entriesCO->blockSignals(true);
int const oldIndex = entriesCO->currentIndex();
entriesCO->clear();
QStringList const & entries = form_->getEntriesAsQStringList();
entriesCO->insertItem(0, qt_("All Entry Types"));
entriesCO->insertItems(1, entries);
if (oldIndex != -1 && oldIndex < entriesCO->count())
entriesCO->setCurrentIndex(oldIndex);
entriesCO->blockSignals(false);
}
bool GuiCitationDialog::isSelected(const QModelIndex & idx)
{
QString const str = idx.data().toString();
return form_->selected()->stringList().contains(str);
}
void GuiCitationDialog::setButtons()
{
selectionManager->update();
int const srows = selectedLV->model()->rowCount();
applyPB->setEnabled(srows > 0);
okPB->setEnabled(srows > 0);
}
void GuiCitationDialog::updateInfo(QModelIndex const & idx)
{
if (idx.isValid()) {
QString const keytxt = form_->getKeyInfo(idx.data().toString());
infoML->document()->setPlainText(keytxt);
} else
infoML->document()->clear();
}
void GuiCitationDialog::setCitedKeys()
{
form_->setCitedKeys();
}
void GuiCitationDialog::findText(QString const & text, bool reset)
{
//"All Fields" and "Keys" are the first two
int index = fieldsCO->currentIndex() - 2;
vector<docstring> const & fields = form_->availableFields();
docstring field;
if (index <= -1 || index >= int(fields.size()))
//either "All Fields" or "Keys" or an invalid value
field = from_ascii("");
else
field = fields[index];
//Was it "Keys"?
bool const onlyKeys = index == -1;
//"All Entry Types" is first.
index = entriesCO->currentIndex() - 1;
vector<docstring> const & entries = form_->availableEntries();
docstring entryType;
if (index < 0 || index >= int(entries.size()))
entryType = from_ascii("");
else
entryType = entries[index];
bool const case_sentitive = caseCB->checkState();
bool const reg_exp = regexCB->checkState();
form_->findKey(text, onlyKeys, field, entryType,
case_sentitive, reg_exp, reset);
//FIXME
//It'd be nice to save and restore the current selection in
//availableLV. Currently, we get an automatic reset, since the
//model is reset.
updateDialog();
}
void GuiCitationDialog::on_fieldsCO_currentIndexChanged(int /*index*/)
{
findText(findLE->text(), true);
}
void GuiCitationDialog::on_entriesCO_currentIndexChanged(int /*index*/)
{
findText(findLE->text(), true);
}
void GuiCitationDialog::on_findLE_textChanged(const QString & text)
{
clearPB->setDisabled(text.isEmpty());
if (text.isEmpty())
findLE->setFocus();
findText(text);
}
void GuiCitationDialog::on_caseCB_stateChanged(int)
{
findText(findLE->text());
}
void GuiCitationDialog::on_regexCB_stateChanged(int)
{
findText(findLE->text());
}
void GuiCitationDialog::changed()
{
fillStyles();
setButtons();
}
///////////////////////////////////////////////////////////////////////
//
// GuiCitation
//
///////////////////////////////////////////////////////////////////////
GuiCitation::GuiCitation(Dialog & parent)
: ControlCitation(parent)
@ -166,8 +570,8 @@ void GuiCitation::findKey(QString const & str, bool only_keys,
QStringList result;
//First, filter by entryType, which will be faster than
//what follows, so we may get to do that on less.
// First, filter by entryType, which will be faster than
// what follows, so we may get to do that on less.
vector<docstring> keyVector = to_docstring_vector(keys);
filterByEntryType(keyVector, entryType);
@ -181,12 +585,14 @@ void GuiCitation::findKey(QString const & str, bool only_keys,
}
QStringList GuiCitation::getFieldsAsQStringList() {
QStringList GuiCitation::getFieldsAsQStringList()
{
return to_qstring_list(availableFields());
}
QStringList GuiCitation::getEntriesAsQStringList() {
QStringList GuiCitation::getEntriesAsQStringList()
{
return to_qstring_list(availableEntries());
}
@ -208,6 +614,8 @@ void GuiCitation::setCitedKeys()
cited_keys_ = selected_model_.stringList();
}
} // namespace frontend
} // namespace lyx
#include "GuiCitation_moc.cpp"

View File

@ -15,15 +15,96 @@
#ifndef GUICITATION_H
#define GUICITATION_H
#include "Dialog.h"
#include "GuiSelectionManager.h"
#include "ui_CitationUi.h"
#include "ControlCitation.h"
#include "support/docstring.h"
#include <QKeyEvent>
#include <QStringList>
#include <QStringListModel>
namespace lyx {
namespace frontend {
class GuiCitation;
class GuiCitationDialog : public QDialog,
public Ui::CitationUi, public Dialog::View
{
Q_OBJECT
public:
GuiCitationDialog(Dialog &, GuiCitation * form );
virtual ~GuiCitationDialog();
virtual void apply();
/// Hide the dialog from sight
void hide();
/// Redraw the dialog (e.g. if the colors have been remapped).
void redraw() {}
/// Create the dialog if necessary, update it and display it.
void show();
/// \return true if the dialog is visible.
bool isVisible() const;
public Q_SLOTS:
/// Update the display of the dialog whilst it is still visible.
void update();
protected:
void closeEvent(QCloseEvent * e);
/// prepares a call to GuiCitation::searchKeys when we
/// are ready to search the BibTeX entries
void findText(QString const & text, bool reset = false);
/// check whether key is already selected
bool isSelected(const QModelIndex &);
/// update the display of BibTeX information
void updateInfo(QModelIndex const &);
protected Q_SLOTS:
void cleanUp();
void on_okPB_clicked();
void on_cancelPB_clicked();
void on_restorePB_clicked();
void on_applyPB_clicked();
void on_findLE_textChanged(const QString & text);
void on_fieldsCO_currentIndexChanged(int index);
void on_entriesCO_currentIndexChanged(int index);
void on_caseCB_stateChanged(int);
void on_regexCB_stateChanged(int);
virtual void changed();
///
void setCitedKeys();
/// performs a limited update, suitable for internal call
void updateDialog();
private:
/// enable/disable buttons
void setButtons();
/// fill the styles combo
void fillStyles();
/// fill the fields combo
void fillFields();
/// fill the entries combo
void fillEntries();
/// set the styles combo
void updateStyle();
/// last used citation style
int style_;
GuiCitation * form_;
GuiSelectionManager * selectionManager;
};
class GuiCitation : public ControlCitation
{
public:

View File

@ -1,432 +0,0 @@
/**
* \file GuiCitationDialog.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Kalle Dalheimer
* \author John Levon
* \author Jürgen Spitzmüller
* \author Abdelrazak Younes
* \author Richard Heck
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "GuiCitationDialog.h"
#include "GuiCitation.h"
#include "frontends/controllers/frontend_helpers.h"
#include "frontends/controllers/ControlCitation.h"
#include "qt_helpers.h"
#include "support/docstring.h"
#include "debug.h"
#include "gettext.h"
#include <algorithm>
#include <vector>
#include <string>
#include <QCloseEvent>
#include <QKeyEvent>
#undef KeyPress
using std::vector;
using std::string;
namespace lyx {
namespace frontend {
GuiCitationDialog::GuiCitationDialog(Dialog & dialog, GuiCitation * form)
: Dialog::View(dialog, _("Citation")), form_(form)
{
setupUi(this);
setWindowTitle(toqstr("LyX: " + getTitle()));
connect(citationStyleCO, SIGNAL(activated(int)),
this, SLOT(changed()));
connect(fulllistCB, SIGNAL(clicked()),
this, SLOT(changed()));
connect(forceuppercaseCB, SIGNAL(clicked()),
this, SLOT(changed()));
connect(textBeforeED, SIGNAL(textChanged(const QString&)),
this, SLOT(changed()));
connect(textAfterED, SIGNAL(textChanged(const QString&)),
this, SLOT(changed()));
connect(clearPB, SIGNAL(clicked()),
findLE, SLOT(clear()));
connect(this, SIGNAL(rejected()), this, SLOT(cleanUp()));
selectionManager =
new GuiSelectionManager(availableLV, selectedLV,
addPB, deletePB, upPB, downPB,
form_->available(), form_->selected());
connect(selectionManager, SIGNAL(selectionChanged()),
this, SLOT(setCitedKeys()));
connect(selectionManager, SIGNAL(updateHook()),
this, SLOT(updateDialog()));
connect(selectionManager, SIGNAL(okHook()),
this, SLOT(on_okPB_clicked()));
}
GuiCitationDialog::~GuiCitationDialog()
{}
void GuiCitationDialog::cleanUp()
{
form_->clearSelection();
form_->clearParams();
close();
}
void GuiCitationDialog::closeEvent(QCloseEvent * e)
{
form_->clearSelection();
form_->clearParams();
e->accept();
}
void GuiCitationDialog::apply()
{
int const choice = std::max(0, citationStyleCO->currentIndex());
style_ = choice;
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 GuiCitationDialog::hide()
{
form_->clearParams();
accept();
}
void GuiCitationDialog::show()
{
findLE->clear();
availableLV->setFocus();
QDialog::show();
raise();
activateWindow();
}
bool GuiCitationDialog::isVisible() const
{
return QDialog::isVisible();
}
void GuiCitationDialog::on_okPB_clicked()
{
apply();
form_->clearSelection();
hide();
}
void GuiCitationDialog::on_cancelPB_clicked()
{
form_->clearSelection();
hide();
}
void GuiCitationDialog::on_applyPB_clicked()
{
apply();
}
void GuiCitationDialog::on_restorePB_clicked()
{
form_->init();
update();
}
void GuiCitationDialog::update()
{
fillFields();
fillEntries();
updateDialog();
}
//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,
//will not have changed. At the moment, however, the division between
//fillStyles() and updateStyles() doesn't lend itself to dividing the
//two methods, though they should be divisible.
void GuiCitationDialog::updateDialog()
{
if (selectionManager->selectedFocused()) {
if (selectedLV->selectionModel()->selectedIndexes().isEmpty())
updateInfo(availableLV->currentIndex());
else
updateInfo(selectedLV->currentIndex());
} else {
if (availableLV->selectionModel()->selectedIndexes().isEmpty())
updateInfo(QModelIndex());
else
updateInfo(availableLV->currentIndex());
}
setButtons();
textBeforeED->setText(form_->textBefore());
textAfterED->setText(form_->textAfter());
fillStyles();
updateStyle();
}
void GuiCitationDialog::updateStyle()
{
biblio::CiteEngine const engine = form_->getEngine();
bool const natbib_engine =
engine == biblio::ENGINE_NATBIB_AUTHORYEAR ||
engine == biblio::ENGINE_NATBIB_NUMERICAL;
bool const basic_engine = engine == biblio::ENGINE_BASIC;
bool const haveSelection =
selectedLV->model()->rowCount() > 0;
fulllistCB->setEnabled(natbib_engine && haveSelection);
forceuppercaseCB->setEnabled(natbib_engine && haveSelection);
textBeforeED->setEnabled(!basic_engine && haveSelection);
textBeforeLA->setEnabled(!basic_engine && haveSelection);
textAfterED->setEnabled(haveSelection);
textAfterLA->setEnabled(haveSelection);
citationStyleCO->setEnabled(!basic_engine && haveSelection);
citationStyleLA->setEnabled(!basic_engine && haveSelection);
string const & command = form_->params().getCmdName();
// Find the style of the citekeys
vector<biblio::CiteStyle> const & styles =
ControlCitation::getCiteStyles();
biblio::CitationStyle const cs(command);
vector<biblio::CiteStyle>::const_iterator cit =
std::find(styles.begin(), styles.end(), cs.style);
// restore the latest natbib style
if (style_ >= 0 && style_ < citationStyleCO->count())
citationStyleCO->setCurrentIndex(style_);
else
citationStyleCO->setCurrentIndex(0);
if (cit != styles.end()) {
int const i = int(cit - styles.begin());
citationStyleCO->setCurrentIndex(i);
fulllistCB->setChecked(cs.full);
forceuppercaseCB->setChecked(cs.forceUCase);
} else {
fulllistCB->setChecked(false);
forceuppercaseCB->setChecked(false);
}
}
//This one needs to be called whenever citationStyleCO needs
//to be updated---and this would be on anything that changes the
//selection in selectedLV, or on a general update.
void GuiCitationDialog::fillStyles()
{
int const oldIndex = citationStyleCO->currentIndex();
citationStyleCO->clear();
QStringList selected_keys = form_->selected()->stringList();
if (selected_keys.empty()) {
citationStyleCO->setEnabled(false);
citationStyleLA->setEnabled(false);
return;
}
int curr = selectedLV->model()->rowCount() - 1;
if (curr < 0)
return;
if (!selectedLV->selectionModel()->selectedIndexes().empty())
curr = selectedLV->selectionModel()->selectedIndexes()[0].row();
QStringList sty = form_->citationStyles(curr);
bool const basic_engine =
(form_->getEngine() == biblio::ENGINE_BASIC);
citationStyleCO->setEnabled(!sty.isEmpty() && !basic_engine);
citationStyleLA->setEnabled(!sty.isEmpty() && !basic_engine);
if (sty.isEmpty() || basic_engine)
return;
citationStyleCO->insertItems(0, sty);
if (oldIndex != -1 && oldIndex < citationStyleCO->count())
citationStyleCO->setCurrentIndex(oldIndex);
}
void GuiCitationDialog::fillFields()
{
fieldsCO->blockSignals(true);
int const oldIndex = fieldsCO->currentIndex();
fieldsCO->clear();
QStringList const & fields = form_->getFieldsAsQStringList();
fieldsCO->insertItem(0, qt_("All Fields"));
fieldsCO->insertItem(1, qt_("Keys"));
fieldsCO->insertItems(2, fields);
if (oldIndex != -1 && oldIndex < fieldsCO->count())
fieldsCO->setCurrentIndex(oldIndex);
fieldsCO->blockSignals(false);
}
void GuiCitationDialog::fillEntries()
{
entriesCO->blockSignals(true);
int const oldIndex = entriesCO->currentIndex();
entriesCO->clear();
QStringList const & entries = form_->getEntriesAsQStringList();
entriesCO->insertItem(0, qt_("All Entry Types"));
entriesCO->insertItems(1, entries);
if (oldIndex != -1 && oldIndex < entriesCO->count())
entriesCO->setCurrentIndex(oldIndex);
entriesCO->blockSignals(false);
}
bool GuiCitationDialog::isSelected(const QModelIndex & idx)
{
QString const str = idx.data().toString();
return form_->selected()->stringList().contains(str);
}
void GuiCitationDialog::setButtons()
{
selectionManager->update();
int const srows = selectedLV->model()->rowCount();
applyPB->setEnabled(srows > 0);
okPB->setEnabled(srows > 0);
}
void GuiCitationDialog::updateInfo(QModelIndex const & idx)
{
if (idx.isValid()) {
QString const keytxt = form_->getKeyInfo(idx.data().toString());
infoML->document()->setPlainText(keytxt);
} else
infoML->document()->clear();
}
void GuiCitationDialog::setCitedKeys()
{
form_->setCitedKeys();
}
void GuiCitationDialog::findText(QString const & text, bool reset)
{
//"All Fields" and "Keys" are the first two
int index = fieldsCO->currentIndex() - 2;
vector<docstring> const & fields = form_->availableFields();
docstring field;
if (index <= -1 || index >= int(fields.size()))
//either "All Fields" or "Keys" or an invalid value
field = from_ascii("");
else
field = fields[index];
//Was it "Keys"?
bool const onlyKeys = index == -1;
//"All Entry Types" is first.
index = entriesCO->currentIndex() - 1;
vector<docstring> const & entries = form_->availableEntries();
docstring entryType;
if (index < 0 || index >= int(entries.size()))
entryType = from_ascii("");
else
entryType = entries[index];
bool const case_sentitive = caseCB->checkState();
bool const reg_exp = regexCB->checkState();
form_->findKey(text, onlyKeys, field, entryType,
case_sentitive, reg_exp, reset);
//FIXME
//It'd be nice to save and restore the current selection in
//availableLV. Currently, we get an automatic reset, since the
//model is reset.
updateDialog();
}
void GuiCitationDialog::on_fieldsCO_currentIndexChanged(int /*index*/)
{
findText(findLE->text(), true);
}
void GuiCitationDialog::on_entriesCO_currentIndexChanged(int /*index*/)
{
findText(findLE->text(), true);
}
void GuiCitationDialog::on_findLE_textChanged(const QString & text)
{
clearPB->setDisabled(text.isEmpty());
if (text.isEmpty())
findLE->setFocus();
findText(text);
}
void GuiCitationDialog::on_caseCB_stateChanged(int)
{
findText(findLE->text());
}
void GuiCitationDialog::on_regexCB_stateChanged(int)
{
findText(findLE->text());
}
void GuiCitationDialog::changed()
{
fillStyles();
setButtons();
}
} // namespace frontend
} // namespace lyx
#include "GuiCitationDialog_moc.cpp"

View File

@ -1,108 +0,0 @@
// -*- C++ -*-
/**
* \file GuiCitationDialog.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Kalle Dalheimer
* \author Abdelrazak Younes
* \author Richard Heck
*
* Full author contact details are available in file CREDITS.
*/
#ifndef GUICITATIONDIALOG_H
#define GUICITATIONDIALOG_H
#include "Dialog.h"
#include "GuiSelectionManager.h"
#include "ui_CitationUi.h"
#include <QCloseEvent>
#include <QKeyEvent>
#include <QStringList>
#include <QStringListModel>
namespace lyx {
namespace frontend {
class GuiCitation;
class GuiCitationDialog : public QDialog,
public Ui::CitationUi, public Dialog::View
{
Q_OBJECT
public:
GuiCitationDialog(Dialog &, GuiCitation * form );
virtual ~GuiCitationDialog();
virtual void apply();
/// Hide the dialog from sight
void hide();
/// Redraw the dialog (e.g. if the colors have been remapped).
void redraw() {}
/// Create the dialog if necessary, update it and display it.
void show();
/// \return true if the dialog is visible.
bool isVisible() const;
public Q_SLOTS:
/// Update the display of the dialog whilst it is still visible.
void update();
protected:
void closeEvent (QCloseEvent * e);
/// prepares a call to GuiCitation::searchKeys when we
/// are ready to search the BibTeX entries
void findText(QString const & text, bool reset = false);
/// check whether key is already selected
bool isSelected(const QModelIndex &);
/// update the display of BibTeX information
void updateInfo(QModelIndex const &);
protected Q_SLOTS:
void cleanUp();
void on_okPB_clicked();
void on_cancelPB_clicked();
void on_restorePB_clicked();
void on_applyPB_clicked();
void on_findLE_textChanged(const QString & text);
void on_fieldsCO_currentIndexChanged(int index);
void on_entriesCO_currentIndexChanged(int index);
void on_caseCB_stateChanged(int);
void on_regexCB_stateChanged(int);
virtual void changed();
///
void setCitedKeys();
/// performs a limited update, suitable for internal call
void updateDialog();
private:
/// enable/disable buttons
void setButtons();
/// fill the styles combo
void fillStyles();
/// fill the fields combo
void fillFields();
/// fill the entries combo
void fillEntries();
/// set the styles combo
void updateStyle();
/// last used citation style
int style_;
GuiCitation * form_;
GuiSelectionManager * selectionManager;
};
} // namespace frontend
} // namespace lyx
#endif // GUICITATIOINDIALOG_H

View File

@ -1,5 +1,5 @@
/**
* \file GuiDelimiterDialog.cpp
* \file GuiDelimiter.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
@ -10,7 +10,7 @@
#include <config.h>
#include "GuiDelimiterDialog.h"
#include "GuiDelimiter.h"
#include "GuiApplication.h"
#include "GuiView.h"
@ -22,8 +22,6 @@
#include <QCheckBox>
#include <QListWidgetItem>
#include <sstream>
// Set to zero if unicode symbols are preferred.
#define USE_PIXMAP 1
@ -248,4 +246,4 @@ void GuiDelimiterDialog::on_matchCB_stateChanged(int state)
} // namespace frontend
} // namespace lyx
#include "GuiDelimiterDialog_moc.cpp"
#include "GuiDelimiter_moc.cpp"

View File

@ -1,5 +1,5 @@
/**
* \file GuiMathMatrixDialog.cpp
* \file GuiMathMatrix.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
@ -10,7 +10,7 @@
#include <config.h>
#include "GuiMathMatrixDialog.h"
#include "GuiMathMatrix.h"
#include "EmptyTable.h"
#include "qt_helpers.h"
@ -121,4 +121,4 @@ void GuiMathMatrixDialog::slotClose()
} // namespace frontend
} // namespace lyx
#include "GuiMathMatrixDialog_moc.cpp"
#include "GuiMathMatrix_moc.cpp"

View File

@ -1,5 +1,5 @@
/**
* \file GuiURLDialog.cpp
* \file GuiURL.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
@ -10,7 +10,7 @@
#include <config.h>
#include "GuiURLDialog.h"
#include "GuiURL.h"
#include "Qt2BC.h"
#include "qt_helpers.h"
#include "ButtonController.h"
@ -111,4 +111,5 @@ bool UrlView::isValid()
} // namespace frontend
} // namespace lyx
#include "GuiURLDialog_moc.cpp"
#include "GuiURL_moc.cpp"

View File

@ -54,11 +54,10 @@ SOURCEFILES = \
GuiChanges.cpp \
GuiCharacter.cpp \
GuiCitation.cpp \
GuiCitationDialog.cpp \
GuiClipboard.cpp \
GuiCommandBuffer.cpp \
GuiCommandEdit.cpp \
GuiDelimiterDialog.cpp \
GuiDelimiter.cpp \
GuiDialogView.cpp \
GuiDocument.cpp \
GuiEmbeddedFiles.cpp \
@ -78,7 +77,7 @@ SOURCEFILES = \
GuiKeySymbol.cpp \
GuiListings.cpp \
GuiLog.cpp \
GuiMathMatrixDialog.cpp \
GuiMathMatrix.cpp \
GuiMenubar.cpp \
GuiNomencl.cpp \
GuiNote.cpp \
@ -101,7 +100,7 @@ SOURCEFILES = \
GuiThesaurus.cpp \
GuiToc.cpp \
GuiToolbar.cpp \
GuiURLDialog.cpp \
GuiURL.cpp \
GuiView.cpp \
GuiViewSource.cpp \
GuiVSpace.cpp \
@ -146,11 +145,10 @@ MOCHEADER = \
GuiBranch.h \
GuiChanges.h \
GuiCharacter.h \
GuiCitationDialog.h \
GuiCitation.h \
GuiCommandBuffer.h \
GuiCommandEdit.h \
GuiDelimiterDialog.h \
GuiDelimiter.h \
GuiDialogView.h \
GuiDocument.h \
GuiEmbeddedFiles.h \
@ -166,7 +164,7 @@ MOCHEADER = \
GuiKeySymbol.h \
GuiListings.h \
GuiLog.h \
GuiMathMatrixDialog.h \
GuiMathMatrix.h \
GuiMenubar.h \
GuiNomencl.h \
GuiNote.h \
@ -187,7 +185,7 @@ MOCHEADER = \
GuiThesaurus.h \
GuiToc.h \
GuiToolbar.h \
GuiURLDialog.h \
GuiURL.h \
GuiView.h \
GuiViewSource.h \
GuiVSpace.h \