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"), new OkCancelPolicy),
36 dialog_(0), ih_(0), inset_(0)
38 d->showInclude.connect(slot(this, &FormInclude::showInclude));
42 FormInclude::~FormInclude()
48 FL_FORM * FormInclude::form() const
56 void FormInclude::connect()
58 u_ = d_->updateBufferDependent.
59 connect(slot(this, &FormInclude::updateSlot));
60 h_ = d_->hideBufferDependent.
61 connect(slot(this, &FormInclude::hide));
66 void FormInclude::disconnect()
69 FormBaseBD::disconnect();
74 void FormInclude::updateSlot(bool switched)
83 void FormInclude::build()
85 dialog_ = build_include();
87 // Workaround dumb xforms sizing bug
91 // Manage the ok and cancel buttons
92 bc_.setOK(dialog_->button_ok);
93 bc_.setCancel(dialog_->button_cancel);
96 bc_.addReadOnly(dialog_->button_browse);
97 bc_.addReadOnly(dialog_->check_verbatim);
98 bc_.addReadOnly(dialog_->check_typeset);
99 bc_.addReadOnly(dialog_->check_useinput);
100 bc_.addReadOnly(dialog_->check_useinclude);
104 void FormInclude::showInclude(InsetInclude * inset)
106 // If connected to another inset, disconnect from it.
111 params = inset->params();
112 ih_ = inset->hideDialog.connect(slot(this, &FormInclude::hide));
117 void FormInclude::update()
119 bc_.readOnly(lv_->buffer()->isReadonly());
122 fl_set_input(dialog_->input_filename, "");
123 fl_set_button(dialog_->check_typeset, 0);
124 fl_set_button(dialog_->check_useinput, 0);
125 fl_set_button(dialog_->check_useinclude, 1);
126 fl_set_button(dialog_->check_verbatim, 0);
127 fl_set_button(dialog_->check_visiblespace, 0);
128 fl_deactivate_object(dialog_->check_visiblespace);
129 fl_set_object_lcol(dialog_->check_visiblespace, FL_INACTIVE);
133 fl_set_input(dialog_->input_filename, params.cparams.getContents().c_str());
135 string const cmdname = params.cparams.getCmdName();
137 fl_set_button(dialog_->check_typeset, int(params.noload));
139 fl_set_button(dialog_->check_useinput, cmdname == "input");
140 fl_set_button(dialog_->check_useinclude, cmdname == "include");
141 if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") {
142 fl_set_button(dialog_->check_verbatim, 1);
143 fl_set_button(dialog_->check_visiblespace, cmdname == "verbatiminput*");
144 setEnabled(dialog_->check_visiblespace, true);
146 fl_set_button(dialog_->check_visiblespace, 0);
147 setEnabled(dialog_->check_visiblespace, false);
151 fl_set_button(dialog_->check_useinclude, 1);
155 void FormInclude::apply()
157 if (lv_->buffer()->isReadonly())
160 params.noload = fl_get_button(dialog_->check_typeset);
162 params.cparams.setContents(fl_get_input(dialog_->input_filename));
164 if (fl_get_button(dialog_->check_useinput))
165 params.flag = InsetInclude::INPUT;
166 else if (fl_get_button(dialog_->check_useinclude))
167 params.flag = InsetInclude::INCLUDE;
168 else if (fl_get_button(dialog_->check_verbatim)) {
169 if (fl_get_button(dialog_->check_visiblespace))
170 params.flag = InsetInclude::VERBAST;
172 params.flag = InsetInclude::VERB;
175 inset_->setFromParams(params);
176 lv_->view()->updateInset(inset_, true);
180 #warning convert this to use the buttoncontroller
182 bool FormInclude::input(FL_OBJECT *, long data)
184 State state = static_cast<State>(data);
188 // Should browsing too be disabled in RO-mode?
189 FileDialog fileDlg(lv_, _("Select document to include"),
190 LFUN_SELECT_FILE_SYNC,
191 make_pair(string(_("Documents")), string(lyxrc.document_path)));
195 /* input TeX, verbatim, or LyX file ? */
196 if (fl_get_button(dialog_->check_useinput))
197 ext = _("*.tex| LaTeX Documents (*.tex)");
198 else if (fl_get_button(dialog_->check_verbatim))
199 ext = _("*| All files ");
201 ext = _("*.lyx| LyX Documents (*.lyx)");
205 mpath = OnlyPath(params.buffer->fileName());
207 FileDialog::Result result = fileDlg.Select(mpath, ext, fl_get_input(dialog_->input_filename));
209 // check selected filename
210 if (result.second.empty())
213 string const filename2 = MakeRelPath(result.second, mpath);
215 if (prefixIs(filename2, ".."))
216 fl_set_input(dialog_->input_filename, result.second.c_str());
218 fl_set_input(dialog_->input_filename, filename2.c_str());
223 if (compare(fl_get_input(dialog_->input_filename),"")) {
225 lv_->getLyXFunc()->Dispatch(LFUN_CHILDOPEN, params.cparams.getContents());
230 setEnabled(dialog_->check_visiblespace, true);
234 fl_set_button(dialog_->check_visiblespace, 0);
235 setEnabled(dialog_->check_visiblespace, false);