3 * Copyright 2001 the LyX Team
4 * Read the file COPYING
6 * \author Alejandro Aguilar Sierra
7 * \author John Levon, moz@compsoc.man.ac.uk
8 * \author Angus Leeming, a.leeming@.ac.uk
15 #pragma implementation
20 #include "ControlInclude.h"
21 #include "FormInclude.h"
22 #include "form_include.h"
23 #include "insets/insetinclude.h"
25 #include "frontends/FileDialog.h"
29 #include "xforms_helpers.h" // setEnabled
30 #include "support/filetools.h"
31 #include "support/lstrings.h"
37 typedef FormCB<ControlInclude, FormDB<FD_form_include> > base_class;
39 FormInclude::FormInclude(ControlInclude & c)
40 : base_class(c, _("Include file"))
44 void FormInclude::build()
46 dialog_.reset(build_include());
48 // Manage the ok and cancel buttons
49 bc().setOK(dialog_->button_ok);
50 bc().setCancel(dialog_->button_cancel);
53 bc().addReadOnly(dialog_->button_browse);
54 bc().addReadOnly(dialog_->check_verbatim);
55 bc().addReadOnly(dialog_->check_typeset);
56 bc().addReadOnly(dialog_->check_useinput);
57 bc().addReadOnly(dialog_->check_useinclude);
61 void FormInclude::update()
63 if (controller().params().noload) {
64 fl_set_input(dialog_->input_filename, "");
65 fl_set_button(dialog_->check_typeset, 0);
66 fl_set_button(dialog_->check_useinput, 0);
67 fl_set_button(dialog_->check_useinclude, 1);
68 fl_set_button(dialog_->check_verbatim, 0);
69 fl_set_button(dialog_->check_visiblespace, 0);
70 fl_deactivate_object(dialog_->check_visiblespace);
71 fl_set_object_lcol(dialog_->check_visiblespace, FL_INACTIVE);
75 fl_set_input(dialog_->input_filename,
76 controller().params().cparams.getContents().c_str());
78 string const cmdname = controller().params().cparams.getCmdName();
80 fl_set_button(dialog_->check_typeset,
81 int(controller().params().noload));
83 fl_set_button(dialog_->check_useinput, cmdname == "input");
84 fl_set_button(dialog_->check_useinclude, cmdname == "include");
85 if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") {
86 fl_set_button(dialog_->check_verbatim, 1);
87 fl_set_button(dialog_->check_visiblespace, cmdname == "verbatiminput*");
88 setEnabled(dialog_->check_visiblespace, true);
90 fl_set_button(dialog_->check_visiblespace, 0);
91 setEnabled(dialog_->check_visiblespace, false);
95 fl_set_button(dialog_->check_useinclude, 1);
99 void FormInclude::apply()
101 controller().params().noload = fl_get_button(dialog_->check_typeset);
103 controller().params().cparams.
104 setContents(fl_get_input(dialog_->input_filename));
106 if (fl_get_button(dialog_->check_useinput))
107 controller().params().flag = InsetInclude::INPUT;
108 else if (fl_get_button(dialog_->check_useinclude))
109 controller().params().flag = InsetInclude::INCLUDE;
110 else if (fl_get_button(dialog_->check_verbatim)) {
111 if (fl_get_button(dialog_->check_visiblespace))
112 controller().params().flag = InsetInclude::VERBAST;
114 controller().params().flag = InsetInclude::VERB;
119 ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
121 if (ob == dialog_->button_browse)
122 return inputBrowse();
124 if (ob == dialog_->button_load) {
125 if (compare(fl_get_input(dialog_->input_filename),"")) {
127 return ButtonPolicy::SMI_NOOP;
131 if (ob == dialog_->check_verbatim) {
132 setEnabled(dialog_->check_visiblespace, true);
134 } else if (ob == dialog_->check_useinclude ||
135 ob == dialog_->check_useinput) {
136 fl_set_button(dialog_->check_visiblespace, 0);
137 setEnabled(dialog_->check_visiblespace, false);
140 return ButtonPolicy::SMI_VALID;
144 ButtonPolicy::SMInput FormInclude::inputBrowse()
146 // Should browsing too be disabled in RO-mode?
147 FileDialog fileDlg(controller().lv(),
148 _("Select document to include"),
149 LFUN_SELECT_FILE_SYNC,
150 make_pair(string(_("Documents")),
151 string(lyxrc.document_path)));
155 // input TeX, verbatim, or LyX file ?
156 if (fl_get_button(dialog_->check_useinput))
157 ext = _("*.tex| LaTeX Documents (*.tex)");
158 else if (fl_get_button(dialog_->check_verbatim))
159 ext = _("*| All files ");
161 ext = _("*.lyx| LyX Documents (*.lyx)");
164 OnlyPath(controller().params().masterFilename_);
166 FileDialog::Result const result =
167 fileDlg.Select(mpath, ext,
168 fl_get_input(dialog_->input_filename));
170 // check selected filename
171 if (result.second.empty())
172 return ButtonPolicy::SMI_NOOP;
174 string const filename2 = MakeRelPath(result.second, mpath);
176 if (prefixIs(filename2, ".."))
177 fl_set_input(dialog_->input_filename, result.second.c_str());
179 fl_set_input(dialog_->input_filename, filename2.c_str());
181 return ButtonPolicy::SMI_VALID;