2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-03-10 11:21:56 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2010-03-10 11:21:56 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-03-10 11:21:56 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2010-03-10 11:21:56 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-03-10 11:21:56 +01:00
|
|
|
|
|
|
|
|
#include "commandmappings.h"
|
|
|
|
|
#include "commandsfile.h"
|
2014-02-14 19:45:35 +01:00
|
|
|
|
2013-08-29 16:36:42 +02:00
|
|
|
#include <coreplugin/dialogs/shortcutsettings.h>
|
2010-03-10 11:21:56 +01:00
|
|
|
|
2012-08-23 15:53:58 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2013-03-20 15:45:38 +01:00
|
|
|
#include <utils/headerviewstretcher.h>
|
2014-02-14 19:45:35 +01:00
|
|
|
#include <utils/fancylineedit.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
2010-03-10 11:21:56 +01:00
|
|
|
|
2012-08-06 13:42:46 +02:00
|
|
|
#include <QDebug>
|
2014-02-14 19:45:35 +01:00
|
|
|
#include <QGroupBox>
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QPointer>
|
|
|
|
|
#include <QPushButton>
|
|
|
|
|
#include <QTreeWidgetItem>
|
|
|
|
|
#include <QVBoxLayout>
|
2010-03-10 11:21:56 +01:00
|
|
|
|
2010-12-16 11:25:28 +01:00
|
|
|
Q_DECLARE_METATYPE(Core::Internal::ShortcutItem*)
|
2010-03-10 11:21:56 +01:00
|
|
|
|
2014-02-14 19:45:35 +01:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
|
|
|
|
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
|
2010-03-10 11:21:56 +01:00
|
|
|
|
|
|
|
|
CommandMappings::CommandMappings(QObject *parent)
|
2014-02-14 19:45:35 +01:00
|
|
|
: IOptionsPage(parent), d(new Internal::CommandMappingsPrivate(this))
|
2010-03-10 11:21:56 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-14 19:45:35 +01:00
|
|
|
CommandMappings::~CommandMappings()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
2010-03-10 11:21:56 +01:00
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
QWidget *CommandMappings::widget()
|
2010-03-10 11:21:56 +01:00
|
|
|
{
|
2014-02-14 19:45:35 +01:00
|
|
|
if (!d->m_widget)
|
|
|
|
|
d->setupWidget();
|
|
|
|
|
return d->m_widget;
|
2010-03-10 11:21:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CommandMappings::setImportExportEnabled(bool enabled)
|
|
|
|
|
{
|
2014-02-14 19:45:35 +01:00
|
|
|
d->importButton->setVisible(enabled);
|
|
|
|
|
d->exportButton->setVisible(enabled);
|
2010-03-10 11:21:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTreeWidget *CommandMappings::commandList() const
|
|
|
|
|
{
|
2014-02-14 19:45:35 +01:00
|
|
|
return d->commandList;
|
2010-03-10 11:21:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QLineEdit *CommandMappings::targetEdit() const
|
|
|
|
|
{
|
2014-02-14 19:45:35 +01:00
|
|
|
return d->targetEdit;
|
2010-03-10 11:21:56 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-12 08:51:56 +01:00
|
|
|
void CommandMappings::setPageTitle(const QString &s)
|
2010-03-10 11:21:56 +01:00
|
|
|
{
|
2014-02-14 19:45:35 +01:00
|
|
|
d->groupBox->setTitle(s);
|
2010-03-10 11:21:56 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-12 08:51:56 +01:00
|
|
|
void CommandMappings::setTargetLabelText(const QString &s)
|
2010-03-10 11:21:56 +01:00
|
|
|
{
|
2014-02-14 19:45:35 +01:00
|
|
|
d->targetEdit->setText(s);
|
2010-03-10 11:21:56 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-12 08:51:56 +01:00
|
|
|
void CommandMappings::setTargetEditTitle(const QString &s)
|
2010-03-10 11:21:56 +01:00
|
|
|
{
|
2014-02-14 19:45:35 +01:00
|
|
|
d->targetEditGroup->setTitle(s);
|
2010-03-10 11:21:56 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-12 08:51:56 +01:00
|
|
|
void CommandMappings::setTargetHeader(const QString &s)
|
2010-03-10 11:21:56 +01:00
|
|
|
{
|
2014-02-14 19:45:35 +01:00
|
|
|
d->commandList->setHeaderLabels(QStringList() << tr("Command") << tr("Label") << s);
|
2010-03-10 11:21:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CommandMappings::finish()
|
|
|
|
|
{
|
2014-02-14 19:45:35 +01:00
|
|
|
delete d->m_widget;
|
2010-03-10 11:21:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CommandMappings::commandChanged(QTreeWidgetItem *current)
|
|
|
|
|
{
|
|
|
|
|
if (!current || !current->data(0, Qt::UserRole).isValid()) {
|
2014-02-14 19:45:35 +01:00
|
|
|
d->targetEdit->setText(QString());
|
|
|
|
|
d->targetEditGroup->setEnabled(false);
|
2010-03-10 11:21:56 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2014-02-14 19:45:35 +01:00
|
|
|
d->targetEditGroup->setEnabled(true);
|
2010-03-10 11:21:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CommandMappings::filterChanged(const QString &f)
|
|
|
|
|
{
|
2014-02-14 19:45:35 +01:00
|
|
|
for (int i = 0; i < d->commandList->topLevelItemCount(); ++i) {
|
|
|
|
|
QTreeWidgetItem *item = d->commandList->topLevelItem(i);
|
2012-05-22 14:56:37 +02:00
|
|
|
filter(f, item);
|
2010-03-10 11:21:56 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-14 19:45:35 +01:00
|
|
|
bool CommandMappings::hasConflicts() const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-22 14:56:37 +02:00
|
|
|
bool CommandMappings::filter(const QString &filterString, QTreeWidgetItem *item)
|
2010-03-10 11:21:56 +01:00
|
|
|
{
|
2012-05-22 14:56:37 +02:00
|
|
|
bool visible = filterString.isEmpty();
|
|
|
|
|
int columnCount = item->columnCount();
|
2012-05-22 15:14:22 +02:00
|
|
|
for (int i = 0; !visible && i < columnCount; ++i) {
|
|
|
|
|
QString text = item->text(i);
|
2014-02-14 19:45:35 +01:00
|
|
|
if (HostOsInfo::isMacHost()) {
|
2012-08-23 15:53:58 +02:00
|
|
|
// accept e.g. Cmd+E in the filter. the text shows special fancy characters for Cmd
|
|
|
|
|
if (i == columnCount - 1) {
|
|
|
|
|
QKeySequence key = QKeySequence::fromString(text, QKeySequence::NativeText);
|
|
|
|
|
if (!key.isEmpty()) {
|
|
|
|
|
text = key.toString(QKeySequence::PortableText);
|
|
|
|
|
text.replace(QLatin1String("Ctrl"), QLatin1String("Cmd"));
|
|
|
|
|
text.replace(QLatin1String("Meta"), QLatin1String("Ctrl"));
|
|
|
|
|
text.replace(QLatin1String("Alt"), QLatin1String("Opt"));
|
|
|
|
|
}
|
2012-05-22 15:14:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
visible |= (bool)text.contains(filterString, Qt::CaseInsensitive);
|
|
|
|
|
}
|
2012-05-22 14:56:37 +02:00
|
|
|
|
|
|
|
|
int childCount = item->childCount();
|
|
|
|
|
if (childCount > 0) {
|
|
|
|
|
// force visibility if this item matches
|
|
|
|
|
QString leafFilterString = visible ? QString() : filterString;
|
|
|
|
|
for (int i = 0; i < childCount; ++i) {
|
|
|
|
|
QTreeWidgetItem *citem = item->child(i);
|
|
|
|
|
visible |= !filter(leafFilterString, citem); // parent visible if any child visible
|
2010-03-10 11:21:56 +01:00
|
|
|
}
|
|
|
|
|
}
|
2012-05-22 14:56:37 +02:00
|
|
|
item->setHidden(!visible);
|
|
|
|
|
return !visible;
|
2010-03-10 11:21:56 +01:00
|
|
|
}
|
2010-03-29 14:42:46 +02:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
2010-12-06 17:21:03 +01:00
|
|
|
|
|
|
|
|
QString CommandMappings::filterText() const
|
|
|
|
|
{
|
2014-02-14 19:45:35 +01:00
|
|
|
return d->filterEdit ? d->filterEdit->text() : QString();
|
2010-12-06 17:21:03 +01:00
|
|
|
}
|
2014-02-14 19:45:35 +01:00
|
|
|
|
|
|
|
|
} // namespace Core
|