Commit 0078bb08 authored by con's avatar con
Browse files

Avoid use of QKeySequence::isEmpty in checks in command implementations.

isEmpty is the wrong thing to check when setting the default shortcut. In addition,
registering commands should not set their shortcut automatically (that
should be defined solely by the default shortcut and reading the
settings, which is done later).
parent 6371d283
......@@ -377,8 +377,6 @@ Command *ActionManagerPrivate::registerOverridableAction(QAction *action, const
#endif
a->setAction(baseAction);
m_mainWnd->addAction(baseAction);
a->setKeySequence(a->keySequence());
a->setDefaultKeySequence(QKeySequence());
} else if (checkUnique) {
qWarning() << "registerOverridableAction: id" << id << "is already registered.";
}
......@@ -417,9 +415,6 @@ Command *ActionManagerPrivate::registerShortcut(QShortcut *shortcut, const Id &i
else
sc->setContext(context);
sc->setKeySequence(shortcut->key());
sc->setDefaultKeySequence(QKeySequence());
return sc;
}
......
......@@ -200,12 +200,14 @@ using namespace Core::Internal;
*/
CommandPrivate::CommandPrivate(int id)
: m_attributes(0), m_id(id)
: m_attributes(0), m_id(id), m_isKeyInitialized(false)
{
}
void CommandPrivate::setDefaultKeySequence(const QKeySequence &key)
{
if (!m_isKeyInitialized)
setKeySequence(key);
m_defaultKey = key;
}
......@@ -214,6 +216,12 @@ QKeySequence CommandPrivate::defaultKeySequence() const
return m_defaultKey;
}
void CommandPrivate::setKeySequence(const QKeySequence &key)
{
Q_UNUSED(key)
m_isKeyInitialized = true;
}
void CommandPrivate::setDefaultText(const QString &text)
{
m_defaultText = text;
......@@ -306,15 +314,9 @@ Core::Context Shortcut::context() const
return m_context;
}
void Shortcut::setDefaultKeySequence(const QKeySequence &key)
{
if (m_shortcut->key().isEmpty())
setKeySequence(key);
CommandPrivate::setDefaultKeySequence(key);
}
void Shortcut::setKeySequence(const QKeySequence &key)
{
CommandPrivate::setKeySequence(key);
m_shortcut->setKey(key);
emit keySequenceChanged();
}
......@@ -405,15 +407,9 @@ QList<CommandLocation> Action::locations() const
return m_locations;
}
void Action::setDefaultKeySequence(const QKeySequence &key)
{
if (m_action->shortcut().isEmpty())
setKeySequence(key);
CommandPrivate::setDefaultKeySequence(key);
}
void Action::setKeySequence(const QKeySequence &key)
{
CommandPrivate::setKeySequence(key);
m_action->setShortcut(key);
updateToolTipWithKeySequence();
emit keySequenceChanged();
......@@ -538,3 +534,4 @@ void Action::setActive(bool state)
emit activeStateChanged();
}
}
......@@ -53,6 +53,8 @@ public:
void setDefaultKeySequence(const QKeySequence &key);
QKeySequence defaultKeySequence() const;
void setKeySequence(const QKeySequence &key);
void setDefaultText(const QString &text);
QString defaultText() const;
......@@ -78,6 +80,7 @@ protected:
int m_id;
QKeySequence m_defaultKey;
QString m_defaultText;
bool m_isKeyInitialized;
};
class Shortcut : public CommandPrivate
......@@ -88,7 +91,6 @@ public:
QString name() const;
void setDefaultKeySequence(const QKeySequence &key);
void setKeySequence(const QKeySequence &key);
QKeySequence keySequence() const;
......@@ -116,7 +118,6 @@ public:
QString name() const;
void setDefaultKeySequence(const QKeySequence &key);
void setKeySequence(const QKeySequence &key);
QKeySequence keySequence() const;
......
......@@ -198,6 +198,9 @@ void ModeManager::objectAdded(QObject *obj)
connect(cmd, SIGNAL(keySequenceChanged()), this, SLOT(updateModeToolTip()));
for (int i = 0; i < d->m_modeShortcuts.size(); ++i) {
Command *currentCmd = d->m_modeShortcuts.at(i);
// we need this hack with currentlyHasDefaultSequence
// because we call setDefaultShortcut multiple times on the same cmd
// and still expect the current shortcut to change with it
bool currentlyHasDefaultSequence = (currentCmd->keySequence()
== currentCmd->defaultKeySequence());
#ifdef Q_WS_MAC
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment