]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiInfo.cpp
Add missing initialization
[lyx.git] / src / frontends / qt4 / GuiInfo.cpp
index 82be0ce268962ab079639116eefd32d14d2c007b..8994b9431e8fdb54fbe41fafb3b325a5356a2c1b 100644 (file)
 #include "BufferParams.h"
 #include "BufferView.h"
 #include "Cursor.h"
-#include "FuncRequest.h"
 
 #include "insets/InsetInfo.h"
 
 #include "support/debug.h"
+#include "support/gettext.h"
 #include "support/lstrings.h"
 
 
@@ -40,84 +40,67 @@ namespace frontend {
 /////////////////////////////////////////////////////////////////
 
 char const * info_types[] =
-{ "unknown", "shortcut", "shortcuts", "lyxrc", "package", "textclass", "menu", "icon", "buffer", "" };
+{ "unknown", "shortcut", "shortcuts", "lyxrc", "package", "textclass", "menu", "icon", "buffer", "lyxinfo", "" };
 
 char const * info_types_gui[] =
 { N_("unknown"), N_("shortcut"), N_("shortcuts"), N_("lyxrc"), N_("package"), N_("textclass"),
-  N_("menu"), N_("icon"), N_("buffer"), ""};
+  N_("menu"), N_("icon"), N_("buffer"), N_("lyxinfo"), ""};
 
 
-
-GuiInfo::GuiInfo(GuiView & lv)
-       : DialogView(lv, "info", qt_("Info"))
+GuiInfo::GuiInfo(QWidget * parent) : InsetParamsWidget(parent)
 {
        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]));
-}
-
-
-void GuiInfo::on_cancelPB_clicked()
-{
-       hide();
-}
-
-
-void GuiInfo::applyView()
-{
-       InsetInfo * ii = static_cast<InsetInfo *>(inset(INFO_CODE));
-       if (!ii)
-               return;
-       
-       // FIXME: update the inset contents
+       typeCO->blockSignals(false);
 
-       updateLabels(bufferview()->buffer());
-       bufferview()->updateMetrics();
-       bufferview()->buffer().changed();
-
-       hide();
+       connect(typeCO, SIGNAL(currentIndexChanged(int)), this, SIGNAL(changed()));
+       connect(nameLE, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
 }
 
 
-void GuiInfo::updateView()
+void GuiInfo::paramsToDialog(Inset const * inset)
 {
-       InsetInfo * ii = static_cast<InsetInfo *>(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());
-       typeCO->setCurrentIndex(type >= 0 ? type : 0);
-       nameLE->setText(toqstr(ii->infoName()));
+       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_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);
+       typeCO->blockSignals(false);
+       nameLE->blockSignals(false);
 }
 
 
-void GuiInfo::enableView(bool enable)
+docstring GuiInfo::dialogToParams() const
 {
-       //FIXME: enable controls that need enabling.
+       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);
 }
 
 
-void GuiInfo::dispatchParams()
+bool GuiInfo::checkWidgets(bool readonly) const
 {
+       nameLE->setReadOnly(readonly);
+       typeCO->setEnabled(!readonly);
+       if (!InsetParamsWidget::checkWidgets())
+               return false;
+       return !nameLE->text().isEmpty();
 }
 
 
-Dialog * createGuiInfo(GuiView & lv) { return new GuiInfo(lv); }
-
-
 } // namespace frontend
 } // namespace lyx
 
-#include "GuiInfo_moc.cpp"
+#include "moc_GuiInfo.cpp"