]> git.lyx.org Git - features.git/blob - src/frontends/controllers/ControlErrorList.C
This commit creates a error_lists map member inside the Buffer class.
[features.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 "gettext.h"
18 #include "lyxtext.h"
19 #include "paragraph.h"
20 #include "pariterator.h"
21
22 #include "support/lstrings.h"
23
24 using lyx::support::bformat;
25
26 using std::endl;
27 using std::string;
28
29 namespace lyx {
30 namespace frontend {
31
32 ControlErrorList::ControlErrorList(Dialog & d)
33         : Dialog::Controller(d)
34 {}
35
36
37 void ControlErrorList::clearParams()
38 {}
39
40
41 ErrorList const & ControlErrorList::errorList() const
42 {
43         return errorlist_;
44 }
45
46
47 bool ControlErrorList::initialiseParams(string const & error_type)
48 {
49         Buffer * buf = kernel().bufferview()->buffer();
50         string const title = bformat(_("%1$s Errors (%2$s)"),
51                 _(error_type), buf->fileName());
52         errorlist_ = buf->errorList(error_type);
53         name_ = title;
54         return true;
55 }
56
57
58 string const & ControlErrorList::name()
59 {
60         return name_;
61 }
62
63
64 void ControlErrorList::goTo(int item)
65 {
66         ErrorItem const & err = errorlist_[item];
67
68         if (err.par_id == -1)
69                 return;
70
71         Buffer & buf = kernel().buffer();
72         ParIterator pit = buf.getParFromID(err.par_id);
73
74         if (pit == buf.par_iterator_end()) {
75                 lyxerr << "par id " << err.par_id << " not found" << endl;
76                 return;
77         }
78
79         // Now make the selection.
80         // This should be implemented using an LFUN. (Angus)
81         // if pos_end is 0, this means it is end-of-paragraph
82         pos_type const end = err.pos_end ? std::min(err.pos_end, pit->size())
83                                          : pit->size();
84         pos_type const start = std::min(err.pos_start, end);
85         pos_type const range = end - start;
86         DocIterator const dit = makeDocIterator(pit, start);
87         kernel().bufferview()->putSelectionAt(dit, range, false);
88         // If we used an LFUN, we would not need that
89         kernel().bufferview()->update();
90 }
91
92 } // namespace frontend
93 } // namespace lyx