forked from qt-creator/qt-creator
Core: Mark shortcut conflicts in keyboard settings input box
Task-number: QTCREATORBUG-6 Change-Id: Ife1f97d24733814e7512dd8bc6584a1d72f66fa8 Reviewed-by: Christian Stenger <christian.stenger@digia.com> Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
@@ -28,142 +28,254 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "commandmappings.h"
|
#include "commandmappings.h"
|
||||||
#include "ui_commandmappings.h"
|
|
||||||
#include "commandsfile.h"
|
#include "commandsfile.h"
|
||||||
|
|
||||||
#include <coreplugin/dialogs/shortcutsettings.h>
|
#include <coreplugin/dialogs/shortcutsettings.h>
|
||||||
|
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/headerviewstretcher.h>
|
#include <utils/headerviewstretcher.h>
|
||||||
|
#include <utils/fancylineedit.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QTreeWidgetItem>
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QGroupBox>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QPointer>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QTreeWidgetItem>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(Core::Internal::ShortcutItem*)
|
Q_DECLARE_METATYPE(Core::Internal::ShortcutItem*)
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Utils;
|
||||||
using namespace Core::Internal;
|
|
||||||
|
namespace Core {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
class KeySequenceValidator : public FancyLineEdit
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
KeySequenceValidator(QWidget *parent, CommandMappings *mappings)
|
||||||
|
: FancyLineEdit(parent), m_mappings(mappings)
|
||||||
|
{}
|
||||||
|
|
||||||
|
bool validate(const QString &, QString *) const
|
||||||
|
{
|
||||||
|
return !m_mappings->hasConflicts();
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandMappings *m_mappings;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CommandMappingsPrivate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CommandMappingsPrivate(CommandMappings *parent)
|
||||||
|
: q(parent), m_widget(0)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void setupWidget()
|
||||||
|
{
|
||||||
|
QTC_CHECK(m_widget == 0);
|
||||||
|
m_widget = new QWidget;
|
||||||
|
|
||||||
|
groupBox = new QGroupBox(m_widget);
|
||||||
|
groupBox->setTitle(CommandMappings::tr("Command Mappings"));
|
||||||
|
|
||||||
|
filterEdit = new FancyLineEdit(groupBox);
|
||||||
|
filterEdit->setFiltering(true);
|
||||||
|
|
||||||
|
commandList = new QTreeWidget(groupBox);
|
||||||
|
commandList->setRootIsDecorated(false);
|
||||||
|
commandList->setUniformRowHeights(true);
|
||||||
|
commandList->setSortingEnabled(true);
|
||||||
|
commandList->setColumnCount(3);
|
||||||
|
|
||||||
|
QTreeWidgetItem *item = commandList->headerItem();
|
||||||
|
item->setText(2, CommandMappings::tr("Target"));
|
||||||
|
item->setText(1, CommandMappings::tr("Label"));
|
||||||
|
item->setText(0, CommandMappings::tr("Command"));
|
||||||
|
|
||||||
|
defaultButton = new QPushButton(CommandMappings::tr("Reset All"), groupBox);
|
||||||
|
defaultButton->setToolTip(CommandMappings::tr("Reset all to default"));
|
||||||
|
|
||||||
|
importButton = new QPushButton(CommandMappings::tr("Import..."), groupBox);
|
||||||
|
exportButton = new QPushButton(CommandMappings::tr("Export..."), groupBox);
|
||||||
|
|
||||||
|
targetEditGroup = new QGroupBox(CommandMappings::tr("Target Identifier"), m_widget);
|
||||||
|
|
||||||
|
targetEdit = new KeySequenceValidator(targetEditGroup, q);
|
||||||
|
targetEdit->setAutoHideButton(FancyLineEdit::Right, true);
|
||||||
|
targetEdit->setPlaceholderText(QString());
|
||||||
|
targetEdit->installEventFilter(q);
|
||||||
|
targetEdit->setFiltering(true);
|
||||||
|
|
||||||
|
resetButton = new QPushButton(targetEditGroup);
|
||||||
|
resetButton->setToolTip(CommandMappings::tr("Reset to default"));
|
||||||
|
resetButton->setText(CommandMappings::tr("Reset"));
|
||||||
|
|
||||||
|
QLabel *infoLabel = new QLabel(targetEditGroup);
|
||||||
|
infoLabel->setTextFormat(Qt::RichText);
|
||||||
|
|
||||||
|
QHBoxLayout *hboxLayout1 = new QHBoxLayout();
|
||||||
|
hboxLayout1->addWidget(defaultButton);
|
||||||
|
hboxLayout1->addStretch();
|
||||||
|
hboxLayout1->addWidget(importButton);
|
||||||
|
hboxLayout1->addWidget(exportButton);
|
||||||
|
|
||||||
|
QHBoxLayout *hboxLayout = new QHBoxLayout();
|
||||||
|
hboxLayout->addWidget(filterEdit);
|
||||||
|
|
||||||
|
QVBoxLayout *vboxLayout1 = new QVBoxLayout(groupBox);
|
||||||
|
vboxLayout1->addLayout(hboxLayout);
|
||||||
|
vboxLayout1->addWidget(commandList);
|
||||||
|
vboxLayout1->addLayout(hboxLayout1);
|
||||||
|
|
||||||
|
QHBoxLayout *hboxLayout2 = new QHBoxLayout();
|
||||||
|
hboxLayout2->addWidget(new QLabel(CommandMappings::tr("Target:"), targetEditGroup));
|
||||||
|
hboxLayout2->addWidget(targetEdit);
|
||||||
|
hboxLayout2->addWidget(resetButton);
|
||||||
|
|
||||||
|
QVBoxLayout *vboxLayout2 = new QVBoxLayout(targetEditGroup);
|
||||||
|
vboxLayout2->addLayout(hboxLayout2);
|
||||||
|
vboxLayout2->addWidget(infoLabel);
|
||||||
|
|
||||||
|
QVBoxLayout *vboxLayout = new QVBoxLayout(m_widget);
|
||||||
|
vboxLayout->addWidget(groupBox);
|
||||||
|
vboxLayout->addWidget(targetEditGroup);
|
||||||
|
|
||||||
|
q->connect(targetEdit, SIGNAL(buttonClicked(Utils::FancyLineEdit::Side)),
|
||||||
|
SLOT(removeTargetIdentifier()));
|
||||||
|
q->connect(resetButton, SIGNAL(clicked()),
|
||||||
|
SLOT(resetTargetIdentifier()));
|
||||||
|
q->connect(exportButton, SIGNAL(clicked()),
|
||||||
|
SLOT(exportAction()));
|
||||||
|
q->connect(importButton, SIGNAL(clicked()),
|
||||||
|
SLOT(importAction()));
|
||||||
|
q->connect(defaultButton, SIGNAL(clicked()),
|
||||||
|
SLOT(defaultAction()));
|
||||||
|
|
||||||
|
q->initialize();
|
||||||
|
|
||||||
|
commandList->sortByColumn(0, Qt::AscendingOrder);
|
||||||
|
|
||||||
|
q->connect(filterEdit, SIGNAL(textChanged(QString)),
|
||||||
|
SLOT(filterChanged(QString)));
|
||||||
|
q->connect(commandList, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
|
||||||
|
SLOT(commandChanged(QTreeWidgetItem*)));
|
||||||
|
q->connect(targetEdit, SIGNAL(textChanged(QString)),
|
||||||
|
SLOT(targetIdentifierChanged()));
|
||||||
|
|
||||||
|
new HeaderViewStretcher(commandList->header(), 1);
|
||||||
|
|
||||||
|
q->commandChanged(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandMappings *q;
|
||||||
|
QPointer<QWidget> m_widget;
|
||||||
|
|
||||||
|
QGroupBox *groupBox;
|
||||||
|
FancyLineEdit *filterEdit;
|
||||||
|
QTreeWidget *commandList;
|
||||||
|
QPushButton *defaultButton;
|
||||||
|
QPushButton *importButton;
|
||||||
|
QPushButton *exportButton;
|
||||||
|
QGroupBox *targetEditGroup;
|
||||||
|
FancyLineEdit *targetEdit;
|
||||||
|
QPushButton *resetButton;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
|
||||||
CommandMappings::CommandMappings(QObject *parent)
|
CommandMappings::CommandMappings(QObject *parent)
|
||||||
: IOptionsPage(parent), m_page(0)
|
: IOptionsPage(parent), d(new Internal::CommandMappingsPrivate(this))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// IOptionsPage
|
CommandMappings::~CommandMappings()
|
||||||
|
{
|
||||||
|
delete d;
|
||||||
|
}
|
||||||
|
|
||||||
QWidget *CommandMappings::widget()
|
QWidget *CommandMappings::widget()
|
||||||
{
|
{
|
||||||
if (!m_widget) {
|
if (!d->m_widget)
|
||||||
m_page = new Ui::CommandMappings();
|
d->setupWidget();
|
||||||
m_widget = new QWidget;
|
return d->m_widget;
|
||||||
m_page->setupUi(m_widget);
|
|
||||||
m_page->targetEdit->setAutoHideButton(Utils::FancyLineEdit::Right, true);
|
|
||||||
m_page->targetEdit->setPlaceholderText(QString());
|
|
||||||
m_page->targetEdit->installEventFilter(this);
|
|
||||||
m_page->targetEdit->setFiltering(true);
|
|
||||||
|
|
||||||
m_page->filterEdit->setFiltering(true);
|
|
||||||
|
|
||||||
connect(m_page->targetEdit, SIGNAL(buttonClicked(Utils::FancyLineEdit::Side)),
|
|
||||||
this, SLOT(removeTargetIdentifier()));
|
|
||||||
connect(m_page->resetButton, SIGNAL(clicked()),
|
|
||||||
this, SLOT(resetTargetIdentifier()));
|
|
||||||
connect(m_page->exportButton, SIGNAL(clicked()),
|
|
||||||
this, SLOT(exportAction()));
|
|
||||||
connect(m_page->importButton, SIGNAL(clicked()),
|
|
||||||
this, SLOT(importAction()));
|
|
||||||
connect(m_page->defaultButton, SIGNAL(clicked()),
|
|
||||||
this, SLOT(defaultAction()));
|
|
||||||
|
|
||||||
initialize();
|
|
||||||
|
|
||||||
m_page->commandList->sortByColumn(0, Qt::AscendingOrder);
|
|
||||||
|
|
||||||
connect(m_page->filterEdit, SIGNAL(textChanged(QString)),
|
|
||||||
this, SLOT(filterChanged(QString)));
|
|
||||||
connect(m_page->commandList, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
|
|
||||||
this, SLOT(commandChanged(QTreeWidgetItem*)));
|
|
||||||
connect(m_page->targetEdit, SIGNAL(textChanged(QString)),
|
|
||||||
this, SLOT(targetIdentifierChanged()));
|
|
||||||
|
|
||||||
new Utils::HeaderViewStretcher(m_page->commandList->header(), 1);
|
|
||||||
|
|
||||||
commandChanged(0);
|
|
||||||
}
|
|
||||||
return m_widget;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandMappings::setImportExportEnabled(bool enabled)
|
void CommandMappings::setImportExportEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
m_page->importButton->setVisible(enabled);
|
d->importButton->setVisible(enabled);
|
||||||
m_page->exportButton->setVisible(enabled);
|
d->exportButton->setVisible(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTreeWidget *CommandMappings::commandList() const
|
QTreeWidget *CommandMappings::commandList() const
|
||||||
{
|
{
|
||||||
return m_page->commandList;
|
return d->commandList;
|
||||||
}
|
}
|
||||||
|
|
||||||
QLineEdit *CommandMappings::targetEdit() const
|
QLineEdit *CommandMappings::targetEdit() const
|
||||||
{
|
{
|
||||||
return m_page->targetEdit;
|
return d->targetEdit;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandMappings::setPageTitle(const QString &s)
|
void CommandMappings::setPageTitle(const QString &s)
|
||||||
{
|
{
|
||||||
m_page->groupBox->setTitle(s);
|
d->groupBox->setTitle(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandMappings::setTargetLabelText(const QString &s)
|
void CommandMappings::setTargetLabelText(const QString &s)
|
||||||
{
|
{
|
||||||
m_page->targetEditLabel->setText(s);
|
d->targetEdit->setText(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandMappings::setTargetEditTitle(const QString &s)
|
void CommandMappings::setTargetEditTitle(const QString &s)
|
||||||
{
|
{
|
||||||
m_page->targetEditGroup->setTitle(s);
|
d->targetEditGroup->setTitle(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandMappings::setTargetHeader(const QString &s)
|
void CommandMappings::setTargetHeader(const QString &s)
|
||||||
{
|
{
|
||||||
m_page->commandList->setHeaderLabels(QStringList() << tr("Command") << tr("Label") << s);
|
d->commandList->setHeaderLabels(QStringList() << tr("Command") << tr("Label") << s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandMappings::finish()
|
void CommandMappings::finish()
|
||||||
{
|
{
|
||||||
delete m_widget;
|
delete d->m_widget;
|
||||||
if (!m_page) // page was never shown
|
|
||||||
return;
|
|
||||||
delete m_page;
|
|
||||||
m_page = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandMappings::commandChanged(QTreeWidgetItem *current)
|
void CommandMappings::commandChanged(QTreeWidgetItem *current)
|
||||||
{
|
{
|
||||||
if (!current || !current->data(0, Qt::UserRole).isValid()) {
|
if (!current || !current->data(0, Qt::UserRole).isValid()) {
|
||||||
m_page->targetEdit->setText(QString());
|
d->targetEdit->setText(QString());
|
||||||
m_page->targetEditGroup->setEnabled(false);
|
d->targetEditGroup->setEnabled(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_page->targetEditGroup->setEnabled(true);
|
d->targetEditGroup->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandMappings::filterChanged(const QString &f)
|
void CommandMappings::filterChanged(const QString &f)
|
||||||
{
|
{
|
||||||
if (!m_page)
|
for (int i = 0; i < d->commandList->topLevelItemCount(); ++i) {
|
||||||
return;
|
QTreeWidgetItem *item = d->commandList->topLevelItem(i);
|
||||||
for (int i=0; i<m_page->commandList->topLevelItemCount(); ++i) {
|
|
||||||
QTreeWidgetItem *item = m_page->commandList->topLevelItem(i);
|
|
||||||
filter(f, item);
|
filter(f, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CommandMappings::hasConflicts() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool CommandMappings::filter(const QString &filterString, QTreeWidgetItem *item)
|
bool CommandMappings::filter(const QString &filterString, QTreeWidgetItem *item)
|
||||||
{
|
{
|
||||||
bool visible = filterString.isEmpty();
|
bool visible = filterString.isEmpty();
|
||||||
int columnCount = item->columnCount();
|
int columnCount = item->columnCount();
|
||||||
for (int i = 0; !visible && i < columnCount; ++i) {
|
for (int i = 0; !visible && i < columnCount; ++i) {
|
||||||
QString text = item->text(i);
|
QString text = item->text(i);
|
||||||
if (Utils::HostOsInfo::isMacHost()) {
|
if (HostOsInfo::isMacHost()) {
|
||||||
// accept e.g. Cmd+E in the filter. the text shows special fancy characters for Cmd
|
// accept e.g. Cmd+E in the filter. the text shows special fancy characters for Cmd
|
||||||
if (i == columnCount - 1) {
|
if (i == columnCount - 1) {
|
||||||
QKeySequence key = QKeySequence::fromString(text, QKeySequence::NativeText);
|
QKeySequence key = QKeySequence::fromString(text, QKeySequence::NativeText);
|
||||||
@@ -203,7 +315,7 @@ void CommandMappings::setModified(QTreeWidgetItem *item , bool modified)
|
|||||||
|
|
||||||
QString CommandMappings::filterText() const
|
QString CommandMappings::filterText() const
|
||||||
{
|
{
|
||||||
if (!m_page)
|
return d->filterEdit ? d->filterEdit->text() : QString();
|
||||||
return QString();
|
|
||||||
return m_page->filterEdit->text();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Core
|
||||||
|
|||||||
@@ -33,7 +33,6 @@
|
|||||||
#include <coreplugin/dialogs/ioptionspage.h>
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QPointer>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
@@ -41,9 +40,11 @@ class QTreeWidget;
|
|||||||
class QTreeWidgetItem;
|
class QTreeWidgetItem;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
namespace Utils { class FancyLineEdit; }
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
namespace Internal { namespace Ui { class CommandMappings; } }
|
namespace Internal { class CommandMappingsPrivate; }
|
||||||
|
|
||||||
class CORE_EXPORT CommandMappings : public Core::IOptionsPage
|
class CORE_EXPORT CommandMappings : public Core::IOptionsPage
|
||||||
{
|
{
|
||||||
@@ -51,6 +52,8 @@ class CORE_EXPORT CommandMappings : public Core::IOptionsPage
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
CommandMappings(QObject *parent = 0);
|
CommandMappings(QObject *parent = 0);
|
||||||
|
~CommandMappings();
|
||||||
|
virtual bool hasConflicts() const;
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void commandChanged(QTreeWidgetItem *current);
|
void commandChanged(QTreeWidgetItem *current);
|
||||||
@@ -78,11 +81,10 @@ protected:
|
|||||||
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);
|
void setModified(QTreeWidgetItem *item, bool modified);
|
||||||
virtual void markPossibleCollisions(QTreeWidgetItem *) {}
|
|
||||||
virtual void resetCollisionMarkers() {}
|
|
||||||
private:
|
private:
|
||||||
QPointer<QWidget> m_widget;
|
friend class Internal::CommandMappingsPrivate;
|
||||||
Internal::Ui::CommandMappings *m_page;
|
Internal::CommandMappingsPrivate *d;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
|||||||
@@ -1,165 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>Core::Internal::CommandMappings</class>
|
|
||||||
<widget class="QWidget" name="Core::Internal::CommandMappings">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>568</width>
|
|
||||||
<height>451</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="QGroupBox" name="groupBox">
|
|
||||||
<property name="title">
|
|
||||||
<string>Command Mappings</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout">
|
|
||||||
<item>
|
|
||||||
<layout class="QHBoxLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="Utils::FancyLineEdit" name="filterEdit"/>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QTreeWidget" name="commandList">
|
|
||||||
<property name="rootIsDecorated">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="uniformRowHeights">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="sortingEnabled">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="columnCount">
|
|
||||||
<number>3</number>
|
|
||||||
</property>
|
|
||||||
<column>
|
|
||||||
<property name="text">
|
|
||||||
<string>Command</string>
|
|
||||||
</property>
|
|
||||||
</column>
|
|
||||||
<column>
|
|
||||||
<property name="text">
|
|
||||||
<string>Label</string>
|
|
||||||
</property>
|
|
||||||
</column>
|
|
||||||
<column>
|
|
||||||
<property name="text">
|
|
||||||
<string>Target</string>
|
|
||||||
</property>
|
|
||||||
</column>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<layout class="QHBoxLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="defaultButton">
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Reset all to default</string>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Reset All</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer>
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="importButton">
|
|
||||||
<property name="text">
|
|
||||||
<string>Import...</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="exportButton">
|
|
||||||
<property name="text">
|
|
||||||
<string>Export...</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QGroupBox" name="targetEditGroup">
|
|
||||||
<property name="title">
|
|
||||||
<string>Target Identifier</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout">
|
|
||||||
<item>
|
|
||||||
<layout class="QHBoxLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="targetEditLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>Target:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="Utils::FancyLineEdit" name="targetEdit"/>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="resetButton">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Reset to default</string>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Reset</string>
|
|
||||||
</property>
|
|
||||||
<property name="iconSize">
|
|
||||||
<size>
|
|
||||||
<width>16</width>
|
|
||||||
<height>16</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="infoLabel">
|
|
||||||
<property name="textFormat">
|
|
||||||
<enum>Qt::RichText</enum>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<customwidgets>
|
|
||||||
<customwidget>
|
|
||||||
<class>Utils::FancyLineEdit</class>
|
|
||||||
<extends>QLineEdit</extends>
|
|
||||||
<header location="global">utils/fancylineedit.h</header>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
|
||||||
<resources/>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
||||||
@@ -197,7 +197,6 @@ HEADERS += mainwindow.h \
|
|||||||
dialogs/addtovcsdialog.h
|
dialogs/addtovcsdialog.h
|
||||||
|
|
||||||
FORMS += dialogs/newdialog.ui \
|
FORMS += dialogs/newdialog.ui \
|
||||||
actionmanager/commandmappings.ui \
|
|
||||||
dialogs/saveitemsdialog.ui \
|
dialogs/saveitemsdialog.ui \
|
||||||
dialogs/readonlyfilesdialog.ui \
|
dialogs/readonlyfilesdialog.ui \
|
||||||
dialogs/openwithdialog.ui \
|
dialogs/openwithdialog.ui \
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ QtcPlugin {
|
|||||||
"actionmanager.cpp", "actionmanager.h", "actionmanager_p.h",
|
"actionmanager.cpp", "actionmanager.h", "actionmanager_p.h",
|
||||||
"command.cpp", "command.h", "command_p.h",
|
"command.cpp", "command.h", "command_p.h",
|
||||||
"commandbutton.cpp", "commandbutton.h",
|
"commandbutton.cpp", "commandbutton.h",
|
||||||
"commandmappings.cpp", "commandmappings.h", "commandmappings.ui",
|
"commandmappings.cpp", "commandmappings.h",
|
||||||
"commandsfile.cpp", "commandsfile.h",
|
"commandsfile.cpp", "commandsfile.h",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,8 @@
|
|||||||
#include <coreplugin/actionmanager/command_p.h>
|
#include <coreplugin/actionmanager/command_p.h>
|
||||||
#include <coreplugin/actionmanager/commandsfile.h>
|
#include <coreplugin/actionmanager/commandsfile.h>
|
||||||
|
|
||||||
|
#include <utils/fancylineedit.h>
|
||||||
|
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
@@ -127,6 +129,7 @@ void ShortcutSettings::commandChanged(QTreeWidgetItem *current)
|
|||||||
return;
|
return;
|
||||||
ShortcutItem *scitem = qvariant_cast<ShortcutItem *>(current->data(0, Qt::UserRole));
|
ShortcutItem *scitem = qvariant_cast<ShortcutItem *>(current->data(0, Qt::UserRole));
|
||||||
setKeySequence(scitem->m_key);
|
setKeySequence(scitem->m_key);
|
||||||
|
markCollisions(scitem);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShortcutSettings::targetIdentifierChanged()
|
void ShortcutSettings::targetIdentifierChanged()
|
||||||
@@ -140,11 +143,47 @@ void ShortcutSettings::targetIdentifierChanged()
|
|||||||
else
|
else
|
||||||
setModified(current, false);
|
setModified(current, false);
|
||||||
current->setText(2, scitem->m_key.toString(QKeySequence::NativeText));
|
current->setText(2, scitem->m_key.toString(QKeySequence::NativeText));
|
||||||
resetCollisionMarker(scitem);
|
markCollisions(scitem);
|
||||||
markPossibleCollisions(scitem);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ShortcutSettings::hasConflicts() const
|
||||||
|
{
|
||||||
|
QTreeWidgetItem *current = commandList()->currentItem();
|
||||||
|
if (!current || !current->data(0, Qt::UserRole).isValid())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ShortcutItem *item = qvariant_cast<ShortcutItem *>(current->data(0, Qt::UserRole));
|
||||||
|
if (!item)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const QKeySequence currentKey = QKeySequence::fromString(targetEdit()->text(), QKeySequence::NativeText);
|
||||||
|
if (currentKey.isEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const Id globalId(Constants::C_GLOBAL);
|
||||||
|
const Context itemContext = item->m_cmd->context();
|
||||||
|
|
||||||
|
foreach (ShortcutItem *listItem, m_scitems) {
|
||||||
|
if (item == listItem)
|
||||||
|
continue;
|
||||||
|
if (listItem->m_key.isEmpty())
|
||||||
|
continue;
|
||||||
|
if (listItem->m_key.matches(currentKey) == QKeySequence::NoMatch)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const Context listContext = listItem->m_cmd->context();
|
||||||
|
if (itemContext.contains(globalId) && !listContext.isEmpty())
|
||||||
|
return true;
|
||||||
|
if (listContext.contains(globalId) && !itemContext.isEmpty())
|
||||||
|
return true;
|
||||||
|
foreach (Id id, listContext)
|
||||||
|
if (itemContext.contains(id))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void ShortcutSettings::setKeySequence(const QKeySequence &key)
|
void ShortcutSettings::setKeySequence(const QKeySequence &key)
|
||||||
{
|
{
|
||||||
m_key[0] = m_key[1] = m_key[2] = m_key[3] = 0;
|
m_key[0] = m_key[1] = m_key[2] = m_key[3] = 0;
|
||||||
@@ -168,6 +207,9 @@ void ShortcutSettings::removeTargetIdentifier()
|
|||||||
{
|
{
|
||||||
m_keyNum = m_key[0] = m_key[1] = m_key[2] = m_key[3] = 0;
|
m_keyNum = m_key[0] = m_key[1] = m_key[2] = m_key[3] = 0;
|
||||||
targetEdit()->clear();
|
targetEdit()->clear();
|
||||||
|
|
||||||
|
foreach (ShortcutItem *item, m_scitems)
|
||||||
|
markCollisions(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShortcutSettings::importAction()
|
void ShortcutSettings::importAction()
|
||||||
@@ -195,10 +237,8 @@ void ShortcutSettings::importAction()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (ShortcutItem *item, m_scitems) {
|
foreach (ShortcutItem *item, m_scitems)
|
||||||
resetCollisionMarker(item);
|
markCollisions(item);
|
||||||
markPossibleCollisions(item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,10 +252,8 @@ void ShortcutSettings::defaultAction()
|
|||||||
commandChanged(item->m_item);
|
commandChanged(item->m_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (ShortcutItem *item, m_scitems) {
|
foreach (ShortcutItem *item, m_scitems)
|
||||||
resetCollisionMarker(item);
|
markCollisions(item);
|
||||||
markPossibleCollisions(item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShortcutSettings::exportAction()
|
void ShortcutSettings::exportAction()
|
||||||
@@ -247,7 +285,7 @@ void ShortcutSettings::initialize()
|
|||||||
clear();
|
clear();
|
||||||
QMap<QString, QTreeWidgetItem *> sections;
|
QMap<QString, QTreeWidgetItem *> sections;
|
||||||
|
|
||||||
foreach (Command *c, ActionManager::instance()->commands()) {
|
foreach (Command *c, ActionManager::commands()) {
|
||||||
if (c->hasAttribute(Command::CA_NonConfigurable))
|
if (c->hasAttribute(Command::CA_NonConfigurable))
|
||||||
continue;
|
continue;
|
||||||
if (c->action() && c->action()->isSeparator())
|
if (c->action() && c->action()->isSeparator())
|
||||||
@@ -283,7 +321,7 @@ void ShortcutSettings::initialize()
|
|||||||
|
|
||||||
item->setData(0, Qt::UserRole, qVariantFromValue(s));
|
item->setData(0, Qt::UserRole, qVariantFromValue(s));
|
||||||
|
|
||||||
markPossibleCollisions(s);
|
markCollisions(s);
|
||||||
}
|
}
|
||||||
filterChanged(filterText());
|
filterChanged(filterText());
|
||||||
}
|
}
|
||||||
@@ -341,44 +379,32 @@ int ShortcutSettings::translateModifiers(Qt::KeyboardModifiers state,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShortcutSettings::markPossibleCollisions(ShortcutItem *item)
|
void ShortcutSettings::markCollisions(ShortcutItem *item)
|
||||||
{
|
{
|
||||||
if (item->m_key.isEmpty())
|
bool hasCollision = false;
|
||||||
return;
|
if (!item->m_key.isEmpty()) {
|
||||||
|
|
||||||
Id globalId = Context(Constants::C_GLOBAL).at(0);
|
Id globalId = Context(Constants::C_GLOBAL).at(0);
|
||||||
|
const Context itemContext = item->m_cmd->context();
|
||||||
|
|
||||||
foreach (ShortcutItem *currentItem, m_scitems) {
|
foreach (ShortcutItem *currentItem, m_scitems) {
|
||||||
|
|
||||||
if (currentItem->m_key.isEmpty() || item == currentItem ||
|
if (currentItem->m_key.isEmpty() || item == currentItem
|
||||||
item->m_key != currentItem->m_key) {
|
|| item->m_key != currentItem->m_key)
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
foreach (Id id, currentItem->m_cmd->context()) {
|
foreach (Id id, currentItem->m_cmd->context()) {
|
||||||
// conflict if context is identical, OR if one
|
// conflict if context is identical, OR if one
|
||||||
// of the contexts is the global context
|
// of the contexts is the global context
|
||||||
if (item->m_cmd->context().contains(id) ||
|
const Context thisContext = currentItem->m_cmd->context();
|
||||||
(item->m_cmd->context().contains(globalId) &&
|
if (itemContext.contains(id)
|
||||||
!currentItem->m_cmd->context().isEmpty()) ||
|
|| (itemContext.contains(globalId) && !thisContext.isEmpty())
|
||||||
(currentItem->m_cmd->context().contains(globalId) &&
|
|| (thisContext.contains(globalId) && !itemContext.isEmpty())) {
|
||||||
!item->m_cmd->context().isEmpty())) {
|
|
||||||
currentItem->m_item->setForeground(2, Qt::red);
|
currentItem->m_item->setForeground(2, Qt::red);
|
||||||
item->m_item->setForeground(2, Qt::red);
|
hasCollision = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
item->m_item->setForeground(2, hasCollision ? Qt::red : commandList()->palette().foreground());
|
||||||
|
}
|
||||||
|
|
||||||
void ShortcutSettings::resetCollisionMarker(ShortcutItem *item)
|
|
||||||
{
|
|
||||||
item->m_item->setForeground(2, commandList()->palette().foreground());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ShortcutSettings::resetCollisionMarkers()
|
|
||||||
{
|
|
||||||
foreach (ShortcutItem *item, m_scitems)
|
|
||||||
resetCollisionMarker(item);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -85,10 +85,9 @@ 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);
|
||||||
using Core::CommandMappings::markPossibleCollisions;
|
|
||||||
void markPossibleCollisions(ShortcutItem *);
|
void markCollisions(ShortcutItem *);
|
||||||
void resetCollisionMarker(ShortcutItem *);
|
bool hasConflicts() const;
|
||||||
void resetCollisionMarkers();
|
|
||||||
|
|
||||||
QList<ShortcutItem *> m_scitems;
|
QList<ShortcutItem *> m_scitems;
|
||||||
int m_key[4], m_keyNum;
|
int m_key[4], m_keyNum;
|
||||||
|
|||||||
Reference in New Issue
Block a user