Commit 7e1f9d9f authored by Daniel Molkentin's avatar Daniel Molkentin
Browse files

Highlight colliding shortcuts for imported keyboard schemes.

parent 4dda4853
......@@ -238,6 +238,11 @@ QShortcut *CommandPrivate::shortcut() const
return 0;
}
QList<int> CommandPrivate::context() const
{
return m_context;
}
void CommandPrivate::setAttribute(CommandAttribute attr)
{
m_attributes |= attr;
......
......@@ -65,6 +65,7 @@ public:
virtual QAction *action() const = 0;
virtual QShortcut *shortcut() const = 0;
virtual QList<int> context() const = 0;
virtual void setAttribute(CommandAttribute attr) = 0;
virtual void removeAttribute(CommandAttribute attr) = 0;
......
......@@ -60,6 +60,8 @@ public:
QAction *action() const;
QShortcut *shortcut() const;
QList<int> context() const;
void setAttribute(CommandAttribute attr);
void removeAttribute(CommandAttribute attr);
......@@ -70,6 +72,7 @@ public:
QString stringWithAppendedShortcut(const QString &str) const;
protected:
QList<int> m_context;
QString m_category;
int m_attributes;
int m_id;
......@@ -101,7 +104,6 @@ public:
bool isActive() const;
private:
QList<int> m_context;
QShortcut *m_shortcut;
QString m_defaultText;
};
......@@ -140,7 +142,6 @@ private:
QString m_toolTip;
QPointer<QAction> m_currentAction;
QList<int> m_context;
QMap<int, QPointer<QAction> > m_contextActionMap;
bool m_active;
bool m_contextInitialized;
......
......@@ -191,3 +191,13 @@ bool CommandMappings::filter(const QString &f, const QTreeWidgetItem *item)
}
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 setTargetEditTitle(const QString &s);
void setTargetHeader(const QString &s);
void setModified(QTreeWidgetItem *item, bool modified);
virtual void markPossibleCollisions(QTreeWidgetItem *) {}
virtual void resetCollisionMarkers() {}
private:
Ui_CommandMappings *m_page;
};
......
......@@ -36,6 +36,7 @@
#include "filemanager.h"
#include "icore.h"
#include "uniqueidmanager.h"
#include <utils/treewidgetcolumnstretcher.h>
......@@ -121,7 +122,8 @@ void ShortcutSettings::finish()
bool ShortcutSettings::eventFilter(QObject *o, QEvent *e)
{
Q_UNUSED(o);
Q_UNUSED(o)
if ( e->type() == QEvent::KeyPress ) {
QKeyEvent *k = static_cast<QKeyEvent*>(e);
handleKeyEvent(k);
......@@ -157,22 +159,12 @@ void ShortcutSettings::targetIdentifierChanged()
if (current && current->data(0, Qt::UserRole).isValid()) {
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]);
if (scitem->m_cmd->defaultKeySequence() != scitem->m_key) {
QFont f = current->font(0);
f.setItalic(true);
current->setFont(0, f);
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);
}
if (scitem->m_cmd->defaultKeySequence() != scitem->m_key)
setModified(current, true);
else
setModified(current, false);
current->setText(2, scitem->m_key);
markPossibleCollisions(scitem);
}
}
......@@ -219,6 +211,13 @@ void ShortcutSettings::importAction()
item->m_item->setText(2, item->m_key);
if (item->m_item == commandList()->currentItem())
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) {
item->m_key = item->m_cmd->defaultKeySequence();
item->m_item->setText(2, item->m_key);
setModified(item->m_item, false);
if (item->m_item == commandList()->currentItem())
commandChanged(item->m_item);
resetCollisionMarkers();
}
}
......@@ -294,15 +295,8 @@ void ShortcutSettings::initialize()
}
item->setText(2, s->m_key);
if (s->m_cmd->defaultKeySequence() != s->m_key) {
QFont f = item->font(0);
f.setItalic(true);
item->setFont(0, f);
item->setFont(1, f);
f.setBold(true);
item->setFont(2, f);
}
if (s->m_cmd->defaultKeySequence() != s->m_key)
setModified(item, true);
item->setData(0, Qt::UserRole, qVariantFromValue(s));
}
......@@ -360,3 +354,39 @@ int ShortcutSettings::translateModifiers(Qt::KeyboardModifiers state,
result |= Qt::ALT;
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);
int translateModifiers(Qt::KeyboardModifiers state, const QString &text);
void markPossibleCollisions(ShortcutItem *);
void resetCollisionMarkers();
QList<ShortcutItem *> m_scitems;
int m_key[4], m_keyNum;
......
......@@ -371,15 +371,8 @@ void FakeVimExCommandsPage::initialize()
item->setText(2, ci->m_regex);
item->setData(0, Qt::UserRole, qVariantFromValue(ci));
if (ci->m_regex != s_defaultExCommandMap[name].pattern()) {
QFont f = item->font(0);
f.setItalic(true);
item->setFont(0, f);
item->setFont(1, f);
f.setBold(true);
item->setFont(2, f);
}
if (ci->m_regex != s_defaultExCommandMap[name].pattern())
setModified(item, true);
}
commandChanged(0);
......@@ -412,21 +405,10 @@ void FakeVimExCommandsPage::targetIdentifierChanged()
s_exCommandMap[name] = QRegExp(citem->m_regex);
}
if (citem->m_regex != s_defaultExCommandMap[name].pattern()) {
QFont f = current->font(0);
f.setItalic(true);
current->setFont(0, f);
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);
}
if (citem->m_regex != s_defaultExCommandMap[name].pattern())
setModified(current, true);
else
setModified(current, false);
}
......@@ -464,6 +446,7 @@ void FakeVimExCommandsPage::defaultAction()
} else {
item->m_regex.clear();
}
setModified(item->m_item, false);
item->m_item->setText(2, item->m_regex);
if (item->m_item == commandList()->currentItem())
commandChanged(item->m_item);
......
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