On Thu, Feb 25, 2010 at 9:24 PM, Jürgen Spitzmüller <sp...@lyx.org> wrote: <snip> >> 3) On Linux/Ubuntu Languages that the user has installed >> language-packs for (or maybe aspell/hunspell packs) >> 4) Languages that the user has configured input methods for. >> >> In my case this would mean that I always have English, English (UK), >> English (USA), French, German and Japanese as options, regardless of >> whether they already exist in the document. > > Yes, I thought about this, too. This would be an additional feature. > (another possibility is that we store the used languages in session; so if > you once selected your Englishes in a document, you'll always have them in > the menu).
Well, I in the attached (very draft) patch I have cut and pasted feature (3) from GuiSpellChecker.cpp. It seems reasonable that the user install spellchecker modules for languages they want permanently in the Langauges menu. However converse it not true, as a user may be using a public machine where all languages have been installed. To deal with this I was thinking of limiting the languages added from the spellchecker to code to say 12, using a menu separator to split off from the languages actually used in the Document. Does this approach sound reasonable? Also the attached patch I have sorted the language by name. I think this makes the list easier to read, and also it makes your keyboard accelerator code work better. E.g. with the new sorting code I get: _English English (_UK) Rather than _English (UK) E_nglish In general your shortcut code will work better if parent languages appear before sub-languages: _Language Language (_Sublanguage) This patch also commented out the "if (languages.size() < 2)" code. I recall that Lars didn't like dumping the user straight into the text style dialog box, but I don't like the idea of graying out the Languages dialog box, IMHO the user should always be able to set the Language from Edit->Languages. > However, this is something for later (at least as far as I am concerned). I may as well paint the bikeshed now, while we are thinking about it :) -- John C. McCabe-Dansted
Index: frontends/qt4/Menus.cpp =================================================================== --- frontends/qt4/Menus.cpp (revision 33588) +++ frontends/qt4/Menus.cpp (working copy) @@ -50,6 +50,8 @@ #include "TocBackend.h" #include "Toolbars.h" #include "WordLangTuple.h" +#include "SpellChecker.h" +#include "Thesaurus.h" #include "insets/Inset.h" #include "insets/InsetCitation.h" @@ -760,23 +762,47 @@ } +struct ltlang { + bool operator()(const Language *a, const Language *b) const { + return QString(a->display().c_str()).localeAwareCompare(b->display().c_str()) < 0; + } +}; void MenuDefinition::expandLanguageSelector(Buffer const * buf) { if (!buf) return; - std::set<Language const *> languages = + std::set<Language const *> languages_x = buf->masterBuffer()->getLanguages(); - if (languages.size() < 2) - return; + std::set<Language const *, ltlang> languages; + std::set<Language const *>::const_iterator const begin_x = languages_x.begin(); + for (std::set<Language const *>::const_iterator cit = begin_x; + cit != languages_x.end(); ++cit) { + languages.insert(*cit); + } + + Languages::const_iterator it = lyx::languages.begin(); + Languages::const_iterator end = lyx::languages.end(); + for (; it != end; ++it) { + if ( (theSpellChecker() && theSpellChecker()->hasDictionary(&it->second)) || + (thesaurus.thesaurusInstalled(from_ascii(it->second.code()))) ) { + languages.insert(&it->second); + } + } + + // We may want to show the Language Menu anyway so we don't just + // Dump the user into the Text Style Dialog without warning. + //if (languages.size() < 2) + // return; + MenuItem item(MenuItem::Submenu, qt_("Language|L")); item.setSubmenu(MenuDefinition(qt_("Language"))); QStringList accelerators; - std::set<Language const *>::const_iterator const begin = languages.begin(); - for (std::set<Language const *>::const_iterator cit = begin; + std::set<Language const *, ltlang>::const_iterator const begin = languages.begin(); + for (std::set<Language const *, ltlang>::const_iterator cit = begin; cit != languages.end(); ++cit) { QString label = qt_((*cit)->display()); // try to add an accelerator