]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormInclude.C
dont use pragma impementation and interface anymore
[lyx.git] / src / frontends / xforms / FormInclude.C
1 /**
2  * \file FormInclude.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author John Levon
8  * \author Angus Leeming
9  *
10  * Full author contact details are available in file CREDITS
11  */
12
13 #include <config.h>
14 #include <algorithm>
15
16
17 #include "debug.h"
18
19 #include "xformsBC.h"
20 #include "ControlInclude.h"
21 #include "FormInclude.h"
22 #include "forms/form_include.h"
23 #include "insets/insetinclude.h"
24 #include "xforms_helpers.h" // setEnabled
25 #include "support/lstrings.h" // strip
26 #include FORMS_H_LOCATION
27
28 typedef FormCB<ControlInclude, FormDB<FD_include> > base_class;
29
30 FormInclude::FormInclude()
31         : base_class(_("Include file"))
32 {}
33
34
35 void FormInclude::build()
36 {
37         dialog_.reset(build_include(this));
38
39         fl_set_input_return(dialog_->input_filename, FL_RETURN_CHANGED);
40         setPrehandler(dialog_->input_filename);
41
42         // Manage the ok and cancel buttons
43         bc().setOK(dialog_->button_ok);
44         bc().setCancel(dialog_->button_close);
45
46         bc().addReadOnly(dialog_->button_browse);
47         bc().addReadOnly(dialog_->radio_verbatim);
48         bc().addReadOnly(dialog_->radio_useinput);
49         bc().addReadOnly(dialog_->radio_useinclude);
50 }
51
52
53 void FormInclude::update()
54 {
55         fl_set_input(dialog_->input_filename,
56                      controller().params().cparams.getContents().c_str());
57
58         string const cmdname = controller().params().cparams.getCmdName();
59
60         if (cmdname == "input")
61                 fl_set_button(dialog_->check_preview,
62                               int(controller().params().cparams.preview()));
63         else
64                 fl_set_button(dialog_->check_preview, 0);
65
66         setEnabled(dialog_->check_preview, (cmdname == "input"));
67
68         fl_set_button(dialog_->radio_useinput, cmdname == "input");
69         fl_set_button(dialog_->radio_useinclude, cmdname == "include");
70         if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") {
71                 fl_set_button(dialog_->radio_verbatim, 1);
72                 fl_set_button(dialog_->check_visiblespace, cmdname == "verbatiminput*");
73                 setEnabled(dialog_->check_visiblespace, true);
74                 setEnabled(dialog_->button_load, false);
75         } else {
76                 fl_set_button(dialog_->check_visiblespace, 0);
77                 setEnabled(dialog_->check_visiblespace, false);
78                 setEnabled(dialog_->button_load, true);
79         }
80
81         if (cmdname.empty())
82                 fl_set_button(dialog_->radio_useinclude, 1);
83 }
84
85
86 void FormInclude::apply()
87 {
88         controller().params().cparams
89                 .preview(fl_get_button(dialog_->check_preview));
90
91         string const file = fl_get_input(dialog_->input_filename);
92         if (controller().fileExists(file))
93                 controller().params().cparams.setContents(file);
94         else
95                 controller().params().cparams.setContents("");
96
97         if (fl_get_button(dialog_->radio_useinput))
98                 controller().params().flag = InsetInclude::INPUT;
99         else if (fl_get_button(dialog_->radio_useinclude))
100                 controller().params().flag = InsetInclude::INCLUDE;
101         else if (fl_get_button(dialog_->radio_verbatim)) {
102                 if (fl_get_button(dialog_->check_visiblespace))
103                         controller().params().flag = InsetInclude::VERBAST;
104                 else
105                         controller().params().flag = InsetInclude::VERB;
106         }
107 }
108
109
110 ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
111 {
112         ButtonPolicy::SMInput action = ButtonPolicy::SMI_VALID;
113
114         if (ob == dialog_->button_browse) {
115                 ControlInclude::Type type;
116                 if (fl_get_button(dialog_->radio_useinput))
117                         type = ControlInclude::INPUT;
118                 else if (fl_get_button(dialog_->radio_verbatim))
119                         type = ControlInclude::VERBATIM;
120                 else
121                         type = ControlInclude::INCLUDE;
122
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());
128
129         } else if (ob == dialog_->button_load) {
130                 string const in_name = fl_get_input(dialog_->input_filename);
131                 if (!rtrim(in_name).empty() && controller().fileExists(in_name)) {
132                         controller().OKButton();
133                         controller().load(rtrim(in_name));
134                         action = ButtonPolicy::SMI_NOOP;
135                 }
136
137         } else if (ob == dialog_->radio_verbatim) {
138                 setEnabled(dialog_->check_visiblespace, true);
139                 setEnabled(dialog_->button_load, false);
140
141         } else if (ob == dialog_->radio_useinclude ||
142                    ob == dialog_->radio_useinput) {
143                 fl_set_button(dialog_->check_visiblespace, 0);
144                 setEnabled(dialog_->check_visiblespace, false);
145                 setEnabled(dialog_->button_load, true);
146
147         } else if (ob == dialog_->input_filename) {
148                 string const in_name = fl_get_input(dialog_->input_filename);
149                 if (rtrim(in_name).empty())
150                         action = ButtonPolicy::SMI_INVALID;
151         }
152
153         if (ob == dialog_->radio_useinput) {
154                 setEnabled(dialog_->check_preview, true);
155         } else if (ob == dialog_->radio_verbatim ||
156                    ob == dialog_->radio_useinclude) {
157                 fl_set_button(dialog_->check_preview, 0);
158                 setEnabled(dialog_->check_preview, false);
159         }
160
161         return action;
162 }