]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiErrorList.cpp
Complete the removal of the embedding stuff. Maybe. It's hard to be sure we got every...
[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 "qt_helpers.h"
16
17 #include "Buffer.h"
18 #include "BufferView.h"
19 #include "ParIterator.h"
20 #include "Text.h"
21
22 #include "support/debug.h"
23 #include "support/gettext.h"
24 #include "support/lstrings.h"
25
26 #include <QListWidget>
27 #include <QPushButton>
28 #include <QShowEvent>
29 #include <QTextBrowser>
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", qt_("Error List"))
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::showEvent(QShowEvent * e)
53 {
54         errorsLW->setCurrentRow(0);
55         select(errorsLW->item(0));
56         e->accept();
57 }
58
59
60 void GuiErrorList::select(QListWidgetItem * wi)
61 {
62         int const item = errorsLW->row(wi);
63         goTo(item);
64         descriptionTB->setPlainText(toqstr(errorList()[item].description));
65 }
66
67
68 void GuiErrorList::updateContents()
69 {
70         setTitle(toqstr(name_));
71         errorsLW->clear();
72         descriptionTB->setPlainText(QString());
73
74         ErrorList::const_iterator it = errorList().begin();
75         ErrorList::const_iterator end = errorList().end();
76         for (; it != end; ++it)
77                 errorsLW->addItem(toqstr(it->error));
78 }
79
80
81 ErrorList const & GuiErrorList::errorList() const
82 {
83         return bufferview()->buffer().errorList(error_type_);
84 }
85
86
87 bool GuiErrorList::initialiseParams(string const & error_type)
88 {
89         error_type_ = error_type;
90         Buffer const & buf = bufferview()->buffer();
91         name_ = bformat(_("%1$s Errors (%2$s)"), _(error_type),
92                                      from_utf8(buf.absFileName()));
93         return true;
94 }
95
96
97 void GuiErrorList::goTo(int item)
98 {
99         ErrorItem const & err = errorList()[item];
100
101         if (err.par_id == -1)
102                 return;
103
104         Buffer & buf = buffer();
105         DocIterator dit = buf.getParFromID(err.par_id);
106
107         if (dit == doc_iterator_end(buf.inset())) {
108                 LYXERR0("par id " << err.par_id << " not found");
109                 return;
110         }
111
112         // Now make the selection.
113         // if pos_end is 0, this means it is end-of-paragraph
114         pos_type const s = dit.paragraph().size();
115         pos_type const end = err.pos_end ? min(err.pos_end, s) : s;
116         pos_type const start = min(err.pos_start, end);
117         pos_type const range = end - start;
118         dit.pos() = start;
119         bufferview()->putSelectionAt(dit, range, false);
120         // FIXME: If we used an LFUN, we would not need this line:
121         bufferview()->processUpdateFlags(Update::Force | Update::FitCursor);
122 }
123
124
125 Dialog * createGuiErrorList(GuiView & lv) { return new GuiErrorList(lv); }
126
127 } // namespace frontend
128 } // namespace lyx
129
130
131 #include "GuiErrorList_moc.cpp"