]> git.lyx.org Git - lyx.git/commitdiff
Implement sane UI for switching tristate toolbars (#6364)
authorJuergen Spitzmueller <spitz@lyx.org>
Thu, 17 Dec 2020 09:15:18 +0000 (10:15 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Thu, 17 Dec 2020 09:15:18 +0000 (10:15 +0100)
Also fix toolbar toggling with AllowAuto which was broken since
a long time.

lib/doc/UserGuide.lyx
lib/doc/de/UserGuide.lyx
src/FuncCode.h
src/LyXAction.cpp
src/frontends/qt/GuiToolbar.cpp
src/frontends/qt/GuiToolbar.h
src/frontends/qt/GuiView.cpp
src/frontends/qt/Menus.cpp
src/frontends/qt/Toolbars.cpp
src/frontends/qt/Toolbars.h

index 1d0104a1defcf9118528196baa12f906f24160fb..82d588786d09de52c60f5459d7fe469debfedc49 100644 (file)
@@ -8751,14 +8751,12 @@ Verbatim
 \end_layout
 
 \begin_layout Verbatim
-
 This is Verbatim.
 \end_layout
 
 \begin_layout Verbatim
 \noindent
 \align block
-
 The following 2 lines are empty:
 \end_layout
 
@@ -8771,7 +8769,6 @@ The following 2 lines are empty:
 \end_layout
 
 \begin_layout Verbatim
-
 Almost everything is allowed in Verbatim:"%&$§#~'`
 \backslash
 }][{|
@@ -8795,7 +8792,6 @@ Verbatim
 \end_layout
 
 \begin_layout Verbatim*
-
 This is Verbatim*.
 \end_layout
 
@@ -41119,13 +41115,41 @@ Command
 
 Buffer
 \family default
- can be turned on and off.
+ can be turned 
+\emph on
+on
+\emph default
+ and 
+\emph on
+off
+\emph default
+.
  The 
 \emph on
 on
 \emph default
  state is denoted in the menu with a checkmark.
- The 
+
+\change_deleted -712698321 1608195495
+\change_inserted -712698321 1608195492
+
+\end_layout
+
+\begin_layout Standard
+The
+\change_inserted -712698321 1608195407
+\family sans
+Phonetic
+\begin_inset space ~
+\end_inset
+
+Symbols
+\family default
+,
+\change_unchanged
 \family sans
 Table
 \family default
@@ -41156,12 +41180,34 @@ Panels
  toolbars can additionally be set to the state 
 \emph on
 automatic
+\change_deleted -712698321 1608195728
+
 \emph default
-, denoted in the menu with the suffix 
+, 
+\change_inserted -712698321 1608196033
+.
+ The state of these toolbars is set and indicated in a submenu which lets
+ you select 
+\family sans
+On
+\family default
+, 
+\family sans
+Off
+\family default
+, and 
+\family sans
+Automatic
+\family default
+.
+\change_deleted -712698321 1608195563
+denoted in the menu with the suffix 
 \family sans
 (auto)
 \family default
 .
+\change_unchanged
+
 \end_layout
 
 \begin_layout Standard
@@ -41169,7 +41215,15 @@ In the
 \emph on
 on
 \emph default
- state the toolbar is permanently shown; in the 
+ state the toolbar is permanently shown
+\change_inserted -712698321 1608195803
+, in the 
+\emph on
+off
+\emph default
+ state it is never shown
+\change_unchanged
+; in the 
 \emph on
 automatic
 \emph default
@@ -41177,7 +41231,11 @@ automatic
  or when a certain feature is enabled.
  That means that the review toolbar will only be shown if change tracking
  is activated, the math and table toolbars are only shown if the cursor
- is inside a formula or table respectively.
+ is inside a formula or table respectively
+\change_inserted -712698321 1608195857
+, the phonetic symbols toolbar only in the phonetic symbols environment
+\change_unchanged
+.
 \end_layout
 
 \begin_layout Standard
index 105eb51c2e7ecc41c863b16160878db2b1210f35..dfe5702533cee107ff13e347214216fbde7d0387 100644 (file)
@@ -8649,10 +8649,12 @@ Unformatiert
 \end_layout
 
 \begin_layout Verbatim
+
 Dies ist Unformatiert.
 \end_layout
 
 \begin_layout Verbatim
+
 Die folgenden 2 Zeilen sind leer:
 \end_layout
 
@@ -8665,6 +8667,7 @@ Die folgenden 2 Zeilen sind leer:
 \end_layout
 
 \begin_layout Verbatim
+
 Fast alles ist in Unformatiert erlaubt:"%&$§#~'`
 \backslash
 }][{|
@@ -8688,6 +8691,7 @@ Unformatiert
 \end_layout
 
 \begin_layout Verbatim*
+
 Dies ist Unformatiert*.
 \end_layout
 
@@ -38548,12 +38552,16 @@ enen Werkzeugleisten eingestellt werden.
 Befehlseingabefenster
 \family default
  können an- und ausgeschaltet werden.
- Der Zustand 
+ Der Status 
 \emph on
 an
 \emph default
  ist im Menü mit einem Häkchen gekennzeichnet.
- Die Werkzeugleisten 
+\end_layout
+
+\begin_layout Standard
+Die Werkzeugleisten 
 \family sans
 Überarbeiten
 \family default
@@ -38571,29 +38579,36 @@ Kontrollflächen
 \family default
 , 
 \family sans
-Mathe-Makros
+Mathe-Makros,
 \family default
- und 
 \family sans
 Mathe
 \family default
- können zusätzlich auf den Zustand 
+ und 
+\family sans
+Phonetische Symbole
+\family default
+ können zusätzlich auf den Status 
 \emph on
 automatisch
 \emph default
- gesetzt werden, der im Menü mit dem Suffix 
-\family sans
-(automatisch)
-\family default
- gekennzeichnet ist.
+ gesetzt werden.
+ Der Status dieser Werkzeugleisten wird in einem Untermenü mit den Einträgen
+ Ein, Aus und Automatisch gesetzt und angezeigt.
 \end_layout
 
 \begin_layout Standard
-Im Zustand 
+Im Status 
 \emph on
 an
 \emph default
- wird die Werkzeugleiste permanent angezeigt, im Zustand 
+ wird die Werkzeugleiste permanent angezeigt, im Status 
+\emph on
+aus
+\emph default
+ nie.
+ Im Zustand 
 \emph on
 automatisch
 \emph default
@@ -38603,13 +38618,18 @@ automatisch
 \family sans
 Überarbeiten
 \family default
- nur angezeigt wird, wenn Änderungsverfolgung aktiviert ist, die Mathe und
Tabellen Werkzeugleisten werden nur angezeigt, wenn der Cursor in einer
+ nur angezeigt wird, wenn Änderungsverfolgung aktiviert ist, die Mathe-
und Tabellen-Werkzeugleisten werden nur angezeigt, wenn der Cursor in einer
  Formel bzw.
 \begin_inset space \space{}
 \end_inset
 
-Tabelle ist.
+Tabelle ist, die Werkzeugleiste mit phonetischen Symbolen nur in der Einfügung
+\emph on
+Phonetische Symbole
+\emph default
+.
 \end_layout
 
 \begin_layout Standard
index 391faf71ce621c6d359eff8ee866afdbbd9d04f7..6b970fb579647febfc55772ee71861201465b1bc 100644 (file)
@@ -491,6 +491,8 @@ enum FuncCode
        LFUN_IF_RELATIVES,              // spitz 20200102
        LFUN_WINDOW_RAISE,              // forenr, 20202104
        LFUN_CITATION_OPEN,             // sanda, 20200815
+       LFUN_TOOLBAR_SET,               // spitz 20201217
+       // 385
        LFUN_LASTACTION                 // end of the table
 };
 
index 25bf0493c6aaa9d00dcf3da61111b62c0c2cc8bc..462e397d3a7c8d6fd0c4a5c81684a1cfe228162c 100644 (file)
@@ -3975,6 +3975,19 @@ void LyXAction::init()
 */
                { LFUN_TOOLBAR_MOVABLE, "toolbar-movable", NoBuffer, Buffer },
 
+/*!
+ * \var lyx::FuncCode lyx::LFUN_TOOLBAR_SET
+ * \li Action: Sets visibility of a given toolbar to on, off, or auto.
+ * \li Notion: Skipping "auto" when allowauto is false.
+ * \li Syntax: toolbar-set <NAME> [on|off|auto]
+ * \li Params: <NAME>: standard|extra|table|math|mathmacrotemplate|\n
+                      minibuffer|review|view/update|math_panels|vcs|
+                      view-others|update-others
+ * \li Origin: spitz, 17 Dec 2020
+ * \endvar
+ */
+               { LFUN_TOOLBAR_SET, "toolbar-set", NoBuffer, Buffer },
+
 /*!
  * \var lyx::FuncCode lyx::LFUN_TOOLBAR_TOGGLE
  * \li Action: Toggles visibility of a given toolbar between on/off/auto.
index 4e906e5e7121f09bb915bb48e826676e54ebfe16..5600f4a74f7212d78d6e25e3495ee00048311755 100644 (file)
@@ -611,36 +611,51 @@ bool GuiToolbar::isVisibiltyOn() const
 }
 
 
-void GuiToolbar::toggle()
+void GuiToolbar::setState(string const state)
 {
-       docstring state;
-       if (visibility_ & Toolbars::ALLOWAUTO) {
-               if (!(visibility_ & Toolbars::AUTO)) {
+       docstring newstate;
+       if (state == "auto") {
+               if (visibility_ & Toolbars::ALLOWAUTO) {
                        visibility_ |= Toolbars::AUTO;
                        hide();
-                       state = _("auto");
-               } else {
-                       visibility_ &= ~Toolbars::AUTO;
-                       if (isVisible()) {
-                               hide();
-                               state = _("off");
-                       } else {
-                               show();
-                               state = _("on");
-                       }
-               }
+                       newstate = _("auto");
+               } else
+                       owner_.message(bformat(_("Toolbar \"%1$s\" does not support state \"auto\""),
+                               qstring_to_ucs4(windowTitle())));
        } else {
-               if (isVisible()) {
+               if (visibility_ & Toolbars::AUTO)
+                       visibility_ &= ~Toolbars::AUTO;
+               if (state == "off") {
                        hide();
-                       state = _("off");
-               } else {
+                       newstate = _("off");
+               } else if (state == "on") {
                        show();
-                       state = _("on");
+                       newstate = _("on");
                }
        }
 
        owner_.message(bformat(_("Toolbar \"%1$s\" state set to %2$s"),
-               qstring_to_ucs4(windowTitle()), state));
+               qstring_to_ucs4(windowTitle()), newstate));
+}
+
+
+void GuiToolbar::toggle()
+{
+       if (visibility_ & Toolbars::ALLOWAUTO) {
+               if (!(visibility_ & Toolbars::AUTO) && !isVisibiltyOn()) {
+                       setState("auto");
+               } else {
+                       if (isVisibiltyOn())
+                               setState("off");
+                       else
+                               setState("on");
+               }
+       } else {
+               if (isVisible())
+                       setState("off");
+               else
+                       setState("on");
+       }
 }
 
 void GuiToolbar::movable(bool silent)
index aebc9e28442899d3cfb011548983a10d736aa49b..262b09ef0793202c9c987d50fb3391264dd3ea3f 100644 (file)
@@ -147,6 +147,8 @@ public:
        /// Refresh the contents of the bar.
        void update(int context = 0);
 
+       ///
+       void setState(std::string const state);
        ///
        void toggle();
 
index 6f50a15d57c53fea3cd9545a8a802586c7bf628b..1643493c08473c8040d03280d66f7596a111318c 100644 (file)
@@ -2117,6 +2117,41 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
                flag.setOnOff(devel_mode_);
                break;
 
+       case LFUN_TOOLBAR_SET: {
+               string const name = cmd.getArg(0);
+               string const state = cmd.getArg(1);
+               if (name.empty() || state.empty()) {
+                       enable = false;
+                       docstring const msg =
+                               _("Function toolbar-set requires two arguments!");
+                       flag.message(msg);
+                       break;
+               }
+               if (state != "on" && state != "off" && state != "auto") {
+                       enable = false;
+                       docstring const msg =
+                               bformat(_("Invalid argument \"%1$s\" to function toolbar-set!"),
+                                       from_utf8(state));
+                       flag.message(msg);
+                       break;
+               }
+               if (GuiToolbar * t = toolbar(name)) {
+                       bool const autovis = t->visibility() & Toolbars::AUTO;
+                       if (state == "on")
+                               flag.setOnOff(t->isVisible() && !autovis);
+                       else if (state == "off")
+                               flag.setOnOff(!t->isVisible() && !autovis);
+                       else if (state == "auto")
+                               flag.setOnOff(autovis);
+               } else {
+                       enable = false;
+                       docstring const msg =
+                               bformat(_("Unknown toolbar \"%1$s\""), from_utf8(name));
+                       flag.message(msg);
+               }
+               break;
+       }
+
        case LFUN_TOOLBAR_TOGGLE: {
                string const name = cmd.getArg(0);
                if (GuiToolbar * t = toolbar(name))
@@ -4275,6 +4310,14 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                                dr.setMessage(_("Developer mode is now disabled."));
                        break;
 
+               case LFUN_TOOLBAR_SET: {
+                       string const name = cmd.getArg(0);
+                       string const state = cmd.getArg(1);
+                       if (GuiToolbar * t = toolbar(name))
+                               t->setState(state);
+                       break;
+               }
+
                case LFUN_TOOLBAR_TOGGLE: {
                        string const name = cmd.getArg(0);
                        if (GuiToolbar * t = toolbar(name))
index c30b73807c5d503155b355dcc73ecb58307bb9d9..266fb68d306968019ee50f711cfdd9c44811d770 100644 (file)
@@ -1415,8 +1415,19 @@ void MenuDefinition::expandToolbars()
        Toolbars::Infos::const_iterator cit = guiApp->toolbars().begin();
        Toolbars::Infos::const_iterator end = guiApp->toolbars().end();
        for (; cit != end; ++cit) {
-               MenuItem const item(MenuItem::Command, toqstr(cit->gui_name),
-                               FuncRequest(LFUN_TOOLBAR_TOGGLE, cit->name));
+               MenuItem item(MenuItem::Command, toqstr(cit->gui_name),
+                             FuncRequest(LFUN_TOOLBAR_TOGGLE, cit->name));
+               if (cit->allow_auto) {
+                       MenuDefinition tristate;
+                       tristate.add(MenuItem(MenuItem::Command, qt_("[[Toolbar]]On|O"),
+                                             FuncRequest(LFUN_TOOLBAR_SET, cit->name + " on")));
+                       tristate.add(MenuItem(MenuItem::Command, qt_("[[Toolbar]]Off|f"),
+                                             FuncRequest(LFUN_TOOLBAR_SET, cit->name + " off")));
+                       tristate.add(MenuItem(MenuItem::Command, qt_("[[Toolbar]]Automatic|A"),
+                                             FuncRequest(LFUN_TOOLBAR_SET, cit->name + " auto")));
+                       item = MenuItem(MenuItem::Submenu,toqstr(cit->gui_name));
+                       item.setSubmenu(tristate);
+               }
                if (guiApp->toolbars().isMainToolbar(cit->name))
                        add(item);
                else
index 7d29344732e8d44a05fdb1cdc59689a148135ea1..cf184ae9e25273c7bb6abc0c482f9dc6dee50136 100644 (file)
@@ -405,8 +405,7 @@ void Toolbars::readToolbarSettings(Lexer & lex)
 
                if (visibility & ALLOWAUTO) {
                        if (ToolbarInfo const * ti = info(name))
-                               const_cast<ToolbarInfo *>(ti)->gui_name +=
-                                       " (" + _("auto") + ")";
+                               const_cast<ToolbarInfo *>(ti)->allow_auto = true;
                }
        }
 }
index 2d9213986cfb8e1224af2068d88584d7eb974424..be621c9db8daa230f5c91c8959c694589459e03c 100644 (file)
@@ -80,12 +80,14 @@ public:
        typedef Items::const_iterator item_iterator;
 
        explicit ToolbarInfo(std::string const & name = std::string())
-               : name(name) {}
+               : name(name), allow_auto(false) {}
 
        /// toolbar name
        std::string name;
        /// toolbar GUI name
        docstring gui_name;
+       /// allows auto visibility
+       bool allow_auto;
        /// toolbar contents
        Items items;