From: Abdelrazak Younes Date: Sat, 30 Jan 2010 11:15:05 +0000 (+0000) Subject: Inset::validateModifyArgument(): new virtual interface for using LFUN_INSET_MODIFY. X-Git-Tag: 2.0.0~4189 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=d3487d106cfeb5b7e1ab5f5a2859d7f80ef31745;p=features.git Inset::validateModifyArgument(): new virtual interface for using LFUN_INSET_MODIFY. GuiInfo: extract generic code into new class InsetDialog. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33270 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/development/scons/scons_manifest.py b/development/scons/scons_manifest.py index 166c16e485..e9727e28d4 100644 --- a/development/scons/scons_manifest.py +++ b/development/scons/scons_manifest.py @@ -782,6 +782,7 @@ src_frontends_qt4_header_files = Split(''' GuiWrap.h IconPalette.h InsertTableWidget.h + InsetDialog.h LaTeXHighlighter.h LayoutBox.h LengthCombo.h @@ -882,6 +883,7 @@ src_frontends_qt4_files = Split(''' GuiWrap.cpp IconPalette.cpp InsertTableWidget.cpp + InsetDialog.cpp LengthCombo.cpp LaTeXHighlighter.cpp LayoutBox.cpp diff --git a/src/frontends/qt4/GuiInfo.cpp b/src/frontends/qt4/GuiInfo.cpp index cb6c2b549d..6c37c819f5 100644 --- a/src/frontends/qt4/GuiInfo.cpp +++ b/src/frontends/qt4/GuiInfo.cpp @@ -48,7 +48,7 @@ char const * info_types_gui[] = GuiInfo::GuiInfo(GuiView & lv) - : DialogView(lv, "info", qt_("Info")) + : InsetDialog(lv, INFO_CODE, "info", qt_("Info")) { setupUi(this); @@ -61,18 +61,13 @@ GuiInfo::GuiInfo(GuiView & lv) void GuiInfo::on_newPB_clicked() { - dialogToParams(); - docstring const argument = qstring_to_ucs4(type_ + ' ' + name_); + // FIXME: if we used a standard LFUN_INSET_INSERT command, + // This slot could be transferred to InsetDialog. + docstring const argument = dialogToParams(); dispatch(FuncRequest(LFUN_INFO_INSERT, argument)); } -void GuiInfo::on_closePB_clicked() -{ - hide(); -} - - void GuiInfo::on_typeCO_currentIndexChanged(int) { applyView(); @@ -85,58 +80,32 @@ void GuiInfo::on_nameLE_textChanged(QString const &) } -void GuiInfo::applyView() -{ - InsetInfo const * ii = dynamic_cast(inset(INFO_CODE)); - if (!ii) - return; - - 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 - bufferview()->buffer().updateLabels(); -} - - -void GuiInfo::updateView() -{ - InsetInfo const * ii = dynamic_cast(inset(INFO_CODE)); - if (!ii) { - enableView(false); - return; - } - - type_ = toqstr(ii->infoType()); - name_ = toqstr(ii->infoName()); - paramsToDialog(); -} - - -void GuiInfo::paramsToDialog() +void GuiInfo::paramsToDialog(Inset const * inset) { + InsetInfo const * ii = static_cast(inset); + QString const type = toqstr(ii->infoType()); + QString const name = toqstr(ii->infoName()); typeCO->blockSignals(true); nameLE->blockSignals(true); - int type = findToken(info_types, fromqstr(type_)); - typeCO->setCurrentIndex(type >= 0 ? type : 0); - // Without this test, 'math-insert' (name_) will replace 'math-insert ' + int type_index = findToken(info_types, fromqstr(type)); + typeCO->setCurrentIndex(type_index >= 0 ? type_index : 0); + // Without this test, 'math-insert' (name) will replace 'math-insert ' // in nameLE and effectively disallow the input of spaces after a LFUN. - if (nameLE->text().trimmed() != name_) - nameLE->setText(name_); + if (nameLE->text().trimmed() != name) + nameLE->setText(name); typeCO->blockSignals(false); nameLE->blockSignals(false); } -void GuiInfo::dialogToParams() +docstring GuiInfo::dialogToParams() const { - int type = typeCO->currentIndex(); - if (type != -1) - type_ = info_types[type]; - name_ = nameLE->text(); + int type_index = typeCO->currentIndex(); + QString type; + if (type_index != -1) + type = info_types[type_index]; + QString const name = nameLE->text(); + return qstring_to_ucs4(type + ' ' + name); } diff --git a/src/frontends/qt4/GuiInfo.h b/src/frontends/qt4/GuiInfo.h index 9094dc7e0c..562a9a1faf 100644 --- a/src/frontends/qt4/GuiInfo.h +++ b/src/frontends/qt4/GuiInfo.h @@ -12,14 +12,16 @@ #ifndef GUI_INFO_H #define GUI_INFO_H -#include "DialogView.h" +#include "InsetDialog.h" #include "ui_InfoUi.h" namespace lyx { +class Inset; + namespace frontend { -class GuiInfo : public DialogView, public Ui::InfoUi +class GuiInfo : public InsetDialog, public Ui::InfoUi { Q_OBJECT @@ -28,25 +30,20 @@ public: /// \name Dialog inherited methods //@{ - void applyView(); - void updateView(); - void dispatchParams() {} void enableView(bool enable); - bool isBufferDependent() const { return true; } - bool canApply() const { return true; } //@} private Q_SLOTS: 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_; + /// \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 new file mode 100644 index 0000000000..7f3e90fff7 --- /dev/null +++ b/src/frontends/qt4/InsetDialog.cpp @@ -0,0 +1,80 @@ +/** + * \file InsetDialog.cpp + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Abdelrazak Younes + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "InsetDialog.h" + +#include "qt_helpers.h" + +#include "Buffer.h" +#include "buffer_funcs.h" +#include "BufferParams.h" +#include "BufferView.h" +#include "Cursor.h" +#include "FuncRequest.h" + +#include "support/debug.h" +#include "support/lstrings.h" + + +using namespace std; +using namespace lyx::support; + +namespace lyx { +namespace frontend { + +///////////////////////////////////////////////////////////////// +// +// InsetDialog +// +///////////////////////////////////////////////////////////////// + + +InsetDialog::InsetDialog(GuiView & lv, InsetCode code, + QString const & name, QString const & title) + : DialogView(lv, name, title), code_(code) +{ +} + + +void InsetDialog::on_closePB_clicked() +{ + hide(); +} + + +void InsetDialog::applyView() +{ + Inset const * i = inset(code_); + if (!i) + return; + + docstring const argument = dialogToParams(); + if (!i->validateModifyArgument(argument)) + return; + + dispatch(FuncRequest(LFUN_INSET_MODIFY, argument)); +} + + +void InsetDialog::updateView() +{ + Inset const * i = inset(code_); + if (i) + paramsToDialog(i); + else + enableView(false); +} + +} // namespace frontend +} // namespace lyx + +#include "moc_InsetDialog.cpp" diff --git a/src/frontends/qt4/InsetDialog.h b/src/frontends/qt4/InsetDialog.h new file mode 100644 index 0000000000..d6595d188e --- /dev/null +++ b/src/frontends/qt4/InsetDialog.h @@ -0,0 +1,55 @@ +// -*- C++ -*- +/** + * \file InsetDialog.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Abdelrazak Younes + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef INSET_DIALOG_H +#define INSET_DIALOG_H + +#include "DialogView.h" + +namespace lyx { + +class Inset; + +namespace frontend { + +class InsetDialog : public DialogView +{ + Q_OBJECT + +public: + InsetDialog(GuiView & lv, InsetCode code, + QString const & name, QString const & title); + + /// \name DialogView inherited methods + //@{ + void applyView(); + void updateView(); + void dispatchParams() {} + bool isBufferDependent() const { return true; } + bool canApply() const { return true; } + //@} + +protected Q_SLOTS: + void on_closePB_clicked(); + +protected: + /// + virtual void paramsToDialog(Inset const *) = 0; + /// + virtual docstring dialogToParams() const = 0; + /// + InsetCode const code_; +}; + +} // namespace frontend +} // namespace lyx + +#endif // INSET_DIALOG_H diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index a1fbf59e02..936bc2d827 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -132,6 +132,7 @@ SOURCEFILES = \ GuiWrap.cpp \ IconPalette.cpp \ InsertTableWidget.cpp \ + InsetDialog.cpp \ LengthCombo.cpp \ LyXFileDialog.cpp \ LaTeXHighlighter.cpp \ @@ -234,6 +235,7 @@ MOCHEADER = \ GuiWrap.h \ IconPalette.h \ InsertTableWidget.h \ + InsetDialog.h \ LayoutBox.h \ LengthCombo.h \ LyXFileDialog.h \ diff --git a/src/insets/Inset.h b/src/insets/Inset.h index 8b56f802cd..3958f965b2 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -291,6 +291,9 @@ public: /// request "external features" virtual void validate(LaTeXFeatures &) const {} + /// Validate LFUN_INSET_MODIFY argument. + virtual bool validateModifyArgument(docstring const &) const { return true; } + /// describe content if cursor inside virtual void infoize(odocstream &) const {} /// describe content if cursor behind diff --git a/src/insets/InsetInfo.cpp b/src/insets/InsetInfo.cpp index 45d63287c8..28e873ca55 100644 --- a/src/insets/InsetInfo.cpp +++ b/src/insets/InsetInfo.cpp @@ -150,7 +150,7 @@ void InsetInfo::write(ostream & os) const } -bool InsetInfo::validate(docstring const & arg) const +bool InsetInfo::validateModifyArgument(docstring const & arg) const { string type; string const name = trim(split(to_utf8(arg), type, ' ')); diff --git a/src/insets/InsetInfo.h b/src/insets/InsetInfo.h index 797eb08ff7..ebe987b9cc 100644 --- a/src/insets/InsetInfo.h +++ b/src/insets/InsetInfo.h @@ -110,7 +110,7 @@ public: /// std::string infoName() const { return name_; } /// - bool validate(docstring const & argument) const; + bool validateModifyArgument(docstring const & argument) const; /// bool showInsetDialog(BufferView * bv) const; ///