]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlViewSource.C
enable Font cache only for MacOSX and inline width() for other platform.
[lyx.git] / src / frontends / controllers / ControlViewSource.C
1 /**
2  * \file ControlViewSource.C
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 using std::ostringstream;
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 string 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         ostringstream ostr;
57         view->buffer()->getSourceCode(ostr, par_begin, par_end + 1, fullSource);
58         return ostr.str();
59 }
60
61
62 void ControlViewSource::clearParams()
63 {
64 }
65
66
67 string const ControlViewSource::title() const
68 {
69         string source_type;
70
71         Kernel::DocType doctype = kernel().docType();
72         switch (doctype) {
73         case Kernel::LATEX:
74                 source_type = "LaTeX";
75                 break;
76         case Kernel::DOCBOOK:
77                 source_type = "DocBook";
78                 break;
79         case Kernel::LITERATE:
80                 source_type = "Literate";
81         default:
82                 BOOST_ASSERT(false);
83         }
84         return lyx::to_utf8(_(source_type + " Source"));
85 }
86
87 } // namespace frontend
88 } // namespace lyx