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"
15 #include "QIncludeDialog.h"
18 #include "checkedwidgets.h"
20 #include "qt_helpers.h"
21 #include "validators.h"
25 #include "controllers/ControlInclude.h"
27 #include <qlineedit.h>
28 #include <qpushbutton.h>
29 #include <qcheckbox.h>
33 using lyx::support::os::internal_path;
38 typedef QController<ControlInclude, QView<QIncludeDialog> > base_class;
41 QInclude::QInclude(Dialog & parent)
42 : base_class(parent, _("Child Document"))
46 void QInclude::build_dialog()
48 dialog_.reset(new QIncludeDialog(this));
50 bcview().setOK(dialog_->okPB);
51 bcview().setCancel(dialog_->closePB);
52 bcview().addReadOnly(dialog_->filenameED);
53 bcview().addReadOnly(dialog_->browsePB);
54 bcview().addReadOnly(dialog_->visiblespaceCB);
55 bcview().addReadOnly(dialog_->typeCO);
57 addCheckedLineEdit(bcview(), dialog_->filenameED, dialog_->filenameLA);
61 void QInclude::update_contents()
63 PathValidator * path_validator = getPathValidator(dialog_->filenameED);
65 path_validator->setChecker(kernel().docType(), lyxrc);
67 InsetCommandParams const & params = controller().params();
69 dialog_->filenameED->setText(toqstr(params["filename"]));
71 dialog_->visiblespaceCB->setChecked(false);
72 dialog_->visiblespaceCB->setEnabled(false);
73 dialog_->previewCB->setChecked(false);
74 dialog_->previewCB->setEnabled(false);
76 string cmdname = controller().params().getCmdName();
77 if (cmdname != "include" &&
78 cmdname != "verbatiminput" &&
79 cmdname != "verbatiminput*")
82 if (cmdname == "input") {
83 dialog_->typeCO->setCurrentIndex(0);
84 dialog_->previewCB->setEnabled(true);
85 dialog_->previewCB->setChecked(params.preview());
87 } else if (cmdname == "include") {
88 dialog_->typeCO->setCurrentIndex(1);
90 } else if (cmdname == "verbatiminput*") {
91 dialog_->typeCO->setCurrentIndex(2);
92 dialog_->visiblespaceCB->setEnabled(true);
93 dialog_->visiblespaceCB->setChecked(true);
95 } else if (cmdname == "verbatiminput") {
96 dialog_->typeCO->setCurrentIndex(2);
97 dialog_->visiblespaceCB->setEnabled(true);
102 void QInclude::apply()
104 InsetCommandParams params = controller().params();
106 params["filename"] = from_utf8(internal_path(fromqstr(dialog_->filenameED->text())));
107 params.preview(dialog_->previewCB->isChecked());
109 int const item = dialog_->typeCO->currentIndex();
111 params.setCmdName("input");
113 params.setCmdName("include");
115 if (dialog_->visiblespaceCB->isChecked())
116 params.setCmdName("verbatiminput*");
118 params.setCmdName("verbatiminput");
120 controller().setParams(params);
124 void QInclude::browse()
126 ControlInclude::Type type;
128 int const item = dialog_->typeCO->currentIndex();
130 type = ControlInclude::INPUT;
132 type = ControlInclude::INCLUDE;
134 type = ControlInclude::VERBATIM;
136 docstring const & name =
137 controller().browse(qstring_to_ucs4(dialog_->filenameED->text()), type);
139 dialog_->filenameED->setText(toqstr(name));
143 void QInclude::load()
146 string const file(fromqstr(dialog_->filenameED->text()));
148 controller().load(file);
153 bool QInclude::isValid()
155 return !dialog_->filenameED->text().isEmpty();
158 } // namespace frontend