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