]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBibtex.C
try this for distinguishing inner and outer tabs
[lyx.git] / src / frontends / xforms / FormBibtex.C
1 /**
2  * \file FormBibtex.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 "FormBibtex.h"
21 #include "LyXView.h"
22 #include "buffer.h"
23 #include "form_bibtex.h"
24 #include "lyxfunc.h"
25 #include "debug.h"
26
27 using std::endl;
28
29 FormBibtex::FormBibtex(LyXView * lv, Dialogs * d)
30         : FormCommand(lv, d, _("BibTeX Database"), new OkCancelReadOnlyPolicy),
31           dialog_(0)
32 {
33         d->showBibtex.connect(slot(this, &FormBibtex::showInset));
34 }
35
36
37 FormBibtex::~FormBibtex()
38 {
39         delete dialog_;
40 }
41
42
43 FL_FORM * FormBibtex::form() const
44 {
45         if (dialog_)
46                 return dialog_->form;
47         return 0;
48 }
49
50
51 void FormBibtex::connect()
52 {
53         fl_set_form_maxsize(form(), 2 * minw_, minh_);
54         FormCommand::connect();
55 }
56         
57
58 void FormBibtex::build()
59 {
60         dialog_ = build_bibtex();
61
62         // Workaround dumb xforms sizing bug
63         minw_ = form()->w;
64         minh_ = form()->h;
65
66         fl_set_input_return(dialog_->database, FL_RETURN_CHANGED);
67         fl_set_input_return(dialog_->style, 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_->database);
75         bc_.addReadOnly(dialog_->style);
76 }
77
78
79 bool FormBibtex::input(FL_OBJECT *, long)
80 {
81         // minimal validation 
82         if (!compare(fl_get_input(dialog_->database),""))
83                 return false;
84
85         return true;
86 }
87
88
89 void FormBibtex::update()
90 {
91         fl_set_input(dialog_->database, params.getContents().c_str());
92         fl_set_input(dialog_->style, 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 FormBibtex::apply()
101 {
102         if (lv_->buffer()->isReadonly())
103                 return;
104
105         params.setContents(fl_get_input(dialog_->database));
106         params.setOptions(fl_get_input(dialog_->style));
107
108         if (inset_ != 0) {
109                 // Only update if contents have changed
110                 if (params != inset_->params()) {
111                         if (params.getContents() != inset_->params().getContents())
112                                 lv_->view()->ChangeCitationsIfUnique(
113                                         inset_->params().getContents(), params.getContents());
114
115                 inset_->setParams(params);
116                 lv_->view()->updateInset(inset_, true);
117
118                 // We need to do a redraw because the maximum
119                 // InsetBibKey width could have changed
120                 lv_->view()->redraw();
121                 lv_->view()->fitCursor(lv_->view()->getLyXText());
122                 }
123         } else
124                 lyxerr[Debug::GUI] << "Editing non-existent bibtex inset !" << endl;
125 }