GuiWrap.h
IconPalette.h
InsertTableWidget.h
+ InsetDialog.h
LaTeXHighlighter.h
LayoutBox.h
LengthCombo.h
GuiWrap.cpp
IconPalette.cpp
InsertTableWidget.cpp
+ InsetDialog.cpp
LengthCombo.cpp
LaTeXHighlighter.cpp
LayoutBox.cpp
GuiInfo::GuiInfo(GuiView & lv)
- : DialogView(lv, "info", qt_("Info"))
+ : InsetDialog(lv, INFO_CODE, "info", qt_("Info"))
{
setupUi(this);
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();
}
-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);
}
#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
/// \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
--- /dev/null
+/**\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
--- /dev/null
+// -*- 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
GuiWrap.cpp \
IconPalette.cpp \
InsertTableWidget.cpp \
+ InsetDialog.cpp \
LengthCombo.cpp \
LyXFileDialog.cpp \
LaTeXHighlighter.cpp \
GuiWrap.h \
IconPalette.h \
InsertTableWidget.h \
+ InsetDialog.h \
LayoutBox.h \
LengthCombo.h \
LyXFileDialog.h \
/// 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
}
-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, ' '));
///
std::string infoName() const { return name_; }
///
- bool validate(docstring const & argument) const;
+ bool validateModifyArgument(docstring const & argument) const;
///
bool showInsetDialog(BufferView * bv) const;
///