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