]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlErrorList.cpp
fix scrolling bug: 3320 and 3652, maybe not perfect
[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 "Paragraph.h"
20 #include "ParIterator.h"
21
22 // FIXME: those two headers are needed because of the
23 // WorkArea::redraw() call below.
24 #include "frontends/LyXView.h"
25 #include "frontends/WorkArea.h"
26
27 #include "support/lstrings.h"
28
29 using lyx::support::bformat;
30
31 using std::endl;
32 using std::string;
33
34 namespace lyx {
35 namespace frontend {
36
37 ControlErrorList::ControlErrorList(Dialog & d)
38         : Dialog::Controller(d)
39 {}
40
41
42 void ControlErrorList::clearParams()
43 {}
44
45
46 ErrorList const & ControlErrorList::errorList() const
47 {
48         return kernel().bufferview()->buffer()->errorList(error_type_);
49 }
50
51
52 bool ControlErrorList::initialiseParams(string const & error_type)
53 {
54         error_type_ = error_type;
55         Buffer * buf = kernel().bufferview()->buffer();
56         // FIXME UNICODE
57         docstring const title = bformat(_("%1$s Errors (%2$s)"),
58                                      _(error_type),
59                                      lyx::from_utf8(buf->fileName()));
60         name_ = lyx::to_utf8(title);
61         return true;
62 }
63
64
65 string const & ControlErrorList::name()
66 {
67         return name_;
68 }
69
70
71 void ControlErrorList::goTo(int item)
72 {
73         ErrorItem const & err = errorList()[item];
74
75         if (err.par_id == -1)
76                 return;
77
78         Buffer & buf = kernel().buffer();
79         ParIterator pit = buf.getParFromID(err.par_id);
80
81         if (pit == buf.par_iterator_end()) {
82                 lyxerr << "par id " << err.par_id << " not found" << endl;
83                 return;
84         }
85
86         // Now make the selection.
87         // This should be implemented using an LFUN. (Angus)
88         // if pos_end is 0, this means it is end-of-paragraph
89         pos_type const end = err.pos_end ? std::min(err.pos_end, pit->size())
90                                          : pit->size();
91         pos_type const start = std::min(err.pos_start, end);
92         pos_type const range = end - start;
93         DocIterator const dit = makeDocIterator(pit, start);
94         kernel().bufferview()->putSelectionAt(dit, range, false);
95         // FIXME: If we used an LFUN, we would not need those two lines:
96         kernel().bufferview()->update();
97         kernel().lyxview().currentWorkArea()->redraw();
98 }
99
100 } // namespace frontend
101 } // namespace lyx