]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlErrorList.cpp
* src/frontend/controllers/frontend_helpers.cpp: safety fix suggested by Andre
[lyx.git] / src / frontends / controllers / ControlErrorList.cpp
1 /**
2  * \file ControlErrorList.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alfredo Braunstein
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "ControlErrorList.h"
14 #include "Buffer.h"
15 #include "BufferView.h"
16 #include "debug.h"
17 #include "gettext.h"
18 #include "Text.h"
19 #include "ParIterator.h"
20
21 // FIXME: those two headers are needed because of the
22 // WorkArea::redraw() call below.
23 #include "frontends/LyXView.h"
24 #include "frontends/WorkArea.h"
25
26 #include "support/lstrings.h"
27
28 using lyx::support::bformat;
29
30 using std::endl;
31 using std::string;
32
33 namespace lyx {
34 namespace frontend {
35
36 ControlErrorList::ControlErrorList(Dialog & d)
37         : Dialog::Controller(d)
38 {}
39
40
41 void ControlErrorList::clearParams()
42 {}
43
44
45 ErrorList const & ControlErrorList::errorList() const
46 {
47         return kernel().bufferview()->buffer()->errorList(error_type_);
48 }
49
50
51 bool ControlErrorList::initialiseParams(string const & error_type)
52 {
53         error_type_ = error_type;
54         Buffer * buf = kernel().bufferview()->buffer();
55         // FIXME UNICODE
56         docstring const title = bformat(_("%1$s Errors (%2$s)"),
57                                      _(error_type),
58                                      lyx::from_utf8(buf->fileName()));
59         name_ = lyx::to_utf8(title);
60         return true;
61 }
62
63
64 string const & ControlErrorList::name()
65 {
66         return name_;
67 }
68
69
70 void ControlErrorList::goTo(int item)
71 {
72         ErrorItem const & err = errorList()[item];
73
74         if (err.par_id == -1)
75                 return;
76
77         Buffer & buf = kernel().buffer();
78         ParIterator pit = buf.getParFromID(err.par_id);
79
80         if (pit == buf.par_iterator_end()) {
81                 lyxerr << "par id " << err.par_id << " not found" << endl;
82                 return;
83         }
84
85         // Now make the selection.
86         // This should be implemented using an LFUN. (Angus)
87         // if pos_end is 0, this means it is end-of-paragraph
88         pos_type const end = err.pos_end ? std::min(err.pos_end, pit->size())
89                                          : pit->size();
90         pos_type const start = std::min(err.pos_start, end);
91         pos_type const range = end - start;
92         DocIterator const dit = makeDocIterator(pit, start);
93         kernel().bufferview()->putSelectionAt(dit, range, false);
94         // FIXME: If we used an LFUN, we would not need those two lines:
95         kernel().bufferview()->update();
96         kernel().lyxview().currentWorkArea()->redraw();
97 }
98
99 } // namespace frontend
100 } // namespace lyx