]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBibtex.C
b062d719a12bd0868b97f9f48214b1b52da48ed6
[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         fl_set_input_return(dialog_->database, FL_RETURN_CHANGED);
57         fl_set_input_return(dialog_->style, FL_RETURN_CHANGED);
58
59         // Manage the ok, apply, restore and cancel/close buttons
60         bc().setOK(dialog_->button_ok);
61         bc().setCancel(dialog_->button_cancel);
62         bc().refresh();
63
64         bc().addReadOnly(dialog_->database);
65         bc().addReadOnly(dialog_->style);
66 }
67
68
69 bool FormBibtex::input(FL_OBJECT *, long)
70 {
71         // minimal validation 
72         if (!compare(fl_get_input(dialog_->database),""))
73                 return false;
74
75         return true;
76 }
77
78
79 void FormBibtex::update()
80 {
81         fl_set_input(dialog_->database, params.getContents().c_str());
82         fl_set_input(dialog_->style, params.getOptions().c_str());
83         // Surely, this should reset the buttons to their original state?
84         // It doesn't. Instead "Restore" becomes a "Close"
85         //bc().refresh();
86         bc().readOnly(lv_->buffer()->isReadonly());
87 }
88
89
90 void FormBibtex::apply()
91 {
92         if (lv_->buffer()->isReadonly())
93                 return;
94
95         params.setContents(fl_get_input(dialog_->database));
96         params.setOptions(fl_get_input(dialog_->style));
97
98         if (inset_ != 0) {
99                 // Only update if contents have changed
100                 if (params != inset_->params()) {
101                         if (params.getContents() != inset_->params().getContents())
102                                 lv_->view()->ChangeCitationsIfUnique(
103                                         inset_->params().getContents(), params.getContents());
104
105                 inset_->setParams(params);
106                 lv_->view()->updateInset(inset_, true);
107
108                 // We need to do a redraw because the maximum
109                 // InsetBibKey width could have changed
110                 lv_->view()->redraw();
111                 lv_->view()->fitCursor(lv_->view()->getLyXText());
112                 }
113         } else
114                 lyxerr[Debug::GUI] << "Editing non-existent bibtex inset !" << endl;
115 }