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 controller().params().cparams.
94 setContents(fl_get_input(dialog_->input_filename));
96 if (fl_get_button(dialog_->check_useinput))
97 controller().params().flag = InsetInclude::INPUT;
98 else if (fl_get_button(dialog_->check_useinclude))
99 controller().params().flag = InsetInclude::INCLUDE;
100 else if (fl_get_button(dialog_->check_verbatim)) {
101 if (fl_get_button(dialog_->check_visiblespace))
102 controller().params().flag = InsetInclude::VERBAST;
104 controller().params().flag = InsetInclude::VERB;
109 ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
111 ButtonPolicy::SMInput action = ButtonPolicy::SMI_VALID;
113 if (ob == dialog_->button_browse) {
114 ControlInclude::Type type;
115 if (fl_get_button(dialog_->check_useinput))
116 type = ControlInclude::INPUT;
117 else if (fl_get_button(dialog_->check_verbatim))
118 type = ControlInclude::VERBATIM;
120 type = ControlInclude::INCLUDE;
122 string const in_name = fl_get_input(dialog_->input_filename);
123 fl_freeze_form(form());
124 string const out_name = controller().Browse(in_name, type);
125 fl_set_input(dialog_->input_filename, out_name.c_str());
126 fl_unfreeze_form(form());
128 } else if (ob == dialog_->button_load) {
129 string const in_name = fl_get_input(dialog_->input_filename);
130 if (!strip(in_name).empty()) {
132 controller().load(strip(in_name));
133 action = ButtonPolicy::SMI_NOOP;
136 } else if (ob == dialog_->check_verbatim) {
137 setEnabled(dialog_->check_visiblespace, true);
139 } else if (ob == dialog_->check_useinclude ||
140 ob == dialog_->check_useinput) {
141 fl_set_button(dialog_->check_visiblespace, 0);
142 setEnabled(dialog_->check_visiblespace, false);
144 } else if (ob == dialog_->input_filename) {
145 string const in_name = fl_get_input(dialog_->input_filename);
146 if (strip(in_name).empty())
147 action = ButtonPolicy::SMI_INVALID;