]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlErrorList.C
Another 49 #includes bite the dust.
[lyx.git] / src / frontends / controllers / ControlErrorList.C
1 /**
2  * \file ControlErrorList.C
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 "iterators.h"
18 #include "lyxtext.h"
19
20
21 using std::endl;
22
23
24 ControlErrorList::ControlErrorList(Dialog & d)
25         : Dialog::Controller(d)
26 {}
27
28
29 void ControlErrorList::clearParams()
30 {}
31
32
33 ErrorList const &
34 ControlErrorList::errorList() const
35 {
36         return errorlist_;
37 }
38
39
40 bool ControlErrorList::initialiseParams(string const & name)
41 {
42         errorlist_ = kernel().bufferview()->getErrorList();
43         name_ = name;
44         return true;
45 }
46
47
48 string const & ControlErrorList::name()
49 {
50         return name_;
51 }
52
53
54 void ControlErrorList::goTo(int item)
55 {
56         ErrorItem const & err = errorlist_[item];
57
58         if (err.par_id == -1)
59                 return;
60
61         Buffer & buf = kernel().buffer();
62         ParIterator pit = buf.getParFromID(err.par_id);
63
64         if (pit == buf.par_iterator_end()) {
65                 lyxerr << "par id not found" << endl;
66                 return;
67         }
68
69         int range = err.pos_end - err.pos_start;
70
71         if (err.pos_end > pit->size() || range <= 0)
72                 range = pit->size() - err.pos_start;
73
74         // Now make the selection.
75         BufferView * const bv = kernel().bufferview();
76         bv->insetUnlock();
77         bv->text->clearSelection();
78         bv->text->setCursor(pit.pit(), err.pos_start);
79         bv->text->setSelectionRange(range);
80         bv->fitCursor();
81         bv->update();
82 }