]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QBibtexDialog.C
Strip out another 350 redundant #includes.
[lyx.git] / src / frontends / qt2 / QBibtexDialog.C
1 /**
2  * \file QBibtexDialog.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13
14 #include "qt_helpers.h"
15
16 #include "support/filetools.h"
17
18 #include <qpushbutton.h>
19 #include <qcombobox.h>
20 #include <qlineedit.h>
21 #include <qlistbox.h>
22 #include <qfiledialog.h>
23
24 #include "ui/QBibtexAddDialogBase.h"
25 #include "QBibtexDialog.h"
26 #include "QBibtex.h"
27
28
29 using namespace lyx::support;
30
31 QBibtexDialog::QBibtexDialog(QBibtex * form)
32         : QBibtexDialogBase(0, 0, false, 0),
33         form_(form)
34 {
35         connect(okPB, SIGNAL(clicked()),
36                 form, SLOT(slotOK()));
37         connect(closePB, SIGNAL(clicked()),
38                 form, SLOT(slotClose()));
39
40         add_ = new QBibtexAddDialogBase(this, "", true);
41         connect(add_->addPB, SIGNAL(clicked()), this, SLOT(addDatabase()));
42         connect(add_->addPB, SIGNAL(clicked()), this, SLOT(addDatabase()));
43         connect(add_->bibLB, SIGNAL(selected(QListBoxItem *)), this, SLOT(addDatabase()));
44         connect(add_->bibLB, SIGNAL(selected(QListBoxItem *)), add_, SLOT(accept()));
45         connect(add_->bibLB, SIGNAL(currentChanged(QListBoxItem *)), this, SLOT(availableChanged()));
46         connect(add_->browsePB, SIGNAL(clicked()), this, SLOT(browseBibPressed()));
47 }
48
49
50 void QBibtexDialog::change_adaptor()
51 {
52         form_->changed();
53 }
54
55
56 void QBibtexDialog::browsePressed()
57 {
58         QString const file =
59                 QFileDialog::getOpenFileName(QString::null,
60                                              qt_("BibTeX style files (*.bst)"),
61                                              this,
62                                              0,
63                                              qt_("Select a BibTeX style"));
64         if (!file.isNull()) {
65                 string const filen = ChangeExtension(fromqstr(file), "");
66                 bool present = false;
67                 unsigned int pres = 0;
68
69                 for (int i = 0; i != styleCB->count(); ++i) {
70                         if (fromqstr(styleCB->text(i)) == filen) {
71                                 present = true;
72                                 pres = i;
73                         }
74                 }
75
76                 if (!present)
77                         styleCB->insertItem(toqstr(filen),0);
78
79                 styleCB->setCurrentItem(pres);
80                 form_->changed();
81         }
82 }
83
84
85 void QBibtexDialog::browseBibPressed()
86 {
87         QString const file = QFileDialog::getOpenFileName(QString::null,
88                 qt_("BibTeX database files (*.bib)"), add_, 0, qt_("Select a BibTeX database to add"));
89
90         if (!file.isNull()) {
91                 string const f = ChangeExtension(fromqstr(file), "");
92                 bool present = false;
93
94                 for (unsigned int i = 0; i != add_->bibLB->count(); i++) {
95                         if (fromqstr(add_->bibLB->text(i)) == f)
96                                 present = true;
97                 }
98
99                 if (!present) {
100                         add_->bibLB->insertItem(toqstr(f));
101                         form_->changed();
102                 }
103
104                 add_->bibED->setText(toqstr(f));
105         }
106 }
107
108 void QBibtexDialog::addPressed()
109 {
110         add_->exec();
111 }
112
113
114 void QBibtexDialog::addDatabase()
115 {
116         int const sel = add_->bibLB->currentItem();
117         QString const file = add_->bibED->text();
118
119         if (sel < 0 && file.isNull())
120                 return;
121
122         // Add the selected browser_bib keys to browser_database
123         // multiple selections are possible
124         for (unsigned int i = 0; i != add_->bibLB->count(); i++) {
125                 if (add_->bibLB->isSelected(i)) {
126                         // do not allow duplicates
127                         if ((databaseLB->findItem(add_->bibLB->text(i))) == 0)
128                                 databaseLB->insertItem(add_->bibLB->text(i));
129                 }
130         }
131
132         if (!file.isEmpty()) {
133                 QString const f = toqstr(ChangeExtension(fromqstr(file), ""));
134                 if ((databaseLB->findItem(f)) == 0)
135                         databaseLB->insertItem(f);
136         }
137
138         form_->changed();
139 }
140
141
142 void QBibtexDialog::deletePressed()
143 {
144         databaseLB->removeItem(databaseLB->currentItem());
145 }
146
147
148
149 void QBibtexDialog::databaseChanged()
150 {
151         deletePB->setEnabled(!form_->readOnly() && databaseLB->currentItem() != -1);
152 }
153
154
155 void QBibtexDialog::availableChanged()
156 {
157         form_->changed();
158 }
159
160
161 void QBibtexDialog::closeEvent(QCloseEvent *e)
162 {
163         form_->slotWMHide();
164         e->accept();
165 }