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 "ui_commandmappings.h"
|
|
|
|
|
#include "commandsfile.h"
|
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>
|
2010-03-10 11:21:56 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QTreeWidgetItem>
|
2012-08-06 13:42:46 +02:00
|
|
|
#include <QDebug>
|
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
|
|
|
|
|
|
|
|
using namespace Core;
|
|
|
|
|
using namespace Core::Internal;
|
|
|
|
|
|
|
|
|
|
CommandMappings::CommandMappings(QObject *parent)
|
2010-12-02 18:28:16 +01:00
|
|
|
: IOptionsPage(parent), m_page(0)
|
2010-03-10 11:21:56 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IOptionsPage
|
|
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
QWidget *CommandMappings::widget()
|
2010-03-10 11:21:56 +01:00
|
|
|
{
|
2013-12-03 14:17:03 +01:00
|
|
|
if (!m_widget) {
|
|
|
|
|
m_page = new Ui::CommandMappings();
|
|
|
|
|
m_widget = new QWidget;
|
|
|
|
|
m_page->setupUi(m_widget);
|
|
|
|
|
m_page->targetEdit->setAutoHideButton(Utils::FancyLineEdit::Right, true);
|
|
|
|
|
m_page->targetEdit->setPlaceholderText(QString());
|
|
|
|
|
m_page->targetEdit->installEventFilter(this);
|
2014-02-13 13:54:39 +01:00
|
|
|
m_page->targetEdit->setFiltering(true);
|
|
|
|
|
|
|
|
|
|
m_page->filterEdit->setFiltering(true);
|
2013-12-03 14:17:03 +01:00
|
|
|
|
|
|
|
|
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;
|
2010-03-10 11:21:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CommandMappings::setImportExportEnabled(bool enabled)
|
|
|
|
|
{
|
|
|
|
|
m_page->importButton->setVisible(enabled);
|
|
|
|
|
m_page->exportButton->setVisible(enabled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTreeWidget *CommandMappings::commandList() const
|
|
|
|
|
{
|
|
|
|
|
return m_page->commandList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QLineEdit *CommandMappings::targetEdit() const
|
|
|
|
|
{
|
|
|
|
|
return m_page->targetEdit;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-12 08:51:56 +01:00
|
|
|
void CommandMappings::setPageTitle(const QString &s)
|
2010-03-10 11:21:56 +01:00
|
|
|
{
|
|
|
|
|
m_page->groupBox->setTitle(s);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-12 08:51:56 +01:00
|
|
|
void CommandMappings::setTargetLabelText(const QString &s)
|
2010-03-10 11:21:56 +01:00
|
|
|
{
|
|
|
|
|
m_page->targetEditLabel->setText(s);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-12 08:51:56 +01:00
|
|
|
void CommandMappings::setTargetEditTitle(const QString &s)
|
2010-03-10 11:21:56 +01:00
|
|
|
{
|
|
|
|
|
m_page->targetEditGroup->setTitle(s);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-12 08:51:56 +01:00
|
|
|
void CommandMappings::setTargetHeader(const QString &s)
|
2010-03-10 11:21:56 +01:00
|
|
|
{
|
|
|
|
|
m_page->commandList->setHeaderLabels(QStringList() << tr("Command") << tr("Label") << s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CommandMappings::finish()
|
|
|
|
|
{
|
2013-12-03 14:17:03 +01:00
|
|
|
delete m_widget;
|
2010-12-02 18:28:16 +01:00
|
|
|
if (!m_page) // page was never shown
|
|
|
|
|
return;
|
2010-03-10 11:21:56 +01:00
|
|
|
delete m_page;
|
2010-12-02 18:28:16 +01:00
|
|
|
m_page = 0;
|
2010-03-10 11:21:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CommandMappings::commandChanged(QTreeWidgetItem *current)
|
|
|
|
|
{
|
|
|
|
|
if (!current || !current->data(0, Qt::UserRole).isValid()) {
|
2011-12-22 14:44:14 +01:00
|
|
|
m_page->targetEdit->setText(QString());
|
2010-03-10 11:21:56 +01:00
|
|
|
m_page->targetEditGroup->setEnabled(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
m_page->targetEditGroup->setEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CommandMappings::filterChanged(const QString &f)
|
|
|
|
|
{
|
2010-12-06 17:21:03 +01:00
|
|
|
if (!m_page)
|
|
|
|
|
return;
|
2010-03-10 11:21:56 +01:00
|
|
|
for (int i=0; i<m_page->commandList->topLevelItemCount(); ++i) {
|
|
|
|
|
QTreeWidgetItem *item = m_page->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();
|
2012-05-22 15:14:22 +02:00
|
|
|
for (int i = 0; !visible && i < columnCount; ++i) {
|
|
|
|
|
QString text = item->text(i);
|
2012-08-23 15:53:58 +02:00
|
|
|
if (Utils::HostOsInfo::isMacHost()) {
|
|
|
|
|
// 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
|
|
|
|
|
{
|
|
|
|
|
if (!m_page)
|
|
|
|
|
return QString();
|
|
|
|
|
return m_page->filterEdit->text();
|
|
|
|
|
}
|