2 * \file ControlViewSource.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
10 * Full author contact details are available in file CREDITS.
15 #include "ControlViewSource.h"
17 #include "support/types.h"
18 #include "BufferView.h"
29 ControlViewSource::ControlViewSource(Dialog & parent)
30 : Dialog::Controller(parent)
34 bool ControlViewSource::initialiseParams(string const & /*source*/)
39 docstring const ControlViewSource::updateContent(bool fullSource)
41 // get the *top* level paragraphs that contain the cursor,
42 // or the selected text
43 lyx::pit_type par_begin;
44 lyx::pit_type par_end;
46 BufferView * view = kernel().bufferview();
47 if (!view->cursor().selection()) {
48 par_begin = view->cursor().bottom().pit();
51 par_begin = view->cursor().selectionBegin().bottom().pit();
52 par_end = view->cursor().selectionEnd().bottom().pit();
54 if (par_begin > par_end)
55 std::swap(par_begin, par_end);
56 lyx::odocstringstream ostr;
57 view->buffer().getSourceCode(ostr, par_begin, par_end + 1, fullSource);
62 std::pair<int, int> ControlViewSource::getRows() const
64 BufferView const * view = kernel().bufferview();
65 CursorSlice beg = view->cursor().selectionBegin().bottom();
66 CursorSlice end = view->cursor().selectionEnd().bottom();
68 int begrow = view->buffer().texrow().
69 getRowFromIdPos(beg.paragraph().id(), beg.pos());
70 int endrow = view->buffer().texrow().
71 getRowFromIdPos(end.paragraph().id(), end.pos());
72 int nextendrow = view->buffer().texrow().
73 getRowFromIdPos(end.paragraph().id(), end.pos() + 1);
74 return std::make_pair(begrow, endrow == nextendrow ? endrow : (nextendrow - 1));
78 void ControlViewSource::clearParams()
83 docstring const ControlViewSource::title() const
87 Kernel::DocType doctype = kernel().docType();
90 source_type = "LaTeX";
93 source_type = "DocBook";
95 case Kernel::LITERATE:
96 source_type = "Literate";
100 return _(source_type + " Source");
103 } // namespace frontend