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