2011-01-06 18:26:09 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
|
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
|
**
|
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
|
**
|
|
|
|
|
** No Commercial Usage
|
|
|
|
|
**
|
|
|
|
|
** This file contains pre-release code and may not be distributed.
|
|
|
|
|
** You may use this file in accordance with the terms and conditions
|
|
|
|
|
** contained in the Technology Preview License Agreement accompanying
|
|
|
|
|
** this package.
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
|
|
|
|
** 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, Nokia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
|
** Nokia at qt-info@nokia.com.
|
|
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "externaltoolconfig.h"
|
|
|
|
|
#include "ui_externaltoolconfig.h"
|
|
|
|
|
|
2011-01-21 10:58:06 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2011-01-06 18:26:09 +01:00
|
|
|
#include <QtCore/QTextStream>
|
|
|
|
|
|
|
|
|
|
using namespace Core::Internal;
|
|
|
|
|
|
|
|
|
|
ExternalToolConfig::ExternalToolConfig(QWidget *parent) :
|
|
|
|
|
QWidget(parent),
|
|
|
|
|
ui(new Ui::ExternalToolConfig)
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
2011-01-21 10:58:06 +01:00
|
|
|
ui->toolTree->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed);
|
2011-01-06 18:26:09 +01:00
|
|
|
connect(ui->toolTree, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
|
|
|
|
|
this, SLOT(showInfoForItem(QTreeWidgetItem*)));
|
2011-01-21 10:58:06 +01:00
|
|
|
connect(ui->toolTree, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
|
|
|
|
|
this, SLOT(updateItem(QTreeWidgetItem *)));
|
2011-01-06 18:26:09 +01:00
|
|
|
showInfoForItem(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExternalToolConfig::~ExternalToolConfig()
|
|
|
|
|
{
|
2011-01-21 10:58:06 +01:00
|
|
|
QMapIterator<QString, QList<ExternalTool *> > it(m_tools);
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
|
|
|
|
qDeleteAll(it.value());
|
|
|
|
|
}
|
2011-01-06 18:26:09 +01:00
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ExternalToolConfig::searchKeywords() const
|
|
|
|
|
{
|
|
|
|
|
QString keywords;
|
|
|
|
|
QTextStream(&keywords)
|
|
|
|
|
<< ui->descriptionLabel->text()
|
|
|
|
|
<< ui->executableLabel->text()
|
|
|
|
|
<< ui->argumentsLabel->text()
|
|
|
|
|
<< ui->workingDirectoryLabel->text()
|
|
|
|
|
<< ui->outputLabel->text()
|
|
|
|
|
<< ui->errorOutputLabel->text()
|
2011-01-24 12:21:42 +01:00
|
|
|
<< ui->modifiesDocumentCheckbox->text()
|
|
|
|
|
<< ui->inputLabel->text();
|
2011-01-06 18:26:09 +01:00
|
|
|
return keywords;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExternalToolConfig::setTools(const QMap<QString, QList<ExternalTool *> > &tools)
|
|
|
|
|
{
|
2011-01-21 10:58:06 +01:00
|
|
|
QMapIterator<QString, QList<ExternalTool *> > it(tools);
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
|
|
|
|
QList<ExternalTool *> itemCopy;
|
|
|
|
|
foreach (ExternalTool *tool, it.value())
|
|
|
|
|
itemCopy.append(new ExternalTool(tool));
|
|
|
|
|
m_tools.insert(it.key(), itemCopy);
|
|
|
|
|
}
|
2011-01-06 18:26:09 +01:00
|
|
|
|
2011-01-21 10:58:06 +01:00
|
|
|
bool blocked = ui->toolTree->blockSignals(true); // block itemChanged
|
|
|
|
|
Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEditable;
|
|
|
|
|
QMapIterator<QString, QList<ExternalTool *> > categories(m_tools);
|
2011-01-06 18:26:09 +01:00
|
|
|
while (categories.hasNext()) {
|
|
|
|
|
categories.next();
|
|
|
|
|
QString name = (categories.key().isEmpty() ? tr("External Tools Menu") : categories.key());
|
|
|
|
|
QTreeWidgetItem *category = new QTreeWidgetItem(ui->toolTree, QStringList() << name);
|
2011-01-21 10:58:06 +01:00
|
|
|
category->setFlags(flags);
|
|
|
|
|
category->setData(0, Qt::UserRole, name); // save the name in case of category being renamed by user
|
2011-01-06 18:26:09 +01:00
|
|
|
foreach (ExternalTool *tool, categories.value()) {
|
|
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem(category, QStringList() << tool->displayName());
|
2011-01-21 10:58:06 +01:00
|
|
|
item->setFlags(flags);
|
2011-01-06 18:26:09 +01:00
|
|
|
item->setData(0, Qt::UserRole, qVariantFromValue(tool));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ui->toolTree->expandAll();
|
2011-01-21 10:58:06 +01:00
|
|
|
ui->toolTree->blockSignals(blocked); // unblock itemChanged
|
2011-01-06 18:26:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExternalToolConfig::showInfoForItem(QTreeWidgetItem *item)
|
|
|
|
|
{
|
|
|
|
|
ExternalTool *tool = 0;
|
|
|
|
|
if (item)
|
|
|
|
|
tool = item->data(0, Qt::UserRole).value<ExternalTool *>();
|
|
|
|
|
if (!tool) {
|
|
|
|
|
ui->description->setText(QString());
|
|
|
|
|
ui->executable->setPath(QString());
|
|
|
|
|
ui->arguments->setText(QString());
|
|
|
|
|
ui->workingDirectory->setPath(QString());
|
|
|
|
|
ui->inputText->setPlainText(QString());
|
|
|
|
|
ui->infoWidget->setEnabled(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ui->infoWidget->setEnabled(true);
|
|
|
|
|
ui->description->setText(tool->description());
|
|
|
|
|
ui->executable->setPath(tool->executables().isEmpty() ? QString() : tool->executables().first());
|
|
|
|
|
ui->arguments->setText(tool->arguments());
|
|
|
|
|
ui->workingDirectory->setPath(tool->workingDirectory());
|
|
|
|
|
ui->outputBehavior->setCurrentIndex((int)tool->outputHandling());
|
|
|
|
|
ui->errorOutputBehavior->setCurrentIndex((int)tool->errorHandling());
|
2011-01-24 12:21:42 +01:00
|
|
|
ui->modifiesDocumentCheckbox->setChecked(tool->modifiesCurrentDocument());
|
2011-01-06 18:26:09 +01:00
|
|
|
ui->inputText->setPlainText(tool->input());
|
|
|
|
|
ui->description->setCursorPosition(0);
|
|
|
|
|
ui->arguments->setCursorPosition(0);
|
|
|
|
|
}
|
2011-01-21 10:58:06 +01:00
|
|
|
|
|
|
|
|
void ExternalToolConfig::updateItem(QTreeWidgetItem *item)
|
|
|
|
|
{
|
|
|
|
|
ExternalTool *tool = 0;
|
|
|
|
|
if (item)
|
|
|
|
|
tool = item->data(0, Qt::UserRole).value<ExternalTool *>();
|
|
|
|
|
if (tool) {
|
|
|
|
|
// tool was renamed
|
|
|
|
|
const QString &newName = item->data(0, Qt::DisplayRole).toString();
|
|
|
|
|
if (newName == tool->displayName())
|
|
|
|
|
return;
|
|
|
|
|
if (newName.isEmpty()) {
|
|
|
|
|
// prevent empty names
|
|
|
|
|
bool blocked = ui->toolTree->blockSignals(true); // block itemChanged
|
|
|
|
|
item->setData(0, Qt::DisplayRole, tool->displayName());
|
|
|
|
|
ui->toolTree->blockSignals(blocked); // unblock itemChanged
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
tool->setDisplayName(item->data(0, Qt::DisplayRole).toString());
|
|
|
|
|
} else {
|
|
|
|
|
// category was renamed
|
|
|
|
|
const QString &oldName = item->data(0, Qt::UserRole).toString();
|
|
|
|
|
const QString &newName = item->data(0, Qt::DisplayRole).toString();
|
|
|
|
|
if (oldName == newName)
|
|
|
|
|
return;
|
|
|
|
|
if (newName.isEmpty() && m_tools.contains(newName)) {
|
|
|
|
|
// prevent empty or duplicate names
|
|
|
|
|
bool blocked = ui->toolTree->blockSignals(true); // block itemChanged
|
|
|
|
|
item->setData(0, Qt::DisplayRole, oldName);
|
|
|
|
|
ui->toolTree->blockSignals(blocked); // unblock itemChanged
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
QTC_ASSERT(m_tools.contains(oldName), return);
|
|
|
|
|
m_tools.insert(newName, m_tools.value(oldName));
|
|
|
|
|
m_tools.remove(oldName);
|
|
|
|
|
|
|
|
|
|
bool blocked = ui->toolTree->blockSignals(true); // block itemChanged
|
|
|
|
|
item->setData(0, Qt::UserRole, newName);
|
|
|
|
|
int currentIndex = ui->toolTree->indexOfTopLevelItem(item);
|
|
|
|
|
bool wasExpanded = ui->toolTree->isExpanded(ui->toolTree->model()->index(currentIndex, 0));
|
|
|
|
|
ui->toolTree->takeTopLevelItem(currentIndex);
|
|
|
|
|
int newIndex = m_tools.keys().indexOf(newName);
|
|
|
|
|
ui->toolTree->insertTopLevelItem(newIndex, item);
|
|
|
|
|
if (wasExpanded)
|
|
|
|
|
ui->toolTree->expand(ui->toolTree->model()->index(newIndex, 0));
|
|
|
|
|
ui->toolTree->blockSignals(blocked); // unblock itemChanged
|
|
|
|
|
}
|
|
|
|
|
}
|