]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormInclude.C
remove defaults stuff, let Qt handle no toolbar
[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 "Tooltips.h"
25 #include "xforms_helpers.h" // setEnabled
26 #include "support/lstrings.h" // strip
27 #include FORMS_H_LOCATION
28
29 typedef FormController<ControlInclude, FormView<FD_include> > base_class;
30
31 FormInclude::FormInclude(Dialog & parent)
32         : base_class(parent, _("Include file"))
33 {}
34
35
36 void FormInclude::build()
37 {
38         dialog_.reset(build_include(this));
39
40         // Manage the ok and cancel buttons
41         bcview().setOK(dialog_->button_ok);
42         bcview().setCancel(dialog_->button_close);
43
44         // trigger an input event for cut&paste with middle mouse button.
45         setPrehandler(dialog_->input_filename);
46
47         fl_set_input_return(dialog_->input_filename, FL_RETURN_CHANGED);
48
49         // disable for read-only documents
50         bcview().addReadOnly(dialog_->button_browse);
51         bcview().addReadOnly(dialog_->radio_useinput);
52         bcview().addReadOnly(dialog_->radio_useinclude);
53         bcview().addReadOnly(dialog_->radio_verbatim);
54
55         type_.init(dialog_->radio_useinput,   ControlInclude::INPUT);
56         type_.init(dialog_->radio_useinclude, ControlInclude::INCLUDE);
57         type_.init(dialog_->radio_verbatim,   ControlInclude::VERBATIM);
58
59         // set up the tooltips
60         string str = _("File name to include.");
61         tooltips().init(dialog_->input_filename, str);
62         str = _("Browse directories for file name.");
63         tooltips().init(dialog_->button_browse, str);
64         str = _("Use LaTeX \\input.");
65         tooltips().init(dialog_->radio_useinput, str);
66         str = _("Use LaTeX \\include.");
67         tooltips().init(dialog_->radio_useinclude, str);
68         str = _("Use LaTeX \\verbatiminput.");
69         tooltips().init(dialog_->radio_verbatim, str);
70         str = _("Underline spaces in generated output.");
71         tooltips().init(dialog_->check_visiblespace, str);
72         str = _("Show LaTeX preview.");
73         tooltips().init(dialog_->check_preview, str);
74         str = _("Load the file.");
75         tooltips().init(dialog_->button_load, str);
76 }
77
78
79 void FormInclude::update()
80 {
81         string const filename = controller().params().cparams.getContents();
82         string const cmdname = controller().params().cparams.getCmdName();
83         bool const preview = static_cast<bool>((controller().params().cparams.preview()));
84
85         fl_set_input(dialog_->input_filename, filename.c_str());
86
87         bool const inputCommand = cmdname == "input";
88         bool const includeCommand = cmdname == "include";
89         bool const verbatimStarCommand = cmdname == "verbatiminput*";
90         bool const verbatimCommand = cmdname == "verbatiminput";
91
92         setEnabled(dialog_->check_preview, inputCommand);
93         fl_set_button(dialog_->check_preview, inputCommand ? preview : 0);
94
95         if (cmdname.empty())
96                 type_.set(ControlInclude::INPUT);
97
98         if (includeCommand)
99                 type_.set(ControlInclude::INCLUDE);
100
101         if (verbatimCommand || verbatimStarCommand) {
102                 type_.set(ControlInclude::VERBATIM);
103                 fl_set_button(dialog_->check_visiblespace, verbatimStarCommand);
104                 setEnabled(dialog_->check_visiblespace, true);
105                 setEnabled(dialog_->button_load, false);
106         } else {
107                 fl_set_button(dialog_->check_visiblespace, 0);
108                 setEnabled(dialog_->check_visiblespace, false);
109                 setEnabled(dialog_->button_load, true);
110         }
111 }
112
113
114 void FormInclude::apply()
115 {
116         InsetInclude::Params params = controller().params();
117
118         params.cparams.preview(fl_get_button(dialog_->check_preview));
119
120         string const file = fl_get_input(dialog_->input_filename);
121         if (controller().fileExists(file))
122                 params.cparams.setContents(file);
123         else
124                 params.cparams.setContents("");
125
126         ControlInclude::Type const type = ControlInclude::Type(type_.get());
127         if (type == ControlInclude::INPUT)
128                 params.flag = InsetInclude::INPUT;
129         else if (type == ControlInclude::INCLUDE)
130                 params.flag = InsetInclude::INCLUDE;
131         else if (type == ControlInclude::VERBATIM) {
132                 if (fl_get_button(dialog_->check_visiblespace))
133                         params.flag = InsetInclude::VERBAST;
134                 else
135                         params.flag = InsetInclude::VERB;
136         }
137
138         controller().setParams(params);
139 }
140
141
142 ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
143 {
144         ButtonPolicy::SMInput action = ButtonPolicy::SMI_VALID;
145
146         if (ob == dialog_->button_browse) {
147                 string const in_name = fl_get_input(dialog_->input_filename);
148                 fl_freeze_form(form());
149                 ControlInclude::Type const type = ControlInclude::Type(type_.get());
150                 string const out_name = controller().Browse(in_name, type);
151                 fl_set_input(dialog_->input_filename, out_name.c_str());
152                 fl_unfreeze_form(form());
153
154         } else if (ob == dialog_->button_load) {
155                 string const in_name = fl_get_input(dialog_->input_filename);
156                 if (!rtrim(in_name).empty() && controller().fileExists(in_name)) {
157                         dialog().OKButton();
158                         controller().load(rtrim(in_name));
159                         action = ButtonPolicy::SMI_NOOP;
160                 }
161
162         } else if (ob == dialog_->radio_verbatim) {
163                 setEnabled(dialog_->check_visiblespace, true);
164                 setEnabled(dialog_->button_load, false);
165
166         } else if (ob == dialog_->radio_useinclude ||
167                    ob == dialog_->radio_useinput) {
168                 fl_set_button(dialog_->check_visiblespace, 0);
169                 setEnabled(dialog_->check_visiblespace, false);
170                 setEnabled(dialog_->button_load, true);
171
172         } else if (ob == dialog_->input_filename) {
173                 string const in_name = fl_get_input(dialog_->input_filename);
174                 if (rtrim(in_name).empty())
175                         action = ButtonPolicy::SMI_INVALID;
176         }
177
178         if (ob == dialog_->radio_useinput) {
179                 setEnabled(dialog_->check_preview, true);
180         } else if (ob == dialog_->radio_verbatim ||
181                    ob == dialog_->radio_useinclude) {
182                 fl_set_button(dialog_->check_preview, 0);
183                 setEnabled(dialog_->check_preview, false);
184         }
185
186         return action;
187 }