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;
40 string const CONF_ENTRY_URL("FormUrl_url");
41 string const CONF_ENTRY_NAME("FormUrl_name");
46 FormUrl::FormUrl(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->showUrl.connect(slot(this, &FormUrl::showInset));
53 d->createUrl.connect(slot(this, &FormUrl::createInset));
62 void FormUrl::showInset( InsetCommand * const inset )
64 if( dialog_!=0 || inset == 0 ) return;
67 ih_ = inset_->hideDialog.connect(slot(this, &FormUrl::hide));
69 params = inset->params();
74 void FormUrl::createInset( string const & arg )
76 if( dialog_!=0 ) return;
78 params.setFromString( arg );
86 using namespace Gtk::Box_Helpers;
89 Gtk::Table * table = manage( new Gtk::Table(2, 2, FALSE) );
90 Gtk::Box * mbox = manage( new Gtk::HBox() );
91 Gtk::ButtonBox * bbox = manage( new Gtk::VButtonBox() );
92 Gtk::Separator * sep = manage( new Gtk::VSeparator() );
94 url_ = manage( new Gnome::Entry() );
95 name_ = manage( new Gnome::Entry() );
96 html_type_ = manage( new Gtk::CheckButton(_("HTML type")) );
98 b_ok = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_OK) ) );
99 b_cancel = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_CANCEL) ) );
102 table->set_row_spacings(2);
103 table->set_col_spacings(2);
104 mbox->set_spacing(2);
105 bbox->set_spacing(4);
108 url_->set_history_id(CONF_ENTRY_URL);
109 url_->set_max_saved(10);
110 url_->load_history();
111 url_->set_use_arrows_always(true);
113 name_->set_history_id(CONF_ENTRY_NAME);
114 name_->set_max_saved(10);
115 name_->load_history();
116 name_->set_use_arrows_always(true);
119 bbox->children().push_back(Element(*b_ok, false, false));
120 bbox->children().push_back(Element(*b_cancel, false, false));
122 label = manage( new Gtk::Label(_("URL")) );
123 table->attach( *label, 0, 1, 0, 1, 0, 0 );
124 label = manage( new Gtk::Label(_("Name")) );
125 table->attach( *label, 0, 1, 1, 2, 0, 0 );
126 table->attach( *url_, 1, 2, 0, 1 );
127 table->attach( *name_, 1, 2, 1, 2 );
129 mbox->children().push_back(Element(*table));
130 mbox->children().push_back(Element(*html_type_, false, false));
131 mbox->children().push_back(Element(*sep, false, false));
132 mbox->children().push_back(Element(*bbox, false, false));
134 // packing dialog to main window
136 mainAppWin->add_action(*dialog_, _(" URL "));
139 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(url_->get_entry()->gtkobj()), GTK_CAN_DEFAULT);
140 gtk_widget_grab_focus (GTK_WIDGET(url_->get_entry()->gtkobj()));
141 gtk_widget_grab_default (GTK_WIDGET(url_->get_entry()->gtkobj()));
143 // connecting signals
144 b_ok->clicked.connect(slot(this, &FormUrl::apply));
145 name_->get_entry()->activate.connect(slot(this, &FormUrl::apply));
147 b_cancel->clicked.connect(slot(mainAppWin, &GLyxAppWin::remove_action));
149 dialog_->destroy.connect(slot(this, &FormUrl::free));
151 u_ = d_->updateBufferDependent.connect(slot(this, &FormUrl::updateSlot));
152 h_ = d_->hideBufferDependent.connect(slot(this, &FormUrl::hide));
154 updateSlot(); // make sure its up-to-date
158 void FormUrl::updateSlot(bool switched)
167 lv_->view()->available())
169 url_->get_entry()->set_text(params.getContents().c_str());
170 name_->get_entry()->set_text(params.getOptions().c_str());
172 html_type_->set_active( (params.getCmdName() == "htmlurl") );
174 bool sens = (!(lv_->buffer()->isReadonly()));
176 html_type_->set_sensitive(sens);
177 url_->set_sensitive(sens);
178 name_->set_sensitive(sens);
179 b_ok->set_sensitive(sens);
185 if (dialog_!=0) mainAppWin->remove_action();
200 void FormUrl::apply()
202 if( lv_->buffer()->isReadonly() ) return;
204 params.setContents( url_->get_entry()->get_text() );
205 params.setOptions( name_->get_entry()->get_text() );
207 if (html_type_->get_active())
208 params.setCmdName("htmlurl");
210 params.setCmdName("url");
214 // Only update if contents have changed
215 if( params != inset_->params() ) {
216 inset_->setParams( params );
217 lv_->view()->updateInset( inset_, true );
222 lv_->getLyXFunc()->Dispatch( LFUN_INSERT_URL,
223 params.getAsString() );
227 url_->save_history();
228 name_->save_history();