2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2000 The LyX Team.
9 * ======================================================
15 #pragma implementation
21 #include "FormIndex.h"
27 #include "diainsertindex_interface.h"
31 #include <gtk--/base.h>
35 #include "FormIndex.h"
38 #include "form_index.h"
41 FormIndex::FormIndex(LyXView * lv, Dialogs * d)
42 : lv_(lv), d_(d), u_(0), h_(0), ih_(0), inset_(0), dialog_(NULL)
44 // let the dialog be shown
45 // These are permanent connections so we won't bother
46 // storing a copy because we won't be disconnecting.
47 d->showIndex.connect(slot(this, &FormIndex::showInset));
48 d->createIndex.connect(slot(this, &FormIndex::createInset));
52 FormIndex::~FormIndex()
57 void FormIndex::showInset( InsetCommand * const inset )
59 if( dialog_!=NULL || inset == 0 ) return;
62 ih_ = inset_->hide.connect(slot(this, &FormIndex::hide));
64 params = inset->params();
68 void FormIndex::createInset( string const & arg )
70 if( dialog_!=NULL ) return;
72 params.setFromString( arg );
76 void FormIndex::show()
80 GtkWidget * pd = create_DiaInsertIndex();
82 dialog_ = Gtk::wrap(pd);
83 keyword_ = Gtk::wrap( GNOME_ENTRY( lookup_widget(pd, "keyword") ) );
85 b_ok = Gtk::wrap( GTK_BUTTON( lookup_widget(pd, "button_ok") ) );
86 b_cancel = Gtk::wrap( GTK_BUTTON( lookup_widget(pd, "button_cancel") ) );
88 b_ok->clicked.connect(slot(this, &FormIndex::apply));
89 b_ok->clicked.connect(dialog_->destroy.slot());
90 b_cancel->clicked.connect(dialog_->destroy.slot());
91 dialog_->destroy.connect(slot(this, &FormIndex::free));
93 u_ = d_->updateBufferDependent.connect(slot(this, &FormIndex::update));
94 h_ = d_->hideBufferDependent.connect(slot(this, &FormIndex::hide));
96 if (!dialog_->is_visible()) dialog_->show_all();
98 update(); // make sure its up-to-date
102 Gdk_Window dialog_win(dialog_->get_window());
107 void FormIndex::update()
109 if (dialog_ != NULL &&
110 lv_->view()->available())
112 keyword_->get_entry()->set_text(params.getContents().c_str());
114 bool sens = (!(lv_->buffer()->isReadonly()));
116 keyword_->set_sensitive(sens);
117 b_ok->set_sensitive(sens);
121 void FormIndex::hide()
123 if (dialog_!=NULL) dialog_->destroy();
126 void FormIndex::free()
138 void FormIndex::apply()
140 if( lv_->buffer()->isReadonly() ) return;
142 params.setContents( keyword_->get_entry()->get_text() );
146 // Only update if contents have changed
147 if( params != inset_->params() )
149 inset_->setParams( params );
150 lv_->view()->updateInset( inset_, true );
155 lv_->getLyXFunc()->Dispatch( LFUN_INDEX_INSERT,
156 params.getAsString().c_str() );