4 * Copyright 2001 the LyX Team
5 * Read the file COPYING
7 * \author Alejandro Aguilar Sierra
8 * \author John Levon, moz@compsoc.man.ac.uk
9 * \author Angus Leeming, a.leeming@.ac.uk
16 #pragma implementation
20 #include "ControlInclude.h"
21 #include "FormInclude.h"
22 #include "form_include.h"
23 #include "insets/insetinclude.h"
24 #include "xforms_helpers.h" // setEnabled
25 #include "support/lstrings.h" // strip
27 typedef FormCB<ControlInclude, FormDB<FD_form_include> > base_class;
29 FormInclude::FormInclude(ControlInclude & c)
30 : base_class(c, _("Include file"))
34 void FormInclude::build()
36 dialog_.reset(build_include());
38 fl_set_input_return(dialog_->input_filename, FL_RETURN_CHANGED);
40 // Manage the ok and cancel buttons
41 bc().setOK(dialog_->button_ok);
42 bc().setCancel(dialog_->button_cancel);
44 bc().addReadOnly(dialog_->button_browse);
45 bc().addReadOnly(dialog_->check_verbatim);
46 bc().addReadOnly(dialog_->check_typeset);
47 bc().addReadOnly(dialog_->check_useinput);
48 bc().addReadOnly(dialog_->check_useinclude);
52 void FormInclude::update()
54 if (controller().params().noload) {
55 fl_set_input(dialog_->input_filename, "");
56 fl_set_button(dialog_->check_typeset, 0);
57 fl_set_button(dialog_->check_useinput, 0);
58 fl_set_button(dialog_->check_useinclude, 1);
59 fl_set_button(dialog_->check_verbatim, 0);
60 fl_set_button(dialog_->check_visiblespace, 0);
61 fl_deactivate_object(dialog_->check_visiblespace);
62 fl_set_object_lcol(dialog_->check_visiblespace, FL_INACTIVE);
66 fl_set_input(dialog_->input_filename,
67 controller().params().cparams.getContents().c_str());
69 string const cmdname = controller().params().cparams.getCmdName();
71 fl_set_button(dialog_->check_typeset,
72 int(controller().params().noload));
74 fl_set_button(dialog_->check_useinput, cmdname == "input");
75 fl_set_button(dialog_->check_useinclude, cmdname == "include");
76 if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") {
77 fl_set_button(dialog_->check_verbatim, 1);
78 fl_set_button(dialog_->check_visiblespace, cmdname == "verbatiminput*");
79 setEnabled(dialog_->check_visiblespace, true);
81 fl_set_button(dialog_->check_visiblespace, 0);
82 setEnabled(dialog_->check_visiblespace, false);
86 fl_set_button(dialog_->check_useinclude, 1);
90 void FormInclude::apply()
92 controller().params().noload = fl_get_button(dialog_->check_typeset);
94 controller().params().cparams.
95 setContents(fl_get_input(dialog_->input_filename));
97 if (fl_get_button(dialog_->check_useinput))
98 controller().params().flag = InsetInclude::INPUT;
99 else if (fl_get_button(dialog_->check_useinclude))
100 controller().params().flag = InsetInclude::INCLUDE;
101 else if (fl_get_button(dialog_->check_verbatim)) {
102 if (fl_get_button(dialog_->check_visiblespace))
103 controller().params().flag = InsetInclude::VERBAST;
105 controller().params().flag = InsetInclude::VERB;
110 ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
112 ButtonPolicy::SMInput action = ButtonPolicy::SMI_VALID;
114 if (ob == dialog_->button_browse) {
115 ControlInclude::Type type;
116 if (fl_get_button(dialog_->check_useinput))
117 type = ControlInclude::INPUT;
118 else if (fl_get_button(dialog_->check_verbatim))
119 type = ControlInclude::VERBATIM;
121 type = ControlInclude::INCLUDE;
123 string const in_name = fl_get_input(dialog_->input_filename);
124 fl_freeze_form(form());
125 string const out_name = controller().Browse(in_name, type);
126 fl_set_input(dialog_->input_filename, out_name.c_str());
127 fl_unfreeze_form(form());
129 } else if (ob == dialog_->button_load) {
130 string const in_name = fl_get_input(dialog_->input_filename);
131 if (!strip(in_name).empty()) {
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;