Commit 1e2d2665 authored by Benjamin Zeller's avatar Benjamin Zeller

Make CMakeTool known to the Kits

This patch adds support for binding a specific CMakeTool to a Kit.
When creating a new Kit or loading a existing one without a valid
CMakeTool, the default CMakeTool will be set.

Change-Id: I28d0843a01c583c4b31fc680a0ec556b40cd9c0d
Reviewed-by: default avatarDaniel Teske <daniel.teske@theqtcompany.com>
parent 20a05c98
......@@ -33,11 +33,20 @@
#include "cmakeprojectmanager.h"
#include "cmakesettingspage.h"
#include "cmaketoolmanager.h"
#include "cmakekitinformation.h"
#include <texteditor/codeassist/keywordscompletionassist.h>
#include <texteditor/codeassist/assistinterface.h>
#include <projectexplorer/projecttree.h>
#include <projectexplorer/project.h>
#include <projectexplorer/kit.h>
#include <projectexplorer/target.h>
#include <coreplugin/editormanager/editormanager.h>
#include <projectexplorer/session.h>
using namespace CMakeProjectManager::Internal;
using namespace TextEditor;
using namespace ProjectExplorer;
// -------------------------------
// CMakeFileCompletionAssistProvider
......@@ -55,10 +64,31 @@ bool CMakeFileCompletionAssistProvider::supportsEditor(Core::Id editorId) const
IAssistProcessor *CMakeFileCompletionAssistProvider::createProcessor() const
{
TextEditor::Keywords keywords = TextEditor::Keywords(QStringList(), QStringList(), QMap<QString, QStringList>());
CMakeTool *cmake = CMakeToolManager::defaultCMakeTool();
if (cmake && cmake->isValid())
keywords = cmake->keywords();
return new CMakeFileCompletionAssist();
}
CMakeFileCompletionAssist::CMakeFileCompletionAssist() :
KeywordsCompletionAssistProcessor(Keywords())
{}
IAssistProposal *CMakeFileCompletionAssist::perform(const AssistInterface *interface)
{
TextEditor::Keywords keywords;
QString fileName = interface->fileName();
if (!fileName.isEmpty() && QFileInfo(fileName).isFile()) {
Utils::FileName file = Utils::FileName::fromString(fileName);
if (Project *p = SessionManager::projectForFile(file)) {
if (Target *t = p->activeTarget()) {
if (CMakeTool *cmake = CMakeKitInformation::cmakeTool(t->kit())) {
if (cmake->isValid())
keywords = cmake->keywords();
}
}
}
}
return new KeywordsCompletionAssistProcessor(keywords);
setKeywords(keywords);
return KeywordsCompletionAssistProcessor::perform(interface);
}
......@@ -32,12 +32,22 @@
#define CMAKEFILECOMPLETIONASSIST_H
#include <texteditor/codeassist/completionassistprovider.h>
#include <texteditor/codeassist/keywordscompletionassist.h>
namespace CMakeProjectManager {
namespace Internal {
class CMakeSettingsPage;
class CMakeFileCompletionAssist : public TextEditor::KeywordsCompletionAssistProcessor
{
public:
CMakeFileCompletionAssist();
// IAssistProcessor interface
TextEditor::IAssistProposal *perform(const TextEditor::AssistInterface *interface) Q_DECL_OVERRIDE;
};
class CMakeFileCompletionAssistProvider : public TextEditor::CompletionAssistProvider
{
Q_OBJECT
......
/****************************************************************************
**
** Copyright (C) 2015 Canonical Ltd.
** Contact: http://www.qt.io/licensing
**
** 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
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** 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 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "cmakeprojectconstants.h"
#include "cmakekitconfigwidget.h"
#include "cmakekitinformation.h"
#include "cmaketoolmanager.h"
#include "cmaketool.h"
#include <utils/qtcassert.h>
#include <coreplugin/icore.h>
#include <projectexplorer/kit.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <QComboBox>
#include <QPushButton>
namespace CMakeProjectManager {
namespace Internal {
CMakeKitConfigWidget::CMakeKitConfigWidget(ProjectExplorer::Kit *kit,
const ProjectExplorer::KitInformation *ki) :
ProjectExplorer::KitConfigWidget(kit, ki),
m_removingItem(false)
{
m_comboBox = new QComboBox;
m_comboBox->setEnabled(false);
m_comboBox->setToolTip(toolTip());
foreach (CMakeTool *tool, CMakeToolManager::cmakeTools())
cmakeToolAdded(tool->id());
updateComboBox();
refresh();
connect(m_comboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &CMakeKitConfigWidget::currentCMakeToolChanged);
m_manageButton = new QPushButton(KitConfigWidget::msgManage());
m_manageButton->setContentsMargins(0, 0, 0, 0);
connect(m_manageButton, &QPushButton::clicked,
this, &CMakeKitConfigWidget::manageCMakeTools);
CMakeToolManager *cmakeMgr = CMakeToolManager::instance();
connect(cmakeMgr, &CMakeToolManager::cmakeAdded,
this, &CMakeKitConfigWidget::cmakeToolAdded);
connect(cmakeMgr, &CMakeToolManager::cmakeRemoved,
this, &CMakeKitConfigWidget::cmakeToolRemoved);
connect(cmakeMgr, &CMakeToolManager::cmakeUpdated,
this, &CMakeKitConfigWidget::cmakeToolUpdated);
}
CMakeKitConfigWidget::~CMakeKitConfigWidget()
{
delete m_comboBox;
delete m_manageButton;
}
QString CMakeKitConfigWidget::displayName() const
{
return tr("CMake Tool:");
}
void CMakeKitConfigWidget::makeReadOnly()
{
m_comboBox->setEnabled(false);
}
void CMakeKitConfigWidget::refresh()
{
CMakeTool *tool = CMakeKitInformation::cmakeTool(m_kit);
m_comboBox->setCurrentIndex(tool == 0 ? -1 : indexOf(tool->id()));
}
QWidget *CMakeKitConfigWidget::mainWidget() const
{
return m_comboBox;
}
QWidget *CMakeKitConfigWidget::buttonWidget() const
{
return m_manageButton;
}
QString CMakeKitConfigWidget::toolTip() const
{
return tr("The CMake Tool to use when building a project with CMake.<br>"
"This setting is ignored when using other build systems.");
}
int CMakeKitConfigWidget::indexOf(const Core::Id &id)
{
for (int i = 0; i < m_comboBox->count(); ++i) {
if (id == Core::Id::fromSetting(m_comboBox->itemData(i)))
return i;
}
return -1;
}
void CMakeKitConfigWidget::cmakeToolAdded(const Core::Id &id)
{
const CMakeTool *tool = CMakeToolManager::findById(id);
QTC_ASSERT(tool, return);
m_comboBox->addItem(tool->displayName(), tool->id().toSetting());
updateComboBox();
refresh();
}
void CMakeKitConfigWidget::cmakeToolUpdated(const Core::Id &id)
{
const int pos = indexOf(id);
QTC_ASSERT(pos >= 0, return);
const CMakeTool *tool = CMakeToolManager::findById(id);
QTC_ASSERT(tool, return);
m_comboBox->setItemText(pos, tool->displayName());
}
void CMakeKitConfigWidget::cmakeToolRemoved(const Core::Id &id)
{
const int pos = indexOf(id);
QTC_ASSERT(pos >= 0, return);
// do not handle the current index changed signal
m_removingItem = true;
m_comboBox->removeItem(pos);
m_removingItem = false;
// update the checkbox and set the current index
updateComboBox();
refresh();
}
void CMakeKitConfigWidget::updateComboBox()
{
// remove unavailable cmake tool:
int pos = indexOf(Core::Id());
if (pos >= 0)
m_comboBox->removeItem(pos);
if (m_comboBox->count() == 0) {
m_comboBox->addItem(tr("<No CMake Tool available>"),
Core::Id().toSetting());
m_comboBox->setEnabled(false);
} else {
m_comboBox->setEnabled(true);
}
}
void CMakeKitConfigWidget::currentCMakeToolChanged(int index)
{
if (m_removingItem)
return;
const Core::Id id = Core::Id::fromSetting(m_comboBox->itemData(index));
CMakeKitInformation::setCMakeTool(m_kit, id);
}
void CMakeKitConfigWidget::manageCMakeTools()
{
Core::ICore::showOptionsDialog(Constants::CMAKE_SETTINGSPAGE_ID,
buttonWidget());
}
} // namespace Internal
} // namespace CMakeProjectManager
/****************************************************************************
**
** Copyright (C) 2015 Canonical Ltd.
** Contact: http://www.qt.io/licensing
**
** 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
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** 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 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef CMAKEPROJECTMANAGER_INTERNAL_CMAKEKITCONFIGWIDGET_H
#define CMAKEPROJECTMANAGER_INTERNAL_CMAKEKITCONFIGWIDGET_H
#include <projectexplorer/kitconfigwidget.h>
namespace ProjectExplorer {
class Kit;
class KitInformation;
}
QT_FORWARD_DECLARE_CLASS(QComboBox)
QT_FORWARD_DECLARE_CLASS(QPushButton)
namespace CMakeProjectManager {
class CMakeTool;
namespace Internal {
class CMakeKitConfigWidget : public ProjectExplorer::KitConfigWidget
{
Q_OBJECT
public:
CMakeKitConfigWidget(ProjectExplorer::Kit *kit, const ProjectExplorer::KitInformation *ki);
virtual ~CMakeKitConfigWidget();
// KitConfigWidget interface
QString displayName() const Q_DECL_OVERRIDE;
void makeReadOnly() Q_DECL_OVERRIDE;
void refresh() Q_DECL_OVERRIDE;
QWidget *mainWidget() const Q_DECL_OVERRIDE;
QWidget *buttonWidget() const Q_DECL_OVERRIDE;
QString toolTip() const Q_DECL_OVERRIDE;
private:
int indexOf(const Core::Id &id);
void updateComboBox();
void cmakeToolAdded(const Core::Id &id);
void cmakeToolUpdated(const Core::Id &id);
void cmakeToolRemoved(const Core::Id &id);
void currentCMakeToolChanged(int index);
void manageCMakeTools();
private:
bool m_removingItem;
QComboBox *m_comboBox;
QPushButton *m_manageButton;
};
} // namespace Internal
} // namespace CMakeProjectManager
#endif // CMAKEPROJECTMANAGER_INTERNAL_CMAKEKITCONFIGWIDGET_H
/****************************************************************************
**
** Copyright (C) 2015 Canonical Ltd.
** Contact: http://www.qt.io/licensing
**
** 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
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** 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 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "cmakekitinformation.h"
#include "cmakekitconfigwidget.h"
#include "cmaketoolmanager.h"
#include "cmaketool.h"
#include <utils/qtcassert.h>
#include <projectexplorer/task.h>
#include <projectexplorer/kit.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <QDebug>
using namespace ProjectExplorer;
namespace CMakeProjectManager {
CMakeKitInformation::CMakeKitInformation()
{
setObjectName(QLatin1String("CMakeKitInformation"));
setId(CMakeKitInformation::id());
//make sure the default value is set if a selected CMake is removed
connect(CMakeToolManager::instance(), &CMakeToolManager::cmakeRemoved,
[this]() { foreach (Kit *k, KitManager::kits()) fix(k); });
//make sure the default value is set if a new default CMake is set
connect(CMakeToolManager::instance(), &CMakeToolManager::defaultCMakeChanged,
[this]() { foreach (Kit *k, KitManager::kits()) fix(k); });
}
Core::Id CMakeKitInformation::id()
{
return "CMakeProjectManager.CMakeKitInformation";
}
CMakeTool *CMakeKitInformation::cmakeTool(const Kit *k)
{
if (!k)
return 0;
const QVariant id = k->value(CMakeKitInformation::id());
return CMakeToolManager::findById(Core::Id::fromSetting(id));
}
void CMakeKitInformation::setCMakeTool(Kit *k, const Core::Id id)
{
QTC_ASSERT(k, return);
if (id.isValid()) {
// Only set cmake tools that are known to the manager
QTC_ASSERT(CMakeToolManager::findById(id), return);
k->setValue(CMakeKitInformation::id(), id.toSetting());
} else {
//setting a empty Core::Id will reset to the default value
k->setValue(CMakeKitInformation::id(),defaultValue().toSetting());
}
}
Core::Id CMakeKitInformation::defaultValue()
{
CMakeTool *defaultTool = CMakeToolManager::defaultCMakeTool();
if (defaultTool)
return defaultTool->id();
return Core::Id();
}
QVariant CMakeKitInformation::defaultValue(Kit *) const
{
return defaultValue().toSetting();
}
QList<Task> CMakeKitInformation::validate(const Kit *k) const
{
CMakeTool *tool = CMakeKitInformation::cmakeTool(k);
QList<Task> result;
if (!tool) {
result.append(Task(Task::Warning,
tr("No CMake tool set."),
Utils::FileName(),
-1,
Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM)));
}
return result;
}
void CMakeKitInformation::setup(Kit *k)
{
CMakeTool *tool = CMakeKitInformation::cmakeTool(k);
if (tool)
return;
setCMakeTool(k, defaultValue());
}
void CMakeKitInformation::fix(Kit *k)
{
CMakeTool *tool = CMakeKitInformation::cmakeTool(k);
if (!tool)
setup(k);
}
KitInformation::ItemList CMakeKitInformation::toUserOutput(const Kit *k) const
{
CMakeTool *tool = cmakeTool(k);
return ItemList() << qMakePair(tr("CMake"), tool == 0 ? tr("Unconfigured") : tool->displayName());
}
KitConfigWidget *CMakeKitInformation::createConfigWidget(Kit *k) const
{
return new Internal::CMakeKitConfigWidget(k, this);
}
} // namespace CMakeProjectManager
/****************************************************************************
**
** Copyright (C) 2015 Canonical Ltd.
** Contact: http://www.qt.io/licensing
**
** 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
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** 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 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef CMAKEPROJECTMANAGER_CMAKEKITINFORMATION_H
#define CMAKEPROJECTMANAGER_CMAKEKITINFORMATION_H
#include "cmake_global.h"
#include <projectexplorer/kitmanager.h>
namespace CMakeProjectManager {
class CMakeTool;
class CMAKE_EXPORT CMakeKitInformation : public ProjectExplorer::KitInformation
{
Q_OBJECT
public:
CMakeKitInformation();
static Core::Id id();
static CMakeTool *cmakeTool(const ProjectExplorer::Kit *k);
static void setCMakeTool(ProjectExplorer::Kit *k, const Core::Id id);
static Core::Id defaultValue();
// KitInformation interface
QVariant defaultValue(ProjectExplorer::Kit *) const Q_DECL_OVERRIDE;
QList<ProjectExplorer::Task> validate(const ProjectExplorer::Kit *k) const Q_DECL_OVERRIDE;
void setup(ProjectExplorer::Kit *k) Q_DECL_OVERRIDE;
void fix(ProjectExplorer::Kit *k) Q_DECL_OVERRIDE;
virtual ItemList toUserOutput(const ProjectExplorer::Kit *k) const Q_DECL_OVERRIDE;
virtual ProjectExplorer::KitConfigWidget *createConfigWidget(ProjectExplorer::Kit *k) const Q_DECL_OVERRIDE;
};
} // namespace CMakeProjectManager
#endif // CMAKEPROJECTMANAGER_CMAKEKITINFORMATION_H
......@@ -109,7 +109,8 @@ class NoKitPage : public QWizardPage
Q_OBJECT
public:
NoKitPage(CMakeOpenProjectWizard *cmakeWizard);
bool isComplete() const;
bool isComplete() const Q_DECL_OVERRIDE;
void initializePage() Q_DECL_OVERRIDE;
private slots:
void kitsChanged();
void showOptions();
......@@ -140,20 +141,18 @@ private:
Utils::PathChooser *m_pc;
};
class ChooseCMakePage : public QWizardPage
class NoCMakePage : public QWizardPage
{
Q_OBJECT
public:
ChooseCMakePage(CMakeOpenProjectWizard *cmakeWizard);
virtual bool isComplete() const;
public slots:
void cmakeExecutableChanged();
NoCMakePage(CMakeOpenProjectWizard *cmakeWizard);
bool isComplete() const;
private slots:
void cmakeToolsChanged();
void showOptions();
private:
void updateErrorText();
QLabel *m_cmakeLabel;
CMakeOpenProjectWizard *m_cmakeWizard;
Utils::PathChooser *m_cmakeExecutable;
QLabel *m_descriptionLabel;
QPushButton *m_optionsButton;
};
class CMakeRunPage : public QWizardPage
......
......@@ -51,6 +51,9 @@ const char CMAKE_BC_ID[] = "CMakeProjectManager.CMakeBuildConfiguration";
// Menu
const char M_CONTEXT[] = "CMakeEditor.ContextMenu";
// Settings page