2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiRef.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 John Levon
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Jürgen Spitzmüller
|
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 "GuiRef.h"
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2007-10-05 19:04:38 +00:00
|
|
|
#include "Buffer.h"
|
|
|
|
#include "BufferList.h"
|
|
|
|
#include "FuncRequest.h"
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "insets/InsetRef.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-12-17 16:04:46 +00:00
|
|
|
#include "support/FileName.h"
|
2008-07-29 08:52:25 +00:00
|
|
|
#include "support/FileNameList.h"
|
2008-04-20 09:24:14 +00:00
|
|
|
#include "support/filetools.h" // makeAbsPath, makeDisplayPath
|
2007-10-05 19:04:38 +00:00
|
|
|
|
2006-05-03 19:51:15 +00:00
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QCheckBox>
|
2010-01-30 10:51:24 +00:00
|
|
|
#include <QTreeWidget>
|
|
|
|
#include <QTreeWidgetItem>
|
2006-05-03 19:51:15 +00:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QToolTip>
|
2007-04-25 10:57:54 +00:00
|
|
|
#include <QCloseEvent>
|
2010-02-01 09:54:41 +00:00
|
|
|
#include <QHeaderView>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
GuiRef::GuiRef(GuiView & lv)
|
2008-04-20 09:24:14 +00:00
|
|
|
: GuiDialog(lv, "ref", qt_("Cross-reference")),
|
|
|
|
params_(insetCode("ref"))
|
2007-04-25 10:57:54 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
at_ref_ = false;
|
|
|
|
|
2009-02-18 23:45:00 +00:00
|
|
|
// Enabling is set in updateRefs. Disable for now in case no
|
|
|
|
// call to updateContents follows (e.g. read-only documents).
|
|
|
|
sortCB->setEnabled(false);
|
2009-02-24 22:56:57 +00:00
|
|
|
caseSensitiveCB->setEnabled(false);
|
|
|
|
caseSensitiveCB->setChecked(false);
|
2010-01-30 10:51:24 +00:00
|
|
|
refsTW->setEnabled(false);
|
2009-02-18 23:45:00 +00:00
|
|
|
gotoPB->setEnabled(false);
|
|
|
|
|
2010-01-30 10:51:24 +00:00
|
|
|
refsTW->setColumnCount(1);
|
|
|
|
refsTW->header()->setVisible(false);
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
|
|
|
|
connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
|
|
|
|
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
|
2009-05-23 09:47:20 +00:00
|
|
|
connect(closePB, SIGNAL(clicked()), this, SLOT(resetDialog()));
|
|
|
|
connect(this, SIGNAL(rejected()), this, SLOT(dialogRejected()));
|
2007-04-25 10:57:54 +00:00
|
|
|
|
2007-05-28 22:27:45 +00:00
|
|
|
connect(typeCO, SIGNAL(activated(int)),
|
2007-04-25 10:57:54 +00:00
|
|
|
this, SLOT(changed_adaptor()));
|
2007-10-09 19:34:27 +00:00
|
|
|
connect(referenceED, SIGNAL(textChanged(QString)),
|
2007-04-25 10:57:54 +00:00
|
|
|
this, SLOT(changed_adaptor()));
|
2010-01-30 11:19:48 +00:00
|
|
|
connect(findLE, SIGNAL(textEdited(QString)),
|
|
|
|
this, SLOT(filterLabels()));
|
2010-01-30 10:51:24 +00:00
|
|
|
connect(csFindCB, SIGNAL(clicked()),
|
2010-01-30 11:19:48 +00:00
|
|
|
this, SLOT(filterLabels()));
|
2007-10-09 19:34:27 +00:00
|
|
|
connect(nameED, SIGNAL(textChanged(QString)),
|
2007-04-25 10:57:54 +00:00
|
|
|
this, SLOT(changed_adaptor()));
|
2010-01-30 10:51:24 +00:00
|
|
|
connect(refsTW, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
|
|
|
|
this, SLOT(refHighlighted(QTreeWidgetItem *)));
|
|
|
|
connect(refsTW, SIGNAL(itemSelectionChanged()),
|
2007-04-25 10:57:54 +00:00
|
|
|
this, SLOT(selectionChanged()));
|
2010-01-30 10:51:24 +00:00
|
|
|
connect(refsTW, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
|
|
|
|
this, SLOT(refSelected(QTreeWidgetItem *)));
|
2009-02-19 19:41:41 +00:00
|
|
|
connect(sortCB, SIGNAL(clicked()),
|
|
|
|
this, SLOT(sortToggled()));
|
2009-02-24 22:56:57 +00:00
|
|
|
connect(caseSensitiveCB, SIGNAL(clicked()),
|
|
|
|
this, SLOT(caseSensitiveToggled()));
|
2010-01-30 10:51:24 +00:00
|
|
|
connect(groupCB, SIGNAL(clicked()),
|
|
|
|
this, SLOT(groupToggled()));
|
2007-05-28 22:27:45 +00:00
|
|
|
connect(gotoPB, SIGNAL(clicked()),
|
2007-04-25 10:57:54 +00:00
|
|
|
this, SLOT(gotoClicked()));
|
2007-05-28 22:27:45 +00:00
|
|
|
connect(updatePB, SIGNAL(clicked()),
|
2007-04-25 10:57:54 +00:00
|
|
|
this, SLOT(updateClicked()));
|
2007-05-28 22:27:45 +00:00
|
|
|
connect(bufferCO, SIGNAL(activated(int)),
|
2007-04-25 10:57:54 +00:00
|
|
|
this, SLOT(updateClicked()));
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
|
|
|
|
bc().setOK(okPB);
|
|
|
|
bc().setApply(applyPB);
|
|
|
|
bc().setCancel(closePB);
|
2010-01-30 10:51:24 +00:00
|
|
|
bc().addReadOnly(refsTW);
|
2007-09-05 20:33:29 +00:00
|
|
|
bc().addReadOnly(sortCB);
|
2009-02-24 22:56:57 +00:00
|
|
|
bc().addReadOnly(caseSensitiveCB);
|
2007-09-05 20:33:29 +00:00
|
|
|
bc().addReadOnly(nameED);
|
|
|
|
bc().addReadOnly(referenceED);
|
|
|
|
bc().addReadOnly(typeCO);
|
|
|
|
bc().addReadOnly(bufferCO);
|
|
|
|
|
|
|
|
restored_buffer_ = -1;
|
2008-10-28 15:38:28 +00:00
|
|
|
active_buffer_ = -1;
|
2007-09-05 20:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 19:04:38 +00:00
|
|
|
void GuiRef::changed_adaptor()
|
2007-04-25 10:57:54 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2007-04-25 10:57:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 19:04:38 +00:00
|
|
|
void GuiRef::gotoClicked()
|
2007-04-25 10:57:54 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
gotoRef();
|
2007-04-25 10:57:54 +00:00
|
|
|
}
|
|
|
|
|
2007-10-09 19:34:27 +00:00
|
|
|
|
2007-10-05 19:04:38 +00:00
|
|
|
void GuiRef::selectionChanged()
|
2007-04-25 10:57:54 +00:00
|
|
|
{
|
2007-10-05 19:04:38 +00:00
|
|
|
if (isBufferReadonly())
|
2007-04-25 10:57:54 +00:00
|
|
|
return;
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2010-01-30 10:51:24 +00:00
|
|
|
QList<QTreeWidgetItem *> selections = refsTW->selectedItems();
|
2007-04-25 10:57:54 +00:00
|
|
|
if (selections.isEmpty())
|
|
|
|
return;
|
2010-01-30 10:51:24 +00:00
|
|
|
QTreeWidgetItem * sel = selections.first();
|
2007-04-25 10:57:54 +00:00
|
|
|
refHighlighted(sel);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-30 10:51:24 +00:00
|
|
|
void GuiRef::refHighlighted(QTreeWidgetItem * sel)
|
2007-04-25 10:57:54 +00:00
|
|
|
{
|
2007-10-09 21:21:01 +00:00
|
|
|
if (isBufferReadonly())
|
2007-04-25 10:57:54 +00:00
|
|
|
return;
|
|
|
|
|
2010-01-30 10:51:24 +00:00
|
|
|
if (sel->childCount() > 0) {
|
|
|
|
sel->setExpanded(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* int const cur_item = refsTW->currentRow();
|
2007-04-25 10:57:54 +00:00
|
|
|
bool const cur_item_selected = cur_item >= 0 ?
|
|
|
|
refsLB->isSelected(cur_item) : false;*/
|
2010-01-30 10:51:24 +00:00
|
|
|
bool const cur_item_selected = refsTW->isItemSelected(sel);
|
2007-04-25 10:57:54 +00:00
|
|
|
|
|
|
|
if (cur_item_selected)
|
2010-01-30 10:51:24 +00:00
|
|
|
referenceED->setText(sel->text(0));
|
2007-04-25 10:57:54 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
if (at_ref_)
|
|
|
|
gotoRef();
|
2007-04-25 10:57:54 +00:00
|
|
|
gotoPB->setEnabled(true);
|
2007-09-05 20:33:29 +00:00
|
|
|
if (typeAllowed())
|
2007-04-25 10:57:54 +00:00
|
|
|
typeCO->setEnabled(true);
|
2010-01-30 10:51:24 +00:00
|
|
|
nameED->setHidden(!nameAllowed());
|
|
|
|
nameL->setHidden(!nameAllowed());
|
2007-04-25 10:57:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-30 10:51:24 +00:00
|
|
|
void GuiRef::refSelected(QTreeWidgetItem * sel)
|
2007-04-25 10:57:54 +00:00
|
|
|
{
|
2007-10-05 19:04:38 +00:00
|
|
|
if (isBufferReadonly())
|
2007-04-25 10:57:54 +00:00
|
|
|
return;
|
|
|
|
|
2010-01-30 10:51:24 +00:00
|
|
|
/* int const cur_item = refsTW->currentRow();
|
2007-04-25 10:57:54 +00:00
|
|
|
bool const cur_item_selected = cur_item >= 0 ?
|
|
|
|
refsLB->isSelected(cur_item) : false;*/
|
2010-01-30 10:51:24 +00:00
|
|
|
bool const cur_item_selected = refsTW->isItemSelected(sel);
|
2007-04-25 10:57:54 +00:00
|
|
|
|
|
|
|
if (cur_item_selected)
|
2010-01-30 10:51:24 +00:00
|
|
|
referenceED->setText(sel->text(0));
|
2007-04-25 10:57:54 +00:00
|
|
|
// <enter> or double click, inserts ref and closes dialog
|
2007-09-05 20:33:29 +00:00
|
|
|
slotOK();
|
2007-04-25 10:57:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-19 19:41:41 +00:00
|
|
|
void GuiRef::sortToggled()
|
2009-02-24 22:56:57 +00:00
|
|
|
{
|
|
|
|
caseSensitiveCB->setEnabled(sortCB->isChecked());
|
|
|
|
redoRefs();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiRef::caseSensitiveToggled()
|
2007-04-25 10:57:54 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
redoRefs();
|
2007-04-25 10:57:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-30 10:51:24 +00:00
|
|
|
void GuiRef::groupToggled()
|
|
|
|
{
|
|
|
|
redoRefs();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 19:04:38 +00:00
|
|
|
void GuiRef::updateClicked()
|
2007-04-25 10:57:54 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
updateRefs();
|
2007-04-25 10:57:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-23 09:47:20 +00:00
|
|
|
void GuiRef::dialogRejected()
|
2008-08-25 17:38:57 +00:00
|
|
|
{
|
2009-05-23 09:47:20 +00:00
|
|
|
resetDialog();
|
2008-08-25 17:38:57 +00:00
|
|
|
// We have to do this manually, instead of calling slotClose(), because
|
|
|
|
// the dialog has already been made invisible before rejected() triggers.
|
|
|
|
Dialog::disconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-23 09:47:20 +00:00
|
|
|
void GuiRef::resetDialog()
|
2007-09-05 20:33:29 +00:00
|
|
|
{
|
|
|
|
at_ref_ = false;
|
|
|
|
setGotoRef();
|
2007-04-25 10:57:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 19:04:38 +00:00
|
|
|
void GuiRef::closeEvent(QCloseEvent * e)
|
2007-04-25 10:57:54 +00:00
|
|
|
{
|
2007-09-11 17:06:15 +00:00
|
|
|
slotClose();
|
2009-05-23 09:47:20 +00:00
|
|
|
resetDialog();
|
2008-02-17 20:16:14 +00:00
|
|
|
e->accept();
|
2007-04-25 10:57:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 19:04:38 +00:00
|
|
|
void GuiRef::updateContents()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
int orig_type = typeCO->currentIndex();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-05 19:04:38 +00:00
|
|
|
referenceED->setText(toqstr(params_["reference"]));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-05 19:04:38 +00:00
|
|
|
nameED->setText(toqstr(params_["name"]));
|
2010-01-30 10:51:24 +00:00
|
|
|
nameED->setHidden(!nameAllowed() && !isBufferReadonly());
|
|
|
|
nameL->setHidden(!nameAllowed() && !isBufferReadonly());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
// restore type settings for new insets
|
2007-10-05 19:04:38 +00:00
|
|
|
if (params_["reference"].empty())
|
2007-09-05 20:33:29 +00:00
|
|
|
typeCO->setCurrentIndex(orig_type);
|
2006-03-05 17:24:44 +00:00
|
|
|
else
|
2007-10-05 19:04:38 +00:00
|
|
|
typeCO->setCurrentIndex(InsetRef::getType(params_.getCmdName()));
|
|
|
|
typeCO->setEnabled(typeAllowed() && !isBufferReadonly());
|
2006-03-05 17:24:44 +00:00
|
|
|
if (!typeAllowed())
|
2007-09-05 20:33:29 +00:00
|
|
|
typeCO->setCurrentIndex(0);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
// insert buffer list
|
2007-09-05 20:33:29 +00:00
|
|
|
bufferCO->clear();
|
2008-07-29 08:52:25 +00:00
|
|
|
FileNameList const & buffers = theBufferList().fileNames();
|
|
|
|
for (FileNameList::const_iterator it = buffers.begin();
|
2007-10-05 19:04:38 +00:00
|
|
|
it != buffers.end(); ++it) {
|
2010-04-21 01:19:09 +00:00
|
|
|
bufferCO->addItem(toqstr(makeDisplayPath(it->absFileName())));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
2007-10-05 19:04:38 +00:00
|
|
|
|
2008-10-28 16:02:33 +00:00
|
|
|
int const thebuffer = theBufferList().bufferNum(buffer().fileName());
|
2006-03-05 17:24:44 +00:00
|
|
|
// restore the buffer combo setting for new insets
|
2007-10-05 19:04:38 +00:00
|
|
|
if (params_["reference"].empty() && restored_buffer_ != -1
|
2008-10-28 15:38:28 +00:00
|
|
|
&& restored_buffer_ < bufferCO->count() && thebuffer == active_buffer_)
|
2007-09-05 20:33:29 +00:00
|
|
|
bufferCO->setCurrentIndex(restored_buffer_);
|
2007-10-20 10:03:45 +00:00
|
|
|
else {
|
2008-10-28 16:02:33 +00:00
|
|
|
int const num = theBufferList().bufferNum(buffer().fileName());
|
2007-10-20 10:03:45 +00:00
|
|
|
bufferCO->setCurrentIndex(num);
|
2008-10-28 15:38:28 +00:00
|
|
|
if (thebuffer != active_buffer_)
|
|
|
|
restored_buffer_ = num;
|
2007-10-20 10:03:45 +00:00
|
|
|
}
|
2008-10-28 15:38:28 +00:00
|
|
|
active_buffer_ = thebuffer;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
updateRefs();
|
2007-09-03 05:59:32 +00:00
|
|
|
bc().setValid(false);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 19:04:38 +00:00
|
|
|
void GuiRef::applyView()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
last_reference_ = referenceED->text();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-05 19:04:38 +00:00
|
|
|
params_.setCmdName(InsetRef::getName(typeCO->currentIndex()));
|
|
|
|
params_["reference"] = qstring_to_ucs4(last_reference_);
|
|
|
|
params_["name"] = qstring_to_ucs4(nameED->text());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
restored_buffer_ = bufferCO->currentIndex();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 19:04:38 +00:00
|
|
|
bool GuiRef::nameAllowed()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-10-05 19:04:38 +00:00
|
|
|
KernelDocType const doc_type = docType();
|
2007-09-10 22:32:59 +00:00
|
|
|
return doc_type != LATEX && doc_type != LITERATE;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 19:04:38 +00:00
|
|
|
bool GuiRef::typeAllowed()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-10-05 19:04:38 +00:00
|
|
|
return docType() != DOCBOOK;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 19:04:38 +00:00
|
|
|
void GuiRef::setGoBack()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
gotoPB->setText(qt_("&Go Back"));
|
|
|
|
gotoPB->setToolTip("");
|
|
|
|
gotoPB->setToolTip(qt_("Jump back"));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 19:04:38 +00:00
|
|
|
void GuiRef::setGotoRef()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
gotoPB->setText(qt_("&Go to Label"));
|
|
|
|
gotoPB->setToolTip("");
|
|
|
|
gotoPB->setToolTip(qt_("Jump to label"));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 19:04:38 +00:00
|
|
|
void GuiRef::gotoRef()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-09-10 22:32:59 +00:00
|
|
|
string ref = fromqstr(referenceED->text());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
if (at_ref_) {
|
|
|
|
// go back
|
|
|
|
setGotoRef();
|
2007-10-05 19:04:38 +00:00
|
|
|
gotoBookmark();
|
2006-03-05 17:24:44 +00:00
|
|
|
} else {
|
|
|
|
// go to the ref
|
|
|
|
setGoBack();
|
2007-10-05 19:04:38 +00:00
|
|
|
gotoRef(ref);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
at_ref_ = !at_ref_;
|
|
|
|
}
|
|
|
|
|
2009-02-24 22:56:57 +00:00
|
|
|
inline bool caseInsensitiveLessThan(QString const & s1, QString const & s2)
|
|
|
|
{
|
|
|
|
return s1.toLower() < s2.toLower();
|
|
|
|
}
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-05 19:04:38 +00:00
|
|
|
void GuiRef::redoRefs()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
// Prevent these widgets from emitting any signals whilst
|
|
|
|
// we modify their state.
|
2010-01-30 10:51:24 +00:00
|
|
|
refsTW->blockSignals(true);
|
2007-09-05 20:33:29 +00:00
|
|
|
referenceED->blockSignals(true);
|
2010-01-30 10:51:24 +00:00
|
|
|
refsTW->setUpdatesEnabled(false);
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2010-01-30 10:51:24 +00:00
|
|
|
refsTW->clear();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
// need this because Qt will send a highlight() here for
|
|
|
|
// the first item inserted
|
2007-09-05 20:33:29 +00:00
|
|
|
QString const oldSelection(referenceED->text());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2009-02-24 22:56:57 +00:00
|
|
|
QStringList refsStrings;
|
2010-01-30 10:51:24 +00:00
|
|
|
QStringList refsCategories;
|
2009-02-24 22:56:57 +00:00
|
|
|
vector<docstring>::const_iterator iter;
|
2010-01-30 10:51:24 +00:00
|
|
|
for (iter = refs_.begin(); iter != refs_.end(); ++iter) {
|
|
|
|
QString const lab = toqstr(*iter);
|
|
|
|
refsStrings.append(lab);
|
|
|
|
if (groupCB->isChecked() && lab.contains(":")) {
|
|
|
|
QString const pref = lab.split(':')[0];
|
|
|
|
if (!pref.isEmpty() && !refsCategories.contains(pref))
|
|
|
|
refsCategories.append(pref);
|
|
|
|
}
|
|
|
|
}
|
2010-01-30 12:13:00 +00:00
|
|
|
// sort categories case-intensively
|
|
|
|
qSort(refsCategories.begin(), refsCategories.end(),
|
|
|
|
caseInsensitiveLessThan /*defined above*/);
|
|
|
|
refsCategories.insert(0, qt_("<No prefix>"));
|
2009-02-24 22:56:57 +00:00
|
|
|
|
|
|
|
if (sortCB->isEnabled() && sortCB->isChecked()) {
|
|
|
|
if(caseSensitiveCB->isEnabled() && caseSensitiveCB->isChecked())
|
|
|
|
qSort(refsStrings.begin(), refsStrings.end());
|
|
|
|
else
|
|
|
|
qSort(refsStrings.begin(), refsStrings.end(),
|
|
|
|
caseInsensitiveLessThan /*defined above*/);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
2010-01-30 10:51:24 +00:00
|
|
|
|
|
|
|
if (groupCB->isChecked()) {
|
|
|
|
QList<QTreeWidgetItem *> refsCats;
|
|
|
|
for (int i = 0; i < refsCategories.size(); ++i) {
|
|
|
|
QString const cat = refsCategories.at(i);
|
|
|
|
QTreeWidgetItem * item = new QTreeWidgetItem(refsTW);
|
|
|
|
item->setText(0, cat);
|
|
|
|
for (int i = 0; i < refsStrings.size(); ++i) {
|
|
|
|
QString const ref = refsStrings.at(i);
|
|
|
|
if ((ref.startsWith(cat + QString(":")))
|
2010-01-30 12:13:00 +00:00
|
|
|
|| (cat == qt_("<No prefix>")
|
2010-01-30 10:51:24 +00:00
|
|
|
&& !ref.contains(":"))) {
|
|
|
|
QTreeWidgetItem * child =
|
|
|
|
new QTreeWidgetItem(item);
|
|
|
|
child->setText(0, ref);
|
|
|
|
item->addChild(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
refsCats.append(item);
|
|
|
|
}
|
|
|
|
refsTW->addTopLevelItems(refsCats);
|
|
|
|
} else {
|
|
|
|
QList<QTreeWidgetItem *> refsItems;
|
|
|
|
for (int i = 0; i < refsStrings.size(); ++i) {
|
|
|
|
QTreeWidgetItem * item = new QTreeWidgetItem(refsTW);
|
|
|
|
item->setText(0, refsStrings.at(i));
|
|
|
|
refsItems.append(item);
|
|
|
|
}
|
|
|
|
refsTW->addTopLevelItems(refsItems);
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
referenceED->setText(oldSelection);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-04-24 22:10:56 +00:00
|
|
|
// restore the last selection or, for new insets, highlight
|
|
|
|
// the previous selection
|
|
|
|
if (!oldSelection.isEmpty() || !last_reference_.isEmpty()) {
|
|
|
|
bool const newInset = oldSelection.isEmpty();
|
|
|
|
QString textToFind = newInset ? last_reference_ : oldSelection;
|
2007-10-09 19:34:27 +00:00
|
|
|
last_reference_.clear();
|
2010-01-30 10:51:24 +00:00
|
|
|
QTreeWidgetItemIterator it(refsTW);
|
|
|
|
while (*it) {
|
|
|
|
if ((*it)->text(0) == textToFind) {
|
|
|
|
refsTW->setCurrentItem(*it);
|
|
|
|
refsTW->setItemSelected(*it, !newInset);
|
2007-04-24 22:10:56 +00:00
|
|
|
//Make sure selected item is visible
|
2010-01-30 10:51:24 +00:00
|
|
|
refsTW->scrollToItem(*it);
|
2007-10-09 19:34:27 +00:00
|
|
|
last_reference_ = textToFind;
|
|
|
|
break;
|
2006-05-03 19:51:15 +00:00
|
|
|
}
|
2010-01-30 10:51:24 +00:00
|
|
|
++it;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
2007-04-24 22:10:56 +00:00
|
|
|
}
|
2010-01-30 10:51:24 +00:00
|
|
|
refsTW->setUpdatesEnabled(true);
|
|
|
|
refsTW->update();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2010-01-30 11:19:48 +00:00
|
|
|
// redo filter
|
|
|
|
filterLabels();
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
// Re-activate the emission of signals by these widgets.
|
2010-01-30 10:51:24 +00:00
|
|
|
refsTW->blockSignals(false);
|
2007-09-05 20:33:29 +00:00
|
|
|
referenceED->blockSignals(false);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 19:04:38 +00:00
|
|
|
void GuiRef::updateRefs()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
refs_.clear();
|
2009-02-18 23:45:00 +00:00
|
|
|
int const the_buffer = bufferCO->currentIndex();
|
|
|
|
if (the_buffer != -1) {
|
|
|
|
FileName const & name = theBufferList().fileNames()[the_buffer];
|
|
|
|
Buffer const * buf = theBufferList().getBuffer(name);
|
|
|
|
buf->getLabelList(refs_);
|
|
|
|
}
|
2007-09-05 20:33:29 +00:00
|
|
|
sortCB->setEnabled(!refs_.empty());
|
2009-02-24 22:56:57 +00:00
|
|
|
caseSensitiveCB->setEnabled(sortCB->isEnabled() && sortCB->isChecked());
|
2010-01-30 10:51:24 +00:00
|
|
|
refsTW->setEnabled(!refs_.empty());
|
|
|
|
// refsTW should only be the focus proxy when it is enabled
|
|
|
|
setFocusProxy(refs_.empty() ? 0 : refsTW);
|
2007-09-05 20:33:29 +00:00
|
|
|
gotoPB->setEnabled(!refs_.empty());
|
2006-03-05 17:24:44 +00:00
|
|
|
redoRefs();
|
|
|
|
}
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2007-10-05 19:04:38 +00:00
|
|
|
bool GuiRef::isValid()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
return !referenceED->text().isEmpty();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2007-10-05 19:04:38 +00:00
|
|
|
|
|
|
|
void GuiRef::gotoRef(string const & ref)
|
|
|
|
{
|
|
|
|
dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0"));
|
|
|
|
dispatch(FuncRequest(LFUN_LABEL_GOTO, ref));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiRef::gotoBookmark()
|
|
|
|
{
|
|
|
|
dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-30 11:19:48 +00:00
|
|
|
void GuiRef::filterLabels()
|
2010-01-30 10:51:24 +00:00
|
|
|
{
|
|
|
|
Qt::CaseSensitivity cs = csFindCB->isChecked() ?
|
|
|
|
Qt::CaseSensitive : Qt::CaseInsensitive;
|
2010-01-30 11:19:48 +00:00
|
|
|
QTreeWidgetItemIterator it(refsTW);
|
2010-01-30 10:51:24 +00:00
|
|
|
while (*it) {
|
|
|
|
(*it)->setHidden(
|
|
|
|
(*it)->childCount() == 0
|
|
|
|
&& !(*it)->text(0).contains(findLE->text(), cs)
|
|
|
|
);
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-20 09:24:14 +00:00
|
|
|
bool GuiRef::initialiseParams(std::string const & data)
|
|
|
|
{
|
2010-10-29 00:25:28 +00:00
|
|
|
InsetCommand::string2params(data, params_);
|
2008-04-20 09:24:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiRef::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));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
Dialog * createGuiRef(GuiView & lv) { return new GuiRef(lv); }
|
2007-10-05 19:04:38 +00:00
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-04-25 10:57:54 +00:00
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_GuiRef.cpp"
|