2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2020 Alexis Jeandet.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2020-05-01 18:20:56 +02:00
|
|
|
|
|
|
|
|
#include "toolkitaspectwidget.h"
|
2020-10-29 10:20:14 +01:00
|
|
|
|
2020-05-01 18:20:56 +02:00
|
|
|
#include "mesonpluginconstants.h"
|
|
|
|
|
#include "mesontoolkitaspect.h"
|
|
|
|
|
#include "ninjatoolkitaspect.h"
|
2020-10-29 10:20:14 +01:00
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
2020-05-01 18:20:56 +02:00
|
|
|
|
|
|
|
|
namespace MesonProjectManager {
|
|
|
|
|
namespace Internal {
|
2020-10-29 10:20:14 +01:00
|
|
|
|
2020-05-01 18:20:56 +02:00
|
|
|
ToolKitAspectWidget::ToolKitAspectWidget(ProjectExplorer::Kit *kit,
|
|
|
|
|
const ProjectExplorer::KitAspect *ki,
|
|
|
|
|
ToolType type)
|
|
|
|
|
: ProjectExplorer::KitAspectWidget(kit, ki)
|
2021-04-07 18:55:21 +02:00
|
|
|
, m_toolsComboBox(createSubWidget<QComboBox>())
|
2021-04-12 10:58:54 +02:00
|
|
|
, m_manageButton(createManageButton(Constants::SettingsPage::TOOLS_ID))
|
2020-05-01 18:20:56 +02:00
|
|
|
, m_type{type}
|
|
|
|
|
{
|
|
|
|
|
m_toolsComboBox->setSizePolicy(QSizePolicy::Ignored,
|
|
|
|
|
m_toolsComboBox->sizePolicy().verticalPolicy());
|
|
|
|
|
m_toolsComboBox->setEnabled(false);
|
|
|
|
|
m_toolsComboBox->setToolTip(ki->description());
|
|
|
|
|
loadTools();
|
|
|
|
|
|
2022-07-19 23:43:58 +02:00
|
|
|
connect(MesonTools::instance(), &MesonTools::toolAdded,
|
|
|
|
|
this, &ToolKitAspectWidget::addTool);
|
|
|
|
|
connect(MesonTools::instance(), &MesonTools::toolRemoved,
|
|
|
|
|
this, &ToolKitAspectWidget::removeTool);
|
|
|
|
|
connect(m_toolsComboBox, &QComboBox::currentIndexChanged,
|
|
|
|
|
this, &ToolKitAspectWidget::setCurrentToolIndex);
|
2020-05-01 18:20:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ToolKitAspectWidget::~ToolKitAspectWidget()
|
|
|
|
|
{
|
|
|
|
|
delete m_toolsComboBox;
|
|
|
|
|
delete m_manageButton;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ToolKitAspectWidget::addTool(const MesonTools::Tool_t &tool)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(tool, return );
|
|
|
|
|
if (isCompatible(tool))
|
|
|
|
|
this->m_toolsComboBox->addItem(tool->name(), tool->id().toSetting());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ToolKitAspectWidget::removeTool(const MesonTools::Tool_t &tool)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(tool, return );
|
|
|
|
|
if (!isCompatible(tool))
|
|
|
|
|
return;
|
|
|
|
|
const int index = indexOf(tool->id());
|
|
|
|
|
QTC_ASSERT(index >= 0, return );
|
|
|
|
|
if (index == m_toolsComboBox->currentIndex())
|
|
|
|
|
setToDefault();
|
|
|
|
|
m_toolsComboBox->removeItem(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ToolKitAspectWidget::setCurrentToolIndex(int index)
|
|
|
|
|
{
|
2022-10-26 08:35:00 +02:00
|
|
|
if (m_toolsComboBox->count() == 0)
|
|
|
|
|
return;
|
2020-06-26 13:59:38 +02:00
|
|
|
const Utils::Id id = Utils::Id::fromSetting(m_toolsComboBox->itemData(index));
|
2020-05-01 18:20:56 +02:00
|
|
|
if (m_type == ToolType::Meson)
|
|
|
|
|
MesonToolKitAspect::setMesonTool(m_kit, id);
|
|
|
|
|
else
|
|
|
|
|
NinjaToolKitAspect::setNinjaTool(m_kit, id);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
int ToolKitAspectWidget::indexOf(const Utils::Id &id)
|
2020-05-01 18:20:56 +02:00
|
|
|
{
|
|
|
|
|
for (int i = 0; i < m_toolsComboBox->count(); ++i) {
|
2020-06-26 13:59:38 +02:00
|
|
|
if (id == Utils::Id::fromSetting(m_toolsComboBox->itemData(i)))
|
2020-05-01 18:20:56 +02:00
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ToolKitAspectWidget::isCompatible(const MesonTools::Tool_t &tool)
|
|
|
|
|
{
|
|
|
|
|
return (m_type == ToolType::Meson && MesonTools::isMesonWrapper(tool))
|
|
|
|
|
|| (m_type == ToolType::Ninja && MesonTools::isNinjaWrapper(tool));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ToolKitAspectWidget::loadTools()
|
|
|
|
|
{
|
2020-10-27 17:58:55 +01:00
|
|
|
for (const MesonTools::Tool_t &tool : MesonTools::tools()) {
|
|
|
|
|
addTool(tool);
|
|
|
|
|
}
|
2020-05-01 18:20:56 +02:00
|
|
|
refresh();
|
|
|
|
|
m_toolsComboBox->setEnabled(m_toolsComboBox->count());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ToolKitAspectWidget::setToDefault()
|
|
|
|
|
{
|
|
|
|
|
const MesonTools::Tool_t autoDetected = [this]() {
|
|
|
|
|
if (m_type == ToolType::Meson)
|
|
|
|
|
return std::dynamic_pointer_cast<ToolWrapper>(MesonTools::mesonWrapper());
|
|
|
|
|
return std::dynamic_pointer_cast<ToolWrapper>(MesonTools::ninjaWrapper());
|
|
|
|
|
}();
|
|
|
|
|
|
|
|
|
|
if (autoDetected) {
|
|
|
|
|
const auto index = indexOf(autoDetected->id());
|
|
|
|
|
m_toolsComboBox->setCurrentIndex(index);
|
|
|
|
|
setCurrentToolIndex(index);
|
|
|
|
|
} else {
|
|
|
|
|
m_toolsComboBox->setCurrentIndex(0);
|
|
|
|
|
setCurrentToolIndex(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-29 10:20:14 +01:00
|
|
|
|
2020-05-01 18:20:56 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace MesonProjectManager
|