]> git.lyx.org Git - features.git/commitdiff
Ronen's patch for lfun language set
authorJuergen Spitzmueller <spitz@lyx.org>
Wed, 3 Oct 2012 05:27:36 +0000 (07:27 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Wed, 3 Oct 2012 05:27:36 +0000 (07:27 +0200)
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'

src/LyXAction.cpp
src/Text3.cpp
src/frontends/qt4/Menus.cpp

index 1a49bd4e287abc9a9866659100e52f647b409164..dbda5c0a4ca94fc05916dc5e03dcd9270f289c75 100644 (file)
@@ -2514,9 +2514,14 @@ void LyXAction::init()
 /*!
  * \var lyx::FuncCode lyx::LFUN_LANGUAGE
  * \li Action: Set language from the current cursor position.
- * \li Syntax: language <LANG>
+ * \li Syntax: language <LANG> [set]
  * \li Params: <LANG>: 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
  */
index b114cf242e5ff8c9e12ea9049f177e62440ced8d..ecb5d257641f21c049e6ab4ae7c44d2ff08ae6a0 100644 (file)
@@ -1962,12 +1962,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;
        }
 
@@ -2749,7 +2756,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_PARAGRAPH_BREAK:
index 22d1d9e80fc4e2a9e93b32e587d3a85b8613bced..674afaf09a56f973d10b2f14a8df18fd295ae30a 100644 (file)
@@ -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));