From 6e34079211af64219f1edec9b8813e32b2b9e0d7 Mon Sep 17 00:00:00 2001 From: Alfredo Braunstein Date: Mon, 13 Aug 2007 14:24:49 +0000 Subject: [PATCH] This implements selection of current cursor position (and main selection) \ in the view source panel * Buffer.cpp (getSourceCode, writeLaTeXSource): fix sync between output and texrow * frontends/controllers/ControlViewSource.{h,cpp} (getRows): new method to get the current selection in term of latex rows * frontends/qt4/QViewSource.{h,cpp}: make a selection in the ViewSource widget git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19503 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 14 +++++++++----- src/frontends/controllers/ControlViewSource.cpp | 15 +++++++++++++++ src/frontends/controllers/ControlViewSource.h | 3 +++ src/frontends/qt4/QViewSource.cpp | 7 +++++++ 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 5e9972138c..987605cb69 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -925,6 +925,7 @@ bool Buffer::makeLaTeXFile(FileName const & fname, bool failed_export = false; try { + texrow().reset(); writeLaTeXSource(ofs, original_path, runparams, output_preamble, output_body); } @@ -972,12 +973,8 @@ void Buffer::writeLaTeXSource(odocstream & os, validate(features); LYXERR(Debug::LATEX) << " Buffer validation done." << endl; - texrow().reset(); - // The starting paragraph of the coming rows is the // first paragraph of the document. (Asger) - texrow().start(paragraphs().begin()->id(), 0); - if (output_preamble && runparams.nice) { os << "%% LyX " << lyx_version << " created this file. " "For more info, see http://www.lyx.org/.\n" @@ -1027,6 +1024,9 @@ void Buffer::writeLaTeXSource(odocstream & os, os << "\\begin{document}\n"; texrow().newline(); } // output_preamble + + texrow().start(paragraphs().begin()->id(), 0); + LYXERR(Debug::INFO) << "preamble finished, now the body." << endl; if (!lyxrc.language_auto_begin && @@ -1784,8 +1784,11 @@ void Buffer::getSourceCode(odocstream & os, pit_type par_begin, // No side effect of file copying and image conversion runparams.dryrun = true; + texrow().reset(); if (full_source) { os << "% " << _("Preview source code") << "\n\n"; + texrow().newline(); + texrow().newline(); if (isLatex()) writeLaTeXSource(os, filePath(), runparams, true, true); else { @@ -1804,9 +1807,10 @@ void Buffer::getSourceCode(odocstream & os, pit_type par_begin, convert(par_begin), convert(par_end - 1)) << "\n\n"; + texrow().newline(); + texrow().newline(); // output paragraphs if (isLatex()) { - texrow().reset(); latexParagraphs(*this, paragraphs(), os, texrow(), runparams); } else { // DocBook diff --git a/src/frontends/controllers/ControlViewSource.cpp b/src/frontends/controllers/ControlViewSource.cpp index 68a90bb0d5..c9bb578884 100644 --- a/src/frontends/controllers/ControlViewSource.cpp +++ b/src/frontends/controllers/ControlViewSource.cpp @@ -18,6 +18,7 @@ #include "BufferView.h" #include "Buffer.h" #include "Cursor.h" +#include "TexRow.h" #include using std::string; @@ -58,6 +59,20 @@ docstring const ControlViewSource::updateContent(bool fullSource) } +std::pair ControlViewSource::getRows() const +{ + BufferView const * view = kernel().bufferview(); + CursorSlice beg = view->cursor().selectionBegin().bottom(); + CursorSlice end = view->cursor().selectionEnd().bottom(); + + int begrow = view->buffer()->texrow(). + getRowFromIdPos(beg.paragraph().id(), beg.pos()); + int endrow = view->buffer()->texrow(). + getRowFromIdPos(end.paragraph().id(), end.pos() + 1); + return std::make_pair(begrow, endrow); +} + + void ControlViewSource::clearParams() { } diff --git a/src/frontends/controllers/ControlViewSource.h b/src/frontends/controllers/ControlViewSource.h index 0c2218e5d4..c2a3a2b642 100644 --- a/src/frontends/controllers/ControlViewSource.h +++ b/src/frontends/controllers/ControlViewSource.h @@ -47,6 +47,9 @@ public: \param fullSource get full source code */ docstring const updateContent(bool fullSource); + /** get the cursor position in the source code + */ + std::pair getRows() const; }; } // namespace frontend diff --git a/src/frontends/qt4/QViewSource.cpp b/src/frontends/qt4/QViewSource.cpp index 6c866764cb..d1110bed15 100644 --- a/src/frontends/qt4/QViewSource.cpp +++ b/src/frontends/qt4/QViewSource.cpp @@ -61,6 +61,13 @@ void QViewSourceDialog::update() if (autoUpdateCB->isChecked()) form_->update(viewFullSourceCB->isChecked()); + int beg, end; + boost::tie(beg, end) = form_->getRows(); + QTextCursor c = QTextCursor(viewSourceTV->document()); + c.movePosition(QTextCursor::NextBlock, QTextCursor::MoveAnchor, beg); + c.select(QTextCursor::BlockUnderCursor); + c.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor, end - beg + 1); + viewSourceTV->setTextCursor(c); QWidget::update(); } -- 2.39.2