]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlViewSource.cpp
fix scrolling bug: 3320 and 3652, maybe not perfect
[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 <sstream>
22
23 using std::string;
24
25 namespace lyx {
26 namespace frontend {
27
28 ControlViewSource::ControlViewSource(Dialog & parent)
29         : Dialog::Controller(parent)
30 {}
31
32
33 bool ControlViewSource::initialiseParams(string const & /*source*/)
34 {
35         return true;
36 }
37
38 docstring const ControlViewSource::updateContent(bool fullSource)
39 {
40         // get the *top* level paragraphs that contain the cursor,
41         // or the selected text
42         lyx::pit_type par_begin;
43         lyx::pit_type par_end;
44
45         BufferView * view = kernel().bufferview();
46         if (!view->cursor().selection()) {
47                 par_begin = view->cursor().bottom().pit();
48                 par_end = par_begin;
49         } else {
50                 par_begin = view->cursor().selectionBegin().bottom().pit();
51                 par_end = view->cursor().selectionEnd().bottom().pit();
52         }
53         if (par_begin > par_end)
54                 std::swap(par_begin, par_end);
55         lyx::odocstringstream ostr;
56         view->buffer()->getSourceCode(ostr, par_begin, par_end + 1, fullSource);
57         return ostr.str();
58 }
59
60
61 void ControlViewSource::clearParams()
62 {
63 }
64
65
66 docstring const ControlViewSource::title() const
67 {
68         string source_type;
69
70         Kernel::DocType doctype = kernel().docType();
71         switch (doctype) {
72         case Kernel::LATEX:
73                 source_type = "LaTeX";
74                 break;
75         case Kernel::DOCBOOK:
76                 source_type = "DocBook";
77                 break;
78         case Kernel::LITERATE:
79                 source_type = "Literate";
80         default:
81                 BOOST_ASSERT(false);
82         }
83         return _(source_type + " Source");
84 }
85
86 } // namespace frontend
87 } // namespace lyx