2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2009-12-11 16:43:39 +01:00
|
|
|
#include "command_p.h"
|
|
|
|
|
|
|
|
|
|
#include "icore.h"
|
2010-06-25 12:56:16 +02:00
|
|
|
#include "icontext.h"
|
2011-09-05 16:10:37 +02:00
|
|
|
#include "id.h"
|
2009-12-11 16:43:39 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtCore/QDebug>
|
2009-12-11 16:43:39 +01:00
|
|
|
#include <QtCore/QTextStream>
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtGui/QAction>
|
|
|
|
|
#include <QtGui/QShortcut>
|
2009-12-14 14:24:47 +01:00
|
|
|
#include <QtGui/QMainWindow>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
/*!
|
2009-01-14 13:17:53 +01:00
|
|
|
\class Core::Command
|
2008-12-02 12:01:29 +01:00
|
|
|
\mainclass
|
|
|
|
|
|
2009-05-04 15:09:31 +02:00
|
|
|
\brief The class Command represents an action like a menu item, tool button, or shortcut.
|
2009-05-05 18:37:18 +02:00
|
|
|
You don't create Command objects directly, instead use \l{ActionManager::registerAction()}
|
|
|
|
|
to register an action and retrieve a Command. The Command object represents the user visible
|
|
|
|
|
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.
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-05-05 18:37:18 +02:00
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
You can tell a Command to also update the actions icon and text by setting the
|
|
|
|
|
corresponding \l{Command::CommandAttribute}{attribute}.
|
|
|
|
|
|
|
|
|
|
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}.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-01-14 13:17:53 +01:00
|
|
|
\enum Command::CommandAttribute
|
2009-05-06 18:29:37 +02:00
|
|
|
Defines how the user visible action is updated when the active action changes.
|
|
|
|
|
The default is to update the enabled and visible state, and to disable the
|
|
|
|
|
user visible action when there is no active action.
|
|
|
|
|
\omitvalue CA_Mask
|
|
|
|
|
\value CA_UpdateText
|
|
|
|
|
Also update the actions text.
|
|
|
|
|
\value CA_UpdateIcon
|
|
|
|
|
Also update the actions icon.
|
|
|
|
|
\value CA_Hide
|
|
|
|
|
When there is no active action, hide the user "visible" action, instead of just
|
|
|
|
|
disabling it.
|
2011-02-09 15:23:48 +01:00
|
|
|
\value CA_NonConfigurable
|
2009-05-06 18:29:37 +02:00
|
|
|
Flag to indicate that the keyboard shortcut of this Command should not be
|
|
|
|
|
configurable by the user.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-05-06 18:29:37 +02:00
|
|
|
\fn void Command::setDefaultKeySequence(const QKeySequence &key)
|
|
|
|
|
Set 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.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-05-06 18:29:37 +02:00
|
|
|
\fn void Command::defaultKeySequence() const
|
|
|
|
|
Returns the default keyboard shortcut that can be used to activate this command.
|
|
|
|
|
\sa setDefaultKeySequence()
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-05-06 18:29:37 +02:00
|
|
|
\fn void 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.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-05-06 18:29:37 +02:00
|
|
|
\fn QKeySequence Command::keySequence() const
|
|
|
|
|
Returns the current keyboard shortcut assigned to this Command.
|
|
|
|
|
\sa defaultKeySequence()
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-05-06 18:29:37 +02:00
|
|
|
\fn void Command::setKeySequence(const QKeySequence &key)
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2012-01-13 09:36:30 +01:00
|
|
|
\fn void Command::setDescription(const QString &text)
|
2009-05-06 18:29:37 +02:00
|
|
|
Set the \a text that is used to represent the Command in the
|
|
|
|
|
keyboard shortcut settings dialog. If you don't set this,
|
|
|
|
|
the current text from the user visible action is taken (which
|
|
|
|
|
is ok in many cases).
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2012-01-13 09:36:30 +01:00
|
|
|
\fn QString Command::description() const
|
2009-05-06 18:29:37 +02:00
|
|
|
Returns the text that is used to present this Command to the user.
|
2012-01-13 09:36:30 +01:00
|
|
|
\sa setDescription()
|
2009-05-06 18:29:37 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn int Command::id() const
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn QString 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn QAction *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.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-05-06 18:29:37 +02:00
|
|
|
\fn QShortcut *Command::shortcut() const
|
|
|
|
|
Returns the shortcut for this Command.
|
|
|
|
|
If the Command represents an action, it returns null.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-05-06 18:29:37 +02:00
|
|
|
\fn void Command::setAttribute(CommandAttribute attribute)
|
|
|
|
|
Add the \a attribute to the attributes of this Command.
|
|
|
|
|
\sa CommandAttribute
|
|
|
|
|
\sa removeAttribute()
|
|
|
|
|
\sa hasAttribute()
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-05-06 18:29:37 +02:00
|
|
|
\fn void Command::removeAttribute(CommandAttribute attribute)
|
|
|
|
|
Remove the \a attribute from the attributes of this Command.
|
|
|
|
|
\sa CommandAttribute
|
|
|
|
|
\sa setAttribute()
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-05-06 18:29:37 +02:00
|
|
|
\fn bool Command::hasAttribute(CommandAttribute attribute) const
|
|
|
|
|
Returns if the Command has the \a attribute set.
|
|
|
|
|
\sa CommandAttribute
|
|
|
|
|
\sa removeAttribute()
|
|
|
|
|
\sa setAttribute()
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn bool Command::isActive() const
|
|
|
|
|
Returns if the Command has an active action/shortcut for the current
|
|
|
|
|
context.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-12-20 10:35:30 +01:00
|
|
|
/*!
|
|
|
|
|
\fn bool Command::isScriptable() const
|
|
|
|
|
Returns if the Command is scriptable. A scriptable command can be called
|
|
|
|
|
from a script without the need for the user to interact with it.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn bool Command::isScriptable(const Context &) const
|
|
|
|
|
Returns if the Command is scriptable for the given context.
|
|
|
|
|
A scriptable command can be called from a script without the need for the user to
|
|
|
|
|
interact with it.
|
|
|
|
|
*/
|
|
|
|
|
|
2009-05-06 18:29:37 +02:00
|
|
|
/*!
|
|
|
|
|
\fn Command::~Command()
|
|
|
|
|
\internal
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
2011-11-11 12:16:20 +01:00
|
|
|
using namespace Core;
|
2008-12-02 12:01:29 +01:00
|
|
|
using namespace Core::Internal;
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-01-14 12:58:06 +01:00
|
|
|
\class CommandPrivate
|
|
|
|
|
\internal
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
2011-11-11 12:16:20 +01:00
|
|
|
CommandPrivate::CommandPrivate(Id id)
|
2010-10-08 13:18:35 +02:00
|
|
|
: m_attributes(0), m_id(id), m_isKeyInitialized(false)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-14 12:58:06 +01:00
|
|
|
void CommandPrivate::setDefaultKeySequence(const QKeySequence &key)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-10-08 13:18:35 +02:00
|
|
|
if (!m_isKeyInitialized)
|
|
|
|
|
setKeySequence(key);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_defaultKey = key;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-14 12:58:06 +01:00
|
|
|
QKeySequence CommandPrivate::defaultKeySequence() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return m_defaultKey;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-08 13:18:35 +02:00
|
|
|
void CommandPrivate::setKeySequence(const QKeySequence &key)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(key)
|
|
|
|
|
m_isKeyInitialized = true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-06 17:13:18 +01:00
|
|
|
void CommandPrivate::setDescription(const QString &text)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
m_defaultText = text;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-06 17:13:18 +01:00
|
|
|
QString CommandPrivate::description() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2012-01-06 17:13:18 +01:00
|
|
|
if (!m_defaultText.isEmpty())
|
|
|
|
|
return m_defaultText;
|
|
|
|
|
if (action()) {
|
|
|
|
|
QString text = action()->text();
|
|
|
|
|
text.remove(QRegExp(QLatin1String("&(?!&)")));
|
|
|
|
|
if (!text.isEmpty())
|
|
|
|
|
return text;
|
|
|
|
|
} else if (shortcut()) {
|
|
|
|
|
if (!shortcut()->whatsThis().isEmpty())
|
|
|
|
|
return shortcut()->whatsThis();
|
|
|
|
|
}
|
|
|
|
|
return id().toString();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-11-11 12:16:20 +01:00
|
|
|
Id CommandPrivate::id() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return m_id;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-14 12:58:06 +01:00
|
|
|
QAction *CommandPrivate::action() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-14 12:58:06 +01:00
|
|
|
QShortcut *CommandPrivate::shortcut() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-25 12:56:16 +02:00
|
|
|
Core::Context CommandPrivate::context() const
|
2010-03-29 14:42:46 +02:00
|
|
|
{
|
|
|
|
|
return m_context;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-14 12:58:06 +01:00
|
|
|
void CommandPrivate::setAttribute(CommandAttribute attr)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-05-06 16:06:43 +02:00
|
|
|
m_attributes |= attr;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-01-14 12:58:06 +01:00
|
|
|
void CommandPrivate::removeAttribute(CommandAttribute attr)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-05-06 16:06:43 +02:00
|
|
|
m_attributes &= ~attr;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-01-14 12:58:06 +01:00
|
|
|
bool CommandPrivate::hasAttribute(CommandAttribute attr) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-05-06 16:06:43 +02:00
|
|
|
return (m_attributes & attr);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-01-14 12:58:06 +01:00
|
|
|
QString CommandPrivate::stringWithAppendedShortcut(const QString &str) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-01-12 09:45:19 +01:00
|
|
|
return Utils::ProxyAction::stringWithAppendedShortcut(str, keySequence());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---------- Shortcut ------------
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\class Shortcut
|
2009-05-06 18:29:37 +02:00
|
|
|
\internal
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
2011-11-11 12:16:20 +01:00
|
|
|
Shortcut::Shortcut(Id id)
|
2010-12-20 10:35:30 +01:00
|
|
|
: CommandPrivate(id), m_shortcut(0), m_scriptable(false)
|
2011-11-11 12:16:20 +01:00
|
|
|
{}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
void Shortcut::setShortcut(QShortcut *shortcut)
|
|
|
|
|
{
|
|
|
|
|
m_shortcut = shortcut;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QShortcut *Shortcut::shortcut() const
|
|
|
|
|
{
|
|
|
|
|
return m_shortcut;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-25 12:56:16 +02:00
|
|
|
void Shortcut::setContext(const Core::Context &context)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
m_context = context;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-25 12:56:16 +02:00
|
|
|
Core::Context Shortcut::context() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return m_context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Shortcut::setKeySequence(const QKeySequence &key)
|
|
|
|
|
{
|
2010-10-08 13:18:35 +02:00
|
|
|
CommandPrivate::setKeySequence(key);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_shortcut->setKey(key);
|
|
|
|
|
emit keySequenceChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QKeySequence Shortcut::keySequence() const
|
|
|
|
|
{
|
|
|
|
|
return m_shortcut->key();
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-12 09:45:19 +01:00
|
|
|
void Shortcut::setCurrentContext(const Core::Context &context)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-06-25 18:05:09 +02:00
|
|
|
foreach (int ctxt, m_context) {
|
|
|
|
|
if (context.contains(ctxt)) {
|
2010-04-22 17:36:09 +02:00
|
|
|
if (!m_shortcut->isEnabled()) {
|
|
|
|
|
m_shortcut->setEnabled(true);
|
|
|
|
|
emit activeStateChanged();
|
|
|
|
|
}
|
2011-01-12 09:45:19 +01:00
|
|
|
return;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
2010-04-22 17:36:09 +02:00
|
|
|
if (m_shortcut->isEnabled()) {
|
|
|
|
|
m_shortcut->setEnabled(false);
|
|
|
|
|
emit activeStateChanged();
|
|
|
|
|
}
|
2011-01-12 09:45:19 +01:00
|
|
|
return;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Shortcut::isActive() const
|
|
|
|
|
{
|
|
|
|
|
return m_shortcut->isEnabled();
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-20 10:35:30 +01:00
|
|
|
bool Shortcut::isScriptable() const
|
|
|
|
|
{
|
|
|
|
|
return m_scriptable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Shortcut::isScriptable(const Core::Context &) const
|
|
|
|
|
{
|
|
|
|
|
return m_scriptable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Shortcut::setScriptable(bool value)
|
|
|
|
|
{
|
|
|
|
|
m_scriptable = value;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// ---------- Action ------------
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-05-06 18:29:37 +02:00
|
|
|
\class Action
|
|
|
|
|
\internal
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
2011-11-11 12:16:20 +01:00
|
|
|
Action::Action(Id id)
|
2010-01-14 15:33:58 +01:00
|
|
|
: CommandPrivate(id),
|
2011-01-12 09:45:19 +01:00
|
|
|
m_action(new Utils::ProxyAction(this)),
|
2010-01-14 15:33:58 +01:00
|
|
|
m_active(false),
|
|
|
|
|
m_contextInitialized(false)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-01-12 09:45:19 +01:00
|
|
|
m_action->setShortcutVisibleInToolTip(true);
|
|
|
|
|
connect(m_action, SIGNAL(changed()), this, SLOT(updateActiveState()));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAction *Action::action() const
|
|
|
|
|
{
|
|
|
|
|
return m_action;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Action::setKeySequence(const QKeySequence &key)
|
|
|
|
|
{
|
2010-10-08 13:18:35 +02:00
|
|
|
CommandPrivate::setKeySequence(key);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_action->setShortcut(key);
|
|
|
|
|
emit keySequenceChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QKeySequence Action::keySequence() const
|
|
|
|
|
{
|
|
|
|
|
return m_action->shortcut();
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-12 09:45:19 +01:00
|
|
|
void Action::setCurrentContext(const Core::Context &context)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
m_context = context;
|
|
|
|
|
|
2011-01-12 09:45:19 +01:00
|
|
|
QAction *currentAction = 0;
|
2008-12-02 12:01:29 +01:00
|
|
|
for (int i = 0; i < m_context.size(); ++i) {
|
|
|
|
|
if (QAction *a = m_contextActionMap.value(m_context.at(i), 0)) {
|
2011-01-12 09:45:19 +01:00
|
|
|
currentAction = a;
|
2008-12-02 12:01:29 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-12 09:45:19 +01:00
|
|
|
m_action->setAction(currentAction);
|
|
|
|
|
updateActiveState();
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-01-12 09:45:19 +01:00
|
|
|
void Action::updateActiveState()
|
|
|
|
|
{
|
|
|
|
|
setActive(m_action->isEnabled() && m_action->isVisible() && !m_action->isSeparator());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-09-02 12:45:36 +02:00
|
|
|
static QString msgActionWarning(QAction *newAction, int k, QAction *oldAction)
|
2009-12-11 16:43:39 +01:00
|
|
|
{
|
|
|
|
|
QString msg;
|
|
|
|
|
QTextStream str(&msg);
|
|
|
|
|
str << "addOverrideAction " << newAction->objectName() << '/' << newAction->text()
|
|
|
|
|
<< ": Action ";
|
|
|
|
|
if (oldAction)
|
|
|
|
|
str << oldAction->objectName() << '/' << oldAction->text();
|
|
|
|
|
str << " is already registered for context " << k << ' '
|
2011-09-02 12:45:36 +02:00
|
|
|
<< Core::Id::fromUniqueIdentifier(k).toString()
|
2009-12-11 16:43:39 +01:00
|
|
|
<< '.';
|
|
|
|
|
return msg;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-20 10:35:30 +01:00
|
|
|
void Action::addOverrideAction(QAction *action, const Core::Context &context, bool scriptable)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2012-01-25 10:25:05 +01:00
|
|
|
#ifdef Q_OS_MAC
|
2011-01-12 09:45:19 +01:00
|
|
|
action->setIconVisibleInMenu(false);
|
|
|
|
|
#endif
|
|
|
|
|
if (isEmpty())
|
|
|
|
|
m_action->initialize(action);
|
2010-06-25 18:05:09 +02:00
|
|
|
if (context.isEmpty()) {
|
2008-12-02 12:01:29 +01:00
|
|
|
m_contextActionMap.insert(0, action);
|
|
|
|
|
} else {
|
2010-06-25 17:37:59 +02:00
|
|
|
for (int i = 0; i < context.size(); ++i) {
|
2008-12-02 12:01:29 +01:00
|
|
|
int k = context.at(i);
|
|
|
|
|
if (m_contextActionMap.contains(k))
|
2009-12-11 16:43:39 +01:00
|
|
|
qWarning("%s", qPrintable(msgActionWarning(action, k, m_contextActionMap.value(k, 0))));
|
2008-12-02 12:01:29 +01:00
|
|
|
m_contextActionMap.insert(k, action);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-12-20 10:35:30 +01:00
|
|
|
m_scriptableMap[action] = scriptable;
|
2011-01-18 17:03:14 +01:00
|
|
|
setCurrentContext(m_context);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-12-06 17:21:03 +01:00
|
|
|
void Action::removeOverrideAction(QAction *action)
|
|
|
|
|
{
|
|
|
|
|
QMutableMapIterator<int, QPointer<QAction> > it(m_contextActionMap);
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
|
|
|
|
if (it.value() == 0) {
|
|
|
|
|
it.remove();
|
|
|
|
|
} else if (it.value() == action) {
|
|
|
|
|
it.remove();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
setCurrentContext(m_context);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-14 15:33:58 +01:00
|
|
|
bool Action::isActive() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return m_active;
|
|
|
|
|
}
|
2010-04-22 17:36:09 +02:00
|
|
|
|
|
|
|
|
void Action::setActive(bool state)
|
|
|
|
|
{
|
|
|
|
|
if (state != m_active) {
|
|
|
|
|
m_active = state;
|
|
|
|
|
emit activeStateChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-10-08 13:18:35 +02:00
|
|
|
|
2010-12-06 17:21:03 +01:00
|
|
|
bool Action::isEmpty() const
|
|
|
|
|
{
|
|
|
|
|
return m_contextActionMap.isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-20 10:35:30 +01:00
|
|
|
bool Action::isScriptable() const
|
|
|
|
|
{
|
|
|
|
|
return m_scriptableMap.values().contains(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Action::isScriptable(const Core::Context &context) const
|
|
|
|
|
{
|
2011-01-12 09:45:19 +01:00
|
|
|
if (context == m_context && m_scriptableMap.contains(m_action->action()))
|
|
|
|
|
return m_scriptableMap.value(m_action->action());
|
2010-12-20 10:35:30 +01:00
|
|
|
|
|
|
|
|
for (int i = 0; i < context.size(); ++i) {
|
|
|
|
|
if (QAction *a = m_contextActionMap.value(context.at(i), 0)) {
|
|
|
|
|
if (m_scriptableMap.contains(a) && m_scriptableMap.value(a))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-01-12 09:45:19 +01:00
|
|
|
|
|
|
|
|
void Action::setAttribute(CommandAttribute attr)
|
|
|
|
|
{
|
|
|
|
|
CommandPrivate::setAttribute(attr);
|
|
|
|
|
switch (attr) {
|
|
|
|
|
case Core::Command::CA_Hide:
|
|
|
|
|
m_action->setAttribute(Utils::ProxyAction::Hide);
|
|
|
|
|
break;
|
|
|
|
|
case Core::Command::CA_UpdateText:
|
|
|
|
|
m_action->setAttribute(Utils::ProxyAction::UpdateText);
|
|
|
|
|
break;
|
|
|
|
|
case Core::Command::CA_UpdateIcon:
|
|
|
|
|
m_action->setAttribute(Utils::ProxyAction::UpdateIcon);
|
|
|
|
|
break;
|
2011-02-09 15:23:48 +01:00
|
|
|
case Core::Command::CA_NonConfigurable:
|
2011-01-12 09:45:19 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Action::removeAttribute(CommandAttribute attr)
|
|
|
|
|
{
|
|
|
|
|
CommandPrivate::removeAttribute(attr);
|
|
|
|
|
switch (attr) {
|
|
|
|
|
case Core::Command::CA_Hide:
|
|
|
|
|
m_action->removeAttribute(Utils::ProxyAction::Hide);
|
|
|
|
|
break;
|
|
|
|
|
case Core::Command::CA_UpdateText:
|
|
|
|
|
m_action->removeAttribute(Utils::ProxyAction::UpdateText);
|
|
|
|
|
break;
|
|
|
|
|
case Core::Command::CA_UpdateIcon:
|
|
|
|
|
m_action->removeAttribute(Utils::ProxyAction::UpdateIcon);
|
|
|
|
|
break;
|
2011-02-09 15:23:48 +01:00
|
|
|
case Core::Command::CA_NonConfigurable:
|
2011-01-12 09:45:19 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|