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