From 81cc98a500909125cb24259e0fb56e90b69569c8 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Fri, 6 Jun 2008 08:45:58 +0000 Subject: [PATCH] InsetInfo: Some fixes... git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25154 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiInfo.cpp | 84 ++++++++++++++++++++++++----------- src/frontends/qt4/GuiInfo.h | 15 +++++-- src/insets/InsetInfo.cpp | 21 ++++++--- src/insets/InsetInfo.h | 2 +- 4 files changed, 87 insertions(+), 35 deletions(-) diff --git a/src/frontends/qt4/GuiInfo.cpp b/src/frontends/qt4/GuiInfo.cpp index 82be0ce268..3a9a1433f8 100644 --- a/src/frontends/qt4/GuiInfo.cpp +++ b/src/frontends/qt4/GuiInfo.cpp @@ -47,70 +47,104 @@ char const * info_types_gui[] = N_("menu"), N_("icon"), N_("buffer"), ""}; - GuiInfo::GuiInfo(GuiView & lv) : DialogView(lv, "info", qt_("Info")) { setupUi(this); - connect(okPB, SIGNAL(clicked()), this, SLOT(slotApply())); - - connect(typeCO, SIGNAL(clicked()), this, SLOT(change_adaptor())); - connect(nameLE, SIGNAL(textChanged(QString)), this, SLOT(change_adaptor())); - + typeCO->blockSignals(true); for (int n = 0; info_types[n][0]; ++n) typeCO->addItem(qt_(info_types_gui[n])); + typeCO->blockSignals(false); } -void GuiInfo::on_cancelPB_clicked() +void GuiInfo::on_newPB_clicked() +{ + dialogToParams(); + docstring const argument = qstring_to_ucs4(type_ + ' ' + name_); + dispatch(FuncRequest(LFUN_INFO_INSERT, argument)); +} + + +void GuiInfo::on_closePB_clicked() { hide(); } +void GuiInfo::on_typeCO_currentIndexChanged(int) +{ + applyView(); +} + + +void GuiInfo::on_nameLE_textChanged(QString const &) +{ + applyView(); +} + + void GuiInfo::applyView() { - InsetInfo * ii = static_cast(inset(INFO_CODE)); - if (!ii) + InsetInfo const * ii = static_cast(inset(INFO_CODE)); + if (!ii) { return; + } - // FIXME: update the inset contents + dialogToParams(); + docstring const argument = qstring_to_ucs4(type_ + ' ' + name_); + if (!ii->validate(argument)) + return; + dispatch(FuncRequest(LFUN_INSET_MODIFY, argument)); + // FIXME: update the inset contents updateLabels(bufferview()->buffer()); bufferview()->updateMetrics(); bufferview()->buffer().changed(); - - hide(); } void GuiInfo::updateView() { - InsetInfo * ii = static_cast(inset(INFO_CODE)); + InsetInfo const * ii = static_cast(inset(INFO_CODE)); if (!ii) { - typeCO->setCurrentIndex(0); - nameLE->clear(); - // FIXME: A New button to create an InsetInfo at the cursor location - // would be nice. enableView(false); return; } - int type = findToken(info_types, ii->infoType()); + type_ = toqstr(ii->infoType()); + name_ = toqstr(ii->infoName()); + paramsToDialog(); +} + + +void GuiInfo::paramsToDialog() +{ + typeCO->blockSignals(true); + nameLE->blockSignals(true); + int type = findToken(info_types, fromqstr(type_)); typeCO->setCurrentIndex(type >= 0 ? type : 0); - nameLE->setText(toqstr(ii->infoName())); + nameLE->setText(name_); + typeCO->blockSignals(false); + nameLE->blockSignals(false); +} + + +void GuiInfo::dialogToParams() +{ + int type = typeCO->currentIndex(); + if (type != -1) + type_ = info_types[type]; + name_ = nameLE->text(); } void GuiInfo::enableView(bool enable) { - //FIXME: enable controls that need enabling. -} - - -void GuiInfo::dispatchParams() -{ + typeCO->setEnabled(enable); + nameLE->setEnabled(enable); + newPB->setEnabled(!enable); } diff --git a/src/frontends/qt4/GuiInfo.h b/src/frontends/qt4/GuiInfo.h index 4d24609a7c..431bc3300c 100644 --- a/src/frontends/qt4/GuiInfo.h +++ b/src/frontends/qt4/GuiInfo.h @@ -17,8 +17,6 @@ namespace lyx { -class InsetInfo; - namespace frontend { class GuiInfo : public DialogView, public Ui::InfoUi @@ -32,13 +30,22 @@ public: //@{ void applyView(); void updateView(); - void dispatchParams(); + void dispatchParams() {} void enableView(bool enable); bool isBufferDependent() const { return true; } //@} private Q_SLOTS: - void on_cancelPB_clicked(); + void on_newPB_clicked(); + void on_closePB_clicked(); + void on_typeCO_currentIndexChanged(int); + void on_nameLE_textChanged(QString const &); + +private: + void paramsToDialog(); + void dialogToParams(); + QString type_; + QString name_; }; } // namespace frontend diff --git a/src/insets/InsetInfo.cpp b/src/insets/InsetInfo.cpp index bb777164c1..2efedc6f2e 100644 --- a/src/insets/InsetInfo.cpp +++ b/src/insets/InsetInfo.cpp @@ -147,10 +147,10 @@ void InsetInfo::write(ostream & os) const } -bool InsetInfo::validate(string const & argument) const +bool InsetInfo::validate(docstring const & argument) const { // FIXME! - return false; + return true; } @@ -165,13 +165,18 @@ bool InsetInfo::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & flag) const { switch (cmd.action) { + case LFUN_MOUSE_PRESS: + case LFUN_MOUSE_RELEASE: + case LFUN_MOUSE_MOTION: + case LFUN_MOUSE_DOUBLE: + case LFUN_MOUSE_TRIPLE: + case LFUN_COPY: + case LFUN_INSET_SETTINGS: + return InsetText::getStatus(cur, cmd, flag); case LFUN_INSET_MODIFY: flag.setEnabled(true); break; - //FIXME: do something. - /* - */ default: return false; @@ -194,6 +199,11 @@ void InsetInfo::doDispatch(Cursor & cur, FuncRequest & cmd) InsetText::doDispatch(cur, cmd); break; + case LFUN_INSET_MODIFY: + setInfo(to_utf8(cmd.argument())); + cur.pos() = 0; + break; + default: break; } @@ -208,6 +218,7 @@ void InsetInfo::setInfo(string const & name) string type; name_ = trim(split(name, type, ' ')); type_ = nameTranslator().find(type); + updateInfo(); } diff --git a/src/insets/InsetInfo.h b/src/insets/InsetInfo.h index 57e7b8442d..ad4b3977f4 100644 --- a/src/insets/InsetInfo.h +++ b/src/insets/InsetInfo.h @@ -109,7 +109,7 @@ public: /// std::string infoName() const { return name_; } /// - bool validate(std::string const & argument) const; + bool validate(docstring const & argument) const; /// bool showInsetDialog(BufferView * bv) const; ///