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"
28 #include "FormIndex.h"
31 #include "form_index.h"
34 #include <gtk--/label.h>
35 #include <gtk--/box.h>
36 #include <gtk--/buttonbox.h>
37 #include <gnome--/entry.h>
38 #include <gnome--/stock.h>
39 #include <gtk--/separator.h>
41 // temporary solution for LyXView
43 extern GLyxAppWin * mainAppWin;
48 string const CONF_ENTRY("FormIndex_entry");
53 FormIndex::FormIndex(LyXView * lv, Dialogs * d)
54 : lv_(lv), d_(d), inset_(0), u_(0), h_(0), ih_(0), dialog_(0)
56 // let the dialog be shown
57 // These are permanent connections so we won't bother
58 // storing a copy because we won't be disconnecting.
59 d->showIndex.connect(slot(this, &FormIndex::showInset));
60 d->createIndex.connect(slot(this, &FormIndex::createInset));
64 FormIndex::~FormIndex()
69 void FormIndex::showInset( InsetCommand * const inset )
71 if( dialog_!=0 || inset == 0 ) return;
74 ih_ = inset_->hideDialog.connect(slot(this, &FormIndex::hide));
76 params = inset->params();
80 void FormIndex::createInset( string const & arg )
82 if( dialog_!=0 ) return;
84 params.setFromString( arg );
88 void FormIndex::show()
92 using namespace Gtk::Box_Helpers;
94 Gtk::Label * label = manage( new Gtk::Label(_("Keyword")) );
95 Gtk::Box * mbox = manage( new Gtk::HBox() );
96 Gtk::ButtonBox * bbox = manage( new Gtk::HButtonBox() );
97 Gtk::Separator * sep = manage( new Gtk::VSeparator() );
99 keyword_ = manage( new Gnome::Entry() );
101 b_ok = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_OK) ) );
102 b_cancel = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_CANCEL) ) );
105 mbox->set_spacing(2);
106 bbox->set_spacing(4);
108 keyword_->set_history_id(CONF_ENTRY);
109 keyword_->set_max_saved(10);
110 keyword_->load_history();
111 keyword_->set_use_arrows_always(true);
114 bbox->children().push_back(Element(*b_ok, false, false));
115 bbox->children().push_back(Element(*b_cancel, false, false));
117 mbox->children().push_back(Element(*label, false, false));
118 mbox->children().push_back(Element(*keyword_, true, true));
119 mbox->children().push_back(Element(*sep, false, false));
120 mbox->children().push_back(Element(*bbox, false, false));
122 // packing dialog to main window
124 mainAppWin->add_action(*dialog_, _(" Index "));
127 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(keyword_->get_entry()->gtkobj()), GTK_CAN_DEFAULT);
128 gtk_widget_grab_focus (GTK_WIDGET(keyword_->get_entry()->gtkobj()));
129 gtk_widget_grab_default (GTK_WIDGET(keyword_->get_entry()->gtkobj()));
131 // connecting signals
132 b_ok->clicked.connect(slot(this, &FormIndex::apply));
133 keyword_->get_entry()->activate.connect(slot(this, &FormIndex::apply));
135 b_cancel->clicked.connect(slot(mainAppWin, &GLyxAppWin::remove_action));
137 dialog_->destroy.connect(slot(this, &FormIndex::free));
139 u_ = d_->updateBufferDependent.connect(slot(this, &FormIndex::updateSlot));
140 h_ = d_->hideBufferDependent.connect(slot(this, &FormIndex::hide));
142 updateSlot(); // make sure its up-to-date
146 void FormIndex::updateSlot(bool switched)
155 lv_->view()->available())
157 keyword_->get_entry()->set_text(params.getContents().c_str());
159 bool sens = (!(lv_->buffer()->isReadonly()));
161 keyword_->set_sensitive(sens);
162 b_ok->set_sensitive(sens);
166 void FormIndex::hide()
168 if (dialog_!=0) mainAppWin->remove_action();
171 void FormIndex::free()
183 void FormIndex::apply()
185 if( lv_->buffer()->isReadonly() ) return;
187 params.setContents( keyword_->get_entry()->get_text() );
191 // Only update if contents have changed
192 if( params != inset_->params() )
194 inset_->setParams( params );
195 lv_->view()->updateInset( inset_, true );
200 lv_->getLyXFunc()->Dispatch( LFUN_INDEX_INSERT,
201 params.getAsString() );
205 keyword_->save_history();