Redo the viewer_alternatives and editor_alternatives in terms of a map,

rather than a vector. This helps deal with problems involving multiple
specifications of a single command. (Even after the previous commit, 
we were still getting duplicates in the UI after every alteration of 
the preferences.) It's also more natural, anyway.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31654 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2009-10-17 22:52:16 +00:00
parent 9c3fc03f3a
commit 973b0e25fb
4 changed files with 84 additions and 42 deletions

View File

@ -1044,13 +1044,13 @@ int LyXRC::read(Lexer & lexrc)
format = lexrc.getString();
if (lexrc.eatLine())
command = lexrc.getString();
viewer_alternatives.push_back(make_pair(format, command));
viewer_alternatives[format].insert(command);
break;
}
case RC_EDITOR_ALTERNATIVES: {
string format, command;
lexrc >> format >> command;
editor_alternatives.push_back(make_pair(format, command));
editor_alternatives[format].insert(command);
break;
}
@ -1393,8 +1393,8 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
if (tag != RC_LAST)
break;
case RC_BIBTEX_ALTERNATIVES: {
set<string>::const_iterator it = bibtex_alternatives.begin();
set<string>::const_iterator end = bibtex_alternatives.end();
CommandSet::const_iterator it = bibtex_alternatives.begin();
CommandSet::const_iterator end = bibtex_alternatives.end();
for ( ; it != end; ++it) {
if (ignore_system_lyxrc
|| !system_lyxrc.bibtex_alternatives.count(*it))
@ -1419,8 +1419,8 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
if (tag != RC_LAST)
break;
case RC_INDEX_ALTERNATIVES: {
set<string>::const_iterator it = index_alternatives.begin();
set<string>::const_iterator end = index_alternatives.end();
CommandSet::const_iterator it = index_alternatives.begin();
CommandSet::const_iterator end = index_alternatives.end();
for ( ; it != end; ++it) {
if (ignore_system_lyxrc
|| !system_lyxrc.index_alternatives.count(*it))
@ -2492,31 +2492,51 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
if (tag != RC_LAST)
break;
case RC_VIEWER_ALTERNATIVES: {
vector<pair<string, string> >::const_iterator it = viewer_alternatives.begin();
vector<pair<string, string> >::const_iterator const en = viewer_alternatives.end();
vector<pair<string, string> >::const_iterator const sysbeg =
system_lyxrc.viewer_alternatives.begin();
vector<pair<string, string> >::const_iterator const sysend =
Alternatives::const_iterator it = viewer_alternatives.begin();
Alternatives::const_iterator const en = viewer_alternatives.end();
Alternatives::const_iterator const sysend =
system_lyxrc.viewer_alternatives.end();
for ( ; it != en; ++it) {
if (ignore_system_lyxrc || find(sysbeg, sysend, *it) == sysend)
os << "\\viewer_alternatives "
<< it->first << " " << it->second << "\n";
for (; it != en; ++it) {
string const & fmt = it->first;
CommandSet const & cmd = it->second;
CommandSet::const_iterator sit = cmd.begin();
CommandSet::const_iterator const sen = cmd.end();
Alternatives::const_iterator const sysfmt = ignore_system_lyxrc ?
system_lyxrc.viewer_alternatives.begin() : // we won't use it in this case
system_lyxrc.viewer_alternatives.find(fmt);
for (; sit != sen; ++sit) {
string const & cmd = *sit;
if (ignore_system_lyxrc
|| sysfmt == sysend // format not found
|| sysfmt->second.count(cmd) == 0 // this command not found
)
os << "\\viewer_alternatives " << fmt << " " << cmd << "\n";
}
}
if (tag != RC_LAST)
break;
}
case RC_EDITOR_ALTERNATIVES: {
vector<pair<string, string> >::const_iterator it = editor_alternatives.begin();
vector<pair<string, string> >::const_iterator const en = editor_alternatives.end();
vector<pair<string, string> >::const_iterator const sysbeg =
system_lyxrc.editor_alternatives.begin();
vector<pair<string, string> >::const_iterator const sysend =
Alternatives::const_iterator it = editor_alternatives.begin();
Alternatives::const_iterator const en = editor_alternatives.end();
Alternatives::const_iterator const sysend =
system_lyxrc.editor_alternatives.end();
for ( ; it != en; ++it) {
if (ignore_system_lyxrc || find(sysbeg, sysend, *it) == sysend)
os << "\\editor_alternatives "
<< it->first << " " << it->second << "\n";
for (; it != en; ++it) {
string const & fmt = it->first;
CommandSet const & cmd = it->second;
CommandSet::const_iterator sit = cmd.begin();
CommandSet::const_iterator const sen = cmd.end();
Alternatives::const_iterator const sysfmt = ignore_system_lyxrc ?
system_lyxrc.editor_alternatives.begin() : // we won't use it in this case
system_lyxrc.editor_alternatives.find(fmt);
for (; sit != sen; ++sit) {
string const & cmd = *sit;
if (ignore_system_lyxrc
|| sysfmt == sysend // format not found
|| sysfmt->second.count(cmd) == 0 // this command not found
)
os << "\\editor_alternatives " << fmt << " " << cmd << "\n";
}
}
if (tag != RC_LAST)
break;

View File

@ -22,6 +22,7 @@
#include "support/strfwd.h"
#include <map>
#include <set>
#include <string>
#include <vector>
@ -197,6 +198,11 @@ private:
///
int read(Lexer &);
public:
///
typedef std::set<std::string> CommandSet;
/// maps a format to a set of commands that can be used to
/// edit or view it.
typedef std::map<std::string, CommandSet> Alternatives;
///
void write(support::FileName const & filename,
bool ignore_system_lyxrc) const;
@ -257,13 +263,13 @@ public:
/// command to run chktex incl. options
std::string chktex_command;
/// all available commands to run bibtex incl. options
std::set<std::string> bibtex_alternatives;
CommandSet bibtex_alternatives;
/// command to run bibtex incl. options
std::string bibtex_command;
/// command to run japanese bibtex incl. options
std::string jbibtex_command;
/// all available index commands incl. options
std::set<std::string> index_alternatives;
CommandSet index_alternatives;
/// command to run makeindex incl. options or other index programs
std::string index_command;
/// command to run japanese index program incl. options
@ -388,9 +394,9 @@ public:
///
std::string default_view_format;
/// all available viewers
std::vector<std::pair<std::string, std::string> > viewer_alternatives;
Alternatives viewer_alternatives;
/// all available editors
std::vector<std::pair<std::string, std::string> > editor_alternatives;
Alternatives editor_alternatives;
///
bool mac_like_word_movement;
///

View File

@ -631,7 +631,7 @@ void PrefLatex::on_latexBibtexCO_activated(int n)
latexBibtexOptionsLA->setText(qt_("Co&mmand:"));
return;
}
for (set<string>::const_iterator it = bibtex_alternatives.begin();
for (LyXRC::CommandSet::const_iterator it = bibtex_alternatives.begin();
it != bibtex_alternatives.end(); ++it) {
QString const bib = toqstr(*it);
int ind = bib.indexOf(" ");
@ -656,7 +656,7 @@ void PrefLatex::on_latexIndexCO_activated(int n)
latexIndexOptionsLA->setText(qt_("Co&mmand:"));
return;
}
for (set<string>::const_iterator it = index_alternatives.begin();
for (LyXRC::CommandSet::const_iterator it = index_alternatives.begin();
it != index_alternatives.end(); ++it) {
QString const idx = toqstr(*it);
int ind = idx.indexOf(" ");
@ -719,7 +719,7 @@ void PrefLatex::update(LyXRC const & rc)
latexBibtexCO->clear();
latexBibtexCO->addItem(qt_("Custom"), QString());
for (set<string>::const_iterator it = rc.bibtex_alternatives.begin();
for (LyXRC::CommandSet::const_iterator it = rc.bibtex_alternatives.begin();
it != rc.bibtex_alternatives.end(); ++it) {
QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
latexBibtexCO->addItem(command, command);
@ -746,7 +746,7 @@ void PrefLatex::update(LyXRC const & rc)
latexIndexCO->clear();
latexIndexCO->addItem(qt_("Custom"), QString());
for (set<string>::const_iterator it = rc.index_alternatives.begin();
for (LyXRC::CommandSet::const_iterator it = rc.index_alternatives.begin();
it != rc.index_alternatives.end(); ++it) {
QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
latexIndexCO->addItem(command, command);
@ -1840,10 +1840,18 @@ void PrefFileformats::updateViewers()
Format const f = currentFormat();
viewerCO->clear();
viewerCO->addItem(qt_("None"), QString());
for (vector<pair<string, string> >::const_iterator it = viewer_alternatives.begin();
it != viewer_alternatives.end(); ++it) {
if (it->first == f.name())
viewerCO->addItem(toqstr(it->second), toqstr(it->second));
LyXRC::Alternatives::const_iterator it =
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"));
@ -1865,10 +1873,18 @@ void PrefFileformats::updateEditors()
Format const f = currentFormat();
editorCO->clear();
editorCO->addItem(qt_("None"), QString());
for (vector<pair<string, string> >::const_iterator it = editor_alternatives.begin();
it != editor_alternatives.end(); ++it) {
if (it->first == f.name())
editorCO->addItem(toqstr(it->second), toqstr(it->second));
LyXRC::Alternatives::const_iterator it =
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"));

View File

@ -382,9 +382,9 @@ private:
///
void updateEditors();
///
std::vector<std::pair<std::string, std::string> > viewer_alternatives;
LyXRC::Alternatives viewer_alternatives;
///
std::vector<std::pair<std::string, std::string> > editor_alternatives;
LyXRC::Alternatives editor_alternatives;
};