2000-08-17 15:20:30 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 2000 The LyX Team.
|
|
|
|
*
|
|
|
|
* ======================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#include "gettext.h"
|
|
|
|
#include "Dialogs.h"
|
|
|
|
#include "FormIndex.h"
|
|
|
|
#include "LyXView.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "lyxfunc.h"
|
|
|
|
#include "form_index.h"
|
|
|
|
|
2000-09-19 13:50:47 +00:00
|
|
|
#include <gtk--/label.h>
|
|
|
|
#include <gtk--/box.h>
|
|
|
|
#include <gtk--/buttonbox.h>
|
|
|
|
#include <gnome--/entry.h>
|
|
|
|
#include <gnome--/stock.h>
|
|
|
|
#include <gtk--/separator.h>
|
|
|
|
|
|
|
|
// temporary solution for LyXView
|
|
|
|
#include "mainapp.h"
|
|
|
|
extern GLyxAppWin * mainAppWin;
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
namespace {
|
|
|
|
|
2000-09-19 13:50:47 +00:00
|
|
|
// configuration keys
|
2001-03-20 01:22:46 +00:00
|
|
|
string const CONF_ENTRY("FormIndex_entry");
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
2000-09-19 13:50:47 +00:00
|
|
|
|
2000-08-17 15:20:30 +00:00
|
|
|
FormIndex::FormIndex(LyXView * lv, Dialogs * d)
|
2000-10-30 11:33:05 +00:00
|
|
|
: lv_(lv), d_(d), inset_(0), u_(0), h_(0), ih_(0), dialog_(0)
|
2000-08-17 15:20:30 +00:00
|
|
|
{
|
|
|
|
// let the dialog be shown
|
|
|
|
// These are permanent connections so we won't bother
|
|
|
|
// storing a copy because we won't be disconnecting.
|
|
|
|
d->showIndex.connect(slot(this, &FormIndex::showInset));
|
|
|
|
d->createIndex.connect(slot(this, &FormIndex::createInset));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FormIndex::~FormIndex()
|
|
|
|
{
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormIndex::showInset( InsetCommand * const inset )
|
|
|
|
{
|
2000-10-30 11:33:05 +00:00
|
|
|
if( dialog_!=0 || inset == 0 ) return;
|
2000-08-17 15:20:30 +00:00
|
|
|
|
|
|
|
inset_ = inset;
|
2001-03-08 12:58:40 +00:00
|
|
|
ih_ = inset_->hideDialog.connect(slot(this, &FormIndex::hide));
|
2000-08-17 15:20:30 +00:00
|
|
|
|
|
|
|
params = inset->params();
|
|
|
|
show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormIndex::createInset( string const & arg )
|
|
|
|
{
|
2000-10-30 11:33:05 +00:00
|
|
|
if( dialog_!=0 ) return;
|
2000-08-17 15:20:30 +00:00
|
|
|
|
|
|
|
params.setFromString( arg );
|
|
|
|
show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormIndex::show()
|
|
|
|
{
|
|
|
|
if (!dialog_)
|
|
|
|
{
|
2000-09-19 13:50:47 +00:00
|
|
|
using namespace Gtk::Box_Helpers;
|
|
|
|
|
2000-10-13 12:20:38 +00:00
|
|
|
Gtk::Label * label = manage( new Gtk::Label(_("Keyword")) );
|
2000-09-19 13:50:47 +00:00
|
|
|
Gtk::Box * mbox = manage( new Gtk::HBox() );
|
|
|
|
Gtk::ButtonBox * bbox = manage( new Gtk::HButtonBox() );
|
|
|
|
Gtk::Separator * sep = manage( new Gtk::VSeparator() );
|
2000-08-17 15:20:30 +00:00
|
|
|
|
2000-09-19 13:50:47 +00:00
|
|
|
keyword_ = manage( new Gnome::Entry() );
|
|
|
|
|
|
|
|
b_ok = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_OK) ) );
|
|
|
|
b_cancel = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_CANCEL) ) );
|
|
|
|
|
|
|
|
// set up spacing
|
|
|
|
mbox->set_spacing(2);
|
|
|
|
bbox->set_spacing(4);
|
|
|
|
|
|
|
|
keyword_->set_history_id(CONF_ENTRY);
|
|
|
|
keyword_->set_max_saved(10);
|
|
|
|
keyword_->load_history();
|
|
|
|
keyword_->set_use_arrows_always(true);
|
2000-08-17 15:20:30 +00:00
|
|
|
|
2000-09-19 13:50:47 +00:00
|
|
|
// packing
|
|
|
|
bbox->children().push_back(Element(*b_ok, false, false));
|
|
|
|
bbox->children().push_back(Element(*b_cancel, false, false));
|
|
|
|
|
|
|
|
mbox->children().push_back(Element(*label, false, false));
|
|
|
|
mbox->children().push_back(Element(*keyword_, true, true));
|
|
|
|
mbox->children().push_back(Element(*sep, false, false));
|
|
|
|
mbox->children().push_back(Element(*bbox, false, false));
|
|
|
|
|
|
|
|
// packing dialog to main window
|
|
|
|
dialog_ = mbox;
|
2000-10-13 12:20:38 +00:00
|
|
|
mainAppWin->add_action(*dialog_, _(" Index "));
|
2000-08-17 15:20:30 +00:00
|
|
|
|
2000-09-19 13:50:47 +00:00
|
|
|
// setting focus
|
|
|
|
GTK_WIDGET_SET_FLAGS (GTK_WIDGET(keyword_->get_entry()->gtkobj()), GTK_CAN_DEFAULT);
|
|
|
|
gtk_widget_grab_focus (GTK_WIDGET(keyword_->get_entry()->gtkobj()));
|
|
|
|
gtk_widget_grab_default (GTK_WIDGET(keyword_->get_entry()->gtkobj()));
|
|
|
|
|
|
|
|
// connecting signals
|
2000-08-17 15:20:30 +00:00
|
|
|
b_ok->clicked.connect(slot(this, &FormIndex::apply));
|
2000-09-19 13:50:47 +00:00
|
|
|
keyword_->get_entry()->activate.connect(slot(this, &FormIndex::apply));
|
|
|
|
|
|
|
|
b_cancel->clicked.connect(slot(mainAppWin, &GLyxAppWin::remove_action));
|
|
|
|
|
2000-08-17 15:20:30 +00:00
|
|
|
dialog_->destroy.connect(slot(this, &FormIndex::free));
|
|
|
|
|
2000-10-30 11:33:05 +00:00
|
|
|
u_ = d_->updateBufferDependent.connect(slot(this, &FormIndex::updateSlot));
|
2000-08-17 15:20:30 +00:00
|
|
|
h_ = d_->hideBufferDependent.connect(slot(this, &FormIndex::hide));
|
|
|
|
|
2000-10-30 11:33:05 +00:00
|
|
|
updateSlot(); // make sure its up-to-date
|
2000-08-17 15:20:30 +00:00
|
|
|
}
|
|
|
|
}
|
2000-10-13 12:20:38 +00:00
|
|
|
|
2000-10-30 11:33:05 +00:00
|
|
|
void FormIndex::updateSlot(bool switched)
|
2000-08-17 15:20:30 +00:00
|
|
|
{
|
2000-10-13 12:20:38 +00:00
|
|
|
if (switched)
|
|
|
|
{
|
2000-10-13 05:57:05 +00:00
|
|
|
hide();
|
|
|
|
return;
|
2000-10-13 12:20:38 +00:00
|
|
|
}
|
|
|
|
|
2000-10-30 11:33:05 +00:00
|
|
|
if (dialog_ != 0 &&
|
2000-08-17 15:20:30 +00:00
|
|
|
lv_->view()->available())
|
|
|
|
{
|
|
|
|
keyword_->get_entry()->set_text(params.getContents().c_str());
|
2000-10-13 12:20:38 +00:00
|
|
|
|
2000-08-17 15:20:30 +00:00
|
|
|
bool sens = (!(lv_->buffer()->isReadonly()));
|
2000-10-13 12:20:38 +00:00
|
|
|
|
2000-08-17 15:20:30 +00:00
|
|
|
keyword_->set_sensitive(sens);
|
|
|
|
b_ok->set_sensitive(sens);
|
|
|
|
}
|
|
|
|
}
|
2000-10-13 12:20:38 +00:00
|
|
|
|
2000-08-17 15:20:30 +00:00
|
|
|
void FormIndex::hide()
|
|
|
|
{
|
2000-10-30 11:33:05 +00:00
|
|
|
if (dialog_!=0) mainAppWin->remove_action();
|
2000-08-17 15:20:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FormIndex::free()
|
|
|
|
{
|
2000-10-30 11:33:05 +00:00
|
|
|
if (dialog_!=0)
|
2000-08-17 15:20:30 +00:00
|
|
|
{
|
2000-10-30 11:33:05 +00:00
|
|
|
dialog_ = 0;
|
2000-08-17 15:20:30 +00:00
|
|
|
u_.disconnect();
|
|
|
|
h_.disconnect();
|
|
|
|
inset_ = 0;
|
|
|
|
ih_.disconnect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormIndex::apply()
|
|
|
|
{
|
|
|
|
if( lv_->buffer()->isReadonly() ) return;
|
|
|
|
|
|
|
|
params.setContents( keyword_->get_entry()->get_text() );
|
|
|
|
|
|
|
|
if( inset_ != 0 )
|
|
|
|
{
|
|
|
|
// Only update if contents have changed
|
|
|
|
if( params != inset_->params() )
|
|
|
|
{
|
|
|
|
inset_->setParams( params );
|
|
|
|
lv_->view()->updateInset( inset_, true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lv_->getLyXFunc()->Dispatch( LFUN_INDEX_INSERT,
|
2000-09-20 16:15:27 +00:00
|
|
|
params.getAsString() );
|
2000-08-17 15:20:30 +00:00
|
|
|
}
|
2000-09-19 13:50:47 +00:00
|
|
|
|
|
|
|
// save history
|
|
|
|
keyword_->save_history();
|
|
|
|
|
|
|
|
// hide the dialog
|
|
|
|
hide();
|
2000-08-17 15:20:30 +00:00
|
|
|
}
|
2000-09-19 13:50:47 +00:00
|
|
|
|