#include "insets/InsetInfo.h"
#include "support/debug.h"
+#include "support/lstrings.h"
using namespace std;
+using namespace lyx::support;
namespace lyx {
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));
}
}
-InsetInfo * GuiInfo::inset() const
+void GuiInfo::on_typeCO_currentIndexChanged(int)
+{
+ applyView();
+}
+
+
+void GuiInfo::on_nameLE_textChanged(QString const &)
{
- Inset * ins = bufferview()->cursor().innerInsetOfType(INFO_CODE);
- if (!ins)
- ins = bufferview()->cursor().nextInset();
- if (ins->lyxCode() != INFO_CODE)
- return 0;
- return static_cast<InsetInfo *>(ins);
+ 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);
}
} // namespace frontend
} // namespace lyx
-#include "GuiInfo_moc.cpp"
+#include "moc_GuiInfo.cpp"