]> git.lyx.org Git - features.git/commitdiff
This implements selection of current cursor position (and main selection) \
authorAlfredo Braunstein <abraunst@lyx.org>
Mon, 13 Aug 2007 14:24:49 +0000 (14:24 +0000)
committerAlfredo Braunstein <abraunst@lyx.org>
Mon, 13 Aug 2007 14:24:49 +0000 (14:24 +0000)
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
src/frontends/controllers/ControlViewSource.cpp
src/frontends/controllers/ControlViewSource.h
src/frontends/qt4/QViewSource.cpp

index 5e9972138cb09dce281f4ccf29087e79fadbfcc1..987605cb695ffd47f5252b3e8206ce55e30ec7c3 100644 (file)
@@ -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<docstring>(par_begin),
                                        convert<docstring>(par_end - 1))
                           << "\n\n";
+               texrow().newline();
+               texrow().newline();
                // output paragraphs
                if (isLatex()) {
-                       texrow().reset();
                        latexParagraphs(*this, paragraphs(), os, texrow(), runparams);
                } else {
                        // DocBook
index 68a90bb0d5c62fd4edbefc4e3b27e016c2ec7aba..c9bb57888485507023ef474b8ae07f57e29864a1 100644 (file)
@@ -18,6 +18,7 @@
 #include "BufferView.h"
 #include "Buffer.h"
 #include "Cursor.h"
+#include "TexRow.h"
 #include <sstream>
 
 using std::string;
@@ -58,6 +59,20 @@ docstring const ControlViewSource::updateContent(bool fullSource)
 }
 
 
+std::pair<int, int> 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()
 {
 }
index 0c2218e5d430a948c15a0b68b3d3ac52e96ccefb..c2a3a2b642f28d0796ba882238953bf029dfaf6e 100644 (file)
@@ -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<int, int> getRows() const;
 };
 
 } // namespace frontend
index 6c866764cb09038b783d3c556ac4c4220c371a94..d1110bed15c006ae3b8b2233a59979a778096f2c 100644 (file)
@@ -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();
 }