namespace frontend {
TocWidget::TocWidget(GuiView & gui_view, QWidget * parent)
- : QWidget(parent), depth_(0), persistent_(false), gui_view_(gui_view),
- timer_(new QTimer(this))
+ : QWidget(parent), depth_(0), persistent_(false), keep_expanded_(false),
+ gui_view_(gui_view), timer_(new QTimer(this))
{
setupUi(this);
this, SLOT(showContextMenu(const QPoint &)));
connect(filter_, SIGNAL(textEdited(QString)),
this, SLOT(filterContents()));
-#if (QT_VERSION < 0x050000)
- connect(filter_, SIGNAL(downPressed()),
- tocTV, SLOT(setFocus()));
-#else
connect(filter_, &FancyLineEdit::downPressed,
tocTV, [this](){ focusAndHighlight(tocTV); });
-#endif
connect(activeFilterCO, SIGNAL(activated(int)),
this, SLOT(filterContents()));
void TocWidget::doDispatch(Cursor & cur, FuncRequest const & cmd,
DispatchResult & dr)
{
-
Inset * inset = itemInset();
QModelIndex const & index = tocTV->currentIndex();
void TocWidget::on_tocTV_pressed(QModelIndex const & index)
{
-
+ DocIterator const & dit = gui_view_.documentBufferView()->cursor();
+ keep_expanded_ = gui_view_.tocModels().currentIndex(current_type_, dit) == index;
Qt::MouseButtons const button = QApplication::mouseButtons();
if (button & Qt::LeftButton) {
goTo(index);
}
+void TocWidget::on_tocTV_doubleClicked(QModelIndex const &)
+{
+ keep_expanded_ = true;
+}
+
+
void TocWidget::goTo(QModelIndex const & index)
{
LYXERR(Debug::GUI, "goto " << index.row()
}
-void TocWidget::on_typeCO_currentIndexChanged(int index)
+void TocWidget::on_typeCO_activated(int index)
{
-
if (index == -1)
return;
current_type_ = typeCO->itemData(index).toString();
void TocWidget::sendDispatch(FuncRequest fr)
{
-
fr.setViewOrigin(&gui_view_);
+ GuiWorkArea * old_wa = gui_view_.currentWorkArea();
+ GuiWorkArea * doc_wa = gui_view_.currentMainWorkArea();
+ /* The ToC command should be dispatched to the document work area,
+ * not the Adv. Find&Replace (which is the only other know
+ * possibility.
+ */
+ if (doc_wa != nullptr && doc_wa != old_wa)
+ gui_view_.setCurrentWorkArea(doc_wa);
DispatchResult const & dr = dispatch(fr);
+ /* If the current workarea has not explicitely changed, and the
+ * original one is still visible, let's reset it.
+ */
+ if (gui_view_.currentWorkArea() == doc_wa
+ && gui_view_.hasVisibleWorkArea(old_wa)
+ && doc_wa != old_wa)
+ gui_view_.setCurrentWorkArea(old_wa);
if (dr.error())
gui_view_.message(dr.message());
}
// Expensive operations are on a timer. We finish the update immediately
// for sparse edition actions, i.e. there was no edition/cursor movement
// recently, then every 300ms.
- if (!timer_->isActive()) {
+ if (!timer_->isActive() && !keep_expanded_) {
finishUpdateView();
timer_->start(300);
}
+ keep_expanded_ = false;
}
// text and moving with arrows. For bigger operations, this is negligible,
// and outweighted by TocModels::reset() anyway.
if (canNavigate()) {
- if (!persistent_)
+ if (!persistent_ && !keep_expanded_)
setTreeDepth(depth_);
+ keep_expanded_ = false;
persistentCB->setChecked(persistent_);
// select the item at current cursor location
if (gui_view_.documentBufferView()) {
typeCO->setCurrentIndex(new_index);
typeCO->blockSignals(false);
updateViewNow();
+ if (persistent_)
+ setTreeDepth(depth_);
}
} // namespace frontend