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:
Eike Ziller
2014-02-28 17:33:48 +01:00
parent 92e930b367
commit e58c1ab06e
18 changed files with 152 additions and 433 deletions

View File

@@ -113,10 +113,6 @@ void ActionMacroHandler::registerCommand(Id id)
m_mapper->setMapping(action, id.toString());
return;
}
if (QShortcut *shortcut = command->shortcut()) {
connect(shortcut, SIGNAL(activated()), m_mapper, SLOT(map()));
m_mapper->setMapping(shortcut, id.toString());
}
}
}

View File

@@ -49,6 +49,7 @@
#include <coreplugin/icontext.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <utils/qtcassert.h>
#include <QDir>
#include <QFile>
@@ -57,7 +58,6 @@
#include <QSignalMapper>
#include <QList>
#include <QShortcut>
#include <QAction>
#include <QFileDialog>
#include <QMessageBox>
@@ -100,6 +100,7 @@ public:
MacroManager *q;
QMap<QString, Macro *> macros;
QMap<QString, QAction *> actions;
Macro *currentMacro;
bool isRecording;
@@ -163,14 +164,16 @@ void MacroManager::MacroManagerPrivate::addMacro(Macro *macro)
{
// Add sortcut
Core::Context context(TextEditor::Constants::C_TEXTEDITOR);
QShortcut *shortcut = new QShortcut(Core::ICore::mainWindow());
shortcut->setWhatsThis(macro->description());
Core::ActionManager::registerShortcut(shortcut, makeId(macro->displayName()), context);
connect(shortcut, SIGNAL(activated()), mapper, SLOT(map()));
mapper->setMapping(shortcut, macro->displayName());
QAction *action = new QAction(macro->description(), q);
Core::Command *command = Core::ActionManager::registerAction(
action, makeId(macro->displayName()), context);
command->setAttribute(Core::Command::CA_UpdateText);
connect(action, SIGNAL(triggered()), mapper, SLOT(map()));
mapper->setMapping(action, macro->displayName());
// Add macro to the map
macros[macro->displayName()] = macro;
actions[macro->displayName()] = action;
}
void MacroManager::MacroManagerPrivate::removeMacro(const QString &name)
@@ -178,7 +181,9 @@ void MacroManager::MacroManagerPrivate::removeMacro(const QString &name)
if (!macros.contains(name))
return;
// 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
Macro *macro = macros.take(name);
@@ -192,10 +197,9 @@ void MacroManager::MacroManagerPrivate::changeMacroDescription(Macro *macro, con
macro->setDescription(description);
macro->save(macro->fileName(), Core::ICore::mainWindow());
// Change shortcut what's this
Core::Command *command = Core::ActionManager::command(makeId(macro->displayName()));
if (command && command->shortcut())
command->shortcut()->setWhatsThis(description);
QAction *action = actions[macro->displayName()];
QTC_ASSERT(action, return);
action->setText(description);
}
bool MacroManager::MacroManagerPrivate::executeMacro(Macro *macro)

View File

@@ -112,8 +112,8 @@ void MacroOptionsWidget::createTable()
Core::Command *command =
Core::ActionManager::command(base.withSuffix(it.value()->displayName()));
if (command && command->shortcut())
macroItem->setText(2, command->shortcut()->key().toString());
if (command && command->action())
macroItem->setText(2, command->action()->shortcut().toString());
}
}
}

View File

@@ -75,7 +75,7 @@ void TextEditorMacroHandler::startRecording(Macro *macro)
m_currentEditor->widget()->installEventFilter(this);
// 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)
@@ -85,7 +85,7 @@ void TextEditorMacroHandler::endRecordingMacro(Macro *macro)
IMacroHandler::endRecordingMacro(macro);
// 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 &macroEvent)