2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2018 The Qt Company Ltd.
|
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
|
2018-08-13 11:15:27 +02:00
|
|
|
|
|
|
|
|
#include "compilationdatabaseconstants.h"
|
|
|
|
|
#include "compilationdatabaseproject.h"
|
2023-02-08 14:30:01 +01:00
|
|
|
#include "compilationdatabaseprojectmanagertr.h"
|
2018-10-30 10:31:34 +01:00
|
|
|
#include "compilationdatabasetests.h"
|
2018-08-13 11:15:27 +02:00
|
|
|
|
2019-03-14 15:34:14 +01:00
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
2019-10-23 10:22:16 +02:00
|
|
|
|
2024-01-12 13:15:55 +01:00
|
|
|
#include <extensionsystem/iplugin.h>
|
|
|
|
|
|
2019-03-14 15:34:14 +01:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2018-08-13 11:15:27 +02:00
|
|
|
#include <projectexplorer/projectmanager.h>
|
2019-03-14 15:34:14 +01:00
|
|
|
#include <projectexplorer/projecttree.h>
|
2023-02-14 15:47:22 +01:00
|
|
|
#include <projectexplorer/projectmanager.h>
|
2019-10-23 10:22:16 +02:00
|
|
|
|
2024-01-26 17:15:51 +01:00
|
|
|
#include <utils/action.h>
|
2022-05-31 11:16:44 +02:00
|
|
|
#include <utils/fsengine/fileiconprovider.h>
|
2018-08-13 11:15:27 +02:00
|
|
|
#include <utils/utilsicons.h>
|
|
|
|
|
|
2019-10-23 10:22:16 +02:00
|
|
|
using namespace Core;
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
2023-02-09 10:39:40 +01:00
|
|
|
namespace CompilationDatabaseProjectManager::Internal {
|
2018-08-13 11:15:27 +02:00
|
|
|
|
2019-03-14 15:34:14 +01:00
|
|
|
const char CHANGEROOTDIR[] = "CompilationDatabaseProjectManager.ChangeRootDirectory";
|
2019-05-01 16:59:52 +02:00
|
|
|
const char COMPILE_COMMANDS_JSON[] = "compile_commands.json";
|
2019-03-14 15:34:14 +01:00
|
|
|
|
2024-01-12 13:15:55 +01:00
|
|
|
class CompilationDatabaseProjectManagerPlugin final : public ExtensionSystem::IPlugin
|
2019-10-23 10:22:16 +02:00
|
|
|
{
|
2024-01-12 13:15:55 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "CompilationDatabaseProjectManager.json")
|
2019-10-23 10:22:16 +02:00
|
|
|
|
2024-01-12 13:15:55 +01:00
|
|
|
void initialize() final
|
|
|
|
|
{
|
2024-01-29 18:36:27 +01:00
|
|
|
setupCompilationDatabaseEditor();
|
|
|
|
|
setupCompilationDatabaseBuildConfiguration();
|
2019-10-23 10:22:16 +02:00
|
|
|
|
2024-01-12 13:15:55 +01:00
|
|
|
Utils::FileIconProvider::registerIconOverlayForFilename(Utils::Icons::PROJECT.imageFilePath().toString(),
|
|
|
|
|
COMPILE_COMMANDS_JSON);
|
|
|
|
|
Utils::FileIconProvider::registerIconOverlayForFilename(
|
|
|
|
|
Utils::Icons::PROJECT.imageFilePath().toString(),
|
|
|
|
|
QString(COMPILE_COMMANDS_JSON) + Constants::COMPILATIONDATABASEPROJECT_FILES_SUFFIX);
|
2018-08-13 11:15:27 +02:00
|
|
|
|
2024-01-12 13:15:55 +01:00
|
|
|
ProjectManager::registerProjectType<CompilationDatabaseProject>(
|
|
|
|
|
Constants::COMPILATIONDATABASEMIMETYPE);
|
2019-10-23 10:22:16 +02:00
|
|
|
|
2024-01-29 18:36:27 +01:00
|
|
|
Command *cmd = ActionManager::registerAction(&m_changeRootAction, CHANGEROOTDIR);
|
2019-10-23 10:22:16 +02:00
|
|
|
|
2024-01-12 13:15:55 +01:00
|
|
|
ActionContainer *mprojectContextMenu = ActionManager::actionContainer(
|
|
|
|
|
ProjectExplorer::Constants::M_PROJECTCONTEXT);
|
|
|
|
|
mprojectContextMenu->addSeparator(ProjectExplorer::Constants::G_PROJECT_TREE);
|
|
|
|
|
mprojectContextMenu->addAction(cmd, ProjectExplorer::Constants::G_PROJECT_TREE);
|
2019-03-14 15:34:14 +01:00
|
|
|
|
2024-01-29 18:36:27 +01:00
|
|
|
connect(&m_changeRootAction, &QAction::triggered,
|
2024-01-12 13:15:55 +01:00
|
|
|
ProjectTree::instance(), &ProjectTree::changeProjectRootDirectory);
|
2019-03-14 15:34:14 +01:00
|
|
|
|
2024-01-12 13:15:55 +01:00
|
|
|
const auto onProjectChanged = [this] {
|
|
|
|
|
const auto currentProject = qobject_cast<CompilationDatabaseProject *>(
|
|
|
|
|
ProjectTree::currentProject());
|
2018-08-13 11:15:27 +02:00
|
|
|
|
2024-01-29 18:36:27 +01:00
|
|
|
m_changeRootAction.setEnabled(currentProject);
|
2024-01-12 13:15:55 +01:00
|
|
|
};
|
2018-08-13 11:15:27 +02:00
|
|
|
|
2024-01-12 13:15:55 +01:00
|
|
|
connect(ProjectManager::instance(), &ProjectManager::startupProjectChanged,
|
|
|
|
|
this, onProjectChanged);
|
2019-03-14 15:34:14 +01:00
|
|
|
|
2024-01-12 13:15:55 +01:00
|
|
|
connect(ProjectTree::instance(), &ProjectTree::currentProjectChanged,
|
|
|
|
|
this, onProjectChanged);
|
2018-08-13 11:15:27 +02:00
|
|
|
|
2018-10-30 10:31:34 +01:00
|
|
|
#ifdef WITH_TESTS
|
2024-01-12 13:15:55 +01:00
|
|
|
addTest<CompilationDatabaseTests>();
|
2018-10-30 10:31:34 +01:00
|
|
|
#endif
|
2024-01-12 13:15:55 +01:00
|
|
|
}
|
|
|
|
|
|
2024-01-29 18:36:27 +01:00
|
|
|
QAction m_changeRootAction{Tr::tr("Change Root Directory")};
|
2024-01-12 13:15:55 +01:00
|
|
|
};
|
2018-10-30 10:31:34 +01:00
|
|
|
|
2023-02-09 10:39:40 +01:00
|
|
|
} // CompilationDatabaseProjectManager::Internal
|
2024-01-12 13:15:55 +01:00
|
|
|
|
|
|
|
|
#include "compilationdatabaseprojectmanagerplugin.moc"
|