]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QInclude.C
build fixes
[lyx.git] / src / frontends / qt2 / QInclude.C
1 /**
2  * \file QInclude.C
3  * Copyright 2001 the LyX Team
4  * Read the file COPYING
5  *
6  * \author John Levon <moz@compsoc.man.ac.uk>
7  */
8
9 #include <config.h>
10
11 #ifdef __GNUG__
12 #pragma implementation
13 #endif
14
15 #include "ControlInclude.h"
16 #include "gettext.h"
17 #include "debug.h"
18  
19 #include "QIncludeDialog.h"
20 #include "QInclude.h"
21 #include "Qt2BC.h"
22
23 #include <qlineedit.h>
24 #include <qpushbutton.h>
25 #include <qcheckbox.h>
26 #include <qcombobox.h>
27
28 typedef Qt2CB<ControlInclude, Qt2DB<QIncludeDialog> > base_class;
29
30 QInclude::QInclude()
31         : base_class(_("Include"))
32 {
33 }
34
35
36 void QInclude::build_dialog()
37 {
38         dialog_.reset(new QIncludeDialog(this));
39
40         bc().setOK(dialog_->okPB);
41         bc().setCancel(dialog_->closePB);
42         bc().addReadOnly(dialog_->filenameED);
43         bc().addReadOnly(dialog_->browsePB);
44         bc().addReadOnly(dialog_->visiblespaceCB);
45         bc().addReadOnly(dialog_->typeCO);
46 }
47
48
49 void QInclude::update_contents()
50 {
51         dialog_->filenameED->setText(controller().params().cparams.getContents().c_str());
52
53         string const cmdname = controller().params().cparams.getCmdName();
54
55         dialog_->visiblespaceCB->setChecked(false);
56         dialog_->visiblespaceCB->setEnabled(false);
57
58         lyxerr << cmdname << endl;
59  
60         if (cmdname == "input")
61                 dialog_->typeCO->setCurrentItem(0);
62         else if (!cmdname.empty()) {
63                 dialog_->typeCO->setCurrentItem(2);
64                 dialog_->visiblespaceCB->setChecked(cmdname == "verbatiminput*");
65                 dialog_->visiblespaceCB->setEnabled(true);
66         } else {
67                 dialog_->typeCO->setCurrentItem(1);
68         }
69 }
70
71
72 void QInclude::apply()
73 {
74         controller().params().cparams.
75                 setContents(dialog_->filenameED->text().latin1());
76
77         int const item = dialog_->typeCO->currentItem();
78         if (item == 0)
79                 controller().params().flag = InsetInclude::INPUT;
80         else if (item == 1)
81                 controller().params().flag = InsetInclude::INCLUDE;
82         else {
83                 if (dialog_->visiblespaceCB->isChecked())
84                         controller().params().flag = InsetInclude::VERBAST;
85                 else
86                         controller().params().flag = InsetInclude::VERB;
87         }
88 }
89
90
91 void QInclude::browse()
92 {
93         ControlInclude::Type type;
94
95         int const item = dialog_->typeCO->currentItem();
96         if (item==0)
97                 type = ControlInclude::INPUT;
98         else if (item==1)
99                 type = ControlInclude::INCLUDE;
100         else
101                 type = ControlInclude::VERBATIM;
102
103         string const & name = controller().Browse(dialog_->filenameED->text().latin1(), type);
104         if (!name.empty())
105                 dialog_->filenameED->setText(name.c_str());
106 }
107
108
109 void QInclude::load()
110 {
111         if (isValid()) {
112                 string const file(dialog_->filenameED->text().latin1());
113                 slotOK();
114                 controller().load(file);
115         }
116 }
117
118
119 bool QInclude::isValid()
120 {
121         return !string(dialog_->filenameED->text().latin1()).empty();
122 }