]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormInclude.C
remove noload/don't typeset
[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 #ifdef __GNUG__
17 #pragma implementation
18 #endif
19
20 #include "debug.h"
21  
22 #include "xformsBC.h"
23 #include "ControlInclude.h"
24 #include "FormInclude.h"
25 #include "forms/form_include.h"
26 #include "insets/insetinclude.h"
27 #include "xforms_helpers.h" // setEnabled
28 #include "support/lstrings.h" // strip
29 #include FORMS_H_LOCATION
30
31 typedef FormCB<ControlInclude, FormDB<FD_include> > base_class;
32
33 FormInclude::FormInclude()
34         : base_class(_("Include file"))
35 {}
36
37
38 void FormInclude::build()
39 {
40         dialog_.reset(build_include(this));
41
42         fl_set_input_return(dialog_->input_filename, FL_RETURN_CHANGED);
43         setPrehandler(dialog_->input_filename);
44
45         // Manage the ok and cancel buttons
46         bc().setOK(dialog_->button_ok);
47         bc().setCancel(dialog_->button_close);
48
49         bc().addReadOnly(dialog_->button_browse);
50         bc().addReadOnly(dialog_->radio_verbatim);
51         bc().addReadOnly(dialog_->radio_useinput);
52         bc().addReadOnly(dialog_->radio_useinclude);
53 }
54
55
56 void FormInclude::update()
57 {
58         fl_set_input(dialog_->input_filename,
59                      controller().params().cparams.getContents().c_str());
60
61         string const cmdname = controller().params().cparams.getCmdName();
62
63         lyxerr << cmdname << endl; 
64         if (cmdname == "input")
65                 fl_set_button(dialog_->check_preview,
66                               int(controller().params().cparams.preview()));
67         else
68                 fl_set_button(dialog_->check_preview, 0);
69
70         setEnabled(dialog_->check_preview, (cmdname == "input"));
71
72         fl_set_button(dialog_->radio_useinput, cmdname == "input");
73         fl_set_button(dialog_->radio_useinclude, cmdname == "include");
74         if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") {
75                 fl_set_button(dialog_->radio_verbatim, 1);
76                 fl_set_button(dialog_->check_visiblespace, cmdname == "verbatiminput*");
77                 setEnabled(dialog_->check_visiblespace, true);
78                 setEnabled(dialog_->button_load, false);
79         } else {
80                 fl_set_button(dialog_->check_visiblespace, 0);
81                 setEnabled(dialog_->check_visiblespace, false);
82                 setEnabled(dialog_->button_load, true);
83         }
84
85         if (cmdname.empty())
86                 fl_set_button(dialog_->radio_useinclude, 1);
87 }
88
89
90 void FormInclude::apply()
91 {
92         controller().params().cparams
93                 .preview(fl_get_button(dialog_->check_preview));
94
95         string const file = fl_get_input(dialog_->input_filename);
96         if (controller().fileExists(file))
97                 controller().params().cparams.setContents(file);
98         else
99                 controller().params().cparams.setContents("");
100
101         if (fl_get_button(dialog_->radio_useinput))
102                 controller().params().flag = InsetInclude::INPUT;
103         else if (fl_get_button(dialog_->radio_useinclude))
104                 controller().params().flag = InsetInclude::INCLUDE;
105         else if (fl_get_button(dialog_->radio_verbatim)) {
106                 if (fl_get_button(dialog_->check_visiblespace))
107                         controller().params().flag = InsetInclude::VERBAST;
108                 else
109                         controller().params().flag = InsetInclude::VERB;
110         }
111 }
112
113
114 ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
115 {
116         ButtonPolicy::SMInput action = ButtonPolicy::SMI_VALID;
117
118         if (ob == dialog_->button_browse) {
119                 ControlInclude::Type type;
120                 if (fl_get_button(dialog_->radio_useinput))
121                         type = ControlInclude::INPUT;
122                 else if (fl_get_button(dialog_->radio_verbatim))
123                         type = ControlInclude::VERBATIM;
124                 else
125                         type = ControlInclude::INCLUDE;
126
127                 string const in_name  = fl_get_input(dialog_->input_filename);
128                 fl_freeze_form(form());
129                 string const out_name = controller().Browse(in_name, type);
130                 fl_set_input(dialog_->input_filename, out_name.c_str());
131                 fl_unfreeze_form(form());
132
133         } else if (ob == dialog_->button_load) {
134                 string const in_name = fl_get_input(dialog_->input_filename);
135                 if (!rtrim(in_name).empty() && controller().fileExists(in_name)) {
136                         controller().OKButton();
137                         controller().load(rtrim(in_name));
138                         action = ButtonPolicy::SMI_NOOP;
139                 }
140
141         } else if (ob == dialog_->radio_verbatim) {
142                 setEnabled(dialog_->check_visiblespace, true);
143                 setEnabled(dialog_->button_load, false);
144
145         } else if (ob == dialog_->radio_useinclude ||
146                    ob == dialog_->radio_useinput) {
147                 fl_set_button(dialog_->check_visiblespace, 0);
148                 setEnabled(dialog_->check_visiblespace, false);
149                 setEnabled(dialog_->button_load, true);
150
151         } else if (ob == dialog_->input_filename) {
152                 string const in_name = fl_get_input(dialog_->input_filename);
153                 if (rtrim(in_name).empty())
154                         action = ButtonPolicy::SMI_INVALID;
155         }
156
157         if (ob == dialog_->radio_useinput) {
158                 setEnabled(dialog_->check_preview, true);
159         } else if (ob == dialog_->radio_verbatim ||
160                    ob == dialog_->radio_useinclude) {
161                 fl_set_button(dialog_->check_preview, 0);
162                 setEnabled(dialog_->check_preview, false);
163         }
164
165         return action;
166 }