]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormInclude.C
The Ok button is now activated in the Include dialog when the filename is
[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@.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
39         // Manage the ok and cancel buttons
40         bc().setOK(dialog_->button_ok);
41         bc().setCancel(dialog_->button_cancel);
42
43         bc().addReadOnly(dialog_->button_browse);
44         bc().addReadOnly(dialog_->check_verbatim);
45         bc().addReadOnly(dialog_->check_typeset);
46         bc().addReadOnly(dialog_->check_useinput);
47         bc().addReadOnly(dialog_->check_useinclude);
48 }
49
50
51 void FormInclude::update()
52 {
53         if (controller().params().noload) {
54                 fl_set_input(dialog_->input_filename, "");
55                 fl_set_button(dialog_->check_typeset, 0);
56                 fl_set_button(dialog_->check_useinput, 0);
57                 fl_set_button(dialog_->check_useinclude, 1);
58                 fl_set_button(dialog_->check_verbatim, 0);
59                 fl_set_button(dialog_->check_visiblespace, 0);
60                 fl_deactivate_object(dialog_->check_visiblespace);
61                 fl_set_object_lcol(dialog_->check_visiblespace, FL_INACTIVE);
62                 return;
63         }
64
65         fl_set_input(dialog_->input_filename,
66                      controller().params().cparams.getContents().c_str());
67
68         string const cmdname = controller().params().cparams.getCmdName();
69
70         fl_set_button(dialog_->check_typeset,
71                       int(controller().params().noload));
72
73         fl_set_button(dialog_->check_useinput, cmdname == "input");
74         fl_set_button(dialog_->check_useinclude, cmdname == "include");
75         if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") {
76                 fl_set_button(dialog_->check_verbatim, 1);
77                 fl_set_button(dialog_->check_visiblespace, cmdname == "verbatiminput*");
78                 setEnabled(dialog_->check_visiblespace, true);
79         } else {
80                 fl_set_button(dialog_->check_visiblespace, 0);
81                 setEnabled(dialog_->check_visiblespace, false);
82         }
83  
84         if (cmdname.empty())
85                 fl_set_button(dialog_->check_useinclude, 1);
86 }
87
88
89 void FormInclude::apply()
90 {
91         controller().params().noload = fl_get_button(dialog_->check_typeset);
92
93         controller().params().cparams.
94                 setContents(fl_get_input(dialog_->input_filename));
95
96         if (fl_get_button(dialog_->check_useinput))
97                 controller().params().flag = InsetInclude::INPUT;
98         else if (fl_get_button(dialog_->check_useinclude))
99                 controller().params().flag = InsetInclude::INCLUDE;
100         else if (fl_get_button(dialog_->check_verbatim)) {
101                 if (fl_get_button(dialog_->check_visiblespace))
102                         controller().params().flag = InsetInclude::VERBAST;
103                 else
104                         controller().params().flag = InsetInclude::VERB;
105         }
106 }
107
108
109 ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
110 {
111         ButtonPolicy::SMInput action = ButtonPolicy::SMI_VALID;
112
113         if (ob == dialog_->button_browse) {
114                 ControlInclude::Type type;
115                 if (fl_get_button(dialog_->check_useinput))
116                         type = ControlInclude::INPUT;
117                 else if (fl_get_button(dialog_->check_verbatim))
118                         type = ControlInclude::VERBATIM;
119                 else
120                         type = ControlInclude::INCLUDE;
121
122                 string const in_name  = fl_get_input(dialog_->input_filename);
123                 fl_freeze_form(form()); 
124                 string const out_name = controller().Browse(in_name, type);
125                 fl_set_input(dialog_->input_filename, out_name.c_str());
126                 fl_unfreeze_form(form()); 
127
128         } else if (ob == dialog_->button_load) {
129                 string const in_name = fl_get_input(dialog_->input_filename);
130                 if (!strip(in_name).empty()) {
131                         ApplyButton();
132                         action = ButtonPolicy::SMI_NOOP;
133                 }
134
135         } else if (ob == dialog_->check_verbatim) {
136                 setEnabled(dialog_->check_visiblespace, true);
137
138         } else if (ob == dialog_->check_useinclude ||
139                    ob == dialog_->check_useinput) {
140                 fl_set_button(dialog_->check_visiblespace, 0);
141                 setEnabled(dialog_->check_visiblespace, false);
142
143         } else if (ob == dialog_->input_filename) {
144                 string const in_name = fl_get_input(dialog_->input_filename);
145                 if (strip(in_name).empty())
146                         action = ButtonPolicy::SMI_INVALID;
147         }
148         
149         return action;
150 }