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