4 * John Levon, moz@compsoc.man.ac.uk
7 /***************************************************************************
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
14 ***************************************************************************/
24 #include "formurldialog.h"
26 FormUrl::FormUrl(LyXView *v, Dialogs *d)
27 : dialog_(0), lv_(v), d_(d), inset_(0), h_(0), u_(0), ih_(0)
29 // let the dialog be shown
30 // This is a permanent connection so we won't bother
31 // storing a copy because we won't be disconnecting.
32 d->showUrl.connect(slot(this, &FormUrl::showUrl));
33 d->createUrl.connect(slot(this, &FormUrl::createUrl));
41 void FormUrl::showUrl(InsetCommand * const inset)
43 // FIXME: when could inset be 0 here ?
48 readonly = lv_->buffer()->isReadonly();
49 ih_ = inset_->hide.connect(slot(this,&FormUrl::hide));
50 params = inset->params();
55 void FormUrl::createUrl(string const & arg)
57 // we could already be showing a URL, clear it out
61 readonly = lv_->buffer()->isReadonly();
62 params.setFromString(arg);
66 void FormUrl::update()
68 dialog_->url->setText(params.getContents().c_str());
69 dialog_->urlname->setText(params.getOptions().c_str());
71 if (params.getCmdName()=="url")
72 dialog_->htmlurl->setChecked(0);
74 dialog_->htmlurl->setChecked(1);
77 dialog_->urlname->setFocusPolicy(QWidget::NoFocus);
78 dialog_->url->setFocusPolicy(QWidget::NoFocus);
79 dialog_->buttonOk->setEnabled(false);
80 dialog_->buttonCancel->setText(_("Close"));
81 dialog_->htmlurl->setEnabled(false);
83 dialog_->urlname->setFocusPolicy(QWidget::StrongFocus);
84 dialog_->url->setFocusPolicy(QWidget::StrongFocus);
85 dialog_->url->setFocus();
86 dialog_->buttonOk->setEnabled(true);
87 dialog_->buttonCancel->setText(_("Cancel"));
88 dialog_->htmlurl->setEnabled(true);
97 params.setContents(dialog_->url->text());
98 params.setOptions(dialog_->urlname->text());
100 if (dialog_->htmlurl->isChecked())
101 params.setCmdName("htmlurl");
103 params.setCmdName("url");
106 if (params != inset_->params()) {
107 inset_->setParams(params);
108 lv_->view()->updateInset(inset_, true);
111 lv_->getLyXFunc()->Dispatch(LFUN_INSERT_URL, params.getAsString().c_str());
117 dialog_ = new FormUrlDialog(this, 0, _("LyX: Url"), false);
119 if (!dialog_->isVisible()) {
120 h_ = d_->hideBufferDependent.connect(slot(this, &FormUrl::hide));
121 u_ = d_->updateBufferDependent.connect(slot(this, &FormUrl::update));
125 dialog_->setActiveWindow();
131 void FormUrl::close()