]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiErrorList.cpp
f25f1940c437acf154a0299a621f60fdd458e94b
[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 "GuiView.h"
16 #include "qt_helpers.h"
17
18 #include "Buffer.h"
19 #include "BufferView.h"
20 #include "FuncRequest.h"
21 #include "FuncStatus.h"
22 #include "BufferList.h"
23 #include "LyX.h"
24 #include "ParIterator.h"
25 #include "Text.h"
26 #include "TexRow.h"
27
28 #include "support/debug.h"
29 #include "support/gettext.h"
30 #include "support/lstrings.h"
31
32 #include <QListWidget>
33 #include <QPushButton>
34 #include <QShowEvent>
35 #include <QTextBrowser>
36
37 using namespace std;
38 using namespace lyx::support;
39
40 namespace {
41
42 string const guiErrorType(string const & s)
43 {
44         if (s == "docbook")
45                 return N_("DocBook");
46         else if (s == "literate")
47                 return N_("Literate");
48         else if (s == "latex")
49                 // This covers all LaTeX variants
50                 // (LaTeX, PDFLaTeX, XeTeX, LuaTeX, pLaTeX)
51                 return N_("LaTeX");
52         return s;
53 }
54
55 } // namespace anon
56
57 namespace lyx {
58 namespace frontend {
59
60 GuiErrorList::GuiErrorList(GuiView & lv)
61         : GuiDialog(lv, "errorlist", qt_("Error List")), buf_(0), from_master_(false)
62 {
63         setupUi(this);
64
65         connect(closePB, SIGNAL(clicked()),
66                 this, SLOT(slotClose()));
67         connect(viewLogPB, SIGNAL(clicked()),
68                 this, SLOT(viewLog()));
69         connect(showAnywayPB, SIGNAL(clicked()),
70                 this, SLOT(showAnyway()));
71         connect(errorsLW, SIGNAL(currentRowChanged(int)),
72                 this, SLOT(select()));
73
74         bc().setPolicy(ButtonPolicy::OkCancelPolicy);
75         bc().setCancel(closePB);
76 }
77
78
79 void GuiErrorList::showEvent(QShowEvent * e)
80 {
81         select();
82         paramsToDialog();
83         e->accept();
84 }
85
86
87 void GuiErrorList::select()
88 {
89         int const item = errorsLW->row(errorsLW->currentItem());
90         if (item == -1)
91                 return;
92         goTo(item);
93         descriptionTB->setPlainText(
94                 toqstr(errorList()[item].description));
95 }
96
97
98 void GuiErrorList::viewLog()
99 {
100         if (&buffer() != buf_) {
101                 if (!theBufferList().isLoaded(buf_))
102                         return;
103                 FuncRequest fr(LFUN_BUFFER_SWITCH, buf_->absFileName());
104                 dispatch(fr);
105         }
106         dispatch(FuncRequest(LFUN_DIALOG_SHOW, "latexlog"));
107 }
108
109
110 void GuiErrorList::showAnyway()
111 {
112         dispatch(FuncRequest(LFUN_BUFFER_VIEW_CACHE));
113 }
114
115
116 void GuiErrorList::paramsToDialog()
117 {
118         setTitle(toqstr(name_));
119         errorsLW->clear();
120         descriptionTB->setPlainText(QString());
121
122         ErrorList const & el = errorList();
123         ErrorList::const_iterator it = el.begin();
124         ErrorList::const_iterator const en = el.end();
125         for (; it != en; ++it)
126                 errorsLW->addItem(toqstr(it->error));
127         errorsLW->setCurrentRow(0);
128         showAnywayPB->setEnabled(
129                 lyx::getStatus(FuncRequest(LFUN_BUFFER_VIEW_CACHE)).enabled());
130 }
131
132
133 ErrorList const & GuiErrorList::errorList() const
134 {
135         Buffer const * buffer = from_master_
136                                 ? bufferview()->buffer().masterBuffer()
137                                 : &bufferview()->buffer();
138         if (buffer == buf_)
139                 error_list_ = buffer->errorList(error_type_);
140
141         return error_list_;
142 }
143
144
145 bool GuiErrorList::initialiseParams(string const & data)
146 {
147         from_master_ = prefixIs(data, "from_master|");
148         string error_type = data;
149         if (from_master_)
150                 error_type = split(data, '|');
151         error_type_ = error_type;
152         buf_ = from_master_ ?
153                 bufferview()->buffer().masterBuffer()
154                 : &bufferview()->buffer();
155         name_ = bformat(_("%1$s Errors (%2$s)"),
156                                 _(guiErrorType(error_type)),
157                                     from_utf8(buf_->absFileName()));
158         paramsToDialog();
159         return true;
160 }
161
162
163 bool GuiErrorList::goTo(int item)
164 {
165         ErrorItem const & err = errorList()[item];
166         if (TexRow::isNone(err.start))
167                 return false;
168
169         Buffer const * errbuf = err.buffer ? err.buffer : buf_;
170
171         if (&buffer() != errbuf) {
172                 if (!theBufferList().isLoaded(errbuf))
173                         return false;
174                 FuncRequest fr(LFUN_BUFFER_SWITCH, errbuf->absFileName());
175                 dispatch(fr);
176         }
177         dispatch(TexRow::goToFunc(err.start, err.end));
178         return true;
179 }
180
181
182 Dialog * createGuiErrorList(GuiView & lv) { return new GuiErrorList(lv); }
183
184 } // namespace frontend
185 } // namespace lyx
186
187
188 #include "moc_GuiErrorList.cpp"