forked from qt-creator/qt-creator
Refactor CommandMappings to be a widget instead of options page
The IOptionsPage parts in it were trivial, and we need more flexibility for the shortcut settings options pages. Change-Id: I93ddaf060ac88ef339da9f542719f2d695660ac0 Reviewed-by: hjk <hjk@theqtcompany.com>
This commit is contained in:
@@ -58,15 +58,9 @@ class CommandMappingsPrivate
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CommandMappingsPrivate(CommandMappings *parent)
|
CommandMappingsPrivate(CommandMappings *parent)
|
||||||
: q(parent), m_widget(0)
|
: q(parent)
|
||||||
{}
|
|
||||||
|
|
||||||
void setupWidget()
|
|
||||||
{
|
{
|
||||||
QTC_CHECK(m_widget == 0);
|
groupBox = new QGroupBox(parent);
|
||||||
m_widget = new QWidget;
|
|
||||||
|
|
||||||
groupBox = new QGroupBox(m_widget);
|
|
||||||
groupBox->setTitle(CommandMappings::tr("Command Mappings"));
|
groupBox->setTitle(CommandMappings::tr("Command Mappings"));
|
||||||
|
|
||||||
filterEdit = new FancyLineEdit(groupBox);
|
filterEdit = new FancyLineEdit(groupBox);
|
||||||
@@ -89,12 +83,12 @@ public:
|
|||||||
importButton = new QPushButton(CommandMappings::tr("Import..."), groupBox);
|
importButton = new QPushButton(CommandMappings::tr("Import..."), groupBox);
|
||||||
exportButton = new QPushButton(CommandMappings::tr("Export..."), groupBox);
|
exportButton = new QPushButton(CommandMappings::tr("Export..."), groupBox);
|
||||||
|
|
||||||
targetEditGroup = new QGroupBox(CommandMappings::tr("Target Identifier"), m_widget);
|
targetEditGroup = new QGroupBox(CommandMappings::tr("Target Identifier"), parent);
|
||||||
|
targetEditGroup->setEnabled(false);
|
||||||
|
|
||||||
targetEdit = new FancyLineEdit(targetEditGroup);
|
targetEdit = new FancyLineEdit(targetEditGroup);
|
||||||
targetEdit->setAutoHideButton(FancyLineEdit::Right, true);
|
targetEdit->setAutoHideButton(FancyLineEdit::Right, true);
|
||||||
targetEdit->setPlaceholderText(QString());
|
targetEdit->setPlaceholderText(QString());
|
||||||
targetEdit->installEventFilter(q);
|
|
||||||
targetEdit->setFiltering(true);
|
targetEdit->setFiltering(true);
|
||||||
targetEdit->setValidationFunction([this](FancyLineEdit *, QString *) {
|
targetEdit->setValidationFunction([this](FancyLineEdit *, QString *) {
|
||||||
return !q->hasConflicts();
|
return !q->hasConflicts();
|
||||||
@@ -121,8 +115,10 @@ public:
|
|||||||
vboxLayout1->addWidget(commandList);
|
vboxLayout1->addWidget(commandList);
|
||||||
vboxLayout1->addLayout(hboxLayout1);
|
vboxLayout1->addLayout(hboxLayout1);
|
||||||
|
|
||||||
|
targetLabel = new QLabel(CommandMappings::tr("Target:"));
|
||||||
|
|
||||||
QHBoxLayout *hboxLayout2 = new QHBoxLayout();
|
QHBoxLayout *hboxLayout2 = new QHBoxLayout();
|
||||||
hboxLayout2->addWidget(new QLabel(CommandMappings::tr("Target:"), targetEditGroup));
|
hboxLayout2->addWidget(targetLabel);
|
||||||
hboxLayout2->addWidget(targetEdit);
|
hboxLayout2->addWidget(targetEdit);
|
||||||
hboxLayout2->addWidget(resetButton);
|
hboxLayout2->addWidget(resetButton);
|
||||||
|
|
||||||
@@ -130,39 +126,34 @@ public:
|
|||||||
vboxLayout2->addLayout(hboxLayout2);
|
vboxLayout2->addLayout(hboxLayout2);
|
||||||
vboxLayout2->addWidget(infoLabel);
|
vboxLayout2->addWidget(infoLabel);
|
||||||
|
|
||||||
QVBoxLayout *vboxLayout = new QVBoxLayout(m_widget);
|
QVBoxLayout *vboxLayout = new QVBoxLayout(parent);
|
||||||
vboxLayout->addWidget(groupBox);
|
vboxLayout->addWidget(groupBox);
|
||||||
vboxLayout->addWidget(targetEditGroup);
|
vboxLayout->addWidget(targetEditGroup);
|
||||||
|
|
||||||
q->connect(targetEdit, SIGNAL(buttonClicked(Utils::FancyLineEdit::Side)),
|
q->connect(targetEdit, &FancyLineEdit::buttonClicked,
|
||||||
SLOT(removeTargetIdentifier()));
|
q, &CommandMappings::removeTargetIdentifier);
|
||||||
q->connect(resetButton, SIGNAL(clicked()),
|
q->connect(resetButton, &QPushButton::clicked,
|
||||||
SLOT(resetTargetIdentifier()));
|
q, &CommandMappings::resetTargetIdentifier);
|
||||||
q->connect(exportButton, SIGNAL(clicked()),
|
q->connect(exportButton, &QPushButton::clicked,
|
||||||
SLOT(exportAction()));
|
q, &CommandMappings::exportAction);
|
||||||
q->connect(importButton, SIGNAL(clicked()),
|
q->connect(importButton, &QPushButton::clicked,
|
||||||
SLOT(importAction()));
|
q, &CommandMappings::importAction);
|
||||||
q->connect(defaultButton, SIGNAL(clicked()),
|
q->connect(defaultButton, &QPushButton::clicked,
|
||||||
SLOT(defaultAction()));
|
q, &CommandMappings::defaultAction);
|
||||||
|
|
||||||
q->initialize();
|
|
||||||
|
|
||||||
commandList->sortByColumn(0, Qt::AscendingOrder);
|
commandList->sortByColumn(0, Qt::AscendingOrder);
|
||||||
|
|
||||||
q->connect(filterEdit, SIGNAL(textChanged(QString)),
|
q->connect(filterEdit, &FancyLineEdit::textChanged,
|
||||||
SLOT(filterChanged(QString)));
|
q, &CommandMappings::filterChanged);
|
||||||
q->connect(commandList, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
|
q->connect(commandList, &QTreeWidget::currentItemChanged,
|
||||||
SLOT(commandChanged(QTreeWidgetItem*)));
|
q, &CommandMappings::commandChanged);
|
||||||
q->connect(targetEdit, SIGNAL(textChanged(QString)),
|
q->connect(targetEdit, &FancyLineEdit::textChanged,
|
||||||
SLOT(targetIdentifierChanged()));
|
q, &CommandMappings::targetIdentifierChanged);
|
||||||
|
|
||||||
new HeaderViewStretcher(commandList->header(), 1);
|
new HeaderViewStretcher(commandList->header(), 1);
|
||||||
|
|
||||||
q->commandChanged(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandMappings *q;
|
CommandMappings *q;
|
||||||
QPointer<QWidget> m_widget;
|
|
||||||
|
|
||||||
QGroupBox *groupBox;
|
QGroupBox *groupBox;
|
||||||
FancyLineEdit *filterEdit;
|
FancyLineEdit *filterEdit;
|
||||||
@@ -171,14 +162,15 @@ public:
|
|||||||
QPushButton *importButton;
|
QPushButton *importButton;
|
||||||
QPushButton *exportButton;
|
QPushButton *exportButton;
|
||||||
QGroupBox *targetEditGroup;
|
QGroupBox *targetEditGroup;
|
||||||
|
QLabel *targetLabel;
|
||||||
FancyLineEdit *targetEdit;
|
FancyLineEdit *targetEdit;
|
||||||
QPushButton *resetButton;
|
QPushButton *resetButton;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|
||||||
CommandMappings::CommandMappings(QObject *parent)
|
CommandMappings::CommandMappings(QWidget *parent)
|
||||||
: IOptionsPage(parent), d(new Internal::CommandMappingsPrivate(this))
|
: QWidget(parent), d(new Internal::CommandMappingsPrivate(this))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,13 +179,6 @@ CommandMappings::~CommandMappings()
|
|||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *CommandMappings::widget()
|
|
||||||
{
|
|
||||||
if (!d->m_widget)
|
|
||||||
d->setupWidget();
|
|
||||||
return d->m_widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommandMappings::setImportExportEnabled(bool enabled)
|
void CommandMappings::setImportExportEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
d->importButton->setVisible(enabled);
|
d->importButton->setVisible(enabled);
|
||||||
@@ -217,7 +202,7 @@ void CommandMappings::setPageTitle(const QString &s)
|
|||||||
|
|
||||||
void CommandMappings::setTargetLabelText(const QString &s)
|
void CommandMappings::setTargetLabelText(const QString &s)
|
||||||
{
|
{
|
||||||
d->targetEdit->setText(s);
|
d->targetLabel->setText(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandMappings::setTargetEditTitle(const QString &s)
|
void CommandMappings::setTargetEditTitle(const QString &s)
|
||||||
@@ -230,11 +215,6 @@ void CommandMappings::setTargetHeader(const QString &s)
|
|||||||
d->commandList->setHeaderLabels(QStringList() << tr("Command") << tr("Label") << s);
|
d->commandList->setHeaderLabels(QStringList() << tr("Command") << tr("Label") << s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandMappings::finish()
|
|
||||||
{
|
|
||||||
delete d->m_widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
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()) {
|
||||||
|
|||||||
@@ -31,7 +31,9 @@
|
|||||||
#ifndef COMMANDMAPPINGS_H
|
#ifndef COMMANDMAPPINGS_H
|
||||||
#define COMMANDMAPPINGS_H
|
#define COMMANDMAPPINGS_H
|
||||||
|
|
||||||
#include <coreplugin/dialogs/ioptionspage.h>
|
#include <coreplugin/core_global.h>
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
@@ -45,31 +47,32 @@ namespace Core {
|
|||||||
|
|
||||||
namespace Internal { class CommandMappingsPrivate; }
|
namespace Internal { class CommandMappingsPrivate; }
|
||||||
|
|
||||||
class CORE_EXPORT CommandMappings : public IOptionsPage
|
class CORE_EXPORT CommandMappings : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CommandMappings(QObject *parent = 0);
|
CommandMappings(QWidget *parent = 0);
|
||||||
~CommandMappings();
|
~CommandMappings();
|
||||||
virtual bool hasConflicts() const;
|
virtual bool hasConflicts() const;
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void commandChanged(QTreeWidgetItem *current);
|
|
||||||
void filterChanged(const QString &f);
|
|
||||||
virtual void importAction() {}
|
|
||||||
virtual void exportAction() {}
|
|
||||||
virtual void defaultAction() = 0;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// IOptionsPage
|
virtual void removeTargetIdentifier() = 0;
|
||||||
QWidget *widget();
|
virtual void resetTargetIdentifier() = 0;
|
||||||
virtual void apply() {}
|
virtual void targetIdentifierChanged() = 0;
|
||||||
virtual void finish();
|
|
||||||
|
|
||||||
virtual void initialize() = 0;
|
virtual void defaultAction() = 0;
|
||||||
|
|
||||||
|
virtual void exportAction() {}
|
||||||
|
virtual void importAction() {}
|
||||||
|
|
||||||
|
void filterChanged(const QString &f);
|
||||||
bool filter(const QString &filterString, QTreeWidgetItem *item);
|
bool filter(const QString &filterString, QTreeWidgetItem *item);
|
||||||
|
|
||||||
|
virtual void commandChanged(QTreeWidgetItem *current);
|
||||||
|
|
||||||
// access to m_page
|
// access to m_page
|
||||||
void setImportExportEnabled(bool enabled);
|
void setImportExportEnabled(bool enabled);
|
||||||
QTreeWidget *commandList() const;
|
QTreeWidget *commandList() const;
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
#include <coreplugin/actionmanager/commandsfile.h>
|
#include <coreplugin/actionmanager/commandsfile.h>
|
||||||
|
|
||||||
#include <utils/fancylineedit.h>
|
#include <utils/fancylineedit.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
@@ -49,14 +50,54 @@
|
|||||||
|
|
||||||
Q_DECLARE_METATYPE(Core::Internal::ShortcutItem*)
|
Q_DECLARE_METATYPE(Core::Internal::ShortcutItem*)
|
||||||
|
|
||||||
|
static int translateModifiers(Qt::KeyboardModifiers state,
|
||||||
|
const QString &text)
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
// The shift modifier only counts when it is not used to type a symbol
|
||||||
|
// that is only reachable using the shift key anyway
|
||||||
|
if ((state & Qt::ShiftModifier) && (text.size() == 0
|
||||||
|
|| !text.at(0).isPrint()
|
||||||
|
|| text.at(0).isLetterOrNumber()
|
||||||
|
|| text.at(0).isSpace()))
|
||||||
|
result |= Qt::SHIFT;
|
||||||
|
if (state & Qt::ControlModifier)
|
||||||
|
result |= Qt::CTRL;
|
||||||
|
if (state & Qt::MetaModifier)
|
||||||
|
result |= Qt::META;
|
||||||
|
if (state & Qt::AltModifier)
|
||||||
|
result |= Qt::ALT;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
ShortcutSettings::ShortcutSettings(QObject *parent)
|
ShortcutSettingsWidget::ShortcutSettingsWidget(QWidget *parent)
|
||||||
: CommandMappings(parent), m_initialized(false)
|
: CommandMappings(parent)
|
||||||
{
|
{
|
||||||
connect(ActionManager::instance(), SIGNAL(commandListChanged()), this, SLOT(initialize()));
|
setPageTitle(tr("Keyboard Shortcuts"));
|
||||||
|
setTargetLabelText(tr("Key sequence:"));
|
||||||
|
setTargetEditTitle(tr("Shortcut"));
|
||||||
|
setTargetHeader(tr("Shortcut"));
|
||||||
|
targetEdit()->setPlaceholderText(tr("Type to set shortcut"));
|
||||||
|
|
||||||
|
m_keyNum = m_key[0] = m_key[1] = m_key[2] = m_key[3] = 0;
|
||||||
|
|
||||||
|
connect(ActionManager::instance(), &ActionManager::commandListChanged,
|
||||||
|
this, &ShortcutSettingsWidget::initialize);
|
||||||
|
targetEdit()->installEventFilter(this);
|
||||||
|
initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
ShortcutSettingsWidget::~ShortcutSettingsWidget()
|
||||||
|
{
|
||||||
|
qDeleteAll(m_scitems);
|
||||||
|
}
|
||||||
|
|
||||||
|
ShortcutSettings::ShortcutSettings(QObject *parent)
|
||||||
|
: IOptionsPage(parent)
|
||||||
|
{
|
||||||
setId(Constants::SETTINGS_ID_SHORTCUTS);
|
setId(Constants::SETTINGS_ID_SHORTCUTS);
|
||||||
setDisplayName(tr("Keyboard"));
|
setDisplayName(tr("Keyboard"));
|
||||||
setCategory(Constants::SETTINGS_CATEGORY_CORE);
|
setCategory(Constants::SETTINGS_CATEGORY_CORE);
|
||||||
@@ -66,40 +107,29 @@ ShortcutSettings::ShortcutSettings(QObject *parent)
|
|||||||
|
|
||||||
QWidget *ShortcutSettings::widget()
|
QWidget *ShortcutSettings::widget()
|
||||||
{
|
{
|
||||||
m_initialized = true;
|
if (!m_widget)
|
||||||
m_keyNum = m_key[0] = m_key[1] = m_key[2] = m_key[3] = 0;
|
m_widget = new ShortcutSettingsWidget();
|
||||||
|
return m_widget;
|
||||||
QWidget *w = CommandMappings::widget();
|
|
||||||
|
|
||||||
const QString pageTitle = tr("Keyboard Shortcuts");
|
|
||||||
const QString targetLabelText = tr("Key sequence:");
|
|
||||||
const QString editTitle = tr("Shortcut");
|
|
||||||
|
|
||||||
setPageTitle(pageTitle);
|
|
||||||
setTargetLabelText(targetLabelText);
|
|
||||||
setTargetEditTitle(editTitle);
|
|
||||||
setTargetHeader(editTitle);
|
|
||||||
targetEdit()->setPlaceholderText(tr("Type to set shortcut"));
|
|
||||||
|
|
||||||
return w;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShortcutSettings::apply()
|
void ShortcutSettingsWidget::apply()
|
||||||
{
|
{
|
||||||
foreach (ShortcutItem *item, m_scitems)
|
foreach (ShortcutItem *item, m_scitems)
|
||||||
item->m_cmd->setKeySequence(item->m_key);
|
item->m_cmd->setKeySequence(item->m_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShortcutSettings::finish()
|
void ShortcutSettings::apply()
|
||||||
{
|
{
|
||||||
qDeleteAll(m_scitems);
|
QTC_ASSERT(m_widget, return);
|
||||||
m_scitems.clear();
|
m_widget->apply();
|
||||||
|
|
||||||
CommandMappings::finish();
|
|
||||||
m_initialized = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShortcutSettings::eventFilter(QObject *o, QEvent *e)
|
void ShortcutSettings::finish()
|
||||||
|
{
|
||||||
|
delete m_widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ShortcutSettingsWidget::eventFilter(QObject *o, QEvent *e)
|
||||||
{
|
{
|
||||||
Q_UNUSED(o)
|
Q_UNUSED(o)
|
||||||
|
|
||||||
@@ -123,7 +153,7 @@ bool ShortcutSettings::eventFilter(QObject *o, QEvent *e)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShortcutSettings::commandChanged(QTreeWidgetItem *current)
|
void ShortcutSettingsWidget::commandChanged(QTreeWidgetItem *current)
|
||||||
{
|
{
|
||||||
CommandMappings::commandChanged(current);
|
CommandMappings::commandChanged(current);
|
||||||
if (!current || !current->data(0, Qt::UserRole).isValid())
|
if (!current || !current->data(0, Qt::UserRole).isValid())
|
||||||
@@ -133,7 +163,7 @@ void ShortcutSettings::commandChanged(QTreeWidgetItem *current)
|
|||||||
markCollisions(scitem);
|
markCollisions(scitem);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShortcutSettings::targetIdentifierChanged()
|
void ShortcutSettingsWidget::targetIdentifierChanged()
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *current = commandList()->currentItem();
|
QTreeWidgetItem *current = commandList()->currentItem();
|
||||||
if (current && current->data(0, Qt::UserRole).isValid()) {
|
if (current && current->data(0, Qt::UserRole).isValid()) {
|
||||||
@@ -148,7 +178,7 @@ void ShortcutSettings::targetIdentifierChanged()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShortcutSettings::hasConflicts() const
|
bool ShortcutSettingsWidget::hasConflicts() const
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *current = commandList()->currentItem();
|
QTreeWidgetItem *current = commandList()->currentItem();
|
||||||
if (!current || !current->data(0, Qt::UserRole).isValid())
|
if (!current || !current->data(0, Qt::UserRole).isValid())
|
||||||
@@ -185,7 +215,7 @@ bool ShortcutSettings::hasConflicts() const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShortcutSettings::setKeySequence(const QKeySequence &key)
|
void ShortcutSettingsWidget::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;
|
||||||
m_keyNum = key.count();
|
m_keyNum = key.count();
|
||||||
@@ -195,7 +225,7 @@ void ShortcutSettings::setKeySequence(const QKeySequence &key)
|
|||||||
targetEdit()->setText(key.toString(QKeySequence::NativeText));
|
targetEdit()->setText(key.toString(QKeySequence::NativeText));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShortcutSettings::resetTargetIdentifier()
|
void ShortcutSettingsWidget::resetTargetIdentifier()
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *current = commandList()->currentItem();
|
QTreeWidgetItem *current = commandList()->currentItem();
|
||||||
if (current && current->data(0, Qt::UserRole).isValid()) {
|
if (current && current->data(0, Qt::UserRole).isValid()) {
|
||||||
@@ -206,7 +236,7 @@ void ShortcutSettings::resetTargetIdentifier()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShortcutSettings::removeTargetIdentifier()
|
void ShortcutSettingsWidget::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();
|
||||||
@@ -215,9 +245,9 @@ void ShortcutSettings::removeTargetIdentifier()
|
|||||||
markCollisions(item);
|
markCollisions(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShortcutSettings::importAction()
|
void ShortcutSettingsWidget::importAction()
|
||||||
{
|
{
|
||||||
QString fileName = QFileDialog::getOpenFileName(widget(), tr("Import Keyboard Mapping Scheme"),
|
QString fileName = QFileDialog::getOpenFileName(ICore::dialogParent(), tr("Import Keyboard Mapping Scheme"),
|
||||||
ICore::resourcePath() + QLatin1String("/schemes/"),
|
ICore::resourcePath() + QLatin1String("/schemes/"),
|
||||||
tr("Keyboard Mapping Scheme (*.kms)"));
|
tr("Keyboard Mapping Scheme (*.kms)"));
|
||||||
if (!fileName.isEmpty()) {
|
if (!fileName.isEmpty()) {
|
||||||
@@ -245,7 +275,7 @@ void ShortcutSettings::importAction()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShortcutSettings::defaultAction()
|
void ShortcutSettingsWidget::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();
|
||||||
@@ -259,7 +289,7 @@ void ShortcutSettings::defaultAction()
|
|||||||
markCollisions(item);
|
markCollisions(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShortcutSettings::exportAction()
|
void ShortcutSettingsWidget::exportAction()
|
||||||
{
|
{
|
||||||
QString fileName = DocumentManager::getSaveFileNameWithExtension(
|
QString fileName = DocumentManager::getSaveFileNameWithExtension(
|
||||||
tr("Export Keyboard Mapping Scheme"),
|
tr("Export Keyboard Mapping Scheme"),
|
||||||
@@ -271,7 +301,7 @@ void ShortcutSettings::exportAction()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShortcutSettings::clear()
|
void ShortcutSettingsWidget::clear()
|
||||||
{
|
{
|
||||||
QTreeWidget *tree = commandList();
|
QTreeWidget *tree = commandList();
|
||||||
for (int i = tree->topLevelItemCount()-1; i >= 0 ; --i) {
|
for (int i = tree->topLevelItemCount()-1; i >= 0 ; --i) {
|
||||||
@@ -281,10 +311,8 @@ void ShortcutSettings::clear()
|
|||||||
m_scitems.clear();
|
m_scitems.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShortcutSettings::initialize()
|
void ShortcutSettingsWidget::initialize()
|
||||||
{
|
{
|
||||||
if (!m_initialized)
|
|
||||||
return;
|
|
||||||
clear();
|
clear();
|
||||||
QMap<QString, QTreeWidgetItem *> sections;
|
QMap<QString, QTreeWidgetItem *> sections;
|
||||||
|
|
||||||
@@ -329,7 +357,7 @@ void ShortcutSettings::initialize()
|
|||||||
filterChanged(filterText());
|
filterChanged(filterText());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShortcutSettings::handleKeyEvent(QKeyEvent *e)
|
void ShortcutSettingsWidget::handleKeyEvent(QKeyEvent *e)
|
||||||
{
|
{
|
||||||
int nextKey = e->key();
|
int nextKey = e->key();
|
||||||
if ( m_keyNum > 3 ||
|
if ( m_keyNum > 3 ||
|
||||||
@@ -362,27 +390,7 @@ void ShortcutSettings::handleKeyEvent(QKeyEvent *e)
|
|||||||
e->accept();
|
e->accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ShortcutSettings::translateModifiers(Qt::KeyboardModifiers state,
|
void ShortcutSettingsWidget::markCollisions(ShortcutItem *item)
|
||||||
const QString &text)
|
|
||||||
{
|
|
||||||
int result = 0;
|
|
||||||
// The shift modifier only counts when it is not used to type a symbol
|
|
||||||
// that is only reachable using the shift key anyway
|
|
||||||
if ((state & Qt::ShiftModifier) && (text.size() == 0
|
|
||||||
|| !text.at(0).isPrint()
|
|
||||||
|| text.at(0).isLetterOrNumber()
|
|
||||||
|| text.at(0).isSpace()))
|
|
||||||
result |= Qt::SHIFT;
|
|
||||||
if (state & Qt::ControlModifier)
|
|
||||||
result |= Qt::CTRL;
|
|
||||||
if (state & Qt::MetaModifier)
|
|
||||||
result |= Qt::META;
|
|
||||||
if (state & Qt::AltModifier)
|
|
||||||
result |= Qt::ALT;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShortcutSettings::markCollisions(ShortcutItem *item)
|
|
||||||
{
|
{
|
||||||
bool hasCollision = false;
|
bool hasCollision = false;
|
||||||
if (!item->m_key.isEmpty()) {
|
if (!item->m_key.isEmpty()) {
|
||||||
|
|||||||
@@ -32,8 +32,10 @@
|
|||||||
#define SHORTCUTSETTINGS_H
|
#define SHORTCUTSETTINGS_H
|
||||||
|
|
||||||
#include <coreplugin/actionmanager/commandmappings.h>
|
#include <coreplugin/actionmanager/commandmappings.h>
|
||||||
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
|
|
||||||
#include <QKeySequence>
|
#include <QKeySequence>
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QKeyEvent;
|
class QKeyEvent;
|
||||||
@@ -55,45 +57,52 @@ struct ShortcutItem
|
|||||||
QTreeWidgetItem *m_item;
|
QTreeWidgetItem *m_item;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ShortcutSettingsWidget : public CommandMappings
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
class ShortcutSettings : public CommandMappings
|
public:
|
||||||
|
ShortcutSettingsWidget(QWidget *parent = 0);
|
||||||
|
~ShortcutSettingsWidget() override;
|
||||||
|
|
||||||
|
void apply();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool eventFilter(QObject *o, QEvent *e) override;
|
||||||
|
|
||||||
|
void commandChanged(QTreeWidgetItem *current) override;
|
||||||
|
void targetIdentifierChanged() override;
|
||||||
|
void resetTargetIdentifier() override;
|
||||||
|
void removeTargetIdentifier() override;
|
||||||
|
void importAction() override;
|
||||||
|
void exportAction() override;
|
||||||
|
void defaultAction() override;
|
||||||
|
bool hasConflicts() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void initialize();
|
||||||
|
void handleKeyEvent(QKeyEvent *e);
|
||||||
|
void markCollisions(ShortcutItem *);
|
||||||
|
void setKeySequence(const QKeySequence &key);
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
QList<ShortcutItem *> m_scitems;
|
||||||
|
int m_key[4], m_keyNum;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ShortcutSettings : public IOptionsPage
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ShortcutSettings(QObject *parent = 0);
|
ShortcutSettings(QObject *parent = 0);
|
||||||
|
|
||||||
QWidget *widget();
|
QWidget *widget() override;
|
||||||
void apply();
|
void apply() override;
|
||||||
void finish();
|
void finish() override;
|
||||||
|
|
||||||
protected:
|
|
||||||
bool eventFilter(QObject *o, QEvent *e);
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void commandChanged(QTreeWidgetItem *current);
|
|
||||||
void targetIdentifierChanged();
|
|
||||||
void resetTargetIdentifier();
|
|
||||||
void removeTargetIdentifier();
|
|
||||||
void importAction();
|
|
||||||
void exportAction();
|
|
||||||
void defaultAction();
|
|
||||||
void initialize();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setKeySequence(const QKeySequence &key);
|
QPointer<ShortcutSettingsWidget> m_widget;
|
||||||
void clear();
|
|
||||||
|
|
||||||
void handleKeyEvent(QKeyEvent *e);
|
|
||||||
int translateModifiers(Qt::KeyboardModifiers state, const QString &text);
|
|
||||||
|
|
||||||
void markCollisions(ShortcutItem *);
|
|
||||||
bool hasConflicts() const;
|
|
||||||
|
|
||||||
QList<ShortcutItem *> m_scitems;
|
|
||||||
int m_key[4], m_keyNum;
|
|
||||||
|
|
||||||
bool m_initialized;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -539,7 +539,41 @@ void FakeVimOptionPage::updateVimRcWidgets()
|
|||||||
|
|
||||||
enum { CommandRole = Qt::UserRole };
|
enum { CommandRole = Qt::UserRole };
|
||||||
|
|
||||||
class FakeVimExCommandsPage : public CommandMappings
|
class FakeVimExCommandsWidget : public CommandMappings
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
FakeVimExCommandsWidget(FakeVimPluginPrivate *q, QWidget *parent = 0)
|
||||||
|
: CommandMappings(parent), m_q(q)
|
||||||
|
{
|
||||||
|
setPageTitle(Tr::tr("Ex Command Mapping"));
|
||||||
|
setTargetHeader(Tr::tr("Ex Trigger Expression"));
|
||||||
|
setTargetLabelText(Tr::tr("Regular expression:"));
|
||||||
|
setTargetEditTitle(Tr::tr("Ex Command"));
|
||||||
|
targetEdit()->setPlaceholderText(QString());
|
||||||
|
setImportExportEnabled(false);
|
||||||
|
initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void targetIdentifierChanged() override;
|
||||||
|
void resetTargetIdentifier() override;
|
||||||
|
void removeTargetIdentifier() override;
|
||||||
|
void defaultAction() override;
|
||||||
|
|
||||||
|
void commandChanged(QTreeWidgetItem *current) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void initialize();
|
||||||
|
|
||||||
|
ExCommandMap &exCommandMap();
|
||||||
|
ExCommandMap &defaultExCommandMap();
|
||||||
|
|
||||||
|
FakeVimPluginPrivate *m_q;
|
||||||
|
};
|
||||||
|
|
||||||
|
class FakeVimExCommandsPage : public IOptionsPage
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@@ -554,34 +588,28 @@ public:
|
|||||||
setCategoryIcon(_(SETTINGS_CATEGORY_FAKEVIM_ICON));
|
setCategoryIcon(_(SETTINGS_CATEGORY_FAKEVIM_ICON));
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *widget();
|
QWidget *widget() override;
|
||||||
void initialize();
|
void apply() override {}
|
||||||
ExCommandMap &exCommandMap();
|
void finish() override;
|
||||||
ExCommandMap &defaultExCommandMap();
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void commandChanged(QTreeWidgetItem *current);
|
|
||||||
void targetIdentifierChanged();
|
|
||||||
void resetTargetIdentifier();
|
|
||||||
void removeTargetIdentifier();
|
|
||||||
void defaultAction();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FakeVimPluginPrivate *m_q;
|
FakeVimPluginPrivate *m_q;
|
||||||
|
QPointer<QWidget> m_widget;
|
||||||
};
|
};
|
||||||
|
|
||||||
QWidget *FakeVimExCommandsPage::widget()
|
QWidget *FakeVimExCommandsPage::widget()
|
||||||
{
|
{
|
||||||
QWidget *w = CommandMappings::widget();
|
if (!m_widget)
|
||||||
setPageTitle(Tr::tr("Ex Command Mapping"));
|
m_widget = new FakeVimExCommandsWidget(m_q);
|
||||||
setTargetHeader(Tr::tr("Ex Trigger Expression"));
|
return m_widget;
|
||||||
setTargetLabelText(Tr::tr("Regular expression:"));
|
|
||||||
setTargetEditTitle(Tr::tr("Ex Command"));
|
|
||||||
setImportExportEnabled(false);
|
|
||||||
return w;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimExCommandsPage::initialize()
|
void FakeVimExCommandsPage::finish()
|
||||||
|
{
|
||||||
|
delete m_widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FakeVimExCommandsWidget::initialize()
|
||||||
{
|
{
|
||||||
QMap<QString, QTreeWidgetItem *> sections;
|
QMap<QString, QTreeWidgetItem *> sections;
|
||||||
|
|
||||||
@@ -622,14 +650,14 @@ void FakeVimExCommandsPage::initialize()
|
|||||||
commandChanged(0);
|
commandChanged(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimExCommandsPage::commandChanged(QTreeWidgetItem *current)
|
void FakeVimExCommandsWidget::commandChanged(QTreeWidgetItem *current)
|
||||||
{
|
{
|
||||||
CommandMappings::commandChanged(current);
|
CommandMappings::commandChanged(current);
|
||||||
if (current)
|
if (current)
|
||||||
targetEdit()->setText(current->text(2));
|
targetEdit()->setText(current->text(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimExCommandsPage::targetIdentifierChanged()
|
void FakeVimExCommandsWidget::targetIdentifierChanged()
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *current = commandList()->currentItem();
|
QTreeWidgetItem *current = commandList()->currentItem();
|
||||||
if (!current)
|
if (!current)
|
||||||
@@ -646,7 +674,7 @@ void FakeVimExCommandsPage::targetIdentifierChanged()
|
|||||||
setModified(current, regex != defaultExCommandMap()[name].pattern());
|
setModified(current, regex != defaultExCommandMap()[name].pattern());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimExCommandsPage::resetTargetIdentifier()
|
void FakeVimExCommandsWidget::resetTargetIdentifier()
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *current = commandList()->currentItem();
|
QTreeWidgetItem *current = commandList()->currentItem();
|
||||||
if (!current)
|
if (!current)
|
||||||
@@ -658,12 +686,12 @@ void FakeVimExCommandsPage::resetTargetIdentifier()
|
|||||||
targetEdit()->setText(regex);
|
targetEdit()->setText(regex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimExCommandsPage::removeTargetIdentifier()
|
void FakeVimExCommandsWidget::removeTargetIdentifier()
|
||||||
{
|
{
|
||||||
targetEdit()->clear();
|
targetEdit()->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimExCommandsPage::defaultAction()
|
void FakeVimExCommandsWidget::defaultAction()
|
||||||
{
|
{
|
||||||
int n = commandList()->topLevelItemCount();
|
int n = commandList()->topLevelItemCount();
|
||||||
for (int i = 0; i != n; ++i) {
|
for (int i = 0; i != n; ++i) {
|
||||||
@@ -987,7 +1015,7 @@ public:
|
|||||||
FakeVimPluginPrivate(FakeVimPlugin *);
|
FakeVimPluginPrivate(FakeVimPlugin *);
|
||||||
~FakeVimPluginPrivate();
|
~FakeVimPluginPrivate();
|
||||||
friend class FakeVimPlugin;
|
friend class FakeVimPlugin;
|
||||||
friend class FakeVimExCommandsPage;
|
friend class FakeVimExCommandsWidget;
|
||||||
friend class FakeVimUserCommandsPage;
|
friend class FakeVimUserCommandsPage;
|
||||||
friend class FakeVimUserCommandsModel;
|
friend class FakeVimUserCommandsModel;
|
||||||
|
|
||||||
@@ -2201,12 +2229,12 @@ void FakeVimPluginPrivate::switchToFile(int n)
|
|||||||
EditorManager::activateEditorForEntry(DocumentModel::entries().at(n));
|
EditorManager::activateEditorForEntry(DocumentModel::entries().at(n));
|
||||||
}
|
}
|
||||||
|
|
||||||
ExCommandMap &FakeVimExCommandsPage::exCommandMap()
|
ExCommandMap &FakeVimExCommandsWidget::exCommandMap()
|
||||||
{
|
{
|
||||||
return m_q->exCommandMap();
|
return m_q->exCommandMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
ExCommandMap &FakeVimExCommandsPage::defaultExCommandMap()
|
ExCommandMap &FakeVimExCommandsWidget::defaultExCommandMap()
|
||||||
{
|
{
|
||||||
return m_q->defaultExCommandMap();
|
return m_q->defaultExCommandMap();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user