]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiErrorList.cpp
* fix spelling in comments to please John.
[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 "FuncRequest.h"
20 #include "ParIterator.h"
21 #include "Text.h"
22
23 #include "support/debug.h"
24 #include "support/gettext.h"
25 #include "support/lstrings.h"
26
27 #include <QListWidget>
28 #include <QPushButton>
29 #include <QShowEvent>
30 #include <QTextBrowser>
31
32 using namespace std;
33 using namespace lyx::support;
34
35 namespace lyx {
36 namespace frontend {
37
38 GuiErrorList::GuiErrorList(GuiView & lv)
39         : GuiDialog(lv, "errorlist", qt_("Error List"))
40 {
41         setupUi(this);
42
43         connect(closePB, SIGNAL(clicked()),
44                 this, SLOT(slotClose()));
45         connect(viewLogPB, SIGNAL(clicked()),
46                 this, SLOT(viewLog()));
47         connect(errorsLW, SIGNAL(currentRowChanged(int)),
48                 this, SLOT(select()));
49
50         bc().setPolicy(ButtonPolicy::OkCancelPolicy);
51         bc().setCancel(closePB);
52 }
53
54
55 void GuiErrorList::showEvent(QShowEvent * e)
56 {
57         select();
58         paramsToDialog();
59         e->accept();
60 }
61
62
63 void GuiErrorList::select()
64 {
65         int const item = errorsLW->row(errorsLW->currentItem());
66         if (item == -1)
67                 return;
68         goTo(item);
69         descriptionTB->setPlainText(
70                 toqstr(errorList()[item].description));
71 }
72
73
74 void GuiErrorList::viewLog()
75 {
76         dispatch(FuncRequest(LFUN_DIALOG_SHOW, "latexlog"));
77 }
78
79
80 void GuiErrorList::paramsToDialog()
81 {
82         setTitle(toqstr(name_));
83         errorsLW->clear();
84         descriptionTB->setPlainText(QString());
85
86         ErrorList::const_iterator it = errorList().begin();
87         ErrorList::const_iterator end = errorList().end();
88         for (; it != end; ++it)
89                 errorsLW->addItem(toqstr(it->error));
90         errorsLW->setCurrentRow(0);
91 }
92
93
94 ErrorList const & GuiErrorList::errorList() const
95 {
96         return from_master_ ? 
97                 bufferview()->buffer().masterBuffer()->errorList(error_type_)
98                 : bufferview()->buffer().errorList(error_type_);
99 }
100
101
102 bool GuiErrorList::initialiseParams(string const & data)
103 {
104         from_master_ = prefixIs(data, "from_master|");
105         string error_type = data;
106         if (from_master_)
107                 error_type = split(data, '|');
108         error_type_ = error_type;
109         Buffer const * buf = from_master_ ?
110                 bufferview()->buffer().masterBuffer()
111                 : &bufferview()->buffer();
112         name_ = bformat(_("%1$s Errors (%2$s)"), _(error_type),
113                                      from_utf8(buf->absFileName()));
114         paramsToDialog();
115         return true;
116 }
117
118
119 bool GuiErrorList::goTo(int item)
120 {
121         ErrorItem const & err = errorList()[item];
122
123         if (err.par_id == -1)
124                 return false;
125
126         if (from_master_)
127                 // FIXME: implement
128                 return false;
129
130         Buffer const & buf = buffer();
131         DocIterator dit = buf.getParFromID(err.par_id);
132
133         if (dit == doc_iterator_end(&buf)) {
134         // FIXME: Happens when loading a read-only doc with 
135         // unknown layout. Should this be the case?
136                 LYXERR0("par id " << err.par_id << " not found");
137                 return false;
138         }
139
140         // Now make the selection.
141         // if pos_end is 0, this means it is end-of-paragraph
142         pos_type const s = dit.paragraph().size();
143         pos_type const end = err.pos_end ? min(err.pos_end, s) : s;
144         pos_type const start = min(err.pos_start, end);
145         pos_type const range = end - start;
146         dit.pos() = start;
147         BufferView * bv = const_cast<BufferView *>(bufferview());
148         // FIXME: If we used an LFUN, we would not need this line:
149         bv->putSelectionAt(dit, range, false);
150         bv->processUpdateFlags(Update::Force | Update::FitCursor);
151         return true;
152 }
153
154
155 Dialog * createGuiErrorList(GuiView & lv) { return new GuiErrorList(lv); }
156
157 } // namespace frontend
158 } // namespace lyx
159
160
161 #include "moc_GuiErrorList.cpp"