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
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
2001-03-23 06:31:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2002-09-24 13:57:09 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-08-26 00:29:39 +00:00
|
|
|
#include "ControlRef.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-07-22 14:04:38 +00:00
|
|
|
#include "helper_funcs.h" // getStringFromVector
|
|
|
|
#include "support/lstrings.h" // frontStrip, strip
|
|
|
|
#include "gettext.h"
|
|
|
|
#include "insets/insetref.h"
|
|
|
|
|
|
|
|
using std::find;
|
|
|
|
using std::max;
|
|
|
|
using std::sort;
|
|
|
|
using std::vector;
|
2001-03-23 06:31:30 +00:00
|
|
|
using std::endl;
|
|
|
|
|
2001-08-26 00:29:39 +00:00
|
|
|
typedef Qt2CB<ControlRef, Qt2DB<QRefDialog> > base_class;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-08-12 14:28:43 +00:00
|
|
|
QRef::QRef()
|
|
|
|
: base_class(_("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));
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
bc().setOK(dialog_->okPB);
|
|
|
|
bc().setCancel(dialog_->closePB);
|
2001-08-26 00:29:39 +00:00
|
|
|
bc().addReadOnly(dialog_->refsLB);
|
|
|
|
bc().addReadOnly(dialog_->sortCB);
|
|
|
|
bc().addReadOnly(dialog_->nameED);
|
|
|
|
bc().addReadOnly(dialog_->referenceED);
|
|
|
|
bc().addReadOnly(dialog_->typeCO);
|
2002-07-22 14:04:38 +00:00
|
|
|
bc().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
|
|
|
{
|
2001-08-26 00:29:39 +00:00
|
|
|
dialog_->referenceED->setText(controller().params().getContents().c_str());
|
|
|
|
|
2002-07-22 14:04:38 +00:00
|
|
|
dialog_->nameED->setText(controller().params().getOptions().c_str());
|
2001-08-26 00:29:39 +00:00
|
|
|
dialog_->nameED->setReadOnly(!nameAllowed() && !readOnly());
|
|
|
|
|
2002-07-22 14:04:38 +00:00
|
|
|
dialog_->typeCO->setCurrentItem(InsetRef::getType(controller().params().getCmdName()));
|
2001-08-26 00:29:39 +00:00
|
|
|
dialog_->typeCO->setEnabled(!typeAllowed() && !readOnly());
|
|
|
|
if (!typeAllowed())
|
|
|
|
dialog_->typeCO->setCurrentItem(0);
|
|
|
|
|
|
|
|
dialog_->sortCB->setChecked(sort_);
|
|
|
|
|
2002-07-22 14:04:38 +00:00
|
|
|
/* insert buffer list */
|
|
|
|
dialog_->bufferCO->clear();
|
|
|
|
vector<string> const buffers = controller().getBufferList();
|
|
|
|
for (vector<string>::const_iterator it = buffers.begin();
|
|
|
|
it != buffers.end(); ++it) {
|
|
|
|
dialog_->bufferCO->insertItem(it->c_str());
|
|
|
|
}
|
|
|
|
dialog_->bufferCO->setCurrentItem(controller().getBufferNum());
|
|
|
|
|
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
|
|
|
{
|
2001-08-26 00:29:39 +00:00
|
|
|
controller().params().setCmdName(InsetRef::getName(dialog_->typeCO->currentItem()));
|
|
|
|
controller().params().setContents(dialog_->referenceED->text().latin1());
|
|
|
|
controller().params().setOptions(dialog_->nameED->text().latin1());
|
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
|
|
|
{
|
2001-08-26 00:29:39 +00:00
|
|
|
return controller().docType() != ControlRef::LATEX &&
|
|
|
|
controller().docType() != ControlRef::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
|
|
|
{
|
2001-08-26 00:29:39 +00:00
|
|
|
return controller().docType() == ControlRef::LINUXDOC ||
|
|
|
|
controller().docType() == ControlRef::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
|
|
|
{
|
2001-08-26 00:29:39 +00:00
|
|
|
dialog_->gotoPB->setText(_("&Go back"));
|
|
|
|
QToolTip::remove(dialog_->gotoPB);
|
|
|
|
QToolTip::add(dialog_->gotoPB, _("Go 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
|
|
|
{
|
2001-08-31 09:07:00 +00:00
|
|
|
dialog_->gotoPB->setText(_("&Goto"));
|
2001-08-26 00:29:39 +00:00
|
|
|
QToolTip::remove(dialog_->gotoPB);
|
|
|
|
QToolTip::add(dialog_->gotoPB, _("Go 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
|
|
|
{
|
2001-08-26 00:29:39 +00:00
|
|
|
string ref(dialog_->referenceED->text());
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
// need this because Qt will send a highlight() here for
|
|
|
|
// the first item inserted
|
|
|
|
string tmp(dialog_->referenceED->text());
|
|
|
|
|
2001-08-26 00:29:39 +00:00
|
|
|
for (std::vector<string>::const_iterator iter = refs_.begin();
|
|
|
|
iter != refs_.end(); ++iter) {
|
|
|
|
if (sort_)
|
2001-03-23 06:31:30 +00:00
|
|
|
dialog_->refsLB->inSort(iter->c_str());
|
|
|
|
else
|
|
|
|
dialog_->refsLB->insertItem(iter->c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog_->referenceED->setText(tmp.c_str());
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < dialog_->refsLB->count(); ++i) {
|
2001-08-26 00:29:39 +00:00
|
|
|
if (!compare(tmp.c_str(), dialog_->refsLB->text(i).latin1()))
|
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();
|
|
|
|
dialog_->refsLB->clear();
|
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
|
|
|
}
|