Implement sane UI for switching tristate toolbars (#6364)

Also fix toolbar toggling with AllowAuto which was broken since
a long time.
This commit is contained in:
Juergen Spitzmueller 2020-12-17 10:15:18 +01:00
parent 7e11cb2b37
commit f661469734
10 changed files with 214 additions and 49 deletions

View File

@ -8751,14 +8751,12 @@ Verbatim
\end_layout \end_layout
\begin_layout Verbatim \begin_layout Verbatim
This is Verbatim. This is Verbatim.
\end_layout \end_layout
\begin_layout Verbatim \begin_layout Verbatim
\noindent \noindent
\align block \align block
The following 2 lines are empty: The following 2 lines are empty:
\end_layout \end_layout
@ -8771,7 +8769,6 @@ The following 2 lines are empty:
\end_layout \end_layout
\begin_layout Verbatim \begin_layout Verbatim
Almost everything is allowed in Verbatim:"%&$§#~'` Almost everything is allowed in Verbatim:"%&$§#~'`
\backslash \backslash
}][{| }][{|
@ -8795,7 +8792,6 @@ Verbatim
\end_layout \end_layout
\begin_layout Verbatim* \begin_layout Verbatim*
This is Verbatim*. This is Verbatim*.
\end_layout \end_layout
@ -41119,13 +41115,41 @@ Command
Buffer Buffer
\family default \family default
can be turned on and off. can be turned
\emph on
on
\emph default
and
\emph on
off
\emph default
.
The The
\emph on \emph on
on on
\emph default \emph default
state is denoted in the menu with a checkmark. state is denoted in the menu with a checkmark.
\change_deleted -712698321 1608195495
\change_inserted -712698321 1608195492
\end_layout
\begin_layout Standard
The The
\change_inserted -712698321 1608195407
\family sans
Phonetic
\begin_inset space ~
\end_inset
Symbols
\family default
,
\change_unchanged
\family sans \family sans
Table Table
\family default \family default
@ -41156,12 +41180,34 @@ Panels
toolbars can additionally be set to the state toolbars can additionally be set to the state
\emph on \emph on
automatic automatic
\change_deleted -712698321 1608195728
\emph default \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 \family sans
(auto) (auto)
\family default \family default
. .
\change_unchanged
\end_layout \end_layout
\begin_layout Standard \begin_layout Standard
@ -41169,7 +41215,15 @@ In the
\emph on \emph on
on on
\emph default \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 \emph on
automatic automatic
\emph default \emph default
@ -41177,7 +41231,11 @@ automatic
or when a certain feature is enabled. or when a certain feature is enabled.
That means that the review toolbar will only be shown if change tracking 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 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 \end_layout
\begin_layout Standard \begin_layout Standard

View File

@ -8649,10 +8649,12 @@ Unformatiert
\end_layout \end_layout
\begin_layout Verbatim \begin_layout Verbatim
Dies ist Unformatiert. Dies ist Unformatiert.
\end_layout \end_layout
\begin_layout Verbatim \begin_layout Verbatim
Die folgenden 2 Zeilen sind leer: Die folgenden 2 Zeilen sind leer:
\end_layout \end_layout
@ -8665,6 +8667,7 @@ Die folgenden 2 Zeilen sind leer:
\end_layout \end_layout
\begin_layout Verbatim \begin_layout Verbatim
Fast alles ist in Unformatiert erlaubt:"%&$§#~'` Fast alles ist in Unformatiert erlaubt:"%&$§#~'`
\backslash \backslash
}][{| }][{|
@ -8688,6 +8691,7 @@ Unformatiert
\end_layout \end_layout
\begin_layout Verbatim* \begin_layout Verbatim*
Dies ist Unformatiert*. Dies ist Unformatiert*.
\end_layout \end_layout
@ -38548,11 +38552,15 @@ enen Werkzeugleisten eingestellt werden.
Befehlseingabefenster Befehlseingabefenster
\family default \family default
können an- und ausgeschaltet werden. können an- und ausgeschaltet werden.
Der Zustand Der Status
\emph on \emph on
an an
\emph default \emph default
ist im Menü mit einem Häkchen gekennzeichnet. ist im Menü mit einem Häkchen gekennzeichnet.
\end_layout
\begin_layout Standard
Die Werkzeugleisten Die Werkzeugleisten
\family sans \family sans
Überarbeiten Überarbeiten
@ -38571,29 +38579,36 @@ Kontrollflächen
\family default \family default
, ,
\family sans \family sans
Mathe-Makros Mathe-Makros,
\family default \family default
und
\family sans \family sans
Mathe Mathe
\family default \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 \emph on
automatisch automatisch
\emph default \emph default
gesetzt werden, der im Menü mit dem Suffix gesetzt werden.
\family sans Der Status dieser Werkzeugleisten wird in einem Untermenü mit den Einträgen
(automatisch) Ein, Aus und Automatisch gesetzt und angezeigt.
\family default
gekennzeichnet ist.
\end_layout \end_layout
\begin_layout Standard \begin_layout Standard
Im Zustand Im Status
\emph on \emph on
an an
\emph default \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 \emph on
automatisch automatisch
\emph default \emph default
@ -38603,13 +38618,18 @@ automatisch
\family sans \family sans
Überarbeiten Überarbeiten
\family default \family default
nur angezeigt wird, wenn Änderungsverfolgung aktiviert ist, die Mathe und nur angezeigt wird, wenn Änderungsverfolgung aktiviert ist, die Mathe-
Tabellen Werkzeugleisten werden nur angezeigt, wenn der Cursor in einer und Tabellen-Werkzeugleisten werden nur angezeigt, wenn der Cursor in einer
Formel bzw. Formel bzw.
\begin_inset space \space{} \begin_inset space \space{}
\end_inset \end_inset
Tabelle ist. Tabelle ist, die Werkzeugleiste mit phonetischen Symbolen nur in der Einfügung
\emph on
Phonetische Symbole
\emph default
.
\end_layout \end_layout
\begin_layout Standard \begin_layout Standard

View File

@ -491,6 +491,8 @@ enum FuncCode
LFUN_IF_RELATIVES, // spitz 20200102 LFUN_IF_RELATIVES, // spitz 20200102
LFUN_WINDOW_RAISE, // forenr, 20202104 LFUN_WINDOW_RAISE, // forenr, 20202104
LFUN_CITATION_OPEN, // sanda, 20200815 LFUN_CITATION_OPEN, // sanda, 20200815
LFUN_TOOLBAR_SET, // spitz 20201217
// 385
LFUN_LASTACTION // end of the table LFUN_LASTACTION // end of the table
}; };

View File

@ -3975,6 +3975,19 @@ void LyXAction::init()
*/ */
{ LFUN_TOOLBAR_MOVABLE, "toolbar-movable", NoBuffer, Buffer }, { 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 * \var lyx::FuncCode lyx::LFUN_TOOLBAR_TOGGLE
* \li Action: Toggles visibility of a given toolbar between on/off/auto. * \li Action: Toggles visibility of a given toolbar between on/off/auto.

View File

@ -611,36 +611,51 @@ bool GuiToolbar::isVisibiltyOn() const
} }
void GuiToolbar::toggle() void GuiToolbar::setState(string const state)
{ {
docstring state; docstring newstate;
if (state == "auto") {
if (visibility_ & Toolbars::ALLOWAUTO) { if (visibility_ & Toolbars::ALLOWAUTO) {
if (!(visibility_ & Toolbars::AUTO)) {
visibility_ |= Toolbars::AUTO; visibility_ |= Toolbars::AUTO;
hide(); hide();
state = _("auto"); newstate = _("auto");
} else
owner_.message(bformat(_("Toolbar \"%1$s\" does not support state \"auto\""),
qstring_to_ucs4(windowTitle())));
} else { } else {
if (visibility_ & Toolbars::AUTO)
visibility_ &= ~Toolbars::AUTO; visibility_ &= ~Toolbars::AUTO;
if (isVisible()) { if (state == "off") {
hide(); hide();
state = _("off"); newstate = _("off");
} else { } else if (state == "on") {
show(); show();
state = _("on"); newstate = _("on");
}
}
} else {
if (isVisible()) {
hide();
state = _("off");
} else {
show();
state = _("on");
} }
} }
owner_.message(bformat(_("Toolbar \"%1$s\" state set to %2$s"), 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) void GuiToolbar::movable(bool silent)

View File

@ -147,6 +147,8 @@ public:
/// Refresh the contents of the bar. /// Refresh the contents of the bar.
void update(int context = 0); void update(int context = 0);
///
void setState(std::string const state);
/// ///
void toggle(); void toggle();

View File

@ -2117,6 +2117,41 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
flag.setOnOff(devel_mode_); flag.setOnOff(devel_mode_);
break; 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: { case LFUN_TOOLBAR_TOGGLE: {
string const name = cmd.getArg(0); string const name = cmd.getArg(0);
if (GuiToolbar * t = toolbar(name)) if (GuiToolbar * t = toolbar(name))
@ -4275,6 +4310,14 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
dr.setMessage(_("Developer mode is now disabled.")); dr.setMessage(_("Developer mode is now disabled."));
break; 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: { case LFUN_TOOLBAR_TOGGLE: {
string const name = cmd.getArg(0); string const name = cmd.getArg(0);
if (GuiToolbar * t = toolbar(name)) if (GuiToolbar * t = toolbar(name))

View File

@ -1415,8 +1415,19 @@ void MenuDefinition::expandToolbars()
Toolbars::Infos::const_iterator cit = guiApp->toolbars().begin(); Toolbars::Infos::const_iterator cit = guiApp->toolbars().begin();
Toolbars::Infos::const_iterator end = guiApp->toolbars().end(); Toolbars::Infos::const_iterator end = guiApp->toolbars().end();
for (; cit != end; ++cit) { for (; cit != end; ++cit) {
MenuItem const item(MenuItem::Command, toqstr(cit->gui_name), MenuItem item(MenuItem::Command, toqstr(cit->gui_name),
FuncRequest(LFUN_TOOLBAR_TOGGLE, cit->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)) if (guiApp->toolbars().isMainToolbar(cit->name))
add(item); add(item);
else else

View File

@ -405,8 +405,7 @@ void Toolbars::readToolbarSettings(Lexer & lex)
if (visibility & ALLOWAUTO) { if (visibility & ALLOWAUTO) {
if (ToolbarInfo const * ti = info(name)) if (ToolbarInfo const * ti = info(name))
const_cast<ToolbarInfo *>(ti)->gui_name += const_cast<ToolbarInfo *>(ti)->allow_auto = true;
" (" + _("auto") + ")";
} }
} }
} }

View File

@ -80,12 +80,14 @@ public:
typedef Items::const_iterator item_iterator; typedef Items::const_iterator item_iterator;
explicit ToolbarInfo(std::string const & name = std::string()) explicit ToolbarInfo(std::string const & name = std::string())
: name(name) {} : name(name), allow_auto(false) {}
/// toolbar name /// toolbar name
std::string name; std::string name;
/// toolbar GUI name /// toolbar GUI name
docstring gui_name; docstring gui_name;
/// allows auto visibility
bool allow_auto;
/// toolbar contents /// toolbar contents
Items items; Items items;