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" // compare
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 // Manage the ok and cancel buttons
38 bc().setOK(dialog_->button_ok);
39 bc().setCancel(dialog_->button_cancel);
42 bc().addReadOnly(dialog_->button_browse);
43 bc().addReadOnly(dialog_->check_verbatim);
44 bc().addReadOnly(dialog_->check_typeset);
45 bc().addReadOnly(dialog_->check_useinput);
46 bc().addReadOnly(dialog_->check_useinclude);
50 void FormInclude::update()
52 if (controller().params().noload) {
53 fl_set_input(dialog_->input_filename, "");
54 fl_set_button(dialog_->check_typeset, 0);
55 fl_set_button(dialog_->check_useinput, 0);
56 fl_set_button(dialog_->check_useinclude, 1);
57 fl_set_button(dialog_->check_verbatim, 0);
58 fl_set_button(dialog_->check_visiblespace, 0);
59 fl_deactivate_object(dialog_->check_visiblespace);
60 fl_set_object_lcol(dialog_->check_visiblespace, FL_INACTIVE);
64 fl_set_input(dialog_->input_filename,
65 controller().params().cparams.getContents().c_str());
67 string const cmdname = controller().params().cparams.getCmdName();
69 fl_set_button(dialog_->check_typeset,
70 int(controller().params().noload));
72 fl_set_button(dialog_->check_useinput, cmdname == "input");
73 fl_set_button(dialog_->check_useinclude, cmdname == "include");
74 if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") {
75 fl_set_button(dialog_->check_verbatim, 1);
76 fl_set_button(dialog_->check_visiblespace, cmdname == "verbatiminput*");
77 setEnabled(dialog_->check_visiblespace, true);
79 fl_set_button(dialog_->check_visiblespace, 0);
80 setEnabled(dialog_->check_visiblespace, false);
84 fl_set_button(dialog_->check_useinclude, 1);
88 void FormInclude::apply()
90 controller().params().noload = fl_get_button(dialog_->check_typeset);
92 controller().params().cparams.
93 setContents(fl_get_input(dialog_->input_filename));
95 if (fl_get_button(dialog_->check_useinput))
96 controller().params().flag = InsetInclude::INPUT;
97 else if (fl_get_button(dialog_->check_useinclude))
98 controller().params().flag = InsetInclude::INCLUDE;
99 else if (fl_get_button(dialog_->check_verbatim)) {
100 if (fl_get_button(dialog_->check_visiblespace))
101 controller().params().flag = InsetInclude::VERBAST;
103 controller().params().flag = InsetInclude::VERB;
108 ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
110 if (ob == dialog_->button_browse) {
111 ControlInclude::Type type;
112 if (fl_get_button(dialog_->check_useinput))
113 type = ControlInclude::INPUT;
114 else if (fl_get_button(dialog_->check_verbatim))
115 type = ControlInclude::VERBATIM;
117 type = ControlInclude::INCLUDE;
119 string const in_name = fl_get_input(dialog_->input_filename);
120 fl_freeze_form(form());
121 string const out_name = controller().Browse(in_name, type);
122 fl_set_input(dialog_->input_filename, out_name.c_str());
123 fl_unfreeze_form(form());
125 return ButtonPolicy::SMI_VALID;
128 if (ob == dialog_->button_load) {
129 if (compare(fl_get_input(dialog_->input_filename),"")) {
131 return ButtonPolicy::SMI_NOOP;
135 if (ob == dialog_->check_verbatim) {
136 setEnabled(dialog_->check_visiblespace, true);
138 } else if (ob == dialog_->check_useinclude ||
139 ob == dialog_->check_useinput) {
140 fl_set_button(dialog_->check_visiblespace, 0);
141 setEnabled(dialog_->check_visiblespace, false);
144 return ButtonPolicy::SMI_VALID;