]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QBibtexDialog.C
some tabular fixes for the problems reported by Helge
[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 #include "QBibtexDialog.h"
14 #include "ui/QBibtexAddDialogBase.h"
15 #include "QBibtex.h"
16 #include "qt_helpers.h"
17
18 #include "controllers/ControlBibtex.h"
19 #include "support/filetools.h"
20
21 #include <qpushbutton.h>
22 #include <qcombobox.h>
23 #include <qlineedit.h>
24 #include <qlistbox.h>
25
26 using lyx::support::ChangeExtension;
27
28 using std::string;
29
30 namespace lyx {
31 namespace frontend {
32
33 QBibtexDialog::QBibtexDialog(QBibtex * form)
34         : QBibtexDialogBase(0, 0, false, 0),
35         form_(form)
36 {
37         connect(okPB, SIGNAL(clicked()),
38                 form, SLOT(slotOK()));
39         connect(closePB, SIGNAL(clicked()),
40                 form, SLOT(slotClose()));
41
42         add_ = new QBibtexAddDialogBase(this, "", true);
43         connect(add_->addPB, SIGNAL(clicked()), this, SLOT(addDatabase()));
44         connect(add_->addPB, SIGNAL(clicked()), this, SLOT(addDatabase()));
45         connect(add_->bibLB, SIGNAL(selected(QListBoxItem *)), this, SLOT(addDatabase()));
46         connect(add_->bibLB, SIGNAL(selected(QListBoxItem *)), add_, SLOT(accept()));
47         connect(add_->bibLB, SIGNAL(currentChanged(QListBoxItem *)), this, SLOT(availableChanged()));
48         connect(add_->browsePB, SIGNAL(clicked()), this, SLOT(browseBibPressed()));
49 }
50
51
52 void QBibtexDialog::change_adaptor()
53 {
54         form_->changed();
55 }
56
57
58 void QBibtexDialog::browsePressed()
59 {
60         string const file = form_->controller().browseBst("");
61
62         if (!file.empty()) {
63                 string const filen = ChangeExtension(file, "");
64                 bool present = false;
65                 unsigned int pres = 0;
66
67                 for (int i = 0; i != styleCB->count(); ++i) {
68                         if (fromqstr(styleCB->text(i)) == filen) {
69                                 present = true;
70                                 pres = i;
71                         }
72                 }
73
74                 if (!present)
75                         styleCB->insertItem(toqstr(filen),0);
76
77                 styleCB->setCurrentItem(pres);
78                 form_->changed();
79         }
80 }
81
82
83 void QBibtexDialog::browseBibPressed()
84 {
85         string const file = form_->controller().browseBib("");
86
87         if (!file.empty()) {
88                 string const f = ChangeExtension(file, "");
89                 bool present = false;
90
91                 for (unsigned int i = 0; i != add_->bibLB->count(); i++) {
92                         if (fromqstr(add_->bibLB->text(i)) == f)
93                                 present = true;
94                 }
95
96                 if (!present) {
97                         add_->bibLB->insertItem(toqstr(f));
98                         form_->changed();
99                 }
100
101                 add_->bibED->setText(toqstr(f));
102         }
103 }
104
105 void QBibtexDialog::addPressed()
106 {
107         add_->exec();
108 }
109
110
111 void QBibtexDialog::addDatabase()
112 {
113         int const sel = add_->bibLB->currentItem();
114         QString const file = add_->bibED->text();
115
116         if (sel < 0 && file.isNull())
117                 return;
118
119         // Add the selected browser_bib keys to browser_database
120         // multiple selections are possible
121         for (unsigned int i = 0; i != add_->bibLB->count(); i++) {
122                 if (add_->bibLB->isSelected(i)) {
123                         // do not allow duplicates
124                         if ((databaseLB->findItem(add_->bibLB->text(i))) == 0)
125                                 databaseLB->insertItem(add_->bibLB->text(i));
126                 }
127         }
128
129         if (!file.isEmpty()) {
130                 QString const f = toqstr(ChangeExtension(fromqstr(file), ""));
131                 if ((databaseLB->findItem(f)) == 0)
132                         databaseLB->insertItem(f);
133         }
134
135         form_->changed();
136 }
137
138
139 void QBibtexDialog::deletePressed()
140 {
141         databaseLB->removeItem(databaseLB->currentItem());
142 }
143
144
145
146 void QBibtexDialog::databaseChanged()
147 {
148         deletePB->setEnabled(!form_->readOnly() && databaseLB->currentItem() != -1);
149 }
150
151
152 void QBibtexDialog::availableChanged()
153 {
154         form_->changed();
155 }
156
157
158 void QBibtexDialog::closeEvent(QCloseEvent *e)
159 {
160         form_->slotWMHide();
161         e->accept();
162 }
163
164 } // namespace frontend
165 } // namespace lyx