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