]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormInclude.C
Nothing but a changed email address (trying to factor my tree in in small steps)
[lyx.git] / src / frontends / xforms / FormInclude.C
1 /**
2  * \file FormInclude.C
3  * Copyright 2001 the LyX Team
4  * Read the file COPYING
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author John Levon, moz@compsoc.man.ac.uk
8  * \author Angus Leeming <leeming@lyx.org>
9  */
10
11 #include <config.h>
12 #include <algorithm>
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 #include "xformsBC.h"
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
26
27 typedef FormCB<ControlInclude, FormDB<FD_include> > base_class;
28
29 FormInclude::FormInclude()
30         : base_class(_("Include file"))
31 {}
32
33
34 void FormInclude::build()
35 {
36         dialog_.reset(build_include(this));
37
38         fl_set_input_return(dialog_->input_filename, FL_RETURN_CHANGED);
39         setPrehandler(dialog_->input_filename);
40
41         // Manage the ok and cancel buttons
42         bc().setOK(dialog_->button_ok);
43         bc().setCancel(dialog_->button_close);
44
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);
50 }
51
52
53 void FormInclude::update()
54 {
55         #if 0
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);
67                 return;
68         }
69         #endif
70
71         fl_set_input(dialog_->input_filename,
72                      controller().params().cparams.getContents().c_str());
73
74         string const cmdname = controller().params().cparams.getCmdName();
75
76         fl_set_button(dialog_->check_typeset,
77                       int(controller().params().noload));
78
79         if (cmdname == "input")
80                 fl_set_button(dialog_->check_preview,
81                               int(controller().params().cparams.preview()));
82         else
83                 fl_set_button(dialog_->check_preview, 0);
84
85         setEnabled(dialog_->check_preview, (cmdname == "input"));
86
87         fl_set_button(dialog_->radio_useinput, cmdname == "input");
88         fl_set_button(dialog_->radio_useinclude, cmdname == "include");
89         if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") {
90                 fl_set_button(dialog_->radio_verbatim, 1);
91                 fl_set_button(dialog_->check_visiblespace, cmdname == "verbatiminput*");
92                 setEnabled(dialog_->check_visiblespace, true);
93                 setEnabled(dialog_->button_load, false);
94         } else {
95                 fl_set_button(dialog_->check_visiblespace, 0);
96                 setEnabled(dialog_->check_visiblespace, false);
97                 setEnabled(dialog_->button_load, true);
98         }
99
100         if (cmdname.empty())
101                 fl_set_button(dialog_->radio_useinclude, 1);
102 }
103
104
105 void FormInclude::apply()
106 {
107         controller().params().noload = fl_get_button(dialog_->check_typeset);
108         controller().params().cparams
109                 .preview(fl_get_button(dialog_->check_preview));
110
111         string const file = fl_get_input(dialog_->input_filename);
112         if (controller().fileExists(file))
113                 controller().params().cparams.setContents(file);
114         else
115                 controller().params().cparams.setContents("");
116
117         if (fl_get_button(dialog_->radio_useinput))
118                 controller().params().flag = InsetInclude::INPUT;
119         else if (fl_get_button(dialog_->radio_useinclude))
120                 controller().params().flag = InsetInclude::INCLUDE;
121         else if (fl_get_button(dialog_->radio_verbatim)) {
122                 if (fl_get_button(dialog_->check_visiblespace))
123                         controller().params().flag = InsetInclude::VERBAST;
124                 else
125                         controller().params().flag = InsetInclude::VERB;
126         }
127 }
128
129
130 ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
131 {
132         ButtonPolicy::SMInput action = ButtonPolicy::SMI_VALID;
133
134         if (ob == dialog_->button_browse) {
135                 ControlInclude::Type type;
136                 if (fl_get_button(dialog_->radio_useinput))
137                         type = ControlInclude::INPUT;
138                 else if (fl_get_button(dialog_->radio_verbatim))
139                         type = ControlInclude::VERBATIM;
140                 else
141                         type = ControlInclude::INCLUDE;
142
143                 string const in_name  = fl_get_input(dialog_->input_filename);
144                 fl_freeze_form(form());
145                 string const out_name = controller().Browse(in_name, type);
146                 fl_set_input(dialog_->input_filename, out_name.c_str());
147                 fl_unfreeze_form(form());
148
149         } else if (ob == dialog_->button_load) {
150                 string const in_name = fl_get_input(dialog_->input_filename);
151                 if (!rtrim(in_name).empty() && controller().fileExists(in_name)) {
152 //                      ApplyButton();
153                         controller().OKButton();
154                         controller().load(rtrim(in_name));
155                         action = ButtonPolicy::SMI_NOOP;
156                 }
157
158         } else if (ob == dialog_->radio_verbatim) {
159                 setEnabled(dialog_->check_visiblespace, true);
160                 setEnabled(dialog_->button_load, false);
161
162         } else if (ob == dialog_->radio_useinclude ||
163                    ob == dialog_->radio_useinput) {
164                 fl_set_button(dialog_->check_visiblespace, 0);
165                 setEnabled(dialog_->check_visiblespace, false);
166                 setEnabled(dialog_->button_load, true);
167
168         } else if (ob == dialog_->input_filename) {
169                 string const in_name = fl_get_input(dialog_->input_filename);
170                 if (rtrim(in_name).empty())
171                         action = ButtonPolicy::SMI_INVALID;
172         }
173
174         if (ob == dialog_->radio_useinput) {
175                 setEnabled(dialog_->check_preview, true);
176         } else if (ob == dialog_->radio_verbatim ||
177                    ob == dialog_->radio_useinclude) {
178                 fl_set_button(dialog_->check_preview, 0);
179                 setEnabled(dialog_->check_preview, false);
180         }
181
182         return action;
183 }