3 * Copyright 2001 the LyX Team
4 * Read the file COPYING
6 * \author Angus Leeming
12 #include FORMS_H_LOCATION
15 #pragma implementation
20 #include "FormBibitem.h"
23 #include "form_bibitem.h"
29 FormBibitem::FormBibitem(LyXView * lv, Dialogs * d)
30 : FormCommand(lv, d, _("Bibliography Entry"), new OkCancelReadOnlyPolicy),
33 d->showBibitem.connect(slot(this, &FormBibitem::showInset));
37 FormBibitem::~FormBibitem()
43 FL_FORM * FormBibitem::form() const
51 void FormBibitem::connect()
53 fl_set_form_maxsize(form(), 2 * minw_, minh_);
54 FormCommand::connect();
58 void FormBibitem::build()
60 dialog_ = build_bibitem();
62 // Workaround dumb xforms sizing bug
66 fl_set_input_return(dialog_->key, FL_RETURN_CHANGED);
67 fl_set_input_return(dialog_->label, FL_RETURN_CHANGED);
69 // Manage the ok, apply, restore and cancel/close buttons
70 bc_.setOK(dialog_->button_ok);
71 bc_.setCancel(dialog_->button_cancel);
74 bc_.addReadOnly(dialog_->key);
75 bc_.addReadOnly(dialog_->label);
79 bool FormBibitem::input(FL_OBJECT *, long)
82 if (!compare(fl_get_input(dialog_->key), ""))
89 void FormBibitem::update()
91 fl_set_input(dialog_->key, params.getContents().c_str());
92 fl_set_input(dialog_->label, params.getOptions().c_str());
93 // Surely, this should reset the buttons to their original state?
94 // It doesn't. Instead "Restore" becomes a "Close"
96 bc_.readOnly(lv_->buffer()->isReadonly());
100 void FormBibitem::apply()
102 if (lv_->buffer()->isReadonly())
105 params.setContents(fl_get_input(dialog_->key));
106 params.setOptions(fl_get_input(dialog_->label));
109 // Only update if contents have changed
110 if (params != inset_->params()) {
111 // FIXME: confirm, is this only necessary for FormBibTeX ???
112 if (params.getContents() != inset_->params().getContents())
113 lv_->view()->ChangeCitationsIfUnique(
114 inset_->params().getContents(), params.getContents());
116 inset_->setParams(params);
117 lv_->view()->updateInset(inset_, true);
119 // We need to do a redraw because the maximum
120 // InsetBibKey width could have changed
121 lv_->view()->redraw();
122 lv_->view()->fitCursor(lv_->view()->getLyXText());
125 lyxerr[Debug::GUI] << "Editing non-existent bibitem !" << endl;