3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Abdelrazak Younes
8 * Full author contact details are available in file CREDITS.
15 #include "qt_helpers.h"
18 #include "buffer_funcs.h"
19 #include "BufferParams.h"
20 #include "BufferView.h"
22 #include "FuncRequest.h"
24 #include "insets/InsetInfo.h"
26 #include "support/debug.h"
27 #include "support/lstrings.h"
31 using namespace lyx::support;
36 /////////////////////////////////////////////////////////////////
40 /////////////////////////////////////////////////////////////////
42 char const * info_types[] =
43 { "unknown", "shortcut", "shortcuts", "lyxrc", "package", "textclass", "menu", "icon", "buffer", "" };
45 char const * info_types_gui[] =
46 { N_("unknown"), N_("shortcut"), N_("shortcuts"), N_("lyxrc"), N_("package"), N_("textclass"),
47 N_("menu"), N_("icon"), N_("buffer"), ""};
50 GuiInfo::GuiInfo(GuiView & lv)
51 : DialogView(lv, "info", qt_("Info"))
55 typeCO->blockSignals(true);
56 for (int n = 0; info_types[n][0]; ++n)
57 typeCO->addItem(qt_(info_types_gui[n]));
58 typeCO->blockSignals(false);
62 void GuiInfo::on_newPB_clicked()
65 docstring const argument = qstring_to_ucs4(type_ + ' ' + name_);
66 dispatch(FuncRequest(LFUN_INFO_INSERT, argument));
70 void GuiInfo::on_closePB_clicked()
76 void GuiInfo::on_typeCO_currentIndexChanged(int)
82 void GuiInfo::on_nameLE_textChanged(QString const &)
88 void GuiInfo::applyView()
90 InsetInfo const * ii = dynamic_cast<InsetInfo const *>(inset(INFO_CODE));
95 docstring const argument = qstring_to_ucs4(type_ + ' ' + name_);
96 if (!ii->validate(argument))
99 dispatch(FuncRequest(LFUN_INSET_MODIFY, argument));
100 // FIXME: update the inset contents
101 bufferview()->buffer().updateLabels();
102 BufferView * bv = const_cast<BufferView *>(bufferview());
103 bv->buffer().changed(true);
104 bv->buffer().markDirty();
108 void GuiInfo::updateView()
110 InsetInfo const * ii = dynamic_cast<InsetInfo const *>(inset(INFO_CODE));
116 type_ = toqstr(ii->infoType());
117 name_ = toqstr(ii->infoName());
122 void GuiInfo::paramsToDialog()
124 typeCO->blockSignals(true);
125 nameLE->blockSignals(true);
126 int type = findToken(info_types, fromqstr(type_));
127 typeCO->setCurrentIndex(type >= 0 ? type : 0);
128 // Without this test, 'math-insert' (name_) will replace 'math-insert '
129 // in nameLE and effectively disallow the input of spaces after a LFUN.
130 if (nameLE->text().trimmed() != name_)
131 nameLE->setText(name_);
132 typeCO->blockSignals(false);
133 nameLE->blockSignals(false);
137 void GuiInfo::dialogToParams()
139 int type = typeCO->currentIndex();
141 type_ = info_types[type];
142 name_ = nameLE->text();
146 void GuiInfo::enableView(bool enable)
148 typeCO->setEnabled(enable);
149 nameLE->setEnabled(enable);
150 newPB->setEnabled(!enable);
154 Dialog * createGuiInfo(GuiView & lv) { return new GuiInfo(lv); }
157 } // namespace frontend
160 #include "moc_GuiInfo.cpp"