forked from qt-creator/qt-creator
Highlight colliding shortcuts for imported keyboard schemes.
This commit is contained in:
@@ -238,6 +238,11 @@ QShortcut *CommandPrivate::shortcut() const
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<int> CommandPrivate::context() const
|
||||||
|
{
|
||||||
|
return m_context;
|
||||||
|
}
|
||||||
|
|
||||||
void CommandPrivate::setAttribute(CommandAttribute attr)
|
void CommandPrivate::setAttribute(CommandAttribute attr)
|
||||||
{
|
{
|
||||||
m_attributes |= attr;
|
m_attributes |= attr;
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ public:
|
|||||||
|
|
||||||
virtual QAction *action() const = 0;
|
virtual QAction *action() const = 0;
|
||||||
virtual QShortcut *shortcut() const = 0;
|
virtual QShortcut *shortcut() const = 0;
|
||||||
|
virtual QList<int> context() const = 0;
|
||||||
|
|
||||||
virtual void setAttribute(CommandAttribute attr) = 0;
|
virtual void setAttribute(CommandAttribute attr) = 0;
|
||||||
virtual void removeAttribute(CommandAttribute attr) = 0;
|
virtual void removeAttribute(CommandAttribute attr) = 0;
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ public:
|
|||||||
|
|
||||||
QAction *action() const;
|
QAction *action() const;
|
||||||
QShortcut *shortcut() const;
|
QShortcut *shortcut() const;
|
||||||
|
QList<int> context() const;
|
||||||
|
|
||||||
|
|
||||||
void setAttribute(CommandAttribute attr);
|
void setAttribute(CommandAttribute attr);
|
||||||
void removeAttribute(CommandAttribute attr);
|
void removeAttribute(CommandAttribute attr);
|
||||||
@@ -70,6 +72,7 @@ public:
|
|||||||
QString stringWithAppendedShortcut(const QString &str) const;
|
QString stringWithAppendedShortcut(const QString &str) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
QList<int> m_context;
|
||||||
QString m_category;
|
QString m_category;
|
||||||
int m_attributes;
|
int m_attributes;
|
||||||
int m_id;
|
int m_id;
|
||||||
@@ -101,7 +104,6 @@ public:
|
|||||||
|
|
||||||
bool isActive() const;
|
bool isActive() const;
|
||||||
private:
|
private:
|
||||||
QList<int> m_context;
|
|
||||||
QShortcut *m_shortcut;
|
QShortcut *m_shortcut;
|
||||||
QString m_defaultText;
|
QString m_defaultText;
|
||||||
};
|
};
|
||||||
@@ -140,7 +142,6 @@ private:
|
|||||||
QString m_toolTip;
|
QString m_toolTip;
|
||||||
|
|
||||||
QPointer<QAction> m_currentAction;
|
QPointer<QAction> m_currentAction;
|
||||||
QList<int> m_context;
|
|
||||||
QMap<int, QPointer<QAction> > m_contextActionMap;
|
QMap<int, QPointer<QAction> > m_contextActionMap;
|
||||||
bool m_active;
|
bool m_active;
|
||||||
bool m_contextInitialized;
|
bool m_contextInitialized;
|
||||||
|
|||||||
@@ -191,3 +191,13 @@ bool CommandMappings::filter(const QString &f, const QTreeWidgetItem *item)
|
|||||||
}
|
}
|
||||||
return !found;
|
return !found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CommandMappings::setModified(QTreeWidgetItem *item , bool modified)
|
||||||
|
{
|
||||||
|
QFont f = item->font(0);
|
||||||
|
f.setItalic(modified);
|
||||||
|
item->setFont(0, f);
|
||||||
|
item->setFont(1, f);
|
||||||
|
f.setBold(modified);
|
||||||
|
item->setFont(2, f);
|
||||||
|
}
|
||||||
|
|||||||
@@ -84,7 +84,9 @@ protected:
|
|||||||
void setTargetLabelText(const QString &s);
|
void setTargetLabelText(const QString &s);
|
||||||
void setTargetEditTitle(const QString &s);
|
void setTargetEditTitle(const QString &s);
|
||||||
void setTargetHeader(const QString &s);
|
void setTargetHeader(const QString &s);
|
||||||
|
void setModified(QTreeWidgetItem *item, bool modified);
|
||||||
|
virtual void markPossibleCollisions(QTreeWidgetItem *) {}
|
||||||
|
virtual void resetCollisionMarkers() {}
|
||||||
private:
|
private:
|
||||||
Ui_CommandMappings *m_page;
|
Ui_CommandMappings *m_page;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
#include "filemanager.h"
|
#include "filemanager.h"
|
||||||
#include "icore.h"
|
#include "icore.h"
|
||||||
#include "uniqueidmanager.h"
|
#include "uniqueidmanager.h"
|
||||||
|
|
||||||
#include <utils/treewidgetcolumnstretcher.h>
|
#include <utils/treewidgetcolumnstretcher.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -121,7 +122,8 @@ void ShortcutSettings::finish()
|
|||||||
|
|
||||||
bool ShortcutSettings::eventFilter(QObject *o, QEvent *e)
|
bool ShortcutSettings::eventFilter(QObject *o, QEvent *e)
|
||||||
{
|
{
|
||||||
Q_UNUSED(o);
|
Q_UNUSED(o)
|
||||||
|
|
||||||
if ( e->type() == QEvent::KeyPress ) {
|
if ( e->type() == QEvent::KeyPress ) {
|
||||||
QKeyEvent *k = static_cast<QKeyEvent*>(e);
|
QKeyEvent *k = static_cast<QKeyEvent*>(e);
|
||||||
handleKeyEvent(k);
|
handleKeyEvent(k);
|
||||||
@@ -157,22 +159,12 @@ void ShortcutSettings::targetIdentifierChanged()
|
|||||||
if (current && current->data(0, Qt::UserRole).isValid()) {
|
if (current && current->data(0, Qt::UserRole).isValid()) {
|
||||||
ShortcutItem *scitem = qVariantValue<ShortcutItem *>(current->data(0, Qt::UserRole));
|
ShortcutItem *scitem = qVariantValue<ShortcutItem *>(current->data(0, Qt::UserRole));
|
||||||
scitem->m_key = QKeySequence(m_key[0], m_key[1], m_key[2], m_key[3]);
|
scitem->m_key = QKeySequence(m_key[0], m_key[1], m_key[2], m_key[3]);
|
||||||
if (scitem->m_cmd->defaultKeySequence() != scitem->m_key) {
|
if (scitem->m_cmd->defaultKeySequence() != scitem->m_key)
|
||||||
QFont f = current->font(0);
|
setModified(current, true);
|
||||||
f.setItalic(true);
|
else
|
||||||
current->setFont(0, f);
|
setModified(current, false);
|
||||||
current->setFont(1, f);
|
|
||||||
f.setBold(true);
|
|
||||||
current->setFont(2, f);
|
|
||||||
} else {
|
|
||||||
QFont f = current->font(0);
|
|
||||||
f.setItalic(false);
|
|
||||||
f.setBold(false);
|
|
||||||
current->setFont(0, f);
|
|
||||||
current->setFont(1, f);
|
|
||||||
current->setFont(2, f);
|
|
||||||
}
|
|
||||||
current->setText(2, scitem->m_key);
|
current->setText(2, scitem->m_key);
|
||||||
|
markPossibleCollisions(scitem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,6 +211,13 @@ void ShortcutSettings::importAction()
|
|||||||
item->m_item->setText(2, item->m_key);
|
item->m_item->setText(2, item->m_key);
|
||||||
if (item->m_item == commandList()->currentItem())
|
if (item->m_item == commandList()->currentItem())
|
||||||
commandChanged(item->m_item);
|
commandChanged(item->m_item);
|
||||||
|
|
||||||
|
if (item->m_cmd->defaultKeySequence() != item->m_key)
|
||||||
|
setModified(item->m_item, true);
|
||||||
|
else
|
||||||
|
setModified(item->m_item, false);
|
||||||
|
|
||||||
|
markPossibleCollisions(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -229,8 +228,10 @@ void ShortcutSettings::defaultAction()
|
|||||||
foreach (ShortcutItem *item, m_scitems) {
|
foreach (ShortcutItem *item, m_scitems) {
|
||||||
item->m_key = item->m_cmd->defaultKeySequence();
|
item->m_key = item->m_cmd->defaultKeySequence();
|
||||||
item->m_item->setText(2, item->m_key);
|
item->m_item->setText(2, item->m_key);
|
||||||
|
setModified(item->m_item, false);
|
||||||
if (item->m_item == commandList()->currentItem())
|
if (item->m_item == commandList()->currentItem())
|
||||||
commandChanged(item->m_item);
|
commandChanged(item->m_item);
|
||||||
|
resetCollisionMarkers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,15 +295,8 @@ void ShortcutSettings::initialize()
|
|||||||
}
|
}
|
||||||
|
|
||||||
item->setText(2, s->m_key);
|
item->setText(2, s->m_key);
|
||||||
if (s->m_cmd->defaultKeySequence() != s->m_key) {
|
if (s->m_cmd->defaultKeySequence() != s->m_key)
|
||||||
QFont f = item->font(0);
|
setModified(item, true);
|
||||||
f.setItalic(true);
|
|
||||||
item->setFont(0, f);
|
|
||||||
item->setFont(1, f);
|
|
||||||
f.setBold(true);
|
|
||||||
item->setFont(2, f);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
item->setData(0, Qt::UserRole, qVariantFromValue(s));
|
item->setData(0, Qt::UserRole, qVariantFromValue(s));
|
||||||
}
|
}
|
||||||
@@ -360,3 +354,39 @@ int ShortcutSettings::translateModifiers(Qt::KeyboardModifiers state,
|
|||||||
result |= Qt::ALT;
|
result |= Qt::ALT;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void ShortcutSettings::markPossibleCollisions(ShortcutItem *item)
|
||||||
|
{
|
||||||
|
if (item->m_key.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
foreach (ShortcutItem *currentItem, m_scitems) {
|
||||||
|
|
||||||
|
if (currentItem->m_key.isEmpty() || item == currentItem ||
|
||||||
|
item->m_key != currentItem->m_key) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach(int context, currentItem->m_cmd->context()) {
|
||||||
|
|
||||||
|
// conflict if context is identical, OR if one
|
||||||
|
// of the contexts is the global context
|
||||||
|
if (item->m_cmd->context().contains(context) ||
|
||||||
|
(item->m_cmd->context().contains(Constants::C_GLOBAL_ID) &&
|
||||||
|
!currentItem->m_cmd->context().isEmpty()) ||
|
||||||
|
(currentItem->m_cmd->context().contains(Constants::C_GLOBAL_ID) &&
|
||||||
|
!item->m_cmd->context().isEmpty())) {
|
||||||
|
currentItem->m_item->setForeground(2, Qt::red);
|
||||||
|
item->m_item->setForeground(2, Qt::red);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShortcutSettings::resetCollisionMarkers()
|
||||||
|
{
|
||||||
|
foreach (ShortcutItem *item, m_scitems)
|
||||||
|
item->m_item->setForeground(2, commandList()->palette().foreground());
|
||||||
|
}
|
||||||
|
|||||||
@@ -92,6 +92,8 @@ private:
|
|||||||
|
|
||||||
void handleKeyEvent(QKeyEvent *e);
|
void handleKeyEvent(QKeyEvent *e);
|
||||||
int translateModifiers(Qt::KeyboardModifiers state, const QString &text);
|
int translateModifiers(Qt::KeyboardModifiers state, const QString &text);
|
||||||
|
void markPossibleCollisions(ShortcutItem *);
|
||||||
|
void resetCollisionMarkers();
|
||||||
|
|
||||||
QList<ShortcutItem *> m_scitems;
|
QList<ShortcutItem *> m_scitems;
|
||||||
int m_key[4], m_keyNum;
|
int m_key[4], m_keyNum;
|
||||||
|
|||||||
@@ -371,15 +371,8 @@ void FakeVimExCommandsPage::initialize()
|
|||||||
item->setText(2, ci->m_regex);
|
item->setText(2, ci->m_regex);
|
||||||
item->setData(0, Qt::UserRole, qVariantFromValue(ci));
|
item->setData(0, Qt::UserRole, qVariantFromValue(ci));
|
||||||
|
|
||||||
if (ci->m_regex != s_defaultExCommandMap[name].pattern()) {
|
if (ci->m_regex != s_defaultExCommandMap[name].pattern())
|
||||||
QFont f = item->font(0);
|
setModified(item, true);
|
||||||
f.setItalic(true);
|
|
||||||
item->setFont(0, f);
|
|
||||||
item->setFont(1, f);
|
|
||||||
f.setBold(true);
|
|
||||||
item->setFont(2, f);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
commandChanged(0);
|
commandChanged(0);
|
||||||
@@ -412,21 +405,10 @@ void FakeVimExCommandsPage::targetIdentifierChanged()
|
|||||||
s_exCommandMap[name] = QRegExp(citem->m_regex);
|
s_exCommandMap[name] = QRegExp(citem->m_regex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (citem->m_regex != s_defaultExCommandMap[name].pattern()) {
|
if (citem->m_regex != s_defaultExCommandMap[name].pattern())
|
||||||
QFont f = current->font(0);
|
setModified(current, true);
|
||||||
f.setItalic(true);
|
else
|
||||||
current->setFont(0, f);
|
setModified(current, false);
|
||||||
current->setFont(1, f);
|
|
||||||
f.setBold(true);
|
|
||||||
current->setFont(2, f);
|
|
||||||
} else {
|
|
||||||
QFont f = current->font(0);
|
|
||||||
f.setItalic(false);
|
|
||||||
f.setBold(false);
|
|
||||||
current->setFont(0, f);
|
|
||||||
current->setFont(1, f);
|
|
||||||
current->setFont(2, f);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -464,6 +446,7 @@ void FakeVimExCommandsPage::defaultAction()
|
|||||||
} else {
|
} else {
|
||||||
item->m_regex.clear();
|
item->m_regex.clear();
|
||||||
}
|
}
|
||||||
|
setModified(item->m_item, false);
|
||||||
item->m_item->setText(2, item->m_regex);
|
item->m_item->setText(2, item->m_regex);
|
||||||
if (item->m_item == commandList()->currentItem())
|
if (item->m_item == commandList()->currentItem())
|
||||||
commandChanged(item->m_item);
|
commandChanged(item->m_item);
|
||||||
|
|||||||
Reference in New Issue
Block a user