2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2000 The LyX Team.
9 * ======================================================
15 #pragma implementation
26 #include <gtk--/label.h>
27 #include <gtk--/table.h>
28 #include <gtk--/box.h>
29 #include <gtk--/buttonbox.h>
30 #include <gtk--/base.h>
31 #include <gtk--/separator.h>
33 // temporary solution for LyXView
35 extern GLyxAppWin * mainAppWin;
38 static string const CONF_ENTRY_URL("FormUrl_url");
39 static string const CONF_ENTRY_NAME("FormUrl_name");
41 FormUrl::FormUrl(LyXView * lv, Dialogs * d)
42 : lv_(lv), d_(d), inset_(0), u_(0), h_(0), ih_(0), dialog_(NULL)
44 // let the dialog be shown
45 // These are permanent connections so we won't bother
46 // storing a copy because we won't be disconnecting.
47 d->showUrl.connect(slot(this, &FormUrl::showInset));
48 d->createUrl.connect(slot(this, &FormUrl::createInset));
57 void FormUrl::showInset( InsetCommand * const inset )
59 if( dialog_!=NULL || inset == 0 ) return;
62 ih_ = inset_->hide.connect(slot(this, &FormUrl::hide));
64 params = inset->params();
69 void FormUrl::createInset( string const & arg )
71 if( dialog_!=NULL ) return;
73 params.setFromString( arg );
81 using namespace Gtk::Box_Helpers;
84 Gtk::Table * table = manage( new Gtk::Table(2, 2, FALSE) );
85 Gtk::Box * mbox = manage( new Gtk::HBox() );
86 Gtk::ButtonBox * bbox = manage( new Gtk::VButtonBox() );
87 Gtk::Separator * sep = manage( new Gtk::VSeparator() );
89 url_ = manage( new Gnome::Entry() );
90 name_ = manage( new Gnome::Entry() );
91 html_type_ = manage( new Gtk::CheckButton(N_("HTML type")) );
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) ) );
97 table->set_row_spacings(2);
98 table->set_col_spacings(2);
100 bbox->set_spacing(4);
103 url_->set_history_id(CONF_ENTRY_URL);
104 url_->set_max_saved(10);
105 url_->load_history();
106 url_->set_use_arrows_always(true);
108 name_->set_history_id(CONF_ENTRY_NAME);
109 name_->set_max_saved(10);
110 name_->load_history();
111 name_->set_use_arrows_always(true);
114 bbox->children().push_back(Element(*b_ok, false, false));
115 bbox->children().push_back(Element(*b_cancel, false, false));
117 label = manage( new Gtk::Label(N_("URL")) );
118 table->attach( *label, 0, 1, 0, 1, 0, 0 );
119 label = manage( new Gtk::Label(N_("Name")) );
120 table->attach( *label, 0, 1, 1, 2, 0, 0 );
121 table->attach( *url_, 1, 2, 0, 1 );
122 table->attach( *name_, 1, 2, 1, 2 );
124 mbox->children().push_back(Element(*table));
125 mbox->children().push_back(Element(*html_type_, false, false));
126 mbox->children().push_back(Element(*sep, false, false));
127 mbox->children().push_back(Element(*bbox, false, false));
129 // packing dialog to main window
131 mainAppWin->add_action(*dialog_, N_(" URL "));
134 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(url_->get_entry()->gtkobj()), GTK_CAN_DEFAULT);
135 gtk_widget_grab_focus (GTK_WIDGET(url_->get_entry()->gtkobj()));
136 gtk_widget_grab_default (GTK_WIDGET(url_->get_entry()->gtkobj()));
138 // connecting signals
139 b_ok->clicked.connect(slot(this, &FormUrl::apply));
140 name_->get_entry()->activate.connect(slot(this, &FormUrl::apply));
142 b_cancel->clicked.connect(slot(mainAppWin, &GLyxAppWin::remove_action));
144 dialog_->destroy.connect(slot(this, &FormUrl::free));
146 u_ = d_->updateBufferDependent.connect(slot(this, &FormUrl::update));
147 h_ = d_->hideBufferDependent.connect(slot(this, &FormUrl::hide));
149 update(); // make sure its up-to-date
153 void FormUrl::update()
155 if (dialog_ != NULL &&
156 lv_->view()->available())
158 url_->get_entry()->set_text(params.getContents().c_str());
159 name_->get_entry()->set_text(params.getOptions().c_str());
161 html_type_->set_active( (params.getCmdName() == "htmlurl") );
163 bool sens = (!(lv_->buffer()->isReadonly()));
165 html_type_->set_sensitive(sens);
166 url_->set_sensitive(sens);
167 name_->set_sensitive(sens);
168 b_ok->set_sensitive(sens);
174 if (dialog_!=NULL) mainAppWin->remove_action();
189 void FormUrl::apply()
191 if( lv_->buffer()->isReadonly() ) return;
193 params.setContents( url_->get_entry()->get_text() );
194 params.setOptions( name_->get_entry()->get_text() );
196 if (html_type_->get_active())
197 params.setCmdName("htmlurl");
199 params.setCmdName("url");
203 // Only update if contents have changed
204 if( params != inset_->params() ) {
205 inset_->setParams( params );
206 lv_->view()->updateInset( inset_, true );
211 lv_->getLyXFunc()->Dispatch( LFUN_INSERT_URL,
212 params.getAsString() );
216 url_->save_history();
217 name_->save_history();