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 "controllers/ControlInclude.h"
26 #include <QPushButton>
28 #include <QCloseEvent>
33 using lyx::support::os::internal_path;
39 /////////////////////////////////////////////////////////////////////
43 /////////////////////////////////////////////////////////////////////
45 QIncludeDialog::QIncludeDialog(QInclude * form)
49 connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
50 connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
52 connect(visiblespaceCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
53 connect(filenameED, SIGNAL(textChanged(const QString &)),
54 this, SLOT(change_adaptor()));
55 connect(loadPB, SIGNAL(clicked()), this, SLOT(loadClicked()));
56 connect(browsePB, SIGNAL(clicked()), this, SLOT(browseClicked()));
57 connect(typeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
58 connect(typeCO, SIGNAL(activated(int)), this, SLOT(typeChanged(int)));
59 connect(previewCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
61 filenameED->setValidator(new PathValidator(true, filenameED));
62 setFocusProxy(filenameED);
66 void QIncludeDialog::show()
72 void QIncludeDialog::change_adaptor()
78 void QIncludeDialog::closeEvent(QCloseEvent * e)
85 void QIncludeDialog::typeChanged(int v)
90 visiblespaceCB->setEnabled(false);
91 visiblespaceCB->setChecked(false);
92 previewCB->setEnabled(false);
93 previewCB->setChecked(false);
97 visiblespaceCB->setEnabled(false);
98 visiblespaceCB->setChecked(false);
99 previewCB->setEnabled(true);
103 visiblespaceCB->setEnabled(true);
104 previewCB->setEnabled(false);
105 previewCB->setChecked(false);
111 void QIncludeDialog::loadClicked()
117 void QIncludeDialog::browseClicked()
123 /////////////////////////////////////////////////////////////////////
127 /////////////////////////////////////////////////////////////////////
130 typedef QController<ControlInclude, QView<QIncludeDialog> > IncludeBase;
133 QInclude::QInclude(Dialog & parent)
134 : IncludeBase(parent, _("Child Document"))
138 void QInclude::build_dialog()
140 dialog_.reset(new QIncludeDialog(this));
142 bcview().setOK(dialog_->okPB);
143 bcview().setCancel(dialog_->closePB);
144 bcview().addReadOnly(dialog_->filenameED);
145 bcview().addReadOnly(dialog_->browsePB);
146 bcview().addReadOnly(dialog_->visiblespaceCB);
147 bcview().addReadOnly(dialog_->typeCO);
149 addCheckedLineEdit(bcview(), dialog_->filenameED, dialog_->filenameLA);
153 void QInclude::update_contents()
155 PathValidator * path_validator = getPathValidator(dialog_->filenameED);
157 path_validator->setChecker(kernel().docType(), lyxrc);
159 InsetCommandParams const & params = controller().params();
161 dialog_->filenameED->setText(toqstr(params["filename"]));
163 dialog_->visiblespaceCB->setChecked(false);
164 dialog_->visiblespaceCB->setEnabled(false);
165 dialog_->previewCB->setChecked(false);
166 dialog_->previewCB->setEnabled(false);
168 string cmdname = controller().params().getCmdName();
169 if (cmdname != "include" &&
170 cmdname != "verbatiminput" &&
171 cmdname != "verbatiminput*")
174 if (cmdname == "include") {
175 dialog_->typeCO->setCurrentIndex(0);
177 } else if (cmdname == "input") {
178 dialog_->typeCO->setCurrentIndex(1);
179 dialog_->previewCB->setEnabled(true);
180 dialog_->previewCB->setChecked(params.preview());
182 } else if (cmdname == "verbatiminput*") {
183 dialog_->typeCO->setCurrentIndex(2);
184 dialog_->visiblespaceCB->setEnabled(true);
185 dialog_->visiblespaceCB->setChecked(true);
187 } else if (cmdname == "verbatiminput") {
188 dialog_->typeCO->setCurrentIndex(2);
189 dialog_->visiblespaceCB->setEnabled(true);
194 void QInclude::apply()
196 InsetCommandParams params = controller().params();
198 params["filename"] = from_utf8(internal_path(fromqstr(dialog_->filenameED->text())));
199 params.preview(dialog_->previewCB->isChecked());
201 int const item = dialog_->typeCO->currentIndex();
203 params.setCmdName("include");
205 params.setCmdName("input");
207 if (dialog_->visiblespaceCB->isChecked())
208 params.setCmdName("verbatiminput*");
210 params.setCmdName("verbatiminput");
212 controller().setParams(params);
216 void QInclude::browse()
218 ControlInclude::Type type;
220 int const item = dialog_->typeCO->currentIndex();
222 type = ControlInclude::INCLUDE;
224 type = ControlInclude::INPUT;
226 type = ControlInclude::VERBATIM;
228 docstring const & name =
229 controller().browse(qstring_to_ucs4(dialog_->filenameED->text()), type);
231 dialog_->filenameED->setText(toqstr(name));
235 void QInclude::load()
238 string const file = fromqstr(dialog_->filenameED->text());
240 controller().load(file);
245 bool QInclude::isValid()
247 return !dialog_->filenameED->text().isEmpty();
250 } // namespace frontend
253 #include "QInclude_moc.cpp"