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, a.leeming@.ac.uk
15 #pragma implementation
19 #include "ControlInclude.h"
20 #include "FormInclude.h"
21 #include "form_include.h"
22 #include "insets/insetinclude.h"
23 #include "xforms_helpers.h" // setEnabled
24 #include "support/lstrings.h" // strip
26 typedef FormCB<ControlInclude, FormDB<FD_form_include> > base_class;
28 FormInclude::FormInclude(ControlInclude & c)
29 : base_class(c, _("Include file"))
33 void FormInclude::build()
35 dialog_.reset(build_include());
37 fl_set_input_return(dialog_->input_filename, FL_RETURN_CHANGED);
39 // Manage the ok and cancel buttons
40 bc().setOK(dialog_->button_ok);
41 bc().setCancel(dialog_->button_cancel);
43 bc().addReadOnly(dialog_->button_browse);
44 bc().addReadOnly(dialog_->check_verbatim);
45 bc().addReadOnly(dialog_->check_typeset);
46 bc().addReadOnly(dialog_->check_useinput);
47 bc().addReadOnly(dialog_->check_useinclude);
51 void FormInclude::update()
53 if (controller().params().noload) {
54 fl_set_input(dialog_->input_filename, "");
55 fl_set_button(dialog_->check_typeset, 0);
56 fl_set_button(dialog_->check_useinput, 0);
57 fl_set_button(dialog_->check_useinclude, 1);
58 fl_set_button(dialog_->check_verbatim, 0);
59 fl_set_button(dialog_->check_visiblespace, 0);
60 fl_deactivate_object(dialog_->check_visiblespace);
61 fl_set_object_lcol(dialog_->check_visiblespace, FL_INACTIVE);
65 fl_set_input(dialog_->input_filename,
66 controller().params().cparams.getContents().c_str());
68 string const cmdname = controller().params().cparams.getCmdName();
70 fl_set_button(dialog_->check_typeset,
71 int(controller().params().noload));
73 fl_set_button(dialog_->check_useinput, cmdname == "input");
74 fl_set_button(dialog_->check_useinclude, cmdname == "include");
75 if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") {
76 fl_set_button(dialog_->check_verbatim, 1);
77 fl_set_button(dialog_->check_visiblespace, cmdname == "verbatiminput*");
78 setEnabled(dialog_->check_visiblespace, true);
80 fl_set_button(dialog_->check_visiblespace, 0);
81 setEnabled(dialog_->check_visiblespace, false);
85 fl_set_button(dialog_->check_useinclude, 1);
89 void FormInclude::apply()
91 controller().params().noload = fl_get_button(dialog_->check_typeset);
93 string const file = fl_get_input(dialog_->input_filename);
94 if (controller().fileExists(file))
95 controller().params().cparams.setContents(file);
97 controller().params().cparams.setContents("");
99 if (fl_get_button(dialog_->check_useinput))
100 controller().params().flag = InsetInclude::INPUT;
101 else if (fl_get_button(dialog_->check_useinclude))
102 controller().params().flag = InsetInclude::INCLUDE;
103 else if (fl_get_button(dialog_->check_verbatim)) {
104 if (fl_get_button(dialog_->check_visiblespace))
105 controller().params().flag = InsetInclude::VERBAST;
107 controller().params().flag = InsetInclude::VERB;
112 ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
114 ButtonPolicy::SMInput action = ButtonPolicy::SMI_VALID;
116 if (ob == dialog_->button_browse) {
117 ControlInclude::Type type;
118 if (fl_get_button(dialog_->check_useinput))
119 type = ControlInclude::INPUT;
120 else if (fl_get_button(dialog_->check_verbatim))
121 type = ControlInclude::VERBATIM;
123 type = ControlInclude::INCLUDE;
125 string const in_name = fl_get_input(dialog_->input_filename);
126 fl_freeze_form(form());
127 string const out_name = controller().Browse(in_name, type);
128 fl_set_input(dialog_->input_filename, out_name.c_str());
129 fl_unfreeze_form(form());
131 } else if (ob == dialog_->button_load) {
132 string const in_name = fl_get_input(dialog_->input_filename);
133 if (!strip(in_name).empty() && controller().fileExists(in_name)) {
136 controller().load(strip(in_name));
137 action = ButtonPolicy::SMI_NOOP;
140 } else if (ob == dialog_->check_verbatim) {
141 setEnabled(dialog_->check_visiblespace, true);
143 } else if (ob == dialog_->check_useinclude ||
144 ob == dialog_->check_useinput) {
145 fl_set_button(dialog_->check_visiblespace, 0);
146 setEnabled(dialog_->check_visiblespace, false);
148 } else if (ob == dialog_->input_filename) {
149 string const in_name = fl_get_input(dialog_->input_filename);
150 if (strip(in_name).empty())
151 action = ButtonPolicy::SMI_INVALID;