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