]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/FormIndex.C
implement getLabelList
[lyx.git] / src / frontends / qt2 / FormIndex.C
1 /*
2  * FormIndex.C
3  * (C) 2000 LyX Team
4  * John Levon, moz@compsoc.man.ac.uk
5  */
6  
7 /***************************************************************************
8  *                                                                         *
9  *   This program is free software; you can redistribute it and/or modify  *
10  *   it under the terms of the GNU General Public License as published by  *
11  *   the Free Software Foundation; either version 2 of the License, or     *
12  *   (at your option) any later version.                                   *
13  *                                                                         *
14  ***************************************************************************/
15
16 #include <config.h>
17
18 #include "FormIndexDialog.h"
19 #undef emit
20
21 #include "Dialogs.h"
22 #include "FormIndex.h"
23 #include "gettext.h"
24 #include "buffer.h"
25 #include "LyXView.h"
26 #include "lyxfunc.h" 
27
28 #include <qlineedit.h>
29 #include <qpushbutton.h>
30
31 FormIndex::FormIndex(LyXView *v, Dialogs *d)
32         : dialog_(0), lv_(v), d_(d), inset_(0), h_(0), u_(0), ih_(0)
33 {
34         // let the dialog be shown
35         // This is a permanent connection so we won't bother
36         // storing a copy because we won't be disconnecting.
37         d->showIndex.connect(slot(this, &FormIndex::showIndex));
38         d->createIndex.connect(slot(this, &FormIndex::createIndex));
39 }
40
41 FormIndex::~FormIndex()
42 {
43         delete dialog_;
44 }
45
46 void FormIndex::showIndex(InsetCommand * const inset)
47 {
48         // FIXME: when could inset be 0 here ?
49         if (inset==0)
50                 return;
51
52         inset_ = inset;
53         readonly = lv_->buffer()->isReadonly();
54         ih_ = inset_->hide.connect(slot(this,&FormIndex::hide));
55         params = inset->params();
56         
57         show();
58 }
59  
60 void FormIndex::createIndex(string const & arg)
61 {
62         // we could already be showing a URL, clear it out
63         if (inset_)
64                 close();
65  
66         readonly = lv_->buffer()->isReadonly();
67         params.setFromString(arg);
68         show();
69 }
70  
71 void FormIndex::update()
72 {
73         dialog_->keywordED->setText(params.getContents().c_str());
74
75         if (readonly) {
76                 dialog_->keywordED->setFocusPolicy(QWidget::NoFocus);
77                 dialog_->okPB->setEnabled(false);
78                 dialog_->cancelPB->setText(_("Close"));
79         } else {
80                 dialog_->keywordED->setFocusPolicy(QWidget::StrongFocus);
81                 dialog_->keywordED->setFocus();
82                 dialog_->okPB->setEnabled(true);
83                 dialog_->cancelPB->setText(_("Cancel"));
84         }
85 }
86  
87 void FormIndex::apply()
88 {
89         if (readonly)
90                 return;
91
92         params.setContents(dialog_->keywordED->text().latin1());
93
94         if (inset_ != 0) {
95                 if (params != inset_->params()) {
96                         inset_->setParams(params);
97                         lv_->view()->updateInset(inset_, true);
98                 }
99         } else
100                 lv_->getLyXFunc()->Dispatch(LFUN_INDEX_INSERT, params.getAsString().c_str());
101 }
102  
103 void FormIndex::show()
104 {
105         if (!dialog_)
106                 dialog_ = new FormIndexDialog(this, 0, _("LyX: Index"), false);
107  
108         if (!dialog_->isVisible()) {
109                 h_ = d_->hideBufferDependent.connect(slot(this, &FormIndex::hide));
110                 u_ = d_->updateBufferDependent.connect(slot(this, &FormIndex::update));
111         }
112
113         dialog_->raise();
114         dialog_->setActiveWindow();
115  
116         update();
117         dialog_->show();
118 }
119
120 void FormIndex::close()
121 {
122         h_.disconnect();
123         u_.disconnect();
124         ih_.disconnect();
125         inset_ = 0;
126 }
127  
128 void FormIndex::hide()
129 {
130         dialog_->hide();
131         close();
132 }