]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBibtex.C
d877eddf4c6bbd88118671d32eda80dbe55effc9
[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"))
31 {
32         d->showBibtex.connect(slot(this, &FormBibtex::showInset));
33 }
34
35
36 FL_FORM * FormBibtex::form() const
37 {
38         if (dialog_.get())
39                 return dialog_->form;
40         return 0;
41 }
42
43
44 void FormBibtex::connect()
45 {
46         fl_set_form_maxsize(form(), 2 * minw_, minh_);
47         FormCommand::connect();
48 }
49         
50
51 void FormBibtex::build()
52 {
53         dialog_.reset(build_bibtex());
54
55         // Workaround dumb xforms sizing bug
56         minw_ = form()->w;
57         minh_ = form()->h;
58
59         fl_set_input_return(dialog_->database, FL_RETURN_CHANGED);
60         fl_set_input_return(dialog_->style, FL_RETURN_CHANGED);
61
62         // Manage the ok, apply, restore and cancel/close buttons
63         bc().setOK(dialog_->button_ok);
64         bc().setCancel(dialog_->button_cancel);
65         bc().refresh();
66
67         bc().addReadOnly(dialog_->database);
68         bc().addReadOnly(dialog_->style);
69 }
70
71
72 bool FormBibtex::input(FL_OBJECT *, long)
73 {
74         // minimal validation 
75         if (!compare(fl_get_input(dialog_->database),""))
76                 return false;
77
78         return true;
79 }
80
81
82 void FormBibtex::update()
83 {
84         fl_set_input(dialog_->database, params.getContents().c_str());
85         fl_set_input(dialog_->style, params.getOptions().c_str());
86         // Surely, this should reset the buttons to their original state?
87         // It doesn't. Instead "Restore" becomes a "Close"
88         //bc().refresh();
89         bc().readOnly(lv_->buffer()->isReadonly());
90 }
91
92
93 void FormBibtex::apply()
94 {
95         if (lv_->buffer()->isReadonly())
96                 return;
97
98         params.setContents(fl_get_input(dialog_->database));
99         params.setOptions(fl_get_input(dialog_->style));
100
101         if (inset_ != 0) {
102                 // Only update if contents have changed
103                 if (params != inset_->params()) {
104                         if (params.getContents() != inset_->params().getContents())
105                                 lv_->view()->ChangeCitationsIfUnique(
106                                         inset_->params().getContents(), params.getContents());
107
108                 inset_->setParams(params);
109                 lv_->view()->updateInset(inset_, true);
110
111                 // We need to do a redraw because the maximum
112                 // InsetBibKey width could have changed
113                 lv_->view()->redraw();
114                 lv_->view()->fitCursor(lv_->view()->getLyXText());
115                 }
116         } else
117                 lyxerr[Debug::GUI] << "Editing non-existent bibtex inset !" << endl;
118 }