]> git.lyx.org Git - features.git/commitdiff
TexRow info in source panel and gotoCursor() for debugging
authorGuillaume Munch <gm@lyx.org>
Sun, 11 Oct 2015 13:50:32 +0000 (14:50 +0100)
committerGuillaume Munch <gm@lyx.org>
Mon, 19 Oct 2015 05:55:17 +0000 (06:55 +0100)
These features are active in DEVEL_VERSION when Debug is set to LATEX.

1. The TexRow information is prepended to the source panel.

2. Clicking on any line in the source triggers reverse search. (This would be an
interesting feature to implement on the user side, but we need a proper LFUN.)

src/BufferView.cpp
src/BufferView.h
src/frontends/qt4/GuiViewSource.cpp
src/frontends/qt4/GuiViewSource.h
src/mathed/InsetMathHull.cpp

index 24be1624ce759bbe3606895cbac163fa5c6d6d9c..1aac0b241da8542f52afba2b5e564bbd084f3bf2 100644 (file)
@@ -2365,13 +2365,19 @@ int BufferView::scrollUp(int offset)
 
 
 void BufferView::setCursorFromRow(int row)
+{
+       setCursorFromRow(row, buffer_.texrow());
+}
+
+
+void BufferView::setCursorFromRow(int row, TexRow const & texrow)
 {
        int tmpid;
        int tmppos;
        pit_type newpit = 0;
        pos_type newpos = 0;
 
-       buffer_.texrow().getIdFromRow(row, tmpid, tmppos);
+       texrow.getIdFromRow(row, tmpid, tmppos);
 
        bool posvalid = (tmpid != -1);
        if (posvalid) {
index bfdb0bac429ac912613f1b08344534ef65a497f4..15d2c6bd0fb67c359ebaed132bd1297f4c527344 100644 (file)
@@ -44,6 +44,7 @@ class PainterInfo;
 class ParIterator;
 class ParagraphMetrics;
 class Point;
+class TexRow;
 class Text;
 class TextMetrics;
 
@@ -159,6 +160,8 @@ public:
 
        /// set the cursor based on the given TeX source row.
        void setCursorFromRow(int row);
+       ///
+       void setCursorFromRow(int row, TexRow const & texrow);
 
        /// set cursor to the given inset. Return true if found.
        bool setCursorFromInset(Inset const *);
index 16956645eb26aa2f1ed7ad9881e13418f6f42dd3..c908a2eaa01733f255d8f8bb94a59e67e58fcc04 100644 (file)
@@ -26,6 +26,7 @@
 #include "support/debug.h"
 #include "support/lassert.h"
 #include "support/docstream.h"
+#include "support/docstring_list.h"
 #include "support/gettext.h"
 
 #include <boost/crc.hpp>
@@ -64,6 +65,11 @@ 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);
@@ -89,7 +95,7 @@ ViewSourceWidget::ViewSourceWidget()
 }
 
 
-auto_ptr<TexRow> ViewSourceWidget::getContent(BufferView const * view,
+void ViewSourceWidget::getContent(BufferView const * view,
                        Buffer::OutputWhat output, docstring & str, string const & format,
                        bool master)
 {
@@ -108,11 +114,10 @@ auto_ptr<TexRow> ViewSourceWidget::getContent(BufferView const * view,
        if (par_begin > par_end)
                swap(par_begin, par_end);
        odocstringstream ostr;
-       auto_ptr<TexRow> texrow = view->buffer().getSourceCode(ostr, format,
-                                                                   par_begin, par_end + 1, output, master);
+       texrow_ = view->buffer().getSourceCode(ostr, format,
+                                                                               par_begin, par_end + 1, output, master);
        //ensure that the last line can always be selected in its full width
        str = ostr.str() + "\n";
-       return texrow;
 }
 
 
@@ -164,6 +169,23 @@ void ViewSourceWidget::updateViewNow()
        update_timer_->start(0);
 }
 
+namespace {
+
+QString prependTexRow(TexRow const & texrow, QString const & content)
+{
+       QStringList list = content.split(QChar('\n'));
+       docstring_list dlist;
+       for (QStringList::const_iterator it = list.begin(); it != list.end(); ++it)
+               dlist.push_back(from_utf8(fromqstr(*it)));
+       texrow.prepend(dlist);
+       QString qstr;
+       for (docstring_list::iterator it = dlist.begin(); it != dlist.end(); ++it)
+               qstr += toqstr(*it) + '\n';
+       return qstr;
+}
+
+} // anon namespace
+
 void ViewSourceWidget::realUpdateView()
 {
        if (!bv_) {
@@ -191,13 +213,18 @@ void ViewSourceWidget::realUpdateView()
                output = Buffer::OnlyBody;
 
        docstring content;
-       auto_ptr<TexRow> texrow = getContent(bv_, output, content, format,
-                                                                          masterPerspectiveCB->isChecked());
+       getContent(bv_, output, content, format, masterPerspectiveCB->isChecked());
        QString old = document_->toPlainText();
        QString qcontent = toqstr(content);
+#ifdef DEVEL_VERSION
+       if (texrow_.get() && lyx::lyxerr.debugging(Debug::LATEX))
+               qcontent = prependTexRow(*texrow_, qcontent);
+#endif
+       // prevent gotoCursor()
+       viewSourceTV->blockSignals(true);
        bool const changed = setText(qcontent);
 
-       if (changed && !texrow.get()) {
+       if (changed && !texrow_.get()) {
                // position-to-row is unavailable
                // we jump to the first modification
                const QChar * oc = old.constData();
@@ -227,18 +254,18 @@ void ViewSourceWidget::realUpdateView()
                //c.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor,1);
                viewSourceTV->setTextCursor(c);
 
-       } else if (texrow.get()) {
+       } else if (texrow_.get()) {
                // Use the available position-to-row conversion to highlight
                // the current selection in the source
                int beg_row, end_row;
                {
                        DocIterator beg = bv_->cursor().selectionBegin();
                        DocIterator end = bv_->cursor().selectionEnd();
-                       std::pair<int,int> beg_rows = texrow->rowFromDocIterator(beg);
+                       std::pair<int,int> beg_rows = texrow_->rowFromDocIterator(beg);
                        beg_row = beg_rows.first;
                        if (beg != end) {
                                end.backwardChar();
-                               std::pair<int,int> end_rows = texrow->rowFromDocIterator(end);
+                               std::pair<int,int> end_rows = texrow_->rowFromDocIterator(end);
                                end_row = end_rows.second;
                        } else {
                                end_row = beg_rows.second;
@@ -290,9 +317,22 @@ void ViewSourceWidget::realUpdateView()
                viewSourceTV->setTextCursor(c);
                viewSourceTV->horizontalScrollBar()->setValue(h_scroll);
        } // else if (texrow)
+       viewSourceTV->blockSignals(false);
 }
 
 
+// only used in DEVEL_MODE for debugging
+// need a proper LFUN if we want to implement it in release mode
+void ViewSourceWidget::gotoCursor()
+{
+       if (!bv_ || !texrow_.get())
+               return;
+       int row = viewSourceTV->textCursor().blockNumber() + 1;
+       const_cast<BufferView *>(bv_)->setCursorFromRow(row, *texrow_);
+}
+
+
+
 void ViewSourceWidget::updateDefaultFormat()
 {
        if (!bv_)
index 7b451a6bf6b9ed768ebc65c75fe82976853ce4ab..e089305be58fabb1985616ff6485b293ecd398f1 100644 (file)
@@ -62,6 +62,8 @@ public Q_SLOTS:
        void updateDefaultFormat();
        ///
        void contentsChanged();
+       ///
+       void gotoCursor();
 
 private Q_SLOTS:
        /// update content
@@ -69,10 +71,8 @@ private Q_SLOTS:
 
 private:
        /// Get the source code of selected paragraphs, or the whole document.
-       /// If TexRow is unavailable for the format then t is null.
-       std::auto_ptr<TexRow> getContent(BufferView const * view,
-                                                                        Buffer::OutputWhat output, docstring & str,
-                                                                        std::string const & format, bool master);
+       void getContent(BufferView const * view, Buffer::OutputWhat output,
+                          docstring & str, std::string const & format, bool master);
        ///
        BufferView const * bv_;
        ///
@@ -83,6 +83,9 @@ private:
        QString view_format_;
        ///
        QTimer * update_timer_;
+       /// TexRow information from the last source view. If TexRow is unavailable
+       /// for the last format then texrow_ is null.
+       std::auto_ptr<TexRow> texrow_;
 };
 
 
index 08c0dec760a0c76ee702dd123d45983eab03a702..6ff8833fee2fb0c5fe1a16be4ea4e9d202a9f89a 100644 (file)
@@ -927,7 +927,7 @@ void InsetMathHull::validate(LaTeXFeatures & features) const
 void InsetMathHull::header_write(WriteStream & os) const
 {
        bool n = numberedType();
-       
+
        switch(type_) {
        case hullNone:
                break;