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 // Workaround dumb xforms sizing bug
86 // Manage the ok and cancel buttons
87 bc_.setOK(dialog_->button_ok);
88 bc_.setCancel(dialog_->button_cancel);
91 bc_.addReadOnly(dialog_->button_browse);
92 bc_.addReadOnly(dialog_->check_verbatim);
93 bc_.addReadOnly(dialog_->check_typeset);
94 bc_.addReadOnly(dialog_->check_useinput);
95 bc_.addReadOnly(dialog_->check_useinclude);
99 void FormInclude::showInclude(InsetInclude * inset)
101 // If connected to another inset, disconnect from it.
106 params = inset->params();
107 ih_ = inset->hideDialog.connect(slot(this, &FormInclude::hide));
112 void FormInclude::update()
114 bc().readOnly(lv_->buffer()->isReadonly());
117 fl_set_input(dialog_->input_filename, "");
118 fl_set_button(dialog_->check_typeset, 0);
119 fl_set_button(dialog_->check_useinput, 0);
120 fl_set_button(dialog_->check_useinclude, 1);
121 fl_set_button(dialog_->check_verbatim, 0);
122 fl_set_button(dialog_->check_visiblespace, 0);
123 fl_deactivate_object(dialog_->check_visiblespace);
124 fl_set_object_lcol(dialog_->check_visiblespace, FL_INACTIVE);
128 fl_set_input(dialog_->input_filename, params.cparams.getContents().c_str());
130 string const cmdname = params.cparams.getCmdName();
132 fl_set_button(dialog_->check_typeset, int(params.noload));
134 fl_set_button(dialog_->check_useinput, cmdname == "input");
135 fl_set_button(dialog_->check_useinclude, cmdname == "include");
136 if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") {
137 fl_set_button(dialog_->check_verbatim, 1);
138 fl_set_button(dialog_->check_visiblespace, cmdname == "verbatiminput*");
139 setEnabled(dialog_->check_visiblespace, true);
141 fl_set_button(dialog_->check_visiblespace, 0);
142 setEnabled(dialog_->check_visiblespace, false);
146 fl_set_button(dialog_->check_useinclude, 1);
150 void FormInclude::apply()
152 if (lv_->buffer()->isReadonly())
155 params.noload = fl_get_button(dialog_->check_typeset);
157 params.cparams.setContents(fl_get_input(dialog_->input_filename));
159 if (fl_get_button(dialog_->check_useinput))
160 params.flag = InsetInclude::INPUT;
161 else if (fl_get_button(dialog_->check_useinclude))
162 params.flag = InsetInclude::INCLUDE;
163 else if (fl_get_button(dialog_->check_verbatim)) {
164 if (fl_get_button(dialog_->check_visiblespace))
165 params.flag = InsetInclude::VERBAST;
167 params.flag = InsetInclude::VERB;
170 inset_->setFromParams(params);
171 lv_->view()->updateInset(inset_, true);
175 #warning convert this to use the buttoncontroller
177 bool FormInclude::input(FL_OBJECT *, long data)
179 State state = static_cast<State>(data);
183 // Should browsing too be disabled in RO-mode?
184 FileDialog fileDlg(lv_, _("Select document to include"),
185 LFUN_SELECT_FILE_SYNC,
186 make_pair(string(_("Documents")), string(lyxrc.document_path)));
190 /* input TeX, verbatim, or LyX file ? */
191 if (fl_get_button(dialog_->check_useinput))
192 ext = _("*.tex| LaTeX Documents (*.tex)");
193 else if (fl_get_button(dialog_->check_verbatim))
194 ext = _("*| All files ");
196 ext = _("*.lyx| LyX Documents (*.lyx)");
200 mpath = OnlyPath(params.buffer->fileName());
202 FileDialog::Result result = fileDlg.Select(mpath, ext, fl_get_input(dialog_->input_filename));
204 // check selected filename
205 if (result.second.empty())
208 string const filename2 = MakeRelPath(result.second, mpath);
210 if (prefixIs(filename2, ".."))
211 fl_set_input(dialog_->input_filename, result.second.c_str());
213 fl_set_input(dialog_->input_filename, filename2.c_str());
218 if (compare(fl_get_input(dialog_->input_filename),"")) {
220 lv_->getLyXFunc()->Dispatch(LFUN_CHILDOPEN, params.cparams.getContents());
225 setEnabled(dialog_->check_visiblespace, true);
229 fl_set_button(dialog_->check_visiblespace, 0);
230 setEnabled(dialog_->check_visiblespace, false);