]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QCitation.C
ee29292827d80b5a14585731b2b5a112d00da993
[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 "debug.h"
30 #include "gettext.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 Qt2CB<ControlCitation, Qt2DB<QCitationDialog> > base_class;
43
44 QCitation::QCitation(ControlCitation & c)
45         : base_class(c, _("Citation"))
46 {}
47
48
49 void QCitation::apply()
50 {
51         controller().params().setCmdName("cite");
52         controller().params().setContents(getStringFromVector(citekeys));
53         
54         string const after  = dialog_->textAfterED->text().latin1();
55         controller().params().setOptions(after);
56 }
57
58
59 void QCitation::hide()
60 {
61         citekeys.clear();
62         bibkeys.clear();
63         
64         Qt2Base::hide();
65 }
66
67
68 void QCitation::build()
69 {
70         dialog_.reset(new QCitationDialog(this));
71
72         dialog_->searchTypeCB->setChecked(false);
73         dialog_->searchCaseCB->setChecked(false);
74         
75         // Manage the ok, apply, restore and cancel/close buttons
76         bc().setOK(dialog_->okPB);
77         bc().setApply(dialog_->applyPB);
78         bc().setCancel(dialog_->closePB);
79         bc().setRestore(dialog_->restorePB);
80
81         bc().addReadOnly(dialog_->addPB);
82         bc().addReadOnly(dialog_->delPB);
83         bc().addReadOnly(dialog_->upPB);
84         bc().addReadOnly(dialog_->downPB);
85         bc().addReadOnly(dialog_->citationStyleCO);
86         // add when enabled ! 
87         //bc().addReadOnly(dialog_->textBeforeED);
88         bc().addReadOnly(dialog_->textAfterED);
89 }
90
91
92 void QCitation::update()
93 {
94         // Make the list of all available bibliography keys
95         bibkeys = biblio::getKeys(controller().bibkeysInfo());
96         updateBrowser(dialog_->bibLB, bibkeys);
97         
98         // Ditto for the keys cited in this inset
99         citekeys = getVectorFromString(controller().params().getContents());
100         updateBrowser(dialog_->citeLB, citekeys);
101
102         // No keys have been selected yet, so...
103         dialog_->infoML->clear();
104         setBibButtons(OFF);
105         setCiteButtons(OFF);
106
107         dialog_->textAfterED->setText(controller().params().getOptions().c_str());
108
109         reset();
110 }
111
112
113 void QCitation::updateBrowser(QListBox* browser,
114                                   vector<string> const & keys) const
115 {
116         browser->clear();
117
118         for (vector<string>::const_iterator it = keys.begin();
119                 it < keys.end(); ++it) {
120                 string const key = frontStrip(strip(*it));
121                 // FIXME: why the .empty() test ?
122                 if(!key.empty())
123                         browser->insertItem(key.c_str());
124         }
125 }
126
127
128 void QCitation::setBibButtons(State status) const
129 {
130         dialog_->addPB->setEnabled((status == ON));
131 }
132
133
134 void QCitation::setCiteButtons(State status) const
135 {
136         int const sel = dialog_->citeLB->currentItem();
137         int const maxline = dialog_->citeLB->count() - 1;
138         bool const activate = (status == ON);
139         bool const activate_up = (activate && sel != 0);
140         bool const activate_down = (activate && sel != maxline);
141
142         dialog_->delPB->setEnabled(activate);
143         dialog_->upPB->setEnabled(activate_up);
144         dialog_->downPB->setEnabled(activate_down);
145 }