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@ic.ac.uk
15 #pragma implementation
19 #include "ControlInclude.h"
20 #include "FormInclude.h"
21 #include "forms/form_include.h"
22 #include "insets/insetinclude.h"
23 #include "xforms_helpers.h" // setEnabled
24 #include "support/lstrings.h" // strip
25 #include FORMS_H_LOCATION
27 typedef FormCB<ControlInclude, FormDB<FD_include> > base_class;
29 FormInclude::FormInclude(ControlInclude & c, Dialogs & d)
30 : base_class(c, d, _("Include file"))
34 void FormInclude::build()
36 dialog_.reset(build_include(this));
38 fl_set_input_return(dialog_->input_filename, FL_RETURN_CHANGED);
39 setPrehandler(dialog_->input_filename);
41 // Manage the ok and cancel buttons
42 bc().setOK(dialog_->button_ok);
43 bc().setCancel(dialog_->button_close);
45 bc().addReadOnly(dialog_->button_browse);
46 bc().addReadOnly(dialog_->radio_verbatim);
47 bc().addReadOnly(dialog_->check_typeset);
48 bc().addReadOnly(dialog_->radio_useinput);
49 bc().addReadOnly(dialog_->radio_useinclude);
53 void FormInclude::update()
56 // I believe this is not needed.
57 // Anyway, it is plain wrong (JSpitzm 3/7/02)
58 if (controller().params().noload) {
59 fl_set_input(dialog_->input_filename, "");
60 fl_set_button(dialog_->check_typeset, 0);
61 fl_set_button(dialog_->radio_useinput, 0);
62 fl_set_button(dialog_->radio_useinclude, 1);
63 fl_set_button(dialog_->radio_verbatim, 0);
64 fl_set_button(dialog_->check_visiblespace, 0);
65 fl_deactivate_object(dialog_->check_visiblespace);
66 fl_set_object_lcol(dialog_->check_visiblespace, FL_INACTIVE);
71 fl_set_input(dialog_->input_filename,
72 controller().params().cparams.getContents().c_str());
74 string const cmdname = controller().params().cparams.getCmdName();
76 fl_set_button(dialog_->check_typeset,
77 int(controller().params().noload));
79 fl_set_button(dialog_->radio_useinput, cmdname == "input");
80 fl_set_button(dialog_->radio_useinclude, cmdname == "include");
81 if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") {
82 fl_set_button(dialog_->radio_verbatim, 1);
83 fl_set_button(dialog_->check_visiblespace, cmdname == "verbatiminput*");
84 setEnabled(dialog_->check_visiblespace, true);
85 setEnabled(dialog_->button_load, false);
87 fl_set_button(dialog_->check_visiblespace, 0);
88 setEnabled(dialog_->check_visiblespace, false);
89 setEnabled(dialog_->button_load, true);
93 fl_set_button(dialog_->radio_useinclude, 1);
97 void FormInclude::apply()
99 controller().params().noload = fl_get_button(dialog_->check_typeset);
101 string const file = fl_get_input(dialog_->input_filename);
102 if (controller().fileExists(file))
103 controller().params().cparams.setContents(file);
105 controller().params().cparams.setContents("");
107 if (fl_get_button(dialog_->radio_useinput))
108 controller().params().flag = InsetInclude::INPUT;
109 else if (fl_get_button(dialog_->radio_useinclude))
110 controller().params().flag = InsetInclude::INCLUDE;
111 else if (fl_get_button(dialog_->radio_verbatim)) {
112 if (fl_get_button(dialog_->check_visiblespace))
113 controller().params().flag = InsetInclude::VERBAST;
115 controller().params().flag = InsetInclude::VERB;
120 ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
122 ButtonPolicy::SMInput action = ButtonPolicy::SMI_VALID;
124 if (ob == dialog_->button_browse) {
125 ControlInclude::Type type;
126 if (fl_get_button(dialog_->radio_useinput))
127 type = ControlInclude::INPUT;
128 else if (fl_get_button(dialog_->radio_verbatim))
129 type = ControlInclude::VERBATIM;
131 type = ControlInclude::INCLUDE;
133 string const in_name = fl_get_input(dialog_->input_filename);
134 fl_freeze_form(form());
135 string const out_name = controller().Browse(in_name, type);
136 fl_set_input(dialog_->input_filename, out_name.c_str());
137 fl_unfreeze_form(form());
139 } else if (ob == dialog_->button_load) {
140 string const in_name = fl_get_input(dialog_->input_filename);
141 if (!strip(in_name).empty() && controller().fileExists(in_name)) {
144 controller().load(strip(in_name));
145 action = ButtonPolicy::SMI_NOOP;
148 } else if (ob == dialog_->radio_verbatim) {
149 setEnabled(dialog_->check_visiblespace, true);
150 setEnabled(dialog_->button_load, false);
152 } else if (ob == dialog_->radio_useinclude ||
153 ob == dialog_->radio_useinput) {
154 fl_set_button(dialog_->check_visiblespace, 0);
155 setEnabled(dialog_->check_visiblespace, false);
156 setEnabled(dialog_->button_load, true);
158 } else if (ob == dialog_->input_filename) {
159 string const in_name = fl_get_input(dialog_->input_filename);
160 if (strip(in_name).empty())
161 action = ButtonPolicy::SMI_INVALID;