]> git.lyx.org Git - features.git/commitdiff
Inset::validateModifyArgument(): new virtual interface for using LFUN_INSET_MODIFY.
authorAbdelrazak Younes <younes@lyx.org>
Sat, 30 Jan 2010 11:15:05 +0000 (11:15 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sat, 30 Jan 2010 11:15:05 +0000 (11:15 +0000)
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

development/scons/scons_manifest.py
src/frontends/qt4/GuiInfo.cpp
src/frontends/qt4/GuiInfo.h
src/frontends/qt4/InsetDialog.cpp [new file with mode: 0644]
src/frontends/qt4/InsetDialog.h [new file with mode: 0644]
src/frontends/qt4/Makefile.am
src/insets/Inset.h
src/insets/InsetInfo.cpp
src/insets/InsetInfo.h

index 166c16e485e1cfe9a81f82d7a37e82a7f6ca051c..e9727e28d41ef3d78e7899af26021fd3a7b6ea83 100644 (file)
@@ -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
index cb6c2b549dc87b1d52e85b1516749b95818c941e..6c37c819f59069161399cd8f2bda3052004d2c8e 100644 (file)
@@ -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<InsetInfo const *>(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<InsetInfo const *>(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<InsetInfo const *>(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);
 }
 
 
index 9094dc7e0c1af3e879431486009668a23496c0a6..562a9a1faf8a63e8e79b8d8c3d246574d38be8be 100644 (file)
 #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 (file)
index 0000000..7f3e90f
--- /dev/null
@@ -0,0 +1,80 @@
+/**\r
+ * \file InsetDialog.cpp\r
+ * This file is part of LyX, the document processor.\r
+ * Licence details can be found in the file COPYING.\r
+ *\r
+ * \author Abdelrazak Younes\r
+ *\r
+ * Full author contact details are available in file CREDITS.\r
+ */\r
+\r
+#include <config.h>\r
+\r
+#include "InsetDialog.h"\r
+\r
+#include "qt_helpers.h"\r
+\r
+#include "Buffer.h"\r
+#include "buffer_funcs.h"\r
+#include "BufferParams.h"\r
+#include "BufferView.h"\r
+#include "Cursor.h"\r
+#include "FuncRequest.h"\r
+\r
+#include "support/debug.h"\r
+#include "support/lstrings.h"\r
+\r
+\r
+using namespace std;\r
+using namespace lyx::support;\r
+\r
+namespace lyx {\r
+namespace frontend {\r
+\r
+/////////////////////////////////////////////////////////////////\r
+//\r
+// InsetDialog\r
+//\r
+/////////////////////////////////////////////////////////////////\r
+\r
+\r
+InsetDialog::InsetDialog(GuiView & lv, InsetCode code,\r
+                                                QString const & name, QString const & title)\r
+       : DialogView(lv, name, title), code_(code)\r
+{\r
+}\r
+\r
+\r
+void InsetDialog::on_closePB_clicked()\r
+{\r
+       hide();\r
+}\r
+\r
+\r
+void InsetDialog::applyView()\r
+{\r
+       Inset const * i = inset(code_);\r
+       if (!i)\r
+               return;\r
+       \r
+       docstring const argument = dialogToParams();\r
+       if (!i->validateModifyArgument(argument))\r
+               return;\r
+\r
+       dispatch(FuncRequest(LFUN_INSET_MODIFY, argument));\r
+}\r
+\r
+\r
+void InsetDialog::updateView()\r
+{\r
+       Inset const * i = inset(code_);\r
+       if (i)\r
+               paramsToDialog(i);\r
+       else\r
+               enableView(false);\r
+}\r
+\r
+} // namespace frontend\r
+} // namespace lyx\r
+\r
+#include "moc_InsetDialog.cpp"\r
diff --git a/src/frontends/qt4/InsetDialog.h b/src/frontends/qt4/InsetDialog.h
new file mode 100644 (file)
index 0000000..d6595d1
--- /dev/null
@@ -0,0 +1,55 @@
+// -*- C++ -*-\r
+/**\r
+ * \file InsetDialog.h\r
+ * This file is part of LyX, the document processor.\r
+ * Licence details can be found in the file COPYING.\r
+ *\r
+ * \author Abdelrazak Younes\r
+ *\r
+ * Full author contact details are available in file CREDITS.\r
+ */\r
+\r
+#ifndef INSET_DIALOG_H\r
+#define INSET_DIALOG_H\r
+\r
+#include "DialogView.h"\r
+\r
+namespace lyx {\r
+\r
+class Inset;\r
+\r
+namespace frontend {\r
+\r
+class InsetDialog : public DialogView\r
+{\r
+       Q_OBJECT\r
+\r
+public:\r
+       InsetDialog(GuiView & lv, InsetCode code, \r
+               QString const & name, QString const & title);\r
+\r
+       /// \name DialogView inherited methods\r
+       //@{\r
+       void applyView();\r
+       void updateView();\r
+       void dispatchParams() {}\r
+       bool isBufferDependent() const { return true; }\r
+       bool canApply() const { return true; }\r
+       //@}\r
+\r
+protected Q_SLOTS:\r
+       void on_closePB_clicked();\r
+\r
+protected:\r
+       ///\r
+       virtual void paramsToDialog(Inset const *) = 0;\r
+       ///\r
+       virtual docstring dialogToParams() const = 0;\r
+       ///\r
+       InsetCode const code_;\r
+};\r
+\r
+} // namespace frontend\r
+} // namespace lyx\r
+\r
+#endif // INSET_DIALOG_H\r
index a1fbf59e02b4d43f2e6e6015d27f6bc52f5f71ef..936bc2d827e3641b510f9c8200226e64f41f2f47 100644 (file)
@@ -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 \
index 8b56f802cd4a59870d4af15e553682d3d9652b57..3958f965b2cd6b7cf4d05f40d1aaf706bc53a0e7 100644 (file)
@@ -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
index 45d63287c89d7b92111f0e529a2ea7af9b7525a7..28e873ca5522ac4973cc68fee877683e87f8ae2e 100644 (file)
@@ -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, ' '));
index 797eb08ff78782a72c8b26b0bfd0fa72ce208f78..ebe987b9cc671e78a54d0b68fbd4b1a07f82c47c 100644 (file)
@@ -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;
        ///