]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QCitation.C
the doxygen patch
[lyx.git] / src / frontends / qt2 / QCitation.C
1 /**
2  * \file QCitation.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  * \author Kalle Dalheimer
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 #include <config.h>
13
14 #include "ui/QCitationFindDialogBase.h"
15 #include "QCitationDialog.h"
16 #include "QCitation.h"
17
18 #include <qcheckbox.h>
19 #include <qcombobox.h>
20 #include <qlineedit.h>
21 #include <qlistbox.h>
22 #include <qmultilineedit.h>
23 #include <qpushbutton.h>
24 #include <qlabel.h>
25
26 #include "QtLyXView.h"
27 #include "Qt2BC.h"
28 #include "ControlCitation.h"
29 #include "debug.h"
30 #include "qt_helpers.h"
31 #include "support/lstrings.h"
32 #include "helper_funcs.h"
33
34
35 using std::find;
36 using std::max;
37 using std::min;
38 using std::pair;
39 using std::sort;
40 using std::vector;
41
42 typedef QController<ControlCitation, QView<QCitationDialog> > base_class;
43
44
45 QCitation::QCitation(Dialog & parent)
46         : base_class(parent, _("LyX: Citation Reference"))
47 {}
48
49
50 void QCitation::apply()
51 {
52         vector<biblio::CiteStyle> const & styles =
53                 ControlCitation::getCiteStyles();
54
55         int const choice = dialog_->citationStyleCO->currentItem();
56         bool const full  = dialog_->fulllistCB->isChecked();
57         bool const force = dialog_->forceuppercaseCB->isChecked();
58
59         string const command =
60                 biblio::getCiteCommand(styles[choice], full, force);
61
62         controller().params().setCmdName(command);
63         controller().params().setContents(getStringFromVector(citekeys));
64
65         string const after = fromqstr(dialog_->textAfterED->text());
66         controller().params().setOptions(after);
67 }
68
69
70 void QCitation::hide()
71 {
72         citekeys.clear();
73         bibkeys.clear();
74
75         QDialogView::hide();
76 }
77
78
79 void QCitation::build_dialog()
80 {
81         dialog_.reset(new QCitationDialog(this));
82
83         // Manage the ok, apply, restore and cancel/close buttons
84         bcview().setOK(dialog_->okPB);
85         bcview().setApply(dialog_->applyPB);
86         bcview().setCancel(dialog_->closePB);
87         bcview().setRestore(dialog_->restorePB);
88
89         bcview().addReadOnly(dialog_->addPB);
90         bcview().addReadOnly(dialog_->deletePB);
91         bcview().addReadOnly(dialog_->upPB);
92         bcview().addReadOnly(dialog_->downPB);
93         bcview().addReadOnly(dialog_->citationStyleCO);
94         bcview().addReadOnly(dialog_->forceuppercaseCB);
95         bcview().addReadOnly(dialog_->fulllistCB);
96         // add when enabled !
97         //bcview().addReadOnly(dialog_->textBeforeED);
98         bcview().addReadOnly(dialog_->textAfterED);
99 }
100
101
102 void QCitation::fillStyles()
103 {
104         if (citekeys.empty()) {
105                 dialog_->citationStyleCO->setEnabled(false);
106                 dialog_->citationStyleLA->setEnabled(false);
107                 return;
108         }
109
110         int const orig = dialog_->citationStyleCO->currentItem();
111
112         dialog_->citationStyleCO->clear();
113
114         int curr = dialog_->selectedLB->currentItem();
115         if (curr < 0)
116                 curr = 0;
117
118         string key = citekeys[curr];
119
120         vector<string> const & sty = controller().getCiteStrings(key);
121
122         bool const natbib = controller().usingNatbib();
123         dialog_->citationStyleCO->setEnabled(!sty.empty() && natbib);
124         dialog_->citationStyleLA->setEnabled(!sty.empty() && natbib);
125
126         for (vector<string>::const_iterator it = sty.begin();
127                 it != sty.end(); ++it) {
128                 dialog_->citationStyleCO->insertItem(toqstr(*it));
129         }
130
131         if (orig != -1 && orig < dialog_->citationStyleCO->count())
132                 dialog_->citationStyleCO->setCurrentItem(orig);
133 }
134
135
136 void QCitation::updateStyle()
137 {
138         bool const natbib = controller().usingNatbib();
139
140         dialog_->fulllistCB->setEnabled(natbib);
141         dialog_->forceuppercaseCB->setEnabled(natbib);
142
143         string const & command = controller().params().getCmdName();
144
145         // Find the style of the citekeys
146         vector<biblio::CiteStyle> const & styles =
147                 ControlCitation::getCiteStyles();
148         biblio::CitationStyle cs = biblio::getCitationStyle(command);
149
150         vector<biblio::CiteStyle>::const_iterator cit =
151                 find(styles.begin(), styles.end(), cs.style);
152
153         dialog_->citationStyleCO->setCurrentItem(0);
154         dialog_->fulllistCB->setChecked(false);
155         dialog_->forceuppercaseCB->setChecked(false);
156
157         if (cit != styles.end()) {
158                 int const i = int(cit - styles.begin());
159                 dialog_->citationStyleCO->setCurrentItem(i);
160                 dialog_->fulllistCB->setChecked(cs.full);
161                 dialog_->forceuppercaseCB->setChecked(cs.forceUCase);
162         }
163 }
164
165
166 void QCitation::update_contents()
167 {
168         // Make the list of all available bibliography keys
169         bibkeys = biblio::getKeys(controller().bibkeysInfo());
170         updateBrowser(dialog_->add_->availableLB, bibkeys);
171
172         // Ditto for the keys cited in this inset
173         citekeys = getVectorFromString(controller().params().getContents());
174         updateBrowser(dialog_->selectedLB, citekeys);
175
176         // No keys have been selected yet, so...
177         dialog_->infoML->clear();
178         dialog_->setButtons();
179
180         dialog_->textAfterED->setText(toqstr(controller().params().getOptions()));
181
182         fillStyles();
183         updateStyle();
184 }
185
186
187 void QCitation::updateBrowser(QListBox * browser,
188                               vector<string> const & keys) const
189 {
190         browser->clear();
191
192         for (vector<string>::const_iterator it = keys.begin();
193                 it < keys.end(); ++it) {
194                 string const key = trim(*it);
195                 // FIXME: why the .empty() test ?
196                 if (!key.empty())
197                         browser->insertItem(toqstr(key));
198         }
199 }