]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QCitation.C
qt2 ert dialog
[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_dialog()
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_contents()
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
110
111 void QCitation::updateBrowser(QListBox* browser,
112                                   vector<string> const & keys) const
113 {
114         browser->clear();
115
116         for (vector<string>::const_iterator it = keys.begin();
117                 it < keys.end(); ++it) {
118                 string const key = frontStrip(strip(*it));
119                 // FIXME: why the .empty() test ?
120                 if(!key.empty())
121                         browser->insertItem(key.c_str());
122         }
123 }
124
125
126 void QCitation::setBibButtons(State status) const
127 {
128         dialog_->addPB->setEnabled((status == ON));
129 }
130
131
132 void QCitation::setCiteButtons(State status) const
133 {
134         int const sel = dialog_->citeLB->currentItem();
135         int const maxline = dialog_->citeLB->count() - 1;
136         bool const activate = (status == ON);
137         bool const activate_up = (activate && sel != 0);
138         bool const activate_down = (activate && sel != maxline);
139
140         dialog_->delPB->setEnabled(activate);
141         dialog_->upPB->setEnabled(activate_up);
142         dialog_->downPB->setEnabled(activate_down);
143 }