2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2011-01-12 09:45:19 +01:00
|
|
|
|
|
|
|
|
#include "proxyaction.h"
|
|
|
|
|
|
2019-08-06 10:07:19 +02:00
|
|
|
#include "stringutils.h"
|
|
|
|
|
|
2011-01-12 09:45:19 +01:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
|
|
|
|
ProxyAction::ProxyAction(QObject *parent) :
|
2018-07-23 10:45:40 +02:00
|
|
|
QAction(parent)
|
2011-01-12 09:45:19 +01:00
|
|
|
{
|
2015-03-05 22:00:05 +02:00
|
|
|
connect(this, &QAction::changed, this, &ProxyAction::updateToolTipWithKeySequence);
|
2011-01-12 09:45:19 +01:00
|
|
|
updateState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProxyAction::setAction(QAction *action)
|
|
|
|
|
{
|
|
|
|
|
if (m_action == action)
|
|
|
|
|
return;
|
|
|
|
|
disconnectAction();
|
|
|
|
|
m_action = action;
|
|
|
|
|
connectAction();
|
|
|
|
|
updateState();
|
Add macOS touch bar support
Introduce a generic Utils::TouchBar that implements a touch bar for
macOS based on QAction. Touch bars can be nested, and one is set to be
the application's top level touch bar.
Also add an ActionContainer for the touch bar. That allows us to manage
the layout of the touch bar the same way we do with menus.
Since the touch bar is an input device with very limited space, a
command in the touch bar needs to be specifically styled for the touch
bar by setting either touchBarText or touchBarIcon (or both).
Touch bars can be nested by nesting the ActionContainers. A nested touch
bar ActionContainer needs to specify an icon and/or text to show in the
touch bar button that opens that sub-bar.
Commands are only shown in the touch bar if they are valid within the
current context.
Implementation-wise we cannot use the standard NSPopoverTouchBarItem for
nesting touch bar levels. We cannot hide items in the touch bar, because
hidden items still take up space in the touch bar. So we need to rebuild
the touch bar regularly. Since the items we show are very dynamic, every
time the items in the toplevel bar change because of a context change,
any opened sub-level touch bar closes. That is why we maintain a stack of
touch bar levels ourselves, replacing the main touch bar with the current
level, and managing opening and closing the levels manually.
This patch adds buttons for Help, Bookmarks, Header/Source, Follow
(Symbol), Decl/Def, and a sub-bar for the debugger actions.
Fixes: QTCREATORBUG-21263
Change-Id: Ib63e610f21a993f1d324fe23c83a7f2224f434ac
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
2018-10-05 13:52:57 +02:00
|
|
|
emit currentActionChanged(action);
|
2011-01-12 09:45:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProxyAction::updateState()
|
|
|
|
|
{
|
|
|
|
|
if (m_action) {
|
|
|
|
|
update(m_action, false);
|
|
|
|
|
} else {
|
|
|
|
|
// no active/delegate action, "visible" action is not enabled/visible
|
|
|
|
|
if (hasAttribute(Hide))
|
|
|
|
|
setVisible(false);
|
|
|
|
|
setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProxyAction::disconnectAction()
|
|
|
|
|
{
|
|
|
|
|
if (m_action) {
|
2015-03-05 22:00:05 +02:00
|
|
|
disconnect(m_action.data(), &QAction::changed, this, &ProxyAction::actionChanged);
|
2022-01-10 11:44:09 +01:00
|
|
|
disconnect(this, &ProxyAction::triggered, m_action.data(), &QAction::triggered);
|
|
|
|
|
disconnect(this, &ProxyAction::toggled, m_action.data(), &QAction::setChecked);
|
2011-01-12 09:45:19 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProxyAction::connectAction()
|
|
|
|
|
{
|
|
|
|
|
if (m_action) {
|
2022-01-10 11:44:09 +01:00
|
|
|
connect(m_action.data(), &QAction::changed, this, &ProxyAction::actionChanged);
|
|
|
|
|
connect(this, &ProxyAction::triggered, m_action.data(), &QAction::triggered);
|
2015-03-05 22:00:05 +02:00
|
|
|
connect(this, &ProxyAction::toggled, m_action.data(), &QAction::setChecked);
|
2011-01-12 09:45:19 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAction *ProxyAction::action() const
|
|
|
|
|
{
|
|
|
|
|
return m_action;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProxyAction::setAttribute(ProxyAction::Attribute attribute)
|
|
|
|
|
{
|
|
|
|
|
m_attributes |= attribute;
|
2011-01-31 15:16:52 +01:00
|
|
|
updateState();
|
2011-01-12 09:45:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProxyAction::removeAttribute(ProxyAction::Attribute attribute)
|
|
|
|
|
{
|
|
|
|
|
m_attributes &= ~attribute;
|
2011-01-31 15:16:52 +01:00
|
|
|
updateState();
|
2011-01-12 09:45:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ProxyAction::hasAttribute(ProxyAction::Attribute attribute)
|
|
|
|
|
{
|
|
|
|
|
return (m_attributes & attribute);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProxyAction::actionChanged()
|
|
|
|
|
{
|
|
|
|
|
update(m_action, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProxyAction::initialize(QAction *action)
|
|
|
|
|
{
|
|
|
|
|
update(action, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProxyAction::update(QAction *action, bool initialize)
|
|
|
|
|
{
|
|
|
|
|
if (!action)
|
|
|
|
|
return;
|
2022-01-10 11:44:09 +01:00
|
|
|
disconnect(this, &ProxyAction::changed, this, &ProxyAction::updateToolTipWithKeySequence);
|
2013-04-18 10:42:12 +02:00
|
|
|
if (initialize) {
|
2011-01-12 09:45:19 +01:00
|
|
|
setSeparator(action->isSeparator());
|
2013-04-18 10:42:12 +02:00
|
|
|
setMenuRole(action->menuRole());
|
|
|
|
|
}
|
2011-01-12 09:45:19 +01:00
|
|
|
if (hasAttribute(UpdateIcon) || initialize) {
|
|
|
|
|
setIcon(action->icon());
|
|
|
|
|
setIconText(action->iconText());
|
|
|
|
|
setIconVisibleInMenu(action->isIconVisibleInMenu());
|
|
|
|
|
}
|
|
|
|
|
if (hasAttribute(UpdateText) || initialize) {
|
|
|
|
|
setText(action->text());
|
|
|
|
|
m_toolTip = action->toolTip();
|
|
|
|
|
updateToolTipWithKeySequence();
|
|
|
|
|
setStatusTip(action->statusTip());
|
|
|
|
|
setWhatsThis(action->whatsThis());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setCheckable(action->isCheckable());
|
|
|
|
|
|
2011-01-13 11:35:22 +01:00
|
|
|
if (!initialize) {
|
2022-01-10 11:44:09 +01:00
|
|
|
if (isChecked() != action->isChecked()) {
|
|
|
|
|
if (m_action)
|
|
|
|
|
disconnect(this, &ProxyAction::toggled, m_action.data(), &QAction::setChecked);
|
|
|
|
|
setChecked(action->isChecked());
|
|
|
|
|
if (m_action)
|
|
|
|
|
connect(this, &ProxyAction::toggled, m_action.data(), &QAction::setChecked);
|
|
|
|
|
}
|
2011-01-13 11:35:22 +01:00
|
|
|
setEnabled(action->isEnabled());
|
|
|
|
|
setVisible(action->isVisible());
|
|
|
|
|
}
|
2022-01-10 11:44:09 +01:00
|
|
|
connect(this, &ProxyAction::changed, this, &ProxyAction::updateToolTipWithKeySequence);
|
2011-01-12 09:45:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ProxyAction::shortcutVisibleInToolTip() const
|
|
|
|
|
{
|
|
|
|
|
return m_showShortcut;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProxyAction::setShortcutVisibleInToolTip(bool visible)
|
|
|
|
|
{
|
|
|
|
|
m_showShortcut = visible;
|
|
|
|
|
updateToolTipWithKeySequence();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProxyAction::updateToolTipWithKeySequence()
|
|
|
|
|
{
|
2011-05-27 14:34:48 +02:00
|
|
|
if (m_block)
|
2011-01-12 09:45:19 +01:00
|
|
|
return;
|
2011-05-27 14:34:48 +02:00
|
|
|
m_block = true;
|
2011-01-12 09:45:19 +01:00
|
|
|
if (!m_showShortcut || shortcut().isEmpty())
|
|
|
|
|
setToolTip(m_toolTip);
|
|
|
|
|
else
|
|
|
|
|
setToolTip(stringWithAppendedShortcut(m_toolTip, shortcut()));
|
2011-05-27 14:34:48 +02:00
|
|
|
m_block = false;
|
2011-01-12 09:45:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ProxyAction::stringWithAppendedShortcut(const QString &str, const QKeySequence &shortcut)
|
|
|
|
|
{
|
2019-08-06 10:07:19 +02:00
|
|
|
const QString s = stripAccelerator(str);
|
2022-05-16 08:03:56 +02:00
|
|
|
return QString::fromLatin1("<div style=\"white-space:pre\">%1 "
|
|
|
|
|
"<span style=\"color: gray; font-size: small\">%2</span></div>")
|
2019-08-06 10:07:19 +02:00
|
|
|
.arg(s, shortcut.toString(QKeySequence::NativeText));
|
2011-01-12 09:45:19 +01:00
|
|
|
}
|
2016-04-25 12:25:10 +02:00
|
|
|
|
|
|
|
|
ProxyAction *ProxyAction::proxyActionWithIcon(QAction *original, const QIcon &newIcon)
|
|
|
|
|
{
|
2018-07-19 16:39:41 +02:00
|
|
|
auto proxyAction = new ProxyAction(original);
|
2016-04-25 12:25:10 +02:00
|
|
|
proxyAction->setAction(original);
|
|
|
|
|
proxyAction->setIcon(newIcon);
|
|
|
|
|
proxyAction->setAttribute(UpdateText);
|
|
|
|
|
return proxyAction;
|
|
|
|
|
}
|