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