2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-03-10 11:21:56 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-03-10 11:21:56 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
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
|
|
|
|
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 CommandMappingsPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CommandMappingsPrivate(CommandMappings *parent)
|
2015-04-27 12:29:55 +02:00
|
|
|
: q(parent)
|
2014-02-14 19:45:35 +01:00
|
|
|
{
|
2015-04-27 12:29:55 +02:00
|
|
|
groupBox = new QGroupBox(parent);
|
2014-02-14 19:45:35 +01:00
|
|
|
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);
|
2014-03-06 14:42:25 +01:00
|
|
|
defaultButton->setToolTip(CommandMappings::tr("Reset all to default."));
|
2014-02-14 19:45:35 +01:00
|
|
|
|
2020-03-31 09:54:35 +02:00
|
|
|
resetButton = new QPushButton(CommandMappings::tr("Reset"), groupBox);
|
|
|
|
|
resetButton->setToolTip(CommandMappings::tr("Reset to default."));
|
|
|
|
|
resetButton->setVisible(false);
|
|
|
|
|
|
2014-02-14 19:45:35 +01:00
|
|
|
importButton = new QPushButton(CommandMappings::tr("Import..."), groupBox);
|
|
|
|
|
exportButton = new QPushButton(CommandMappings::tr("Export..."), groupBox);
|
|
|
|
|
|
2018-07-21 21:11:46 +02:00
|
|
|
auto hboxLayout1 = new QHBoxLayout();
|
2014-02-14 19:45:35 +01:00
|
|
|
hboxLayout1->addWidget(defaultButton);
|
2020-03-31 09:54:35 +02:00
|
|
|
hboxLayout1->addWidget(resetButton);
|
2014-02-14 19:45:35 +01:00
|
|
|
hboxLayout1->addStretch();
|
|
|
|
|
hboxLayout1->addWidget(importButton);
|
|
|
|
|
hboxLayout1->addWidget(exportButton);
|
|
|
|
|
|
2018-07-21 21:11:46 +02:00
|
|
|
auto hboxLayout = new QHBoxLayout();
|
2014-02-14 19:45:35 +01:00
|
|
|
hboxLayout->addWidget(filterEdit);
|
|
|
|
|
|
2018-07-21 21:11:46 +02:00
|
|
|
auto vboxLayout1 = new QVBoxLayout(groupBox);
|
2014-02-14 19:45:35 +01:00
|
|
|
vboxLayout1->addLayout(hboxLayout);
|
|
|
|
|
vboxLayout1->addWidget(commandList);
|
|
|
|
|
vboxLayout1->addLayout(hboxLayout1);
|
|
|
|
|
|
2018-07-21 21:11:46 +02:00
|
|
|
auto vboxLayout = new QVBoxLayout(parent);
|
2014-02-14 19:45:35 +01:00
|
|
|
vboxLayout->addWidget(groupBox);
|
|
|
|
|
|
2015-04-27 12:29:55 +02:00
|
|
|
q->connect(exportButton, &QPushButton::clicked,
|
|
|
|
|
q, &CommandMappings::exportAction);
|
|
|
|
|
q->connect(importButton, &QPushButton::clicked,
|
|
|
|
|
q, &CommandMappings::importAction);
|
|
|
|
|
q->connect(defaultButton, &QPushButton::clicked,
|
|
|
|
|
q, &CommandMappings::defaultAction);
|
2020-03-31 09:54:35 +02:00
|
|
|
q->connect(resetButton, &QPushButton::clicked, q, &CommandMappings::resetRequested);
|
2014-02-14 19:45:35 +01:00
|
|
|
|
|
|
|
|
commandList->sortByColumn(0, Qt::AscendingOrder);
|
|
|
|
|
|
2015-04-27 12:29:55 +02:00
|
|
|
q->connect(filterEdit, &FancyLineEdit::textChanged,
|
|
|
|
|
q, &CommandMappings::filterChanged);
|
|
|
|
|
q->connect(commandList, &QTreeWidget::currentItemChanged,
|
2015-04-29 18:01:21 +02:00
|
|
|
q, &CommandMappings::currentCommandChanged);
|
2014-02-14 19:45:35 +01:00
|
|
|
|
|
|
|
|
new HeaderViewStretcher(commandList->header(), 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CommandMappings *q;
|
|
|
|
|
|
|
|
|
|
QGroupBox *groupBox;
|
|
|
|
|
FancyLineEdit *filterEdit;
|
|
|
|
|
QTreeWidget *commandList;
|
|
|
|
|
QPushButton *defaultButton;
|
2020-03-31 09:54:35 +02:00
|
|
|
QPushButton *resetButton;
|
2014-02-14 19:45:35 +01:00
|
|
|
QPushButton *importButton;
|
|
|
|
|
QPushButton *exportButton;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
2010-03-10 11:21:56 +01:00
|
|
|
|
2020-02-12 13:26:28 +01:00
|
|
|
/*!
|
|
|
|
|
\class Core::CommandMappings
|
|
|
|
|
\inmodule QtCreator
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
|
2015-04-27 12:29:55 +02:00
|
|
|
CommandMappings::CommandMappings(QWidget *parent)
|
|
|
|
|
: QWidget(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
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2020-03-31 09:54:35 +02:00
|
|
|
void CommandMappings::setResetVisible(bool visible)
|
|
|
|
|
{
|
|
|
|
|
d->resetButton->setVisible(visible);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
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::setTargetHeader(const QString &s)
|
2010-03-10 11:21:56 +01:00
|
|
|
{
|
2017-02-22 15:09:35 +01:00
|
|
|
d->commandList->setHeaderLabels({tr("Command"), tr("Label"), s});
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
2015-04-27 15:39:09 +02:00
|
|
|
for (int i = 0; !visible && i < columnCount; ++i)
|
|
|
|
|
visible |= !filterColumn(filterString, item, i);
|
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
|
|
|
|
2015-04-27 15:39:09 +02:00
|
|
|
bool CommandMappings::filterColumn(const QString &filterString, QTreeWidgetItem *item,
|
|
|
|
|
int column) const
|
|
|
|
|
{
|
|
|
|
|
return !item->text(column).contains(filterString, Qt::CaseInsensitive);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
{
|
2015-04-29 18:01:21 +02:00
|
|
|
return d->filterEdit->text();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CommandMappings::setFilterText(const QString &text)
|
|
|
|
|
{
|
|
|
|
|
d->filterEdit->setText(text);
|
2010-12-06 17:21:03 +01:00
|
|
|
}
|
2014-02-14 19:45:35 +01:00
|
|
|
|
|
|
|
|
} // namespace Core
|