]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlErrorList.C
fix compile
[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 "support/lstrings.h" // tostr
15 #include "LaTeX.h"
16 #include "buffer.h"
17 #include "BufferView.h"
18 #include "lyxtext.h"
19 #include "debug.h"
20
21
22 using std::endl;
23
24
25 ControlErrorList::ErrorItem::ErrorItem(string const & error,
26                                        string const & description,
27                                        int par_id, int pos_start, int pos_end)
28         : error(error), description(description), par_id(par_id),
29           pos_start(pos_start),  pos_end(pos_end)
30 {}
31
32
33 ControlErrorList::ControlErrorList(Dialog & d)
34         : Dialog::Controller(d), current_(0)
35 {}
36
37
38 void ControlErrorList::clearParams()
39 {
40         logfilename_.clear();
41         clearErrors();
42 }
43
44
45 std::vector<ControlErrorList::ErrorItem> const &
46 ControlErrorList::ErrorList() const
47 {
48         return ErrorList_;
49 }
50
51
52 int ControlErrorList::currentItem() const
53 {
54         return current_;
55 }
56
57
58 bool ControlErrorList::initialiseParams(string const &)
59 {
60         logfilename_ = kernel().buffer()->getLogName().second;
61         clearErrors();
62         fillErrors();
63         current_ = 0;
64         return true;
65 }
66
67
68 void ControlErrorList::clearErrors()
69 {
70         ErrorList_.clear();
71         current_ = 0;
72 }
73
74
75 void ControlErrorList::fillErrors()
76 {
77         LaTeX latex("", logfilename_, "");
78         TeXErrors terr;
79         latex.scanLogFile(terr);
80
81         Buffer * const buf = kernel().buffer();
82
83         TeXErrors::Errors::const_iterator cit = terr.begin();
84         TeXErrors::Errors::const_iterator end = terr.end();
85
86         for (; cit != end; ++cit) {
87                 int par_id = -1;
88                 int posstart = -1;
89                 int const errorrow = cit->error_in_line;
90                 buf->texrow.getIdFromRow(errorrow, par_id, posstart);
91                 int posend = -1;
92                 buf->texrow.getIdFromRow(errorrow + 1, par_id, posend);
93                 ErrorList_.push_back(ErrorItem(cit->error_desc,
94                                                cit->error_text,
95                                                par_id, posstart, posend));
96         }
97 }
98
99
100 string const & ControlErrorList::docName()
101 {
102         return kernel().buffer()->fileName();
103 }
104
105
106 void ControlErrorList::goTo(int item)
107 {
108         BufferView * const bv = kernel().bufferview();
109         Buffer * const buf = kernel().buffer();
110
111         current_ = item;
112
113         ControlErrorList::ErrorItem const & err = ErrorList_[item];
114
115
116         if (err.par_id == -1)
117                 return;
118
119         ParagraphList::iterator pit = buf->getParFromID(err.par_id);
120
121         if (pit == bv->text->ownerParagraphs().end()) {
122                 lyxerr << "par id not found" << endl;
123                 return;
124         }
125
126         int range = err.pos_end - err.pos_start;
127
128         if (err.pos_end > pit->size() || range <= 0)
129                 range = pit->size() - err.pos_start;
130
131         // Now make the selection.
132         bv->insetUnlock();
133         bv->toggleSelection();
134         bv->text->clearSelection();
135         bv->text->setCursor(pit, err.pos_start);
136         bv->text->setSelectionRange(range);
137         bv->toggleSelection(false);
138         bv->fitCursor();
139         bv->update(bv->text, BufferView::SELECT);
140 }