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 ***************************************************************************/
18 #include "FormUrlDialog.h"
28 #include <qlineedit.h>
29 #include <qcheckbox.h>
30 #include <qpushbutton.h>
32 FormUrl::FormUrl(LyXView *v, Dialogs *d)
33 : dialog_(0), lv_(v), d_(d), inset_(0), h_(0), u_(0), ih_(0)
35 // let the dialog be shown
36 // This is a permanent connection so we won't bother
37 // storing a copy because we won't be disconnecting.
38 d->showUrl.connect(slot(this, &FormUrl::showUrl));
39 d->createUrl.connect(slot(this, &FormUrl::createUrl));
47 void FormUrl::showUrl(InsetCommand * const inset)
49 // FIXME: when could inset be 0 here ?
54 readonly = lv_->buffer()->isReadonly();
55 ih_ = inset_->hide.connect(slot(this,&FormUrl::hide));
56 params = inset->params();
61 void FormUrl::createUrl(string const & arg)
63 // we could already be showing a URL, clear it out
67 readonly = lv_->buffer()->isReadonly();
68 params.setFromString(arg);
72 void FormUrl::update()
74 dialog_->urlED->setText(params.getContents().c_str());
75 dialog_->nameED->setText(params.getOptions().c_str());
77 if (params.getCmdName()=="url")
78 dialog_->hyperlinkCB->setChecked(false);
80 dialog_->hyperlinkCB->setChecked(true);
83 dialog_->nameED->setFocusPolicy(QWidget::NoFocus);
84 dialog_->urlED->setFocusPolicy(QWidget::NoFocus);
85 dialog_->okPB->setEnabled(false);
86 dialog_->cancelPB->setText(_("Close"));
87 dialog_->hyperlinkCB->setEnabled(false);
89 dialog_->nameED->setFocusPolicy(QWidget::StrongFocus);
90 dialog_->urlED->setFocusPolicy(QWidget::StrongFocus);
91 dialog_->urlED->setFocus();
92 dialog_->okPB->setEnabled(true);
93 dialog_->cancelPB->setText(_("Cancel"));
94 dialog_->hyperlinkCB->setEnabled(true);
103 params.setContents(dialog_->urlED->text().latin1());
104 params.setOptions(dialog_->nameED->text().latin1());
106 if (dialog_->hyperlinkCB->isChecked())
107 params.setCmdName("htmlurl");
109 params.setCmdName("url");
112 if (params != inset_->params()) {
113 inset_->setParams(params);
114 lv_->view()->updateInset(inset_, true);
117 lv_->getLyXFunc()->Dispatch(LFUN_INSERT_URL, params.getAsString().c_str());
123 dialog_ = new FormUrlDialog(this, 0, _("LyX: Url"), false);
125 if (!dialog_->isVisible()) {
126 h_ = d_->hideBufferDependent.connect(slot(this, &FormUrl::hide));
127 u_ = d_->updateBufferDependent.connect(slot(this, &FormUrl::update));
131 dialog_->setActiveWindow();
137 void FormUrl::close()