]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormIndex.C
update patch from Angus
[lyx.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"), new NoRepeatedApplyPolicy),
30           dialog_(0)
31 {
32         // let the dialog be shown
33         // These are permanent connections so we won't bother
34         // storing a copy because we won't be disconnecting.
35         d->showIndex.connect(slot(this, &FormIndex::showInset));
36         d->createIndex.connect(slot(this, &FormIndex::createInset));
37 }
38
39
40 FormIndex::~FormIndex()
41 {
42         delete dialog_;
43 }
44
45
46 FL_FORM * FormIndex::form() const
47 {
48         if (dialog_) return dialog_->form;
49         return 0;
50 }
51
52
53 void FormIndex::connect()
54 {
55         fl_set_form_maxsize(form(), 2 * minw_, minh_);
56         FormCommand::connect();
57 }
58         
59
60 void FormIndex::build()
61 {
62         dialog_ = build_index();
63
64         // Workaround dumb xforms sizing bug
65         minw_ = form()->w;
66         minh_ = form()->h;
67
68         fl_set_input_return(dialog_->input_key, FL_RETURN_CHANGED);
69
70         // Manage the ok, apply, restore and cancel/close buttons
71         bc_.setOK(dialog_->button_ok);
72         bc_.setApply(dialog_->button_apply);
73         bc_.setCancel(dialog_->button_cancel);
74         bc_.setUndoAll(dialog_->button_restore);
75         bc_.refresh();
76
77         bc_.addReadOnly(dialog_->input_key);
78 }
79
80
81 void FormIndex::update()
82 {
83         fl_set_input(dialog_->input_key, params.getContents().c_str());
84         // Surely, this should reset the buttons to their original state?
85         // It doesn't. Instead "Restore" becomes a "Close"
86         //bc_.refresh();
87         bc_.readOnly(lv_->buffer()->isReadonly());
88 }
89
90
91 void FormIndex::apply()
92 {
93         if (lv_->buffer()->isReadonly()) return;
94
95         params.setContents(fl_get_input(dialog_->input_key));
96
97         if (inset_ != 0) {
98                 // Only update if contents have changed
99                 if (params != inset_->params()) {
100                         inset_->setParams(params);
101                         lv_->view()->updateInset(inset_, true);
102                 }
103         } else {
104                 lv_->getLyXFunc()->Dispatch(LFUN_INDEX_INSERT,
105                                             params.getAsString());
106         }
107 }