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"
25 #include "form_index.h"
27 #include <gtk--/label.h>
28 #include <gtk--/box.h>
29 #include <gtk--/buttonbox.h>
30 #include <gnome--/entry.h>
31 #include <gnome--/stock.h>
32 #include <gtk--/separator.h>
34 // temporary solution for LyXView
36 extern GLyxAppWin * mainAppWin;
41 string const CONF_ENTRY("FormIndex_entry");
46 FormIndex::FormIndex(LyXView * lv, Dialogs * d)
47 : lv_(lv), d_(d), inset_(0), u_(0), h_(0), ih_(0), dialog_(0)
49 // let the dialog be shown
50 // These are permanent connections so we won't bother
51 // storing a copy because we won't be disconnecting.
52 d->showIndex.connect(slot(this, &FormIndex::showInset));
53 d->createIndex.connect(slot(this, &FormIndex::createInset));
57 FormIndex::~FormIndex()
62 void FormIndex::showInset( InsetCommand * const inset )
64 if( dialog_!=0 || inset == 0 ) return;
67 ih_ = inset_->hideDialog.connect(slot(this, &FormIndex::hide));
69 params = inset->params();
73 void FormIndex::createInset( string const & arg )
75 if( dialog_!=0 ) return;
77 params.setFromString( arg );
81 void FormIndex::show()
85 using namespace Gtk::Box_Helpers;
87 Gtk::Label * label = manage( new Gtk::Label(_("Keyword")) );
88 Gtk::Box * mbox = manage( new Gtk::HBox() );
89 Gtk::ButtonBox * bbox = manage( new Gtk::HButtonBox() );
90 Gtk::Separator * sep = manage( new Gtk::VSeparator() );
92 keyword_ = manage( new Gnome::Entry() );
94 b_ok = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_OK) ) );
95 b_cancel = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_CANCEL) ) );
101 keyword_->set_history_id(CONF_ENTRY);
102 keyword_->set_max_saved(10);
103 keyword_->load_history();
104 keyword_->set_use_arrows_always(true);
107 bbox->children().push_back(Element(*b_ok, false, false));
108 bbox->children().push_back(Element(*b_cancel, false, false));
110 mbox->children().push_back(Element(*label, false, false));
111 mbox->children().push_back(Element(*keyword_, true, true));
112 mbox->children().push_back(Element(*sep, false, false));
113 mbox->children().push_back(Element(*bbox, false, false));
115 // packing dialog to main window
117 mainAppWin->add_action(*dialog_, _(" Index "));
120 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(keyword_->get_entry()->gtkobj()), GTK_CAN_DEFAULT);
121 gtk_widget_grab_focus (GTK_WIDGET(keyword_->get_entry()->gtkobj()));
122 gtk_widget_grab_default (GTK_WIDGET(keyword_->get_entry()->gtkobj()));
124 // connecting signals
125 b_ok->clicked.connect(slot(this, &FormIndex::apply));
126 keyword_->get_entry()->activate.connect(slot(this, &FormIndex::apply));
128 b_cancel->clicked.connect(slot(mainAppWin, &GLyxAppWin::remove_action));
130 dialog_->destroy.connect(slot(this, &FormIndex::free));
132 u_ = d_->updateBufferDependent.connect(slot(this, &FormIndex::updateSlot));
133 h_ = d_->hideBufferDependent.connect(slot(this, &FormIndex::hide));
135 updateSlot(); // make sure its up-to-date
139 void FormIndex::updateSlot(bool switched)
148 lv_->view()->available())
150 keyword_->get_entry()->set_text(params.getContents().c_str());
152 bool sens = (!(lv_->buffer()->isReadonly()));
154 keyword_->set_sensitive(sens);
155 b_ok->set_sensitive(sens);
159 void FormIndex::hide()
161 if (dialog_!=0) mainAppWin->remove_action();
164 void FormIndex::free()
176 void FormIndex::apply()
178 if( lv_->buffer()->isReadonly() ) return;
180 params.setContents( keyword_->get_entry()->get_text() );
184 // Only update if contents have changed
185 if( params != inset_->params() )
187 inset_->setParams( params );
188 lv_->view()->updateInset( inset_, true );
193 lv_->getLyXFunc()->Dispatch( LFUN_INDEX_INSERT,
194 params.getAsString() );
198 keyword_->save_history();