From 116ef17ce9e466dcb3c5b2bac089da6a9ca8c835 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Sun, 7 Feb 2010 21:41:39 +0000 Subject: [PATCH] Migrate ERT dialog to InsetDialog. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33354 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiERT.cpp | 54 ++++++++++--------------------- src/frontends/qt4/GuiERT.h | 37 +++++++-------------- src/frontends/qt4/InsetDialog.cpp | 5 ++- 3 files changed, 33 insertions(+), 63 deletions(-) diff --git a/src/frontends/qt4/GuiERT.cpp b/src/frontends/qt4/GuiERT.cpp index 65a6095cee..aa8ee5fc7f 100644 --- a/src/frontends/qt4/GuiERT.cpp +++ b/src/frontends/qt4/GuiERT.cpp @@ -13,6 +13,9 @@ #include #include "GuiERT.h" + +#include "insets/InsetERT.h" + #include "FuncRequest.h" #include "support/gettext.h" @@ -26,64 +29,41 @@ namespace lyx { namespace frontend { GuiERT::GuiERT(GuiView & lv) - : GuiDialog(lv, "ert", qt_("TeX Code Settings")), status_(InsetCollapsable::Collapsed) + : InsetDialog(lv, ERT_CODE, LFUN_INSET_INSERT, "ert", "TeX Code Settings") { setupUi(this); - connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); - connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); - connect(collapsedRB, SIGNAL(clicked()), this, SLOT(change_adaptor())); - connect(openRB, SIGNAL(clicked()), this, SLOT(change_adaptor())); - - bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); - bc().setOK(okPB); - bc().setCancel(closePB); + connect(collapsedRB, SIGNAL(clicked()), this, SLOT(applyView())); + connect(openRB, SIGNAL(clicked()), this, SLOT(applyView())); } -void GuiERT::change_adaptor() +void GuiERT::enableView(bool enable) { - changed(); + collapsedRB->setEnabled(enable); + openRB->setEnabled(enable); } -void GuiERT::applyView() +docstring GuiERT::dialogToParams() const { - if (openRB->isChecked()) - status_ = InsetCollapsable::Open; - else - status_ = InsetCollapsable::Collapsed; + InsetCollapsable::CollapseStatus status = openRB->isChecked() + ? InsetCollapsable::Open : InsetCollapsable::Collapsed; + return from_ascii(InsetERT::params2string(status)); } -void GuiERT::updateContents() +void GuiERT::paramsToDialog(Inset const * inset) { - switch (status_) { + InsetERT const * ert = static_cast(inset); + InsetCollapsable::CollapseStatus status = ert->status(*bufferview()); + switch (status) { case InsetCollapsable::Open: openRB->setChecked(true); break; case InsetCollapsable::Collapsed: collapsedRB->setChecked(true); break; } } -bool GuiERT::initialiseParams(string const & data) -{ - status_ = InsetERT::string2params(data); - return true; -} - - -void GuiERT::clearParams() -{ - status_ = InsetCollapsable::Collapsed; -} - - -void GuiERT::dispatchParams() -{ - dispatch(FuncRequest(getLfun(), InsetERT::params2string(status_))); -} - - Dialog * createGuiERT(GuiView & lv) { return new GuiERT(lv); } diff --git a/src/frontends/qt4/GuiERT.h b/src/frontends/qt4/GuiERT.h index 09debfeb18..b9b7cccc03 100644 --- a/src/frontends/qt4/GuiERT.h +++ b/src/frontends/qt4/GuiERT.h @@ -12,43 +12,30 @@ #ifndef GUIERT_H #define GUIERT_H -#include "GuiDialog.h" +#include "InsetDialog.h" #include "ui_ERTUi.h" -#include "insets/InsetERT.h" // InsetERT::ERTStatus namespace lyx { namespace frontend { -class GuiERT : public GuiDialog, public Ui::ERTUi +class GuiERT : public InsetDialog, public Ui::ERTUi { Q_OBJECT public: GuiERT(GuiView & lv); -private Q_SLOTS: - void change_adaptor(); +private: + /// \name Dialog inerited methods + //@{ + void enableView(bool enable); + //@} -private: - /// Apply changes - void applyView(); - /// update - void updateContents(); - /// - InsetCollapsable::CollapseStatus status() const { return status_; } - /// - void setStatus(InsetCollapsable::CollapseStatus status) { status_ = status; } - /// - bool initialiseParams(std::string const & data); - /// clean-up on hide. - void clearParams(); - /// clean-up on hide. - void dispatchParams(); - /// - bool isBufferDependent() const { return true; } -private: - /// - InsetCollapsable::CollapseStatus status_; + /// \name InsetDialog inherited methods + //@{ + void paramsToDialog(Inset const *); + docstring dialogToParams() const; + //@} }; } // namespace frontend diff --git a/src/frontends/qt4/InsetDialog.cpp b/src/frontends/qt4/InsetDialog.cpp index 5eee47a634..e31eed7314 100644 --- a/src/frontends/qt4/InsetDialog.cpp +++ b/src/frontends/qt4/InsetDialog.cpp @@ -70,7 +70,10 @@ void InsetDialog::on_closePB_clicked() void InsetDialog::on_newPB_clicked() { - docstring const argument = dialogToParams(); + docstring argument; + if (d->creation_code_ == LFUN_INSET_INSERT) + argument = from_ascii(insetName(d->inset_code_)) + " "; + argument += dialogToParams(); dispatch(FuncRequest(d->creation_code_, argument)); }