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-02-01 15:55:40 +01:00
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
|
2011-01-06 18:26:09 +01:00
|
|
|
#include <QtCore/QTextStream>
|
2011-02-01 15:55:40 +01:00
|
|
|
#include <QtCore/QFile>
|
|
|
|
|
#include <QtGui/QMessageBox>
|
2011-01-06 18:26:09 +01:00
|
|
|
|
2011-02-01 15:55:40 +01:00
|
|
|
using namespace Core;
|
2011-01-06 18:26:09 +01:00
|
|
|
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*)),
|
2011-01-24 15:01:48 +01:00
|
|
|
this, SLOT(handleCurrentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)));
|
2011-01-21 10:58:06 +01:00
|
|
|
connect(ui->toolTree, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
|
2011-01-24 15:01:48 +01:00
|
|
|
this, SLOT(updateItemName(QTreeWidgetItem *)));
|
2011-02-01 15:55:40 +01:00
|
|
|
connect(ui->description, SIGNAL(editingFinished()), this, SLOT(updateCurrentItem()));
|
|
|
|
|
connect(ui->executable, SIGNAL(editingFinished()), this, SLOT(updateCurrentItem()));
|
|
|
|
|
connect(ui->executable, SIGNAL(browsingFinished()), this, SLOT(updateCurrentItem()));
|
|
|
|
|
connect(ui->arguments, SIGNAL(editingFinished()), this, SLOT(updateCurrentItem()));
|
|
|
|
|
connect(ui->workingDirectory, SIGNAL(editingFinished()), this, SLOT(updateCurrentItem()));
|
|
|
|
|
connect(ui->workingDirectory, SIGNAL(browsingFinished()), this, SLOT(updateCurrentItem()));
|
|
|
|
|
connect(ui->outputBehavior, SIGNAL(activated(int)), this, SLOT(updateCurrentItem()));
|
|
|
|
|
connect(ui->errorOutputBehavior, SIGNAL(activated(int)), this, SLOT(updateCurrentItem()));
|
|
|
|
|
connect(ui->modifiesDocumentCheckbox, SIGNAL(clicked()), this, SLOT(updateCurrentItem()));
|
|
|
|
|
connect(ui->inputText, SIGNAL(textChanged()), this, SLOT(updateCurrentItem()));
|
|
|
|
|
|
|
|
|
|
ui->addButton->setIcon(QIcon(QLatin1String(Constants::ICON_PLUS)));
|
|
|
|
|
ui->removeButton->setIcon(QIcon(QLatin1String(Constants::ICON_MINUS)));
|
|
|
|
|
ui->revertButton->setIcon(QIcon(QLatin1String(Constants::ICON_RESET)));
|
|
|
|
|
connect(ui->revertButton, SIGNAL(clicked()), this, SLOT(revertCurrentItem()));
|
2011-01-24 15:01:48 +01:00
|
|
|
|
2011-01-06 18:26:09 +01:00
|
|
|
showInfoForItem(0);
|
2011-02-01 15:55:40 +01:00
|
|
|
updateButtons(ui->toolTree->currentItem());
|
2011-01-06 18:26:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2011-01-24 15:01:48 +01:00
|
|
|
void ExternalToolConfig::handleCurrentItemChanged(QTreeWidgetItem *now, QTreeWidgetItem *previous)
|
|
|
|
|
{
|
|
|
|
|
updateItem(previous);
|
|
|
|
|
showInfoForItem(now);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-01 15:55:40 +01:00
|
|
|
void ExternalToolConfig::updateButtons(QTreeWidgetItem *item)
|
|
|
|
|
{
|
|
|
|
|
ExternalTool *tool = 0;
|
|
|
|
|
if (item)
|
|
|
|
|
tool = item->data(0, Qt::UserRole).value<ExternalTool *>();
|
|
|
|
|
if (!tool) {
|
|
|
|
|
ui->removeButton->setEnabled(false);
|
|
|
|
|
ui->revertButton->setEnabled(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!tool->preset()) {
|
|
|
|
|
ui->removeButton->setEnabled(true);
|
|
|
|
|
ui->revertButton->setEnabled(false);
|
|
|
|
|
} else {
|
|
|
|
|
ui->removeButton->setEnabled(false);
|
|
|
|
|
ui->revertButton->setEnabled((*tool) != (*(tool->preset())));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExternalToolConfig::updateCurrentItem()
|
|
|
|
|
{
|
|
|
|
|
QTreeWidgetItem *item = ui->toolTree->currentItem();
|
|
|
|
|
updateItem(item);
|
|
|
|
|
updateButtons(item);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-24 15:01:48 +01:00
|
|
|
void ExternalToolConfig::updateItem(QTreeWidgetItem *item)
|
|
|
|
|
{
|
|
|
|
|
ExternalTool *tool = 0;
|
|
|
|
|
if (item)
|
|
|
|
|
tool = item->data(0, Qt::UserRole).value<ExternalTool *>();
|
|
|
|
|
if (!tool)
|
|
|
|
|
return;
|
|
|
|
|
tool->setDescription(ui->description->text());
|
|
|
|
|
QStringList executables = tool->executables();
|
|
|
|
|
if (executables.size() > 0)
|
2011-02-01 15:55:40 +01:00
|
|
|
executables[0] = ui->executable->rawPath();
|
2011-01-24 15:01:48 +01:00
|
|
|
else
|
2011-02-01 15:55:40 +01:00
|
|
|
executables << ui->executable->rawPath();
|
2011-01-24 15:01:48 +01:00
|
|
|
tool->setExecutables(executables);
|
|
|
|
|
tool->setArguments(ui->arguments->text());
|
2011-02-01 15:55:40 +01:00
|
|
|
tool->setWorkingDirectory(ui->workingDirectory->rawPath());
|
2011-01-24 15:01:48 +01:00
|
|
|
tool->setOutputHandling((ExternalTool::OutputHandling)ui->outputBehavior->currentIndex());
|
|
|
|
|
tool->setErrorHandling((ExternalTool::OutputHandling)ui->errorOutputBehavior->currentIndex());
|
|
|
|
|
tool->setModifiesCurrentDocument(ui->modifiesDocumentCheckbox->checkState());
|
|
|
|
|
tool->setInput(ui->inputText->toPlainText());
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-06 18:26:09 +01:00
|
|
|
void ExternalToolConfig::showInfoForItem(QTreeWidgetItem *item)
|
|
|
|
|
{
|
2011-02-01 15:55:40 +01:00
|
|
|
updateButtons(item);
|
2011-01-06 18:26:09 +01:00
|
|
|
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-02-01 15:55:40 +01:00
|
|
|
bool blocked = ui->inputText->blockSignals(true);
|
2011-01-06 18:26:09 +01:00
|
|
|
ui->inputText->setPlainText(tool->input());
|
2011-02-01 15:55:40 +01:00
|
|
|
ui->inputText->blockSignals(blocked);
|
2011-01-06 18:26:09 +01:00
|
|
|
ui->description->setCursorPosition(0);
|
|
|
|
|
ui->arguments->setCursorPosition(0);
|
|
|
|
|
}
|
2011-01-21 10:58:06 +01:00
|
|
|
|
2011-01-24 15:01:48 +01:00
|
|
|
void ExternalToolConfig::updateItemName(QTreeWidgetItem *item)
|
2011-01-21 10:58:06 +01:00
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
}
|
2011-02-01 15:55:40 +01:00
|
|
|
updateButtons(item);
|
2011-01-21 10:58:06 +01:00
|
|
|
}
|
2011-01-24 15:01:48 +01:00
|
|
|
|
|
|
|
|
QMap<QString, QList<ExternalTool *> > ExternalToolConfig::tools() const
|
|
|
|
|
{
|
|
|
|
|
return m_tools;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExternalToolConfig::apply()
|
|
|
|
|
{
|
|
|
|
|
updateItem(ui->toolTree->currentItem());
|
2011-02-01 15:55:40 +01:00
|
|
|
updateButtons(ui->toolTree->currentItem());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExternalToolConfig::revertCurrentItem()
|
|
|
|
|
{
|
|
|
|
|
QTreeWidgetItem *currentItem = ui->toolTree->currentItem();
|
|
|
|
|
QTC_ASSERT(currentItem, return);
|
|
|
|
|
ExternalTool *tool = currentItem->data(0, Qt::UserRole).value<ExternalTool *>();
|
|
|
|
|
QTC_ASSERT(tool, return);
|
|
|
|
|
QTC_ASSERT(tool->preset() && !tool->preset()->fileName().isEmpty(), return);
|
|
|
|
|
ExternalTool *resetTool = new ExternalTool(tool->preset().data());
|
|
|
|
|
resetTool->setPreset(tool->preset());
|
|
|
|
|
bool blocked = ui->toolTree->blockSignals(true); // block itemChanged
|
|
|
|
|
currentItem->setData(0, Qt::UserRole, qVariantFromValue(resetTool));
|
|
|
|
|
currentItem->setData(0, Qt::DisplayRole, resetTool->displayName());
|
|
|
|
|
ui->toolTree->blockSignals(blocked); // unblock itemChanged
|
|
|
|
|
showInfoForItem(currentItem);
|
|
|
|
|
QMutableMapIterator<QString, QList<ExternalTool *> > it(m_tools);
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
|
|
|
|
QList<ExternalTool *> &items = it.value();
|
|
|
|
|
int index = items.indexOf(tool);
|
|
|
|
|
if (index != -1) {
|
|
|
|
|
items[index] = resetTool;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
delete tool;
|
2011-01-24 15:01:48 +01:00
|
|
|
}
|