]> git.lyx.org Git - features.git/blob - src/frontends/xforms/FormIndex.C
a0a6e3f025e95abafb4802042d25d73c605312bd
[features.git] / src / frontends / xforms / FormIndex.C
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  *
5  *           LyX, The Document Processor
6  *
7  *           Copyright 2000 The LyX Team.
8  *
9  * ======================================================
10  */
11
12 #include <config.h>
13
14 #include FORMS_H_LOCATION
15
16 #ifdef __GNUG__
17 #pragma implementation
18 #endif
19
20
21 #include "Dialogs.h"
22 #include "FormIndex.h"
23 #include "LyXView.h"
24 #include "buffer.h"
25 #include "form_index.h"
26 #include "lyxfunc.h"
27
28 FormIndex::FormIndex(LyXView * lv, Dialogs * d)
29         : FormCommand(lv, d, _("Index"))
30 {
31         // let the dialog be shown
32         // These are permanent connections so we won't bother
33         // storing a copy because we won't be disconnecting.
34         d->showIndex.connect(slot(this, &FormIndex::showInset));
35         d->createIndex.connect(slot(this, &FormIndex::createInset));
36 }
37
38
39 FL_FORM * FormIndex::form() const
40 {
41         if (dialog_.get()) return dialog_->form;
42         return 0;
43 }
44
45
46 void FormIndex::connect()
47 {
48         fl_set_form_maxsize(form(), 2 * minw_, minh_);
49         FormCommand::connect();
50 }
51         
52
53 void FormIndex::build()
54 {
55         dialog_.reset(build_index());
56
57         // Workaround dumb xforms sizing bug
58         minw_ = form()->w;
59         minh_ = form()->h;
60
61         fl_set_input_return(dialog_->input_key, FL_RETURN_CHANGED);
62
63         // Manage the ok, apply, restore and cancel/close buttons
64         bc().setOK(dialog_->button_ok);
65         bc().setApply(dialog_->button_apply);
66         bc().setCancel(dialog_->button_cancel);
67         bc().setUndoAll(dialog_->button_restore);
68         bc().refresh();
69
70         bc().addReadOnly(dialog_->input_key);
71 }
72
73
74 void FormIndex::update()
75 {
76         fl_set_input(dialog_->input_key, params.getContents().c_str());
77         // Surely, this should reset the buttons to their original state?
78         // It doesn't. Instead "Restore" becomes a "Close"
79         //bc().refresh();
80         bc().readOnly(lv_->buffer()->isReadonly());
81 }
82
83
84 void FormIndex::apply()
85 {
86         if (lv_->buffer()->isReadonly()) return;
87
88         params.setContents(fl_get_input(dialog_->input_key));
89
90         if (inset_ != 0) {
91                 // Only update if contents have changed
92                 if (params != inset_->params()) {
93                         inset_->setParams(params);
94                         lv_->view()->updateInset(inset_, true);
95                 }
96         } else {
97                 lv_->getLyXFunc()->Dispatch(LFUN_INDEX_INSERT,
98                                             params.getAsString());
99         }
100 }