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"
34 FormInclude::FormInclude(LyXView * lv, Dialogs * d)
35 : FormBaseBD(lv, d, _("Include file")),
38 d->showInclude.connect(slot(this, &FormInclude::showInclude));
42 FL_FORM * FormInclude::form() const
50 void FormInclude::connect()
52 u_ = d_->updateBufferDependent.
53 connect(slot(this, &FormInclude::updateSlot));
54 h_ = d_->hideBufferDependent.
55 connect(slot(this, &FormInclude::hide));
56 FormBaseDeprecated::connect();
60 void FormInclude::disconnect()
63 FormBaseBD::disconnect();
68 void FormInclude::updateSlot(bool switched)
77 void FormInclude::build()
79 dialog_.reset(build_include());
81 // Workaround dumb xforms sizing bug
85 // Manage the ok and cancel buttons
86 bc_.setOK(dialog_->button_ok);
87 bc_.setCancel(dialog_->button_cancel);
90 bc_.addReadOnly(dialog_->button_browse);
91 bc_.addReadOnly(dialog_->check_verbatim);
92 bc_.addReadOnly(dialog_->check_typeset);
93 bc_.addReadOnly(dialog_->check_useinput);
94 bc_.addReadOnly(dialog_->check_useinclude);
98 void FormInclude::showInclude(InsetInclude * inset)
100 // If connected to another inset, disconnect from it.
105 params = inset->params();
106 ih_ = inset->hideDialog.connect(slot(this, &FormInclude::hide));
111 void FormInclude::update()
113 bc().readOnly(lv_->buffer()->isReadonly());
116 fl_set_input(dialog_->input_filename, "");
117 fl_set_button(dialog_->check_typeset, 0);
118 fl_set_button(dialog_->check_useinput, 0);
119 fl_set_button(dialog_->check_useinclude, 1);
120 fl_set_button(dialog_->check_verbatim, 0);
121 fl_set_button(dialog_->check_visiblespace, 0);
122 fl_deactivate_object(dialog_->check_visiblespace);
123 fl_set_object_lcol(dialog_->check_visiblespace, FL_INACTIVE);
127 fl_set_input(dialog_->input_filename, params.cparams.getContents().c_str());
129 string const cmdname = params.cparams.getCmdName();
131 fl_set_button(dialog_->check_typeset, int(params.noload));
133 fl_set_button(dialog_->check_useinput, cmdname == "input");
134 fl_set_button(dialog_->check_useinclude, cmdname == "include");
135 if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") {
136 fl_set_button(dialog_->check_verbatim, 1);
137 fl_set_button(dialog_->check_visiblespace, cmdname == "verbatiminput*");
138 setEnabled(dialog_->check_visiblespace, true);
140 fl_set_button(dialog_->check_visiblespace, 0);
141 setEnabled(dialog_->check_visiblespace, false);
145 fl_set_button(dialog_->check_useinclude, 1);
149 void FormInclude::apply()
151 if (lv_->buffer()->isReadonly())
154 params.noload = fl_get_button(dialog_->check_typeset);
156 params.cparams.setContents(fl_get_input(dialog_->input_filename));
158 if (fl_get_button(dialog_->check_useinput))
159 params.flag = InsetInclude::INPUT;
160 else if (fl_get_button(dialog_->check_useinclude))
161 params.flag = InsetInclude::INCLUDE;
162 else if (fl_get_button(dialog_->check_verbatim)) {
163 if (fl_get_button(dialog_->check_visiblespace))
164 params.flag = InsetInclude::VERBAST;
166 params.flag = InsetInclude::VERB;
169 inset_->setFromParams(params);
170 lv_->view()->updateInset(inset_, true);
174 #warning convert this to use the buttoncontroller
176 bool FormInclude::input(FL_OBJECT *, long data)
178 State state = static_cast<State>(data);
182 // Should browsing too be disabled in RO-mode?
183 FileDialog fileDlg(lv_, _("Select document to include"),
184 LFUN_SELECT_FILE_SYNC,
185 make_pair(string(_("Documents")), string(lyxrc.document_path)));
189 /* input TeX, verbatim, or LyX file ? */
190 if (fl_get_button(dialog_->check_useinput))
191 ext = _("*.tex| LaTeX Documents (*.tex)");
192 else if (fl_get_button(dialog_->check_verbatim))
193 ext = _("*| All files ");
195 ext = _("*.lyx| LyX Documents (*.lyx)");
199 mpath = OnlyPath(params.buffer->fileName());
201 FileDialog::Result result = fileDlg.Select(mpath, ext, fl_get_input(dialog_->input_filename));
203 // check selected filename
204 if (result.second.empty())
207 string const filename2 = MakeRelPath(result.second, mpath);
209 if (prefixIs(filename2, ".."))
210 fl_set_input(dialog_->input_filename, result.second.c_str());
212 fl_set_input(dialog_->input_filename, filename2.c_str());
217 if (compare(fl_get_input(dialog_->input_filename),"")) {
219 lv_->getLyXFunc()->Dispatch(LFUN_CHILDOPEN, params.cparams.getContents());
224 setEnabled(dialog_->check_visiblespace, true);
228 fl_set_button(dialog_->check_visiblespace, 0);
229 setEnabled(dialog_->check_visiblespace, false);