]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBibitem.C
try this for distinguishing inner and outer tabs
[lyx.git] / src / frontends / xforms / FormBibitem.C
1 /**
2  * \file FormBibitem.C
3  * Copyright 2001 the LyX Team
4  * Read the file COPYING
5  *
6  * \author Angus Leeming
7  * \author John Levon
8  */
9
10 #include <config.h>
11
12 #include FORMS_H_LOCATION
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18
19 #include "Dialogs.h"
20 #include "FormBibitem.h"
21 #include "LyXView.h"
22 #include "buffer.h"
23 #include "form_bibitem.h"
24 #include "lyxfunc.h"
25 #include "debug.h"
26
27 using std::endl;
28
29 FormBibitem::FormBibitem(LyXView * lv, Dialogs * d)
30         : FormCommand(lv, d, _("Bibliography Entry"), new OkCancelReadOnlyPolicy),
31           dialog_(0)
32 {
33         d->showBibitem.connect(slot(this, &FormBibitem::showInset));
34 }
35
36
37 FormBibitem::~FormBibitem()
38 {
39         delete dialog_;
40 }
41
42
43 FL_FORM * FormBibitem::form() const
44 {
45         if (dialog_)
46                 return dialog_->form;
47         return 0;
48 }
49
50
51 void FormBibitem::connect()
52 {
53         fl_set_form_maxsize(form(), 2 * minw_, minh_);
54         FormCommand::connect();
55 }
56         
57
58 void FormBibitem::build()
59 {
60         dialog_ = build_bibitem();
61
62         // Workaround dumb xforms sizing bug
63         minw_ = form()->w;
64         minh_ = form()->h;
65
66         fl_set_input_return(dialog_->key, FL_RETURN_CHANGED);
67         fl_set_input_return(dialog_->label, FL_RETURN_CHANGED);
68
69         // Manage the ok, apply, restore and cancel/close buttons
70         bc_.setOK(dialog_->button_ok);
71         bc_.setCancel(dialog_->button_cancel);
72         bc_.refresh();
73
74         bc_.addReadOnly(dialog_->key);
75         bc_.addReadOnly(dialog_->label);
76 }
77
78
79 bool FormBibitem::input(FL_OBJECT *, long)
80 {
81         // minimal validation 
82         if (!compare(fl_get_input(dialog_->key), ""))
83                 return false;
84
85         return true;
86 }
87
88
89 void FormBibitem::update()
90 {
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"
95         //bc_.refresh();
96         bc_.readOnly(lv_->buffer()->isReadonly());
97 }
98
99
100 void FormBibitem::apply()
101 {
102         if (lv_->buffer()->isReadonly())
103                 return;
104
105         params.setContents(fl_get_input(dialog_->key));
106         params.setOptions(fl_get_input(dialog_->label));
107
108         if (inset_ != 0) {
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());
115
116                 inset_->setParams(params);
117                 lv_->view()->updateInset(inset_, true);
118
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());
123                 }
124         } else
125                 lyxerr[Debug::GUI] << "Editing non-existent bibitem !" << endl;
126 }