]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QIndex.C
The big renaming. Yowser.
[lyx.git] / src / frontends / qt2 / QIndex.C
1 /**
2  * \file QIndex.C
3  * Copyright 2001 the LyX Team
4  * Read the file COPYING
5  *
6  * \author John Levon <moz@compsoc.man.ac.uk>
7  */
8
9 #include <config.h>
10
11 #include "QIndexDialog.h"
12 #include "QtLyXView.h" 
13 #include "BufferView.h"
14
15 #include "Dialogs.h"
16 #include "QIndex.h"
17 #include "gettext.h"
18 #include "buffer.h"
19 #include "lyxfunc.h" 
20
21 #include <qlineedit.h>
22 #include <qpushbutton.h>
23
24 QIndex::QIndex(LyXView *v, Dialogs *d)
25         : dialog_(0), lv_(v), d_(d), inset_(0), h_(0), u_(0), ih_(0)
26 {
27         d->showIndex.connect(slot(this, &QIndex::showIndex));
28         d->createIndex.connect(slot(this, &QIndex::createIndex));
29 }
30
31
32 QIndex::~QIndex()
33 {
34         delete dialog_;
35 }
36
37
38 void QIndex::showIndex(InsetCommand * const inset)
39 {
40         // FIXME: when could inset be 0 here ?
41         if (inset==0)
42                 return;
43
44         inset_ = inset;
45         readonly = lv_->buffer()->isReadonly();
46         //FIXME ih_ = inset_->hide.connect(slot(this,&QIndex::hide));
47         params = inset->params();
48         
49         show();
50 }
51
52  
53 void QIndex::createIndex(string const & arg)
54 {
55         // we could already be showing a URL, clear it out
56         if (inset_)
57                 close();
58  
59         readonly = lv_->buffer()->isReadonly();
60         params.setFromString(arg);
61         show();
62 }
63
64  
65 void QIndex::update()
66 {
67         dialog_->keywordED->setText(params.getContents().c_str());
68
69         if (readonly) {
70                 dialog_->keywordED->setFocusPolicy(QWidget::NoFocus);
71                 dialog_->okPB->setEnabled(false);
72                 dialog_->cancelPB->setText(_("Close"));
73         } else {
74                 dialog_->keywordED->setFocusPolicy(QWidget::StrongFocus);
75                 dialog_->keywordED->setFocus();
76                 dialog_->okPB->setEnabled(true);
77                 dialog_->cancelPB->setText(_("Cancel"));
78         }
79 }
80
81  
82 void QIndex::apply()
83 {
84         if (readonly)
85                 return;
86
87         params.setContents(dialog_->keywordED->text().latin1());
88
89         if (inset_ != 0) {
90                 if (params != inset_->params()) {
91                         inset_->setParams(params);
92                         lv_->view()->updateInset(inset_, true);
93                 }
94         } else
95                 lv_->getLyXFunc()->dispatch(LFUN_INDEX_INSERT, params.getAsString().c_str());
96 }
97
98  
99 void QIndex::show()
100 {
101         if (!dialog_)
102                 dialog_ = new QIndexDialog(this, 0, _("LyX: Index"), false);
103  
104         if (!dialog_->isVisible()) {
105                 h_ = d_->hideBufferDependent.connect(slot(this, &QIndex::hide));
106                 //u_ = d_->updateBufferDependent.connect(slot(this, &QIndex::update));
107         }
108
109         dialog_->raise();
110         dialog_->setActiveWindow();
111  
112         update();
113         dialog_->show();
114 }
115
116
117 void QIndex::close()
118 {
119         h_.disconnect();
120         u_.disconnect();
121         ih_.disconnect();
122         inset_ = 0;
123 }
124
125  
126 void QIndex::hide()
127 {
128         dialog_->hide();
129         close();
130 }