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
|
|
|
|
2016-09-17 13:03:33 +02:00
|
|
|
#include "GuiApplication.h"
|
|
|
|
|
2007-10-05 19:04:38 +00:00
|
|
|
#include "Buffer.h"
|
2016-06-18 19:29:15 -04:00
|
|
|
#include "BufferParams.h"
|
2007-10-05 19:04:38 +00:00
|
|
|
#include "BufferList.h"
|
2018-02-14 17:18:24 +01:00
|
|
|
#include "BufferView.h"
|
|
|
|
#include "Cursor.h"
|
2007-10-05 19:04:38 +00:00
|
|
|
#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;
|
|
|
|
|
2016-09-17 13:03:33 +02:00
|
|
|
// The filter bar
|
|
|
|
filter_ = new FancyLineEdit(this);
|
|
|
|
filter_->setButtonPixmap(FancyLineEdit::Right, getPixmap("images/", "editclear", "svgz,png"));
|
|
|
|
filter_->setButtonVisible(FancyLineEdit::Right, true);
|
|
|
|
filter_->setButtonToolTip(FancyLineEdit::Right, qt_("Clear text"));
|
|
|
|
filter_->setAutoHideButton(FancyLineEdit::Right, true);
|
2016-09-17 13:06:41 +02:00
|
|
|
filter_->setPlaceholderText(qt_("All available labels"));
|
2016-09-17 13:03:33 +02:00
|
|
|
filter_->setToolTip(qt_("Enter string to filter the list of available labels"));
|
2017-02-26 22:15:50 +01:00
|
|
|
#if (QT_VERSION < 0x050000)
|
|
|
|
connect(filter_, SIGNAL(downPressed()),
|
|
|
|
refsTW, SLOT(setFocus()));
|
|
|
|
#else
|
|
|
|
connect(filter_, &FancyLineEdit::downPressed,
|
|
|
|
refsTW, [=](){ focusAndHighlight(refsTW); });
|
|
|
|
#endif
|
2016-09-17 13:03:33 +02:00
|
|
|
|
|
|
|
filterBarL->addWidget(filter_, 0);
|
|
|
|
findKeysLA->setBuddy(filter_);
|
|
|
|
|
|
|
|
sortingCO->addItem(qt_("By Occurrence"), "unsorted");
|
|
|
|
sortingCO->addItem(qt_("Alphabetically (Case-Insensitive)"), "nocase");
|
|
|
|
sortingCO->addItem(qt_("Alphabetically (Case-Sensitive)"), "case");
|
|
|
|
|
2018-07-10 13:04:02 +02:00
|
|
|
buttonBox->button(QDialogButtonBox::Reset)->setText(qt_("&Update"));
|
|
|
|
buttonBox->button(QDialogButtonBox::Reset)->setToolTip(qt_("Update the label list"));
|
|
|
|
|
2010-01-30 10:51:24 +00:00
|
|
|
refsTW->setColumnCount(1);
|
|
|
|
refsTW->header()->setVisible(false);
|
|
|
|
|
2009-05-23 09:47:20 +00:00
|
|
|
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()));
|
2016-09-17 13:03:33 +02:00
|
|
|
connect(referenceED, SIGNAL(textChanged(QString)),
|
|
|
|
this, SLOT(refTextChanged(QString)));
|
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()));
|
2016-09-17 13:03:33 +02:00
|
|
|
connect(filter_, SIGNAL(textEdited(QString)),
|
2010-01-30 11:19:48 +00:00
|
|
|
this, SLOT(filterLabels()));
|
2016-09-18 09:02:23 +02:00
|
|
|
connect(filter_, SIGNAL(rightButtonClicked()),
|
|
|
|
this, SLOT(resetFilter()));
|
2015-05-17 17:27:12 +02:00
|
|
|
connect(csFindCB, SIGNAL(clicked()),
|
2010-01-30 11:19:48 +00:00
|
|
|
this, SLOT(filterLabels()));
|
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 *)));
|
2016-09-17 13:03:33 +02:00
|
|
|
connect(sortingCO, SIGNAL(activated(int)),
|
2009-02-19 19:41:41 +00:00
|
|
|
this, SLOT(sortToggled()));
|
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(bufferCO, SIGNAL(activated(int)),
|
2007-04-25 10:57:54 +00:00
|
|
|
this, SLOT(updateClicked()));
|
2016-06-18 19:29:15 -04:00
|
|
|
connect(pluralCB, SIGNAL(clicked()),
|
|
|
|
this, SLOT(changed_adaptor()));
|
|
|
|
connect(capsCB, SIGNAL(clicked()),
|
|
|
|
this, SLOT(changed_adaptor()));
|
2017-01-07 14:39:03 -05:00
|
|
|
connect(noprefixCB, SIGNAL(clicked()),
|
|
|
|
this, SLOT(changed_adaptor()));
|
2016-06-18 19:29:15 -04:00
|
|
|
|
|
|
|
enableBoxes();
|
2007-04-25 10:57:54 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
|
2018-07-10 13:04:02 +02:00
|
|
|
bc().setOK(buttonBox->button(QDialogButtonBox::Ok));
|
|
|
|
bc().setApply(buttonBox->button(QDialogButtonBox::Apply));
|
|
|
|
bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
|
2007-09-05 20:33:29 +00:00
|
|
|
bc().addReadOnly(typeCO);
|
|
|
|
|
|
|
|
restored_buffer_ = -1;
|
2008-10-28 15:38:28 +00:00
|
|
|
active_buffer_ = -1;
|
2017-02-26 22:15:50 +01:00
|
|
|
|
|
|
|
setFocusProxy(filter_);
|
2007-09-05 20:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-29 16:12:31 +02:00
|
|
|
void GuiRef::enableView(bool enable)
|
|
|
|
{
|
|
|
|
if (!enable)
|
|
|
|
// In the opposite case, updateContents() will be called anyway.
|
|
|
|
updateContents();
|
|
|
|
GuiDialog::enableView(enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-18 19:29:15 -04:00
|
|
|
void GuiRef::enableBoxes()
|
|
|
|
{
|
2019-01-06 17:45:08 -05:00
|
|
|
QString const reftype =
|
|
|
|
typeCO->itemData(typeCO->currentIndex()).toString();
|
|
|
|
bool const isFormatted = (reftype == "formatted");
|
|
|
|
bool const isLabelOnly = (reftype == "labelonly");
|
2016-06-18 19:29:15 -04:00
|
|
|
bool const usingRefStyle = buffer().params().use_refstyle;
|
|
|
|
pluralCB->setEnabled(isFormatted && usingRefStyle);
|
2017-01-07 17:26:06 -05:00
|
|
|
capsCB->setEnabled(isFormatted && usingRefStyle);
|
|
|
|
noprefixCB->setEnabled(isLabelOnly);
|
2016-06-18 19:29:15 -04: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();
|
2016-06-18 19:29:15 -04:00
|
|
|
enableBoxes();
|
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
|
|
|
{
|
2016-06-06 19:36:27 -04:00
|
|
|
// By setting last_reference_, we ensure that the reference
|
|
|
|
// to which we are going (or from which we are returning) is
|
|
|
|
// restored in the dialog. It's a bit of a hack, but it works,
|
|
|
|
// and no-one seems to have any better idea.
|
2017-07-03 13:53:14 -04:00
|
|
|
bool const toggled =
|
2016-06-18 18:32:21 -04:00
|
|
|
last_reference_.isEmpty() || last_reference_.isNull();
|
2016-06-18 18:27:51 -04:00
|
|
|
if (toggled)
|
|
|
|
last_reference_ = referenceED->text();
|
2007-09-05 20:33:29 +00:00
|
|
|
gotoRef();
|
2016-06-18 18:27:51 -04:00
|
|
|
if (toggled)
|
|
|
|
last_reference_.clear();
|
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
|
|
|
{
|
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;*/
|
2020-03-05 20:36:09 -05:00
|
|
|
bool const cur_item_selected = sel->isSelected();
|
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);
|
2020-07-05 02:19:20 +02:00
|
|
|
if (!isBufferReadonly())
|
2007-04-25 10:57:54 +00:00
|
|
|
typeCO->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-17 13:03:33 +02:00
|
|
|
void GuiRef::refTextChanged(QString const & str)
|
|
|
|
{
|
|
|
|
gotoPB->setEnabled(!str.isEmpty());
|
|
|
|
typeCO->setEnabled(!str.isEmpty());
|
|
|
|
typeLA->setEnabled(!str.isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2013-04-19 22:24:16 -04:00
|
|
|
if (sel->childCount()) {
|
|
|
|
sel->setExpanded(false);
|
|
|
|
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;*/
|
2020-03-05 20:36:09 -05:00
|
|
|
bool const cur_item_selected = sel->isSelected();
|
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()
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-10 13:04:02 +02:00
|
|
|
void GuiRef::on_buttonBox_clicked(QAbstractButton * button)
|
|
|
|
{
|
|
|
|
switch (buttonBox->standardButton(button)) {
|
|
|
|
case QDialogButtonBox::Ok:
|
|
|
|
slotOK();
|
|
|
|
break;
|
|
|
|
case QDialogButtonBox::Apply:
|
|
|
|
slotApply();
|
|
|
|
break;
|
|
|
|
case QDialogButtonBox::Cancel:
|
|
|
|
slotClose();
|
|
|
|
resetDialog();
|
|
|
|
break;
|
|
|
|
case QDialogButtonBox::Reset:
|
|
|
|
updateClicked();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2018-02-14 17:18:24 +01:00
|
|
|
QString const orig_type =
|
|
|
|
typeCO->itemData(typeCO->currentIndex()).toString();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2012-09-29 16:12:31 +02:00
|
|
|
referenceED->clear();
|
2018-02-14 17:18:24 +01:00
|
|
|
typeCO->clear();
|
|
|
|
|
|
|
|
// FIXME Bring InsetMathRef on par with InsetRef
|
|
|
|
// (see #9798)
|
|
|
|
typeCO->addItem(qt_("<reference>"), "ref");
|
|
|
|
typeCO->addItem(qt_("(<reference>)"), "eqref");
|
|
|
|
typeCO->addItem(qt_("<page>"), "pageref");
|
|
|
|
typeCO->addItem(qt_("on page <page>"), "vpageref");
|
|
|
|
typeCO->addItem(qt_("<reference> on page <page>"), "vref");
|
2018-04-06 22:29:04 -04:00
|
|
|
typeCO->addItem(qt_("Textual reference"), "nameref");
|
2018-02-14 17:18:24 +01:00
|
|
|
if (bufferview()->cursor().inTexted()) {
|
|
|
|
typeCO->addItem(qt_("Formatted reference"), "formatted");
|
|
|
|
typeCO->addItem(qt_("Label only"), "labelonly");
|
|
|
|
} else
|
|
|
|
typeCO->addItem(qt_("Formatted reference"), "prettyref");
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2012-09-29 16:12:31 +02:00
|
|
|
referenceED->setText(toqstr(params_["reference"]));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
// restore type settings for new insets
|
2016-09-08 15:04:58 +02:00
|
|
|
bool const new_inset = params_["reference"].empty();
|
2018-02-14 17:18:24 +01:00
|
|
|
if (new_inset) {
|
|
|
|
int index = typeCO->findData(orig_type);
|
|
|
|
if (index == -1)
|
|
|
|
index = 0;
|
|
|
|
typeCO->setCurrentIndex(index);
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
else
|
2018-02-14 17:18:24 +01:00
|
|
|
typeCO->setCurrentIndex(
|
|
|
|
typeCO->findData(toqstr(params_.getCmdName())));
|
2020-07-05 02:19:20 +02:00
|
|
|
typeCO->setEnabled(!isBufferReadonly());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2016-06-18 19:29:15 -04:00
|
|
|
pluralCB->setChecked(params_["plural"] == "true");
|
|
|
|
capsCB->setChecked(params_["caps"] == "true");
|
2017-01-07 14:39:03 -05:00
|
|
|
noprefixCB->setChecked(params_["noprefix"] == "true");
|
2016-06-18 19:29:15 -04:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
// insert buffer list
|
2007-09-05 20:33:29 +00:00
|
|
|
bufferCO->clear();
|
2014-07-05 12:51:40 +02:00
|
|
|
FileNameList const buffers(theBufferList().fileNames());
|
2008-07-29 08:52:25 +00:00
|
|
|
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
|
2016-09-10 10:32:40 +02:00
|
|
|
if (new_inset && 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();
|
2016-06-18 19:29:15 -04:00
|
|
|
enableBoxes();
|
2016-09-08 15:04:58 +02:00
|
|
|
// Activate OK/Apply buttons if the users inserts a new ref
|
|
|
|
// and we have a valid pre-setting.
|
|
|
|
bc().setValid(isValid() && new_inset);
|
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
|
|
|
|
2018-02-14 17:18:24 +01:00
|
|
|
params_.setCmdName(fromqstr(typeCO->itemData(typeCO->currentIndex()).toString()));
|
2007-10-05 19:04:38 +00:00
|
|
|
params_["reference"] = qstring_to_ucs4(last_reference_);
|
2017-07-03 13:53:14 -04:00
|
|
|
params_["plural"] = pluralCB->isChecked() ?
|
2016-06-18 19:29:15 -04:00
|
|
|
from_ascii("true") : from_ascii("false");
|
2017-07-03 13:53:14 -04:00
|
|
|
params_["caps"] = capsCB->isChecked() ?
|
2016-06-18 19:29:15 -04:00
|
|
|
from_ascii("true") : from_ascii("false");
|
2017-07-03 13:53:14 -04:00
|
|
|
params_["noprefix"] = noprefixCB->isChecked() ?
|
2017-01-07 14:39:03 -05:00
|
|
|
from_ascii("true") : from_ascii("false");
|
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
|
|
|
void GuiRef::setGoBack()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
gotoPB->setText(qt_("&Go Back"));
|
2016-09-17 13:03:33 +02:00
|
|
|
gotoPB->setToolTip(qt_("Jump back to the original cursor location"));
|
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"));
|
2016-09-17 13:03:33 +02:00
|
|
|
gotoPB->setToolTip(qt_("Jump to the selected 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;
|
2013-04-19 07:48:26 -04:00
|
|
|
bool noprefix = false;
|
2010-01-30 10:51:24 +00:00
|
|
|
for (iter = refs_.begin(); iter != refs_.end(); ++iter) {
|
|
|
|
QString const lab = toqstr(*iter);
|
|
|
|
refsStrings.append(lab);
|
2013-04-19 07:48:26 -04:00
|
|
|
if (groupCB->isChecked()) {
|
|
|
|
if (lab.contains(":")) {
|
|
|
|
QString const pref = lab.split(':')[0];
|
|
|
|
if (!refsCategories.contains(pref)) {
|
|
|
|
if (!pref.isEmpty())
|
|
|
|
refsCategories.append(pref);
|
|
|
|
else
|
|
|
|
noprefix = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
noprefix = true;
|
2010-01-30 10:51:24 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-30 12:13:00 +00:00
|
|
|
// sort categories case-intensively
|
Fix deprecation warnings from use of qSort()
This commit replaces qSort with std::sort to fix warnings from compiling with
Qt 5.14.1. Below is one of the warnings:
error: ‘void qSort(RandomAccessIterator, RandomAccessIterator, LessThan) [with RandomAccessIterator = QList<lyx::ColorCode>::iterator; LessT$
an = bool (*)(lyx::ColorCode, lyx::ColorCode)]’ is deprecated: Use std::sort [-Werror=deprecated-declarations]
qSort() has been deprecated since Qt 5.2. Quoting from the ChangeLog [1]:
With STL no longer being optional for building and using Qt, a number of
parts of QtAlgorithms no longer make sense, and have therefore been
deprecated. Replacements are available in the STL, and generally have
much better performance
There are some cases that require more than just a trivial substitution, but
our code does not appear to use any of those cases.
For some discussion on the differences in speed of std::sort() and
qSort(), see the following:
https://phabricator.kde.org/D10857
These are just warnings now, but will likely be errors with Qt 6:
https://bugreports.qt.io/browse/QTBUG-73048
I tested that LyX can still be built against Qt 4.8.7 with this commit.
This commit follows 24926b2e, which also fixes some deprecation warnings.
[1]
https://code.qt.io/cgit/qt/qtbase.git/tree/dist/changes-5.2.0/?h=v5.2.0
2020-03-05 11:35:49 -05:00
|
|
|
sort(refsCategories.begin(), refsCategories.end(),
|
|
|
|
caseInsensitiveLessThan /*defined above*/);
|
2013-04-19 07:48:26 -04:00
|
|
|
if (noprefix)
|
|
|
|
refsCategories.insert(0, qt_("<No prefix>"));
|
2009-02-24 22:56:57 +00:00
|
|
|
|
2020-03-05 12:16:26 -05:00
|
|
|
QString const sort_method = sortingCO->isEnabled() ?
|
|
|
|
sortingCO->itemData(sortingCO->currentIndex()).toString()
|
|
|
|
: QString();
|
|
|
|
if (sort_method == "nocase")
|
|
|
|
sort(refsStrings.begin(), refsStrings.end(),
|
Fix deprecation warnings from use of qSort()
This commit replaces qSort with std::sort to fix warnings from compiling with
Qt 5.14.1. Below is one of the warnings:
error: ‘void qSort(RandomAccessIterator, RandomAccessIterator, LessThan) [with RandomAccessIterator = QList<lyx::ColorCode>::iterator; LessT$
an = bool (*)(lyx::ColorCode, lyx::ColorCode)]’ is deprecated: Use std::sort [-Werror=deprecated-declarations]
qSort() has been deprecated since Qt 5.2. Quoting from the ChangeLog [1]:
With STL no longer being optional for building and using Qt, a number of
parts of QtAlgorithms no longer make sense, and have therefore been
deprecated. Replacements are available in the STL, and generally have
much better performance
There are some cases that require more than just a trivial substitution, but
our code does not appear to use any of those cases.
For some discussion on the differences in speed of std::sort() and
qSort(), see the following:
https://phabricator.kde.org/D10857
These are just warnings now, but will likely be errors with Qt 6:
https://bugreports.qt.io/browse/QTBUG-73048
I tested that LyX can still be built against Qt 4.8.7 with this commit.
This commit follows 24926b2e, which also fixes some deprecation warnings.
[1]
https://code.qt.io/cgit/qt/qtbase.git/tree/dist/changes-5.2.0/?h=v5.2.0
2020-03-05 11:35:49 -05:00
|
|
|
caseInsensitiveLessThan /*defined above*/);
|
2020-03-05 12:16:26 -05:00
|
|
|
else if (sort_method == "case")
|
|
|
|
sort(refsStrings.begin(), refsStrings.end());
|
2015-05-17 17:27:12 +02: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);
|
2018-02-22 00:20:19 -05:00
|
|
|
for (int j = 0; j < refsStrings.size(); ++j) {
|
|
|
|
QString const ref = refsStrings.at(j);
|
2010-01-30 10:51:24 +00:00
|
|
|
if ((ref.startsWith(cat + QString(":")))
|
2010-01-30 12:13:00 +00:00
|
|
|
|| (cat == qt_("<No prefix>")
|
2013-04-19 07:48:15 -04:00
|
|
|
&& (!ref.mid(1).contains(":") || ref.left(1).contains(":")))) {
|
|
|
|
QTreeWidgetItem * child =
|
|
|
|
new QTreeWidgetItem(item);
|
|
|
|
child->setText(0, ref);
|
|
|
|
item->addChild(child);
|
2010-01-30 10:51:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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-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;
|
2016-06-06 19:36:27 -04:00
|
|
|
referenceED->setText(textToFind);
|
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) {
|
2015-05-17 17:27:12 +02:00
|
|
|
refsTW->setCurrentItem(*it);
|
2020-03-05 11:11:09 -05:00
|
|
|
(*it)->setSelected(true);
|
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);
|
2016-09-17 13:03:33 +02:00
|
|
|
|
|
|
|
gotoPB->setEnabled(!referenceED->text().isEmpty());
|
|
|
|
typeCO->setEnabled(!referenceED->text().isEmpty());
|
|
|
|
typeLA->setEnabled(!referenceED->text().isEmpty());
|
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) {
|
2014-07-05 12:51:40 +02:00
|
|
|
FileNameList const names(theBufferList().fileNames());
|
|
|
|
FileName const & name = names[the_buffer];
|
2009-02-18 23:45:00 +00:00
|
|
|
Buffer const * buf = theBufferList().getBuffer(name);
|
|
|
|
buf->getLabelList(refs_);
|
2012-09-29 16:12:31 +02:00
|
|
|
}
|
2016-09-17 13:03:33 +02:00
|
|
|
sortingCO->setEnabled(!refs_.empty());
|
2010-01-30 10:51:24 +00:00
|
|
|
refsTW->setEnabled(!refs_.empty());
|
2013-04-19 22:39:17 -04:00
|
|
|
groupCB->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
|
2016-09-17 13:03:33 +02:00
|
|
|
&& !(*it)->text(0).contains(filter_->text(), cs)
|
2010-01-30 10:51:24 +00:00
|
|
|
);
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-18 09:02:23 +02:00
|
|
|
void GuiRef::resetFilter()
|
|
|
|
{
|
|
|
|
filter_->setText(QString());
|
|
|
|
filterLabels();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-22 00:20:19 -05:00
|
|
|
bool GuiRef::initialiseParams(std::string const & sdata)
|
2008-04-20 09:24:14 +00:00
|
|
|
{
|
2018-02-22 00:20:19 -05:00
|
|
|
InsetCommand::string2params(sdata, 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"
|