]> git.lyx.org Git - lyx.git/blob - src/frontends/kde/FormIndex.C
small cleanup, doxygen, formatting changes
[lyx.git] / src / frontends / kde / FormIndex.C
1 /**
2  * \file FormIndex.C
3  * Copyright 2001 the LyX Team
4  * Read the file COPYING
5  *
6  * \author John Levon
7  */
8
9 #include <config.h>
10
11 #include "Dialogs.h"
12 #include "FormIndex.h"
13 #include "gettext.h"
14 #include "buffer.h"
15 #include "LyXView.h"
16 #include "lyxfunc.h" 
17 #include "indexdlg.h"
18
19 FormIndex::FormIndex(LyXView *v, Dialogs *d)
20         : dialog_(0), lv_(v), d_(d), inset_(0), h_(0), u_(0), ih_(0)
21 {
22         d->showIndex.connect(slot(this, &FormIndex::showIndex));
23         d->createIndex.connect(slot(this, &FormIndex::createIndex));
24 }
25
26
27 FormIndex::~FormIndex()
28 {
29         delete dialog_;
30 }
31
32
33 void FormIndex::showIndex(InsetCommand * const inset)
34 {
35         // FIXME: when could inset be 0 here ?
36         if (inset==0)
37                 return;
38
39         inset_ = inset;
40         readonly = lv_->buffer()->isReadonly();
41         ih_ = inset_->hide.connect(slot(this,&FormIndex::hide));
42         params = inset->params();
43         
44         show();
45 }
46
47  
48 void FormIndex::createIndex(string const & arg)
49 {
50         // we could already be showing an index entry, clear it out
51         if (inset_)
52                 close();
53  
54         readonly = lv_->buffer()->isReadonly();
55         params.setFromString(arg);
56         show();
57 }
58
59  
60 void FormIndex::update(bool switched)
61 {
62         if (switched) {
63                 hide();
64                 return;
65         }
66
67         dialog_->setIndexText(params.getContents().c_str());
68         dialog_->setReadOnly(readonly);
69 }
70
71  
72 void FormIndex::apply()
73 {
74         if (readonly)
75                 return;
76
77         params.setContents(dialog_->getIndexText());
78
79         if (inset_ != 0) {
80                 if (params != inset_->params()) {
81                         inset_->setParams(params);
82                         lv_->view()->updateInset(inset_, true);
83                 }
84         } else
85                 lv_->getLyXFunc()->Dispatch(LFUN_INDEX_INSERT, params.getAsString().c_str());
86 }
87
88  
89 void FormIndex::show()
90 {
91         if (!dialog_)
92                 dialog_ = new IndexDialog(this, 0, _("LyX: Index"));
93  
94         if (!dialog_->isVisible()) {
95                 h_ = d_->hideBufferDependent.connect(slot(this, &FormIndex::hide));
96                 u_ = d_->updateBufferDependent.connect(slot(this, &FormIndex::update));
97         }
98
99         dialog_->raise();
100         dialog_->setActiveWindow();
101  
102         update();
103         dialog_->show();
104 }
105
106
107 void FormIndex::close()
108 {
109         h_.disconnect();
110         u_.disconnect();
111         ih_.disconnect();
112         inset_ = 0;
113 }
114
115  
116 void FormIndex::hide()
117 {
118         dialog_->hide();
119         close();
120 }