2001-08-19 13:25:15 +00:00
|
|
|
/**
|
|
|
|
* \file QRef.C
|
2002-09-24 13:57:09 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2001-08-19 13:25:15 +00:00
|
|
|
*
|
|
|
|
* \author John Levon
|
2002-09-24 13:57:09 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2001-03-23 06:31:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2003-09-29 10:50:51 +00:00
|
|
|
#include "debug.h"
|
2001-08-26 00:29:39 +00:00
|
|
|
#include "ControlRef.h"
|
2003-06-11 21:58:23 +00:00
|
|
|
#include "insets/insetref.h"
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
#include "QRef.h"
|
|
|
|
#include "QRefDialog.h"
|
|
|
|
#include "Qt2BC.h"
|
2001-03-23 06:31:30 +00:00
|
|
|
|
|
|
|
#include <qlineedit.h>
|
2001-08-26 00:29:39 +00:00
|
|
|
#include <qcheckbox.h>
|
2001-03-23 06:31:30 +00:00
|
|
|
#include <qlistbox.h>
|
|
|
|
#include <qcombobox.h>
|
2001-08-26 00:29:39 +00:00
|
|
|
#include <qpushbutton.h>
|
|
|
|
#include <qtooltip.h>
|
2001-03-23 06:31:30 +00:00
|
|
|
|
2002-12-17 20:37:13 +00:00
|
|
|
#include "qt_helpers.h"
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-07-22 14:04:38 +00:00
|
|
|
using std::vector;
|
2001-03-23 06:31:30 +00:00
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
typedef QController<ControlRef, QView<QRefDialog> > base_class;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
QRef::QRef(Dialog & parent)
|
2003-05-22 15:42:50 +00:00
|
|
|
: base_class(parent, _("LyX: Cross-reference")),
|
2001-08-26 00:29:39 +00:00
|
|
|
sort_(false), at_ref_(false)
|
2001-03-23 06:31:30 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
|
2001-08-26 00:29:39 +00:00
|
|
|
void QRef::build_dialog()
|
2001-03-23 06:31:30 +00:00
|
|
|
{
|
2001-08-26 00:29:39 +00:00
|
|
|
dialog_.reset(new QRefDialog(this));
|
|
|
|
|
2003-03-10 03:13:28 +00:00
|
|
|
bcview().setOK(dialog_->okPB);
|
|
|
|
bcview().setApply(dialog_->applyPB);
|
|
|
|
bcview().setCancel(dialog_->closePB);
|
|
|
|
bcview().addReadOnly(dialog_->refsLB);
|
|
|
|
bcview().addReadOnly(dialog_->sortCB);
|
|
|
|
bcview().addReadOnly(dialog_->nameED);
|
|
|
|
bcview().addReadOnly(dialog_->referenceED);
|
|
|
|
bcview().addReadOnly(dialog_->typeCO);
|
|
|
|
bcview().addReadOnly(dialog_->bufferCO);
|
2001-03-23 06:31:30 +00:00
|
|
|
}
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-26 00:29:39 +00:00
|
|
|
void QRef::update_contents()
|
2001-03-23 06:31:30 +00:00
|
|
|
{
|
2002-10-20 01:48:28 +00:00
|
|
|
InsetCommandParams const & params = controller().params();
|
2001-08-26 00:29:39 +00:00
|
|
|
|
2002-12-17 20:37:13 +00:00
|
|
|
dialog_->referenceED->setText(toqstr(params.getContents()));
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-12-17 20:37:13 +00:00
|
|
|
dialog_->nameED->setText(toqstr(params.getOptions()));
|
2001-08-26 00:29:39 +00:00
|
|
|
dialog_->nameED->setReadOnly(!nameAllowed() && !readOnly());
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
dialog_->typeCO->setCurrentItem(InsetRef::getType(params.getCmdName()));
|
2002-12-10 00:59:59 +00:00
|
|
|
dialog_->typeCO->setEnabled(typeAllowed() && !readOnly());
|
2001-08-26 00:29:39 +00:00
|
|
|
if (!typeAllowed())
|
|
|
|
dialog_->typeCO->setCurrentItem(0);
|
|
|
|
|
|
|
|
dialog_->sortCB->setChecked(sort_);
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
// insert buffer list
|
2002-07-22 14:04:38 +00:00
|
|
|
dialog_->bufferCO->clear();
|
|
|
|
vector<string> const buffers = controller().getBufferList();
|
|
|
|
for (vector<string>::const_iterator it = buffers.begin();
|
|
|
|
it != buffers.end(); ++it) {
|
2002-12-17 20:37:13 +00:00
|
|
|
dialog_->bufferCO->insertItem(toqstr(*it));
|
2002-07-22 14:04:38 +00:00
|
|
|
}
|
|
|
|
dialog_->bufferCO->setCurrentItem(controller().getBufferNum());
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2001-08-26 00:29:39 +00:00
|
|
|
updateRefs();
|
2001-03-23 06:31:30 +00:00
|
|
|
}
|
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
|
2001-08-26 00:29:39 +00:00
|
|
|
void QRef::apply()
|
2001-03-23 06:31:30 +00:00
|
|
|
{
|
2002-10-20 01:48:28 +00:00
|
|
|
InsetCommandParams & params = controller().params();
|
|
|
|
|
|
|
|
params.setCmdName(InsetRef::getName(dialog_->typeCO->currentItem()));
|
2002-12-17 20:37:13 +00:00
|
|
|
params.setContents(fromqstr(dialog_->referenceED->text()));
|
|
|
|
params.setOptions(fromqstr(dialog_->nameED->text()));
|
2001-03-23 06:31:30 +00:00
|
|
|
}
|
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
|
2001-08-26 00:29:39 +00:00
|
|
|
bool QRef::nameAllowed()
|
2001-03-23 06:31:30 +00:00
|
|
|
{
|
2003-02-25 14:51:38 +00:00
|
|
|
Kernel::DocTypes doc_type = kernel().docType();
|
|
|
|
return doc_type != Kernel::LATEX &&
|
|
|
|
doc_type != Kernel::LITERATE;
|
2001-03-23 06:31:30 +00:00
|
|
|
}
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-26 00:29:39 +00:00
|
|
|
bool QRef::typeAllowed()
|
2001-03-23 06:31:30 +00:00
|
|
|
{
|
2003-02-25 14:51:38 +00:00
|
|
|
Kernel::DocTypes doc_type = kernel().docType();
|
|
|
|
return doc_type != Kernel::LINUXDOC &&
|
|
|
|
doc_type != Kernel::DOCBOOK;
|
2001-03-23 06:31:30 +00:00
|
|
|
}
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-26 00:29:39 +00:00
|
|
|
void QRef::setGoBack()
|
2001-03-23 06:31:30 +00:00
|
|
|
{
|
2003-04-03 21:27:12 +00:00
|
|
|
dialog_->gotoPB->setText(qt_("&Go Back"));
|
2001-08-26 00:29:39 +00:00
|
|
|
QToolTip::remove(dialog_->gotoPB);
|
2003-04-03 21:27:12 +00:00
|
|
|
QToolTip::add(dialog_->gotoPB, qt_("Jump back"));
|
2001-03-23 06:31:30 +00:00
|
|
|
}
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-26 00:29:39 +00:00
|
|
|
void QRef::setGotoRef()
|
2001-03-23 06:31:30 +00:00
|
|
|
{
|
2003-04-03 21:27:12 +00:00
|
|
|
dialog_->gotoPB->setText(qt_("&Go to Reference"));
|
2001-08-26 00:29:39 +00:00
|
|
|
QToolTip::remove(dialog_->gotoPB);
|
2003-04-03 21:27:12 +00:00
|
|
|
QToolTip::add(dialog_->gotoPB, qt_("Jump to reference"));
|
2001-03-23 06:31:30 +00:00
|
|
|
}
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-26 00:29:39 +00:00
|
|
|
void QRef::gotoRef()
|
2001-03-23 06:31:30 +00:00
|
|
|
{
|
2002-12-17 20:37:13 +00:00
|
|
|
string ref(fromqstr(dialog_->referenceED->text()));
|
2001-08-26 00:29:39 +00:00
|
|
|
|
|
|
|
if (at_ref_) {
|
|
|
|
// go back
|
|
|
|
setGotoRef();
|
|
|
|
controller().gotoBookmark();
|
|
|
|
} else {
|
|
|
|
// go to the ref
|
|
|
|
setGoBack();
|
|
|
|
controller().gotoRef(ref);
|
2001-03-23 06:31:30 +00:00
|
|
|
}
|
2001-08-26 00:29:39 +00:00
|
|
|
at_ref_ = !at_ref_;
|
|
|
|
}
|
2001-03-23 06:31:30 +00:00
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-26 00:29:39 +00:00
|
|
|
void QRef::redoRefs()
|
|
|
|
{
|
2001-03-23 06:31:30 +00:00
|
|
|
dialog_->refsLB->setAutoUpdate(false);
|
2003-04-03 21:50:36 +00:00
|
|
|
dialog_->refsLB->clear();
|
2001-03-23 06:31:30 +00:00
|
|
|
|
|
|
|
// need this because Qt will send a highlight() here for
|
|
|
|
// the first item inserted
|
2002-12-17 20:37:13 +00:00
|
|
|
QString const tmp(dialog_->referenceED->text());
|
2001-03-23 06:31:30 +00:00
|
|
|
|
2001-08-26 00:29:39 +00:00
|
|
|
for (std::vector<string>::const_iterator iter = refs_.begin();
|
|
|
|
iter != refs_.end(); ++iter) {
|
2003-04-03 21:50:36 +00:00
|
|
|
dialog_->refsLB->insertItem(toqstr(*iter));
|
2001-03-23 06:31:30 +00:00
|
|
|
}
|
|
|
|
|
2003-04-03 21:50:36 +00:00
|
|
|
if (sort_)
|
|
|
|
dialog_->refsLB->sort();
|
|
|
|
|
2002-12-17 20:37:13 +00:00
|
|
|
dialog_->referenceED->setText(tmp);
|
2001-03-23 06:31:30 +00:00
|
|
|
|
|
|
|
for (unsigned int i = 0; i < dialog_->refsLB->count(); ++i) {
|
2002-12-19 01:10:41 +00:00
|
|
|
if (tmp == dialog_->refsLB->text(i))
|
2001-03-23 06:31:30 +00:00
|
|
|
dialog_->refsLB->setCurrentItem(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog_->refsLB->setAutoUpdate(true);
|
|
|
|
dialog_->refsLB->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-26 00:29:39 +00:00
|
|
|
void QRef::updateRefs()
|
2001-03-23 06:31:30 +00:00
|
|
|
{
|
2001-08-26 00:29:39 +00:00
|
|
|
refs_.clear();
|
|
|
|
if (at_ref_)
|
|
|
|
gotoRef();
|
2002-07-22 14:04:38 +00:00
|
|
|
string const name = controller().getBufferName(dialog_->bufferCO->currentItem());
|
|
|
|
refs_ = controller().getLabelList(name);
|
2001-08-26 00:29:39 +00:00
|
|
|
dialog_->sortCB->setEnabled(!refs_.empty());
|
2002-03-21 21:21:28 +00:00
|
|
|
dialog_->refsLB->setEnabled(!refs_.empty());
|
2001-08-26 00:29:39 +00:00
|
|
|
redoRefs();
|
2001-03-23 06:31:30 +00:00
|
|
|
}
|