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;
46 static string const CONF_ENTRY("FormIndex_entry");
48 FormIndex::FormIndex(LyXView * lv, Dialogs * d)
49 : lv_(lv), d_(d), inset_(0), u_(0), h_(0), ih_(0), dialog_(NULL)
51 // let the dialog be shown
52 // These are permanent connections so we won't bother
53 // storing a copy because we won't be disconnecting.
54 d->showIndex.connect(slot(this, &FormIndex::showInset));
55 d->createIndex.connect(slot(this, &FormIndex::createInset));
59 FormIndex::~FormIndex()
64 void FormIndex::showInset( InsetCommand * const inset )
66 if( dialog_!=NULL || inset == 0 ) return;
69 ih_ = inset_->hide.connect(slot(this, &FormIndex::hide));
71 params = inset->params();
75 void FormIndex::createInset( string const & arg )
77 if( dialog_!=NULL ) return;
79 params.setFromString( arg );
83 void FormIndex::show()
87 using namespace Gtk::Box_Helpers;
89 Gtk::Label * label = manage( new Gtk::Label(N_("Keyword")) );
90 Gtk::Box * mbox = manage( new Gtk::HBox() );
91 Gtk::ButtonBox * bbox = manage( new Gtk::HButtonBox() );
92 Gtk::Separator * sep = manage( new Gtk::VSeparator() );
94 keyword_ = manage( new Gnome::Entry() );
96 b_ok = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_OK) ) );
97 b_cancel = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_CANCEL) ) );
100 mbox->set_spacing(2);
101 bbox->set_spacing(4);
103 keyword_->set_history_id(CONF_ENTRY);
104 keyword_->set_max_saved(10);
105 keyword_->load_history();
106 keyword_->set_use_arrows_always(true);
109 bbox->children().push_back(Element(*b_ok, false, false));
110 bbox->children().push_back(Element(*b_cancel, false, false));
112 mbox->children().push_back(Element(*label, false, false));
113 mbox->children().push_back(Element(*keyword_, true, true));
114 mbox->children().push_back(Element(*sep, false, false));
115 mbox->children().push_back(Element(*bbox, false, false));
117 // packing dialog to main window
119 mainAppWin->add_action(*dialog_, N_(" Index "));
122 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(keyword_->get_entry()->gtkobj()), GTK_CAN_DEFAULT);
123 gtk_widget_grab_focus (GTK_WIDGET(keyword_->get_entry()->gtkobj()));
124 gtk_widget_grab_default (GTK_WIDGET(keyword_->get_entry()->gtkobj()));
126 // connecting signals
127 b_ok->clicked.connect(slot(this, &FormIndex::apply));
128 keyword_->get_entry()->activate.connect(slot(this, &FormIndex::apply));
130 b_cancel->clicked.connect(slot(mainAppWin, &GLyxAppWin::remove_action));
132 dialog_->destroy.connect(slot(this, &FormIndex::free));
134 u_ = d_->updateBufferDependent.connect(slot(this, &FormIndex::update));
135 h_ = d_->hideBufferDependent.connect(slot(this, &FormIndex::hide));
137 update(); // make sure its up-to-date
141 void FormIndex::update()
143 if (dialog_ != NULL &&
144 lv_->view()->available())
146 keyword_->get_entry()->set_text(params.getContents().c_str());
148 bool sens = (!(lv_->buffer()->isReadonly()));
150 keyword_->set_sensitive(sens);
151 b_ok->set_sensitive(sens);
155 void FormIndex::hide()
157 if (dialog_!=NULL) mainAppWin->remove_action();
160 void FormIndex::free()
172 void FormIndex::apply()
174 if( lv_->buffer()->isReadonly() ) return;
176 params.setContents( keyword_->get_entry()->get_text() );
180 // Only update if contents have changed
181 if( params != inset_->params() )
183 inset_->setParams( params );
184 lv_->view()->updateInset( inset_, true );
189 lv_->getLyXFunc()->Dispatch( LFUN_INDEX_INSERT,
190 params.getAsString() );
194 keyword_->save_history();