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);
41 bc().addReadOnly(dialog_->button_browse);
42 bc().addReadOnly(dialog_->check_verbatim);
43 bc().addReadOnly(dialog_->check_typeset);
44 bc().addReadOnly(dialog_->check_useinput);
45 bc().addReadOnly(dialog_->check_useinclude);
49 void FormInclude::update()
51 if (controller().params().noload) {
52 fl_set_input(dialog_->input_filename, "");
53 fl_set_button(dialog_->check_typeset, 0);
54 fl_set_button(dialog_->check_useinput, 0);
55 fl_set_button(dialog_->check_useinclude, 1);
56 fl_set_button(dialog_->check_verbatim, 0);
57 fl_set_button(dialog_->check_visiblespace, 0);
58 fl_deactivate_object(dialog_->check_visiblespace);
59 fl_set_object_lcol(dialog_->check_visiblespace, FL_INACTIVE);
63 fl_set_input(dialog_->input_filename,
64 controller().params().cparams.getContents().c_str());
66 string const cmdname = controller().params().cparams.getCmdName();
68 fl_set_button(dialog_->check_typeset,
69 int(controller().params().noload));
71 fl_set_button(dialog_->check_useinput, cmdname == "input");
72 fl_set_button(dialog_->check_useinclude, cmdname == "include");
73 if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") {
74 fl_set_button(dialog_->check_verbatim, 1);
75 fl_set_button(dialog_->check_visiblespace, cmdname == "verbatiminput*");
76 setEnabled(dialog_->check_visiblespace, true);
78 fl_set_button(dialog_->check_visiblespace, 0);
79 setEnabled(dialog_->check_visiblespace, false);
83 fl_set_button(dialog_->check_useinclude, 1);
87 void FormInclude::apply()
89 controller().params().noload = fl_get_button(dialog_->check_typeset);
91 controller().params().cparams.
92 setContents(fl_get_input(dialog_->input_filename));
94 if (fl_get_button(dialog_->check_useinput))
95 controller().params().flag = InsetInclude::INPUT;
96 else if (fl_get_button(dialog_->check_useinclude))
97 controller().params().flag = InsetInclude::INCLUDE;
98 else if (fl_get_button(dialog_->check_verbatim)) {
99 if (fl_get_button(dialog_->check_visiblespace))
100 controller().params().flag = InsetInclude::VERBAST;
102 controller().params().flag = InsetInclude::VERB;
107 ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
109 if (ob == dialog_->button_browse) {
110 ControlInclude::Type type;
111 if (fl_get_button(dialog_->check_useinput))
112 type = ControlInclude::INPUT;
113 else if (fl_get_button(dialog_->check_verbatim))
114 type = ControlInclude::VERBATIM;
116 type = ControlInclude::INCLUDE;
118 string const in_name = fl_get_input(dialog_->input_filename);
119 fl_freeze_form(form());
120 string const out_name = controller().Browse(in_name, type);
121 fl_set_input(dialog_->input_filename, out_name.c_str());
122 fl_unfreeze_form(form());
124 return ButtonPolicy::SMI_VALID;
127 if (ob == dialog_->button_load) {
128 if (compare(fl_get_input(dialog_->input_filename),"")) {
130 return ButtonPolicy::SMI_NOOP;
134 if (ob == dialog_->check_verbatim) {
135 setEnabled(dialog_->check_visiblespace, true);
137 } else if (ob == dialog_->check_useinclude ||
138 ob == dialog_->check_useinput) {
139 fl_set_button(dialog_->check_visiblespace, 0);
140 setEnabled(dialog_->check_visiblespace, false);
143 return ButtonPolicy::SMI_VALID;