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 : FormCommand(lv, d, _("Include file"), new OkCancelPolicy),
38 d->showInclude.connect(slot(this, &FormInclude::showInset));
39 d->createInclude.connect(slot(this, &FormInclude::createInset));
43 FormInclude::~FormInclude()
49 FL_FORM * FormInclude::form() const
57 void FormInclude::build()
59 dialog_ = build_include();
61 // Workaround dumb xforms sizing bug
65 // Manage the ok and cancel buttons
66 bc_.setOK(dialog_->button_ok);
67 bc_.setCancel(dialog_->button_cancel);
70 bc_.addReadOnly(dialog_->browsebt);
71 bc_.addReadOnly(dialog_->flag1);
72 bc_.addReadOnly(dialog_->flag2);
73 bc_.addReadOnly(dialog_->flag3);
74 bc_.addReadOnly(dialog_->flag4);
75 bc_.addReadOnly(dialog_->filename);
76 bc_.addReadOnly(dialog_->flag41);
80 void FormInclude::update()
82 bc_.readOnly(lv_->buffer()->isReadonly());
85 fl_set_input(dialog_->filename, "");
86 fl_set_button(dialog_->flag1, 0);
87 fl_set_button(dialog_->flag2, 0);
88 fl_set_button(dialog_->flag3, 1);
89 fl_set_button(dialog_->flag4, 0);
90 fl_set_button(dialog_->flag41, 0);
91 fl_deactivate_object(dialog_->flag41);
92 fl_set_object_lcol(dialog_->flag41, FL_INACTIVE);
96 fl_set_input(dialog_->filename, params.getContents().c_str());
98 string const cmdname = params.getCmdName();
100 /* FIXME: what do with Don't typeset here ... */
101 //fl_set_button(dialog_->flag1, int(inset_->isNoLoad()));
103 fl_set_button(dialog_->flag2, cmdname == "input");
104 fl_set_button(dialog_->flag3, cmdname == "include");
105 if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") {
106 fl_set_button(dialog_->flag4, 1);
107 fl_set_button(dialog_->flag41, cmdname == "verbatiminput*");
109 fl_set_button(dialog_->flag41, 0);
110 fl_deactivate_object(dialog_->flag41);
111 fl_set_object_lcol(dialog_->flag41, FL_INACTIVE);
116 void FormInclude::apply()
118 if (lv_->buffer()->isReadonly())
121 /* FIXME: no way to update internal flags of inset ??? */
123 //inset_->setNoLoad(fl_get_button(dialog_->flag1));
125 params.setContents(fl_get_input(dialog_->filename));
127 if (fl_get_button(dialog_->flag2))
128 params.setCmdName("input");
129 else if (fl_get_button(dialog_->flag3))
130 params.setCmdName("include");
131 else if (fl_get_button(dialog_->flag4)) {
132 if (fl_get_button(dialog_->flag41))
133 params.setCmdName("verbatiminput*");
135 params.setCmdName("verbatiminput");
139 if (params != inset_->params()) {
140 inset_->setParams(params);
141 lv_->view()->updateInset(inset_, true);
144 lv_->getLyXFunc()->Dispatch(LFUN_CHILD_INSERT, params.getAsString());
148 #warning convert this to use the buttoncontroller
150 bool FormInclude::input(FL_OBJECT *, long data)
152 State state = static_cast<State>(data);
156 // Should browsing too be disabled in RO-mode?
157 FileDialog fileDlg(lv_, _("Select document to include"),
158 LFUN_SELECT_FILE_SYNC,
159 make_pair(string(_("Documents")), string(lyxrc.document_path)));
163 /* input TeX, verbatim, or LyX file ? */
164 if (fl_get_button(dialog_->flag2))
165 ext = _("*.tex| LaTeX Documents (*.tex)");
166 else if (fl_get_button(dialog_->flag4))
167 ext = _("*| All files ");
169 ext = _("*.lyx| LyX Documents (*.lyx)");
173 /* FIXME: what do I do here ? */
175 // mpath = OnlyPath(inset_->getMasterFilename());
177 FileDialog::Result result = fileDlg.Select(mpath, ext, fl_get_input(dialog_->filename));
179 // check selected filename
180 if (result.second.empty())
183 string const filename2 = MakeRelPath(result.second, mpath);
185 if (prefixIs(filename2, ".."))
186 fl_set_input(dialog_->filename, result.second.c_str());
188 fl_set_input(dialog_->filename, filename2.c_str());
194 lv_->getLyXFunc()->Dispatch(LFUN_CHILDOPEN, params.getContents());
198 setEnabled(dialog_->flag41, true);
202 /* FIXME: huh ? why doesn't this work ? */
203 setEnabled(dialog_->flag41, false);
204 fl_set_button(dialog_->flag41, 0);