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
23 #include "ControlInclude.h"
24 #include "FormInclude.h"
25 #include "forms/form_include.h"
26 #include "insets/insetinclude.h"
27 #include "xforms_helpers.h" // setEnabled
28 #include "support/lstrings.h" // strip
29 #include FORMS_H_LOCATION
31 typedef FormCB<ControlInclude, FormDB<FD_include> > base_class;
33 FormInclude::FormInclude()
34 : base_class(_("Include file"))
38 void FormInclude::build()
40 dialog_.reset(build_include(this));
42 fl_set_input_return(dialog_->input_filename, FL_RETURN_CHANGED);
43 setPrehandler(dialog_->input_filename);
45 // Manage the ok and cancel buttons
46 bc().setOK(dialog_->button_ok);
47 bc().setCancel(dialog_->button_close);
49 bc().addReadOnly(dialog_->button_browse);
50 bc().addReadOnly(dialog_->radio_verbatim);
51 bc().addReadOnly(dialog_->radio_useinput);
52 bc().addReadOnly(dialog_->radio_useinclude);
56 void FormInclude::update()
58 fl_set_input(dialog_->input_filename,
59 controller().params().cparams.getContents().c_str());
61 string const cmdname = controller().params().cparams.getCmdName();
63 if (cmdname == "input")
64 fl_set_button(dialog_->check_preview,
65 int(controller().params().cparams.preview()));
67 fl_set_button(dialog_->check_preview, 0);
69 setEnabled(dialog_->check_preview, (cmdname == "input"));
71 fl_set_button(dialog_->radio_useinput, cmdname == "input");
72 fl_set_button(dialog_->radio_useinclude, cmdname == "include");
73 if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") {
74 fl_set_button(dialog_->radio_verbatim, 1);
75 fl_set_button(dialog_->check_visiblespace, cmdname == "verbatiminput*");
76 setEnabled(dialog_->check_visiblespace, true);
77 setEnabled(dialog_->button_load, false);
79 fl_set_button(dialog_->check_visiblespace, 0);
80 setEnabled(dialog_->check_visiblespace, false);
81 setEnabled(dialog_->button_load, true);
85 fl_set_button(dialog_->radio_useinclude, 1);
89 void FormInclude::apply()
91 controller().params().cparams
92 .preview(fl_get_button(dialog_->check_preview));
94 string const file = fl_get_input(dialog_->input_filename);
95 if (controller().fileExists(file))
96 controller().params().cparams.setContents(file);
98 controller().params().cparams.setContents("");
100 if (fl_get_button(dialog_->radio_useinput))
101 controller().params().flag = InsetInclude::INPUT;
102 else if (fl_get_button(dialog_->radio_useinclude))
103 controller().params().flag = InsetInclude::INCLUDE;
104 else if (fl_get_button(dialog_->radio_verbatim)) {
105 if (fl_get_button(dialog_->check_visiblespace))
106 controller().params().flag = InsetInclude::VERBAST;
108 controller().params().flag = InsetInclude::VERB;
113 ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
115 ButtonPolicy::SMInput action = ButtonPolicy::SMI_VALID;
117 if (ob == dialog_->button_browse) {
118 ControlInclude::Type type;
119 if (fl_get_button(dialog_->radio_useinput))
120 type = ControlInclude::INPUT;
121 else if (fl_get_button(dialog_->radio_verbatim))
122 type = ControlInclude::VERBATIM;
124 type = ControlInclude::INCLUDE;
126 string const in_name = fl_get_input(dialog_->input_filename);
127 fl_freeze_form(form());
128 string const out_name = controller().Browse(in_name, type);
129 fl_set_input(dialog_->input_filename, out_name.c_str());
130 fl_unfreeze_form(form());
132 } else if (ob == dialog_->button_load) {
133 string const in_name = fl_get_input(dialog_->input_filename);
134 if (!rtrim(in_name).empty() && controller().fileExists(in_name)) {
135 controller().OKButton();
136 controller().load(rtrim(in_name));
137 action = ButtonPolicy::SMI_NOOP;
140 } else if (ob == dialog_->radio_verbatim) {
141 setEnabled(dialog_->check_visiblespace, true);
142 setEnabled(dialog_->button_load, false);
144 } else if (ob == dialog_->radio_useinclude ||
145 ob == dialog_->radio_useinput) {
146 fl_set_button(dialog_->check_visiblespace, 0);
147 setEnabled(dialog_->check_visiblespace, false);
148 setEnabled(dialog_->button_load, true);
150 } else if (ob == dialog_->input_filename) {
151 string const in_name = fl_get_input(dialog_->input_filename);
152 if (rtrim(in_name).empty())
153 action = ButtonPolicy::SMI_INVALID;
156 if (ob == dialog_->radio_useinput) {
157 setEnabled(dialog_->check_preview, true);
158 } else if (ob == dialog_->radio_verbatim ||
159 ob == dialog_->radio_useinclude) {
160 fl_set_button(dialog_->check_preview, 0);
161 setEnabled(dialog_->check_preview, false);