2011-01-06 18:26:09 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-02-21 14:57:44 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2011-01-06 18:26:09 +01:00
|
|
|
**
|
|
|
|
|
** 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-02-02 17:04:51 +01:00
|
|
|
#include <QtGui/QMenu>
|
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;
|
|
|
|
|
|
2011-02-08 12:28:35 +01:00
|
|
|
|
|
|
|
|
static const Qt::ItemFlags TOOLSMENU_ITEM_FLAGS = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled;
|
|
|
|
|
static const Qt::ItemFlags CATEGORY_ITEM_FLAGS = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEditable;
|
2011-02-08 17:11:00 +01:00
|
|
|
static const Qt::ItemFlags TOOL_ITEM_FLAGS = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsEditable;
|
2011-02-08 12:28:35 +01:00
|
|
|
|
|
|
|
|
// #pragma mark -- ExternalToolModel
|
|
|
|
|
|
|
|
|
|
ExternalToolModel::ExternalToolModel(QObject *parent)
|
|
|
|
|
: QAbstractItemModel(parent)
|
|
|
|
|
{
|
2011-02-08 17:11:00 +01:00
|
|
|
setSupportedDragActions(Qt::MoveAction);
|
2011-02-08 12:28:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExternalToolModel::~ExternalToolModel()
|
|
|
|
|
{
|
|
|
|
|
QMapIterator<QString, QList<ExternalTool *> > it(m_tools);
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
|
|
|
|
qDeleteAll(it.value());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-08 17:11:00 +01:00
|
|
|
Qt::DropActions ExternalToolModel::supportedDropActions() const
|
|
|
|
|
{
|
|
|
|
|
return Qt::MoveAction;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-08 12:28:35 +01:00
|
|
|
int ExternalToolModel::columnCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
|
|
|
|
if (!parent.isValid() || toolForIndex(parent) || !categoryForIndex(parent).isNull())
|
|
|
|
|
return 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant ExternalToolModel::data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
|
|
|
|
if (ExternalTool *tool = toolForIndex(index))
|
|
|
|
|
return data(tool, role);
|
|
|
|
|
QString category = categoryForIndex(index);
|
|
|
|
|
if (!category.isNull())
|
|
|
|
|
return data(category, role);
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant ExternalToolModel::data(ExternalTool *tool, int role) const
|
|
|
|
|
{
|
|
|
|
|
switch (role) {
|
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
|
case Qt::EditRole:
|
|
|
|
|
return tool->displayName();
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant ExternalToolModel::data(const QString &category, int role) const
|
|
|
|
|
{
|
|
|
|
|
switch (role) {
|
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
|
case Qt::EditRole:
|
|
|
|
|
return category.isEmpty() ? tr("External Tools Menu") : category;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-08 17:11:00 +01:00
|
|
|
QMimeData *ExternalToolModel::mimeData(const QModelIndexList &indexes) const
|
|
|
|
|
{
|
|
|
|
|
if (indexes.isEmpty())
|
|
|
|
|
return 0;
|
|
|
|
|
QModelIndex modelIndex = indexes.first();
|
|
|
|
|
ExternalTool *tool = toolForIndex(modelIndex);
|
|
|
|
|
QTC_ASSERT(tool, return 0);
|
|
|
|
|
QString category = categoryForIndex(modelIndex.parent());
|
|
|
|
|
QTC_ASSERT(!category.isNull(), return 0);
|
|
|
|
|
QMimeData *md = new QMimeData();
|
|
|
|
|
QByteArray ba;
|
|
|
|
|
QDataStream stream(&ba, QIODevice::WriteOnly);
|
|
|
|
|
stream << category << m_tools.value(category).indexOf(tool);
|
|
|
|
|
md->setData(QLatin1String("application/qtcreator-externaltool-config"), ba);
|
|
|
|
|
return md;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ExternalToolModel::dropMimeData(const QMimeData *data,
|
|
|
|
|
Qt::DropAction action,
|
|
|
|
|
int row,
|
|
|
|
|
int column,
|
|
|
|
|
const QModelIndex &parent)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(column)
|
|
|
|
|
if (action != Qt::MoveAction || !data)
|
|
|
|
|
return false;
|
|
|
|
|
QString toCategory = categoryForIndex(parent);
|
|
|
|
|
QTC_ASSERT(!toCategory.isNull(), return false);
|
|
|
|
|
QByteArray ba = data->data(QLatin1String("application/qtcreator-externaltool-config"));
|
|
|
|
|
if (ba.isEmpty())
|
|
|
|
|
return false;
|
|
|
|
|
QDataStream stream(&ba, QIODevice::ReadOnly);
|
|
|
|
|
QString category;
|
|
|
|
|
int pos = -1;
|
|
|
|
|
stream >> category;
|
|
|
|
|
stream >> pos;
|
|
|
|
|
QTC_ASSERT(!category.isNull(), return false);
|
|
|
|
|
QList<ExternalTool *> &items = m_tools[category];
|
|
|
|
|
QTC_ASSERT(pos >= 0 && pos < items.count(), return false);
|
|
|
|
|
beginRemoveRows(index(m_tools.keys().indexOf(category), 0), pos, pos);
|
|
|
|
|
ExternalTool *tool = items.takeAt(pos);
|
|
|
|
|
endRemoveRows();
|
|
|
|
|
if (row < 0)
|
|
|
|
|
row = m_tools.value(toCategory).count();
|
|
|
|
|
beginInsertRows(index(m_tools.keys().indexOf(toCategory), 0), row, row);
|
|
|
|
|
m_tools[toCategory].insert(row, tool);
|
|
|
|
|
endInsertRows();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList ExternalToolModel::mimeTypes() const
|
|
|
|
|
{
|
|
|
|
|
return QStringList() << QLatin1String("application/qtcreator-externaltool-config");
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-08 12:28:35 +01:00
|
|
|
QModelIndex ExternalToolModel::index(int row, int column, const QModelIndex &parent) const
|
|
|
|
|
{
|
|
|
|
|
if (column == 0 && parent.isValid()) {
|
|
|
|
|
QString category = categoryForIndex(parent);
|
|
|
|
|
if (!category.isNull()) {
|
|
|
|
|
QList<ExternalTool *> items = m_tools.value(category);
|
|
|
|
|
if (row < items.count()) {
|
|
|
|
|
return createIndex(row, 0, items.at(row));
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-28 12:46:58 +01:00
|
|
|
} else if (column == 0 && row < m_tools.keys().count()) {
|
2011-02-08 17:11:00 +01:00
|
|
|
return createIndex(row, 0);
|
2011-02-28 12:46:58 +01:00
|
|
|
}
|
2011-02-08 17:11:00 +01:00
|
|
|
return QModelIndex();
|
2011-02-08 12:28:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QModelIndex ExternalToolModel::parent(const QModelIndex &child) const
|
|
|
|
|
{
|
|
|
|
|
if (ExternalTool *tool = toolForIndex(child)) {
|
|
|
|
|
int categoryIndex = 0;
|
|
|
|
|
QMapIterator<QString, QList<ExternalTool *> > it(m_tools);
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
|
|
|
|
if (it.value().contains(tool))
|
|
|
|
|
return index(categoryIndex, 0);
|
|
|
|
|
++categoryIndex;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return QModelIndex();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ExternalToolModel::rowCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
|
|
|
|
if (!parent.isValid())
|
|
|
|
|
return m_tools.keys().count();
|
|
|
|
|
if (toolForIndex(parent)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
QString category = categoryForIndex(parent);
|
|
|
|
|
if (!category.isNull()) {
|
|
|
|
|
return m_tools.value(category).count();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Qt::ItemFlags ExternalToolModel::flags(const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
if (toolForIndex(index))
|
|
|
|
|
return TOOL_ITEM_FLAGS;
|
|
|
|
|
QString category = categoryForIndex(index);
|
|
|
|
|
if (!category.isNull()) {
|
|
|
|
|
if (category.isEmpty())
|
|
|
|
|
return TOOLSMENU_ITEM_FLAGS;
|
|
|
|
|
return CATEGORY_ITEM_FLAGS;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ExternalToolModel::setData(const QModelIndex &modelIndex, const QVariant &value, int role)
|
|
|
|
|
{
|
|
|
|
|
if (role != Qt::EditRole)
|
|
|
|
|
return false;
|
|
|
|
|
QString string = value.toString();
|
|
|
|
|
if (ExternalTool *tool = toolForIndex(modelIndex)) {
|
|
|
|
|
if (string.isEmpty() || tool->displayName() == string)
|
|
|
|
|
return false;
|
|
|
|
|
// rename tool
|
|
|
|
|
tool->setDisplayName(string);
|
|
|
|
|
emit dataChanged(modelIndex, modelIndex);
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
QString category = categoryForIndex(modelIndex);
|
|
|
|
|
if (!category.isNull()) {
|
|
|
|
|
if (string.isEmpty() || m_tools.contains(string))
|
|
|
|
|
return false;
|
|
|
|
|
// rename category
|
|
|
|
|
QList<QString> categories = m_tools.keys();
|
|
|
|
|
int previousIndex = categories.indexOf(category);
|
2011-02-08 17:11:00 +01:00
|
|
|
categories.removeAt(previousIndex);
|
2011-02-08 12:28:35 +01:00
|
|
|
categories.append(string);
|
|
|
|
|
qSort(categories);
|
|
|
|
|
int newIndex = categories.indexOf(string);
|
2011-02-08 17:11:00 +01:00
|
|
|
if (newIndex != previousIndex)
|
|
|
|
|
beginMoveRows(QModelIndex(), previousIndex, previousIndex, QModelIndex(), newIndex);
|
2011-02-08 12:28:35 +01:00
|
|
|
QList<ExternalTool *> items = m_tools.take(category);
|
|
|
|
|
m_tools.insert(string, items);
|
2011-02-08 17:11:00 +01:00
|
|
|
if (newIndex != previousIndex)
|
|
|
|
|
endMoveRows();
|
2011-02-08 12:28:35 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExternalToolModel::setTools(const QMap<QString, QList<ExternalTool *> > &tools)
|
|
|
|
|
{
|
|
|
|
|
beginResetModel();
|
|
|
|
|
m_tools = tools;
|
|
|
|
|
endResetModel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMap<QString, QList<ExternalTool *> > ExternalToolModel::tools() const
|
|
|
|
|
{
|
|
|
|
|
return m_tools;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExternalTool *ExternalToolModel::toolForIndex(const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
return static_cast<ExternalTool *>(index.internalPointer());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ExternalToolModel::categoryForIndex(const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
if (index.isValid() && !index.parent().isValid() && index.column() == 0 && index.row() >= 0) {
|
|
|
|
|
const QList<QString> &keys = m_tools.keys();
|
|
|
|
|
if (index.row() < keys.count())
|
|
|
|
|
return keys.at(index.row());
|
|
|
|
|
}
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExternalToolModel::revertTool(const QModelIndex &modelIndex)
|
|
|
|
|
{
|
|
|
|
|
ExternalTool *tool = toolForIndex(modelIndex);
|
|
|
|
|
QTC_ASSERT(tool, return);
|
|
|
|
|
QTC_ASSERT(tool->preset() && !tool->preset()->fileName().isEmpty(), return);
|
|
|
|
|
ExternalTool *resetTool = new ExternalTool(tool->preset().data());
|
|
|
|
|
resetTool->setPreset(tool->preset());
|
|
|
|
|
(*tool) = (*resetTool);
|
|
|
|
|
delete resetTool;
|
|
|
|
|
emit dataChanged(modelIndex, modelIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QModelIndex ExternalToolModel::addCategory()
|
|
|
|
|
{
|
|
|
|
|
const QString &categoryBase = tr("New category");
|
|
|
|
|
QString category = categoryBase;
|
|
|
|
|
int count = 0;
|
|
|
|
|
while (m_tools.contains(category)) {
|
|
|
|
|
++count;
|
|
|
|
|
category = categoryBase + QString::number(count);
|
|
|
|
|
}
|
|
|
|
|
QList<QString> categories = m_tools.keys();
|
|
|
|
|
categories.append(category);
|
|
|
|
|
qSort(categories);
|
|
|
|
|
int pos = categories.indexOf(category);
|
|
|
|
|
|
|
|
|
|
beginInsertRows(QModelIndex(), pos, pos);
|
|
|
|
|
m_tools.insert(category, QList<ExternalTool *>());
|
|
|
|
|
endInsertRows();
|
|
|
|
|
return index(pos, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QModelIndex ExternalToolModel::addTool(const QModelIndex &atIndex)
|
|
|
|
|
{
|
|
|
|
|
QString category = categoryForIndex(atIndex);
|
|
|
|
|
if (category.isNull())
|
|
|
|
|
category = categoryForIndex(atIndex.parent());
|
|
|
|
|
|
|
|
|
|
ExternalTool *tool = new ExternalTool;
|
2011-02-10 10:03:46 +01:00
|
|
|
tool->setDisplayCategory(category);
|
2011-02-08 12:28:35 +01:00
|
|
|
tool->setDisplayName(tr("New tool"));
|
|
|
|
|
tool->setDescription(tr("This tool prints a line of useful text"));
|
2011-02-28 15:03:48 +01:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
tool->setExecutables(QStringList() << "cmd");
|
|
|
|
|
tool->setArguments(tr("/c echo Useful text"));
|
|
|
|
|
#else
|
2011-02-08 12:28:35 +01:00
|
|
|
tool->setExecutables(QStringList() << "echo");
|
|
|
|
|
tool->setArguments(tr("Useful text"));
|
2011-02-28 15:03:48 +01:00
|
|
|
#endif
|
2011-02-08 12:28:35 +01:00
|
|
|
|
|
|
|
|
int pos;
|
|
|
|
|
QModelIndex parent;
|
|
|
|
|
if (atIndex.parent().isValid()) {
|
|
|
|
|
pos = atIndex.row() + 1;
|
|
|
|
|
parent = atIndex.parent();
|
|
|
|
|
} else {
|
|
|
|
|
pos = m_tools.value(category).count();
|
|
|
|
|
parent = atIndex;
|
|
|
|
|
}
|
|
|
|
|
beginInsertRows(parent, pos, pos);
|
|
|
|
|
m_tools[category].insert(pos, tool);
|
|
|
|
|
endInsertRows();
|
|
|
|
|
return index(pos, 0, parent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExternalToolModel::removeTool(const QModelIndex &modelIndex)
|
|
|
|
|
{
|
|
|
|
|
ExternalTool *tool = toolForIndex(modelIndex);
|
|
|
|
|
QTC_ASSERT(tool, return);
|
|
|
|
|
QTC_ASSERT(!tool->preset(), return);
|
|
|
|
|
// remove the tool and the tree item
|
|
|
|
|
int categoryIndex = 0;
|
|
|
|
|
QMutableMapIterator<QString, QList<ExternalTool *> > it(m_tools);
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
|
|
|
|
QList<ExternalTool *> &items = it.value();
|
|
|
|
|
int pos = items.indexOf(tool);
|
|
|
|
|
if (pos != -1) {
|
|
|
|
|
beginRemoveRows(index(categoryIndex, 0), pos, pos);
|
|
|
|
|
items.removeAt(pos);
|
|
|
|
|
endRemoveRows();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++categoryIndex;
|
|
|
|
|
}
|
|
|
|
|
delete tool;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// #pragma mark -- ExternalToolConfig
|
|
|
|
|
|
2011-01-06 18:26:09 +01:00
|
|
|
ExternalToolConfig::ExternalToolConfig(QWidget *parent) :
|
|
|
|
|
QWidget(parent),
|
2011-02-08 12:28:35 +01:00
|
|
|
ui(new Ui::ExternalToolConfig),
|
|
|
|
|
m_model(new ExternalToolModel(this))
|
2011-01-06 18:26:09 +01:00
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
2011-02-08 12:28:35 +01:00
|
|
|
ui->toolTree->setModel(m_model);
|
2011-01-21 10:58:06 +01:00
|
|
|
ui->toolTree->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed);
|
2011-02-08 12:28:35 +01:00
|
|
|
|
|
|
|
|
connect(ui->toolTree->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
|
|
|
|
|
this, SLOT(handleCurrentChanged(QModelIndex,QModelIndex)));
|
|
|
|
|
|
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()));
|
|
|
|
|
|
|
|
|
|
connect(ui->revertButton, SIGNAL(clicked()), this, SLOT(revertCurrentItem()));
|
2011-02-08 12:28:35 +01:00
|
|
|
connect(ui->addButton, SIGNAL(clicked()), this, SLOT(add()));
|
2011-02-02 13:35:48 +01:00
|
|
|
connect(ui->removeButton, SIGNAL(clicked()), this, SLOT(removeTool()));
|
2011-01-24 15:01:48 +01:00
|
|
|
|
2011-02-02 17:04:51 +01:00
|
|
|
QMenu *menu = new QMenu(ui->addButton);
|
|
|
|
|
ui->addButton->setMenu(menu);
|
|
|
|
|
QAction *addCategory = new QAction(tr("Add Category"), this);
|
|
|
|
|
menu->addAction(addCategory);
|
|
|
|
|
connect(addCategory, SIGNAL(triggered()), this, SLOT(addCategory()));
|
|
|
|
|
|
2011-02-08 12:28:35 +01:00
|
|
|
showInfoForItem(QModelIndex());
|
|
|
|
|
// updateButtons(ui->toolTree->currentItem());
|
2011-01-06 18:26:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExternalToolConfig::~ExternalToolConfig()
|
|
|
|
|
{
|
|
|
|
|
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-02-08 12:28:35 +01:00
|
|
|
QMap<QString, QList<ExternalTool *> > toolsCopy;
|
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));
|
2011-02-08 12:28:35 +01:00
|
|
|
toolsCopy.insert(it.key(), itemCopy);
|
2011-01-06 18:26:09 +01:00
|
|
|
}
|
2011-02-08 17:11:00 +01:00
|
|
|
if (!toolsCopy.contains(QLatin1String("")))
|
|
|
|
|
toolsCopy.insert(QLatin1String(""), QList<ExternalTool *>());
|
2011-02-08 12:28:35 +01:00
|
|
|
m_model->setTools(toolsCopy);
|
2011-01-06 18:26:09 +01:00
|
|
|
ui->toolTree->expandAll();
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-08 12:28:35 +01:00
|
|
|
void ExternalToolConfig::handleCurrentChanged(const QModelIndex &now, const QModelIndex &previous)
|
2011-01-24 15:01:48 +01:00
|
|
|
{
|
|
|
|
|
updateItem(previous);
|
|
|
|
|
showInfoForItem(now);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-08 12:28:35 +01:00
|
|
|
void ExternalToolConfig::updateButtons(const QModelIndex &index)
|
2011-02-01 15:55:40 +01:00
|
|
|
{
|
2011-02-08 12:28:35 +01:00
|
|
|
ExternalTool *tool = m_model->toolForIndex(index);
|
2011-02-01 15:55:40 +01:00
|
|
|
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()
|
|
|
|
|
{
|
2011-02-08 12:28:35 +01:00
|
|
|
QModelIndex index = ui->toolTree->selectionModel()->currentIndex();
|
|
|
|
|
updateItem(index);
|
|
|
|
|
updateButtons(index);
|
2011-02-01 15:55:40 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-08 12:28:35 +01:00
|
|
|
void ExternalToolConfig::updateItem(const QModelIndex &index)
|
2011-01-24 15:01:48 +01:00
|
|
|
{
|
2011-02-08 12:28:35 +01:00
|
|
|
ExternalTool *tool = m_model->toolForIndex(index);
|
2011-01-24 15:01:48 +01:00
|
|
|
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-02-08 12:28:35 +01:00
|
|
|
void ExternalToolConfig::showInfoForItem(const QModelIndex &index)
|
2011-01-06 18:26:09 +01:00
|
|
|
{
|
2011-02-08 12:28:35 +01:00
|
|
|
updateButtons(index);
|
|
|
|
|
ExternalTool *tool = m_model->toolForIndex(index);
|
2011-01-06 18:26:09 +01:00
|
|
|
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-08 12:28:35 +01:00
|
|
|
|
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-02-08 12:28:35 +01:00
|
|
|
|
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
|
|
|
QMap<QString, QList<ExternalTool *> > ExternalToolConfig::tools() const
|
|
|
|
|
{
|
2011-02-08 12:28:35 +01:00
|
|
|
return m_model->tools();
|
2011-01-24 15:01:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExternalToolConfig::apply()
|
|
|
|
|
{
|
2011-02-08 12:28:35 +01:00
|
|
|
QModelIndex index = ui->toolTree->selectionModel()->currentIndex();
|
|
|
|
|
updateItem(index);
|
|
|
|
|
updateButtons(index);
|
2011-02-01 15:55:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExternalToolConfig::revertCurrentItem()
|
|
|
|
|
{
|
2011-02-08 12:28:35 +01:00
|
|
|
QModelIndex index = ui->toolTree->selectionModel()->currentIndex();
|
|
|
|
|
m_model->revertTool(index);
|
|
|
|
|
showInfoForItem(index);
|
2011-01-24 15:01:48 +01:00
|
|
|
}
|
2011-02-02 12:35:32 +01:00
|
|
|
|
2011-02-08 12:28:35 +01:00
|
|
|
void ExternalToolConfig::add()
|
2011-02-02 12:35:32 +01:00
|
|
|
{
|
2011-02-08 12:28:35 +01:00
|
|
|
QModelIndex currentIndex = ui->toolTree->selectionModel()->currentIndex();
|
|
|
|
|
if (!currentIndex.isValid()) {
|
2011-02-02 17:04:51 +01:00
|
|
|
addCategory();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-02-08 12:28:35 +01:00
|
|
|
QModelIndex index = m_model->addTool(currentIndex);
|
|
|
|
|
ui->toolTree->selectionModel()->setCurrentIndex(index, QItemSelectionModel::Clear);
|
|
|
|
|
ui->toolTree->selectionModel()->setCurrentIndex(index, QItemSelectionModel::SelectCurrent);
|
|
|
|
|
ui->toolTree->edit(index);
|
2011-02-02 12:35:32 +01:00
|
|
|
}
|
2011-02-02 13:35:48 +01:00
|
|
|
|
|
|
|
|
void ExternalToolConfig::removeTool()
|
|
|
|
|
{
|
2011-02-08 12:28:35 +01:00
|
|
|
QModelIndex currentIndex = ui->toolTree->selectionModel()->currentIndex();
|
|
|
|
|
ui->toolTree->selectionModel()->setCurrentIndex(QModelIndex(), QItemSelectionModel::Clear);
|
|
|
|
|
m_model->removeTool(currentIndex);
|
2011-02-02 13:35:48 +01:00
|
|
|
}
|
2011-02-02 17:04:51 +01:00
|
|
|
|
|
|
|
|
void ExternalToolConfig::addCategory()
|
|
|
|
|
{
|
2011-02-08 12:28:35 +01:00
|
|
|
QModelIndex index = m_model->addCategory();
|
|
|
|
|
ui->toolTree->selectionModel()->setCurrentIndex(index, QItemSelectionModel::Clear);
|
|
|
|
|
ui->toolTree->selectionModel()->setCurrentIndex(index, QItemSelectionModel::SelectCurrent);
|
|
|
|
|
ui->toolTree->edit(index);
|
2011-02-02 17:04:51 +01:00
|
|
|
}
|