3 * Copyright 2001 the LyX Team
4 * Read the file COPYING
6 * \author Alejandro Aguilar Sierra
14 #pragma implementation
18 #include "FormInclude.h"
19 #include "insets/insetinclude.h"
20 #include "frontends/FileDialog.h"
21 #include "support/filetools.h"
22 #include "support/lstrings.h"
27 #include "xforms_helpers.h"
29 #include "form_include.h"
35 FormInclude::FormInclude(LyXView * lv, Dialogs * d)
36 : FormBaseBD(lv, d, _("Include file")),
39 d->showInclude.connect(slot(this, &FormInclude::showInclude));
43 FL_FORM * FormInclude::form() const
51 void FormInclude::connect()
53 u_ = d_->updateBufferDependent.
54 connect(slot(this, &FormInclude::updateSlot));
55 h_ = d_->hideBufferDependent.
56 connect(slot(this, &FormInclude::hide));
57 FormBaseDeprecated::connect();
61 void FormInclude::disconnect()
64 FormBaseBD::disconnect();
69 void FormInclude::updateSlot(bool switched)
78 void FormInclude::build()
80 dialog_.reset(build_include());
82 // Manage the ok and cancel buttons
83 bc_.setOK(dialog_->button_ok);
84 bc_.setCancel(dialog_->button_cancel);
87 bc_.addReadOnly(dialog_->button_browse);
88 bc_.addReadOnly(dialog_->check_verbatim);
89 bc_.addReadOnly(dialog_->check_typeset);
90 bc_.addReadOnly(dialog_->check_useinput);
91 bc_.addReadOnly(dialog_->check_useinclude);
95 void FormInclude::showInclude(InsetInclude * inset)
97 // If connected to another inset, disconnect from it.
102 params = inset->params();
103 ih_ = inset->hideDialog.connect(slot(this, &FormInclude::hide));
108 void FormInclude::update()
110 bc().readOnly(lv_->buffer()->isReadonly());
113 fl_set_input(dialog_->input_filename, "");
114 fl_set_button(dialog_->check_typeset, 0);
115 fl_set_button(dialog_->check_useinput, 0);
116 fl_set_button(dialog_->check_useinclude, 1);
117 fl_set_button(dialog_->check_verbatim, 0);
118 fl_set_button(dialog_->check_visiblespace, 0);
119 fl_deactivate_object(dialog_->check_visiblespace);
120 fl_set_object_lcol(dialog_->check_visiblespace, FL_INACTIVE);
124 fl_set_input(dialog_->input_filename, params.cparams.getContents().c_str());
126 string const cmdname = params.cparams.getCmdName();
128 fl_set_button(dialog_->check_typeset, int(params.noload));
130 fl_set_button(dialog_->check_useinput, cmdname == "input");
131 fl_set_button(dialog_->check_useinclude, cmdname == "include");
132 if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") {
133 fl_set_button(dialog_->check_verbatim, 1);
134 fl_set_button(dialog_->check_visiblespace, cmdname == "verbatiminput*");
135 setEnabled(dialog_->check_visiblespace, true);
137 fl_set_button(dialog_->check_visiblespace, 0);
138 setEnabled(dialog_->check_visiblespace, false);
142 fl_set_button(dialog_->check_useinclude, 1);
146 void FormInclude::apply()
148 if (lv_->buffer()->isReadonly())
151 params.noload = fl_get_button(dialog_->check_typeset);
153 params.cparams.setContents(fl_get_input(dialog_->input_filename));
155 if (fl_get_button(dialog_->check_useinput))
156 params.flag = InsetInclude::INPUT;
157 else if (fl_get_button(dialog_->check_useinclude))
158 params.flag = InsetInclude::INCLUDE;
159 else if (fl_get_button(dialog_->check_verbatim)) {
160 if (fl_get_button(dialog_->check_visiblespace))
161 params.flag = InsetInclude::VERBAST;
163 params.flag = InsetInclude::VERB;
166 inset_->setFromParams(params);
167 lv_->view()->updateInset(inset_, true);
171 #warning convert this to use the buttoncontroller
173 bool FormInclude::input(FL_OBJECT *, long data)
175 State state = static_cast<State>(data);
179 // Should browsing too be disabled in RO-mode?
180 FileDialog fileDlg(lv_, _("Select document to include"),
181 LFUN_SELECT_FILE_SYNC,
182 make_pair(string(_("Documents")), string(lyxrc.document_path)));
186 /* input TeX, verbatim, or LyX file ? */
187 if (fl_get_button(dialog_->check_useinput))
188 ext = _("*.tex| LaTeX Documents (*.tex)");
189 else if (fl_get_button(dialog_->check_verbatim))
190 ext = _("*| All files ");
192 ext = _("*.lyx| LyX Documents (*.lyx)");
196 mpath = OnlyPath(params.buffer->fileName());
198 FileDialog::Result result = fileDlg.Select(mpath, ext, fl_get_input(dialog_->input_filename));
200 // check selected filename
201 if (result.second.empty())
204 string const filename2 = MakeRelPath(result.second, mpath);
206 if (prefixIs(filename2, ".."))
207 fl_set_input(dialog_->input_filename, result.second.c_str());
209 fl_set_input(dialog_->input_filename, filename2.c_str());
214 if (compare(fl_get_input(dialog_->input_filename),"")) {
216 lv_->getLyXFunc()->Dispatch(LFUN_CHILDOPEN, params.cparams.getContents());
221 setEnabled(dialog_->check_visiblespace, true);
225 fl_set_button(dialog_->check_visiblespace, 0);
226 setEnabled(dialog_->check_visiblespace, false);