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