]> git.lyx.org Git - lyx.git/blob - src/frontends/kde/FormIndex.C
Angus's FormInset work; Dekel's languages patch; my reworking of Angus's stuff +...
[lyx.git] / src / frontends / kde / 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 "Dialogs.h"
19 #include "FormIndex.h"
20 #include "gettext.h"
21 #include "buffer.h"
22 #include "LyXView.h"
23 #include "lyxfunc.h" 
24 #include "formindexdialog.h"
25
26 FormIndex::FormIndex(LyXView *v, Dialogs *d)
27         : dialog_(0), lv_(v), d_(d), inset_(0), h_(0), u_(0), ih_(0)
28 {
29         // let the dialog be shown
30         // This is a permanent connection so we won't bother
31         // storing a copy because we won't be disconnecting.
32         d->showIndex.connect(slot(this, &FormIndex::showIndex));
33         d->createIndex.connect(slot(this, &FormIndex::createIndex));
34 }
35
36 FormIndex::~FormIndex()
37 {
38         delete dialog_;
39 }
40
41 void FormIndex::showIndex(InsetCommand * const inset)
42 {
43         // FIXME: when could inset be 0 here ?
44         if (inset==0)
45                 return;
46
47         inset_ = inset;
48         readonly = lv_->buffer()->isReadonly();
49         ih_ = inset_->hide.connect(slot(this,&FormIndex::hide));
50         params = inset->params();
51         
52         show();
53 }
54  
55 void FormIndex::createIndex(string const & arg)
56 {
57         // we could already be showing a URL, clear it out
58         if (inset_)
59                 close();
60  
61         readonly = lv_->buffer()->isReadonly();
62         params.setFromString(arg);
63         show();
64 }
65  
66 void FormIndex::update(bool switched)
67 {
68         if (switched) {
69                 hide();
70                 return;
71         }
72
73         dialog_->setIndexText(params.getContents().c_str());
74 //      dialog_->setReadOnly(readonly);
75 }
76  
77 void FormIndex::apply()
78 {
79         if (readonly)
80                 return;
81
82         params.setContents(dialog_->getIndexText());
83
84         if (inset_ != 0) {
85                 if (params != inset_->params()) {
86                         inset_->setParams(params);
87                         lv_->view()->updateInset(inset_, true);
88                 }
89         } else
90                 lv_->getLyXFunc()->Dispatch(LFUN_INDEX_INSERT, params.getAsString().c_str());
91 }
92  
93 void FormIndex::show()
94 {
95         if (!dialog_)
96 #if 1
97                 dialog_ = new FormIndexDialog(this, 0, _("LyX: Index"));
98 #else
99                 dialog_ = new FormIndexDialog(this, 0, _("LyX: Index"), false);
100 #endif
101  
102         if (!dialog_->isVisible()) {
103                 h_ = d_->hideBufferDependent.connect(slot(this, &FormIndex::hide));
104                 u_ = d_->updateBufferDependent.connect(slot(this, &FormIndex::update));
105         }
106
107         dialog_->raise();
108         dialog_->setActiveWindow();
109  
110         update();
111         dialog_->show();
112 }
113
114 void FormIndex::close()
115 {
116         h_.disconnect();
117         u_.disconnect();
118         ih_.disconnect();
119         inset_ = 0;
120 }
121  
122 void FormIndex::hide()
123 {
124         dialog_->hide();
125         close();
126 }