]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlViewSource.cpp
make lyx compile
[lyx.git] / src / frontends / controllers / ControlViewSource.cpp
1 /**
2  * \file ControlViewSource.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Angus Leeming
8  * \author Bo Peng
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "ControlViewSource.h"
16 #include "gettext.h"
17 #include "support/types.h"
18 #include "BufferView.h"
19 #include "Buffer.h"
20 #include "Cursor.h"
21 #include "TexRow.h"
22 #include <sstream>
23
24 using std::string;
25
26 namespace lyx {
27 namespace frontend {
28
29 ControlViewSource::ControlViewSource(Dialog & parent)
30         : Dialog::Controller(parent)
31 {}
32
33
34 bool ControlViewSource::initialiseParams(string const & /*source*/)
35 {
36         return true;
37 }
38
39 docstring const ControlViewSource::updateContent(bool fullSource)
40 {
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;
45
46         BufferView * view = kernel().bufferview();
47         if (!view->cursor().selection()) {
48                 par_begin = view->cursor().bottom().pit();
49                 par_end = par_begin;
50         } else {
51                 par_begin = view->cursor().selectionBegin().bottom().pit();
52                 par_end = view->cursor().selectionEnd().bottom().pit();
53         }
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);
58         return ostr.str();
59 }
60
61
62 std::pair<int, int> ControlViewSource::getRows() const
63 {
64         BufferView const * view = kernel().bufferview();
65         CursorSlice beg = view->cursor().selectionBegin().bottom();
66         CursorSlice end = view->cursor().selectionEnd().bottom();
67
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));
75 }
76
77
78 void ControlViewSource::clearParams()
79 {
80 }
81
82
83 docstring const ControlViewSource::title() const
84 {
85         string source_type;
86
87         Kernel::DocType doctype = kernel().docType();
88         switch (doctype) {
89         case Kernel::LATEX:
90                 source_type = "LaTeX";
91                 break;
92         case Kernel::DOCBOOK:
93                 source_type = "DocBook";
94                 break;
95         case Kernel::LITERATE:
96                 source_type = "Literate";
97         default:
98                 BOOST_ASSERT(false);
99         }
100         return _(source_type + " Source");
101 }
102
103 } // namespace frontend
104 } // namespace lyx