*/
#include <config.h>
-#include "gettext.h"
+
#include FORMS_H_LOCATION
-#include "BufferView.h"
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+
#include "Dialogs.h"
#include "FormUrl.h"
#include "LyXView.h"
#include "buffer.h"
#include "form_url.h"
#include "lyxfunc.h"
-#include "xform_macros.h"
-#include "insets/insetcommand.h"
-#include "insets/inseturl.h"
-#include "support/filetools.h"
-
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
-C_RETURNCB(FormUrl, WMHideCB)
-C_GENERICCB(FormUrl, OKCB)
-C_GENERICCB(FormUrl, CancelCB)
FormUrl::FormUrl(LyXView * lv, Dialogs * d)
- : dialog_(0), lv_(lv), d_(d), u_(0), h_(0), ih_(0),
- inset_(0), dialogIsOpen(false)
+ : FormCommand(lv, d, _("Url"), new NoRepeatedApplyReadOnlyPolicy),
+ dialog_(0)
{
// let the dialog be shown
// These are permanent connections so we won't bother
// storing a copy because we won't be disconnecting.
d->showUrl.connect(slot(this, &FormUrl::showInset));
d->createUrl.connect(slot(this, &FormUrl::createInset));
- params = new InsetCommandParams();
}
FormUrl::~FormUrl()
{
- free();
- delete params;
+ delete dialog_;
}
-void FormUrl::build()
+FL_FORM * FormUrl::form() const
{
- dialog_ = build_url();
+ if (dialog_) return dialog_->form;
+ return 0;
}
-void FormUrl::showInset( InsetUrl * inset )
+void FormUrl::connect()
{
- if( dialogIsOpen || inset == 0 ) return;
-
- inset_ = inset;
- ih_ = inset_->hide.connect(slot(this, &FormUrl::hide));
-
- (*params) = inset->params();
- show();
+ fl_set_form_maxsize(form(), 2 * minw_, minh_);
+ FormCommand::connect();
}
+
-
-void FormUrl::createInset( string const & arg )
+void FormUrl::build()
{
- if( dialogIsOpen ) return;
+ dialog_ = build_url();
- params->setFromString( arg );
- show();
-}
+ // Workaround dumb xforms sizing bug
+ minw_ = form()->w;
+ minh_ = form()->h;
+ fl_set_input_return(dialog_->name, FL_RETURN_CHANGED);
+ fl_set_input_return(dialog_->url, FL_RETURN_CHANGED);
-void FormUrl::show()
-{
- if (!dialog_) {
- build();
- fl_set_form_atclose(dialog_->form_url,
- C_FormUrlWMHideCB, 0);
- }
-
- update(); // make sure its up-to-date
+ // Manage the ok, apply, restore and cancel/close buttons
+ bc_.setOK(dialog_->button_ok);
+ bc_.setApply(dialog_->button_apply);
+ bc_.setCancel(dialog_->button_cancel);
+ bc_.setUndoAll(dialog_->button_restore);
+ bc_.refresh();
- dialogIsOpen = true;
- if (dialog_->form_url->visible) {
- fl_raise_form(dialog_->form_url);
- } else {
- fl_show_form(dialog_->form_url,
- FL_PLACE_MOUSE | FL_FREE_SIZE,
- FL_TRANSIENT,
- _("Url"));
- u_ = d_->updateBufferDependent.
- connect(slot(this, &FormUrl::update));
- h_ = d_->hideBufferDependent.
- connect(slot(this, &FormUrl::hide));
- }
+ bc_.addReadOnly(dialog_->name);
+ bc_.addReadOnly(dialog_->url);
+ bc_.addReadOnly(dialog_->radio_html);
}
void FormUrl::update()
{
- fl_set_input(dialog_->url, params->getContents().c_str());
- fl_set_input(dialog_->name, params->getOptions().c_str());
+ fl_set_input(dialog_->url, params.getContents().c_str());
+ fl_set_input(dialog_->name, params.getOptions().c_str());
- if ( params->getCmdName() == "url" )
+ if (params.getCmdName() == "url")
fl_set_button(dialog_->radio_html, 0);
else
fl_set_button(dialog_->radio_html, 1);
- static int ow = -1, oh;
-
- if (ow < 0) {
- ow = dialog_->form_url->w;
- oh = dialog_->form_url->h;
- }
-
- fl_set_form_minsize(dialog_->form_url, ow, oh);
- fl_set_form_maxsize(dialog_->form_url, 2*ow, oh);
+ bc_.readOnly(lv_->buffer()->isReadonly());
}
void FormUrl::apply()
{
- if( lv_->buffer()->isReadonly() ) return;
+ if (lv_->buffer()->isReadonly()) return;
- params->setContents( fl_get_input(dialog_->url) );
- params->setOptions( fl_get_input(dialog_->name) );
+ params.setContents(fl_get_input(dialog_->url));
+ params.setOptions(fl_get_input(dialog_->name));
if (fl_get_button(dialog_->radio_html))
- params->setCmdName("htmlurl");
+ params.setCmdName("htmlurl");
else
- params->setCmdName("url");
+ params.setCmdName("url");
- if( inset_ != 0 )
- {
- inset_->setParams( *params );
- lv_->view()->updateInset( inset_, true );
- } else {
- lv_->getLyXFunc()->Dispatch( LFUN_INSERT_URL,
- params->getAsString().c_str() );
- }
-}
-
-
-void FormUrl::hide()
-{
- if (dialog_
- && dialog_->form_url
- && dialog_->form_url->visible) {
- fl_hide_form(dialog_->form_url);
- u_.disconnect();
- h_.disconnect();
- }
-
- // free up the dialog for another inset
- inset_ = 0;
- ih_.disconnect();
- dialogIsOpen = false;
-}
-
-
-void FormUrl::free()
-{
- // we don't need to delete u and h here because
- // hide() does that after disconnecting.
- if (dialog_) {
- if (dialog_->form_url
- && dialog_->form_url->visible) {
- hide();
+ if (inset_ != 0) {
+ // Only update if contents have changed
+ if (params != inset_->params()) {
+ inset_->setParams(params);
+ lv_->view()->updateInset(inset_, true);
}
- fl_free_form(dialog_->form_url);
- delete dialog_;
- dialog_ = 0;
+ } else {
+ lv_->getLyXFunc()->Dispatch(LFUN_INSERT_URL,
+ params.getAsString());
}
}
-
-
-int FormUrl::WMHideCB(FL_FORM * form, void *)
-{
- // Ensure that the signals (u and h) are disconnected even if the
- // window manager is used to close the dialog.
- FormUrl * pre = static_cast<FormUrl*>(form->u_vdata);
- pre->hide();
- return FL_CANCEL;
-}
-
-
-void FormUrl::OKCB(FL_OBJECT * ob, long)
-{
- FormUrl * pre = static_cast<FormUrl*>(ob->form->u_vdata);
- pre->apply();
- pre->hide();
-}
-
-
-void FormUrl::CancelCB(FL_OBJECT * ob, long)
-{
- FormUrl * pre = static_cast<FormUrl*>(ob->form->u_vdata);
- pre->hide();
-}