forked from qt-creator/qt-creator
Designer shortcuts fixes, TaskWindow's copy action fixed
Reverted the commit 59ecb9cf8 which could break wrongly written code
(or the cases like designer).
Fix one of such case (copy action in task window).
Fix synchronization of designer shortcuts by connecting to the
keySequenceChanged() signal of their Command representation.
Reviewed-by: con
Task-number: QTCREATORBUG-471
This commit is contained in:
@@ -500,7 +500,6 @@ void OverrideableAction::addOverrideAction(QAction *action, const QList<int> &co
|
|||||||
m_contextActionMap.insert(k, action);
|
m_contextActionMap.insert(k, action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
action->setShortcut(OverrideableAction::action()->shortcut());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverrideableAction::actionChanged()
|
void OverrideableAction::actionChanged()
|
||||||
@@ -530,14 +529,3 @@ bool OverrideableAction::isActive() const
|
|||||||
{
|
{
|
||||||
return m_active;
|
return m_active;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverrideableAction::setKeySequence(const QKeySequence &key)
|
|
||||||
{
|
|
||||||
QMap<int, QPointer<QAction> >::const_iterator it = m_contextActionMap.constBegin();
|
|
||||||
QMap<int, QPointer<QAction> >::const_iterator itEnd = m_contextActionMap.constEnd();
|
|
||||||
while (it != itEnd) {
|
|
||||||
it.value()->setShortcut(key);
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
Action::setKeySequence(key);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -143,7 +143,6 @@ public:
|
|||||||
bool setCurrentContext(const QList<int> &context);
|
bool setCurrentContext(const QList<int> &context);
|
||||||
void addOverrideAction(QAction *action, const QList<int> &context);
|
void addOverrideAction(QAction *action, const QList<int> &context);
|
||||||
bool isActive() const;
|
bool isActive() const;
|
||||||
void setKeySequence(const QKeySequence &key);
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void actionChanged();
|
void actionChanged();
|
||||||
|
|||||||
@@ -105,33 +105,8 @@ static inline QIcon designerIcon(const QString &iconName)
|
|||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create an action to activate a designer tool
|
// Create a menu separator
|
||||||
static inline QAction *createEditModeAction(QActionGroup *ag,
|
static inline QAction *createSeparator(QObject *parent,
|
||||||
const QList<int> &context,
|
|
||||||
Core::ActionManager *am,
|
|
||||||
Core::ActionContainer *medit,
|
|
||||||
const QString &actionName,
|
|
||||||
const QString &name,
|
|
||||||
int toolNumber,
|
|
||||||
const QString &iconName = QString(),
|
|
||||||
const QString &keySequence = QString())
|
|
||||||
{
|
|
||||||
QAction *rc = new QAction(actionName, ag);
|
|
||||||
rc->setCheckable(true);
|
|
||||||
if (!iconName.isEmpty())
|
|
||||||
rc->setIcon(designerIcon(iconName));
|
|
||||||
Core::Command *command = am->registerAction(rc, name, context);
|
|
||||||
if (!keySequence.isEmpty())
|
|
||||||
command->setDefaultKeySequence(QKeySequence(keySequence));
|
|
||||||
medit->addAction(command, Core::Constants::G_EDIT_OTHER);
|
|
||||||
rc->setData(toolNumber);
|
|
||||||
ag->addAction(rc);
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Create a menu separato
|
|
||||||
static inline QAction * createSeparator(QObject *parent,
|
|
||||||
Core::ActionManager *am,
|
Core::ActionManager *am,
|
||||||
const QList<int> &context,
|
const QList<int> &context,
|
||||||
Core::ActionContainer *container,
|
Core::ActionContainer *container,
|
||||||
@@ -145,20 +120,6 @@ static inline QAction * createSeparator(QObject *parent,
|
|||||||
return actSeparator;
|
return actSeparator;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a tool action
|
|
||||||
static inline void addToolAction(QAction *a,
|
|
||||||
Core::ActionManager *am,
|
|
||||||
const QList<int> &context,
|
|
||||||
const QString &name,
|
|
||||||
Core::ActionContainer *c1,
|
|
||||||
const QString &keySequence = QString())
|
|
||||||
{
|
|
||||||
Core::Command *command = am->registerAction(a, name, context);
|
|
||||||
if (!keySequence.isEmpty())
|
|
||||||
command->setDefaultKeySequence(QKeySequence(keySequence));
|
|
||||||
c1->addAction(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
using namespace Designer;
|
using namespace Designer;
|
||||||
using namespace Designer::Internal;
|
using namespace Designer::Internal;
|
||||||
using namespace Designer::Constants;
|
using namespace Designer::Constants;
|
||||||
@@ -237,7 +198,8 @@ FormEditorW::FormEditorW() :
|
|||||||
m_actionPrint(0),
|
m_actionPrint(0),
|
||||||
m_actionPreview(0),
|
m_actionPreview(0),
|
||||||
m_actionGroupPreviewInStyle(0),
|
m_actionGroupPreviewInStyle(0),
|
||||||
m_actionAboutPlugins(0)
|
m_actionAboutPlugins(0),
|
||||||
|
m_shortcutMapper(new QSignalMapper(this))
|
||||||
{
|
{
|
||||||
if (Designer::Constants::Internal::debug)
|
if (Designer::Constants::Internal::debug)
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
@@ -270,6 +232,8 @@ FormEditorW::FormEditorW() :
|
|||||||
|
|
||||||
connect(m_core->editorManager(), SIGNAL(currentEditorChanged(Core::IEditor *)),
|
connect(m_core->editorManager(), SIGNAL(currentEditorChanged(Core::IEditor *)),
|
||||||
this, SLOT(currentEditorChanged(Core::IEditor *)));
|
this, SLOT(currentEditorChanged(Core::IEditor *)));
|
||||||
|
connect(m_shortcutMapper, SIGNAL(mapped(QObject *)),
|
||||||
|
this, SLOT(updateShortcut(QObject *)));
|
||||||
}
|
}
|
||||||
|
|
||||||
FormEditorW::~FormEditorW()
|
FormEditorW::~FormEditorW()
|
||||||
@@ -397,20 +361,21 @@ void FormEditorW::setupActions()
|
|||||||
mtools->addMenu(mformtools);
|
mtools->addMenu(mformtools);
|
||||||
|
|
||||||
//overridden actions
|
//overridden actions
|
||||||
am->registerAction(m_fwm->actionUndo(), Core::Constants::UNDO, m_context);
|
bindShortcut(am->registerAction(m_fwm->actionUndo(), Core::Constants::UNDO, m_context), m_fwm->actionUndo());
|
||||||
am->registerAction(m_fwm->actionRedo(), Core::Constants::REDO, m_context);
|
bindShortcut(am->registerAction(m_fwm->actionRedo(), Core::Constants::REDO, m_context), m_fwm->actionRedo());
|
||||||
am->registerAction(m_fwm->actionCut(), Core::Constants::CUT, m_context);
|
bindShortcut(am->registerAction(m_fwm->actionCut(), Core::Constants::CUT, m_context), m_fwm->actionCut());
|
||||||
am->registerAction(m_fwm->actionCopy(), Core::Constants::COPY, m_context);
|
bindShortcut(am->registerAction(m_fwm->actionCopy(), Core::Constants::COPY, m_context), m_fwm->actionCopy());
|
||||||
am->registerAction(m_fwm->actionPaste(), Core::Constants::PASTE, m_context);
|
bindShortcut(am->registerAction(m_fwm->actionPaste(), Core::Constants::PASTE, m_context), m_fwm->actionPaste());
|
||||||
am->registerAction(m_fwm->actionSelectAll(), Core::Constants::SELECTALL, m_context);
|
bindShortcut(am->registerAction(m_fwm->actionSelectAll(), Core::Constants::SELECTALL, m_context), m_fwm->actionSelectAll());
|
||||||
|
|
||||||
m_actionPrint = new QAction(this);
|
m_actionPrint = new QAction(this);
|
||||||
am->registerAction(m_actionPrint, Core::Constants::PRINT, m_context);
|
bindShortcut(am->registerAction(m_actionPrint, Core::Constants::PRINT, m_context), m_actionPrint);
|
||||||
connect(m_actionPrint, SIGNAL(triggered()), this, SLOT(print()));
|
connect(m_actionPrint, SIGNAL(triggered()), this, SLOT(print()));
|
||||||
|
|
||||||
//'delete' action
|
//'delete' action
|
||||||
command = am->registerAction(m_fwm->actionDelete(), QLatin1String("FormEditor.Edit.Delete"), m_context);
|
command = am->registerAction(m_fwm->actionDelete(), QLatin1String("FormEditor.Edit.Delete"), m_context);
|
||||||
command->setDefaultKeySequence(QKeySequence::Delete);
|
command->setDefaultKeySequence(QKeySequence::Delete);
|
||||||
|
bindShortcut(command, m_fwm->actionDelete());
|
||||||
command->setAttribute(Core::Command::CA_Hide);
|
command->setAttribute(Core::Command::CA_Hide);
|
||||||
medit->addAction(command, Core::Constants::G_EDIT_COPYPASTE);
|
medit->addAction(command, Core::Constants::G_EDIT_COPYPASTE);
|
||||||
|
|
||||||
@@ -613,6 +578,7 @@ Core::ActionContainer *FormEditorW::createPreviewStyleMenu(Core::ActionManager *
|
|||||||
}
|
}
|
||||||
name += data.toString();
|
name += data.toString();
|
||||||
Core::Command *command = am->registerAction(a, name, m_context);
|
Core::Command *command = am->registerAction(a, name, m_context);
|
||||||
|
bindShortcut(command, a);
|
||||||
if (isDeviceProfile) {
|
if (isDeviceProfile) {
|
||||||
command->setAttribute(Core::Command::CA_UpdateText);
|
command->setAttribute(Core::Command::CA_UpdateText);
|
||||||
command->setAttribute(Core::Command::CA_NonConfigureable);
|
command->setAttribute(Core::Command::CA_NonConfigureable);
|
||||||
@@ -642,6 +608,56 @@ void FormEditorW::critical(const QString &errorMessage)
|
|||||||
QMessageBox::critical(m_core->mainWindow(), tr("Designer"), errorMessage);
|
QMessageBox::critical(m_core->mainWindow(), tr("Designer"), errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply the command shortcut to the action and connects to the command's keySequenceChanged signal
|
||||||
|
void FormEditorW::bindShortcut(Core::Command *command, QAction *action)
|
||||||
|
{
|
||||||
|
m_commandToDesignerAction.insert(command, action);
|
||||||
|
connect(command, SIGNAL(keySequenceChanged()),
|
||||||
|
m_shortcutMapper, SLOT(map()));
|
||||||
|
m_shortcutMapper->setMapping(command, command);
|
||||||
|
updateShortcut(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create an action to activate a designer tool
|
||||||
|
QAction *FormEditorW::createEditModeAction(QActionGroup *ag,
|
||||||
|
const QList<int> &context,
|
||||||
|
Core::ActionManager *am,
|
||||||
|
Core::ActionContainer *medit,
|
||||||
|
const QString &actionName,
|
||||||
|
const QString &name,
|
||||||
|
int toolNumber,
|
||||||
|
const QString &iconName,
|
||||||
|
const QString &keySequence)
|
||||||
|
{
|
||||||
|
QAction *rc = new QAction(actionName, ag);
|
||||||
|
rc->setCheckable(true);
|
||||||
|
if (!iconName.isEmpty())
|
||||||
|
rc->setIcon(designerIcon(iconName));
|
||||||
|
Core::Command *command = am->registerAction(rc, name, context);
|
||||||
|
if (!keySequence.isEmpty())
|
||||||
|
command->setDefaultKeySequence(QKeySequence(keySequence));
|
||||||
|
bindShortcut(command, rc);
|
||||||
|
medit->addAction(command, Core::Constants::G_EDIT_OTHER);
|
||||||
|
rc->setData(toolNumber);
|
||||||
|
ag->addAction(rc);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a tool action
|
||||||
|
void FormEditorW::addToolAction(QAction *a,
|
||||||
|
Core::ActionManager *am,
|
||||||
|
const QList<int> &context,
|
||||||
|
const QString &name,
|
||||||
|
Core::ActionContainer *c1,
|
||||||
|
const QString &keySequence)
|
||||||
|
{
|
||||||
|
Core::Command *command = am->registerAction(a, name, context);
|
||||||
|
if (!keySequence.isEmpty())
|
||||||
|
command->setDefaultKeySequence(QKeySequence(keySequence));
|
||||||
|
bindShortcut(command, a);
|
||||||
|
c1->addAction(command);
|
||||||
|
}
|
||||||
|
|
||||||
FormWindowEditor *FormEditorW::createFormWindowEditor(QWidget* parentWidget)
|
FormWindowEditor *FormEditorW::createFormWindowEditor(QWidget* parentWidget)
|
||||||
{
|
{
|
||||||
m_fwm->closeAllPreviews();
|
m_fwm->closeAllPreviews();
|
||||||
@@ -673,6 +689,17 @@ void FormEditorW::editorDestroyed()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FormEditorW::updateShortcut(QObject *command)
|
||||||
|
{
|
||||||
|
Core::Command *c = qobject_cast<Core::Command *>(command);
|
||||||
|
if (!c)
|
||||||
|
return;
|
||||||
|
QAction *a = m_commandToDesignerAction.value(c);
|
||||||
|
if (!a)
|
||||||
|
return;
|
||||||
|
a->setShortcut(c->action()->shortcut());
|
||||||
|
}
|
||||||
|
|
||||||
void FormEditorW::currentEditorChanged(Core::IEditor *editor)
|
void FormEditorW::currentEditorChanged(Core::IEditor *editor)
|
||||||
{
|
{
|
||||||
if (Designer::Constants::Internal::debug)
|
if (Designer::Constants::Internal::debug)
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
#include <QtCore/QPointer>
|
#include <QtCore/QPointer>
|
||||||
#include <QtCore/QStringList>
|
#include <QtCore/QStringList>
|
||||||
|
#include <QtCore/QSignalMapper>
|
||||||
#include <QtGui/QAction>
|
#include <QtGui/QAction>
|
||||||
|
|
||||||
#include "designerconstants.h"
|
#include "designerconstants.h"
|
||||||
@@ -65,6 +66,7 @@ class ActionManager;
|
|||||||
class ActionContainer;
|
class ActionContainer;
|
||||||
class ICore;
|
class ICore;
|
||||||
class IEditor;
|
class IEditor;
|
||||||
|
class Command;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Designer {
|
namespace Designer {
|
||||||
@@ -141,6 +143,7 @@ private slots:
|
|||||||
void resetToDefaultLayout();
|
void resetToDefaultLayout();
|
||||||
|
|
||||||
void editorDestroyed();
|
void editorDestroyed();
|
||||||
|
void updateShortcut(QObject *command);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FormEditorW();
|
FormEditorW();
|
||||||
@@ -158,6 +161,23 @@ private:
|
|||||||
QActionGroup *actionGroup);
|
QActionGroup *actionGroup);
|
||||||
|
|
||||||
void critical(const QString &errorMessage);
|
void critical(const QString &errorMessage);
|
||||||
|
void bindShortcut(Core::Command *command, QAction *action);
|
||||||
|
QAction *createEditModeAction(QActionGroup *ag,
|
||||||
|
const QList<int> &context,
|
||||||
|
Core::ActionManager *am,
|
||||||
|
Core::ActionContainer *medit,
|
||||||
|
const QString &actionName,
|
||||||
|
const QString &name,
|
||||||
|
int toolNumber,
|
||||||
|
const QString &iconName = QString(),
|
||||||
|
const QString &keySequence = QString());
|
||||||
|
void addToolAction(QAction *a,
|
||||||
|
Core::ActionManager *am,
|
||||||
|
const QList<int> &context,
|
||||||
|
const QString &name,
|
||||||
|
Core::ActionContainer *c1,
|
||||||
|
const QString &keySequence = QString());
|
||||||
|
|
||||||
|
|
||||||
static FormEditorW *m_self;
|
static FormEditorW *m_self;
|
||||||
|
|
||||||
@@ -184,6 +204,8 @@ private:
|
|||||||
|
|
||||||
EditorList m_formWindows;
|
EditorList m_formWindows;
|
||||||
QStringList m_toolActionIds;
|
QStringList m_toolActionIds;
|
||||||
|
QSignalMapper *m_shortcutMapper;
|
||||||
|
QMap<Core::Command *, QAction *> m_commandToDesignerAction;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/uniqueidmanager.h>
|
#include <coreplugin/uniqueidmanager.h>
|
||||||
|
#include <coreplugin/actionmanager/command.h>
|
||||||
#include <texteditor/basetexteditor.h>
|
#include <texteditor/basetexteditor.h>
|
||||||
#include <texteditor/itexteditor.h>
|
#include <texteditor/itexteditor.h>
|
||||||
|
|
||||||
@@ -456,9 +457,9 @@ TaskWindow::TaskWindow()
|
|||||||
core->addContextObject(m_taskWindowContext);
|
core->addContextObject(m_taskWindowContext);
|
||||||
|
|
||||||
m_copyAction = new QAction(QIcon(Core::Constants::ICON_COPY), tr("&Copy"), this);
|
m_copyAction = new QAction(QIcon(Core::Constants::ICON_COPY), tr("&Copy"), this);
|
||||||
core->actionManager()->
|
Core::Command *command = core->actionManager()->
|
||||||
registerAction(m_copyAction, Core::Constants::COPY, m_taskWindowContext->context());
|
registerAction(m_copyAction, Core::Constants::COPY, m_taskWindowContext->context());
|
||||||
m_listview->addAction(m_copyAction);
|
m_listview->addAction(command->action());
|
||||||
|
|
||||||
connect(m_listview->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
|
connect(m_listview->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
|
||||||
tld, SLOT(currentChanged(const QModelIndex &, const QModelIndex &)));
|
tld, SLOT(currentChanged(const QModelIndex &, const QModelIndex &)));
|
||||||
|
|||||||
Reference in New Issue
Block a user