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