diff --git a/lib/ui/stdcontext.inc b/lib/ui/stdcontext.inc index 8048435ba6..d9b470cc75 100644 --- a/lib/ui/stdcontext.inc +++ b/lib/ui/stdcontext.inc @@ -315,6 +315,7 @@ Menuset Item "Apply Last Text Style|A" "textstyle-apply" Submenu "Text Style|S" "edit_textstyles" Item "Paragraph Settings...|P" "layout-paragraph" + LanguageSelector Separator Item "Fullscreen Mode" "ui-toggle fullscreen" End diff --git a/lib/ui/stdmenus.inc b/lib/ui/stdmenus.inc index 66ec6e6d51..0039e99e28 100644 --- a/lib/ui/stdmenus.inc +++ b/lib/ui/stdmenus.inc @@ -111,6 +111,7 @@ Menuset Item "Move Paragraph Down|v" "paragraph-move-down" Separator Submenu "Text Style|S" "edit_textstyles" + LanguageSelector Item "Paragraph Settings...|P" "layout-paragraph" Separator # Mathed b0rkage means these don't work properly @@ -125,7 +126,7 @@ Menuset # obvious what the context is for the others) OptItem "Increase List Depth|I" "depth-increment" OptItem "Decrease List Depth|D" "depth-decrement" - OptItem "Dissolve Inset|l" "inset-dissolve" + OptItem "Dissolve Inset" "inset-dissolve" OptItem "TeX Code Settings...|C" "inset-settings ert" # 'a' shortcut to match Insert entry, shouldn't clash with Table Settings OptItem "Float Settings...|a" "inset-settings float" diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 02634402cf..e4948df8b5 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -2172,6 +2172,27 @@ bool Buffer::isMultiLingual() const } +std::set Buffer::getLanguages() const +{ + std::set languages; + getLanguages(languages); + return languages; +} + + +void Buffer::getLanguages(std::set & languages) const +{ + ParConstIterator end = par_iterator_end(); + for (ParConstIterator it = par_iterator_begin(); it != end; ++it) + it->getLanguages(languages); + // also children + std::vector clist = getChildren(); + for (vector::const_iterator cit = clist.begin(); + cit != clist.end(); ++cit) + (*cit)->getLanguages(languages); +} + + DocIterator Buffer::getParFromID(int const id) const { Buffer * buf = const_cast(this); diff --git a/src/Buffer.h b/src/Buffer.h index acf8bfd404..1d8f003a7d 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -375,6 +375,8 @@ public: /// bool isMultiLingual() const; + /// + std::set getLanguages() const; /// BufferParams & params(); @@ -572,6 +574,8 @@ private: */ ReadStatus readFile(Lexer &, support::FileName const & filename, bool fromString = false); + /// + void getLanguages(std::set &) const; /// Use the Pimpl idiom to hide the internals. class Impl; diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 7d1ef37f25..a45e71b52b 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -2603,7 +2603,7 @@ void Paragraph::changeLanguage(BufferParams const & bparams, bool Paragraph::isMultiLingual(BufferParams const & bparams) const { - Language const * doc_language = bparams.language; + Language const * doc_language = bparams.language; FontList::const_iterator cit = d->fontlist_.begin(); FontList::const_iterator end = d->fontlist_.end(); @@ -2616,6 +2616,20 @@ bool Paragraph::isMultiLingual(BufferParams const & bparams) const } +void Paragraph::getLanguages(std::set & languages) const +{ + FontList::const_iterator cit = d->fontlist_.begin(); + FontList::const_iterator end = d->fontlist_.end(); + + for (; cit != end; ++cit) { + Language const * lang = cit->font().language(); + if (lang != ignore_language && + lang != latex_language) + languages.insert(lang); + } +} + + docstring Paragraph::asString(int options) const { return asString(0, size(), options); diff --git a/src/Paragraph.h b/src/Paragraph.h index a558d3fafc..b50cfacc88 100644 --- a/src/Paragraph.h +++ b/src/Paragraph.h @@ -23,6 +23,8 @@ #include "support/strfwd.h" #include "support/types.h" +#include + namespace lyx { class AuthorList; @@ -117,6 +119,8 @@ public: Language const * from, Language const * to); /// bool isMultiLingual(BufferParams const &) const; + /// + void getLanguages(std::set &) const; /// Convert the paragraph to a string. /// \param AsStringParameter options. This can contain any combination of diff --git a/src/Text3.cpp b/src/Text3.cpp index f292c1a5b1..680494835d 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -2560,6 +2560,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd, case LFUN_LANGUAGE: enable = !cur.inset().getLayout().isPassThru(); + flag.setOnOff(to_utf8(cmd.argument()) == cur.real_current_font.language()->lang()); break; case LFUN_BREAK_PARAGRAPH: diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp index 71220f590b..094e161a13 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -38,6 +38,7 @@ #include "FuncStatus.h" #include "IndicesList.h" #include "KeyMap.h" +#include "Language.h" #include "Lexer.h" #include "LyXAction.h" #include "LyX.h" // for lastfiles @@ -164,7 +165,9 @@ public: /** Available graphics groups */ GraphicsGroups, /// Words suggested by the spellchecker. - SpellingSuggestions + SpellingSuggestions, + /** Used Languages */ + LanguageSelector }; explicit MenuItem(Kind kind) : kind_(kind), optional_(false) {} @@ -322,6 +325,7 @@ public: void expandCiteStyles(BufferView const *); void expandGraphicsGroups(BufferView const *); void expandSpellingSuggestions(BufferView const *); + void expandLanguageSelector(Buffer const * buf); /// ItemList items_; /// @@ -428,7 +432,8 @@ void MenuDefinition::read(Lexer & lex) md_pasterecent, md_toolbars, md_graphicsgroups, - md_spellingsuggestions + md_spellingsuggestions, + md_languageselector }; LexerKeyword menutags[] = { @@ -450,6 +455,7 @@ void MenuDefinition::read(Lexer & lex) { "indiceslists", md_indiceslists }, { "indiceslistscontext", md_indiceslistscontext }, { "item", md_item }, + { "languageselector", md_languageselector }, { "lastfiles", md_lastfiles }, { "optitem", md_optitem }, { "optsubmenu", md_optsubmenu }, @@ -568,6 +574,10 @@ void MenuDefinition::read(Lexer & lex) add(MenuItem(MenuItem::SpellingSuggestions)); break; + case md_languageselector: + add(MenuItem(MenuItem::LanguageSelector)); + break; + case md_indices: add(MenuItem(MenuItem::Indices)); break; @@ -754,6 +764,36 @@ void MenuDefinition::expandSpellingSuggestions(BufferView const * bv) } +void MenuDefinition::expandLanguageSelector(Buffer const * buf) +{ + if (!buf) + return; + + std::set languages = + buf->masterBuffer()->getLanguages(); + + if (languages.size() < 2) { + add(MenuItem(MenuItem::Command, qt_("Language ...|L"), + FuncRequest(LFUN_DIALOG_SHOW, "character"))); + return; + } + + MenuItem item(MenuItem::Submenu, qt_("Language|L")); + item.setSubmenu(MenuDefinition(qt_("Language"))); + std::set::const_iterator const begin = languages.begin(); + for (std::set::const_iterator cit = begin; + cit != languages.end(); ++cit) { + MenuItem w(MenuItem::Command, qt_((*cit)->display()), + FuncRequest(LFUN_LANGUAGE, (*cit)->lang())); + item.submenu().addWithStatusCheck(w); + } + item.submenu().add(MenuItem(MenuItem::Separator)); + item.submenu().add(MenuItem(MenuItem::Command, qt_("More Languages ..."), + FuncRequest(LFUN_DIALOG_SHOW, "character"))); + add(item); +} + + void MenuDefinition::expandLastfiles() { LastFilesSection::LastFiles const & lf = theSession().lastFiles().lastFiles(); @@ -1652,6 +1692,10 @@ void Menus::Impl::expand(MenuDefinition const & frommenu, tomenu.expandSpellingSuggestions(bv); break; + case MenuItem::LanguageSelector: + tomenu.expandLanguageSelector(buf); + break; + case MenuItem::Submenu: { MenuItem item(*cit); item.setSubmenu(MenuDefinition(cit->submenuname()));