2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2009-12-11 16:43:39 +01:00
|
|
|
#include "command_p.h"
|
|
|
|
|
|
2015-06-19 13:09:26 +02:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2013-08-29 16:36:42 +02:00
|
|
|
#include <coreplugin/icontext.h>
|
|
|
|
|
#include <coreplugin/id.h>
|
2009-12-11 16:43:39 +01:00
|
|
|
|
2012-08-23 15:53:58 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2017-07-07 14:05:06 +03:00
|
|
|
#include <utils/stringutils.h>
|
2012-08-23 15:53:58 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QAction>
|
2017-03-09 23:02:32 +01:00
|
|
|
#include <QRegExp>
|
2014-10-01 17:52:57 +02:00
|
|
|
#include <QToolButton>
|
|
|
|
|
#include <QTextStream>
|
|
|
|
|
|
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
|
|
|
|
|
|
2013-09-06 16:38:53 +02:00
|
|
|
\brief The Command class represents an action, such as a menu item, tool button, or shortcut.
|
|
|
|
|
You do not create Command objects directly, but use \l{ActionManager::registerAction()}
|
2009-05-05 18:37:18 +02:00
|
|
|
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
|
|
|
|
2013-09-06 16:38:53 +02:00
|
|
|
A Command has two basic properties: a default shortcut and a default text. The default
|
2009-05-05 18:37:18 +02:00
|
|
|
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
|
2013-09-06 16:38:53 +02:00
|
|
|
This enum defines how the user visible action is updated when the active action changes.
|
2009-05-06 18:29:37 +02:00
|
|
|
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)
|
2013-09-06 16:38:53 +02:00
|
|
|
Sets the default keyboard shortcut that can be used to activate this command to \a key.
|
2009-05-06 18:29:37 +02:00
|
|
|
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)
|
2013-09-06 16:38:53 +02:00
|
|
|
Sets the \a text that is used to represent the Command in the
|
|
|
|
|
keyboard shortcut settings dialog. If you do not set this,
|
2009-05-06 18:29:37 +02:00
|
|
|
the current text from the user visible action is taken (which
|
2013-09-06 16:38:53 +02:00
|
|
|
is fine in many cases).
|
2009-05-06 18:29:37 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
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 void Command::setAttribute(CommandAttribute attribute)
|
2013-09-06 16:38:53 +02:00
|
|
|
Adds \a attribute to the attributes of this Command.
|
2009-05-06 18:29:37 +02:00
|
|
|
\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)
|
2013-09-06 16:38:53 +02:00
|
|
|
Removes \a attribute from the attributes of this Command.
|
2009-05-06 18:29:37 +02:00
|
|
|
\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
|
2013-09-06 16:38:53 +02:00
|
|
|
Returns whether the Command has the \a attribute set.
|
2009-05-06 18:29:37 +02:00
|
|
|
\sa CommandAttribute
|
|
|
|
|
\sa removeAttribute()
|
|
|
|
|
\sa setAttribute()
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn bool Command::isActive() const
|
2013-09-06 16:38:53 +02:00
|
|
|
Returns whether the Command has an active action or shortcut for the current
|
2009-05-06 18:29:37 +02:00
|
|
|
context.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-12-20 10:35:30 +01:00
|
|
|
/*!
|
|
|
|
|
\fn bool Command::isScriptable() const
|
2013-09-06 16:38:53 +02:00
|
|
|
Returns whether the Command is scriptable. A scriptable command can be called
|
2010-12-20 10:35:30 +01:00
|
|
|
from a script without the need for the user to interact with it.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn bool Command::isScriptable(const Context &) const
|
2013-09-06 16:38:53 +02:00
|
|
|
Returns whether the Command is scriptable for the given context.
|
2010-12-20 10:35:30 +01:00
|
|
|
A scriptable command can be called from a script without the need for the user to
|
|
|
|
|
interact with it.
|
|
|
|
|
*/
|
|
|
|
|
|
2014-11-16 10:52:41 +02:00
|
|
|
namespace Core {
|
|
|
|
|
namespace Internal {
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
/*!
|
2014-02-28 17:33:48 +01:00
|
|
|
\class Action
|
|
|
|
|
\internal
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
2014-02-28 17:33:48 +01:00
|
|
|
Action::Action(Id id)
|
|
|
|
|
: m_attributes(0),
|
|
|
|
|
m_id(id),
|
|
|
|
|
m_isKeyInitialized(false),
|
|
|
|
|
m_action(new Utils::ProxyAction(this)),
|
|
|
|
|
m_active(false),
|
|
|
|
|
m_contextInitialized(false)
|
|
|
|
|
{
|
|
|
|
|
m_action->setShortcutVisibleInToolTip(true);
|
2016-02-02 09:10:54 +02:00
|
|
|
connect(m_action, &QAction::changed, this, &Action::updateActiveState);
|
2014-02-28 17:33:48 +01:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-02-28 17:33:48 +01:00
|
|
|
Id Action::id() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-02-28 17:33:48 +01:00
|
|
|
return m_id;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-02-28 17:33:48 +01:00
|
|
|
void Action::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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 17:33:48 +01:00
|
|
|
QKeySequence Action::defaultKeySequence() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return m_defaultKey;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 17:33:48 +01:00
|
|
|
QAction *Action::action() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-02-28 17:33:48 +01:00
|
|
|
return m_action;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-02-28 17:33:48 +01:00
|
|
|
QString Action::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
|
|
|
}
|
|
|
|
|
|
2014-02-28 17:33:48 +01:00
|
|
|
Context Action::context() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return m_context;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 17:33:48 +01:00
|
|
|
void Action::setKeySequence(const QKeySequence &key)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-02-28 17:33:48 +01:00
|
|
|
m_isKeyInitialized = true;
|
|
|
|
|
m_action->setShortcut(key);
|
2008-12-02 12:01:29 +01:00
|
|
|
emit keySequenceChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 17:33:48 +01:00
|
|
|
QKeySequence Action::keySequence() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-02-28 17:33:48 +01:00
|
|
|
return m_action->shortcut();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-02-28 17:33:48 +01:00
|
|
|
void Action::setDescription(const QString &text)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-02-28 17:33:48 +01:00
|
|
|
m_defaultText = text;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-02-28 17:33:48 +01:00
|
|
|
QString Action::description() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-02-28 17:33:48 +01:00
|
|
|
if (!m_defaultText.isEmpty())
|
|
|
|
|
return m_defaultText;
|
2017-07-07 14:05:06 +03:00
|
|
|
if (QAction *act = action()) {
|
|
|
|
|
const QString text = Utils::stripAccelerator(act->text());
|
2014-02-28 17:33:48 +01:00
|
|
|
if (!text.isEmpty())
|
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
return id().toString();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-11-16 10:52:41 +02:00
|
|
|
void Action::setCurrentContext(const 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
|
|
|
}
|
|
|
|
|
|
2013-01-11 13:34:31 +01:00
|
|
|
static QString msgActionWarning(QAction *newAction, Id id, 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();
|
2015-06-24 10:28:32 +02:00
|
|
|
str << " is already registered for context " << id.toString() << '.';
|
2009-12-11 16:43:39 +01:00
|
|
|
return msg;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-16 10:52:41 +02:00
|
|
|
void Action::addOverrideAction(QAction *action, const Context &context, bool scriptable)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-11-07 11:41:07 +01:00
|
|
|
// disallow TextHeuristic menu role, because it doesn't work with translations,
|
|
|
|
|
// e.g. QTCREATORBUG-13101
|
|
|
|
|
if (action->menuRole() == QAction::TextHeuristicRole)
|
|
|
|
|
action->setMenuRole(QAction::NoRole);
|
2011-01-12 09:45:19 +01:00
|
|
|
if (isEmpty())
|
|
|
|
|
m_action->initialize(action);
|
2010-06-25 18:05:09 +02:00
|
|
|
if (context.isEmpty()) {
|
2015-06-19 13:09:26 +02:00
|
|
|
m_contextActionMap.insert(Constants::C_GLOBAL, action);
|
2008-12-02 12:01:29 +01:00
|
|
|
} else {
|
2010-06-25 17:37:59 +02:00
|
|
|
for (int i = 0; i < context.size(); ++i) {
|
2013-01-11 13:34:31 +01:00
|
|
|
Id id = context.at(i);
|
|
|
|
|
if (m_contextActionMap.contains(id))
|
|
|
|
|
qWarning("%s", qPrintable(msgActionWarning(action, id, m_contextActionMap.value(id, 0))));
|
|
|
|
|
m_contextActionMap.insert(id, action);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
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)
|
|
|
|
|
{
|
2013-01-11 13:34:31 +01:00
|
|
|
QMutableMapIterator<Id, QPointer<QAction> > it(m_contextActionMap);
|
2010-12-06 17:21:03 +01:00
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (it.value() == 0)
|
2010-12-06 17:21:03 +01:00
|
|
|
it.remove();
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (it.value() == action)
|
2010-12-06 17:21:03 +01:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-16 10:52:41 +02:00
|
|
|
bool Action::isScriptable(const Context &context) const
|
2010-12-20 10:35:30 +01:00
|
|
|
{
|
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)
|
|
|
|
|
{
|
2014-02-28 17:33:48 +01:00
|
|
|
m_attributes |= attr;
|
2011-01-12 09:45:19 +01:00
|
|
|
switch (attr) {
|
2014-11-16 10:52:41 +02:00
|
|
|
case Command::CA_Hide:
|
2011-01-12 09:45:19 +01:00
|
|
|
m_action->setAttribute(Utils::ProxyAction::Hide);
|
|
|
|
|
break;
|
2014-11-16 10:52:41 +02:00
|
|
|
case Command::CA_UpdateText:
|
2011-01-12 09:45:19 +01:00
|
|
|
m_action->setAttribute(Utils::ProxyAction::UpdateText);
|
|
|
|
|
break;
|
2014-11-16 10:52:41 +02:00
|
|
|
case Command::CA_UpdateIcon:
|
2011-01-12 09:45:19 +01:00
|
|
|
m_action->setAttribute(Utils::ProxyAction::UpdateIcon);
|
|
|
|
|
break;
|
2014-11-16 10:52:41 +02:00
|
|
|
case Command::CA_NonConfigurable:
|
2011-01-12 09:45:19 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Action::removeAttribute(CommandAttribute attr)
|
|
|
|
|
{
|
2014-02-28 17:33:48 +01:00
|
|
|
m_attributes &= ~attr;
|
2011-01-12 09:45:19 +01:00
|
|
|
switch (attr) {
|
2014-11-16 10:52:41 +02:00
|
|
|
case Command::CA_Hide:
|
2011-01-12 09:45:19 +01:00
|
|
|
m_action->removeAttribute(Utils::ProxyAction::Hide);
|
|
|
|
|
break;
|
2014-11-16 10:52:41 +02:00
|
|
|
case Command::CA_UpdateText:
|
2011-01-12 09:45:19 +01:00
|
|
|
m_action->removeAttribute(Utils::ProxyAction::UpdateText);
|
|
|
|
|
break;
|
2014-11-16 10:52:41 +02:00
|
|
|
case Command::CA_UpdateIcon:
|
2011-01-12 09:45:19 +01:00
|
|
|
m_action->removeAttribute(Utils::ProxyAction::UpdateIcon);
|
|
|
|
|
break;
|
2014-11-16 10:52:41 +02:00
|
|
|
case Command::CA_NonConfigurable:
|
2011-01-12 09:45:19 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-28 17:33:48 +01:00
|
|
|
|
|
|
|
|
bool Action::hasAttribute(Command::CommandAttribute attr) const
|
|
|
|
|
{
|
|
|
|
|
return (m_attributes & attr);
|
|
|
|
|
}
|
2014-10-01 17:52:57 +02:00
|
|
|
|
2014-11-16 10:52:41 +02:00
|
|
|
} // namespace Internal
|
2014-10-01 17:52:57 +02:00
|
|
|
|
2014-11-04 14:58:48 +01:00
|
|
|
void Command::augmentActionWithShortcutToolTip(QAction *a) const
|
|
|
|
|
{
|
|
|
|
|
a->setToolTip(stringWithAppendedShortcut(a->text()));
|
2014-11-16 10:52:41 +02:00
|
|
|
QObject::connect(this, &Command::keySequenceChanged, a, [this, a]() {
|
2014-11-04 14:58:48 +01:00
|
|
|
a->setToolTip(stringWithAppendedShortcut(a->text()));
|
|
|
|
|
});
|
|
|
|
|
QObject::connect(a, &QAction::changed, this, [this, a]() {
|
|
|
|
|
a->setToolTip(stringWithAppendedShortcut(a->text()));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-01 17:52:57 +02:00
|
|
|
QToolButton *Command::toolButtonWithAppendedShortcut(QAction *action, Command *cmd)
|
|
|
|
|
{
|
|
|
|
|
QToolButton *button = new QToolButton;
|
|
|
|
|
button->setDefaultAction(action);
|
2014-11-04 14:58:48 +01:00
|
|
|
if (cmd)
|
|
|
|
|
cmd->augmentActionWithShortcutToolTip(action);
|
2014-10-01 17:52:57 +02:00
|
|
|
return button;
|
|
|
|
|
}
|
2014-11-16 10:52:41 +02:00
|
|
|
|
|
|
|
|
} // namespace Core
|