Refactor the "proxy action" behavior of Command to Utils::ProxyAction

A generic action that acts as a proxy for another (changeable) action,
like it is used for mostly all of the visible actions in Qt Creator
through the action manager.
This commit is contained in:
con
2011-01-12 09:45:19 +01:00
parent 20f0088ec9
commit e7ad89ffd8
9 changed files with 369 additions and 166 deletions

View File

@@ -0,0 +1,176 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "proxyaction.h"
using namespace Utils;
ProxyAction::ProxyAction(QObject *parent) :
QAction(parent),
m_action(0),
m_attributes(0),
m_showShortcut(false)
{
connect(this, SIGNAL(changed()), this, SLOT(updateToolTipWithKeySequence()));
updateState();
}
void ProxyAction::setAction(QAction *action)
{
if (m_action == action)
return;
disconnectAction();
m_action = action;
connectAction();
updateState();
}
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) {
disconnect(m_action, SIGNAL(changed()), this, SLOT(actionChanged()));
disconnect(this, SIGNAL(triggered(bool)), m_action, SIGNAL(triggered(bool)));
disconnect(this, SIGNAL(toggled(bool)), m_action, SLOT(setChecked(bool)));
}
}
void ProxyAction::connectAction()
{
if (m_action) {
connect(m_action, SIGNAL(changed()), this, SLOT(actionChanged()));
connect(this, SIGNAL(triggered(bool)), m_action, SIGNAL(triggered(bool)));
connect(this, SIGNAL(toggled(bool)), m_action, SLOT(setChecked(bool)));
}
}
QAction *ProxyAction::action() const
{
return m_action;
}
void ProxyAction::setAttribute(ProxyAction::Attribute attribute)
{
m_attributes |= attribute;
}
void ProxyAction::removeAttribute(ProxyAction::Attribute attribute)
{
m_attributes &= ~attribute;
}
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;
disconnectAction();
disconnect(this, SIGNAL(changed()), this, SLOT(updateToolTipWithKeySequence()));
if (initialize)
setSeparator(action->isSeparator());
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());
setChecked(action->isChecked());
setEnabled(action->isEnabled());
setVisible(action->isVisible());
connectAction();
connect(this, SIGNAL(changed()), this, SLOT(updateToolTipWithKeySequence()));
}
bool ProxyAction::shortcutVisibleInToolTip() const
{
return m_showShortcut;
}
void ProxyAction::setShortcutVisibleInToolTip(bool visible)
{
m_showShortcut = visible;
updateToolTipWithKeySequence();
}
void ProxyAction::updateToolTipWithKeySequence()
{
static bool block = false;
if (block)
return;
block = true;
if (!m_showShortcut || shortcut().isEmpty())
setToolTip(m_toolTip);
else
setToolTip(stringWithAppendedShortcut(m_toolTip, shortcut()));
block = false;
}
QString ProxyAction::stringWithAppendedShortcut(const QString &str, const QKeySequence &shortcut)
{
return QString("%1 <span style=\"color: gray; font-size: small\">%2</span>").arg(str).arg(
shortcut.toString(QKeySequence::NativeText));
}

View File

@@ -0,0 +1,91 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#ifndef PROXYACTION_H
#define PROXYACTION_H
#include "utils_global.h"
#include <QtCore/QPointer>
#include <QtGui/QAction>
namespace Utils {
class QTCREATOR_UTILS_EXPORT ProxyAction : public QAction
{
Q_OBJECT
public:
enum Attribute {
Hide,
UpdateText,
UpdateIcon
};
Q_DECLARE_FLAGS(Attributes, Attribute)
explicit ProxyAction(QObject *parent = 0);
void initialize(QAction *action);
void setAction(QAction *action);
QAction *action() const;
bool shortcutVisibleInToolTip() const;
void setShortcutVisibleInToolTip(bool visible);
void setAttribute(Attribute attribute);
void removeAttribute(Attribute attribute);
bool hasAttribute(Attribute attribute);
static QString stringWithAppendedShortcut(const QString &str, const QKeySequence &shortcut);
private slots:
void actionChanged();
void updateState();
void updateToolTipWithKeySequence();
private:
void disconnectAction();
void connectAction();
void update(QAction *action, bool initialize);
QPointer<QAction> m_action;
Attributes m_attributes;
bool m_showShortcut;
QString m_toolTip;
};
} // namespace Utils
Q_DECLARE_OPERATORS_FOR_FLAGS(Utils::ProxyAction::Attributes)
#endif // PROXYACTION_H

View File

@@ -7,3 +7,9 @@ CONFIG += dll
include($$PWD/../../qtcreatorlibrary.pri) include($$PWD/../../qtcreatorlibrary.pri)
include(utils-lib.pri) include(utils-lib.pri)
HEADERS += \
proxyaction.h
SOURCES += \
proxyaction.cpp

View File

@@ -347,17 +347,16 @@ ActionContainer *ActionManagerPrivate::createMenuBar(const Id &id)
Command *ActionManagerPrivate::registerAction(QAction *action, const Id &id, const Context &context, bool scriptable) Command *ActionManagerPrivate::registerAction(QAction *action, const Id &id, const Context &context, bool scriptable)
{ {
Action *a = 0; Action *a = overridableAction(id);
Command *c = registerOverridableAction(action, id, false); if (a) {
a = static_cast<Action *>(c);
if (a)
a->addOverrideAction(action, context, scriptable); a->addOverrideAction(action, context, scriptable);
emit commandListChanged(); emit commandListChanged();
emit commandAdded(id); emit commandAdded(id);
}
return a; return a;
} }
Command *ActionManagerPrivate::registerOverridableAction(QAction *action, const Id &id, bool checkUnique) Action *ActionManagerPrivate::overridableAction(const Id &id)
{ {
Action *a = 0; Action *a = 0;
const int uid = UniqueIDManager::instance()->uniqueIdentifier(id); const int uid = UniqueIDManager::instance()->uniqueIdentifier(id);
@@ -365,38 +364,16 @@ Command *ActionManagerPrivate::registerOverridableAction(QAction *action, const
a = qobject_cast<Action *>(c); a = qobject_cast<Action *>(c);
if (!a) { if (!a) {
qWarning() << "registerAction: id" << id << "is registered with a different command type."; qWarning() << "registerAction: id" << id << "is registered with a different command type.";
return c; return 0;
} }
} else { } else {
a = new Action(uid); a = new Action(uid);
m_idCmdMap.insert(uid, a); m_idCmdMap.insert(uid, a);
m_mainWnd->addAction(a->action());
a->action()->setObjectName(id);
a->action()->setShortcutContext(Qt::ApplicationShortcut);
} }
if (!a->action()) {
QAction *baseAction = new QAction(m_mainWnd);
baseAction->setObjectName(id);
baseAction->setCheckable(action->isCheckable());
baseAction->setIcon(action->icon());
baseAction->setIconText(action->iconText());
baseAction->setText(action->text());
baseAction->setToolTip(action->toolTip());
baseAction->setStatusTip(action->statusTip());
baseAction->setWhatsThis(action->whatsThis());
baseAction->setChecked(action->isChecked());
baseAction->setSeparator(action->isSeparator());
baseAction->setShortcutContext(Qt::ApplicationShortcut);
baseAction->setEnabled(false);
baseAction->setParent(m_mainWnd);
#ifdef Q_WS_MAC
baseAction->setIconVisibleInMenu(false);
#else
baseAction->setIconVisibleInMenu(action->isIconVisibleInMenu());
#endif
a->setAction(baseAction);
m_mainWnd->addAction(baseAction);
} else if (checkUnique) {
qWarning() << "registerOverridableAction: id" << id << "is already registered.";
}
return a; return a;
} }

View File

@@ -35,6 +35,8 @@
#define ACTIONMANAGERPRIVATE_H #define ACTIONMANAGERPRIVATE_H
#include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/actionmanager/actionmanager.h>
#include "command_p.h"
#include <coreplugin/icontext.h> #include <coreplugin/icontext.h>
#include <QtCore/QMap> #include <QtCore/QMap>
@@ -45,12 +47,6 @@ QT_BEGIN_NAMESPACE
class QSettings; class QSettings;
QT_END_NAMESPACE QT_END_NAMESPACE
struct CommandLocation
{
int m_container;
int m_position;
};
namespace Core { namespace Core {
class UniqueIDManager; class UniqueIDManager;
@@ -99,8 +95,7 @@ public:
private: private:
bool hasContext(const Context &context) const; bool hasContext(const Context &context) const;
Command *registerOverridableAction(QAction *action, const Id &id, Action *overridableAction(const Id &id);
bool checkUnique);
static ActionManagerPrivate *m_instance; static ActionManagerPrivate *m_instance;
QList<int> m_defaultGroups; QList<int> m_defaultGroups;

View File

@@ -286,8 +286,7 @@ bool CommandPrivate::hasAttribute(CommandAttribute attr) const
QString CommandPrivate::stringWithAppendedShortcut(const QString &str) const QString CommandPrivate::stringWithAppendedShortcut(const QString &str) const
{ {
return QString("%1 <span style=\"color: gray; font-size: small\">%2</span>").arg(str).arg( return Utils::ProxyAction::stringWithAppendedShortcut(str, keySequence());
keySequence().toString(QKeySequence::NativeText));
} }
// ---------- Shortcut ------------ // ---------- Shortcut ------------
@@ -303,14 +302,6 @@ Shortcut::Shortcut(int id)
} }
QString Shortcut::name() const
{
if (!m_shortcut)
return QString();
return m_shortcut->whatsThis();
}
void Shortcut::setShortcut(QShortcut *shortcut) void Shortcut::setShortcut(QShortcut *shortcut)
{ {
m_shortcut = shortcut; m_shortcut = shortcut;
@@ -353,7 +344,7 @@ QString Shortcut::defaultText() const
return m_defaultText; return m_defaultText;
} }
bool Shortcut::setCurrentContext(const Core::Context &context) void Shortcut::setCurrentContext(const Core::Context &context)
{ {
foreach (int ctxt, m_context) { foreach (int ctxt, m_context) {
if (context.contains(ctxt)) { if (context.contains(ctxt)) {
@@ -361,14 +352,14 @@ bool Shortcut::setCurrentContext(const Core::Context &context)
m_shortcut->setEnabled(true); m_shortcut->setEnabled(true);
emit activeStateChanged(); emit activeStateChanged();
} }
return true; return;
} }
} }
if (m_shortcut->isEnabled()) { if (m_shortcut->isEnabled()) {
m_shortcut->setEnabled(false); m_shortcut->setEnabled(false);
emit activeStateChanged(); emit activeStateChanged();
} }
return false; return;
} }
bool Shortcut::isActive() const bool Shortcut::isActive() const
@@ -399,29 +390,12 @@ void Shortcut::setScriptable(bool value)
*/ */
Action::Action(int id) Action::Action(int id)
: CommandPrivate(id), : CommandPrivate(id),
m_action(0), m_action(new Utils::ProxyAction(this)),
m_currentAction(0),
m_active(false), m_active(false),
m_contextInitialized(false) m_contextInitialized(false)
{ {
m_action->setShortcutVisibleInToolTip(true);
} connect(m_action, SIGNAL(changed()), this, SLOT(updateActiveState()));
QString Action::name() const
{
if (!m_action)
return QString();
return m_action->text();
}
void Action::setAction(QAction *action)
{
m_action = action;
if (m_action) {
m_action->setParent(this);
m_toolTip = m_action->toolTip();
}
} }
QAction *Action::action() const QAction *Action::action() const
@@ -443,60 +417,33 @@ void Action::setKeySequence(const QKeySequence &key)
{ {
CommandPrivate::setKeySequence(key); CommandPrivate::setKeySequence(key);
m_action->setShortcut(key); m_action->setShortcut(key);
updateToolTipWithKeySequence();
emit keySequenceChanged(); emit keySequenceChanged();
} }
void Action::updateToolTipWithKeySequence()
{
if (m_action->shortcut().isEmpty())
m_action->setToolTip(m_toolTip);
else
m_action->setToolTip(stringWithAppendedShortcut(m_toolTip));
}
QKeySequence Action::keySequence() const QKeySequence Action::keySequence() const
{ {
return m_action->shortcut(); return m_action->shortcut();
} }
bool Action::setCurrentContext(const Core::Context &context) void Action::setCurrentContext(const Core::Context &context)
{ {
m_context = context; m_context = context;
QAction *oldAction = m_currentAction; QAction *currentAction = 0;
m_currentAction = 0;
for (int i = 0; i < m_context.size(); ++i) { for (int i = 0; i < m_context.size(); ++i) {
if (QAction *a = m_contextActionMap.value(m_context.at(i), 0)) { if (QAction *a = m_contextActionMap.value(m_context.at(i), 0)) {
m_currentAction = a; currentAction = a;
break; break;
} }
} }
if (m_currentAction == oldAction && m_contextInitialized) m_action->setAction(currentAction);
return true; updateActiveState();
m_contextInitialized = true; }
if (oldAction) { void Action::updateActiveState()
disconnect(oldAction, SIGNAL(changed()), this, SLOT(actionChanged())); {
disconnect(m_action, SIGNAL(triggered(bool)), oldAction, SIGNAL(triggered(bool))); setActive(m_action->isEnabled() && m_action->isVisible() && !m_action->isSeparator());
disconnect(m_action, SIGNAL(toggled(bool)), oldAction, SLOT(setChecked(bool)));
}
if (m_currentAction) {
connect(m_currentAction, SIGNAL(changed()), this, SLOT(actionChanged()));
// we want to avoid the toggling semantic on slot trigger(), so we just connect the signals
connect(m_action, SIGNAL(triggered(bool)), m_currentAction, SIGNAL(triggered(bool)));
// we need to update the checked state, so we connect to setChecked slot, which also fires a toggled signal
connect(m_action, SIGNAL(toggled(bool)), m_currentAction, SLOT(setChecked(bool)));
actionChanged();
return true;
}
// no active/delegate action, "visible" action is not enabled/visible
if (hasAttribute(CA_Hide))
m_action->setVisible(false);
m_action->setEnabled(false);
setActive(false);
return false;
} }
static inline QString msgActionWarning(QAction *newAction, int k, QAction *oldAction) static inline QString msgActionWarning(QAction *newAction, int k, QAction *oldAction)
@@ -515,6 +462,11 @@ static inline QString msgActionWarning(QAction *newAction, int k, QAction *oldAc
void Action::addOverrideAction(QAction *action, const Core::Context &context, bool scriptable) void Action::addOverrideAction(QAction *action, const Core::Context &context, bool scriptable)
{ {
#ifdef Q_WS_MAC
action->setIconVisibleInMenu(false);
#endif
if (isEmpty())
m_action->initialize(action);
if (context.isEmpty()) { if (context.isEmpty()) {
m_contextActionMap.insert(0, action); m_contextActionMap.insert(0, action);
} else { } else {
@@ -542,33 +494,6 @@ void Action::removeOverrideAction(QAction *action)
setCurrentContext(m_context); setCurrentContext(m_context);
} }
void Action::actionChanged()
{
if (hasAttribute(CA_UpdateIcon)) {
m_action->setIcon(m_currentAction->icon());
m_action->setIconText(m_currentAction->iconText());
#ifndef Q_WS_MAC
m_action->setIconVisibleInMenu(m_currentAction->isIconVisibleInMenu());
#endif
}
if (hasAttribute(CA_UpdateText)) {
m_action->setText(m_currentAction->text());
m_toolTip = m_currentAction->toolTip();
updateToolTipWithKeySequence();
m_action->setStatusTip(m_currentAction->statusTip());
m_action->setWhatsThis(m_currentAction->whatsThis());
}
m_action->setCheckable(m_currentAction->isCheckable());
bool block = m_action->blockSignals(true);
m_action->setChecked(m_currentAction->isChecked());
m_action->blockSignals(block);
m_action->setEnabled(m_currentAction->isEnabled());
m_action->setVisible(m_currentAction->isVisible());
setActive(m_action->isEnabled() && m_action->isVisible() && !m_action->isSeparator());
}
bool Action::isActive() const bool Action::isActive() const
{ {
return m_active; return m_active;
@@ -594,8 +519,8 @@ bool Action::isScriptable() const
bool Action::isScriptable(const Core::Context &context) const bool Action::isScriptable(const Core::Context &context) const
{ {
if (context == m_context && m_scriptableMap.contains(m_currentAction)) if (context == m_context && m_scriptableMap.contains(m_action->action()))
return m_scriptableMap.value(m_currentAction); return m_scriptableMap.value(m_action->action());
for (int i = 0; i < context.size(); ++i) { for (int i = 0; i < context.size(); ++i) {
if (QAction *a = m_contextActionMap.value(context.at(i), 0)) { if (QAction *a = m_contextActionMap.value(context.at(i), 0)) {
@@ -605,3 +530,39 @@ bool Action::isScriptable(const Core::Context &context) const
} }
return false; return false;
} }
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;
case Core::Command::CA_NonConfigureable:
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;
case Core::Command::CA_NonConfigureable:
break;
}
}

View File

@@ -54,12 +54,12 @@ class CORE_EXPORT Command : public QObject
Q_OBJECT Q_OBJECT
public: public:
enum CommandAttribute { enum CommandAttribute {
CA_Hide = 0x0100, CA_Hide,
CA_UpdateText = 0x0200, CA_UpdateText,
CA_UpdateIcon = 0x0400, CA_UpdateIcon,
CA_NonConfigureable = 0x8000, CA_NonConfigureable
CA_Mask = 0xFF00
}; };
Q_DECLARE_FLAGS(CommandAttributes, CommandAttribute)
virtual void setDefaultKeySequence(const QKeySequence &key) = 0; virtual void setDefaultKeySequence(const QKeySequence &key) = 0;
virtual QKeySequence defaultKeySequence() const = 0; virtual QKeySequence defaultKeySequence() const = 0;
@@ -95,4 +95,6 @@ signals:
} // namespace Core } // namespace Core
Q_DECLARE_OPERATORS_FOR_FLAGS(Core::Command::CommandAttributes)
#endif // COMMAND_H #endif // COMMAND_H

View File

@@ -35,7 +35,9 @@
#define COMMAND_P_H #define COMMAND_P_H
#include "command.h" #include "command.h"
#include "actionmanager_p.h"
#include <utils/proxyaction.h>
#include <coreplugin/icontext.h>
#include <QtCore/QList> #include <QtCore/QList>
#include <QtCore/QMultiMap> #include <QtCore/QMultiMap>
@@ -43,6 +45,12 @@
#include <QtCore/QMap> #include <QtCore/QMap>
#include <QtGui/QKeySequence> #include <QtGui/QKeySequence>
struct CommandLocation
{
int m_container;
int m_position;
};
namespace Core { namespace Core {
namespace Internal { namespace Internal {
@@ -53,8 +61,6 @@ public:
CommandPrivate(int id); CommandPrivate(int id);
virtual ~CommandPrivate() {} virtual ~CommandPrivate() {}
virtual QString name() const = 0;
void setDefaultKeySequence(const QKeySequence &key); void setDefaultKeySequence(const QKeySequence &key);
QKeySequence defaultKeySequence() const; QKeySequence defaultKeySequence() const;
@@ -74,14 +80,13 @@ public:
void removeAttribute(CommandAttribute attr); void removeAttribute(CommandAttribute attr);
bool hasAttribute(CommandAttribute attr) const; bool hasAttribute(CommandAttribute attr) const;
virtual bool setCurrentContext(const Context &context) = 0; virtual void setCurrentContext(const Context &context) = 0;
QString stringWithAppendedShortcut(const QString &str) const; QString stringWithAppendedShortcut(const QString &str) const;
protected: protected:
Context m_context; Context m_context;
QString m_category; CommandAttributes m_attributes;
int m_attributes;
int m_id; int m_id;
QKeySequence m_defaultKey; QKeySequence m_defaultKey;
QString m_defaultText; QString m_defaultText;
@@ -94,8 +99,6 @@ class Shortcut : public CommandPrivate
public: public:
Shortcut(int id); Shortcut(int id);
QString name() const;
void setKeySequence(const QKeySequence &key); void setKeySequence(const QKeySequence &key);
QKeySequence keySequence() const; QKeySequence keySequence() const;
@@ -107,7 +110,7 @@ public:
void setContext(const Context &context); void setContext(const Context &context);
Context context() const; Context context() const;
bool setCurrentContext(const Context &context); void setCurrentContext(const Context &context);
bool isActive() const; bool isActive() const;
@@ -127,18 +130,15 @@ class Action : public CommandPrivate
public: public:
Action(int id); Action(int id);
QString name() const;
void setKeySequence(const QKeySequence &key); void setKeySequence(const QKeySequence &key);
QKeySequence keySequence() const; QKeySequence keySequence() const;
virtual void setAction(QAction *action);
QAction *action() const; QAction *action() const;
void setLocations(const QList<CommandLocation> &locations); void setLocations(const QList<CommandLocation> &locations);
QList<CommandLocation> locations() const; QList<CommandLocation> locations() const;
bool setCurrentContext(const Context &context); void setCurrentContext(const Context &context);
bool isActive() const; bool isActive() const;
void addOverrideAction(QAction *action, const Context &context, bool scriptable); void addOverrideAction(QAction *action, const Context &context, bool scriptable);
void removeOverrideAction(QAction *action); void removeOverrideAction(QAction *action);
@@ -147,20 +147,19 @@ public:
bool isScriptable() const; bool isScriptable() const;
bool isScriptable(const Context &context) const; bool isScriptable(const Context &context) const;
protected: void setAttribute(CommandAttribute attr);
void updateToolTipWithKeySequence(); void removeAttribute(CommandAttribute attr);
private slots: private slots:
void actionChanged(); void updateActiveState();
private: private:
void setActive(bool state); void setActive(bool state);
QAction *m_action; Utils::ProxyAction *m_action;
QList<CommandLocation> m_locations; QList<CommandLocation> m_locations;
QString m_toolTip; QString m_toolTip;
QPointer<QAction> m_currentAction;
QMap<int, QPointer<QAction> > m_contextActionMap; QMap<int, QPointer<QAction> > m_contextActionMap;
QMap<QAction*, bool> m_scriptableMap; QMap<QAction*, bool> m_scriptableMap;
bool m_active; bool m_active;

View File

@@ -136,10 +136,6 @@ bool HelloWorldPlugin::initialize(const QStringList &arguments, QString *error_m
Core::IMode *helloMode = new HelloMode; Core::IMode *helloMode = new HelloMode;
addAutoReleasedObject(helloMode); addAutoReleasedObject(helloMode);
// Add the Hello World action command to the mode manager (with 0 priority)
Core::ModeManager *modeManager = core->modeManager();
modeManager->addAction(command, 0);
return true; return true;
} }