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 lyxerr << cmdname << endl;
64 if (cmdname == "input")
65 fl_set_button(dialog_->check_preview,
66 int(controller().params().cparams.preview()));
68 fl_set_button(dialog_->check_preview, 0);
70 setEnabled(dialog_->check_preview, (cmdname == "input"));
72 fl_set_button(dialog_->radio_useinput, cmdname == "input");
73 fl_set_button(dialog_->radio_useinclude, cmdname == "include");
74 if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") {
75 fl_set_button(dialog_->radio_verbatim, 1);
76 fl_set_button(dialog_->check_visiblespace, cmdname == "verbatiminput*");
77 setEnabled(dialog_->check_visiblespace, true);
78 setEnabled(dialog_->button_load, false);
80 fl_set_button(dialog_->check_visiblespace, 0);
81 setEnabled(dialog_->check_visiblespace, false);
82 setEnabled(dialog_->button_load, true);
86 fl_set_button(dialog_->radio_useinclude, 1);
90 void FormInclude::apply()
92 controller().params().cparams
93 .preview(fl_get_button(dialog_->check_preview));
95 string const file = fl_get_input(dialog_->input_filename);
96 if (controller().fileExists(file))
97 controller().params().cparams.setContents(file);
99 controller().params().cparams.setContents("");
101 if (fl_get_button(dialog_->radio_useinput))
102 controller().params().flag = InsetInclude::INPUT;
103 else if (fl_get_button(dialog_->radio_useinclude))
104 controller().params().flag = InsetInclude::INCLUDE;
105 else if (fl_get_button(dialog_->radio_verbatim)) {
106 if (fl_get_button(dialog_->check_visiblespace))
107 controller().params().flag = InsetInclude::VERBAST;
109 controller().params().flag = InsetInclude::VERB;
114 ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
116 ButtonPolicy::SMInput action = ButtonPolicy::SMI_VALID;
118 if (ob == dialog_->button_browse) {
119 ControlInclude::Type type;
120 if (fl_get_button(dialog_->radio_useinput))
121 type = ControlInclude::INPUT;
122 else if (fl_get_button(dialog_->radio_verbatim))
123 type = ControlInclude::VERBATIM;
125 type = ControlInclude::INCLUDE;
127 string const in_name = fl_get_input(dialog_->input_filename);
128 fl_freeze_form(form());
129 string const out_name = controller().Browse(in_name, type);
130 fl_set_input(dialog_->input_filename, out_name.c_str());
131 fl_unfreeze_form(form());
133 } else if (ob == dialog_->button_load) {
134 string const in_name = fl_get_input(dialog_->input_filename);
135 if (!rtrim(in_name).empty() && controller().fileExists(in_name)) {
136 controller().OKButton();
137 controller().load(rtrim(in_name));
138 action = ButtonPolicy::SMI_NOOP;
141 } else if (ob == dialog_->radio_verbatim) {
142 setEnabled(dialog_->check_visiblespace, true);
143 setEnabled(dialog_->button_load, false);
145 } else if (ob == dialog_->radio_useinclude ||
146 ob == dialog_->radio_useinput) {
147 fl_set_button(dialog_->check_visiblespace, 0);
148 setEnabled(dialog_->check_visiblespace, false);
149 setEnabled(dialog_->button_load, true);
151 } else if (ob == dialog_->input_filename) {
152 string const in_name = fl_get_input(dialog_->input_filename);
153 if (rtrim(in_name).empty())
154 action = ButtonPolicy::SMI_INVALID;
157 if (ob == dialog_->radio_useinput) {
158 setEnabled(dialog_->check_preview, true);
159 } else if (ob == dialog_->radio_verbatim ||
160 ob == dialog_->radio_useinclude) {
161 fl_set_button(dialog_->check_preview, 0);
162 setEnabled(dialog_->check_preview, false);