3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "support/os.h"
17 #include "CheckedLineEdit.h"
19 #include "qt_helpers.h"
20 #include "Validator.h"
24 #include "insets/InsetListingsParams.h"
25 #include "controllers/ControlInclude.h"
27 #include <QPushButton>
29 #include <QCloseEvent>
34 using lyx::support::os::internal_path;
40 /////////////////////////////////////////////////////////////////////
44 /////////////////////////////////////////////////////////////////////
46 QIncludeDialog::QIncludeDialog(QInclude * form)
50 connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
51 connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
53 connect(visiblespaceCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
54 connect(filenameED, SIGNAL(textChanged(const QString &)),
55 this, SLOT(change_adaptor()));
56 connect(loadPB, SIGNAL(clicked()), this, SLOT(loadClicked()));
57 connect(browsePB, SIGNAL(clicked()), this, SLOT(browseClicked()));
58 connect(typeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
59 connect(typeCO, SIGNAL(activated(int)), this, SLOT(typeChanged(int)));
60 connect(previewCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
61 connect(listingsED, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
62 connect(listingsED, SIGNAL(textChanged()), this, SLOT(validate_listings_params()));
64 filenameED->setValidator(new PathValidator(true, filenameED));
65 setFocusProxy(filenameED);
69 void QIncludeDialog::show()
75 void QIncludeDialog::change_adaptor()
81 void QIncludeDialog::validate_listings_params()
83 static bool isOK = true;
85 InsetListingsParams par(fromqstr(listingsED->toPlainText()));
88 // listingsTB->setTextColor("black");
89 listingsTB->setPlainText("Input listings parameters below. Enter ? for a list of parameters.");
90 okPB->setEnabled(true);
92 } catch (invalidParam & e) {
94 // listingsTB->setTextColor("red");
95 listingsTB->setPlainText(e.what());
96 okPB->setEnabled(false);
101 void QIncludeDialog::closeEvent(QCloseEvent * e)
108 void QIncludeDialog::typeChanged(int v)
113 visiblespaceCB->setEnabled(false);
114 visiblespaceCB->setChecked(false);
115 previewCB->setEnabled(false);
116 previewCB->setChecked(false);
117 listingsGB->setEnabled(false);
118 listingsED->setEnabled(false);
122 visiblespaceCB->setEnabled(false);
123 visiblespaceCB->setChecked(false);
124 previewCB->setEnabled(true);
125 listingsGB->setEnabled(false);
126 listingsED->setEnabled(false);
130 visiblespaceCB->setEnabled(false);
131 visiblespaceCB->setChecked(false);
132 previewCB->setEnabled(false);
133 listingsGB->setEnabled(true);
134 listingsED->setEnabled(true);
138 visiblespaceCB->setEnabled(true);
139 previewCB->setEnabled(false);
140 previewCB->setChecked(false);
141 listingsGB->setEnabled(false);
142 listingsED->setEnabled(false);
148 void QIncludeDialog::loadClicked()
154 void QIncludeDialog::browseClicked()
160 /////////////////////////////////////////////////////////////////////
164 /////////////////////////////////////////////////////////////////////
167 typedef QController<ControlInclude, QView<QIncludeDialog> > IncludeBase;
170 QInclude::QInclude(Dialog & parent)
171 : IncludeBase(parent, _("Child Document"))
175 void QInclude::build_dialog()
177 dialog_.reset(new QIncludeDialog(this));
179 bcview().setOK(dialog_->okPB);
180 bcview().setCancel(dialog_->closePB);
181 bcview().addReadOnly(dialog_->filenameED);
182 bcview().addReadOnly(dialog_->browsePB);
183 bcview().addReadOnly(dialog_->visiblespaceCB);
184 bcview().addReadOnly(dialog_->typeCO);
185 bcview().addReadOnly(dialog_->listingsED);
186 dialog_->listingsTB->setPlainText("Input listings parameters below. Enter ? for a list of parameters.");
188 addCheckedLineEdit(bcview(), dialog_->filenameED, dialog_->filenameLA);
192 void QInclude::update_contents()
194 PathValidator * path_validator = getPathValidator(dialog_->filenameED);
196 path_validator->setChecker(kernel().docType(), lyxrc);
198 InsetCommandParams const & params = controller().params();
200 dialog_->filenameED->setText(toqstr(params["filename"]));
202 dialog_->visiblespaceCB->setChecked(false);
203 dialog_->visiblespaceCB->setEnabled(false);
204 dialog_->previewCB->setChecked(false);
205 dialog_->previewCB->setEnabled(false);
206 dialog_->listingsGB->setEnabled(false);
207 dialog_->listingsED->setEnabled(false);
209 string cmdname = controller().params().getCmdName();
210 if (cmdname != "include" &&
211 cmdname != "verbatiminput" &&
212 cmdname != "verbatiminput*" &&
213 cmdname != "lstinputlisting")
216 if (cmdname == "include") {
217 dialog_->typeCO->setCurrentIndex(0);
219 } else if (cmdname == "input") {
220 dialog_->typeCO->setCurrentIndex(1);
221 dialog_->previewCB->setEnabled(true);
222 dialog_->previewCB->setChecked(params.preview());
224 } else if (cmdname == "verbatiminput*") {
225 dialog_->typeCO->setCurrentIndex(2);
226 dialog_->visiblespaceCB->setEnabled(true);
227 dialog_->visiblespaceCB->setChecked(true);
229 } else if (cmdname == "verbatiminput") {
230 dialog_->typeCO->setCurrentIndex(2);
231 dialog_->visiblespaceCB->setEnabled(true);
233 } else if (cmdname == "lstinputlisting") {
234 dialog_->typeCO->setCurrentIndex(3);
235 dialog_->listingsGB->setEnabled(true);
236 dialog_->listingsED->setEnabled(true);
237 InsetListingsParams par(params.getOptions());
238 dialog_->listingsED->setText(toqstr(par.separatedParams()));
243 void QInclude::apply()
245 InsetCommandParams params = controller().params();
247 params["filename"] = from_utf8(internal_path(fromqstr(dialog_->filenameED->text())));
248 params.preview(dialog_->previewCB->isChecked());
250 int const item = dialog_->typeCO->currentIndex();
252 params.setCmdName("include");
253 params.setOptions(string());
254 } else if (item == 1) {
255 params.setCmdName("input");
256 params.setOptions(string());
257 } else if (item == 3) {
258 params.setCmdName("lstinputlisting");
259 // the parameter string should have passed validation
260 params.setOptions(InsetListingsParams(fromqstr(dialog_->listingsED->toPlainText())).params());
262 if (dialog_->visiblespaceCB->isChecked())
263 params.setCmdName("verbatiminput*");
265 params.setCmdName("verbatiminput");
266 params.setOptions(string());
268 controller().setParams(params);
272 void QInclude::browse()
274 ControlInclude::Type type;
276 int const item = dialog_->typeCO->currentIndex();
278 type = ControlInclude::INCLUDE;
280 type = ControlInclude::INPUT;
282 type = ControlInclude::VERBATIM;
284 type = ControlInclude::LISTINGS;
286 docstring const & name =
287 controller().browse(qstring_to_ucs4(dialog_->filenameED->text()), type);
289 dialog_->filenameED->setText(toqstr(name));
293 void QInclude::load()
296 string const file = fromqstr(dialog_->filenameED->text());
298 controller().load(file);
303 bool QInclude::isValid()
305 return !dialog_->filenameED->text().isEmpty();
308 } // namespace frontend
311 #include "QInclude_moc.cpp"