]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/FormIndex.C
John's KDE FormRef patch
[lyx.git] / src / frontends / gnome / FormIndex.C
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  *
5  *           LyX, The Document Processor
6  *
7  *           Copyright 2000 The LyX Team.
8  *
9  * ======================================================
10  */
11
12 #include <config.h>
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18
19 #include "gettext.h"
20 #include "Dialogs.h"
21 #include "FormIndex.h"
22 #include "LyXView.h"
23 #include "buffer.h"
24 #include "lyxfunc.h"
25
26 extern "C" {
27 #include "diainsertindex_interface.h"
28 #include "support.h"
29 }
30
31 #include <gtk--/base.h>
32
33 #include "gettext.h"
34 #include "Dialogs.h"
35 #include "FormIndex.h"
36 #include "LyXView.h"
37 #include "buffer.h"
38 #include "form_index.h"
39 #include "lyxfunc.h"
40
41 FormIndex::FormIndex(LyXView * lv, Dialogs * d)
42         : lv_(lv), d_(d), u_(0), h_(0), ih_(0), inset_(0), dialog_(NULL)
43 {
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));
49 }
50
51
52 FormIndex::~FormIndex()
53 {
54   hide();
55 }
56
57 void FormIndex::showInset( InsetCommand * const inset )
58 {
59   if( dialog_!=NULL || inset == 0 ) return;
60   
61   inset_ = inset;
62   ih_ = inset_->hide.connect(slot(this, &FormIndex::hide));
63   
64   params = inset->params();
65   show();
66 }
67
68 void FormIndex::createInset( string const & arg )
69 {
70   if( dialog_!=NULL ) return;
71   
72   params.setFromString( arg );
73   show();
74 }
75
76 void FormIndex::show()
77 {
78   if (!dialog_)
79     {
80       GtkWidget * pd = create_DiaInsertIndex();
81
82       dialog_ = Gtk::wrap(pd);
83       keyword_ = Gtk::wrap( GNOME_ENTRY( lookup_widget(pd, "keyword") ) );
84       
85       b_ok = Gtk::wrap( GTK_BUTTON( lookup_widget(pd, "button_ok") ) );
86       b_cancel = Gtk::wrap( GTK_BUTTON( lookup_widget(pd, "button_cancel") ) );
87
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));
92
93       u_ = d_->updateBufferDependent.connect(slot(this, &FormIndex::update));
94       h_ = d_->hideBufferDependent.connect(slot(this, &FormIndex::hide));
95
96       if (!dialog_->is_visible()) dialog_->show_all();
97
98       update();  // make sure its up-to-date
99     }
100   else
101     {
102       Gdk_Window dialog_win(dialog_->get_window());
103       dialog_win.raise();
104     }
105 }
106       
107 void FormIndex::update()
108 {
109   if (dialog_ != NULL &&
110       lv_->view()->available())
111     {
112       keyword_->get_entry()->set_text(params.getContents().c_str());
113   
114       bool sens = (!(lv_->buffer()->isReadonly()));
115
116       keyword_->set_sensitive(sens);
117       b_ok->set_sensitive(sens);
118     }
119 }
120
121 void FormIndex::hide()
122 {
123   if (dialog_!=NULL) dialog_->destroy();
124 }
125
126 void FormIndex::free()
127 {
128   if (dialog_!=NULL)
129     {
130       dialog_ = NULL;
131       u_.disconnect();
132       h_.disconnect();
133       inset_ = 0;
134       ih_.disconnect();
135     }
136 }
137
138 void FormIndex::apply()
139 {
140   if( lv_->buffer()->isReadonly() ) return;
141
142   params.setContents( keyword_->get_entry()->get_text() );
143
144   if( inset_ != 0 )
145     {
146       // Only update if contents have changed
147       if( params != inset_->params() )
148         {
149           inset_->setParams( params );
150           lv_->view()->updateInset( inset_, true );
151         }
152     }
153   else
154     {
155       lv_->getLyXFunc()->Dispatch( LFUN_INDEX_INSERT,
156                                    params.getAsString().c_str() );
157     }
158 }