Files
qt-creator/src/plugins/coreplugin/actionmanager/command.h

100 lines
2.6 KiB
C
Raw Normal View History

// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
2008-12-02 14:09:21 +01:00
#pragma once
2008-12-02 12:01:29 +01:00
#include <coreplugin/core_global.h>
#include <utils/hostosinfo.h>
#include <utils/id.h>
#include <QObject>
QT_BEGIN_NAMESPACE
class QAction;
class QKeySequence;
class QToolButton;
QT_END_NAMESPACE
2008-12-02 12:01:29 +01:00
namespace Core {
namespace Internal {
class ActionManagerPrivate;
class CommandPrivate;
} // namespace Internal
2008-12-02 12:01:29 +01:00
class ActionManager;
class Context;
constexpr bool useMacShortcuts = Utils::HostOsInfo::isMacHost();
class CORE_EXPORT Command : public QObject
2008-12-02 12:01:29 +01:00
{
Q_OBJECT
public:
enum CommandAttribute {
CA_Hide = 1,
CA_UpdateText = 2,
CA_UpdateIcon = 4,
CA_NonConfigurable = 8
2008-12-02 12:01:29 +01:00
};
Q_DECLARE_FLAGS(CommandAttributes, CommandAttribute)
2008-12-02 12:01:29 +01:00
~Command();
void setDefaultKeySequence(const QKeySequence &key);
void setDefaultKeySequences(const QList<QKeySequence> &keys);
QList<QKeySequence> defaultKeySequences() const;
QList<QKeySequence> keySequences() const;
QKeySequence keySequence() const;
// explicitly set the description (used e.g. in shortcut settings)
// default is to use the action text for actions, or the whatsThis for shortcuts,
// or, as a last fall back if these are empty, the command ID string
// override the default e.g. if the text is context dependent and contains file names etc
void setDescription(const QString &text);
QString description() const;
2008-12-02 12:01:29 +01:00
Utils::Id id() const;
2008-12-02 12:01:29 +01:00
QAction *action() const;
QAction *actionForContext(const Utils::Id &contextId) const;
Context context() const;
2008-12-02 12:01:29 +01:00
void setAttribute(CommandAttribute attr);
void removeAttribute(CommandAttribute attr);
bool hasAttribute(CommandAttribute attr) const;
2008-12-02 12:01:29 +01:00
bool isActive() const;
2008-12-02 12:01:29 +01:00
void setKeySequences(const QList<QKeySequence> &keys);
QString stringWithAppendedShortcut(const QString &str) const;
void augmentActionWithShortcutToolTip(QAction *action) const;
static QToolButton *toolButtonWithAppendedShortcut(QAction *action, Command *cmd);
2008-12-02 12:01:29 +01:00
bool isScriptable() const;
bool isScriptable(const Context &) const;
void setTouchBarText(const QString &text);
QString touchBarText() const;
void setTouchBarIcon(const QIcon &icon);
QIcon touchBarIcon() const;
QAction *touchBarAction() const;
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
2008-12-02 12:01:29 +01:00
signals:
void keySequenceChanged();
void activeStateChanged();
private:
friend class ActionManager;
friend class Internal::ActionManagerPrivate;
Command(Utils::Id id);
Internal::CommandPrivate *d;
2008-12-02 12:01:29 +01:00
};
} // namespace Core
Q_DECLARE_OPERATORS_FOR_FLAGS(Core::Command::CommandAttributes)