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