aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/coreplugin/actionmanager/command.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/coreplugin/actionmanager/command.cpp')
-rw-r--r--src/plugins/coreplugin/actionmanager/command.cpp126
1 files changed, 82 insertions, 44 deletions
diff --git a/src/plugins/coreplugin/actionmanager/command.cpp b/src/plugins/coreplugin/actionmanager/command.cpp
index cd801c1ec2..c7eab9442f 100644
--- a/src/plugins/coreplugin/actionmanager/command.cpp
+++ b/src/plugins/coreplugin/actionmanager/command.cpp
@@ -27,19 +27,17 @@
#include <coreplugin/coreconstants.h>
#include <coreplugin/icontext.h>
-#include <coreplugin/id.h>
#include <utils/hostosinfo.h>
#include <utils/stringutils.h>
#include <QAction>
-#include <QRegExp>
#include <QToolButton>
#include <QTextStream>
-
/*!
\class Core::Command
+ \inheaderfile coreplugin/actionmanager/command.h
\inmodule QtCreator
\ingroup mainclasses
@@ -50,11 +48,13 @@
action and its properties. If multiple actions are registered with the same ID (but
different contexts) the returned Command is the shared one between these actions.
- A Command has two basic properties: a default shortcut and a default text. The default
- shortcut is a key sequence that the user can use to trigger the active action that
- the Command represents. The default text is e.g. used for representing the Command
- in the keyboard shortcut preference pane. If the default text is empty, the text
- of the visible action is used.
+ A Command has two basic properties: a list of default shortcuts and a
+ default text. The default shortcuts are key sequence that the user can use
+ to trigger the active action that the Command represents. The first
+ shortcut in that list is the main shortcut that is for example also shown
+ in tool tips and menus. The default text is used for representing the
+ Command in the keyboard shortcut preference pane. If the default text is
+ empty, the text of the visible action is used.
The user visible action is updated to represent the state of the active action (if any).
For performance reasons only the enabled and visible state are considered by default though.
@@ -64,6 +64,12 @@
If there is no active action, the default behavior of the visible action is to be disabled.
You can change that behavior to make the visible action hide instead via the Command's
\l{Command::CommandAttribute}{attributes}.
+
+ See \l{The Action Manager and Commands} for an overview of how
+ Core::Command and Core::ActionManager interact.
+
+ \sa Core::ActionManager
+ \sa {The Action Manager and Commands}
*/
/*!
@@ -79,37 +85,56 @@
When there is no active action, hide the user-visible action, instead of just
disabling it.
\value CA_NonConfigurable
- Flag to indicate that the keyboard shortcut of this Command should not be
- configurable by the user.
+ Flag to indicate that the keyboard shortcuts of this Command should not
+ be configurable by the user.
*/
/*!
\fn void Core::Command::setDefaultKeySequence(const QKeySequence &key)
- Sets the default keyboard shortcut that can be used to activate this command to \a key.
- This is used if the user didn't customize the shortcut, or resets the shortcut
- to the default one.
+
+ Sets the default keyboard shortcut that can be used to activate this
+ command to \a key. This is used if the user didn't customize the shortcut,
+ or resets the shortcut to the default.
*/
/*!
- \fn void Core::Command::defaultKeySequence() const
- Returns the default keyboard shortcut that can be used to activate this command.
- \sa setDefaultKeySequence()
+ \fn void Core::Command::setDefaultKeySequences(const QList<QKeySequence> &keys)
+
+ Sets the default keyboard shortcuts that can be used to activate this
+ command to \a keys. This is used if the user didn't customize the
+ shortcuts, or resets the shortcuts to the default.
+*/
+
+/*!
+ \fn QList<QKeySequence> Core::Command::defaultKeySequences() const
+
+ Returns the default keyboard shortcuts that can be used to activate this
+ command.
+ \sa setDefaultKeySequences()
*/
/*!
\fn void Core::Command::keySequenceChanged()
- Sent when the keyboard shortcut assigned to this Command changes, e.g.
- when the user sets it in the keyboard shortcut settings dialog.
+ Sent when the keyboard shortcuts assigned to this Command change, e.g.
+ when the user sets them in the keyboard shortcut settings dialog.
+*/
+
+/*!
+ \fn QList<QKeySequence> Core::Command::keySequences() const
+
+ Returns the current keyboard shortcuts assigned to this Command.
+ \sa defaultKeySequences()
*/
/*!
\fn QKeySequence Core::Command::keySequence() const
- Returns the current keyboard shortcut assigned to this Command.
- \sa defaultKeySequence()
+
+ Returns the current main keyboard shortcut assigned to this Command.
+ \sa defaultKeySequences()
*/
/*!
- \fn void Core::Command::setKeySequence(const QKeySequence &key)
+ \fn void Core::Command::setKeySequences(const QList<QKeySequence> &keys)
\internal
*/
@@ -134,21 +159,20 @@
/*!
\fn QString Core::Command::stringWithAppendedShortcut(const QString &string) const
- Returns the \a string with an appended representation of the keyboard shortcut
- that is currently assigned to this Command.
+
+ Returns the \a string with an appended representation of the main keyboard
+ shortcut that is currently assigned to this Command.
*/
/*!
\fn QAction *Core::Command::action() const
- Returns the user visible action for this Command.
- If the Command represents a shortcut, it returns null.
- Use this action to put it on e.g. tool buttons. The action
- automatically forwards trigger and toggle signals to the
- action that is currently active for this Command.
- It also shows the current keyboard shortcut in its
- tool tip (in addition to the tool tip of the active action)
- and gets disabled/hidden when there is
- no active action for the current context.
+
+ Returns the user visible action for this Command. Use this action to put it
+ on e.g. tool buttons. The action automatically forwards \c triggered() and
+ \c toggled() signals to the action that is currently active for this
+ Command. It also shows the current main keyboard shortcut in its tool tip
+ (in addition to the tool tip of the active action) and gets disabled/hidden
+ when there is no active action for the current context.
*/
/*!
@@ -182,8 +206,8 @@
/*!
\fn bool Core::Command::isActive() const
- Returns whether the Command has an active action or shortcut for the current
- context.
+
+ Returns whether the Command has an active action for the current context.
*/
/*!
@@ -230,9 +254,11 @@
/*! \fn virtual QAction *Core::Command::touchBarAction() const
- Adds an action to the touch bar.
+ \internal
*/
+using namespace Utils;
+
namespace Core {
namespace Internal {
@@ -253,13 +279,20 @@ Id Action::id() const
void Action::setDefaultKeySequence(const QKeySequence &key)
{
if (!m_isKeyInitialized)
- setKeySequence(key);
- m_defaultKey = key;
+ setKeySequences({key});
+ m_defaultKeys = {key};
}
-QKeySequence Action::defaultKeySequence() const
+void Action::setDefaultKeySequences(const QList<QKeySequence> &keys)
{
- return m_defaultKey;
+ if (!m_isKeyInitialized)
+ setKeySequences(keys);
+ m_defaultKeys = keys;
+}
+
+QList<QKeySequence> Action::defaultKeySequences() const
+{
+ return m_defaultKeys;
}
QAction *Action::action() const
@@ -277,13 +310,18 @@ Context Action::context() const
return m_context;
}
-void Action::setKeySequence(const QKeySequence &key)
+void Action::setKeySequences(const QList<QKeySequence> &keys)
{
m_isKeyInitialized = true;
- m_action->setShortcut(key);
+ m_action->setShortcuts(keys);
emit keySequenceChanged();
}
+QList<QKeySequence> Action::keySequences() const
+{
+ return m_action->shortcuts();
+}
+
QKeySequence Action::keySequence() const
{
return m_action->shortcut();
@@ -491,8 +529,8 @@ QAction *Action::touchBarAction() const
} // namespace Internal
/*!
- Appends the keyboard shortcut that is currently assigned to the action \a a
- to its tool tip.
+ Appends the main keyboard shortcut that is currently assigned to the action
+ \a a to its tool tip.
*/
void Command::augmentActionWithShortcutToolTip(QAction *a) const
{
@@ -508,7 +546,7 @@ void Command::augmentActionWithShortcutToolTip(QAction *a) const
/*!
Returns a tool button for \a action.
- Appends the keyboard shortcut \a cmd to the tool tip of the action.
+ Appends the main keyboard shortcut \a cmd to the tool tip of the action.
*/
QToolButton *Command::toolButtonWithAppendedShortcut(QAction *action, Command *cmd)
{