3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
8 * \author Angus Leeming
10 * Full author contact details are available in file CREDITS
17 #pragma implementation
21 #include "ControlInclude.h"
22 #include "FormInclude.h"
23 #include "forms/form_include.h"
24 #include "insets/insetinclude.h"
25 #include "xforms_helpers.h" // setEnabled
26 #include "support/lstrings.h" // strip
27 #include FORMS_H_LOCATION
29 typedef FormCB<ControlInclude, FormDB<FD_include> > base_class;
31 FormInclude::FormInclude()
32 : base_class(_("Include file"))
36 void FormInclude::build()
38 dialog_.reset(build_include(this));
40 fl_set_input_return(dialog_->input_filename, FL_RETURN_CHANGED);
41 setPrehandler(dialog_->input_filename);
43 // Manage the ok and cancel buttons
44 bc().setOK(dialog_->button_ok);
45 bc().setCancel(dialog_->button_close);
47 bc().addReadOnly(dialog_->button_browse);
48 bc().addReadOnly(dialog_->radio_verbatim);
49 bc().addReadOnly(dialog_->check_typeset);
50 bc().addReadOnly(dialog_->radio_useinput);
51 bc().addReadOnly(dialog_->radio_useinclude);
55 void FormInclude::update()
58 // I believe this is not needed.
59 // Anyway, it is plain wrong (JSpitzm 3/7/02)
60 if (controller().params().noload) {
61 fl_set_input(dialog_->input_filename, "");
62 fl_set_button(dialog_->check_typeset, 0);
63 fl_set_button(dialog_->radio_useinput, 0);
64 fl_set_button(dialog_->radio_useinclude, 1);
65 fl_set_button(dialog_->radio_verbatim, 0);
66 fl_set_button(dialog_->check_visiblespace, 0);
67 fl_deactivate_object(dialog_->check_visiblespace);
68 fl_set_object_lcol(dialog_->check_visiblespace, FL_INACTIVE);
73 fl_set_input(dialog_->input_filename,
74 controller().params().cparams.getContents().c_str());
76 string const cmdname = controller().params().cparams.getCmdName();
78 fl_set_button(dialog_->check_typeset,
79 int(controller().params().noload));
81 if (cmdname == "input")
82 fl_set_button(dialog_->check_preview,
83 int(controller().params().cparams.preview()));
85 fl_set_button(dialog_->check_preview, 0);
87 setEnabled(dialog_->check_preview, (cmdname == "input"));
89 fl_set_button(dialog_->radio_useinput, cmdname == "input");
90 fl_set_button(dialog_->radio_useinclude, cmdname == "include");
91 if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") {
92 fl_set_button(dialog_->radio_verbatim, 1);
93 fl_set_button(dialog_->check_visiblespace, cmdname == "verbatiminput*");
94 setEnabled(dialog_->check_visiblespace, true);
95 setEnabled(dialog_->button_load, false);
97 fl_set_button(dialog_->check_visiblespace, 0);
98 setEnabled(dialog_->check_visiblespace, false);
99 setEnabled(dialog_->button_load, true);
103 fl_set_button(dialog_->radio_useinclude, 1);
107 void FormInclude::apply()
109 controller().params().noload = fl_get_button(dialog_->check_typeset);
110 controller().params().cparams
111 .preview(fl_get_button(dialog_->check_preview));
113 string const file = fl_get_input(dialog_->input_filename);
114 if (controller().fileExists(file))
115 controller().params().cparams.setContents(file);
117 controller().params().cparams.setContents("");
119 if (fl_get_button(dialog_->radio_useinput))
120 controller().params().flag = InsetInclude::INPUT;
121 else if (fl_get_button(dialog_->radio_useinclude))
122 controller().params().flag = InsetInclude::INCLUDE;
123 else if (fl_get_button(dialog_->radio_verbatim)) {
124 if (fl_get_button(dialog_->check_visiblespace))
125 controller().params().flag = InsetInclude::VERBAST;
127 controller().params().flag = InsetInclude::VERB;
132 ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
134 ButtonPolicy::SMInput action = ButtonPolicy::SMI_VALID;
136 if (ob == dialog_->button_browse) {
137 ControlInclude::Type type;
138 if (fl_get_button(dialog_->radio_useinput))
139 type = ControlInclude::INPUT;
140 else if (fl_get_button(dialog_->radio_verbatim))
141 type = ControlInclude::VERBATIM;
143 type = ControlInclude::INCLUDE;
145 string const in_name = fl_get_input(dialog_->input_filename);
146 fl_freeze_form(form());
147 string const out_name = controller().Browse(in_name, type);
148 fl_set_input(dialog_->input_filename, out_name.c_str());
149 fl_unfreeze_form(form());
151 } else if (ob == dialog_->button_load) {
152 string const in_name = fl_get_input(dialog_->input_filename);
153 if (!rtrim(in_name).empty() && controller().fileExists(in_name)) {
155 controller().OKButton();
156 controller().load(rtrim(in_name));
157 action = ButtonPolicy::SMI_NOOP;
160 } else if (ob == dialog_->radio_verbatim) {
161 setEnabled(dialog_->check_visiblespace, true);
162 setEnabled(dialog_->button_load, false);
164 } else if (ob == dialog_->radio_useinclude ||
165 ob == dialog_->radio_useinput) {
166 fl_set_button(dialog_->check_visiblespace, 0);
167 setEnabled(dialog_->check_visiblespace, false);
168 setEnabled(dialog_->button_load, true);
170 } else if (ob == dialog_->input_filename) {
171 string const in_name = fl_get_input(dialog_->input_filename);
172 if (rtrim(in_name).empty())
173 action = ButtonPolicy::SMI_INVALID;
176 if (ob == dialog_->radio_useinput) {
177 setEnabled(dialog_->check_preview, true);
178 } else if (ob == dialog_->radio_verbatim ||
179 ob == dialog_->radio_useinclude) {
180 fl_set_button(dialog_->check_preview, 0);
181 setEnabled(dialog_->check_preview, false);