]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiErrorList.cpp
a0d824deeb9a91285f8636f9dc92bc7141f208de
[lyx.git] / src / frontends / qt4 / GuiErrorList.cpp
1 /**
2  * \file GuiErrorList.cpp
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 "GuiErrorList.h"
14
15 #include "Buffer.h"
16 #include "BufferView.h"
17 #include "debug.h"
18 #include "gettext.h"
19 #include "Text.h"
20 #include "ParIterator.h"
21
22 #include "qt_helpers.h"
23
24 // FIXME: those two headers are needed because of the
25 // WorkArea::redraw() call below.
26 #include "frontends/LyXView.h"
27 #include "frontends/WorkArea.h"
28
29 #include "support/lstrings.h"
30
31 #include <QListWidget>
32 #include <QTextBrowser>
33 #include <QPushButton>
34 #include <QCloseEvent>
35
36 using std::endl;
37 using std::string;
38
39
40 namespace lyx {
41 namespace frontend {
42
43 using support::bformat;
44
45 GuiErrorList::GuiErrorList(LyXView & lv)
46         : GuiDialog(lv, "errorlist"), Controller(this)
47 {
48         setupUi(this);
49         setController(this, false);
50
51         connect(closePB, SIGNAL(clicked()),
52                 this, SLOT(slotClose()));
53         connect(errorsLW, SIGNAL(itemActivated(QListWidgetItem *)),
54                 this, SLOT(slotClose()));
55         connect( errorsLW, SIGNAL(itemClicked(QListWidgetItem *)),
56                 this, SLOT(select_adaptor(QListWidgetItem *)));
57
58         bc().setPolicy(ButtonPolicy::OkCancelPolicy);
59         bc().setCancel(closePB);
60 }
61
62
63 void GuiErrorList::closeEvent(QCloseEvent * e)
64 {
65         slotClose();
66         e->accept();
67 }
68
69
70 void GuiErrorList::showEvent(QShowEvent * e)
71 {
72         errorsLW->setCurrentRow(0);
73         select(errorsLW->item(0));
74         e->accept();
75 }
76
77
78 void GuiErrorList::select(QListWidgetItem * wi)
79 {
80         int const item = errorsLW->row(wi);
81         goTo(item);
82         descriptionTB->setPlainText(toqstr(errorList()[item].description));
83 }
84
85
86 void GuiErrorList::updateContents()
87 {
88         setViewTitle(name_);
89         errorsLW->clear();
90         descriptionTB->setPlainText(QString());
91
92         ErrorList::const_iterator it = errorList().begin();
93         ErrorList::const_iterator end = errorList().end();
94         for (; it != end; ++it)
95                 errorsLW->addItem(toqstr(it->error));
96 }
97
98
99 ErrorList const & GuiErrorList::errorList() const
100 {
101         return bufferview()->buffer().errorList(error_type_);
102 }
103
104
105 bool GuiErrorList::initialiseParams(string const & error_type)
106 {
107         error_type_ = error_type;
108         Buffer const & buf = bufferview()->buffer();
109         name_ = bformat(_("%1$s Errors (%2$s)"), _(error_type),
110                                      from_utf8(buf.fileName()));
111         return true;
112 }
113
114
115 void GuiErrorList::goTo(int item)
116 {
117         ErrorItem const & err = errorList()[item];
118
119         if (err.par_id == -1)
120                 return;
121
122         Buffer & buf = buffer();
123         ParIterator pit = buf.getParFromID(err.par_id);
124
125         if (pit == buf.par_iterator_end()) {
126                 lyxerr << "par id " << err.par_id << " not found" << endl;
127                 return;
128         }
129
130         // Now make the selection.
131         // This should be implemented using an LFUN. (Angus)
132         // if pos_end is 0, this means it is end-of-paragraph
133         pos_type const end = err.pos_end ? std::min(err.pos_end, pit->size())
134                                          : pit->size();
135         pos_type const start = std::min(err.pos_start, end);
136         pos_type const range = end - start;
137         DocIterator const dit = makeDocIterator(pit, start);
138         bufferview()->putSelectionAt(dit, range, false);
139         // FIXME: If we used an LFUN, we would not need those two lines:
140         bufferview()->update();
141         lyxview().currentWorkArea()->redraw();
142 }
143
144
145 Dialog * createGuiErrorList(LyXView & lv) { return new GuiErrorList(lv); }
146
147 } // namespace frontend
148 } // namespace lyx
149
150
151 #include "GuiErrorList_moc.cpp"