Fix display of bindings for StaticMenuButton

This requires to add a parameter to GuiToolbar::addItem so that it is
possble to make a difference between toolbar buttons and menu items.

The long-term solution is to rely on the menu backend for such things.

Fixes bug #12004.
This commit is contained in:
Jean-Marc Lasgouttes 2022-07-19 18:39:04 +02:00
parent 23a27e90ba
commit 7823d3b01b
2 changed files with 14 additions and 7 deletions

View File

@ -142,17 +142,23 @@ void GuiToolbar::setVisibility(int visibility)
}
Action * GuiToolbar::addItem(ToolbarItem const & item)
Action * GuiToolbar::addItem(ToolbarItem const & item, bool menu)
{
QString text = toqstr(item.label);
QString tooltip = text;
// Get the keys bound to this action, but keep only the
// first one later
KeyMap::Bindings bindings = theTopLevelKeymap().findBindings(*item.func);
if (!bindings.empty())
text += " [" + toqstr(bindings.begin()->print(KeySequence::ForGui)) + "]";
if (!bindings.empty()) {
QString binding = toqstr(bindings.begin()->print(KeySequence::ForGui));
if (menu)
text += '\t' + binding;
else
tooltip += " [" + binding + "]";
}
Action * act = new Action(item.func, getIcon(*item.func, false), text,
text, this);
tooltip, this);
if (item.type == ToolbarItem::BIDICOMMAND)
act->setRtlIcon(getIcon(*item.func, false, true));
@ -277,7 +283,7 @@ void StaticMenuButton::initialize()
ToolbarInfo::item_iterator const end = tbinfo->items.end();
for (; it != end; ++it)
if (!getStatus(*it->func).unknown())
m->add(bar_->addItem(*it));
m->add(bar_->addItem(*it, true));
setMenu(m);
}

View File

@ -169,8 +169,9 @@ public:
///
GuiCommandBuffer * commandBuffer() { return command_buffer_; }
///
Action * addItem(ToolbarItem const & item);
/// add item to toolbar.
/// \param menu : when true, the item is for a menu entry, not a button.
Action * addItem(ToolbarItem const & item, bool menu = false);
///
GuiView const & owner() { return owner_; }