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