2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2000 The LyX Team.
9 * ======================================================
11 * \author Angus Leeming <a.leeming@ic.ac.uk>
17 #pragma implementation
20 #include "FormCitationDialogImpl.h"
21 #include "FormCitation.h"
23 #include <qcheckbox.h>
24 #include <qcombobox.h>
25 #include <qlineedit.h>
27 #include <qmultilineedit.h>
28 #include <qpushbutton.h>
32 #include "ControlCitation.h"
34 #include "support/lstrings.h"
35 #include "helper_funcs.h"
45 typedef Qt2CB<ControlCitation, Qt2DB<FormCitationDialogImpl> > base_class;
47 FormCitation::FormCitation(ControlCitation & c)
48 : base_class(c, _("Citation"))
52 void FormCitation::apply()
54 controller().params().setCmdName("cite");
55 controller().params().setContents(getStringFromVector(citekeys));
57 string const after = dialog_->textAfterED->text().latin1();
58 controller().params().setOptions(after);
62 void FormCitation::hide()
71 void FormCitation::build()
73 // PENDING(kalle) Parent?
74 dialog_.reset( new FormCitationDialogImpl( this ));
76 dialog_->searchTypeCB->setChecked( false );
77 dialog_->searchCaseCB->setChecked( false );
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);
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);
97 void FormCitation::update()
99 // Make the list of all available bibliography keys
100 bibkeys = biblio::getKeys(controller().bibkeysInfo());
101 updateBrowser(dialog_->bibLB, bibkeys);
103 // Ditto for the keys cited in this inset
104 citekeys = getVectorFromString(controller().params().getContents());
105 updateBrowser(dialog_->citeLB, citekeys);
107 // No keys have been selected yet, so...
108 dialog_->infoML->clear();
112 int noKeys = int(max(bibkeys.size(), citekeys.size()));
114 // Place bounds, so that 4 <= noKeys <= 10
115 noKeys = max(4, min(10, noKeys));
117 dialog_->textAfterED->setText( controller().params().getOptions().c_str());
121 void FormCitation::updateBrowser( QListBox* browser,
122 vector<string> const & keys) const
126 for (vector<string>::const_iterator it = keys.begin();
127 it < keys.end(); ++it) {
128 string key = frontStrip(strip(*it));
130 browser->insertItem( key.c_str() );
135 void FormCitation::setBibButtons(State status) const
137 dialog_->addPB->setEnabled( (status == ON) );
141 void FormCitation::setCiteButtons(State status) const
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);
149 dialog_->delPB->setEnabled( activate );
150 dialog_->upPB->setEnabled( activate_up );
151 dialog_->downPB->setEnabled( activate_down );