#include "GuiView.h"
#include "qt_helpers.h"
#include "TocModel.h"
+#include "FancyLineEdit.h"
#include "Buffer.h"
#include "BufferView.h"
+#include "Cursor.h"
#include "CutAndPaste.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
#include <QHeaderView>
#include <QMenu>
+#include <QTimer>
#include <vector>
// Only one item selected at a time.
tocTV->setSelectionMode(QAbstractItemView::SingleSelection);
- setFocusProxy(tocTV);
// The toc types combo won't change its model.
typeCO->setModel(gui_view_.tocModels().nameModel());
+ // The filter bar
+ filter_ = new FancyLineEdit(this);
+ filter_->setClearButton(true);
+ filter_->setPlaceholderText(qt_("All items"));
+ filterBarL->addWidget(filter_, 0);
+ filterLA->setBuddy(filter_);
+ setFocusProxy(filter_);
+
// Make sure the buttons are disabled when first shown without a loaded
// Buffer.
enableControls(false);
this, SLOT(showContextMenu(const QPoint &)));
connect(tocTV, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(showContextMenu(const QPoint &)));
- connect(filterLE, SIGNAL(textEdited(QString)),
+ 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()));
// setting the update timer
}
-void TocWidget::doDispatch(Cursor & cur, FuncRequest const & cmd)
+void TocWidget::doDispatch(Cursor & cur, FuncRequest const & cmd,
+ DispatchResult & dr)
{
Inset * inset = itemInset();
- FuncRequest tmpcmd(cmd);
QModelIndex const & index = tocTV->currentIndex();
TocItem const & item =
switch (cmd.action())
{
case LFUN_CHANGE_ACCEPT:
- case LFUN_CHANGE_REJECT:
+ case LFUN_CHANGE_REJECT: {
+ // The action is almost always LYX_UNKNOWN_ACTION, which will
+ // have the effect of moving the cursor to the location of
+ // the change. (See TocItem::action.)
dispatch(item.action());
- cur.dispatch(tmpcmd);
+ // If we do not reset the origin, then the request will be sent back
+ // here, and we are in an infinite loop. But we need the dispatch
+ // machinery to clean up for us, if the cursor is in an inset that
+ // will be deleted. See bug #10316.
+ FuncRequest tmpcmd(cmd);
+ tmpcmd.setOrigin(FuncRequest::INTERNAL);
+ dispatch(tmpcmd);
+ dr.forceBufferUpdate();
break;
+ }
case LFUN_SECTION_SELECT:
dispatch(item.action());
- cur.dispatch(tmpcmd);
+ cur.dispatch(cmd);
// necessary to get the selection drawn.
cur.buffer()->changed(true);
gui_view_.setFocus();
outline(cmd.action());
break;
- default:
+ default: {
+ FuncRequest tmpcmd(cmd);
if (inset)
inset->dispatch(cur, tmpcmd);
}
+ }
cur.endUndoGroup();
}
}
-void TocWidget::on_typeCO_currentIndexChanged(int index)
+void TocWidget::on_typeCO_activated(int index)
{
-
if (index == -1)
return;
current_type_ = typeCO->itemData(index).toString();
//if another window is active, this attempt will fail,
//but it will work at least for the second attempt
- gui_view_.activateWindow();
+ gui_view_.activateWindow();
enableControls(false);
goTo(list[0]);
{
fr.setViewOrigin(&gui_view_);
- DispatchResult dr=dispatch(fr);
+ 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());
}
QModelIndexList indices = tocTV->model()->match(
tocTV->model()->index(0, 0),
- Qt::DisplayRole, "*", -1,
- Qt::MatchFlags(Qt::MatchWildcard|Qt::MatchRecursive));
+ Qt::DisplayRole, ".*", -1,
+#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
+ Qt::MatchFlags(Qt::MatchRegularExpression|Qt::MatchRecursive));
+#else
+ // deprecated in Qt 5.15.
+ Qt::MatchFlags(Qt::MatchRegExp|Qt::MatchRecursive));
+#endif
+
+ bool const show_active =
+ activeFilterCO->currentIndex() != 2;
+ bool const show_inactive =
+ activeFilterCO->currentIndex() != 1;
int size = indices.size();
+ QString const matchstring = filter_ ? filter_->text() : QString();
for (int i = 0; i < size; i++) {
QModelIndex index = indices[i];
- bool const matches =
- index.data().toString().contains(
- filterLE->text(), Qt::CaseInsensitive);
+ bool matches = index.data().toString().contains(
+ matchstring, Qt::CaseInsensitive);
+ TocItem const & item =
+ gui_view_.tocModels().currentItem(current_type_, index);
+ matches &= (show_active && item.isOutput()) || (show_inactive && !item.isOutput());
tocTV->setRowHidden(index.row(), index.parent(), !matches);
}
// recursively unhide parents of unhidden children