[LyX/master] Implement sane UI for switching tristate toolbars (#6364)
Juergen Spitzmueller
spitz at lyx.org
Thu Dec 17 08:46:11 UTC 2020
commit f66146973407ecb44ca93bae074ee916d5ed2f04
Author: Juergen Spitzmueller <spitz at lyx.org>
Date: Thu Dec 17 10:15:18 2020 +0100
Implement sane UI for switching tristate toolbars (#6364)
Also fix toolbar toggling with AllowAuto which was broken since
a long time.
---
lib/doc/UserGuide.lyx | 76 ++++++++++++++++++++++++++++++++++-----
lib/doc/de/UserGuide.lyx | 50 ++++++++++++++++++--------
src/FuncCode.h | 2 +
src/LyXAction.cpp | 13 +++++++
src/frontends/qt/GuiToolbar.cpp | 55 ++++++++++++++++++----------
src/frontends/qt/GuiToolbar.h | 2 +
src/frontends/qt/GuiView.cpp | 43 ++++++++++++++++++++++
src/frontends/qt/Menus.cpp | 15 +++++++-
src/frontends/qt/Toolbars.cpp | 3 +-
src/frontends/qt/Toolbars.h | 4 ++-
10 files changed, 214 insertions(+), 49 deletions(-)
diff --git a/lib/doc/UserGuide.lyx b/lib/doc/UserGuide.lyx
index 1d0104a..82d5887 100644
--- a/lib/doc/UserGuide.lyx
+++ b/lib/doc/UserGuide.lyx
@@ -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
diff --git a/lib/doc/de/UserGuide.lyx b/lib/doc/de/UserGuide.lyx
index 105eb51..dfe5702 100644
--- a/lib/doc/de/UserGuide.lyx
+++ b/lib/doc/de/UserGuide.lyx
@@ -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
diff --git a/src/FuncCode.h b/src/FuncCode.h
index 391faf7..6b970fb 100644
--- a/src/FuncCode.h
+++ b/src/FuncCode.h
@@ -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
};
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index 25bf049..462e397 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -3976,6 +3976,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.
* \li Notion: Skipping "auto" when allowauto is false.
diff --git a/src/frontends/qt/GuiToolbar.cpp b/src/frontends/qt/GuiToolbar.cpp
index 4e906e5..5600f4a 100644
--- a/src/frontends/qt/GuiToolbar.cpp
+++ b/src/frontends/qt/GuiToolbar.cpp
@@ -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)
diff --git a/src/frontends/qt/GuiToolbar.h b/src/frontends/qt/GuiToolbar.h
index aebc9e2..262b09e 100644
--- a/src/frontends/qt/GuiToolbar.h
+++ b/src/frontends/qt/GuiToolbar.h
@@ -148,6 +148,8 @@ public:
void update(int context = 0);
///
+ void setState(std::string const state);
+ ///
void toggle();
/// toggles movability
diff --git a/src/frontends/qt/GuiView.cpp b/src/frontends/qt/GuiView.cpp
index 6f50a15..1643493 100644
--- a/src/frontends/qt/GuiView.cpp
+++ b/src/frontends/qt/GuiView.cpp
@@ -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))
diff --git a/src/frontends/qt/Menus.cpp b/src/frontends/qt/Menus.cpp
index c30b738..266fb68 100644
--- a/src/frontends/qt/Menus.cpp
+++ b/src/frontends/qt/Menus.cpp
@@ -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
diff --git a/src/frontends/qt/Toolbars.cpp b/src/frontends/qt/Toolbars.cpp
index 7d29344..cf184ae 100644
--- a/src/frontends/qt/Toolbars.cpp
+++ b/src/frontends/qt/Toolbars.cpp
@@ -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;
}
}
}
diff --git a/src/frontends/qt/Toolbars.h b/src/frontends/qt/Toolbars.h
index 2d92139..be621c9 100644
--- a/src/frontends/qt/Toolbars.h
+++ b/src/frontends/qt/Toolbars.h
@@ -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;
More information about the lyx-cvs
mailing list