1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000 The LyX Team.
8 * ======================================================
14 #pragma implementation
20 #include "FormIndex.h"
24 #include "form_index.h"
26 #include <gtk--/label.h>
27 #include <gtk--/box.h>
28 #include <gtk--/buttonbox.h>
29 #include <gnome--/entry.h>
30 #include <gnome--/stock.h>
31 #include <gtk--/separator.h>
33 // temporary solution for LyXView
35 extern GLyxAppWin * mainAppWin;
40 string const CONF_ENTRY("FormIndex_entry");
45 FormIndex::FormIndex(LyXView * lv, Dialogs * d)
46 : lv_(lv), d_(d), inset_(0), u_(0), h_(0), ih_(0), dialog_(0)
48 // let the dialog be shown
49 // These are permanent connections so we won't bother
50 // storing a copy because we won't be disconnecting.
51 d->showIndex.connect(slot(this, &FormIndex::showInset));
52 d->createIndex.connect(slot(this, &FormIndex::createInset));
56 FormIndex::~FormIndex()
61 void FormIndex::showInset( InsetCommand * const inset )
63 if( dialog_!=0 || inset == 0 ) return;
66 ih_ = inset_->hideDialog.connect(slot(this, &FormIndex::hide));
68 params = inset->params();
72 void FormIndex::createInset( string const & arg )
74 if( dialog_!=0 ) return;
76 params.setFromString( arg );
80 void FormIndex::show()
84 using namespace Gtk::Box_Helpers;
86 Gtk::Label * label = manage( new Gtk::Label(_("Keyword")) );
87 Gtk::Box * mbox = manage( new Gtk::HBox() );
88 Gtk::ButtonBox * bbox = manage( new Gtk::HButtonBox() );
89 Gtk::Separator * sep = manage( new Gtk::VSeparator() );
91 keyword_ = manage( new Gnome::Entry() );
93 b_ok = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_OK) ) );
94 b_cancel = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_CANCEL) ) );
100 keyword_->set_history_id(CONF_ENTRY);
101 keyword_->set_max_saved(10);
102 keyword_->load_history();
103 keyword_->set_use_arrows_always(true);
106 bbox->children().push_back(Element(*b_ok, false, false));
107 bbox->children().push_back(Element(*b_cancel, false, false));
109 mbox->children().push_back(Element(*label, false, false));
110 mbox->children().push_back(Element(*keyword_, true, true));
111 mbox->children().push_back(Element(*sep, false, false));
112 mbox->children().push_back(Element(*bbox, false, false));
114 // packing dialog to main window
116 mainAppWin->add_action(*dialog_, _(" Index "));
119 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(keyword_->get_entry()->gtkobj()), GTK_CAN_DEFAULT);
120 gtk_widget_grab_focus (GTK_WIDGET(keyword_->get_entry()->gtkobj()));
121 gtk_widget_grab_default (GTK_WIDGET(keyword_->get_entry()->gtkobj()));
123 // connecting signals
124 b_ok->clicked.connect(slot(this, &FormIndex::apply));
125 keyword_->get_entry()->activate.connect(slot(this, &FormIndex::apply));
127 b_cancel->clicked.connect(slot(mainAppWin, &GLyxAppWin::remove_action));
129 dialog_->destroy.connect(slot(this, &FormIndex::free));
131 u_ = d_->updateBufferDependent.connect(slot(this, &FormIndex::updateSlot));
132 h_ = d_->hideBufferDependent.connect(slot(this, &FormIndex::hide));
134 updateSlot(); // make sure its up-to-date
138 void FormIndex::updateSlot(bool switched)
147 lv_->view()->available())
149 keyword_->get_entry()->set_text(params.getContents().c_str());
151 bool sens = (!(lv_->buffer()->isReadonly()));
153 keyword_->set_sensitive(sens);
154 b_ok->set_sensitive(sens);
158 void FormIndex::hide()
160 if (dialog_!=0) mainAppWin->remove_action();
163 void FormIndex::free()
175 void FormIndex::apply()
177 if( lv_->buffer()->isReadonly() ) return;
179 params.setContents( keyword_->get_entry()->get_text() );
183 // Only update if contents have changed
184 if( params != inset_->params() )
186 inset_->setParams( params );
187 lv_->view()->updateInset( inset_, true );
192 lv_->getLyXFunc()->Dispatch( LFUN_INDEX_INSERT,
193 params.getAsString() );
197 keyword_->save_history();