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 <leeming@lyx.org>
15 #pragma implementation
19 #include "ControlInclude.h"
20 #include "FormInclude.h"
21 #include "forms/form_include.h"
22 #include "insets/insetinclude.h"
23 #include "xforms_helpers.h" // setEnabled
24 #include "support/lstrings.h" // strip
25 #include FORMS_H_LOCATION
27 typedef FormCB<ControlInclude, FormDB<FD_include> > base_class;
29 FormInclude::FormInclude()
30 : base_class(_("Include file"))
34 void FormInclude::build()
36 dialog_.reset(build_include(this));
38 fl_set_input_return(dialog_->input_filename, FL_RETURN_CHANGED);
39 setPrehandler(dialog_->input_filename);
41 // Manage the ok and cancel buttons
42 bc().setOK(dialog_->button_ok);
43 bc().setCancel(dialog_->button_close);
45 bc().addReadOnly(dialog_->button_browse);
46 bc().addReadOnly(dialog_->radio_verbatim);
47 bc().addReadOnly(dialog_->check_typeset);
48 bc().addReadOnly(dialog_->radio_useinput);
49 bc().addReadOnly(dialog_->radio_useinclude);
53 void FormInclude::update()
56 // I believe this is not needed.
57 // Anyway, it is plain wrong (JSpitzm 3/7/02)
58 if (controller().params().noload) {
59 fl_set_input(dialog_->input_filename, "");
60 fl_set_button(dialog_->check_typeset, 0);
61 fl_set_button(dialog_->radio_useinput, 0);
62 fl_set_button(dialog_->radio_useinclude, 1);
63 fl_set_button(dialog_->radio_verbatim, 0);
64 fl_set_button(dialog_->check_visiblespace, 0);
65 fl_deactivate_object(dialog_->check_visiblespace);
66 fl_set_object_lcol(dialog_->check_visiblespace, FL_INACTIVE);
71 fl_set_input(dialog_->input_filename,
72 controller().params().cparams.getContents().c_str());
74 string const cmdname = controller().params().cparams.getCmdName();
76 fl_set_button(dialog_->check_typeset,
77 int(controller().params().noload));
79 if (cmdname == "input")
80 fl_set_button(dialog_->check_preview,
81 int(controller().params().cparams.preview()));
83 fl_set_button(dialog_->check_preview, 0);
85 setEnabled(dialog_->check_preview, (cmdname == "input"));
87 fl_set_button(dialog_->radio_useinput, cmdname == "input");
88 fl_set_button(dialog_->radio_useinclude, cmdname == "include");
89 if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") {
90 fl_set_button(dialog_->radio_verbatim, 1);
91 fl_set_button(dialog_->check_visiblespace, cmdname == "verbatiminput*");
92 setEnabled(dialog_->check_visiblespace, true);
93 setEnabled(dialog_->button_load, false);
95 fl_set_button(dialog_->check_visiblespace, 0);
96 setEnabled(dialog_->check_visiblespace, false);
97 setEnabled(dialog_->button_load, true);
101 fl_set_button(dialog_->radio_useinclude, 1);
105 void FormInclude::apply()
107 controller().params().noload = fl_get_button(dialog_->check_typeset);
108 controller().params().cparams
109 .preview(fl_get_button(dialog_->check_preview));
111 string const file = fl_get_input(dialog_->input_filename);
112 if (controller().fileExists(file))
113 controller().params().cparams.setContents(file);
115 controller().params().cparams.setContents("");
117 if (fl_get_button(dialog_->radio_useinput))
118 controller().params().flag = InsetInclude::INPUT;
119 else if (fl_get_button(dialog_->radio_useinclude))
120 controller().params().flag = InsetInclude::INCLUDE;
121 else if (fl_get_button(dialog_->radio_verbatim)) {
122 if (fl_get_button(dialog_->check_visiblespace))
123 controller().params().flag = InsetInclude::VERBAST;
125 controller().params().flag = InsetInclude::VERB;
130 ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
132 ButtonPolicy::SMInput action = ButtonPolicy::SMI_VALID;
134 if (ob == dialog_->button_browse) {
135 ControlInclude::Type type;
136 if (fl_get_button(dialog_->radio_useinput))
137 type = ControlInclude::INPUT;
138 else if (fl_get_button(dialog_->radio_verbatim))
139 type = ControlInclude::VERBATIM;
141 type = ControlInclude::INCLUDE;
143 string const in_name = fl_get_input(dialog_->input_filename);
144 fl_freeze_form(form());
145 string const out_name = controller().Browse(in_name, type);
146 fl_set_input(dialog_->input_filename, out_name.c_str());
147 fl_unfreeze_form(form());
149 } else if (ob == dialog_->button_load) {
150 string const in_name = fl_get_input(dialog_->input_filename);
151 if (!rtrim(in_name).empty() && controller().fileExists(in_name)) {
153 controller().OKButton();
154 controller().load(rtrim(in_name));
155 action = ButtonPolicy::SMI_NOOP;
158 } else if (ob == dialog_->radio_verbatim) {
159 setEnabled(dialog_->check_visiblespace, true);
160 setEnabled(dialog_->button_load, false);
162 } else if (ob == dialog_->radio_useinclude ||
163 ob == dialog_->radio_useinput) {
164 fl_set_button(dialog_->check_visiblespace, 0);
165 setEnabled(dialog_->check_visiblespace, false);
166 setEnabled(dialog_->button_load, true);
168 } else if (ob == dialog_->input_filename) {
169 string const in_name = fl_get_input(dialog_->input_filename);
170 if (rtrim(in_name).empty())
171 action = ButtonPolicy::SMI_INVALID;
174 if (ob == dialog_->radio_useinput) {
175 setEnabled(dialog_->check_preview, true);
176 } else if (ob == dialog_->radio_verbatim ||
177 ob == dialog_->radio_useinclude) {
178 fl_set_button(dialog_->check_preview, 0);
179 setEnabled(dialog_->check_preview, false);