forked from qt-creator/qt-creator
Shortcuts: Remember them even for plugins that are not loaded
This also fixes the issue that shortcuts of designer integration gets lost if it doesn't get initialized. Task-number: QTCREATORBUG-4264 Task-number: QTCREATORBUG-11399 Change-Id: Ieb4fe5fd345e69aa62403e4578fa6028400aff6f Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
@@ -48,6 +48,8 @@ namespace {
|
|||||||
enum { warnAboutFindFailures = 0 };
|
enum { warnAboutFindFailures = 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char kKeyboardSettingsKey[] = "KeyboardShortcuts";
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
using namespace Core::Internal;
|
using namespace Core::Internal;
|
||||||
|
|
||||||
@@ -281,6 +283,7 @@ Command *ActionManager::registerShortcut(QShortcut *shortcut, Id id, const Conte
|
|||||||
} else {
|
} else {
|
||||||
sc = new Shortcut(id);
|
sc = new Shortcut(id);
|
||||||
d->m_idCmdMap.insert(id, sc);
|
d->m_idCmdMap.insert(id, sc);
|
||||||
|
d->readUserSettings(id, sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sc->shortcut()) {
|
if (sc->shortcut()) {
|
||||||
@@ -571,6 +574,7 @@ Action *ActionManagerPrivate::overridableAction(Id id)
|
|||||||
} else {
|
} else {
|
||||||
a = new Action(id);
|
a = new Action(id);
|
||||||
m_idCmdMap.insert(id, a);
|
m_idCmdMap.insert(id, a);
|
||||||
|
readUserSettings(id, a);
|
||||||
ICore::mainWindow()->addAction(a->action());
|
ICore::mainWindow()->addAction(a->action());
|
||||||
a->action()->setObjectName(id.toString());
|
a->action()->setObjectName(id.toString());
|
||||||
a->action()->setShortcutContext(Qt::ApplicationShortcut);
|
a->action()->setShortcutContext(Qt::ApplicationShortcut);
|
||||||
@@ -583,43 +587,60 @@ Action *ActionManagerPrivate::overridableAction(Id id)
|
|||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char settingsGroup[] = "KeyBindings";
|
void ActionManagerPrivate::readUserSettings(Id id, CommandPrivate *cmd)
|
||||||
static const char idKey[] = "ID";
|
{
|
||||||
static const char sequenceKey[] = "Keysequence";
|
QSettings *settings = Core::ICore::settings();
|
||||||
|
settings->beginGroup(QLatin1String(kKeyboardSettingsKey));
|
||||||
|
if (settings->contains(id.toString()))
|
||||||
|
cmd->setKeySequence(QKeySequence(settings->value(id.toString()).toString()));
|
||||||
|
settings->endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char oldSettingsGroup[] = "KeyBindings";
|
||||||
|
static const char oldIdKey[] = "ID";
|
||||||
|
static const char oldSequenceKey[] = "Keysequence";
|
||||||
|
|
||||||
void ActionManagerPrivate::initialize()
|
void ActionManagerPrivate::initialize()
|
||||||
{
|
{
|
||||||
|
// TODO remove me after some period after 3.1
|
||||||
|
// check if settings in old style (pre 3.1) exist
|
||||||
QSettings *settings = Core::ICore::settings();
|
QSettings *settings = Core::ICore::settings();
|
||||||
const int shortcuts = settings->beginReadArray(QLatin1String(settingsGroup));
|
if (settings->contains(QLatin1String(kKeyboardSettingsKey)))
|
||||||
|
return;
|
||||||
|
// move old settings style to new settings style
|
||||||
|
QMap<Id, QKeySequence> shortcutMap;
|
||||||
|
const int shortcuts = settings->beginReadArray(QLatin1String(oldSettingsGroup));
|
||||||
for (int i = 0; i < shortcuts; ++i) {
|
for (int i = 0; i < shortcuts; ++i) {
|
||||||
settings->setArrayIndex(i);
|
settings->setArrayIndex(i);
|
||||||
const QKeySequence key(settings->value(QLatin1String(sequenceKey)).toString());
|
const QKeySequence key(settings->value(QLatin1String(oldSequenceKey)).toString());
|
||||||
const Id id = Id::fromSetting(settings->value(QLatin1String(idKey)));
|
const Id id = Id::fromSetting(settings->value(QLatin1String(oldIdKey)));
|
||||||
|
shortcutMap.insert(id, key);
|
||||||
Command *cmd = ActionManager::command(id);
|
|
||||||
if (cmd)
|
|
||||||
cmd->setKeySequence(key);
|
|
||||||
}
|
}
|
||||||
settings->endArray();
|
settings->endArray();
|
||||||
|
// write settings in new style
|
||||||
|
settings->beginGroup(QLatin1String(kKeyboardSettingsKey));
|
||||||
|
QMapIterator<Id, QKeySequence> it(shortcutMap);
|
||||||
|
while (it.hasNext()) {
|
||||||
|
it.next();
|
||||||
|
settings->setValue(it.key().toString(), it.value().toString());
|
||||||
|
}
|
||||||
|
settings->endGroup();
|
||||||
|
// remove old settings
|
||||||
|
settings->remove(QLatin1String(oldSettingsGroup));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionManagerPrivate::saveSettings(QSettings *settings)
|
void ActionManagerPrivate::saveSettings(QSettings *settings)
|
||||||
{
|
{
|
||||||
settings->beginWriteArray(QLatin1String(settingsGroup));
|
settings->beginGroup(QLatin1String(kKeyboardSettingsKey));
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
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();
|
CommandPrivate *cmd = j.value();
|
||||||
QKeySequence key = cmd->keySequence();
|
QKeySequence key = cmd->keySequence();
|
||||||
if (key != cmd->defaultKeySequence()) {
|
if (key != cmd->defaultKeySequence())
|
||||||
settings->setArrayIndex(count);
|
settings->setValue(id.toString(), key.toString());
|
||||||
settings->setValue(QLatin1String(idKey), id.toString());
|
else
|
||||||
settings->setValue(QLatin1String(sequenceKey), key.toString());
|
settings->remove(id.toString());
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
settings->endGroup();
|
||||||
settings->endArray();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ signals:
|
|||||||
private:
|
private:
|
||||||
ActionManager(QObject *parent = 0);
|
ActionManager(QObject *parent = 0);
|
||||||
~ActionManager();
|
~ActionManager();
|
||||||
void initialize();
|
static void initialize();
|
||||||
void saveSettings(QSettings *settings);
|
void saveSettings(QSettings *settings);
|
||||||
void setContext(const Context &context);
|
void setContext(const Context &context);
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,8 @@ 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);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void containerDestroyed();
|
void containerDestroyed();
|
||||||
|
|
||||||
|
|||||||
@@ -147,6 +147,8 @@ MainWindow::MainWindow() :
|
|||||||
m_zoomAction(0),
|
m_zoomAction(0),
|
||||||
m_toggleSideBarButton(new QToolButton)
|
m_toggleSideBarButton(new QToolButton)
|
||||||
{
|
{
|
||||||
|
ActionManager::initialize(); // must be done before registering any actions
|
||||||
|
|
||||||
(void) new DocumentManager(this);
|
(void) new DocumentManager(this);
|
||||||
OutputPaneManager::create();
|
OutputPaneManager::create();
|
||||||
|
|
||||||
@@ -344,9 +346,6 @@ void MainWindow::extensionsInitialized()
|
|||||||
m_vcsManager->extensionsInitialized();
|
m_vcsManager->extensionsInitialized();
|
||||||
m_navigationWidget->setFactories(ExtensionSystem::PluginManager::getObjects<INavigationWidgetFactory>());
|
m_navigationWidget->setFactories(ExtensionSystem::PluginManager::getObjects<INavigationWidgetFactory>());
|
||||||
|
|
||||||
// reading the shortcut settings must be done after all shortcuts have been registered
|
|
||||||
m_actionManager->initialize();
|
|
||||||
|
|
||||||
readSettings();
|
readSettings();
|
||||||
updateContext();
|
updateContext();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user