]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiInfo.cpp
* fix spelling in comments to please John.
[lyx.git] / src / frontends / qt4 / GuiInfo.cpp
index d8a104dda4a0ae70e6f3c296679f452d8f938f67..cb6c2b549dc87b1d52e85b1516749b95818c941e 100644 (file)
 #include "insets/InsetInfo.h"
 
 #include "support/debug.h"
+#include "support/lstrings.h"
 
 
 using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 namespace frontend {
@@ -37,10 +39,31 @@ namespace frontend {
 //
 /////////////////////////////////////////////////////////////////
 
+char const * info_types[] =
+{ "unknown", "shortcut", "shortcuts", "lyxrc", "package", "textclass", "menu", "icon", "buffer", "" };
+
+char const * info_types_gui[] =
+{ N_("unknown"), N_("shortcut"), N_("shortcuts"), N_("lyxrc"), N_("package"), N_("textclass"),
+  N_("menu"), N_("icon"), N_("buffer"), ""};
+
+
 GuiInfo::GuiInfo(GuiView & lv)
        : DialogView(lv, "info", qt_("Info"))
 {
        setupUi(this);
+
+       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_newPB_clicked()
+{
+       dialogToParams();
+       docstring const argument = qstring_to_ucs4(type_ + ' ' + name_);
+       dispatch(FuncRequest(LFUN_INFO_INSERT, argument));
 }
 
 
@@ -50,48 +73,78 @@ void GuiInfo::on_closePB_clicked()
 }
 
 
-InsetInfo * GuiInfo::inset() const
+void GuiInfo::on_typeCO_currentIndexChanged(int)
+{
+       applyView();
+}
+
+
+void GuiInfo::on_nameLE_textChanged(QString const &)
 {
-       return static_cast<InsetInfo *>(bufferview()->cursor().
-               innerInsetOfType(INFO_CODE));
+       applyView();
 }
 
 
 void GuiInfo::applyView()
 {
-       InsetInfo * ii = inset();
+       InsetInfo const * ii = dynamic_cast<InsetInfo const *>(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;
 
-       updateLabels(bufferview()->buffer());
-       bufferview()->updateMetrics();
-       bufferview()->buffer().changed();
+       dispatch(FuncRequest(LFUN_INSET_MODIFY, argument));
+       // FIXME: update the inset contents
+       bufferview()->buffer().updateLabels();
 }
 
 
 void GuiInfo::updateView()
 {
-       InsetInfo * ii = inset();
+       InsetInfo const * ii = dynamic_cast<InsetInfo const *>(inset(INFO_CODE));
        if (!ii) {
-               // FIXME: A New button to create an InsetInfo at the cursor location
-               // would be nice.
                enableView(false);
                return;
        }
-       //FIXME: update the controls.
+
+       type_ = toqstr(ii->infoType());
+       name_ = toqstr(ii->infoName());
+       paramsToDialog();
 }
 
 
-void GuiInfo::enableView(bool enable)
+void GuiInfo::paramsToDialog()
 {
-       //FIXME: enable controls that need enabling.
+       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 '
+       // 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::dispatchParams()
+void GuiInfo::dialogToParams()
+{
+       int type = typeCO->currentIndex();
+       if (type != -1)
+               type_ = info_types[type];
+       name_ = nameLE->text();
+}
+
+
+void GuiInfo::enableView(bool enable)
 {
+       typeCO->setEnabled(enable);
+       nameLE->setEnabled(enable);
+       newPB->setEnabled(!enable);
 }
 
 
@@ -101,4 +154,4 @@ Dialog * createGuiInfo(GuiView & lv) { return new GuiInfo(lv); }
 } // namespace frontend
 } // namespace lyx
 
-#include "GuiInfo_moc.cpp"
+#include "moc_GuiInfo.cpp"