diff --git a/src/frontends/qt4/Dialogs.cpp b/src/frontends/qt4/Dialogs.cpp index 64962d0615..6520da14e7 100644 --- a/src/frontends/qt4/Dialogs.cpp +++ b/src/frontends/qt4/Dialogs.cpp @@ -21,7 +21,6 @@ #include "GuiMathMatrix.h" #include "GuiNomencl.h" #include "GuiView.h" -#include "GuiURL.h" // Uncomment this if you prefer dock widget //#define USE_DOCK_WIDGET @@ -202,7 +201,7 @@ Dialog * Dialogs::build(string const & name) if (name == "toc") return createGuiToc(lyxview_); if (name == "url") - return new GuiURLDialog(lyxview_); + return createGuiURL(lyxview_); if (name == "vspace") return createGuiVSpace(lyxview_); if (name == "wrap") diff --git a/src/frontends/qt4/GuiURL.cpp b/src/frontends/qt4/GuiURL.cpp index 7e4d41e04a..ed5f11f9ab 100644 --- a/src/frontends/qt4/GuiURL.cpp +++ b/src/frontends/qt4/GuiURL.cpp @@ -3,6 +3,7 @@ * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * + * \author Angus Leeming * \author John Levon * * Full author contact details are available in file CREDITS. @@ -12,8 +13,10 @@ #include "GuiURL.h" -#include "ControlCommand.h" +#include "GuiURL.h" #include "qt_helpers.h" +#include "FuncRequest.h" +#include "insets/InsetCommand.h" #include #include @@ -24,12 +27,12 @@ namespace lyx { namespace frontend { -GuiURLDialog::GuiURLDialog(LyXView & lv) - : GuiDialog(lv, "url") +GuiURL::GuiURL(LyXView & lv) + : GuiDialog(lv, "url"), Controller(this), params_("url") { setupUi(this); setViewTitle( _("URL")); - setController(new ControlCommand(*this, "url")); + setController(this, false); connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); @@ -51,19 +54,13 @@ GuiURLDialog::GuiURLDialog(LyXView & lv) } -ControlCommand & GuiURLDialog::controller() -{ - return static_cast(GuiDialog::controller()); -} - - -void GuiURLDialog::changed_adaptor() +void GuiURL::changed_adaptor() { changed(); } -void GuiURLDialog::closeEvent(QCloseEvent * e) +void GuiURL::closeEvent(QCloseEvent * e) { slotClose(); e->accept(); @@ -71,33 +68,29 @@ void GuiURLDialog::closeEvent(QCloseEvent * e) -void GuiURLDialog::updateContents() +void GuiURL::updateContents() { - InsetCommandParams const & params = controller().params(); - - urlED->setText(toqstr(params["target"])); - nameED->setText(toqstr(params["name"])); - hyperlinkCB->setChecked(params.getCmdName() != "url"); + urlED->setText(toqstr(params_["target"])); + nameED->setText(toqstr(params_["name"])); + hyperlinkCB->setChecked(params_.getCmdName() != "url"); bc().setValid(isValid()); } -void GuiURLDialog::applyView() +void GuiURL::applyView() { - InsetCommandParams & params = controller().params(); - - params["target"] = qstring_to_ucs4(urlED->text()); - params["name"] = qstring_to_ucs4(nameED->text()); + params_["target"] = qstring_to_ucs4(urlED->text()); + params_["name"] = qstring_to_ucs4(nameED->text()); if (hyperlinkCB->isChecked()) - params.setCmdName("htmlurl"); + params_.setCmdName("htmlurl"); else - params.setCmdName("url"); + params_.setCmdName("url"); } -bool GuiURLDialog::isValid() +bool GuiURL::isValid() { QString const u = urlED->text(); QString const n = nameED->text(); @@ -105,6 +98,27 @@ bool GuiURLDialog::isValid() return !u.isEmpty() || !n.isEmpty(); } + +bool GuiURL::initialiseParams(std::string const & data) +{ + // The name passed with LFUN_INSET_APPLY is also the name + // used to identify the mailer. + InsetCommandMailer::string2params("name", data, params_); + return true; +} + + +void GuiURL::dispatchParams() +{ + std::string const lfun = + InsetCommandMailer::params2string("url", params_); + dispatch(FuncRequest(getLfun(), lfun)); +} + + +Dialog * createGuiURL(LyXView & lv) { return new GuiURL(lv); } + + } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiURL.h b/src/frontends/qt4/GuiURL.h index bb64e77594..51dc2cf11d 100644 --- a/src/frontends/qt4/GuiURL.h +++ b/src/frontends/qt4/GuiURL.h @@ -1,30 +1,32 @@ // -*- C++ -*- /** - * \file GuiURLDialog.h + * \file GuiURL.h * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * * \author John Levon + * \author Angus Leeming * * Full author contact details are available in file CREDITS. */ -#ifndef GUIURLDIALOG_H -#define GUIURLDIALOG_H +#ifndef GUIURL_H +#define GUIURL_H #include "GuiDialog.h" #include "ControlCommand.h" #include "ui_URLUi.h" +#include "insets/InsetCommandParams.h" namespace lyx { namespace frontend { -class GuiURLDialog : public GuiDialog, public Ui::URLUi +class GuiURL : public GuiDialog, public Ui::URLUi, public Controller { Q_OBJECT public: - GuiURLDialog(LyXView & lv); + GuiURL(LyXView & lv); public Q_SLOTS: void changed_adaptor(); @@ -32,16 +34,28 @@ public Q_SLOTS: private: void closeEvent(QCloseEvent *); /// parent controller - ControlCommand & controller(); + Controller & controller() { return *this; } /// bool isValid(); /// apply dialog void applyView(); /// update dialog void updateContents(); + /// + bool initialiseParams(std::string const & data); + /// clean-up on hide. + void clearParams() { params_.clear(); } + /// clean-up on hide. + void dispatchParams(); + /// + bool isBufferDependent() const { return true; } + +private: + /// + InsetCommandParams params_; }; } // namespace frontend } // namespace lyx -#endif // GUIURLDIALOG_H +#endif // GUIURL_H