mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-21 23:09:40 +00:00
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
This commit is contained in:
parent
6b87801d09
commit
6e34079211
@ -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
|
||||
|
@ -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()
|
||||
{
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user