From 48f36f59e74cfdea1d33f9170671d33c45b8ba37 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Fri, 8 May 2009 10:07:32 +0000 Subject: [PATCH] * configure.py: - add new method that records all available alternative programs as opposed to only the first found one. * LyXRC[cpp,h}: * LyXFunc.cpp: - new RCs \bibtex_alternatives and \index_alternatives, holding alternative processors. * GuiPrefs.{cpp, h}: * PrefLatexUi.ui: - UI to select from a list of preconfigures bibliography/index processors. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29568 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/configure.py | 71 +++++- src/LyXFunc.cpp | 2 + src/LyXRC.cpp | 32 +++ src/LyXRC.h | 7 + src/frontends/qt4/GuiPrefs.cpp | 130 ++++++++++- src/frontends/qt4/GuiPrefs.h | 10 + src/frontends/qt4/ui/PrefLatexUi.ui | 350 +++++++++++++++++----------- 7 files changed, 457 insertions(+), 145 deletions(-) diff --git a/lib/configure.py b/lib/configure.py index c2379e75b4..94668e7233 100644 --- a/lib/configure.py +++ b/lib/configure.py @@ -178,6 +178,67 @@ def checkProg(description, progs, rc_entry = [], path = [], not_found = ''): return ['', not_found] +## Searching some useful programs +def checkProgAlternatives(description, progs, rc_entry = [], alt_rc_entry = [], path = [], not_found = ''): + ''' + The same as checkProg, but additionally, all found programs will be added + as alt_rc_entries + ''' + # one rc entry for each progs plus not_found entry + if len(rc_entry) > 1 and len(rc_entry) != len(progs) + 1: + logger.error("rc entry should have one item or item for each prog and not_found.") + sys.exit(2) + # check if alt rcs are given + if len(alt_rc_entry) > 1 and len(alt_rc_entry) != len(rc_entry): + logger.error("invalid alt_rc_entry specification.") + sys.exit(2) + logger.info('checking for ' + description + '...') + ## print '(' + ','.join(progs) + ')', + found_prime = False + real_ac_dir = '' + real_ac_word = not_found + for idx in range(len(progs)): + # ac_prog may have options, ac_word is the command name + ac_prog = progs[idx] + ac_word = ac_prog.split(' ')[0] + msg = '+checking for "' + ac_word + '"... ' + path = os.environ["PATH"].split(os.pathsep) + path + extlist = [''] + if os.environ.has_key("PATHEXT"): + extlist = extlist + os.environ["PATHEXT"].split(os.pathsep) + found_alt = False + for ac_dir in path: + for ext in extlist: + if os.path.isfile( os.path.join(ac_dir, ac_word + ext) ): + logger.info(msg + ' yes') + # write rc entries for this command + if found_prime == False: + if len(rc_entry) == 1: + addToRC(rc_entry[0].replace('%%', ac_prog)) + elif len(rc_entry) > 1: + addToRC(rc_entry[idx].replace('%%', ac_prog)) + real_ac_dir = ac_dir + real_ac_word = ac_word + found_prime = True + if len(alt_rc_entry) == 1: + addToRC(alt_rc_entry[0].replace('%%', ac_prog)) + elif len(alt_rc_entry) > 1: + addToRC(alt_rc_entry[idx].replace('%%', ac_prog)) + found_alt = True + break + if found_alt: + break + if found_alt == False: + # if not successful + logger.info(msg + ' no') + if found_prime: + return [real_ac_dir, real_ac_word] + # write rc entries for 'not found' + if len(rc_entry) > 0: # the last one. + addToRC(rc_entry[-1].replace('%%', not_found)) + return ['', not_found] + + def checkViewer(description, progs, rc_entry = [], path = []): ''' The same as checkProg, but for viewers and editors ''' return checkProg(description, progs, rc_entry, path, not_found = 'auto') @@ -599,12 +660,14 @@ def checkOtherEntries(): ''' entries other than Format and Converter ''' checkProg('ChkTeX', ['chktex -n1 -n3 -n6 -n9 -n22 -n25 -n30 -n38'], rc_entry = [ r'\chktex_command "%%"' ]) - checkProg('BibTeX', ['bibtex'], - rc_entry = [ r'\bibtex_command "%%"' ]) + checkProgAlternatives('BibTeX or alternative programs', ['bibtex', 'bibtex8', 'biber'], + rc_entry = [ r'\bibtex_command "%%"' ], + alt_rc_entry = [ r'\bibtex_alternatives "%%"' ]) checkProg('JBibTeX, the Japanese BibTeX', ['jbibtex', 'bibtex'], rc_entry = [ r'\jbibtex_command "%%"' ]) - checkProg('an index processor', ['texindy', 'makeindex -c -q'], - rc_entry = [ r'\index_command "%%"' ]) + checkProgAlternatives('available index processors', ['texindy', 'makeindex -c -q'], + rc_entry = [ r'\index_command "%%"' ], + alt_rc_entry = [ r'\index_alternatives "%%"' ]) checkProg('an index processor appropriate to Japanese', ['mendex -c -q', 'makeindex -c -q'], rc_entry = [ r'\jindex_command "%%"' ]) checkProg('the splitindex processor', ['splitindex.pl', 'java splitindex', 'splitindex'], diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index ece3b21f57..256f136dc8 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -1880,6 +1880,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new) case LyXRC::RC_AUTOSAVE: case LyXRC::RC_AUTO_NUMBER: case LyXRC::RC_BACKUPDIR_PATH: + case LyXRC::RC_BIBTEX_ALTERNATIVES: case LyXRC::RC_BIBTEX_COMMAND: case LyXRC::RC_BINDFILE: case LyXRC::RC_CHECKLASTFILES: @@ -1919,6 +1920,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new) case LyXRC::RC_FONT_ENCODING: case LyXRC::RC_FORMAT: case LyXRC::RC_GROUP_LAYOUTS: + case LyXRC::RC_INDEX_ALTERNATIVES: case LyXRC::RC_INDEX_COMMAND: case LyXRC::RC_JBIBTEX_COMMAND: case LyXRC::RC_JINDEX_COMMAND: diff --git a/src/LyXRC.cpp b/src/LyXRC.cpp index 121b9f896e..6cc8af0ca1 100644 --- a/src/LyXRC.cpp +++ b/src/LyXRC.cpp @@ -61,6 +61,7 @@ LexerKeyword lyxrcTags[] = { { "\\autocorrection_math", LyXRC::RC_AUTOCORRECTION_MATH }, { "\\autosave", LyXRC::RC_AUTOSAVE }, { "\\backupdir_path", LyXRC::RC_BACKUPDIR_PATH }, + { "\\bibtex_alternatives", LyXRC::RC_BIBTEX_ALTERNATIVES }, { "\\bibtex_command", LyXRC::RC_BIBTEX_COMMAND }, { "\\bind_file", LyXRC::RC_BINDFILE }, { "\\check_lastfiles", LyXRC::RC_CHECKLASTFILES }, @@ -97,6 +98,7 @@ LexerKeyword lyxrcTags[] = { { "\\fullscreen_width", LyXRC::RC_FULL_SCREEN_WIDTH }, { "\\group_layouts", LyXRC::RC_GROUP_LAYOUTS }, { "\\gui_language", LyXRC::RC_GUI_LANGUAGE }, + { "\\index_alternatives", LyXRC::RC_INDEX_ALTERNATIVES }, { "\\index_command", LyXRC::RC_INDEX_COMMAND }, { "\\input", LyXRC::RC_INPUT }, { "\\jbibtex_command", LyXRC::RC_JBIBTEX_COMMAND }, @@ -592,6 +594,12 @@ int LyXRC::read(Lexer & lexrc) } break; + case RC_BIBTEX_ALTERNATIVES: + if (lexrc.next(true)) { + bibtex_alternatives.push_back(lexrc.getString()); + } + break; + case RC_BIBTEX_COMMAND: if (lexrc.next(true)) { bibtex_command = lexrc.getString(); @@ -604,6 +612,12 @@ int LyXRC::read(Lexer & lexrc) } break; + case RC_INDEX_ALTERNATIVES: + if (lexrc.next(true)) { + index_alternatives.push_back(lexrc.getString()); + } + break; + case RC_INDEX_COMMAND: if (lexrc.next(true)) { index_command = lexrc.getString(); @@ -1351,6 +1365,15 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c } if (tag != RC_LAST) break; + case RC_BIBTEX_ALTERNATIVES: + if (ignore_system_lyxrc || + bibtex_alternatives != system_lyxrc.bibtex_alternatives) { + for (vector::const_iterator it = bibtex_alternatives.begin(); + it != bibtex_alternatives.end(); ++it) + os << "\\bibtex_alternatives \"" << *it << "\"\n"; + } + if (tag != RC_LAST) + break; case RC_BIBTEX_COMMAND: if (ignore_system_lyxrc || bibtex_command != system_lyxrc.bibtex_command) { @@ -1365,6 +1388,15 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c } if (tag != RC_LAST) break; + case RC_INDEX_ALTERNATIVES: + if (ignore_system_lyxrc || + index_alternatives != system_lyxrc.index_alternatives) { + for (vector::const_iterator it = index_alternatives.begin(); + it != index_alternatives.end(); ++it) + os << "\\index_alternatives \"" << *it << "\"\n"; + } + if (tag != RC_LAST) + break; case RC_INDEX_COMMAND: if (ignore_system_lyxrc || index_command != system_lyxrc.index_command) { diff --git a/src/LyXRC.h b/src/LyXRC.h index a51d63fffc..931e8b7080 100644 --- a/src/LyXRC.h +++ b/src/LyXRC.h @@ -23,6 +23,7 @@ #include "support/strfwd.h" #include +#include namespace lyx { @@ -46,6 +47,7 @@ public: RC_AUTOSAVE, RC_AUTO_NUMBER, RC_BACKUPDIR_PATH, + RC_BIBTEX_ALTERNATIVES, RC_BIBTEX_COMMAND, RC_BINDFILE, RC_CHECKLASTFILES, @@ -84,6 +86,7 @@ public: RC_FULL_SCREEN_WIDTH, RC_GEOMETRY_SESSION, RC_GROUP_LAYOUTS, + RC_INDEX_ALTERNATIVES, RC_INDEX_COMMAND, RC_INPUT, RC_JBIBTEX_COMMAND, @@ -245,10 +248,14 @@ public: PAPER_SIZE default_papersize; /// command to run chktex incl. options std::string chktex_command; + /// all available commands to run bibtex incl. options + std::vector 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::vector index_alternatives; /// command to run makeindex incl. options or other index programs std::string index_command; /// command to run japanese index program incl. options diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index 7e107d8ffb..da194a63cf 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -569,10 +569,14 @@ PrefLatex::PrefLatex(GuiPreferences * form) this, SIGNAL(changed())); connect(latexChecktexED, SIGNAL(textChanged(QString)), this, SIGNAL(changed())); + connect(latexBibtexCO, SIGNAL(activated(int)), + this, SIGNAL(changed())); connect(latexBibtexED, SIGNAL(textChanged(QString)), this, SIGNAL(changed())); connect(latexJBibtexED, SIGNAL(textChanged(QString)), this, SIGNAL(changed())); + connect(latexIndexCO, SIGNAL(activated(int)), + this, SIGNAL(changed())); connect(latexIndexED, SIGNAL(textChanged(QString)), this, SIGNAL(changed())); connect(latexJIndexED, SIGNAL(textChanged(QString)), @@ -594,13 +598,77 @@ PrefLatex::PrefLatex(GuiPreferences * form) } +void PrefLatex::on_latexBibtexCO_activated(int n) +{ + QString const bibtex = latexBibtexCO->itemData(n).toString(); + if (bibtex.isEmpty()) { + latexBibtexED->clear(); + latexBibtexOptionsLA->setText(qt_("C&ommand:")); + return; + } + for (vector::const_iterator it = bibtex_alternatives.begin(); + it != bibtex_alternatives.end(); ++it) { + QString const bib = toqstr(*it); + int ind = bib.indexOf(" "); + QString sel_command = bib.left(ind); + QString sel_options = bib; + sel_options.remove(0, ind); + if (bibtex == sel_command) { + if (ind == -1) + latexBibtexED->clear(); + else + latexBibtexED->setText(sel_options.trimmed()); + } + } + latexBibtexOptionsLA->setText(qt_("&Options:")); +} + + +void PrefLatex::on_latexIndexCO_activated(int n) +{ + QString const index = latexIndexCO->itemData(n).toString(); + if (index.isEmpty()) { + latexIndexED->clear(); + latexIndexOptionsLA->setText(qt_("Co&mmand:")); + return; + } + for (vector::const_iterator it = index_alternatives.begin(); + it != index_alternatives.end(); ++it) { + QString const idx = toqstr(*it); + int ind = idx.indexOf(" "); + QString sel_command = idx.left(ind); + QString sel_options = idx; + sel_options.remove(0, ind); + if (index == sel_command) { + if (ind == -1) + latexIndexED->clear(); + else + latexIndexED->setText(sel_options.trimmed()); + } + } + latexIndexOptionsLA->setText(qt_("Op&tions:")); +} + + void PrefLatex::apply(LyXRC & rc) const { + QString const bibtex = latexBibtexCO->itemData( + latexBibtexCO->currentIndex()).toString(); + if (bibtex.isEmpty()) + rc.bibtex_command = fromqstr(latexBibtexED->text()); + else + rc.bibtex_command = fromqstr(bibtex) + " " + fromqstr(latexBibtexED->text()); + + QString const index = latexIndexCO->itemData( + latexIndexCO->currentIndex()).toString(); + if (index.isEmpty()) + rc.index_command = fromqstr(latexIndexED->text()); + else + rc.index_command = fromqstr(index) + " " + fromqstr(latexIndexED->text()); + rc.fontenc = fromqstr(latexEncodingED->text()); rc.chktex_command = fromqstr(latexChecktexED->text()); - rc.bibtex_command = fromqstr(latexBibtexED->text()); rc.jbibtex_command = fromqstr(latexJBibtexED->text()); - rc.index_command = fromqstr(latexIndexED->text()); rc.jindex_command = fromqstr(latexJIndexED->text()); rc.nomencl_command = fromqstr(latexNomenclED->text()); rc.auto_reset_options = latexAutoresetCB->isChecked(); @@ -615,11 +683,65 @@ void PrefLatex::apply(LyXRC & rc) const void PrefLatex::update(LyXRC const & rc) { + latexBibtexCO->clear(); + + latexBibtexCO->addItem(qt_("Custom"), QString()); + for (vector::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); + } + + bibtex_alternatives = rc.bibtex_alternatives; + + QString const bib = toqstr(rc.bibtex_command); + int ind = bib.indexOf(" "); + QString sel_command = bib.left(ind); + QString sel_options = bib; + sel_options.remove(0, ind); + + int pos = latexBibtexCO->findData(sel_command); + if (pos != -1) { + latexBibtexCO->setCurrentIndex(pos); + latexBibtexED->setText(sel_options.trimmed()); + latexBibtexOptionsLA->setText(qt_("&Options:")); + } else { + latexBibtexED->setText(toqstr(rc.bibtex_command)); + latexBibtexCO->setCurrentIndex(0); + latexBibtexOptionsLA->setText(qt_("C&ommand:")); + } + + latexIndexCO->clear(); + + latexIndexCO->addItem(qt_("Custom"), QString()); + for (vector::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); + } + + index_alternatives = rc.index_alternatives; + + QString const idx = toqstr(rc.index_command); + ind = idx.indexOf(" "); + sel_command = idx.left(ind); + sel_options = idx; + sel_options.remove(0, ind); + + pos = latexIndexCO->findData(sel_command); + if (pos != -1) { + latexIndexCO->setCurrentIndex(pos); + latexIndexED->setText(sel_options.trimmed()); + latexIndexOptionsLA->setText(qt_("Op&tions:")); + } else { + latexIndexED->setText(toqstr(rc.index_command)); + latexIndexCO->setCurrentIndex(0); + latexIndexOptionsLA->setText(qt_("Co&mmand:")); + } + latexEncodingED->setText(toqstr(rc.fontenc)); latexChecktexED->setText(toqstr(rc.chktex_command)); - latexBibtexED->setText(toqstr(rc.bibtex_command)); latexJBibtexED->setText(toqstr(rc.jbibtex_command)); - latexIndexED->setText(toqstr(rc.index_command)); latexJIndexED->setText(toqstr(rc.jindex_command)); latexNomenclED->setText(toqstr(rc.nomencl_command)); latexAutoresetCB->setChecked(rc.auto_reset_options); diff --git a/src/frontends/qt4/GuiPrefs.h b/src/frontends/qt4/GuiPrefs.h index a9c7e310d2..3e45906e32 100644 --- a/src/frontends/qt4/GuiPrefs.h +++ b/src/frontends/qt4/GuiPrefs.h @@ -221,6 +221,16 @@ public: virtual void apply(LyXRC & rc) const; virtual void update(LyXRC const & rc); + +private Q_SLOTS: + void on_latexBibtexCO_activated(int n); + void on_latexIndexCO_activated(int n); + +private: + /// + std::vector bibtex_alternatives; + /// + std::vector index_alternatives; }; diff --git a/src/frontends/qt4/ui/PrefLatexUi.ui b/src/frontends/qt4/ui/PrefLatexUi.ui index 0e24d8a14a..bbf4367d0d 100644 --- a/src/frontends/qt4/ui/PrefLatexUi.ui +++ b/src/frontends/qt4/ui/PrefLatexUi.ui @@ -5,47 +5,54 @@ 0 0 - 427 - 367 + 489 + 636 - - - 9 - - - 6 - - + + + + + Te&X encoding: + + + latexEncodingED + + + + + + + - Qt::Vertical + Qt::Horizontal QSizePolicy::Expanding - + - 409 - 21 + 21 + 52 - - - - Set class options to default on class change - + + - R&eset class options when document class changes + Default paper si&ze: + + + latexPaperSizeCO - + @@ -89,90 +96,208 @@ - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 21 - 52 - - - - - - + + - Chec&kTeX command: + &DVI viewer paper size options: - latexChecktexED + latexDviPaperED - - + + - CheckTeX start options and flags + Optional paper size flag (-paper) for some DVI viewers - - - - Te&X encoding: + + + + Bibliography generation - - latexEncodingED + + true + + + + + + + &Processor: + + + latexBibtexCO + + + + + + + + + + + + + + &Options: + + + latexBibtexED + + + + + + + BibTeX command and options + + + + + + + + + + + Processor for &Japanese: + + + latexJBibtexED + + + + + + + Specific BibTeX command and options for pLaTeX (Japanese) + + + + + + + latexBibtexLA + latexBibtexCO + latexBibtexED + latexBibtexOptionsLA + latexJBibtexED + latexJBibtexLA + latexDviPaperED + latexDviPaperLA - - + + + + Index generation + + + true + + + + + + + + Pr&ocessor: + + + latexIndexCO + + + + + + + + + + + + + + Op&tions: + + + latexIndexED + + + + + + + Index command and options (makeindex, xindy) + + + + + + + + + + + Processor for Ja&panese: + + + latexJIndexED + + + + + + + Specific index command and options for pLaTeX (Japanese) + + + + + + + + + + - Default paper si&ze: + &Nomenclature command: - latexPaperSizeCO + latexNomenclED - - + + - BibTeX command and options + Command and options for nomencl (usually makeindex) - - + + - &BibTeX command: + Chec&kTeX command: - latexBibtexED + latexChecktexED - - - - &Nomenclature command: - - - latexNomenclED + + + + CheckTeX start options and flags - + true @@ -191,80 +316,31 @@ - - - - Command and options for nomencl (usually makeindex) - - - - - - - Index command and options (makeindex, xindy) - - - - - - - &Index command: - - - latexIndexED - - - - - - - Specific index command and options for pLaTeX (Japanese) - - - - - + + - Specific BibTeX command and options for pLaTeX (Japanese) - - - - - - - BibTeX command (&Japanese): - - - latexJBibtexED + Set class options to default on class change - - - - - Index command (Ja&panese): - - - latexJIndexED + R&eset class options when document class changes - - - - Optional paper size flag (-paper) for some DVI viewers + + + + Qt::Vertical - - - - - - &DVI viewer paper size options: + + QSizePolicy::Expanding - - latexDviPaperED + + + 409 + 21 + - + -- 2.39.5