From 64e68defccf32791d7d072793a9a9e687cfd50e6 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Wed, 3 Oct 2012 07:27:36 +0200 Subject: [PATCH] Ronen's patch for lfun language set This adds an optional 'set' argument to the language lfun and reintroduces toggling. Additions by me reintroduce the possibility to reset to the document language via 'language reset' or just 'language' (cherry picked from commit e3e6befc543cec4eec00f9e28865230bf347a5fb) --- src/LyXAction.cpp | 9 +++++++-- src/Text3.cpp | 15 +++++++++++---- src/frontends/qt4/Menus.cpp | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index a58fc5e341..b143c87c00 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -2475,9 +2475,14 @@ void LyXAction::init() /*! * \var lyx::FuncCode lyx::LFUN_LANGUAGE * \li Action: Set language from the current cursor position. - * \li Syntax: language + * \li Syntax: language [set] * \li Params: : Requested language. Look in lib/languages for - the list. + the list. "language reset" or "language" (without param) + reset to the document language. + set: If used, the language will be set to the specified + language. Otherwise, the language will be toggled (i.e., if + the current language is LANG, switch to the document language + or the default language, if LANG is the document language). * \li Origin: Dekel, 2 Mar 2000 * \endvar */ diff --git a/src/Text3.cpp b/src/Text3.cpp index dc30d5aded..50a6d3d12c 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -1895,12 +1895,19 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) } case LFUN_LANGUAGE: { - Language const * lang = languages.getLanguage(to_utf8(cmd.argument())); - if (!lang) + string const lang_arg = cmd.getArg(0); + bool const reset = (lang_arg.empty() || lang_arg == "reset"); + Language const * lang = + reset ? reset_language + : languages.getLanguage(lang_arg); + // we allow reset_language, which is 0, but only if it + // was requested via empty or "reset" arg. + if (!lang && !reset) break; + bool const toggle = (cmd.getArg(1) != "set"); selectWordWhenUnderCursor(cur, WHOLE_WORD_STRICT); Font font(ignore_font, lang); - toggleAndShow(cur, this, font, false); + toggleAndShow(cur, this, font, toggle); break; } @@ -2667,7 +2674,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd, case LFUN_LANGUAGE: enable = !cur.paragraph().isPassThru(); - flag.setOnOff(to_utf8(cmd.argument()) == cur.real_current_font.language()->lang()); + flag.setOnOff(cmd.getArg(0) == 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 367f14b120..a3adbbac58 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -887,7 +887,7 @@ void MenuDefinition::expandLanguageSelector(Buffer const * buf) } } MenuItem w(MenuItem::Command, label, - FuncRequest(LFUN_LANGUAGE, (*cit)->lang())); + FuncRequest(LFUN_LANGUAGE, (*cit)->lang() + " set")); item.submenu().addWithStatusCheck(w); } item.submenu().add(MenuItem(MenuItem::Separator));