]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiErrorList.cpp
pimpl not needed here
[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")
47 {
48         setupUi(this);
49
50         connect(closePB, SIGNAL(clicked()),
51                 this, SLOT(slotClose()));
52         connect(errorsLW, SIGNAL(itemClicked(QListWidgetItem *)),
53                 this, SLOT(select(QListWidgetItem *)));
54
55         bc().setPolicy(ButtonPolicy::OkCancelPolicy);
56         bc().setCancel(closePB);
57 }
58
59
60 void GuiErrorList::closeEvent(QCloseEvent * e)
61 {
62         slotClose();
63         e->accept();
64 }
65
66
67 void GuiErrorList::showEvent(QShowEvent * e)
68 {
69         errorsLW->setCurrentRow(0);
70         select(errorsLW->item(0));
71         e->accept();
72 }
73
74
75 void GuiErrorList::select(QListWidgetItem * wi)
76 {
77         int const item = errorsLW->row(wi);
78         goTo(item);
79         descriptionTB->setPlainText(toqstr(errorList()[item].description));
80 }
81
82
83 void GuiErrorList::updateContents()
84 {
85         setViewTitle(name_);
86         errorsLW->clear();
87         descriptionTB->setPlainText(QString());
88
89         ErrorList::const_iterator it = errorList().begin();
90         ErrorList::const_iterator end = errorList().end();
91         for (; it != end; ++it)
92                 errorsLW->addItem(toqstr(it->error));
93 }
94
95
96 ErrorList const & GuiErrorList::errorList() const
97 {
98         return bufferview()->buffer().errorList(error_type_);
99 }
100
101
102 bool GuiErrorList::initialiseParams(string const & error_type)
103 {
104         error_type_ = error_type;
105         Buffer const & buf = bufferview()->buffer();
106         name_ = bformat(_("%1$s Errors (%2$s)"), _(error_type),
107                                      from_utf8(buf.absFileName()));
108         return true;
109 }
110
111
112 void GuiErrorList::goTo(int item)
113 {
114         ErrorItem const & err = errorList()[item];
115
116         if (err.par_id == -1)
117                 return;
118
119         Buffer & buf = buffer();
120         ParIterator pit = buf.getParFromID(err.par_id);
121
122         if (pit == buf.par_iterator_end()) {
123                 lyxerr << "par id " << err.par_id << " not found" << endl;
124                 return;
125         }
126
127         // Now make the selection.
128         // This should be implemented using an LFUN. (Angus)
129         // if pos_end is 0, this means it is end-of-paragraph
130         pos_type const end = err.pos_end ? std::min(err.pos_end, pit->size())
131                                          : pit->size();
132         pos_type const start = std::min(err.pos_start, end);
133         pos_type const range = end - start;
134         DocIterator const dit = makeDocIterator(pit, start);
135         bufferview()->putSelectionAt(dit, range, false);
136         // FIXME: If we used an LFUN, we would not need this line:
137         bufferview()->processUpdateFlags(Update::Force | Update::FitCursor);
138 }
139
140
141 Dialog * createGuiErrorList(LyXView & lv) { return new GuiErrorList(lv); }
142
143 } // namespace frontend
144 } // namespace lyx
145
146
147 #include "GuiErrorList_moc.cpp"