commit 01d6333db21d3ed2c16f7c958fa204ff1c52044a Author: Guillaume Munch <g...@lyx.org> Date: Wed Sep 7 01:36:55 2016 +0100
Implement reverse-search in the source panel Double-clicking on a line in the source panel triggers the selection of the corresponding line in the Buffer View. --- src/TexRow.cpp | 6 ++++++ src/TexRow.h | 1 + src/frontends/qt4/GuiViewSource.cpp | 30 ++++++++++++++++++++---------- src/frontends/qt4/GuiViewSource.h | 4 +++- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/TexRow.cpp b/src/TexRow.cpp index 9fd11c2..3b2d565 100644 --- a/src/TexRow.cpp +++ b/src/TexRow.cpp @@ -305,6 +305,12 @@ FuncRequest TexRow::goToFunc(TextEntry start, TextEntry end) } +//static +FuncRequest TexRow::goToFunc(std::pair<TextEntry,TextEntry> entries) +{ + return goToFunc(entries.first, entries.second); +} + //static RowEntry TexRow::rowEntryFromCursorSlice(CursorSlice const & slice) diff --git a/src/TexRow.h b/src/TexRow.h index a95b205..5ec7874 100644 --- a/src/TexRow.h +++ b/src/TexRow.h @@ -168,6 +168,7 @@ public: // A FuncRequest to select from start to end static FuncRequest goToFunc(TextEntry start, TextEntry end); + static FuncRequest goToFunc(std::pair<TextEntry,TextEntry> entries); /** * getDocIteratorFromRow - find pids and positions for a given row diff --git a/src/frontends/qt4/GuiViewSource.cpp b/src/frontends/qt4/GuiViewSource.cpp index 31013a7..1ed549a 100644 --- a/src/frontends/qt4/GuiViewSource.cpp +++ b/src/frontends/qt4/GuiViewSource.cpp @@ -21,6 +21,8 @@ #include "BufferView.h" #include "Cursor.h" #include "Format.h" +#include "FuncRequest.h" +#include "LyX.h" #include "Paragraph.h" #include "TexRow.h" @@ -66,11 +68,6 @@ ViewSourceWidget::ViewSourceWidget() this, SLOT(setViewFormat(int))); connect(outputFormatCO, SIGNAL(activated(int)), this, SLOT(contentsChanged())); -#ifdef DEVEL_VERSION - if (lyx::lyxerr.debugging(Debug::LATEX)) - connect(viewSourceTV, SIGNAL(cursorPositionChanged()), - this, SLOT(gotoCursor())); -#endif // setting the update timer update_timer_->setSingleShot(true); @@ -90,6 +87,9 @@ ViewSourceWidget::ViewSourceWidget() viewSourceTV->setFont(guiApp->typewriterSystemFont()); // again, personal taste viewSourceTV->setWordWrapMode(QTextOption::NoWrap); + + // catch double click events + viewSourceTV->viewport()->installEventFilter(this); } @@ -320,14 +320,24 @@ docstring ViewSourceWidget::currentFormatName(BufferView const * bv) const } -// only used in DEVEL_MODE for debugging -// need a proper LFUN if we want to implement it in release mode -void ViewSourceWidget::gotoCursor() +bool ViewSourceWidget::eventFilter(QObject * obj, QEvent * ev) +{ + // this event filter is installed on the viewport of the QTextView + if (obj == viewSourceTV->viewport() && + ev->type() == QEvent::MouseButtonDblClick) { + goToCursor(); + return true; + } + return false; +} + + +void ViewSourceWidget::goToCursor() const { - if (!bv_ || !texrow_) + if (!texrow_) return; int row = viewSourceTV->textCursor().blockNumber() + 1; - const_cast<BufferView *>(bv_)->setCursorFromRow(row, *texrow_); + dispatch(TexRow::goToFunc(texrow_->getEntriesFromRow(row))); } diff --git a/src/frontends/qt4/GuiViewSource.h b/src/frontends/qt4/GuiViewSource.h index 055bef3..33a9c13 100644 --- a/src/frontends/qt4/GuiViewSource.h +++ b/src/frontends/qt4/GuiViewSource.h @@ -69,7 +69,7 @@ public Q_SLOTS: /// void contentsChanged(); /// - void gotoCursor(); + void goToCursor() const; /// Name of the current format. Empty if none. docstring currentFormatName(BufferView const * bv) const; @@ -84,6 +84,8 @@ private: /// Get the source code of selected paragraphs, or the whole document. void getContent(BufferView const * view, Buffer::OutputWhat output, docstring & str, std::string const & format, bool master); + /// Grab double clicks on the viewport + bool eventFilter(QObject * obj, QEvent * event); /// BufferView const * bv_; ///