CompilationDatabase: Ask for the root path and scan for headers

Let's use the same approach we have for CMake projects by using
the same TreeScanner class.

Compilation database does not have a concept of the root directory
so let's show a file dialog and ask for it the first time the project
is loaded. Next times we open it we take this path from settings.
This root path can later be changed from the project tree context menu.

Fixes: QTCREATORBUG-22031
Change-Id: I151aed8d0504b2e8aa14aa774cad25f8c86d5c17
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Ivan Donchevskii
2019-03-14 15:34:14 +01:00
committed by hjk
parent d34eb692fe
commit 2c5808bada
16 changed files with 197 additions and 47 deletions

View File

@@ -29,13 +29,21 @@
#include "compilationdatabaseproject.h"
#include "compilationdatabasetests.h"
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/fileiconprovider.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectmanager.h>
#include <projectexplorer/projecttree.h>
#include <projectexplorer/session.h>
#include <utils/utilsicons.h>
namespace CompilationDatabaseProjectManager {
namespace Internal {
const char CHANGEROOTDIR[] = "CompilationDatabaseProjectManager.ChangeRootDirectory";
bool CompilationDatabaseProjectManagerPlugin::initialize(const QStringList &arguments, QString *errorMessage)
{
Q_UNUSED(arguments);
@@ -45,10 +53,39 @@ bool CompilationDatabaseProjectManagerPlugin::initialize(const QStringList &argu
ProjectExplorer::ProjectManager::registerProjectType<CompilationDatabaseProject>(
Constants::COMPILATIONDATABASEMIMETYPE);
m_changeProjectRootDirectoryAction = new QAction(tr("Change Root Directory"), this);
Core::Command *cmd = Core::ActionManager::registerAction(m_changeProjectRootDirectoryAction,
CHANGEROOTDIR);
Core::ActionContainer *mprojectContextMenu = Core::ActionManager::actionContainer(
ProjectExplorer::Constants::M_PROJECTCONTEXT);
mprojectContextMenu->addSeparator(ProjectExplorer::Constants::G_PROJECT_TREE);
mprojectContextMenu->addAction(cmd, ProjectExplorer::Constants::G_PROJECT_TREE);
connect(m_changeProjectRootDirectoryAction,
&QAction::triggered,
ProjectExplorer::ProjectTree::instance(),
&ProjectExplorer::ProjectTree::changeProjectRootDirectory);
connect(ProjectExplorer::SessionManager::instance(),
&ProjectExplorer::SessionManager::startupProjectChanged,
this,
&CompilationDatabaseProjectManagerPlugin::projectChanged);
connect(ProjectExplorer::ProjectTree::instance(),
&ProjectExplorer::ProjectTree::currentProjectChanged,
this,
&CompilationDatabaseProjectManagerPlugin::projectChanged);
return true;
}
void CompilationDatabaseProjectManagerPlugin::projectChanged()
{
const auto *currentProject = qobject_cast<CompilationDatabaseProject *>(
ProjectExplorer::ProjectTree::currentProject());
m_changeProjectRootDirectoryAction->setEnabled(currentProject);
}
void CompilationDatabaseProjectManagerPlugin::extensionsInitialized()
{
}