]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlErrorList.C
more unicode filenames
[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 "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         // FIXME UNICODE
51         docstring const title = bformat(_("%1$s Errors (%2$s)"),
52                                      _(error_type),
53                                      lyx::from_utf8(buf->fileName()));
54         errorlist_ = buf->errorList(error_type);
55         name_ = lyx::to_utf8(title);
56         return true;
57 }
58
59
60 string const & ControlErrorList::name()
61 {
62         return name_;
63 }
64
65
66 void ControlErrorList::goTo(int item)
67 {
68         ErrorItem const & err = errorlist_[item];
69
70         if (err.par_id == -1)
71                 return;
72
73         Buffer & buf = kernel().buffer();
74         ParIterator pit = buf.getParFromID(err.par_id);
75
76         if (pit == buf.par_iterator_end()) {
77                 lyxerr << "par id " << err.par_id << " not found" << endl;
78                 return;
79         }
80
81         // Now make the selection.
82         // This should be implemented using an LFUN. (Angus)
83         // if pos_end is 0, this means it is end-of-paragraph
84         pos_type const end = err.pos_end ? std::min(err.pos_end, pit->size())
85                                          : pit->size();
86         pos_type const start = std::min(err.pos_start, end);
87         pos_type const range = end - start;
88         DocIterator const dit = makeDocIterator(pit, start);
89         kernel().bufferview()->putSelectionAt(dit, range, false);
90         // If we used an LFUN, we would not need that
91         kernel().bufferview()->update();
92 }
93
94 } // namespace frontend
95 } // namespace lyx