1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000 The LyX Team.
8 * ======================================================
10 * \author Angus Leeming <a.leeming@ic.ac.uk>
16 #pragma implementation
19 #include "FormCitationDialogImpl.h"
20 #include "FormCitation.h"
22 #include <qcheckbox.h>
23 #include <qcombobox.h>
24 #include <qlineedit.h>
26 #include <qmultilineedit.h>
27 #include <qpushbutton.h>
31 #include "ControlCitation.h"
33 #include "support/lstrings.h"
34 #include "helper_funcs.h"
44 typedef Qt2CB<ControlCitation, Qt2DB<FormCitationDialogImpl> > base_class;
46 FormCitation::FormCitation(ControlCitation & c)
47 : base_class(c, _("Citation"))
51 void FormCitation::apply()
53 controller().params().setCmdName("cite");
54 controller().params().setContents(getStringFromVector(citekeys));
56 string const after = dialog_->textAfterED->text().latin1();
57 controller().params().setOptions(after);
61 void FormCitation::hide()
70 void FormCitation::build()
72 // PENDING(kalle) Parent?
73 dialog_.reset( new FormCitationDialogImpl( this ));
75 dialog_->searchTypeCB->setChecked( false );
76 dialog_->searchCaseCB->setChecked( false );
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().setRestore(dialog_->restorePB);
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);
96 void FormCitation::update()
98 // Make the list of all available bibliography keys
99 bibkeys = biblio::getKeys(controller().bibkeysInfo());
100 updateBrowser(dialog_->bibLB, bibkeys);
102 // Ditto for the keys cited in this inset
103 citekeys = getVectorFromString(controller().params().getContents());
104 updateBrowser(dialog_->citeLB, citekeys);
106 // No keys have been selected yet, so...
107 dialog_->infoML->clear();
111 int noKeys = int(max(bibkeys.size(), citekeys.size()));
113 // Place bounds, so that 4 <= noKeys <= 10
114 noKeys = max(4, min(10, noKeys));
116 dialog_->textAfterED->setText( controller().params().getOptions().c_str());
120 void FormCitation::updateBrowser( QListBox* browser,
121 vector<string> const & keys) const
125 for (vector<string>::const_iterator it = keys.begin();
126 it < keys.end(); ++it) {
127 string key = frontStrip(strip(*it));
129 browser->insertItem( key.c_str() );
134 void FormCitation::setBibButtons(State status) const
136 dialog_->addPB->setEnabled( (status == ON) );
140 void FormCitation::setCiteButtons(State status) const
142 int const sel = dialog_->citeLB->currentItem();
143 int const maxline = dialog_->citeLB->count()-1;
144 bool const activate = (status == ON);
145 bool const activate_up = (activate && sel != 0);
146 bool const activate_down = (activate && sel != maxline);
148 dialog_->delPB->setEnabled( activate );
149 dialog_->upPB->setEnabled( activate_up );
150 dialog_->downPB->setEnabled( activate_down );