2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2000 The LyX Team.
9 * ======================================================
15 #pragma implementation
27 #include "diainserturl_interface.h"
31 #include <gtk--/base.h>
33 FormUrl::FormUrl(LyXView * lv, Dialogs * d)
34 : lv_(lv), d_(d), u_(0), h_(0), ih_(0), inset_(0), dialog_(NULL)
36 // let the dialog be shown
37 // These are permanent connections so we won't bother
38 // storing a copy because we won't be disconnecting.
39 d->showUrl.connect(slot(this, &FormUrl::showInset));
40 d->createUrl.connect(slot(this, &FormUrl::createInset));
49 void FormUrl::showInset( InsetCommand * const inset )
51 if( dialog_!=NULL || inset == 0 ) return;
54 ih_ = inset_->hide.connect(slot(this, &FormUrl::hide));
56 params = inset->params();
61 void FormUrl::createInset( string const & arg )
63 if( dialog_!=NULL ) return;
65 params.setFromString( arg );
73 GtkWidget * pd = create_DiaInsertUrl();
75 dialog_ = Gtk::wrap(pd);
76 url_ = Gtk::wrap( GNOME_ENTRY( lookup_widget(pd, "url") ) );
77 name_ = Gtk::wrap( GNOME_ENTRY( lookup_widget(pd, "name") ) );
78 html_type_ = Gtk::wrap( GTK_CHECK_BUTTON( lookup_widget(pd, "html_type") ) );
80 b_ok = Gtk::wrap( GTK_BUTTON( lookup_widget(pd, "button_ok") ) );
81 b_cancel = Gtk::wrap( GTK_BUTTON( lookup_widget(pd, "button_cancel") ) );
83 b_ok->clicked.connect(slot(this, &FormUrl::apply));
84 b_ok->clicked.connect(dialog_->destroy.slot());
85 b_cancel->clicked.connect(dialog_->destroy.slot());
86 dialog_->destroy.connect(slot(this, &FormUrl::free));
88 u_ = d_->updateBufferDependent.connect(slot(this, &FormUrl::update));
89 h_ = d_->hideBufferDependent.connect(slot(this, &FormUrl::hide));
91 if (!dialog_->is_visible()) dialog_->show_all();
93 update(); // make sure its up-to-date
97 Gdk_Window dialog_win(dialog_->get_window());
102 void FormUrl::update()
104 if (dialog_ != NULL &&
105 lv_->view()->available())
107 url_->get_entry()->set_text(params.getContents().c_str());
108 name_->get_entry()->set_text(params.getOptions().c_str());
110 html_type_->set_active( (params.getCmdName() == "htmlurl") );
112 bool sens = (!(lv_->buffer()->isReadonly()));
114 html_type_->set_sensitive(sens);
115 url_->set_sensitive(sens);
116 name_->set_sensitive(sens);
117 b_ok->set_sensitive(sens);
123 if (dialog_!=NULL) dialog_->destroy();
138 void FormUrl::apply()
140 if( lv_->buffer()->isReadonly() ) return;
142 params.setContents( url_->get_entry()->get_text() );
143 params.setOptions( name_->get_entry()->get_text() );
145 if (html_type_->get_active())
146 params.setCmdName("htmlurl");
148 params.setCmdName("url");
152 // Only update if contents have changed
153 if( params != inset_->params() ) {
154 inset_->setParams( params );
155 lv_->view()->updateInset( inset_, true );
160 lv_->getLyXFunc()->Dispatch( LFUN_INSERT_URL,
161 params.getAsString().c_str() );