2006-03-05 17:24:44 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file QRef.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author John Levon
|
|
|
|
|
* \author J<EFBFBD>rgen Spitzm<EFBFBD>ller
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "QRef.h"
|
|
|
|
|
#include "QRefDialog.h"
|
|
|
|
|
#include "Qt2BC.h"
|
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
|
|
|
|
|
#include "controllers/ButtonController.h"
|
|
|
|
|
#include "controllers/ControlRef.h"
|
|
|
|
|
|
|
|
|
|
#include "insets/insetref.h"
|
|
|
|
|
|
2006-05-03 19:51:15 +00:00
|
|
|
|
#include <QLineEdit>
|
|
|
|
|
#include <QCheckBox>
|
|
|
|
|
#include <QListWidget>
|
|
|
|
|
#include <QListWidgetItem>
|
|
|
|
|
#include <QPushButton>
|
|
|
|
|
#include <QToolTip>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
namespace frontend {
|
|
|
|
|
|
2006-06-06 10:10:11 +00:00
|
|
|
|
// full qualification because qt4 has also a ControlRef type
|
|
|
|
|
typedef QController<lyx::frontend::ControlRef, QView<QRefDialog> > base_class;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QRef::QRef(Dialog & parent)
|
2006-09-09 15:27:44 +00:00
|
|
|
|
: base_class(parent, lyx::to_utf8(_("Cross-reference"))),
|
2006-03-05 17:24:44 +00:00
|
|
|
|
sort_(false), at_ref_(false)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QRef::build_dialog()
|
|
|
|
|
{
|
|
|
|
|
dialog_.reset(new QRefDialog(this));
|
|
|
|
|
|
|
|
|
|
bcview().setOK(dialog_->okPB);
|
|
|
|
|
bcview().setApply(dialog_->applyPB);
|
|
|
|
|
bcview().setCancel(dialog_->closePB);
|
2006-05-03 19:51:15 +00:00
|
|
|
|
bcview().addReadOnly(dialog_->refsLW);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
bcview().addReadOnly(dialog_->sortCB);
|
|
|
|
|
bcview().addReadOnly(dialog_->nameED);
|
|
|
|
|
bcview().addReadOnly(dialog_->referenceED);
|
|
|
|
|
bcview().addReadOnly(dialog_->typeCO);
|
|
|
|
|
bcview().addReadOnly(dialog_->bufferCO);
|
|
|
|
|
|
|
|
|
|
restored_buffer_ = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QRef::update_contents()
|
|
|
|
|
{
|
|
|
|
|
InsetCommandParams const & params = controller().params();
|
|
|
|
|
|
2006-08-17 08:58:28 +00:00
|
|
|
|
int orig_type = dialog_->typeCO->currentIndex();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
dialog_->referenceED->setText(toqstr(params.getContents()));
|
|
|
|
|
|
|
|
|
|
dialog_->nameED->setText(toqstr(params.getOptions()));
|
|
|
|
|
dialog_->nameED->setReadOnly(!nameAllowed() && !readOnly());
|
|
|
|
|
|
|
|
|
|
// restore type settings for new insets
|
|
|
|
|
if (params.getContents().empty())
|
2006-08-17 08:58:28 +00:00
|
|
|
|
dialog_->typeCO->setCurrentIndex(orig_type);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
else
|
2006-08-17 08:58:28 +00:00
|
|
|
|
dialog_->typeCO->setCurrentIndex(InsetRef::getType(params.getCmdName()));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
dialog_->typeCO->setEnabled(typeAllowed() && !readOnly());
|
|
|
|
|
if (!typeAllowed())
|
2006-08-17 08:58:28 +00:00
|
|
|
|
dialog_->typeCO->setCurrentIndex(0);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
dialog_->sortCB->setChecked(sort_);
|
|
|
|
|
|
|
|
|
|
// insert buffer list
|
|
|
|
|
dialog_->bufferCO->clear();
|
|
|
|
|
vector<string> const buffers = controller().getBufferList();
|
|
|
|
|
for (vector<string>::const_iterator it = buffers.begin();
|
|
|
|
|
it != buffers.end(); ++it) {
|
2006-08-17 08:58:28 +00:00
|
|
|
|
dialog_->bufferCO->addItem(toqstr(*it));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
// restore the buffer combo setting for new insets
|
|
|
|
|
if (params.getContents().empty() && restored_buffer_ != -1
|
|
|
|
|
&& restored_buffer_ < dialog_->bufferCO->count())
|
2006-08-17 08:58:28 +00:00
|
|
|
|
dialog_->bufferCO->setCurrentIndex(restored_buffer_);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
else
|
2006-08-17 08:58:28 +00:00
|
|
|
|
dialog_->bufferCO->setCurrentIndex(controller().getBufferNum());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
updateRefs();
|
|
|
|
|
bc().valid(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QRef::apply()
|
|
|
|
|
{
|
|
|
|
|
InsetCommandParams & params = controller().params();
|
|
|
|
|
|
2006-08-17 08:58:28 +00:00
|
|
|
|
params.setCmdName(InsetRef::getName(dialog_->typeCO->currentIndex()));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
params.setContents(fromqstr(dialog_->referenceED->text()));
|
|
|
|
|
params.setOptions(fromqstr(dialog_->nameED->text()));
|
|
|
|
|
|
2006-08-17 08:58:28 +00:00
|
|
|
|
restored_buffer_ = dialog_->bufferCO->currentIndex();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool QRef::nameAllowed()
|
|
|
|
|
{
|
|
|
|
|
Kernel::DocType const doc_type = kernel().docType();
|
|
|
|
|
return doc_type != Kernel::LATEX &&
|
|
|
|
|
doc_type != Kernel::LITERATE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool QRef::typeAllowed()
|
|
|
|
|
{
|
|
|
|
|
Kernel::DocType const doc_type = kernel().docType();
|
2006-08-23 10:57:45 +00:00
|
|
|
|
return doc_type != Kernel::DOCBOOK;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QRef::setGoBack()
|
|
|
|
|
{
|
|
|
|
|
dialog_->gotoPB->setText(qt_("&Go Back"));
|
2006-08-17 08:58:28 +00:00
|
|
|
|
dialog_->gotoPB->setToolTip("");
|
|
|
|
|
dialog_->gotoPB->setToolTip(qt_("Jump back"));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QRef::setGotoRef()
|
|
|
|
|
{
|
|
|
|
|
dialog_->gotoPB->setText(qt_("&Go to Label"));
|
2006-08-17 08:58:28 +00:00
|
|
|
|
dialog_->gotoPB->setToolTip("");
|
|
|
|
|
dialog_->gotoPB->setToolTip(qt_("Jump to label"));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QRef::gotoRef()
|
|
|
|
|
{
|
|
|
|
|
string ref(fromqstr(dialog_->referenceED->text()));
|
|
|
|
|
|
|
|
|
|
if (at_ref_) {
|
|
|
|
|
// go back
|
|
|
|
|
setGotoRef();
|
|
|
|
|
controller().gotoBookmark();
|
|
|
|
|
} else {
|
|
|
|
|
// go to the ref
|
|
|
|
|
setGoBack();
|
|
|
|
|
controller().gotoRef(ref);
|
|
|
|
|
}
|
|
|
|
|
at_ref_ = !at_ref_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QRef::redoRefs()
|
|
|
|
|
{
|
|
|
|
|
// Prevent these widgets from emitting any signals whilst
|
|
|
|
|
// we modify their state.
|
2006-05-03 19:51:15 +00:00
|
|
|
|
dialog_->refsLW->blockSignals(true);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
dialog_->referenceED->blockSignals(true);
|
|
|
|
|
|
2006-05-03 19:51:15 +00:00
|
|
|
|
int lastref = dialog_->refsLW->currentRow();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2006-05-03 19:51:15 +00:00
|
|
|
|
dialog_->refsLW->setUpdatesEnabled(false);
|
|
|
|
|
dialog_->refsLW->clear();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
// need this because Qt will send a highlight() here for
|
|
|
|
|
// the first item inserted
|
|
|
|
|
QString const tmp(dialog_->referenceED->text());
|
|
|
|
|
|
|
|
|
|
for (std::vector<string>::const_iterator iter = refs_.begin();
|
|
|
|
|
iter != refs_.end(); ++iter) {
|
2006-05-03 19:51:15 +00:00
|
|
|
|
dialog_->refsLW->addItem(toqstr(*iter));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sort_)
|
2006-05-03 19:51:15 +00:00
|
|
|
|
dialog_->refsLW->sortItems();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
dialog_->referenceED->setText(tmp);
|
|
|
|
|
|
|
|
|
|
// restore the last selection for new insets
|
|
|
|
|
if (tmp.isEmpty() && lastref != -1
|
2006-05-03 19:51:15 +00:00
|
|
|
|
&& lastref < int(dialog_->refsLW->count())) {
|
|
|
|
|
dialog_->refsLW->setCurrentRow(lastref);
|
|
|
|
|
dialog_->refsLW->clearSelection();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
} else
|
2006-07-06 08:18:51 +00:00
|
|
|
|
for (int i = 0; i < dialog_->refsLW->count(); ++i) {
|
|
|
|
|
QListWidgetItem * item = dialog_->refsLW->item(i);
|
|
|
|
|
if (tmp == item->text()) {
|
2006-05-03 19:51:15 +00:00
|
|
|
|
dialog_->refsLW->setItemSelected(item, true);
|
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-05-03 19:51:15 +00:00
|
|
|
|
dialog_->refsLW->setUpdatesEnabled(true);
|
|
|
|
|
dialog_->refsLW->update();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
// Re-activate the emission of signals by these widgets.
|
2006-05-03 19:51:15 +00:00
|
|
|
|
dialog_->refsLW->blockSignals(false);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
dialog_->referenceED->blockSignals(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QRef::updateRefs()
|
|
|
|
|
{
|
|
|
|
|
refs_.clear();
|
|
|
|
|
if (at_ref_)
|
|
|
|
|
gotoRef();
|
2006-08-17 08:58:28 +00:00
|
|
|
|
string const name = controller().getBufferName(dialog_->bufferCO->currentIndex());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
refs_ = controller().getLabelList(name);
|
|
|
|
|
dialog_->sortCB->setEnabled(!refs_.empty());
|
2006-05-03 19:51:15 +00:00
|
|
|
|
dialog_->refsLW->setEnabled(!refs_.empty());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
dialog_->gotoPB->setEnabled(!refs_.empty());
|
|
|
|
|
redoRefs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QRef::isValid()
|
|
|
|
|
{
|
|
|
|
|
return !dialog_->referenceED->text().isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
|
} // namespace lyx
|