forked from qt-creator/qt-creator
ActionManager: Remove QShortcut registration API
Registering QShortcuts doesn't solve any problem that is not already solved by registering QActions, and shortcuts are in fact much more limited (not being able to register multiple shortcuts for different contexts). Change-Id: I9478e601b2cbc3c5e12fb5baee43cacc20d0fb9c Reviewed-by: Daniel Teske <daniel.teske@digia.com> Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
@@ -258,56 +258,6 @@ Command *ActionManager::registerAction(QAction *action, Id id, const Context &co
|
|||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
Makes a \a shortcut known to the system under the specified \a id.
|
|
||||||
|
|
||||||
Returns a command object that represents the shortcut in the application and is
|
|
||||||
owned by the ActionManager. You can registered several shortcuts with the
|
|
||||||
same \a id as long as the \a context is different. In this case
|
|
||||||
a trigger of the actual shortcut is forwarded to the registered QShortcut
|
|
||||||
for the currently active context.
|
|
||||||
A scriptable shortcut can be called from a script without the need for the user
|
|
||||||
to interact with it.
|
|
||||||
*/
|
|
||||||
Command *ActionManager::registerShortcut(QShortcut *shortcut, Id id, const Context &context, bool scriptable)
|
|
||||||
{
|
|
||||||
QTC_CHECK(!context.isEmpty());
|
|
||||||
Shortcut *sc = 0;
|
|
||||||
if (CommandPrivate *c = d->m_idCmdMap.value(id, 0)) {
|
|
||||||
sc = qobject_cast<Shortcut *>(c);
|
|
||||||
if (!sc) {
|
|
||||||
qWarning() << "registerShortcut: id" << id.name()
|
|
||||||
<< "is registered with a different command type.";
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sc = new Shortcut(id);
|
|
||||||
d->m_idCmdMap.insert(id, sc);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sc->shortcut()) {
|
|
||||||
qWarning() << "registerShortcut: action already registered, id" << id.name() << ".";
|
|
||||||
return sc;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!d->hasContext(context))
|
|
||||||
shortcut->setEnabled(false);
|
|
||||||
shortcut->setObjectName(id.toString());
|
|
||||||
shortcut->setParent(ICore::mainWindow());
|
|
||||||
shortcut->setContext(Qt::ApplicationShortcut);
|
|
||||||
sc->setShortcut(shortcut);
|
|
||||||
sc->setScriptable(scriptable);
|
|
||||||
sc->setContext(context);
|
|
||||||
d->readUserSettings(id, sc);
|
|
||||||
|
|
||||||
emit m_instance->commandListChanged();
|
|
||||||
emit m_instance->commandAdded(id.toString());
|
|
||||||
|
|
||||||
if (isPresentationModeEnabled())
|
|
||||||
connect(sc->shortcut(), SIGNAL(activated()), d, SLOT(shortcutTriggered()));
|
|
||||||
return sc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Returns the Command object that is known to the system
|
Returns the Command object that is known to the system
|
||||||
under the given \a id.
|
under the given \a id.
|
||||||
@@ -350,7 +300,7 @@ ActionContainer *ActionManager::actionContainer(Id id)
|
|||||||
*/
|
*/
|
||||||
QList<Command *> ActionManager::commands()
|
QList<Command *> ActionManager::commands()
|
||||||
{
|
{
|
||||||
// transform list of CommandPrivate into list of Command
|
// transform list of Action into list of Command
|
||||||
QList<Command *> result;
|
QList<Command *> result;
|
||||||
foreach (Command *cmd, d->m_idCmdMap)
|
foreach (Command *cmd, d->m_idCmdMap)
|
||||||
result << cmd;
|
result << cmd;
|
||||||
@@ -367,10 +317,7 @@ QList<Command *> ActionManager::commands()
|
|||||||
*/
|
*/
|
||||||
void ActionManager::unregisterAction(QAction *action, Id id)
|
void ActionManager::unregisterAction(QAction *action, Id id)
|
||||||
{
|
{
|
||||||
Action *a = 0;
|
Action *a = d->m_idCmdMap.value(id, 0);
|
||||||
CommandPrivate *c = d->m_idCmdMap.value(id, 0);
|
|
||||||
QTC_ASSERT(c, return);
|
|
||||||
a = qobject_cast<Action *>(c);
|
|
||||||
if (!a) {
|
if (!a) {
|
||||||
qWarning() << "unregisterAction: id" << id.name()
|
qWarning() << "unregisterAction: id" << id.name()
|
||||||
<< "is registered with a different command type.";
|
<< "is registered with a different command type.";
|
||||||
@@ -388,31 +335,6 @@ void ActionManager::unregisterAction(QAction *action, Id id)
|
|||||||
emit m_instance->commandListChanged();
|
emit m_instance->commandListChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
Removes the knowledge about a shortcut under the specified \a id.
|
|
||||||
|
|
||||||
Usually you do not need to unregister shortcuts. The only valid use case for unregistering
|
|
||||||
shortcuts, is for shortcuts that represent user definable actions. If the user removes such an action,
|
|
||||||
a corresponding shortcut also has to be unregistered from the action manager,
|
|
||||||
to make it disappear from shortcut settings etc.
|
|
||||||
*/
|
|
||||||
void ActionManager::unregisterShortcut(Id id)
|
|
||||||
{
|
|
||||||
Shortcut *sc = 0;
|
|
||||||
CommandPrivate *c = d->m_idCmdMap.value(id, 0);
|
|
||||||
QTC_ASSERT(c, return);
|
|
||||||
sc = qobject_cast<Shortcut *>(c);
|
|
||||||
if (!sc) {
|
|
||||||
qWarning() << "unregisterShortcut: id" << id.name()
|
|
||||||
<< "is registered with a different command type.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
delete sc->shortcut();
|
|
||||||
d->m_idCmdMap.remove(id);
|
|
||||||
delete sc;
|
|
||||||
emit m_instance->commandListChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Handles the display of the used shortcuts in the presentation mode. The presentation mode is
|
Handles the display of the used shortcuts in the presentation mode. The presentation mode is
|
||||||
enabled when starting \QC with the command line argument \c{-presentationMode}. In the
|
enabled when starting \QC with the command line argument \c{-presentationMode}. In the
|
||||||
@@ -431,12 +353,6 @@ void ActionManager::setPresentationModeEnabled(bool enabled)
|
|||||||
else
|
else
|
||||||
disconnect(c->action(), SIGNAL(triggered()), d, SLOT(actionTriggered()));
|
disconnect(c->action(), SIGNAL(triggered()), d, SLOT(actionTriggered()));
|
||||||
}
|
}
|
||||||
if (c->shortcut()) {
|
|
||||||
if (enabled)
|
|
||||||
connect(c->shortcut(), SIGNAL(activated()), d, SLOT(shortcutTriggered()));
|
|
||||||
else
|
|
||||||
disconnect(c->shortcut(), SIGNAL(activated()), d, SLOT(shortcutTriggered()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The label for the shortcuts:
|
// The label for the shortcuts:
|
||||||
@@ -538,13 +454,6 @@ void ActionManagerPrivate::actionTriggered()
|
|||||||
showShortcutPopup(action->shortcut().toString());
|
showShortcutPopup(action->shortcut().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionManagerPrivate::shortcutTriggered()
|
|
||||||
{
|
|
||||||
QShortcut *sc = qobject_cast<QShortcut *>(QObject::sender());
|
|
||||||
if (sc)
|
|
||||||
showShortcutPopup(sc->key().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
void ActionManagerPrivate::showShortcutPopup(const QString &shortcut)
|
void ActionManagerPrivate::showShortcutPopup(const QString &shortcut)
|
||||||
{
|
{
|
||||||
if (shortcut.isEmpty() || !ActionManager::isPresentationModeEnabled())
|
if (shortcut.isEmpty() || !ActionManager::isPresentationModeEnabled())
|
||||||
@@ -563,15 +472,8 @@ void ActionManagerPrivate::showShortcutPopup(const QString &shortcut)
|
|||||||
|
|
||||||
Action *ActionManagerPrivate::overridableAction(Id id)
|
Action *ActionManagerPrivate::overridableAction(Id id)
|
||||||
{
|
{
|
||||||
Action *a = 0;
|
Action *a = m_idCmdMap.value(id, 0);
|
||||||
if (CommandPrivate *c = m_idCmdMap.value(id, 0)) {
|
if (!a) {
|
||||||
a = qobject_cast<Action *>(c);
|
|
||||||
if (!a) {
|
|
||||||
qWarning() << "registerAction: id" << id.name()
|
|
||||||
<< "is registered with a different command type.";
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
a = new Action(id);
|
a = new Action(id);
|
||||||
m_idCmdMap.insert(id, a);
|
m_idCmdMap.insert(id, a);
|
||||||
readUserSettings(id, a);
|
readUserSettings(id, a);
|
||||||
@@ -587,7 +489,7 @@ Action *ActionManagerPrivate::overridableAction(Id id)
|
|||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionManagerPrivate::readUserSettings(Id id, CommandPrivate *cmd)
|
void ActionManagerPrivate::readUserSettings(Id id, Action *cmd)
|
||||||
{
|
{
|
||||||
QSettings *settings = Core::ICore::settings();
|
QSettings *settings = Core::ICore::settings();
|
||||||
settings->beginGroup(QLatin1String(kKeyboardSettingsKey));
|
settings->beginGroup(QLatin1String(kKeyboardSettingsKey));
|
||||||
@@ -635,7 +537,7 @@ void ActionManagerPrivate::saveSettings(QSettings *settings)
|
|||||||
const IdCmdMap::const_iterator cmdcend = m_idCmdMap.constEnd();
|
const IdCmdMap::const_iterator cmdcend = m_idCmdMap.constEnd();
|
||||||
for (IdCmdMap::const_iterator j = m_idCmdMap.constBegin(); j != cmdcend; ++j) {
|
for (IdCmdMap::const_iterator j = m_idCmdMap.constBegin(); j != cmdcend; ++j) {
|
||||||
const Id id = j.key();
|
const Id id = j.key();
|
||||||
CommandPrivate *cmd = j.value();
|
Action *cmd = j.value();
|
||||||
QKeySequence key = cmd->keySequence();
|
QKeySequence key = cmd->keySequence();
|
||||||
if (key != cmd->defaultKeySequence())
|
if (key != cmd->defaultKeySequence())
|
||||||
settings->setValue(id.toString(), key.toString());
|
settings->setValue(id.toString(), key.toString());
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ public:
|
|||||||
static ActionContainer *createMenuBar(Id id);
|
static ActionContainer *createMenuBar(Id id);
|
||||||
|
|
||||||
static Command *registerAction(QAction *action, Id id, const Context &context, bool scriptable = false);
|
static Command *registerAction(QAction *action, Id id, const Context &context, bool scriptable = false);
|
||||||
static Command *registerShortcut(QShortcut *shortcut, Id id, const Context &context, bool scriptable = false);
|
|
||||||
|
|
||||||
static Command *command(Id id);
|
static Command *command(Id id);
|
||||||
static ActionContainer *actionContainer(Id id);
|
static ActionContainer *actionContainer(Id id);
|
||||||
@@ -68,7 +67,6 @@ public:
|
|||||||
static QList<Command *> commands();
|
static QList<Command *> commands();
|
||||||
|
|
||||||
static void unregisterAction(QAction *action, Id id);
|
static void unregisterAction(QAction *action, Id id);
|
||||||
static void unregisterShortcut(Id id);
|
|
||||||
|
|
||||||
static void setPresentationModeEnabled(bool enabled);
|
static void setPresentationModeEnabled(bool enabled);
|
||||||
static bool isPresentationModeEnabled();
|
static bool isPresentationModeEnabled();
|
||||||
|
|||||||
@@ -48,16 +48,16 @@ namespace Core {
|
|||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
class Action;
|
||||||
class ActionContainerPrivate;
|
class ActionContainerPrivate;
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
class CommandPrivate;
|
|
||||||
|
|
||||||
class ActionManagerPrivate : public QObject
|
class ActionManagerPrivate : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef QHash<Core::Id, CommandPrivate *> IdCmdMap;
|
typedef QHash<Core::Id, Action *> IdCmdMap;
|
||||||
typedef QHash<Core::Id, ActionContainerPrivate *> IdContainerMap;
|
typedef QHash<Core::Id, ActionContainerPrivate *> IdContainerMap;
|
||||||
|
|
||||||
explicit ActionManagerPrivate();
|
explicit ActionManagerPrivate();
|
||||||
@@ -74,13 +74,12 @@ public:
|
|||||||
bool hasContext(const Context &context) const;
|
bool hasContext(const Context &context) const;
|
||||||
Action *overridableAction(Id id);
|
Action *overridableAction(Id id);
|
||||||
|
|
||||||
void readUserSettings(Id id, CommandPrivate *cmd);
|
void readUserSettings(Id id, Action *cmd);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void containerDestroyed();
|
void containerDestroyed();
|
||||||
|
|
||||||
void actionTriggered();
|
void actionTriggered();
|
||||||
void shortcutTriggered();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IdCmdMap m_idCmdMap;
|
IdCmdMap m_idCmdMap;
|
||||||
|
|||||||
@@ -204,39 +204,71 @@ using namespace Core;
|
|||||||
using namespace Core::Internal;
|
using namespace Core::Internal;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\class CommandPrivate
|
\class Action
|
||||||
\internal
|
\internal
|
||||||
*/
|
*/
|
||||||
|
Action::Action(Id id)
|
||||||
CommandPrivate::CommandPrivate(Id id)
|
: m_attributes(0),
|
||||||
: m_attributes(0), m_id(id), m_isKeyInitialized(false)
|
m_id(id),
|
||||||
|
m_isKeyInitialized(false),
|
||||||
|
m_action(new Utils::ProxyAction(this)),
|
||||||
|
m_active(false),
|
||||||
|
m_contextInitialized(false)
|
||||||
{
|
{
|
||||||
|
m_action->setShortcutVisibleInToolTip(true);
|
||||||
|
connect(m_action, SIGNAL(changed()), this, SLOT(updateActiveState()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandPrivate::setDefaultKeySequence(const QKeySequence &key)
|
Id Action::id() const
|
||||||
|
{
|
||||||
|
return m_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Action::setDefaultKeySequence(const QKeySequence &key)
|
||||||
{
|
{
|
||||||
if (!m_isKeyInitialized)
|
if (!m_isKeyInitialized)
|
||||||
setKeySequence(key);
|
setKeySequence(key);
|
||||||
m_defaultKey = key;
|
m_defaultKey = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
QKeySequence CommandPrivate::defaultKeySequence() const
|
QKeySequence Action::defaultKeySequence() const
|
||||||
{
|
{
|
||||||
return m_defaultKey;
|
return m_defaultKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandPrivate::setKeySequence(const QKeySequence &key)
|
QAction *Action::action() const
|
||||||
{
|
{
|
||||||
Q_UNUSED(key)
|
return m_action;
|
||||||
m_isKeyInitialized = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandPrivate::setDescription(const QString &text)
|
QString Action::stringWithAppendedShortcut(const QString &str) const
|
||||||
|
{
|
||||||
|
return Utils::ProxyAction::stringWithAppendedShortcut(str, keySequence());
|
||||||
|
}
|
||||||
|
|
||||||
|
Context Action::context() const
|
||||||
|
{
|
||||||
|
return m_context;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Action::setKeySequence(const QKeySequence &key)
|
||||||
|
{
|
||||||
|
m_isKeyInitialized = true;
|
||||||
|
m_action->setShortcut(key);
|
||||||
|
emit keySequenceChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
QKeySequence Action::keySequence() const
|
||||||
|
{
|
||||||
|
return m_action->shortcut();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Action::setDescription(const QString &text)
|
||||||
{
|
{
|
||||||
m_defaultText = text;
|
m_defaultText = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CommandPrivate::description() const
|
QString Action::description() const
|
||||||
{
|
{
|
||||||
if (!m_defaultText.isEmpty())
|
if (!m_defaultText.isEmpty())
|
||||||
return m_defaultText;
|
return m_defaultText;
|
||||||
@@ -245,157 +277,10 @@ QString CommandPrivate::description() const
|
|||||||
text.remove(QRegExp(QLatin1String("&(?!&)")));
|
text.remove(QRegExp(QLatin1String("&(?!&)")));
|
||||||
if (!text.isEmpty())
|
if (!text.isEmpty())
|
||||||
return text;
|
return text;
|
||||||
} else if (shortcut()) {
|
|
||||||
if (!shortcut()->whatsThis().isEmpty())
|
|
||||||
return shortcut()->whatsThis();
|
|
||||||
}
|
}
|
||||||
return id().toString();
|
return id().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
Id CommandPrivate::id() const
|
|
||||||
{
|
|
||||||
return m_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
Core::Context CommandPrivate::context() const
|
|
||||||
{
|
|
||||||
return m_context;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommandPrivate::setAttribute(CommandAttribute attr)
|
|
||||||
{
|
|
||||||
m_attributes |= attr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommandPrivate::removeAttribute(CommandAttribute attr)
|
|
||||||
{
|
|
||||||
m_attributes &= ~attr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CommandPrivate::hasAttribute(CommandAttribute attr) const
|
|
||||||
{
|
|
||||||
return (m_attributes & attr);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString CommandPrivate::stringWithAppendedShortcut(const QString &str) const
|
|
||||||
{
|
|
||||||
return Utils::ProxyAction::stringWithAppendedShortcut(str, keySequence());
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------- Shortcut ------------
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\class Shortcut
|
|
||||||
\internal
|
|
||||||
*/
|
|
||||||
|
|
||||||
Shortcut::Shortcut(Id id)
|
|
||||||
: CommandPrivate(id), m_shortcut(0), m_scriptable(false)
|
|
||||||
{}
|
|
||||||
|
|
||||||
void Shortcut::setShortcut(QShortcut *shortcut)
|
|
||||||
{
|
|
||||||
m_shortcut = shortcut;
|
|
||||||
}
|
|
||||||
|
|
||||||
QShortcut *Shortcut::shortcut() const
|
|
||||||
{
|
|
||||||
return m_shortcut;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Shortcut::setContext(const Core::Context &context)
|
|
||||||
{
|
|
||||||
m_context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
Core::Context Shortcut::context() const
|
|
||||||
{
|
|
||||||
return m_context;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Shortcut::setKeySequence(const QKeySequence &key)
|
|
||||||
{
|
|
||||||
CommandPrivate::setKeySequence(key);
|
|
||||||
m_shortcut->setKey(key);
|
|
||||||
emit keySequenceChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
QKeySequence Shortcut::keySequence() const
|
|
||||||
{
|
|
||||||
return m_shortcut->key();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Shortcut::setCurrentContext(const Core::Context &context)
|
|
||||||
{
|
|
||||||
foreach (Id id, m_context) {
|
|
||||||
if (context.contains(id)) {
|
|
||||||
if (!m_shortcut->isEnabled()) {
|
|
||||||
m_shortcut->setEnabled(true);
|
|
||||||
emit activeStateChanged();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (m_shortcut->isEnabled()) {
|
|
||||||
m_shortcut->setEnabled(false);
|
|
||||||
emit activeStateChanged();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Shortcut::isActive() const
|
|
||||||
{
|
|
||||||
return m_shortcut->isEnabled();
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------- Action ------------
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\class Action
|
|
||||||
\internal
|
|
||||||
*/
|
|
||||||
Action::Action(Id id)
|
|
||||||
: CommandPrivate(id),
|
|
||||||
m_action(new Utils::ProxyAction(this)),
|
|
||||||
m_active(false),
|
|
||||||
m_contextInitialized(false)
|
|
||||||
{
|
|
||||||
m_action->setShortcutVisibleInToolTip(true);
|
|
||||||
connect(m_action, SIGNAL(changed()), this, SLOT(updateActiveState()));
|
|
||||||
}
|
|
||||||
|
|
||||||
QAction *Action::action() const
|
|
||||||
{
|
|
||||||
return m_action;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Action::setKeySequence(const QKeySequence &key)
|
|
||||||
{
|
|
||||||
CommandPrivate::setKeySequence(key);
|
|
||||||
m_action->setShortcut(key);
|
|
||||||
emit keySequenceChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
QKeySequence Action::keySequence() const
|
|
||||||
{
|
|
||||||
return m_action->shortcut();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Action::setCurrentContext(const Core::Context &context)
|
void Action::setCurrentContext(const Core::Context &context)
|
||||||
{
|
{
|
||||||
m_context = context;
|
m_context = context;
|
||||||
@@ -502,7 +387,7 @@ bool Action::isScriptable(const Core::Context &context) const
|
|||||||
|
|
||||||
void Action::setAttribute(CommandAttribute attr)
|
void Action::setAttribute(CommandAttribute attr)
|
||||||
{
|
{
|
||||||
CommandPrivate::setAttribute(attr);
|
m_attributes |= attr;
|
||||||
switch (attr) {
|
switch (attr) {
|
||||||
case Core::Command::CA_Hide:
|
case Core::Command::CA_Hide:
|
||||||
m_action->setAttribute(Utils::ProxyAction::Hide);
|
m_action->setAttribute(Utils::ProxyAction::Hide);
|
||||||
@@ -520,7 +405,7 @@ void Action::setAttribute(CommandAttribute attr)
|
|||||||
|
|
||||||
void Action::removeAttribute(CommandAttribute attr)
|
void Action::removeAttribute(CommandAttribute attr)
|
||||||
{
|
{
|
||||||
CommandPrivate::removeAttribute(attr);
|
m_attributes &= ~attr;
|
||||||
switch (attr) {
|
switch (attr) {
|
||||||
case Core::Command::CA_Hide:
|
case Core::Command::CA_Hide:
|
||||||
m_action->removeAttribute(Utils::ProxyAction::Hide);
|
m_action->removeAttribute(Utils::ProxyAction::Hide);
|
||||||
@@ -535,3 +420,8 @@ void Action::removeAttribute(CommandAttribute attr)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Action::hasAttribute(Command::CommandAttribute attr) const
|
||||||
|
{
|
||||||
|
return (m_attributes & attr);
|
||||||
|
}
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ public:
|
|||||||
virtual Id id() const = 0;
|
virtual Id id() const = 0;
|
||||||
|
|
||||||
virtual QAction *action() const = 0;
|
virtual QAction *action() const = 0;
|
||||||
virtual QShortcut *shortcut() const = 0;
|
|
||||||
virtual Context context() const = 0;
|
virtual Context context() const = 0;
|
||||||
|
|
||||||
virtual void setAttribute(CommandAttribute attr) = 0;
|
virtual void setAttribute(CommandAttribute attr) = 0;
|
||||||
|
|||||||
@@ -46,85 +46,30 @@
|
|||||||
namespace Core {
|
namespace Core {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class CommandPrivate : public Core::Command
|
class Action : public Core::Command
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
CommandPrivate(Id id);
|
|
||||||
virtual ~CommandPrivate() {}
|
|
||||||
|
|
||||||
void setDefaultKeySequence(const QKeySequence &key);
|
|
||||||
QKeySequence defaultKeySequence() const;
|
|
||||||
|
|
||||||
void setKeySequence(const QKeySequence &key);
|
|
||||||
|
|
||||||
void setDescription(const QString &text);
|
|
||||||
QString description() const;
|
|
||||||
|
|
||||||
Id id() const;
|
|
||||||
|
|
||||||
Context context() const;
|
|
||||||
|
|
||||||
|
|
||||||
void setAttribute(CommandAttribute attr);
|
|
||||||
void removeAttribute(CommandAttribute attr);
|
|
||||||
bool hasAttribute(CommandAttribute attr) const;
|
|
||||||
|
|
||||||
virtual void setCurrentContext(const Context &context) = 0;
|
|
||||||
|
|
||||||
QString stringWithAppendedShortcut(const QString &str) const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Context m_context;
|
|
||||||
CommandAttributes m_attributes;
|
|
||||||
Id m_id;
|
|
||||||
QKeySequence m_defaultKey;
|
|
||||||
QString m_defaultText;
|
|
||||||
bool m_isKeyInitialized;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Shortcut : public CommandPrivate
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
Shortcut(Id id);
|
|
||||||
|
|
||||||
void setKeySequence(const QKeySequence &key);
|
|
||||||
QKeySequence keySequence() const;
|
|
||||||
|
|
||||||
void setShortcut(QShortcut *shortcut);
|
|
||||||
QShortcut *shortcut() const;
|
|
||||||
|
|
||||||
QAction *action() const { return 0; }
|
|
||||||
|
|
||||||
void setContext(const Context &context);
|
|
||||||
Context context() const;
|
|
||||||
void setCurrentContext(const Context &context);
|
|
||||||
|
|
||||||
bool isActive() const;
|
|
||||||
|
|
||||||
bool isScriptable() const;
|
|
||||||
bool isScriptable(const Context &) const;
|
|
||||||
void setScriptable(bool value);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QShortcut *m_shortcut;
|
|
||||||
bool m_scriptable;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Action : public CommandPrivate
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Action(Id id);
|
Action(Id id);
|
||||||
|
|
||||||
|
Id id() const;
|
||||||
|
|
||||||
|
void setDefaultKeySequence(const QKeySequence &key);
|
||||||
|
QKeySequence defaultKeySequence() const;
|
||||||
|
|
||||||
void setKeySequence(const QKeySequence &key);
|
void setKeySequence(const QKeySequence &key);
|
||||||
QKeySequence keySequence() const;
|
QKeySequence keySequence() const;
|
||||||
|
|
||||||
QAction *action() const;
|
void setDescription(const QString &text);
|
||||||
QShortcut *shortcut() const { return 0; }
|
QString description() const;
|
||||||
|
|
||||||
|
QAction *action() const;
|
||||||
|
|
||||||
|
QString stringWithAppendedShortcut(const QString &str) const;
|
||||||
|
|
||||||
|
Context context() const;
|
||||||
void 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);
|
||||||
@@ -135,6 +80,7 @@ public:
|
|||||||
|
|
||||||
void setAttribute(CommandAttribute attr);
|
void setAttribute(CommandAttribute attr);
|
||||||
void removeAttribute(CommandAttribute attr);
|
void removeAttribute(CommandAttribute attr);
|
||||||
|
bool hasAttribute(CommandAttribute attr) const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateActiveState();
|
void updateActiveState();
|
||||||
@@ -142,6 +88,13 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
void setActive(bool state);
|
void setActive(bool state);
|
||||||
|
|
||||||
|
Context m_context;
|
||||||
|
CommandAttributes m_attributes;
|
||||||
|
Id m_id;
|
||||||
|
QKeySequence m_defaultKey;
|
||||||
|
QString m_defaultText;
|
||||||
|
bool m_isKeyInitialized;
|
||||||
|
|
||||||
Utils::ProxyAction *m_action;
|
Utils::ProxyAction *m_action;
|
||||||
QString m_toolTip;
|
QString m_toolTip;
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,6 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QShortcut>
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
@@ -307,11 +306,11 @@ EditorManager::EditorManager(QWidget *parent) :
|
|||||||
|
|
||||||
if (Utils::HostOsInfo::isWindowsHost()) {
|
if (Utils::HostOsInfo::isWindowsHost()) {
|
||||||
// workaround for QTCREATORBUG-72
|
// workaround for QTCREATORBUG-72
|
||||||
QShortcut *sc = new QShortcut(parent);
|
QAction *action = new QAction(tr("Alternative Close"), this);
|
||||||
cmd = ActionManager::registerShortcut(sc, Constants::CLOSE_ALTERNATIVE, editManagerContext);
|
cmd = ActionManager::registerAction(action, Constants::CLOSE_ALTERNATIVE, editManagerContext);
|
||||||
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+F4")));
|
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+F4")));
|
||||||
cmd->setDescription(EditorManager::tr("Close"));
|
cmd->setDescription(EditorManager::tr("Close"));
|
||||||
connect(sc, SIGNAL(activated()), this, SLOT(closeEditor()));
|
connect(action, SIGNAL(triggered()), this, SLOT(closeEditor()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close All Action
|
// Close All Action
|
||||||
|
|||||||
@@ -92,7 +92,6 @@
|
|||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QPrinter>
|
#include <QPrinter>
|
||||||
#include <QShortcut>
|
|
||||||
#include <QStatusBar>
|
#include <QStatusBar>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
@@ -537,10 +536,10 @@ void MainWindow::registerDefaultActions()
|
|||||||
|
|
||||||
// Return to editor shortcut: Note this requires Qt to fix up
|
// Return to editor shortcut: Note this requires Qt to fix up
|
||||||
// handling of shortcut overrides in menus, item views, combos....
|
// handling of shortcut overrides in menus, item views, combos....
|
||||||
m_focusToEditor = new QShortcut(this);
|
m_focusToEditor = new QAction(tr("Return to Editor"), this);
|
||||||
Command *cmd = ActionManager::registerShortcut(m_focusToEditor, Constants::S_RETURNTOEDITOR, globalContext);
|
Command *cmd = ActionManager::registerAction(m_focusToEditor, Constants::S_RETURNTOEDITOR, globalContext);
|
||||||
cmd->setDefaultKeySequence(QKeySequence(Qt::Key_Escape));
|
cmd->setDefaultKeySequence(QKeySequence(Qt::Key_Escape));
|
||||||
connect(m_focusToEditor, SIGNAL(activated()), this, SLOT(setFocusToEditor()));
|
connect(m_focusToEditor, SIGNAL(triggered()), this, SLOT(setFocusToEditor()));
|
||||||
|
|
||||||
// New File Action
|
// New File Action
|
||||||
QIcon icon = QIcon::fromTheme(QLatin1String("document-new"), QIcon(QLatin1String(Constants::ICON_NEWFILE)));
|
QIcon icon = QIcon::fromTheme(QLatin1String("document-new"), QIcon(QLatin1String(Constants::ICON_NEWFILE)));
|
||||||
|
|||||||
@@ -40,7 +40,6 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QSettings;
|
class QSettings;
|
||||||
class QShortcut;
|
|
||||||
class QPrinter;
|
class QPrinter;
|
||||||
class QToolButton;
|
class QToolButton;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
@@ -195,7 +194,7 @@ private:
|
|||||||
SystemEditor *m_systemEditor;
|
SystemEditor *m_systemEditor;
|
||||||
|
|
||||||
// actions
|
// actions
|
||||||
QShortcut *m_focusToEditor;
|
QAction *m_focusToEditor;
|
||||||
QAction *m_newAction;
|
QAction *m_newAction;
|
||||||
QAction *m_openAction;
|
QAction *m_openAction;
|
||||||
QAction *m_openWithAction;
|
QAction *m_openWithAction;
|
||||||
|
|||||||
@@ -47,7 +47,6 @@
|
|||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
#include <QSignalMapper>
|
#include <QSignalMapper>
|
||||||
#include <QShortcut>
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
@@ -68,7 +67,7 @@ struct ModeManagerPrivate
|
|||||||
Internal::FancyActionBar *m_actionBar;
|
Internal::FancyActionBar *m_actionBar;
|
||||||
QMap<QAction*, int> m_actions;
|
QMap<QAction*, int> m_actions;
|
||||||
QVector<IMode*> m_modes;
|
QVector<IMode*> m_modes;
|
||||||
QVector<Command*> m_modeShortcuts;
|
QVector<Command*> m_modeCommands;
|
||||||
QSignalMapper *m_signalMapper;
|
QSignalMapper *m_signalMapper;
|
||||||
Context m_addedContexts;
|
Context m_addedContexts;
|
||||||
int m_oldCurrent;
|
int m_oldCurrent;
|
||||||
@@ -182,15 +181,14 @@ void ModeManager::objectAdded(QObject *obj)
|
|||||||
d->m_modeStack->setTabEnabled(index, mode->isEnabled());
|
d->m_modeStack->setTabEnabled(index, mode->isEnabled());
|
||||||
|
|
||||||
// Register mode shortcut
|
// Register mode shortcut
|
||||||
const Id shortcutId = mode->id().withPrefix("QtCreator.Mode.");
|
const Id actionId = mode->id().withPrefix("QtCreator.Mode.");
|
||||||
QShortcut *shortcut = new QShortcut(d->m_mainWindow);
|
QAction *action = new QAction(tr("Switch to <b>%1</b> mode").arg(mode->displayName()), this);
|
||||||
shortcut->setWhatsThis(tr("Switch to <b>%1</b> mode").arg(mode->displayName()));
|
Command *cmd = ActionManager::registerAction(action, actionId, Context(Constants::C_GLOBAL));
|
||||||
Command *cmd = ActionManager::registerShortcut(shortcut, shortcutId, Context(Constants::C_GLOBAL));
|
|
||||||
|
|
||||||
d->m_modeShortcuts.insert(index, cmd);
|
d->m_modeCommands.insert(index, cmd);
|
||||||
connect(cmd, SIGNAL(keySequenceChanged()), m_instance, SLOT(updateModeToolTip()));
|
connect(cmd, SIGNAL(keySequenceChanged()), m_instance, SLOT(updateModeToolTip()));
|
||||||
for (int i = 0; i < d->m_modeShortcuts.size(); ++i) {
|
for (int i = 0; i < d->m_modeCommands.size(); ++i) {
|
||||||
Command *currentCmd = d->m_modeShortcuts.at(i);
|
Command *currentCmd = d->m_modeCommands.at(i);
|
||||||
// we need this hack with currentlyHasDefaultSequence
|
// we need this hack with currentlyHasDefaultSequence
|
||||||
// because we call setDefaultShortcut multiple times on the same cmd
|
// because we call setDefaultShortcut multiple times on the same cmd
|
||||||
// and still expect the current shortcut to change with it
|
// and still expect the current shortcut to change with it
|
||||||
@@ -202,8 +200,8 @@ void ModeManager::objectAdded(QObject *obj)
|
|||||||
currentCmd->setKeySequence(currentCmd->defaultKeySequence());
|
currentCmd->setKeySequence(currentCmd->defaultKeySequence());
|
||||||
}
|
}
|
||||||
|
|
||||||
d->m_signalMapper->setMapping(shortcut, mode->id().uniqueIdentifier());
|
d->m_signalMapper->setMapping(action, mode->id().uniqueIdentifier());
|
||||||
connect(shortcut, SIGNAL(activated()), d->m_signalMapper, SLOT(map()));
|
connect(action, SIGNAL(triggered()), d->m_signalMapper, SLOT(map()));
|
||||||
connect(mode, SIGNAL(enabledStateChanged(bool)),
|
connect(mode, SIGNAL(enabledStateChanged(bool)),
|
||||||
m_instance, SLOT(enabledStateChanged()));
|
m_instance, SLOT(enabledStateChanged()));
|
||||||
}
|
}
|
||||||
@@ -212,9 +210,9 @@ void ModeManager::updateModeToolTip()
|
|||||||
{
|
{
|
||||||
Command *cmd = qobject_cast<Command *>(sender());
|
Command *cmd = qobject_cast<Command *>(sender());
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
int index = d->m_modeShortcuts.indexOf(cmd);
|
int index = d->m_modeCommands.indexOf(cmd);
|
||||||
if (index != -1)
|
if (index != -1)
|
||||||
d->m_modeStack->setTabToolTip(index, cmd->stringWithAppendedShortcut(cmd->shortcut()->whatsThis()));
|
d->m_modeStack->setTabToolTip(index, cmd->action()->toolTip());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,7 +251,7 @@ void ModeManager::aboutToRemoveObject(QObject *obj)
|
|||||||
|
|
||||||
const int index = d->m_modes.indexOf(mode);
|
const int index = d->m_modes.indexOf(mode);
|
||||||
d->m_modes.remove(index);
|
d->m_modes.remove(index);
|
||||||
d->m_modeShortcuts.remove(index);
|
d->m_modeCommands.remove(index);
|
||||||
d->m_modeStack->removeTab(index);
|
d->m_modeStack->removeTab(index);
|
||||||
|
|
||||||
d->m_mainWindow->removeContextObject(mode);
|
d->m_mainWindow->removeContextObject(mode);
|
||||||
|
|||||||
@@ -44,7 +44,6 @@
|
|||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
#include <QShortcut>
|
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(Core::INavigationWidgetFactory *)
|
Q_DECLARE_METATYPE(Core::INavigationWidgetFactory *)
|
||||||
@@ -137,7 +136,7 @@ struct NavigationWidgetPrivate
|
|||||||
~NavigationWidgetPrivate() { delete m_factoryModel; }
|
~NavigationWidgetPrivate() { delete m_factoryModel; }
|
||||||
|
|
||||||
QList<Internal::NavigationSubWidget *> m_subWidgets;
|
QList<Internal::NavigationSubWidget *> m_subWidgets;
|
||||||
QHash<QShortcut *, Core::Id> m_shortcutMap;
|
QHash<QAction *, Core::Id> m_actionMap;
|
||||||
QHash<Core::Id, Core::Command *> m_commandMap;
|
QHash<Core::Id, Core::Command *> m_commandMap;
|
||||||
QStandardItemModel *m_factoryModel;
|
QStandardItemModel *m_factoryModel;
|
||||||
|
|
||||||
@@ -185,12 +184,11 @@ void NavigationWidget::setFactories(const QList<INavigationWidgetFactory *> &fac
|
|||||||
foreach (INavigationWidgetFactory *factory, factories) {
|
foreach (INavigationWidgetFactory *factory, factories) {
|
||||||
const Id id = factory->id();
|
const Id id = factory->id();
|
||||||
|
|
||||||
QShortcut *shortcut = new QShortcut(this);
|
QAction *action= new QAction(tr("Activate %1 Pane").arg(factory->displayName()), this);
|
||||||
shortcut->setWhatsThis(tr("Activate %1 Pane").arg(factory->displayName()));
|
connect(action, SIGNAL(triggered()), this, SLOT(activateSubWidget()));
|
||||||
connect(shortcut, SIGNAL(activated()), this, SLOT(activateSubWidget()));
|
d->m_actionMap.insert(action, id);
|
||||||
d->m_shortcutMap.insert(shortcut, id);
|
|
||||||
|
|
||||||
Command *cmd = ActionManager::registerShortcut(shortcut,
|
Command *cmd = ActionManager::registerAction(action,
|
||||||
id.withPrefix("QtCreator.Sidebar."), navicontext);
|
id.withPrefix("QtCreator.Sidebar."), navicontext);
|
||||||
cmd->setDefaultKeySequence(factory->activationSequence());
|
cmd->setDefaultKeySequence(factory->activationSequence());
|
||||||
d->m_commandMap.insert(id, cmd);
|
d->m_commandMap.insert(id, cmd);
|
||||||
@@ -257,8 +255,8 @@ Internal::NavigationSubWidget *NavigationWidget::insertSubItem(int position,int
|
|||||||
|
|
||||||
void NavigationWidget::activateSubWidget()
|
void NavigationWidget::activateSubWidget()
|
||||||
{
|
{
|
||||||
QShortcut *original = qobject_cast<QShortcut *>(sender());
|
QAction *original = qobject_cast<QAction *>(sender());
|
||||||
Id id = d->m_shortcutMap[original];
|
Id id = d->m_actionMap[original];
|
||||||
activateSubWidget(id);
|
activateSubWidget(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,6 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QSettings;
|
class QSettings;
|
||||||
class QShortcut;
|
|
||||||
class QAbstractItemModel;
|
class QAbstractItemModel;
|
||||||
class QStandardItemModel;
|
class QStandardItemModel;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|||||||
@@ -82,7 +82,6 @@
|
|||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QShortcut>
|
|
||||||
#include <QStackedLayout>
|
#include <QStackedLayout>
|
||||||
#include <QSplitter>
|
#include <QSplitter>
|
||||||
|
|
||||||
@@ -420,11 +419,10 @@ void HelpPlugin::setupUi()
|
|||||||
m_centralWidget, SLOT(showTopicChooser(QMap<QString,QUrl>,QString)));
|
m_centralWidget, SLOT(showTopicChooser(QMap<QString,QUrl>,QString)));
|
||||||
|
|
||||||
QMap<QString, Command*> shortcutMap;
|
QMap<QString, Command*> shortcutMap;
|
||||||
QShortcut *shortcut = new QShortcut(m_splitter);
|
QAction *action = new QAction(tr("Activate Index in Help mode"), m_splitter);
|
||||||
shortcut->setWhatsThis(tr("Activate Index in Help mode"));
|
Command *cmd = ActionManager::registerAction(action, "Help.IndexShortcut", modecontext);
|
||||||
Command *cmd = ActionManager::registerShortcut(shortcut, "Help.IndexShortcut", modecontext);
|
|
||||||
cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+I") : tr("Ctrl+Shift+I")));
|
cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+I") : tr("Ctrl+Shift+I")));
|
||||||
connect(shortcut, SIGNAL(activated()), this, SLOT(activateIndex()));
|
connect(action, SIGNAL(triggered()), this, SLOT(activateIndex()));
|
||||||
shortcutMap.insert(QLatin1String(SB_INDEX), cmd);
|
shortcutMap.insert(QLatin1String(SB_INDEX), cmd);
|
||||||
|
|
||||||
ContentWindow *contentWindow = new ContentWindow();
|
ContentWindow *contentWindow = new ContentWindow();
|
||||||
@@ -433,11 +431,10 @@ void HelpPlugin::setupUi()
|
|||||||
connect(contentWindow, SIGNAL(linkActivated(QUrl)), m_centralWidget,
|
connect(contentWindow, SIGNAL(linkActivated(QUrl)), m_centralWidget,
|
||||||
SLOT(setSource(QUrl)));
|
SLOT(setSource(QUrl)));
|
||||||
|
|
||||||
shortcut = new QShortcut(m_splitter);
|
action = new QAction(tr("Activate Contents in Help mode"), m_splitter);
|
||||||
shortcut->setWhatsThis(tr("Activate Contents in Help mode"));
|
cmd = ActionManager::registerAction(action, "Help.ContentsShortcut", modecontext);
|
||||||
cmd = ActionManager::registerShortcut(shortcut, "Help.ContentsShortcut", modecontext);
|
|
||||||
cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+Shift+C") : tr("Ctrl+Shift+C")));
|
cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+Shift+C") : tr("Ctrl+Shift+C")));
|
||||||
connect(shortcut, SIGNAL(activated()), this, SLOT(activateContents()));
|
connect(action, SIGNAL(triggered()), this, SLOT(activateContents()));
|
||||||
shortcutMap.insert(QLatin1String(SB_CONTENTS), cmd);
|
shortcutMap.insert(QLatin1String(SB_CONTENTS), cmd);
|
||||||
|
|
||||||
SearchWidget *searchWidget = new SearchWidget();
|
SearchWidget *searchWidget = new SearchWidget();
|
||||||
@@ -446,11 +443,10 @@ void HelpPlugin::setupUi()
|
|||||||
connect(searchWidget, SIGNAL(linkActivated(QUrl)), m_centralWidget,
|
connect(searchWidget, SIGNAL(linkActivated(QUrl)), m_centralWidget,
|
||||||
SLOT(setSourceFromSearch(QUrl)));
|
SLOT(setSourceFromSearch(QUrl)));
|
||||||
|
|
||||||
shortcut = new QShortcut(m_splitter);
|
action = new QAction(tr("Activate Search in Help mode"), m_splitter);
|
||||||
shortcut->setWhatsThis(tr("Activate Search in Help mode"));
|
cmd = ActionManager::registerAction(action, "Help.SearchShortcut", modecontext);
|
||||||
cmd = ActionManager::registerShortcut(shortcut, "Help.SearchShortcut", modecontext);
|
|
||||||
cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+/") : tr("Ctrl+Shift+/")));
|
cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+/") : tr("Ctrl+Shift+/")));
|
||||||
connect(shortcut, SIGNAL(activated()), this, SLOT(activateSearch()));
|
connect(action, SIGNAL(triggered()), this, SLOT(activateSearch()));
|
||||||
shortcutMap.insert(QLatin1String(SB_SEARCH), cmd);
|
shortcutMap.insert(QLatin1String(SB_SEARCH), cmd);
|
||||||
|
|
||||||
BookmarkManager *manager = &LocalHelpManager::bookmarkManager();
|
BookmarkManager *manager = &LocalHelpManager::bookmarkManager();
|
||||||
@@ -462,22 +458,20 @@ void HelpPlugin::setupUi()
|
|||||||
connect(bookmarkWidget, SIGNAL(createPage(QUrl,bool)), &OpenPagesManager::instance(),
|
connect(bookmarkWidget, SIGNAL(createPage(QUrl,bool)), &OpenPagesManager::instance(),
|
||||||
SLOT(createPage(QUrl,bool)));
|
SLOT(createPage(QUrl,bool)));
|
||||||
|
|
||||||
shortcut = new QShortcut(m_splitter);
|
action = new QAction(tr("Activate Bookmarks in Help mode"), m_splitter);
|
||||||
shortcut->setWhatsThis(tr("Activate Bookmarks in Help mode"));
|
cmd = ActionManager::registerAction(action, "Help.BookmarkShortcut", modecontext);
|
||||||
cmd = ActionManager::registerShortcut(shortcut, "Help.BookmarkShortcut", modecontext);
|
|
||||||
cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+B") : tr("Ctrl+Shift+B")));
|
cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+B") : tr("Ctrl+Shift+B")));
|
||||||
connect(shortcut, SIGNAL(activated()), this, SLOT(activateBookmarks()));
|
connect(action, SIGNAL(triggered()), this, SLOT(activateBookmarks()));
|
||||||
shortcutMap.insert(QLatin1String(SB_BOOKMARKS), cmd);
|
shortcutMap.insert(QLatin1String(SB_BOOKMARKS), cmd);
|
||||||
|
|
||||||
QWidget *openPagesWidget = OpenPagesManager::instance().openPagesWidget();
|
QWidget *openPagesWidget = OpenPagesManager::instance().openPagesWidget();
|
||||||
openPagesWidget->setWindowTitle(tr("Open Pages"));
|
openPagesWidget->setWindowTitle(tr("Open Pages"));
|
||||||
m_openPagesItem = new SideBarItem(openPagesWidget, QLatin1String(SB_OPENPAGES));
|
m_openPagesItem = new SideBarItem(openPagesWidget, QLatin1String(SB_OPENPAGES));
|
||||||
|
|
||||||
shortcut = new QShortcut(m_splitter);
|
action = new QAction(tr("Activate Open Pages in Help mode"), m_splitter);
|
||||||
shortcut->setWhatsThis(tr("Activate Open Pages in Help mode"));
|
cmd = ActionManager::registerAction(action, "Help.PagesShortcut", modecontext);
|
||||||
cmd = ActionManager::registerShortcut(shortcut, "Help.PagesShortcut", modecontext);
|
|
||||||
cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+O") : tr("Ctrl+Shift+O")));
|
cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+O") : tr("Ctrl+Shift+O")));
|
||||||
connect(shortcut, SIGNAL(activated()), this, SLOT(activateOpenPages()));
|
connect(action, SIGNAL(triggered()), this, SLOT(activateOpenPages()));
|
||||||
shortcutMap.insert(QLatin1String(SB_OPENPAGES), cmd);
|
shortcutMap.insert(QLatin1String(SB_OPENPAGES), cmd);
|
||||||
|
|
||||||
QList<SideBarItem*> itemList;
|
QList<SideBarItem*> itemList;
|
||||||
|
|||||||
@@ -113,10 +113,6 @@ void ActionMacroHandler::registerCommand(Id id)
|
|||||||
m_mapper->setMapping(action, id.toString());
|
m_mapper->setMapping(action, id.toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (QShortcut *shortcut = command->shortcut()) {
|
|
||||||
connect(shortcut, SIGNAL(activated()), m_mapper, SLOT(map()));
|
|
||||||
m_mapper->setMapping(shortcut, id.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,7 @@
|
|||||||
#include <coreplugin/icontext.h>
|
#include <coreplugin/icontext.h>
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <coreplugin/editormanager/ieditor.h>
|
#include <coreplugin/editormanager/ieditor.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
@@ -57,7 +58,6 @@
|
|||||||
#include <QSignalMapper>
|
#include <QSignalMapper>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
|
||||||
#include <QShortcut>
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
@@ -100,6 +100,7 @@ public:
|
|||||||
|
|
||||||
MacroManager *q;
|
MacroManager *q;
|
||||||
QMap<QString, Macro *> macros;
|
QMap<QString, Macro *> macros;
|
||||||
|
QMap<QString, QAction *> actions;
|
||||||
Macro *currentMacro;
|
Macro *currentMacro;
|
||||||
bool isRecording;
|
bool isRecording;
|
||||||
|
|
||||||
@@ -163,14 +164,16 @@ void MacroManager::MacroManagerPrivate::addMacro(Macro *macro)
|
|||||||
{
|
{
|
||||||
// Add sortcut
|
// Add sortcut
|
||||||
Core::Context context(TextEditor::Constants::C_TEXTEDITOR);
|
Core::Context context(TextEditor::Constants::C_TEXTEDITOR);
|
||||||
QShortcut *shortcut = new QShortcut(Core::ICore::mainWindow());
|
QAction *action = new QAction(macro->description(), q);
|
||||||
shortcut->setWhatsThis(macro->description());
|
Core::Command *command = Core::ActionManager::registerAction(
|
||||||
Core::ActionManager::registerShortcut(shortcut, makeId(macro->displayName()), context);
|
action, makeId(macro->displayName()), context);
|
||||||
connect(shortcut, SIGNAL(activated()), mapper, SLOT(map()));
|
command->setAttribute(Core::Command::CA_UpdateText);
|
||||||
mapper->setMapping(shortcut, macro->displayName());
|
connect(action, SIGNAL(triggered()), mapper, SLOT(map()));
|
||||||
|
mapper->setMapping(action, macro->displayName());
|
||||||
|
|
||||||
// Add macro to the map
|
// Add macro to the map
|
||||||
macros[macro->displayName()] = macro;
|
macros[macro->displayName()] = macro;
|
||||||
|
actions[macro->displayName()] = action;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacroManager::MacroManagerPrivate::removeMacro(const QString &name)
|
void MacroManager::MacroManagerPrivate::removeMacro(const QString &name)
|
||||||
@@ -178,7 +181,9 @@ void MacroManager::MacroManagerPrivate::removeMacro(const QString &name)
|
|||||||
if (!macros.contains(name))
|
if (!macros.contains(name))
|
||||||
return;
|
return;
|
||||||
// Remove shortcut
|
// Remove shortcut
|
||||||
Core::ActionManager::unregisterShortcut(makeId(name));
|
QAction *action = actions.take(name);
|
||||||
|
Core::ActionManager::unregisterAction(action, makeId(name));
|
||||||
|
delete action;
|
||||||
|
|
||||||
// Remove macro from the map
|
// Remove macro from the map
|
||||||
Macro *macro = macros.take(name);
|
Macro *macro = macros.take(name);
|
||||||
@@ -192,10 +197,9 @@ void MacroManager::MacroManagerPrivate::changeMacroDescription(Macro *macro, con
|
|||||||
macro->setDescription(description);
|
macro->setDescription(description);
|
||||||
macro->save(macro->fileName(), Core::ICore::mainWindow());
|
macro->save(macro->fileName(), Core::ICore::mainWindow());
|
||||||
|
|
||||||
// Change shortcut what's this
|
QAction *action = actions[macro->displayName()];
|
||||||
Core::Command *command = Core::ActionManager::command(makeId(macro->displayName()));
|
QTC_ASSERT(action, return);
|
||||||
if (command && command->shortcut())
|
action->setText(description);
|
||||||
command->shortcut()->setWhatsThis(description);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MacroManager::MacroManagerPrivate::executeMacro(Macro *macro)
|
bool MacroManager::MacroManagerPrivate::executeMacro(Macro *macro)
|
||||||
|
|||||||
@@ -112,8 +112,8 @@ void MacroOptionsWidget::createTable()
|
|||||||
|
|
||||||
Core::Command *command =
|
Core::Command *command =
|
||||||
Core::ActionManager::command(base.withSuffix(it.value()->displayName()));
|
Core::ActionManager::command(base.withSuffix(it.value()->displayName()));
|
||||||
if (command && command->shortcut())
|
if (command && command->action())
|
||||||
macroItem->setText(2, command->shortcut()->key().toString());
|
macroItem->setText(2, command->action()->shortcut().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ void TextEditorMacroHandler::startRecording(Macro *macro)
|
|||||||
m_currentEditor->widget()->installEventFilter(this);
|
m_currentEditor->widget()->installEventFilter(this);
|
||||||
|
|
||||||
// Block completion
|
// Block completion
|
||||||
Core::ActionManager::command(TextEditor::Constants::COMPLETE_THIS)->shortcut()->blockSignals(true);
|
Core::ActionManager::command(TextEditor::Constants::COMPLETE_THIS)->action()->blockSignals(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorMacroHandler::endRecordingMacro(Macro *macro)
|
void TextEditorMacroHandler::endRecordingMacro(Macro *macro)
|
||||||
@@ -85,7 +85,7 @@ void TextEditorMacroHandler::endRecordingMacro(Macro *macro)
|
|||||||
IMacroHandler::endRecordingMacro(macro);
|
IMacroHandler::endRecordingMacro(macro);
|
||||||
|
|
||||||
// Unblock completion
|
// Unblock completion
|
||||||
Core::ActionManager::command(TextEditor::Constants::COMPLETE_THIS)->shortcut()->blockSignals(false);
|
Core::ActionManager::command(TextEditor::Constants::COMPLETE_THIS)->action()->blockSignals(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextEditorMacroHandler::canExecuteEvent(const MacroEvent ¯oEvent)
|
bool TextEditorMacroHandler::canExecuteEvent(const MacroEvent ¯oEvent)
|
||||||
|
|||||||
@@ -52,7 +52,7 @@
|
|||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QtPlugin>
|
#include <QtPlugin>
|
||||||
#include <QShortcut>
|
#include <QAction>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QTemporaryFile>
|
#include <QTemporaryFile>
|
||||||
|
|
||||||
@@ -169,29 +169,21 @@ bool TextEditorPlugin::initialize(const QStringList &arguments, QString *errorMe
|
|||||||
Core::Context context(TextEditor::Constants::C_TEXTEDITOR);
|
Core::Context context(TextEditor::Constants::C_TEXTEDITOR);
|
||||||
|
|
||||||
// Add shortcut for invoking automatic completion
|
// Add shortcut for invoking automatic completion
|
||||||
QShortcut *completionShortcut = new QShortcut(Core::ICore::mainWindow());
|
QAction *completionAction = new QAction(tr("Trigger Completion"), this);
|
||||||
completionShortcut->setWhatsThis(tr("Triggers a completion in this scope"));
|
Core::Command *command = Core::ActionManager::registerAction(completionAction, Constants::COMPLETE_THIS, context);
|
||||||
// Make sure the shortcut still works when the completion widget is active
|
|
||||||
completionShortcut->setContext(Qt::ApplicationShortcut);
|
|
||||||
Core::Command *command = Core::ActionManager::registerShortcut(completionShortcut, Constants::COMPLETE_THIS, context);
|
|
||||||
command->setDefaultKeySequence(QKeySequence(Core::UseMacShortcuts ? tr("Meta+Space") : tr("Ctrl+Space")));
|
command->setDefaultKeySequence(QKeySequence(Core::UseMacShortcuts ? tr("Meta+Space") : tr("Ctrl+Space")));
|
||||||
connect(completionShortcut, SIGNAL(activated()), this, SLOT(invokeCompletion()));
|
connect(completionAction, SIGNAL(triggered()), this, SLOT(invokeCompletion()));
|
||||||
|
|
||||||
// Add shortcut for invoking quick fix options
|
// Add shortcut for invoking quick fix options
|
||||||
QShortcut *quickFixShortcut = new QShortcut(Core::ICore::mainWindow());
|
QAction *quickFixAction = new QAction(tr("Trigger Quick Fix"), this);
|
||||||
quickFixShortcut->setWhatsThis(tr("Triggers a quick fix in this scope"));
|
Core::Command *quickFixCommand = Core::ActionManager::registerAction(quickFixAction, Constants::QUICKFIX_THIS, context);
|
||||||
// Make sure the shortcut still works when the quick fix widget is active
|
|
||||||
quickFixShortcut->setContext(Qt::ApplicationShortcut);
|
|
||||||
Core::Command *quickFixCommand = Core::ActionManager::registerShortcut(quickFixShortcut, Constants::QUICKFIX_THIS, context);
|
|
||||||
quickFixCommand->setDefaultKeySequence(QKeySequence(tr("Alt+Return")));
|
quickFixCommand->setDefaultKeySequence(QKeySequence(tr("Alt+Return")));
|
||||||
connect(quickFixShortcut, SIGNAL(activated()), this, SLOT(invokeQuickFix()));
|
connect(quickFixAction, SIGNAL(triggered()), this, SLOT(invokeQuickFix()));
|
||||||
|
|
||||||
// Add shortcut for create a scratch buffer
|
// Add shortcut for create a scratch buffer
|
||||||
QShortcut *scratchBufferShortcut = new QShortcut(Core::ICore::mainWindow());
|
QAction *scratchBufferAction = new QAction(tr("Create Scratch Buffer Using a Temporary File"), this);
|
||||||
scratchBufferShortcut->setWhatsThis(tr("Creates a scratch buffer using a temporary file."));
|
Core::ActionManager::registerAction(scratchBufferAction, Constants::CREATE_SCRATCH_BUFFER, context);
|
||||||
scratchBufferShortcut->setContext(Qt::ApplicationShortcut);
|
connect(scratchBufferAction, SIGNAL(triggered()), scratchFile, SLOT(createFile()));
|
||||||
Core::ActionManager::registerShortcut(scratchBufferShortcut, Constants::CREATE_SCRATCH_BUFFER, context);
|
|
||||||
connect(scratchBufferShortcut, SIGNAL(activated()), scratchFile, SLOT(createFile()));
|
|
||||||
|
|
||||||
// Generic highlighter.
|
// Generic highlighter.
|
||||||
connect(Core::ICore::instance(), SIGNAL(coreOpened()),
|
connect(Core::ICore::instance(), SIGNAL(coreOpened()),
|
||||||
|
|||||||
Reference in New Issue
Block a user