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
20 #include "ControlInclude.h"
21 #include "FormInclude.h"
22 #include "forms/form_include.h"
23 #include "insets/insetinclude.h"
24 #include "xforms_helpers.h" // setEnabled
25 #include "support/lstrings.h" // strip
26 #include FORMS_H_LOCATION
28 typedef FormCB<ControlInclude, FormDB<FD_include> > base_class;
30 FormInclude::FormInclude()
31 : base_class(_("Include file"))
35 void FormInclude::build()
37 dialog_.reset(build_include(this));
39 fl_set_input_return(dialog_->input_filename, FL_RETURN_CHANGED);
40 setPrehandler(dialog_->input_filename);
42 // Manage the ok and cancel buttons
43 bc().setOK(dialog_->button_ok);
44 bc().setCancel(dialog_->button_close);
46 bc().addReadOnly(dialog_->button_browse);
47 bc().addReadOnly(dialog_->radio_verbatim);
48 bc().addReadOnly(dialog_->radio_useinput);
49 bc().addReadOnly(dialog_->radio_useinclude);
53 void FormInclude::update()
55 fl_set_input(dialog_->input_filename,
56 controller().params().cparams.getContents().c_str());
58 string const cmdname = controller().params().cparams.getCmdName();
60 if (cmdname == "input")
61 fl_set_button(dialog_->check_preview,
62 int(controller().params().cparams.preview()));
64 fl_set_button(dialog_->check_preview, 0);
66 setEnabled(dialog_->check_preview, (cmdname == "input"));
68 fl_set_button(dialog_->radio_useinput, cmdname == "input");
69 fl_set_button(dialog_->radio_useinclude, cmdname == "include");
70 if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") {
71 fl_set_button(dialog_->radio_verbatim, 1);
72 fl_set_button(dialog_->check_visiblespace, cmdname == "verbatiminput*");
73 setEnabled(dialog_->check_visiblespace, true);
74 setEnabled(dialog_->button_load, false);
76 fl_set_button(dialog_->check_visiblespace, 0);
77 setEnabled(dialog_->check_visiblespace, false);
78 setEnabled(dialog_->button_load, true);
82 fl_set_button(dialog_->radio_useinclude, 1);
86 void FormInclude::apply()
88 controller().params().cparams
89 .preview(fl_get_button(dialog_->check_preview));
91 string const file = fl_get_input(dialog_->input_filename);
92 if (controller().fileExists(file))
93 controller().params().cparams.setContents(file);
95 controller().params().cparams.setContents("");
97 if (fl_get_button(dialog_->radio_useinput))
98 controller().params().flag = InsetInclude::INPUT;
99 else if (fl_get_button(dialog_->radio_useinclude))
100 controller().params().flag = InsetInclude::INCLUDE;
101 else if (fl_get_button(dialog_->radio_verbatim)) {
102 if (fl_get_button(dialog_->check_visiblespace))
103 controller().params().flag = InsetInclude::VERBAST;
105 controller().params().flag = InsetInclude::VERB;
110 ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
112 ButtonPolicy::SMInput action = ButtonPolicy::SMI_VALID;
114 if (ob == dialog_->button_browse) {
115 ControlInclude::Type type;
116 if (fl_get_button(dialog_->radio_useinput))
117 type = ControlInclude::INPUT;
118 else if (fl_get_button(dialog_->radio_verbatim))
119 type = ControlInclude::VERBATIM;
121 type = ControlInclude::INCLUDE;
123 string const in_name = fl_get_input(dialog_->input_filename);
124 fl_freeze_form(form());
125 string const out_name = controller().Browse(in_name, type);
126 fl_set_input(dialog_->input_filename, out_name.c_str());
127 fl_unfreeze_form(form());
129 } else if (ob == dialog_->button_load) {
130 string const in_name = fl_get_input(dialog_->input_filename);
131 if (!rtrim(in_name).empty() && controller().fileExists(in_name)) {
132 controller().OKButton();
133 controller().load(rtrim(in_name));
134 action = ButtonPolicy::SMI_NOOP;
137 } else if (ob == dialog_->radio_verbatim) {
138 setEnabled(dialog_->check_visiblespace, true);
139 setEnabled(dialog_->button_load, false);
141 } else if (ob == dialog_->radio_useinclude ||
142 ob == dialog_->radio_useinput) {
143 fl_set_button(dialog_->check_visiblespace, 0);
144 setEnabled(dialog_->check_visiblespace, false);
145 setEnabled(dialog_->button_load, true);
147 } else if (ob == dialog_->input_filename) {
148 string const in_name = fl_get_input(dialog_->input_filename);
149 if (rtrim(in_name).empty())
150 action = ButtonPolicy::SMI_INVALID;
153 if (ob == dialog_->radio_useinput) {
154 setEnabled(dialog_->check_preview, true);
155 } else if (ob == dialog_->radio_verbatim ||
156 ob == dialog_->radio_useinclude) {
157 fl_set_button(dialog_->check_preview, 0);
158 setEnabled(dialog_->check_preview, false);