2014-03-11 16:08:08 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-03-11 16:08:08 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** 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.
|
2014-03-11 16:08:08 +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.
|
2014-03-11 16:08:08 +01:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
2016-01-15 14:57:40 +01:00
|
|
|
|
2015-02-24 21:57:00 +01:00
|
|
|
#include "cmakeprojectconstants.h"
|
2014-03-11 16:08:08 +01:00
|
|
|
#include "cmakesettingspage.h"
|
2015-02-04 17:54:46 +01:00
|
|
|
#include "cmaketoolmanager.h"
|
2014-03-11 16:08:08 +01:00
|
|
|
|
|
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2018-02-28 18:15:57 +01:00
|
|
|
#include <projectexplorer/projectexplorericons.h>
|
2014-03-11 16:08:08 +01:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <utils/environment.h>
|
2015-02-04 17:54:46 +01:00
|
|
|
#include <utils/detailswidget.h>
|
|
|
|
|
#include <utils/pathchooser.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
2018-03-28 16:03:11 +02:00
|
|
|
#include <utils/stringutils.h>
|
2015-02-04 17:54:46 +01:00
|
|
|
#include <utils/treemodel.h>
|
2014-03-11 16:08:08 +01:00
|
|
|
|
2016-06-27 13:09:14 +02:00
|
|
|
#include <QCheckBox>
|
2014-03-11 16:08:08 +01:00
|
|
|
#include <QFormLayout>
|
2015-02-04 17:54:46 +01:00
|
|
|
#include <QHeaderView>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QLineEdit>
|
|
|
|
|
#include <QPushButton>
|
|
|
|
|
#include <QTreeView>
|
|
|
|
|
#include <QWidget>
|
|
|
|
|
#include <QUuid>
|
2014-03-11 16:08:08 +01:00
|
|
|
|
2015-02-04 17:54:46 +01:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2014-03-11 16:08:08 +01:00
|
|
|
namespace CMakeProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2015-02-04 17:54:46 +01:00
|
|
|
class CMakeToolTreeItem;
|
2014-03-11 16:08:08 +01:00
|
|
|
|
2015-02-04 17:54:46 +01:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
// CMakeToolItemModel
|
|
|
|
|
// --------------------------------------------------------------------------
|
2014-03-11 16:08:08 +01:00
|
|
|
|
2016-06-24 09:36:42 +02:00
|
|
|
class CMakeToolItemModel : public TreeModel<TreeItem, TreeItem, CMakeToolTreeItem>
|
2014-03-11 16:08:08 +01:00
|
|
|
{
|
2015-02-04 17:54:46 +01:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(CMakeProjectManager::CMakeSettingsPage)
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
CMakeToolItemModel();
|
|
|
|
|
|
|
|
|
|
CMakeToolTreeItem *cmakeToolItem(const Core::Id &id) const;
|
|
|
|
|
CMakeToolTreeItem *cmakeToolItem(const QModelIndex &index) const;
|
2017-09-07 14:00:29 +02:00
|
|
|
QModelIndex addCMakeTool(const QString &name, const FileName &executable, const bool autoRun, const bool autoCreate, const bool isAutoDetected);
|
2016-06-10 14:30:57 +02:00
|
|
|
void addCMakeTool(const CMakeTool *item, bool changed);
|
2015-02-04 17:54:46 +01:00
|
|
|
TreeItem *autoGroupItem() const;
|
|
|
|
|
TreeItem *manualGroupItem() const;
|
|
|
|
|
void reevaluateChangedFlag(CMakeToolTreeItem *item) const;
|
2016-06-27 13:09:14 +02:00
|
|
|
void updateCMakeTool(const Core::Id &id, const QString &displayName, const FileName &executable,
|
2017-09-07 14:00:29 +02:00
|
|
|
bool autoRun, bool autoCreate);
|
2015-02-04 17:54:46 +01:00
|
|
|
void removeCMakeTool(const Core::Id &id);
|
|
|
|
|
void apply();
|
|
|
|
|
|
|
|
|
|
Core::Id defaultItemId() const;
|
|
|
|
|
void setDefaultItemId(const Core::Id &id);
|
|
|
|
|
|
|
|
|
|
QString uniqueDisplayName(const QString &base) const;
|
|
|
|
|
private:
|
|
|
|
|
Core::Id m_defaultItemId;
|
|
|
|
|
QList<Core::Id> m_removedItems;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class CMakeToolTreeItem : public TreeItem
|
|
|
|
|
{
|
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(CMakeProjectManager::CMakeSettingsPage)
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
CMakeToolTreeItem(const CMakeTool *item, bool changed) :
|
|
|
|
|
m_id(item->id()),
|
|
|
|
|
m_name(item->displayName()),
|
|
|
|
|
m_executable(item->cmakeExecutable()),
|
2016-06-27 13:09:14 +02:00
|
|
|
m_isAutoRun(item->isAutoRun()),
|
2017-09-07 14:00:29 +02:00
|
|
|
m_autoCreateBuildDirectory(item->autoCreateBuildDirectory()),
|
2015-02-04 17:54:46 +01:00
|
|
|
m_autodetected(item->isAutoDetected()),
|
|
|
|
|
m_changed(changed)
|
|
|
|
|
{}
|
|
|
|
|
|
2016-06-27 13:09:14 +02:00
|
|
|
CMakeToolTreeItem(const QString &name, const Utils::FileName &executable,
|
2017-09-07 14:00:29 +02:00
|
|
|
bool autoRun, bool autoCreate, bool autodetected) :
|
2015-02-04 17:54:46 +01:00
|
|
|
m_id(Core::Id::fromString(QUuid::createUuid().toString())),
|
|
|
|
|
m_name(name),
|
|
|
|
|
m_executable(executable),
|
2016-06-27 13:09:14 +02:00
|
|
|
m_isAutoRun(autoRun),
|
2017-09-07 14:00:29 +02:00
|
|
|
m_autoCreateBuildDirectory(autoCreate),
|
2015-02-04 17:54:46 +01:00
|
|
|
m_autodetected(autodetected),
|
|
|
|
|
m_changed(true)
|
|
|
|
|
{}
|
|
|
|
|
|
2016-06-27 13:09:14 +02:00
|
|
|
CMakeToolTreeItem() = default;
|
2014-03-11 16:08:08 +01:00
|
|
|
|
2015-02-04 17:54:46 +01:00
|
|
|
CMakeToolItemModel *model() const { return static_cast<CMakeToolItemModel *>(TreeItem::model()); }
|
2014-03-11 16:08:08 +01:00
|
|
|
|
2015-02-04 17:54:46 +01:00
|
|
|
QVariant data(int column, int role) const
|
|
|
|
|
{
|
|
|
|
|
switch (role) {
|
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
|
switch (column) {
|
|
|
|
|
case 0: {
|
|
|
|
|
QString name = m_name;
|
|
|
|
|
if (model()->defaultItemId() == m_id)
|
|
|
|
|
name += tr(" (Default)");
|
|
|
|
|
return name;
|
|
|
|
|
}
|
2017-06-02 16:12:53 +03:00
|
|
|
case 1:
|
|
|
|
|
return m_executable.toUserOutput();
|
2015-02-04 17:54:46 +01:00
|
|
|
}
|
2017-06-02 16:12:53 +03:00
|
|
|
break;
|
2015-02-04 17:54:46 +01:00
|
|
|
|
|
|
|
|
case Qt::FontRole: {
|
|
|
|
|
QFont font;
|
|
|
|
|
font.setBold(m_changed);
|
|
|
|
|
font.setItalic(model()->defaultItemId() == m_id);
|
|
|
|
|
return font;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::Id m_id;
|
|
|
|
|
QString m_name;
|
|
|
|
|
FileName m_executable;
|
2016-06-27 13:09:14 +02:00
|
|
|
bool m_isAutoRun = true;
|
2017-09-07 14:00:29 +02:00
|
|
|
bool m_autoCreateBuildDirectory = false;
|
2016-06-27 13:09:14 +02:00
|
|
|
bool m_autodetected = false;
|
|
|
|
|
bool m_changed = true;
|
2015-02-04 17:54:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CMakeToolItemModel::CMakeToolItemModel()
|
|
|
|
|
{
|
2016-06-15 12:47:30 +02:00
|
|
|
setHeader({tr("Name"), tr("Location")});
|
2016-06-17 08:24:47 +02:00
|
|
|
rootItem()->appendChild(new StaticTreeItem(tr("Auto-detected")));
|
|
|
|
|
rootItem()->appendChild(new StaticTreeItem(tr("Manual")));
|
2015-02-04 17:54:46 +01:00
|
|
|
|
|
|
|
|
foreach (const CMakeTool *item, CMakeToolManager::cmakeTools())
|
|
|
|
|
addCMakeTool(item, false);
|
|
|
|
|
|
|
|
|
|
CMakeTool *defTool = CMakeToolManager::defaultCMakeTool();
|
|
|
|
|
m_defaultItemId = defTool ? defTool->id() : Core::Id();
|
2016-05-30 10:56:12 +02:00
|
|
|
connect(CMakeToolManager::instance(), &CMakeToolManager::cmakeRemoved,
|
|
|
|
|
this, &CMakeToolItemModel::removeCMakeTool);
|
|
|
|
|
connect(CMakeToolManager::instance(), &CMakeToolManager::cmakeAdded,
|
|
|
|
|
this, [this](const Core::Id &id) { addCMakeTool(CMakeToolManager::findById(id), false); });
|
|
|
|
|
|
2014-03-11 16:08:08 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-27 13:09:14 +02:00
|
|
|
QModelIndex CMakeToolItemModel::addCMakeTool(const QString &name, const FileName &executable,
|
2017-09-07 14:00:29 +02:00
|
|
|
const bool autoRun, const bool autoCreate,
|
|
|
|
|
const bool isAutoDetected)
|
2014-03-11 16:08:08 +01:00
|
|
|
{
|
2017-09-07 14:00:29 +02:00
|
|
|
CMakeToolTreeItem *item = new CMakeToolTreeItem(name, executable, autoRun, autoCreate, isAutoDetected);
|
2015-02-04 17:54:46 +01:00
|
|
|
if (isAutoDetected)
|
|
|
|
|
autoGroupItem()->appendChild(item);
|
|
|
|
|
else
|
|
|
|
|
manualGroupItem()->appendChild(item);
|
2014-03-11 16:08:08 +01:00
|
|
|
|
2015-02-04 17:54:46 +01:00
|
|
|
return item->index();
|
2014-03-11 16:08:08 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-10 14:30:57 +02:00
|
|
|
void CMakeToolItemModel::addCMakeTool(const CMakeTool *item, bool changed)
|
2015-02-04 17:54:46 +01:00
|
|
|
{
|
2016-12-05 14:52:29 +01:00
|
|
|
QTC_ASSERT(item, return);
|
|
|
|
|
|
2016-06-10 14:30:57 +02:00
|
|
|
if (cmakeToolItem(item->id()))
|
|
|
|
|
return;
|
|
|
|
|
|
2015-02-04 17:54:46 +01:00
|
|
|
CMakeToolTreeItem *treeItem = new CMakeToolTreeItem(item, changed);
|
|
|
|
|
if (item->isAutoDetected())
|
|
|
|
|
autoGroupItem()->appendChild(treeItem);
|
|
|
|
|
else
|
|
|
|
|
manualGroupItem()->appendChild(treeItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TreeItem *CMakeToolItemModel::autoGroupItem() const
|
2014-03-11 16:08:08 +01:00
|
|
|
{
|
2016-07-06 13:38:00 +02:00
|
|
|
return rootItem()->childAt(0);
|
2014-03-11 16:08:08 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-04 17:54:46 +01:00
|
|
|
TreeItem *CMakeToolItemModel::manualGroupItem() const
|
2014-03-11 16:08:08 +01:00
|
|
|
{
|
2016-07-06 13:38:00 +02:00
|
|
|
return rootItem()->childAt(1);
|
2014-03-11 16:08:08 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-04 17:54:46 +01:00
|
|
|
void CMakeToolItemModel::reevaluateChangedFlag(CMakeToolTreeItem *item) const
|
2014-03-11 16:08:08 +01:00
|
|
|
{
|
2015-02-04 17:54:46 +01:00
|
|
|
CMakeTool *orig = CMakeToolManager::findById(item->m_id);
|
|
|
|
|
item->m_changed = !orig || orig->displayName() != item->m_name
|
|
|
|
|
|| orig->cmakeExecutable() != item->m_executable;
|
|
|
|
|
|
|
|
|
|
//make sure the item is marked as changed when the default cmake was changed
|
|
|
|
|
CMakeTool *origDefTool = CMakeToolManager::defaultCMakeTool();
|
|
|
|
|
Core::Id origDefault = origDefTool ? origDefTool->id() : Core::Id();
|
|
|
|
|
if (origDefault != m_defaultItemId) {
|
|
|
|
|
if (item->m_id == origDefault || item->m_id == m_defaultItemId)
|
|
|
|
|
item->m_changed = true;
|
2014-03-11 16:08:08 +01:00
|
|
|
}
|
2015-02-04 17:54:46 +01:00
|
|
|
|
|
|
|
|
item->update(); // Notify views.
|
2014-03-11 16:08:08 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-04 17:54:46 +01:00
|
|
|
void CMakeToolItemModel::updateCMakeTool(const Core::Id &id, const QString &displayName,
|
2017-09-07 14:00:29 +02:00
|
|
|
const FileName &executable, bool autoRun,
|
|
|
|
|
bool autoCreate)
|
2014-03-11 16:08:08 +01:00
|
|
|
{
|
2015-02-04 17:54:46 +01:00
|
|
|
CMakeToolTreeItem *treeItem = cmakeToolItem(id);
|
|
|
|
|
QTC_ASSERT(treeItem, return);
|
|
|
|
|
|
|
|
|
|
treeItem->m_name = displayName;
|
|
|
|
|
treeItem->m_executable = executable;
|
2016-06-27 13:09:14 +02:00
|
|
|
treeItem->m_isAutoRun = autoRun;
|
2017-09-07 14:00:29 +02:00
|
|
|
treeItem->m_autoCreateBuildDirectory = autoCreate;
|
2015-02-04 17:54:46 +01:00
|
|
|
|
|
|
|
|
reevaluateChangedFlag(treeItem);
|
2014-03-11 16:08:08 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-04 17:54:46 +01:00
|
|
|
CMakeToolTreeItem *CMakeToolItemModel::cmakeToolItem(const Core::Id &id) const
|
|
|
|
|
{
|
2016-06-24 09:36:42 +02:00
|
|
|
return findItemAtLevel<2>([id](CMakeToolTreeItem *n) { return n->m_id == id; });
|
2015-02-04 17:54:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CMakeToolTreeItem *CMakeToolItemModel::cmakeToolItem(const QModelIndex &index) const
|
|
|
|
|
{
|
2016-06-24 09:36:42 +02:00
|
|
|
return itemForIndexAtLevel<2>(index);
|
2015-02-04 17:54:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeToolItemModel::removeCMakeTool(const Core::Id &id)
|
|
|
|
|
{
|
|
|
|
|
CMakeToolTreeItem *treeItem = cmakeToolItem(id);
|
|
|
|
|
QTC_ASSERT(treeItem, return);
|
|
|
|
|
|
2016-07-04 15:53:53 +02:00
|
|
|
destroyItem(treeItem);
|
2015-02-04 17:54:46 +01:00
|
|
|
m_removedItems.append(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeToolItemModel::apply()
|
|
|
|
|
{
|
|
|
|
|
foreach (const Core::Id &id, m_removedItems)
|
|
|
|
|
CMakeToolManager::deregisterCMakeTool(id);
|
|
|
|
|
|
2016-06-10 14:30:57 +02:00
|
|
|
QList<CMakeToolTreeItem *> toRegister;
|
2016-06-24 09:36:42 +02:00
|
|
|
forItemsAtLevel<2>([&toRegister](CMakeToolTreeItem *item) {
|
2015-02-04 17:54:46 +01:00
|
|
|
item->m_changed = false;
|
2016-06-10 14:30:57 +02:00
|
|
|
if (CMakeTool *cmake = CMakeToolManager::findById(item->m_id)) {
|
|
|
|
|
cmake->setDisplayName(item->m_name);
|
|
|
|
|
cmake->setCMakeExecutable(item->m_executable);
|
2016-06-27 13:09:14 +02:00
|
|
|
cmake->setAutorun(item->m_isAutoRun);
|
2017-09-07 14:00:29 +02:00
|
|
|
cmake->setAutoCreateBuildDirectory(item->m_autoCreateBuildDirectory);
|
2016-06-10 14:30:57 +02:00
|
|
|
} else {
|
|
|
|
|
toRegister.append(item);
|
2015-02-04 17:54:46 +01:00
|
|
|
}
|
2016-06-10 14:30:57 +02:00
|
|
|
});
|
2015-02-04 17:54:46 +01:00
|
|
|
|
2016-06-10 14:30:57 +02:00
|
|
|
foreach (CMakeToolTreeItem *item, toRegister) {
|
|
|
|
|
CMakeTool::Detection detection = item->m_autodetected ? CMakeTool::AutoDetection
|
|
|
|
|
: CMakeTool::ManualDetection;
|
|
|
|
|
CMakeTool *cmake = new CMakeTool(detection, item->m_id);
|
2015-02-04 17:54:46 +01:00
|
|
|
cmake->setDisplayName(item->m_name);
|
|
|
|
|
cmake->setCMakeExecutable(item->m_executable);
|
2016-06-10 14:30:57 +02:00
|
|
|
if (!CMakeToolManager::registerCMakeTool(cmake)) {
|
|
|
|
|
item->m_changed = true;
|
|
|
|
|
delete cmake;
|
2015-02-04 17:54:46 +01:00
|
|
|
}
|
2016-06-10 14:30:57 +02:00
|
|
|
}
|
2015-02-04 17:54:46 +01:00
|
|
|
|
|
|
|
|
CMakeToolManager::setDefaultCMakeTool(defaultItemId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::Id CMakeToolItemModel::defaultItemId() const
|
2014-03-11 16:08:08 +01:00
|
|
|
{
|
2015-02-04 17:54:46 +01:00
|
|
|
return m_defaultItemId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeToolItemModel::setDefaultItemId(const Core::Id &id)
|
|
|
|
|
{
|
|
|
|
|
if (m_defaultItemId == id)
|
2014-03-11 16:08:08 +01:00
|
|
|
return;
|
2015-02-04 17:54:46 +01:00
|
|
|
|
|
|
|
|
Core::Id oldDefaultId = m_defaultItemId;
|
|
|
|
|
m_defaultItemId = id;
|
|
|
|
|
|
|
|
|
|
CMakeToolTreeItem *newDefault = cmakeToolItem(id);
|
|
|
|
|
if (newDefault)
|
|
|
|
|
reevaluateChangedFlag(newDefault);
|
|
|
|
|
|
|
|
|
|
CMakeToolTreeItem *oldDefault = cmakeToolItem(oldDefaultId);
|
|
|
|
|
if (oldDefault)
|
|
|
|
|
reevaluateChangedFlag(oldDefault);
|
2014-03-11 16:08:08 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-04 17:54:46 +01:00
|
|
|
|
|
|
|
|
QString CMakeToolItemModel::uniqueDisplayName(const QString &base) const
|
2014-03-11 16:08:08 +01:00
|
|
|
{
|
2015-02-04 17:54:46 +01:00
|
|
|
QStringList names;
|
2016-06-24 09:36:42 +02:00
|
|
|
forItemsAtLevel<2>([&names](CMakeToolTreeItem *item) { names << item->m_name; });
|
2018-03-28 16:03:11 +02:00
|
|
|
return Utils::makeUniquelyNumbered(base, names);
|
2015-02-04 17:54:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
// CMakeToolItemConfigWidget
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
class CMakeToolItemConfigWidget : public QWidget
|
|
|
|
|
{
|
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(CMakeProjectManager::CMakeSettingsPage)
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit CMakeToolItemConfigWidget(CMakeToolItemModel *model);
|
|
|
|
|
void load(const CMakeToolTreeItem *item);
|
|
|
|
|
void store() const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
CMakeToolItemModel *m_model;
|
|
|
|
|
QLineEdit *m_displayNameLineEdit;
|
2016-06-27 13:09:14 +02:00
|
|
|
QCheckBox *m_autoRunCheckBox;
|
2017-09-07 14:00:29 +02:00
|
|
|
QCheckBox *m_autoCreateBuildDirectoryCheckBox;
|
2015-02-04 17:54:46 +01:00
|
|
|
PathChooser *m_binaryChooser;
|
|
|
|
|
Core::Id m_id;
|
|
|
|
|
bool m_loadingItem;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CMakeToolItemConfigWidget::CMakeToolItemConfigWidget(CMakeToolItemModel *model)
|
|
|
|
|
: m_model(model), m_loadingItem(false)
|
|
|
|
|
{
|
|
|
|
|
m_displayNameLineEdit = new QLineEdit(this);
|
|
|
|
|
|
|
|
|
|
m_binaryChooser = new PathChooser(this);
|
|
|
|
|
m_binaryChooser->setExpectedKind(PathChooser::ExistingCommand);
|
|
|
|
|
m_binaryChooser->setMinimumWidth(400);
|
|
|
|
|
m_binaryChooser->setHistoryCompleter(QLatin1String("Cmake.Command.History"));
|
2017-02-22 15:09:35 +01:00
|
|
|
m_binaryChooser->setCommandVersionArguments({"--version"});
|
2015-02-04 17:54:46 +01:00
|
|
|
|
2016-06-27 13:09:14 +02:00
|
|
|
m_autoRunCheckBox = new QCheckBox;
|
2016-08-29 13:41:55 +02:00
|
|
|
m_autoRunCheckBox->setText(tr("Autorun CMake"));
|
2016-08-29 13:42:16 +02:00
|
|
|
m_autoRunCheckBox->setToolTip(tr("Automatically run CMake after changes to CMake project files."));
|
2016-06-27 13:09:14 +02:00
|
|
|
|
2017-09-07 14:00:29 +02:00
|
|
|
m_autoCreateBuildDirectoryCheckBox = new QCheckBox;
|
|
|
|
|
m_autoCreateBuildDirectoryCheckBox->setText(tr("Auto-create build directories"));
|
|
|
|
|
m_autoCreateBuildDirectoryCheckBox->setToolTip(tr("Automatically create build directories for CMake projects."));
|
|
|
|
|
|
2015-02-04 17:54:46 +01:00
|
|
|
QFormLayout *formLayout = new QFormLayout(this);
|
|
|
|
|
formLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
|
|
|
|
|
formLayout->addRow(new QLabel(tr("Name:")), m_displayNameLineEdit);
|
|
|
|
|
formLayout->addRow(new QLabel(tr("Path:")), m_binaryChooser);
|
2016-06-27 13:09:14 +02:00
|
|
|
formLayout->addRow(m_autoRunCheckBox);
|
2017-09-07 14:00:29 +02:00
|
|
|
formLayout->addRow(m_autoCreateBuildDirectoryCheckBox);
|
2015-02-04 17:54:46 +01:00
|
|
|
|
2015-08-20 14:56:30 +02:00
|
|
|
connect(m_binaryChooser, &PathChooser::rawPathChanged,
|
2015-02-04 17:54:46 +01:00
|
|
|
this, &CMakeToolItemConfigWidget::store);
|
|
|
|
|
connect(m_displayNameLineEdit, &QLineEdit::textChanged,
|
|
|
|
|
this, &CMakeToolItemConfigWidget::store);
|
2016-06-27 13:09:14 +02:00
|
|
|
connect(m_autoRunCheckBox, &QCheckBox::toggled,
|
|
|
|
|
this, &CMakeToolItemConfigWidget::store);
|
2017-09-07 14:00:29 +02:00
|
|
|
connect(m_autoCreateBuildDirectoryCheckBox, &QCheckBox::toggled,
|
|
|
|
|
this, &CMakeToolItemConfigWidget::store);
|
2014-03-11 16:08:08 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-04 17:54:46 +01:00
|
|
|
void CMakeToolItemConfigWidget::store() const
|
2014-03-11 16:08:08 +01:00
|
|
|
{
|
2015-02-04 17:54:46 +01:00
|
|
|
if (!m_loadingItem && m_id.isValid())
|
2016-06-27 13:09:14 +02:00
|
|
|
m_model->updateCMakeTool(m_id, m_displayNameLineEdit->text(), m_binaryChooser->fileName(),
|
2017-09-07 14:00:29 +02:00
|
|
|
m_autoRunCheckBox->checkState() == Qt::Checked,
|
|
|
|
|
m_autoCreateBuildDirectoryCheckBox->checkState() == Qt::Checked);
|
2015-02-04 17:54:46 +01:00
|
|
|
}
|
2014-03-11 16:08:08 +01:00
|
|
|
|
2015-02-04 17:54:46 +01:00
|
|
|
void CMakeToolItemConfigWidget::load(const CMakeToolTreeItem *item)
|
|
|
|
|
{
|
|
|
|
|
m_loadingItem = true; // avoid intermediate signal handling
|
|
|
|
|
m_id = Core::Id();
|
|
|
|
|
if (!item) {
|
|
|
|
|
m_loadingItem = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set values:
|
|
|
|
|
m_displayNameLineEdit->setEnabled(!item->m_autodetected);
|
|
|
|
|
m_displayNameLineEdit->setText(item->m_name);
|
|
|
|
|
|
|
|
|
|
m_binaryChooser->setReadOnly(item->m_autodetected);
|
|
|
|
|
m_binaryChooser->setFileName(item->m_executable);
|
|
|
|
|
|
2016-06-27 13:09:14 +02:00
|
|
|
m_autoRunCheckBox->setChecked(item->m_isAutoRun);
|
2017-09-07 14:00:29 +02:00
|
|
|
m_autoCreateBuildDirectoryCheckBox->setChecked(item->m_autoCreateBuildDirectory);
|
2016-06-27 13:09:14 +02:00
|
|
|
|
2015-02-04 17:54:46 +01:00
|
|
|
m_id = item->m_id;
|
|
|
|
|
m_loadingItem = false;
|
2014-03-11 16:08:08 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-04 17:54:46 +01:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
// CMakeToolConfigWidget
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
class CMakeToolConfigWidget : public QWidget
|
2014-03-11 16:08:08 +01:00
|
|
|
{
|
2015-07-23 14:31:43 +03:00
|
|
|
Q_OBJECT
|
2015-02-04 17:54:46 +01:00
|
|
|
public:
|
2016-06-27 13:09:14 +02:00
|
|
|
CMakeToolConfigWidget()
|
2015-02-04 17:54:46 +01:00
|
|
|
{
|
|
|
|
|
m_addButton = new QPushButton(tr("Add"), this);
|
|
|
|
|
|
|
|
|
|
m_cloneButton = new QPushButton(tr("Clone"), this);
|
|
|
|
|
m_cloneButton->setEnabled(false);
|
|
|
|
|
|
|
|
|
|
m_delButton = new QPushButton(tr("Remove"), this);
|
|
|
|
|
m_delButton->setEnabled(false);
|
|
|
|
|
|
|
|
|
|
m_makeDefButton = new QPushButton(tr("Make Default"), this);
|
|
|
|
|
m_makeDefButton->setEnabled(false);
|
2015-10-22 17:09:14 +02:00
|
|
|
m_makeDefButton->setToolTip(tr("Set as the default CMake Tool to use when creating a new kit or when no value is set."));
|
2015-02-04 17:54:46 +01:00
|
|
|
|
|
|
|
|
m_container = new DetailsWidget(this);
|
|
|
|
|
m_container->setState(DetailsWidget::NoSummary);
|
|
|
|
|
m_container->setVisible(false);
|
|
|
|
|
|
|
|
|
|
m_cmakeToolsView = new QTreeView(this);
|
|
|
|
|
m_cmakeToolsView->setModel(&m_model);
|
|
|
|
|
m_cmakeToolsView->setUniformRowHeights(true);
|
|
|
|
|
m_cmakeToolsView->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
|
m_cmakeToolsView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
|
m_cmakeToolsView->expandAll();
|
|
|
|
|
|
|
|
|
|
QHeaderView *header = m_cmakeToolsView->header();
|
|
|
|
|
header->setStretchLastSection(false);
|
|
|
|
|
header->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
|
|
|
|
header->setSectionResizeMode(1, QHeaderView::Stretch);
|
|
|
|
|
|
|
|
|
|
QVBoxLayout *buttonLayout = new QVBoxLayout();
|
|
|
|
|
buttonLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
buttonLayout->addWidget(m_addButton);
|
|
|
|
|
buttonLayout->addWidget(m_cloneButton);
|
|
|
|
|
buttonLayout->addWidget(m_delButton);
|
|
|
|
|
buttonLayout->addWidget(m_makeDefButton);
|
|
|
|
|
buttonLayout->addItem(new QSpacerItem(10, 40, QSizePolicy::Minimum, QSizePolicy::Expanding));
|
|
|
|
|
|
|
|
|
|
QVBoxLayout *verticalLayout = new QVBoxLayout();
|
|
|
|
|
verticalLayout->addWidget(m_cmakeToolsView);
|
|
|
|
|
verticalLayout->addWidget(m_container);
|
|
|
|
|
|
|
|
|
|
QHBoxLayout *horizontalLayout = new QHBoxLayout(this);
|
|
|
|
|
horizontalLayout->addLayout(verticalLayout);
|
|
|
|
|
horizontalLayout->addLayout(buttonLayout);
|
|
|
|
|
|
|
|
|
|
connect(m_cmakeToolsView->selectionModel(), &QItemSelectionModel::currentChanged,
|
|
|
|
|
this, &CMakeToolConfigWidget::currentCMakeToolChanged, Qt::QueuedConnection);
|
|
|
|
|
|
|
|
|
|
connect(m_addButton, &QAbstractButton::clicked,
|
|
|
|
|
this, &CMakeToolConfigWidget::addCMakeTool);
|
|
|
|
|
connect(m_cloneButton, &QAbstractButton::clicked,
|
|
|
|
|
this, &CMakeToolConfigWidget::cloneCMakeTool);
|
|
|
|
|
connect(m_delButton, &QAbstractButton::clicked,
|
|
|
|
|
this, &CMakeToolConfigWidget::removeCMakeTool);
|
|
|
|
|
connect(m_makeDefButton, &QAbstractButton::clicked,
|
|
|
|
|
this, &CMakeToolConfigWidget::setDefaultCMakeTool);
|
|
|
|
|
|
|
|
|
|
m_itemConfigWidget = new CMakeToolItemConfigWidget(&m_model);
|
|
|
|
|
m_container->setWidget(m_itemConfigWidget);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void apply();
|
|
|
|
|
void cloneCMakeTool();
|
|
|
|
|
void addCMakeTool();
|
|
|
|
|
void removeCMakeTool();
|
|
|
|
|
void setDefaultCMakeTool();
|
|
|
|
|
void currentCMakeToolChanged(const QModelIndex &newCurrent);
|
|
|
|
|
|
|
|
|
|
CMakeToolItemModel m_model;
|
|
|
|
|
QTreeView *m_cmakeToolsView;
|
|
|
|
|
QPushButton *m_addButton;
|
|
|
|
|
QPushButton *m_cloneButton;
|
|
|
|
|
QPushButton *m_delButton;
|
|
|
|
|
QPushButton *m_makeDefButton;
|
|
|
|
|
DetailsWidget *m_container;
|
|
|
|
|
CMakeToolItemConfigWidget *m_itemConfigWidget;
|
2016-06-27 13:09:14 +02:00
|
|
|
CMakeToolTreeItem *m_currentItem = nullptr;
|
2015-02-04 17:54:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void CMakeToolConfigWidget::apply()
|
|
|
|
|
{
|
|
|
|
|
m_model.apply();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeToolConfigWidget::cloneCMakeTool()
|
|
|
|
|
{
|
|
|
|
|
if (!m_currentItem)
|
2014-03-11 16:08:08 +01:00
|
|
|
return;
|
2015-02-04 17:54:46 +01:00
|
|
|
|
|
|
|
|
QModelIndex newItem = m_model.addCMakeTool(tr("Clone of %1").arg(m_currentItem->m_name),
|
|
|
|
|
m_currentItem->m_executable,
|
2017-09-07 14:00:29 +02:00
|
|
|
m_currentItem->m_isAutoRun,
|
|
|
|
|
m_currentItem->m_autoCreateBuildDirectory, false);
|
2015-02-04 17:54:46 +01:00
|
|
|
|
|
|
|
|
m_cmakeToolsView->setCurrentIndex(newItem);
|
2014-03-11 16:08:08 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-04 17:54:46 +01:00
|
|
|
void CMakeToolConfigWidget::addCMakeTool()
|
2014-03-11 16:08:08 +01:00
|
|
|
{
|
2015-02-04 17:54:46 +01:00
|
|
|
QModelIndex newItem = m_model.addCMakeTool(m_model.uniqueDisplayName(tr("New CMake")),
|
2017-09-07 14:00:29 +02:00
|
|
|
FileName(), true, false, false);
|
2015-02-04 17:54:46 +01:00
|
|
|
|
|
|
|
|
m_cmakeToolsView->setCurrentIndex(newItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeToolConfigWidget::removeCMakeTool()
|
|
|
|
|
{
|
|
|
|
|
bool delDef = m_model.defaultItemId() == m_currentItem->m_id;
|
|
|
|
|
m_model.removeCMakeTool(m_currentItem->m_id);
|
|
|
|
|
m_currentItem = 0;
|
|
|
|
|
|
|
|
|
|
if (delDef) {
|
|
|
|
|
CMakeToolTreeItem *it = static_cast<CMakeToolTreeItem *>(m_model.autoGroupItem()->firstChild());
|
|
|
|
|
if (!it)
|
|
|
|
|
it = static_cast<CMakeToolTreeItem *>(m_model.manualGroupItem()->firstChild());
|
|
|
|
|
if (it)
|
|
|
|
|
m_model.setDefaultItemId(it->m_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TreeItem *newCurrent = m_model.manualGroupItem()->lastChild();
|
|
|
|
|
if (!newCurrent)
|
|
|
|
|
newCurrent = m_model.autoGroupItem()->lastChild();
|
|
|
|
|
|
|
|
|
|
if (newCurrent)
|
|
|
|
|
m_cmakeToolsView->setCurrentIndex(newCurrent->index());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeToolConfigWidget::setDefaultCMakeTool()
|
|
|
|
|
{
|
|
|
|
|
if (!m_currentItem)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_model.setDefaultItemId(m_currentItem->m_id);
|
|
|
|
|
m_makeDefButton->setEnabled(false);
|
2014-03-11 16:08:08 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-04 17:54:46 +01:00
|
|
|
void CMakeToolConfigWidget::currentCMakeToolChanged(const QModelIndex &newCurrent)
|
|
|
|
|
{
|
|
|
|
|
m_currentItem = m_model.cmakeToolItem(newCurrent);
|
|
|
|
|
m_itemConfigWidget->load(m_currentItem);
|
|
|
|
|
m_container->setVisible(m_currentItem);
|
|
|
|
|
m_cloneButton->setEnabled(m_currentItem);
|
|
|
|
|
m_delButton->setEnabled(m_currentItem && !m_currentItem->m_autodetected);
|
|
|
|
|
m_makeDefButton->setEnabled(m_currentItem && (!m_model.defaultItemId().isValid() || m_currentItem->m_id != m_model.defaultItemId()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////
|
|
|
|
|
// CMakeSettingsPage
|
|
|
|
|
////
|
|
|
|
|
|
2016-01-07 15:22:53 +01:00
|
|
|
CMakeSettingsPage::CMakeSettingsPage()
|
2014-03-11 16:08:08 +01:00
|
|
|
{
|
2015-02-24 21:57:00 +01:00
|
|
|
setId(Constants::CMAKE_SETTINGSPAGE_ID);
|
2015-02-04 17:54:46 +01:00
|
|
|
setDisplayName(tr("CMake"));
|
2017-09-15 16:40:31 +02:00
|
|
|
setCategory(ProjectExplorer::Constants::KITS_SETTINGS_CATEGORY);
|
2014-03-11 16:08:08 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-04 17:54:46 +01:00
|
|
|
QWidget *CMakeSettingsPage::widget()
|
2014-03-11 16:08:08 +01:00
|
|
|
{
|
2015-02-04 17:54:46 +01:00
|
|
|
if (!m_widget)
|
|
|
|
|
m_widget = new CMakeToolConfigWidget;
|
|
|
|
|
return m_widget;
|
|
|
|
|
}
|
2014-03-11 16:08:08 +01:00
|
|
|
|
2015-02-04 17:54:46 +01:00
|
|
|
void CMakeSettingsPage::apply()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_widget, return);
|
|
|
|
|
m_widget->m_itemConfigWidget->store();
|
2015-10-09 09:50:44 +02:00
|
|
|
m_widget->apply();
|
2015-02-04 17:54:46 +01:00
|
|
|
}
|
2014-03-11 16:08:08 +01:00
|
|
|
|
2015-02-04 17:54:46 +01:00
|
|
|
void CMakeSettingsPage::finish()
|
|
|
|
|
{
|
|
|
|
|
delete m_widget;
|
|
|
|
|
m_widget = 0;
|
2014-03-11 16:08:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace CMakeProjectManager
|
2015-07-23 14:31:43 +03:00
|
|
|
|
|
|
|
|
#include "cmakesettingspage.moc"
|