Commit d0835af5 authored by Eike Ziller's avatar Eike Ziller

ActionManager: Avoid losing shortcuts when actions are unregistered

Since the action for this ID might be unregistered temporarily, and re-
registered under different circumstances.

Change-Id: I6c4ef3ddf814487cc9b63ff979ebb1539cdf7c81
Task-number: QTCREATORBUG-8108
Reviewed-by: default avatarDavid Schulz <david.schulz@theqtcompany.com>
parent 5d719865
......@@ -326,6 +326,7 @@ void ActionManager::unregisterAction(QAction *action, Id id)
a->removeOverrideAction(action);
if (a->isEmpty()) {
// clean up
d->saveSettings(a);
ICore::mainWindow()->removeAction(a->action());
// ActionContainers listen to the commands' destroyed signals
delete a->action();
......@@ -363,9 +364,9 @@ bool ActionManager::isPresentationModeEnabled()
return d->m_presentationModeEnabled;
}
void ActionManager::saveSettings(QSettings *settings)
void ActionManager::saveSettings()
{
d->saveSettings(settings);
d->saveSettings();
}
void ActionManager::setContext(const Context &context)
......@@ -481,18 +482,21 @@ void ActionManagerPrivate::readUserSettings(Id id, Action *cmd)
settings->endGroup();
}
void ActionManagerPrivate::saveSettings(QSettings *settings)
void ActionManagerPrivate::saveSettings(Action *cmd)
{
const QString settingsKey = QLatin1String(kKeyboardSettingsKey) + QLatin1Char('/')
+ cmd->id().toString();
QKeySequence key = cmd->keySequence();
if (key != cmd->defaultKeySequence())
ICore::settings()->setValue(settingsKey, key.toString());
else
ICore::settings()->remove(settingsKey);
}
void ActionManagerPrivate::saveSettings()
{
settings->beginGroup(QLatin1String(kKeyboardSettingsKey));
const IdCmdMap::const_iterator cmdcend = m_idCmdMap.constEnd();
for (IdCmdMap::const_iterator j = m_idCmdMap.constBegin(); j != cmdcend; ++j) {
const Id id = j.key();
Action *cmd = j.value();
QKeySequence key = cmd->keySequence();
if (key != cmd->defaultKeySequence())
settings->setValue(id.toString(), key.toString());
else
settings->remove(id.toString());
saveSettings(j.value());
}
settings->endGroup();
}
......@@ -86,7 +86,7 @@ signals:
private:
ActionManager(QObject *parent = 0);
~ActionManager();
static void saveSettings(QSettings *settings);
static void saveSettings();
static void setContext(const Context &context);
friend class Core::Internal::CorePlugin; // initialization
......
......@@ -67,7 +67,8 @@ public:
void setContext(const Context &context);
bool hasContext(int context) const;
void saveSettings(QSettings *settings);
void saveSettings();
void saveSettings(Action *cmd);
void showShortcutPopup(const QString &shortcut);
bool hasContext(const Context &context) const;
......
......@@ -985,7 +985,7 @@ void MainWindow::writeSettings()
settings->endGroup();
DocumentManager::saveSettings();
ActionManager::saveSettings(settings);
ActionManager::saveSettings();
EditorManagerPrivate::saveSettings();
m_navigationWidget->saveSettings(settings);
}
......
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