]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QCitation.C
The big renaming. Yowser.
[lyx.git] / src / frontends / qt2 / QCitation.C
1 /**
2  * \file QCitation.C
3  * Copyright 2001 the LyX Team
4  * Read the file COPYING
5  *
6  * \author Angus Leeming <a.leeming@ic.ac.uk>
7  * \author Kalle Dalheimer <kalle@klaralvdalens-datakonsult.se>
8  */
9
10 #include <config.h>
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include "QCitationDialog.h"
17 #include "QCitation.h"
18
19 #include <qcheckbox.h>
20 #include <qcombobox.h>
21 #include <qlineedit.h>
22 #include <qlistbox.h>
23 #include <qmultilineedit.h>
24 #include <qpushbutton.h>
25
26 #include "QtLyXView.h" 
27 #include "qt2BC.h"
28 #include "ControlCitation.h"
29 #include "gettext.h"
30 #include "support/lstrings.h"
31 #include "helper_funcs.h"
32
33
34 using std::find;
35 using std::max;
36 using std::min;
37 using std::pair;
38 using std::sort;
39 using std::vector;
40
41 typedef Qt2CB<ControlCitation, Qt2DB<QCitationDialog> > base_class;
42
43 QCitation::QCitation(ControlCitation & c)
44         : base_class(c, _("Citation"))
45 {}
46
47
48 void QCitation::apply()
49 {
50         controller().params().setCmdName("cite");
51         controller().params().setContents(getStringFromVector(citekeys));
52         
53         string const after  = dialog_->textAfterED->text().latin1();
54         controller().params().setOptions(after);
55 }
56
57
58 void QCitation::hide()
59 {
60         citekeys.clear();
61         bibkeys.clear();
62         
63         Qt2Base::hide();
64 }
65
66
67 void QCitation::build()
68 {
69         dialog_.reset(new QCitationDialog(this));
70
71         dialog_->searchTypeCB->setChecked(false);
72         dialog_->searchCaseCB->setChecked(false);
73         
74         // Manage the ok, apply, restore and cancel/close buttons
75         bc().setOK(dialog_->okPB);
76         bc().setApply(dialog_->applyPB);
77         bc().setCancel(dialog_->cancelPB);
78         bc().setRestore(dialog_->restorePB);
79
80         bc().addReadOnly(dialog_->addPB);
81         bc().addReadOnly(dialog_->delPB);
82         bc().addReadOnly(dialog_->upPB);
83         bc().addReadOnly(dialog_->downPB);
84         bc().addReadOnly(dialog_->citationStyleCO);
85         bc().addReadOnly(dialog_->textBeforeED);
86         bc().addReadOnly(dialog_->textAfterED);
87 }
88
89
90 void QCitation::update()
91 {
92         // Make the list of all available bibliography keys
93         bibkeys = biblio::getKeys(controller().bibkeysInfo());
94         updateBrowser(dialog_->bibLB, bibkeys);
95         
96         // Ditto for the keys cited in this inset
97         citekeys = getVectorFromString(controller().params().getContents());
98         updateBrowser(dialog_->citeLB, citekeys);
99
100         // No keys have been selected yet, so...
101         dialog_->infoML->clear();
102         setBibButtons(OFF);
103         setCiteButtons(OFF);
104
105         dialog_->textAfterED->setText( controller().params().getOptions().c_str());
106 }
107
108
109 void QCitation::updateBrowser(QListBox* browser,
110                                   vector<string> const & keys) const
111 {
112         browser->clear();
113
114         for (vector<string>::const_iterator it = keys.begin();
115                 it < keys.end(); ++it) {
116                 string const key = frontStrip(strip(*it));
117                 // FIXME: why the .empty() test ?
118                 if(!key.empty())
119                         browser->insertItem(key.c_str());
120         }
121 }
122
123
124 void QCitation::setBibButtons(State status) const
125 {
126         dialog_->addPB->setEnabled((status == ON));
127 }
128
129
130 void QCitation::setCiteButtons(State status) const
131 {
132         int const sel = dialog_->citeLB->currentItem();
133         int const maxline = dialog_->citeLB->count() - 1;
134         bool const activate = (status == ON);
135         bool const activate_up = (activate && sel != 0);
136         bool const activate_down = (activate && sel != maxline);
137
138         dialog_->delPB->setEnabled(activate);
139         dialog_->upPB->setEnabled(activate_up);
140         dialog_->downPB->setEnabled(activate_down);
141 }