]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormInclude.C
try this for distinguishing inner and outer tabs
[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
8  */
9 #include <config.h>
10 #include <algorithm>
11 #include <iostream>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "Dialogs.h"
18 #include "FormInclude.h"
19 #include "insets/insetinclude.h" 
20 #include "filedlg.h"
21 #include "support/filetools.C"
22 #include "support/lstrings.h" 
23 #include "LyXView.h"
24 #include "buffer.h"
25 #include "lyxrc.h" 
26 #include "lyxfunc.h" 
27  
28 #include "form_include.h"
29
30 using std::cout;
31
32 FormInclude::FormInclude(LyXView * lv, Dialogs * d)
33         : FormCommand(lv, d, _("Include file"), new OkCancelPolicy),
34           dialog_(0)
35 {
36         // let the dialog be shown
37         // These are permanent connections so we won't bother
38         // storing a copy because we won't be disconnecting.
39         d->showInclude.connect(slot(this, &FormInclude::showInset));
40         d->createInclude.connect(slot(this, &FormInclude::createInset));
41 }
42
43
44 FormInclude::~FormInclude()
45 {
46         delete dialog_;
47 }
48
49
50 FL_FORM * FormInclude::form() const
51 {
52         if (dialog_) 
53                 return dialog_->form;
54         return 0;
55 }
56
57
58 void FormInclude::build()
59 {
60         dialog_ = build_include();
61
62         // Workaround dumb xforms sizing bug
63         minw_ = form()->w;
64         minh_ = form()->h;
65
66         // Manage the ok and cancel buttons
67         bc_.setOK(dialog_->button_ok);
68         bc_.setCancel(dialog_->button_cancel);
69         bc_.refresh();
70
71         bc_.addReadOnly(dialog_->browsebt);
72         bc_.addReadOnly(dialog_->flag1);
73         bc_.addReadOnly(dialog_->flag2);
74         bc_.addReadOnly(dialog_->flag3);
75         bc_.addReadOnly(dialog_->flag4);
76         bc_.addReadOnly(dialog_->filename);
77         bc_.addReadOnly(dialog_->flag41);
78 }
79
80
81 void FormInclude::update()
82 {
83         bc_.readOnly(lv_->buffer()->isReadonly());
84
85         if (!inset_) {
86                 fl_set_input(dialog_->filename, "");
87                 fl_set_button(dialog_->flag1, 0);
88                 fl_set_button(dialog_->flag2, 0);
89                 fl_set_button(dialog_->flag3, 1);
90                 fl_set_button(dialog_->flag4, 0);
91                 fl_set_button(dialog_->flag41, 0);
92                 fl_deactivate_object(dialog_->flag41);
93                 fl_set_object_lcol(dialog_->flag41, FL_INACTIVE);
94                 return;
95         }
96  
97         fl_set_input(dialog_->filename, params.getContents().c_str());
98  
99         string const cmdname = params.getCmdName();
100  
101         /* FIXME: what do with Don't typeset here ... */
102         //fl_set_button(dialog_->flag1, int(inset_->isNoLoad()));
103  
104         fl_set_button(dialog_->flag2, cmdname == "input");
105         fl_set_button(dialog_->flag3, cmdname == "include");
106         if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") {
107                 fl_set_button(dialog_->flag4, 1);
108                 fl_set_button(dialog_->flag41, cmdname == "verbatiminput*");
109         } else {
110                 fl_set_button(dialog_->flag41, 0);
111                 fl_deactivate_object(dialog_->flag41);
112                 fl_set_object_lcol(dialog_->flag41, FL_INACTIVE);
113         }
114 }
115
116
117 void FormInclude::apply()
118 {
119         if (lv_->buffer()->isReadonly())
120                 return;
121
122         /* FIXME: no way to update internal flags of inset ??? */
123  
124         //inset_->setNoLoad(fl_get_button(dialog_->flag1));
125  
126         params.setContents(fl_get_input(dialog_->filename));
127         cout << params.getContents() << endl; 
128         if (fl_get_button(dialog_->flag2))
129                 params.setCmdName("input");
130         else if (fl_get_button(dialog_->flag3))
131                 params.setCmdName("include");
132         else if (fl_get_button(dialog_->flag4)) {
133                 if (fl_get_button(dialog_->flag41))
134                         params.setCmdName("verbatiminput*");
135                 else
136                         params.setCmdName("verbatiminput");     
137         }
138         
139         if (inset_) {
140                 if (params != inset_->params()) {
141                         inset_->setParams(params);
142                         lv_->view()->updateInset(inset_, true);
143                 }
144         } else
145                 lv_->getLyXFunc()->Dispatch(LFUN_CHILD_INSERT, params.getAsString());
146 }
147  
148 #ifdef WITH_WARNINGS
149 #warning convert this to use the buttoncontroller
150 #endif
151 bool FormInclude::input(FL_OBJECT *, long data)
152 {
153         State state = static_cast<State>(data); 
154  
155         switch (state) {
156                 case BROWSE: {
157                         // Should browsing too be disabled in RO-mode?
158                         LyXFileDlg fileDlg;
159  
160                         string ext;
161                     
162                         fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
163
164                         /* input TeX, verbatim, or LyX file ? */
165                         if (fl_get_button(dialog_->flag2))
166                                 ext = "*.tex";
167                         else if (fl_get_button(dialog_->flag4))
168                                 ext = "*";
169                         else
170                                 ext = "*.lyx";
171          
172                         string mpath;
173  
174                         /* FIXME: what do I do here ? */ 
175                         //if (inset_)
176                         //      mpath = OnlyPath(inset_->getMasterFilename());
177  
178                         string const filename = fileDlg.Select(_("Select Child Document"),
179                                                 mpath, ext, fl_get_input(dialog_->filename));
180                         XFlush(fl_get_display());
181          
182                         // check selected filename
183                         if (filename.empty())
184                                 break;
185          
186                         string const filename2 = MakeRelPath(filename, mpath);
187          
188                         if (prefixIs(filename2, ".."))
189                                 fl_set_input(dialog_->filename, filename.c_str());
190                         else
191                                 fl_set_input(dialog_->filename, filename2.c_str());
192  
193                 }       break;
194
195                 case LOAD:
196                         apply();
197                         lv_->getLyXFunc()->Dispatch(LFUN_CHILDOPEN, params.getContents());
198                         break;
199
200                 case VERBATIM:
201                         fl_activate_object(dialog_->flag41);
202                         fl_set_object_lcol(dialog_->flag41, FL_BLACK); 
203                         break;
204          
205                 case INPUTINCLUDE:
206                         cout << "inputinclude" << endl;
207                         /* huh ? why doesn't this work ? */ 
208                         fl_deactivate_object(dialog_->flag41);
209                         fl_set_object_lcol(dialog_->flag41, FL_INACTIVE);
210                         fl_set_button(dialog_->flag41, 0);
211                         break;
212         }
213         return true; 
214 }