Factor out some common code.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31655 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2009-10-17 22:58:44 +00:00
parent 973b0e25fb
commit 5f8f8dd947

View File

@ -1835,24 +1835,33 @@ void PrefFileformats::updatePrettyname()
} }
namespace {
void updateComboBox(LyXRC::Alternatives const & alts,
string const & fmt, QComboBox * combo)
{
LyXRC::Alternatives::const_iterator it =
alts.find(fmt);
if (it != alts.end()) {
LyXRC::CommandSet const & cmds = it->second;
LyXRC::CommandSet::const_iterator sit =
cmds.begin();
LyXRC::CommandSet::const_iterator const sen =
cmds.end();
for (; sit != sen; ++sit) {
QString const qcmd = toqstr(*sit);
combo->addItem(qcmd, qcmd);
}
}
}
}
void PrefFileformats::updateViewers() void PrefFileformats::updateViewers()
{ {
Format const f = currentFormat(); Format const f = currentFormat();
viewerCO->clear(); viewerCO->clear();
viewerCO->addItem(qt_("None"), QString()); viewerCO->addItem(qt_("None"), QString());
LyXRC::Alternatives::const_iterator it = updateComboBox(viewer_alternatives, f.name(), viewerCO);
viewer_alternatives.find(f.name());
if (it != viewer_alternatives.end()) {
LyXRC::CommandSet const & cmds = it->second;
LyXRC::CommandSet::const_iterator sit =
cmds.begin();
LyXRC::CommandSet::const_iterator const sen =
cmds.end();
for (; sit != sen; ++sit) {
QString const qcmd = toqstr(*sit);
viewerCO->addItem(qcmd, qcmd);
}
}
viewerCO->addItem(qt_("Custom"), QString("custom viewer")); viewerCO->addItem(qt_("Custom"), QString("custom viewer"));
int pos = viewerCO->findData(toqstr(f.viewer())); int pos = viewerCO->findData(toqstr(f.viewer()));
@ -1873,19 +1882,7 @@ void PrefFileformats::updateEditors()
Format const f = currentFormat(); Format const f = currentFormat();
editorCO->clear(); editorCO->clear();
editorCO->addItem(qt_("None"), QString()); editorCO->addItem(qt_("None"), QString());
LyXRC::Alternatives::const_iterator it = updateComboBox(editor_alternatives, f.name(), editorCO);
editor_alternatives.find(f.name());
if (it != editor_alternatives.end()) {
LyXRC::CommandSet const & cmds = it->second;
LyXRC::CommandSet::const_iterator sit =
cmds.begin();
LyXRC::CommandSet::const_iterator const sen =
cmds.end();
for (; sit != sen; ++sit) {
QString const qcmd = toqstr(*sit);
editorCO->addItem(qcmd, qcmd);
}
}
editorCO->addItem(qt_("Custom"), QString("custom editor")); editorCO->addItem(qt_("Custom"), QString("custom editor"));
int pos = editorCO->findData(toqstr(f.editor())); int pos = editorCO->findData(toqstr(f.editor()));