QmakeProjectManager: Merge QmakeManager into QmakeProjectManagerPrivate

No need for two manager type classes talking mostly to each other.

Change-Id: I82a52385df08dc4cddac2d294661341a79b86a4d
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2020-02-24 18:34:31 +01:00
parent 61dc14b67f
commit 4672013595
12 changed files with 248 additions and 359 deletions

View File

@@ -32,7 +32,6 @@ add_qtc_plugin(QmakeProjectManager
qmakeparsernodes.cpp qmakeparsernodes.h
qmakeproject.cpp qmakeproject.h
qmakeprojectimporter.cpp qmakeprojectimporter.h
qmakeprojectmanager.cpp qmakeprojectmanager.h
qmakeprojectmanager.qrc
qmakeprojectmanager_global.h
qmakeprojectmanagerconstants.h

View File

@@ -30,8 +30,6 @@
#include "profilehoverhandler.h"
#include "qmakenodes.h"
#include "qmakeproject.h"
#include "qmakeprojectmanager.h"
#include "qmakeprojectmanagerconstants.h"
#include "qmakeprojectmanagerconstants.h"
#include <coreplugin/fileiconprovider.h>

View File

@@ -26,7 +26,7 @@
#include "qmakenodes.h"
#include "qmakeproject.h"
#include "qmakeprojectmanager.h"
#include "qmakeprojectmanagerplugin.h"
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/runconfiguration.h>
@@ -339,7 +339,7 @@ bool QmakeProFileNode::validParse() const
void QmakeProFileNode::build()
{
QmakeManager::buildProduct(getProject(), this);
QmakeProjectManagerPlugin::buildProduct(getProject(), this);
}
QStringList QmakeProFileNode::targetApplications() const

View File

@@ -25,7 +25,6 @@
#include "qmakeproject.h"
#include "qmakeprojectmanager.h"
#include "qmakeprojectimporter.h"
#include "qmakebuildinfo.h"
#include "qmakestep.h"

View File

@@ -26,12 +26,12 @@
#pragma once
#include "qmakeprojectmanager_global.h"
#include "qmakeprojectmanager.h"
#include "qmakenodes.h"
#include "qmakeparsernodes.h"
#include <projectexplorer/deploymentdata.h>
#include <projectexplorer/project.h>
#include <projectexplorer/toolchain.h>
#include <QStringList>
#include <QFutureInterface>

View File

@@ -1,256 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://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 https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** 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.
**
****************************************************************************/
#include "qmakeprojectmanager.h"
#include "qmakeprojectmanagerconstants.h"
#include "qmakeprojectmanagerplugin.h"
#include "qmakenodes.h"
#include "qmakeproject.h"
#include "profileeditor.h"
#include "qmakestep.h"
#include "qmakebuildconfiguration.h"
#include "addlibrarywizard.h"
#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projecttree.h>
#include <projectexplorer/buildmanager.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
#include <utils/qtcassert.h>
#include <texteditor/texteditor.h>
#include <QDir>
#include <QFileInfo>
#include <QVariant>
using namespace ProjectExplorer;
using namespace TextEditor;
namespace QmakeProjectManager {
static QmakeProFileNode *buildableFileProFile(Node *node)
{
if (node) {
auto subPriFileNode = dynamic_cast<QmakePriFileNode *>(node);
if (!subPriFileNode)
subPriFileNode = dynamic_cast<QmakePriFileNode *>(node->parentProjectNode());
if (subPriFileNode)
return subPriFileNode->proFileNode();
}
return nullptr;
}
FileNode *QmakeManager::contextBuildableFileNode()
{
Node *node = ProjectTree::currentNode();
QmakeProFileNode *subProjectNode = buildableFileProFile(node);
FileNode *fileNode = node ? node->asFileNode() : nullptr;
bool buildFilePossible = subProjectNode && fileNode
&& (fileNode->fileType() == ProjectExplorer::FileType::Source);
return buildFilePossible ? fileNode : nullptr;
}
void QmakeManager::addLibrary()
{
if (auto editor = qobject_cast<BaseTextEditor *>(Core::EditorManager::currentEditor()))
addLibraryImpl(editor->document()->filePath().toString(), editor);
}
void QmakeManager::addLibraryContextMenu()
{
QString projectPath;
Node *node = ProjectTree::currentNode();
if (ContainerNode *cn = node->asContainerNode())
projectPath = cn->project()->projectFilePath().toString();
else if (dynamic_cast<QmakeProFileNode *>(node))
projectPath = node->filePath().toString();
addLibraryImpl(projectPath, nullptr);
}
void QmakeManager::addLibraryImpl(const QString &fileName, BaseTextEditor *editor)
{
if (fileName.isEmpty())
return;
Internal::AddLibraryWizard wizard(fileName, Core::ICore::dialogParent());
if (wizard.exec() != QDialog::Accepted)
return;
if (!editor)
editor = qobject_cast<BaseTextEditor *>(Core::EditorManager::openEditor(fileName,
Constants::PROFILE_EDITOR_ID, Core::EditorManager::DoNotMakeVisible));
if (!editor)
return;
const int endOfDoc = editor->position(EndOfDocPosition);
editor->setCursorPosition(endOfDoc);
QString snippet = wizard.snippet();
// add extra \n in case the last line is not empty
int line, column;
editor->convertPosition(endOfDoc, &line, &column);
const int positionInBlock = column - 1;
if (!editor->textAt(endOfDoc - positionInBlock, positionInBlock).simplified().isEmpty())
snippet = QLatin1Char('\n') + snippet;
editor->insert(snippet);
}
void QmakeManager::runQMake()
{
runQMakeImpl(SessionManager::startupProject(), nullptr);
}
void QmakeManager::runQMakeContextMenu()
{
runQMakeImpl(ProjectTree::currentProject(), ProjectTree::currentNode());
}
void QmakeManager::runQMakeImpl(ProjectExplorer::Project *p, ProjectExplorer::Node *node)
{
if (!ProjectExplorerPlugin::saveModifiedFiles())
return;
auto *qmakeProject = qobject_cast<QmakeProject *>(p);
QTC_ASSERT(qmakeProject, return);
if (!qmakeProject->activeTarget() || !qmakeProject->activeTarget()->activeBuildConfiguration())
return;
auto *bc = static_cast<QmakeBuildConfiguration *>(qmakeProject->activeTarget()->activeBuildConfiguration());
QMakeStep *qs = bc->qmakeStep();
if (!qs)
return;
//found qmakeStep, now use it
qs->setForced(true);
if (node && node != qmakeProject->rootProjectNode())
if (auto *profile = dynamic_cast<QmakeProFileNode *>(node))
bc->setSubNodeBuild(profile);
BuildManager::appendStep(qs, tr("QMake"));
bc->setSubNodeBuild(nullptr);
}
void QmakeManager::buildSubDirContextMenu()
{
handleSubDirContextMenu(BUILD, false);
}
void QmakeManager::cleanSubDirContextMenu()
{
handleSubDirContextMenu(CLEAN, false);
}
void QmakeManager::rebuildSubDirContextMenu()
{
handleSubDirContextMenu(REBUILD, false);
}
void QmakeManager::buildFileContextMenu()
{
handleSubDirContextMenu(BUILD, true);
}
void QmakeManager::buildFile()
{
if (Core::IDocument *currentDocument= Core::EditorManager::currentDocument()) {
const Utils::FilePath file = currentDocument->filePath();
Node *n = ProjectTree::nodeForFile(file);
FileNode *node = n ? n->asFileNode() : nullptr;
Project *project = SessionManager::projectForFile(file);
if (project && node)
handleSubDirContextMenu(BUILD, true, project, node->parentProjectNode(), node);
}
}
void QmakeManager::buildProduct(Project *project, Node *proFileNode)
{
handleSubDirContextMenu(BUILD, false, project, proFileNode, nullptr);
}
void QmakeManager::handleSubDirContextMenu(QmakeManager::Action action, bool isFileBuild)
{
handleSubDirContextMenu(action,
isFileBuild,
ProjectTree::currentProject(),
buildableFileProFile(ProjectTree::currentNode()),
contextBuildableFileNode());
}
void QmakeManager::handleSubDirContextMenu(QmakeManager::Action action, bool isFileBuild,
Project *contextProject, Node *contextNode,
FileNode *buildableFile)
{
QTC_ASSERT(contextProject, return);
Target *target = contextProject->activeTarget();
if (!target)
return;
auto *bc = qobject_cast<QmakeBuildConfiguration *>(target->activeBuildConfiguration());
if (!bc)
return;
if (!contextNode || !buildableFile)
isFileBuild = false;
if (auto *prifile = dynamic_cast<QmakePriFileNode *>(contextNode)) {
if (QmakeProFileNode *profile = prifile->proFileNode()) {
if (profile != contextProject->rootProjectNode() || isFileBuild)
bc->setSubNodeBuild(profile->proFileNode());
}
}
if (isFileBuild)
bc->setFileNodeBuild(buildableFile);
if (ProjectExplorerPlugin::saveModifiedFiles()) {
const Core::Id buildStep = ProjectExplorer::Constants::BUILDSTEPS_BUILD;
const Core::Id cleanStep = ProjectExplorer::Constants::BUILDSTEPS_CLEAN;
if (action == BUILD) {
BuildManager::buildList(bc->buildSteps());
} else if (action == CLEAN) {
BuildManager::buildList(bc->cleanSteps());
} else if (action == REBUILD) {
QStringList names;
names << ProjectExplorerPlugin::displayNameForStepId(cleanStep)
<< ProjectExplorerPlugin::displayNameForStepId(buildStep);
BuildManager::buildLists({bc->cleanSteps(), bc->buildSteps()}, names);
}
}
bc->setSubNodeBuild(nullptr);
bc->setFileNodeBuild(nullptr);
}
} // namespace QmakeProjectManager

View File

@@ -1,77 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://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 https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** 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.
**
****************************************************************************/
#pragma once
#include "qmakeprojectmanager_global.h"
#include <projectexplorer/projectnodes.h>
namespace Core { class IEditor; }
namespace TextEditor { class BaseTextEditor; }
namespace ProjectExplorer {
class Project;
class Node;
class ToolChain;
}
namespace QmakeProjectManager {
class QMAKEPROJECTMANAGER_EXPORT QmakeManager : public QObject
{
Q_OBJECT
public:
void notifyChanged(const Utils::FilePath &name);
// Context information used in the slot implementations
static ProjectExplorer::FileNode *contextBuildableFileNode();
enum Action { BUILD, REBUILD, CLEAN };
void addLibrary();
void addLibraryContextMenu();
void runQMake();
void runQMakeContextMenu();
void buildSubDirContextMenu();
void rebuildSubDirContextMenu();
void cleanSubDirContextMenu();
void buildFileContextMenu();
void buildFile();
static void buildProduct(ProjectExplorer::Project *project, ProjectExplorer::Node *proFileNode);
private:
void handleSubDirContextMenu(Action action, bool isFileBuild);
static void handleSubDirContextMenu(QmakeManager::Action action, bool isFileBuild,
ProjectExplorer::Project *contextProject,
ProjectExplorer::Node *contextProFileNode,
ProjectExplorer::FileNode *buildableFile);
void addLibraryImpl(const QString &fileName, TextEditor::BaseTextEditor *editor);
void runQMakeImpl(ProjectExplorer::Project *p, ProjectExplorer::Node *node);
};
} // namespace QmakeProjectManager

View File

@@ -10,7 +10,6 @@ HEADERS += \
qmakeparsernodes.h \
qmakeprojectimporter.h \
qmakeprojectmanagerplugin.h \
qmakeprojectmanager.h \
qmakeproject.h \
qmakesettings.h \
qmakenodes.h \
@@ -40,7 +39,6 @@ SOURCES += \
qmakeparsernodes.cpp \
qmakeprojectimporter.cpp \
qmakeprojectmanagerplugin.cpp \
qmakeprojectmanager.cpp \
qmakeproject.cpp \
qmakenodes.cpp \
qmakesettings.cpp \

View File

@@ -46,7 +46,6 @@ Project {
"qmakenodes.cpp", "qmakenodes.h",
"qmakenodetreebuilder.cpp", "qmakenodetreebuilder.h",
"qmakeproject.cpp", "qmakeproject.h",
"qmakeprojectmanager.cpp", "qmakeprojectmanager.h",
"qmakeprojectmanager.qrc",
"qmakeprojectmanager_global.h",
"qmakeprojectmanagerconstants.h",

View File

@@ -25,8 +25,8 @@
#include "qmakeprojectmanagerplugin.h"
#include "addlibrarywizard.h"
#include "profileeditor.h"
#include "qmakeprojectmanager.h"
#include "qmakenodes.h"
#include "qmakesettings.h"
#include "qmakestep.h"
@@ -50,12 +50,15 @@
#include <coreplugin/editormanager/ieditor.h>
#include <projectexplorer/buildmanager.h>
#include <projectexplorer/projectnodes.h>
#include <projectexplorer/projectmanager.h>
#include <projectexplorer/projecttree.h>
#include <projectexplorer/runcontrol.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
#include <projectexplorer/projectexplorer.h>
#include <texteditor/texteditor.h>
#include <texteditor/texteditoractionhandler.h>
#include <texteditor/texteditorconstants.h>
@@ -68,6 +71,7 @@
using namespace Core;
using namespace ProjectExplorer;
using namespace TextEditor;
namespace QmakeProjectManager {
namespace Internal {
@@ -87,7 +91,6 @@ public:
void disableBuildFileMenus();
void enableBuildFileMenus(const Utils::FilePath &file);
QmakeManager qmakeProjectManager;
Core::Context projectContext;
CustomWizardMetaFactory<CustomQmakeProjectWizard>
@@ -106,7 +109,7 @@ public:
ExternalQtEditor *m_linguistEditor{ExternalQtEditor::createLinguistEditor()};
QmakeProject *m_previousStartupProject = nullptr;
ProjectExplorer::Target *m_previousTarget = nullptr;
Target *m_previousTarget = nullptr;
QAction *m_runQMakeAction = nullptr;
QAction *m_runQMakeActionContextMenu = nullptr;
@@ -123,6 +126,26 @@ public:
QAction *m_addLibraryActionContextMenu = nullptr;
QmakeKitAspect qmakeKitAspect;
enum Action { BUILD, REBUILD, CLEAN };
void addLibrary();
void addLibraryContextMenu();
void runQMake();
void runQMakeContextMenu();
void buildSubDirContextMenu();
void rebuildSubDirContextMenu();
void cleanSubDirContextMenu();
void buildFileContextMenu();
void buildFile();
void handleSubDirContextMenu(Action action, bool isFileBuild);
static void handleSubDirContextMenu(Action action, bool isFileBuild,
Project *contextProject,
Node *contextProFileNode,
FileNode *buildableFile);
void addLibraryImpl(const QString &fileName, TextEditor::BaseTextEditor *editor);
void runQMakeImpl(Project *p, ProjectExplorer::Node *node);
};
QmakeProjectManagerPlugin::~QmakeProjectManagerPlugin()
@@ -172,7 +195,7 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
command->setDescription(d->m_buildSubProjectContextMenu->text());
msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
connect(d->m_buildSubProjectContextMenu, &QAction::triggered,
&d->qmakeProjectManager, &QmakeManager::buildSubDirContextMenu);
d, &QmakeProjectManagerPluginPrivate::buildSubDirContextMenu);
d->m_runQMakeActionContextMenu = new QAction(tr("Run qmake"), this);
command = ActionManager::registerAction(d->m_runQMakeActionContextMenu, Constants::RUNQMAKECONTEXTMENU, projectContext);
@@ -180,7 +203,7 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
mproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
connect(d->m_runQMakeActionContextMenu, &QAction::triggered,
&d->qmakeProjectManager, &QmakeManager::runQMakeContextMenu);
d, &QmakeProjectManagerPluginPrivate::runQMakeContextMenu);
command = msubproject->addSeparator(projectContext, ProjectExplorer::Constants::G_PROJECT_BUILD,
&d->m_subProjectRebuildSeparator);
@@ -192,7 +215,7 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
command->setAttribute(Command::CA_Hide);
msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
connect(d->m_rebuildSubProjectContextMenu, &QAction::triggered,
&d->qmakeProjectManager, &QmakeManager::rebuildSubDirContextMenu);
d, &QmakeProjectManagerPluginPrivate::rebuildSubDirContextMenu);
d->m_cleanSubProjectContextMenu = new QAction(tr("Clean"), this);
command = ActionManager::registerAction(
@@ -200,14 +223,14 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
command->setAttribute(Command::CA_Hide);
msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
connect(d->m_cleanSubProjectContextMenu, &QAction::triggered,
&d->qmakeProjectManager, &QmakeManager::cleanSubDirContextMenu);
d, &QmakeProjectManagerPluginPrivate::cleanSubDirContextMenu);
d->m_buildFileContextMenu = new QAction(tr("Build"), this);
command = ActionManager::registerAction(d->m_buildFileContextMenu, Constants::BUILDFILECONTEXTMENU, projectContext);
command->setAttribute(Command::CA_Hide);
mfile->addAction(command, ProjectExplorer::Constants::G_FILE_OTHER);
connect(d->m_buildFileContextMenu, &QAction::triggered,
&d->qmakeProjectManager, &QmakeManager::buildFileContextMenu);
d, &QmakeProjectManagerPluginPrivate::buildFileContextMenu);
d->m_buildSubProjectAction = new Utils::ParameterAction(tr("Build &Subproject"), tr("Build &Subproject \"%1\""),
Utils::ParameterAction::AlwaysEnabled, this);
@@ -217,13 +240,14 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
command->setDescription(d->m_buildSubProjectAction->text());
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD);
connect(d->m_buildSubProjectAction, &QAction::triggered,
&d->qmakeProjectManager, &QmakeManager::buildSubDirContextMenu);
d, &QmakeProjectManagerPluginPrivate::buildSubDirContextMenu);
d->m_runQMakeAction = new QAction(tr("Run qmake"), this);
const Context globalcontext(Core::Constants::C_GLOBAL);
command = ActionManager::registerAction(d->m_runQMakeAction, Constants::RUNQMAKE, globalcontext);
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD);
connect(d->m_runQMakeAction, &QAction::triggered, &d->qmakeProjectManager, &QmakeManager::runQMake);
connect(d->m_runQMakeAction, &QAction::triggered,
d, &QmakeProjectManagerPluginPrivate::runQMake);
d->m_rebuildSubProjectAction = new Utils::ParameterAction(tr("Rebuild Subproject"), tr("Rebuild Subproject \"%1\""),
Utils::ParameterAction::AlwaysEnabled, this);
@@ -233,7 +257,7 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
command->setDescription(d->m_rebuildSubProjectAction->text());
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_REBUILD);
connect(d->m_rebuildSubProjectAction, &QAction::triggered,
&d->qmakeProjectManager, &QmakeManager::rebuildSubDirContextMenu);
d, &QmakeProjectManagerPluginPrivate::rebuildSubDirContextMenu);
d->m_cleanSubProjectAction = new Utils::ParameterAction(tr("Clean Subproject"), tr("Clean Subproject \"%1\""),
Utils::ParameterAction::AlwaysEnabled, this);
@@ -243,7 +267,7 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
command->setDescription(d->m_cleanSubProjectAction->text());
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_CLEAN);
connect(d->m_cleanSubProjectAction, &QAction::triggered,
&d->qmakeProjectManager, &QmakeManager::cleanSubDirContextMenu);
d, &QmakeProjectManagerPluginPrivate::cleanSubDirContextMenu);
d->m_buildFileAction = new Utils::ParameterAction(tr("Build File"), tr("Build File \"%1\""),
Utils::ParameterAction::AlwaysEnabled, this);
@@ -253,7 +277,8 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
command->setDescription(d->m_buildFileAction->text());
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+B")));
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD);
connect(d->m_buildFileAction, &QAction::triggered, &d->qmakeProjectManager, &QmakeManager::buildFile);
connect(d->m_buildFileAction, &QAction::triggered,
d, &QmakeProjectManagerPluginPrivate::buildFile);
connect(BuildManager::instance(), &BuildManager::buildStateChanged,
d, &QmakeProjectManagerPluginPrivate::buildStateChanged);
@@ -275,14 +300,15 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
d->m_addLibraryAction = new QAction(tr("Add Library..."), this);
command = ActionManager::registerAction(d->m_addLibraryAction,
Constants::ADDLIBRARY, proFileEditorContext);
connect(d->m_addLibraryAction, &QAction::triggered, &d->qmakeProjectManager, &QmakeManager::addLibrary);
connect(d->m_addLibraryAction, &QAction::triggered,
d, &QmakeProjectManagerPluginPrivate::addLibrary);
contextMenu->addAction(command);
d->m_addLibraryActionContextMenu = new QAction(tr("Add Library..."), this);
command = ActionManager::registerAction(d->m_addLibraryActionContextMenu,
Constants::ADDLIBRARY, projectTreeContext);
connect(d->m_addLibraryActionContextMenu, &QAction::triggered,
&d->qmakeProjectManager, &QmakeManager::addLibraryContextMenu);
d, &QmakeProjectManagerPluginPrivate::addLibraryContextMenu);
mproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_FILES);
msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_FILES);
@@ -324,6 +350,203 @@ void QmakeProjectManagerPluginPrivate::projectChanged()
activeTargetChanged();
}
static QmakeProFileNode *buildableFileProFile(Node *node)
{
if (node) {
auto subPriFileNode = dynamic_cast<QmakePriFileNode *>(node);
if (!subPriFileNode)
subPriFileNode = dynamic_cast<QmakePriFileNode *>(node->parentProjectNode());
if (subPriFileNode)
return subPriFileNode->proFileNode();
}
return nullptr;
}
void QmakeProjectManagerPluginPrivate::addLibrary()
{
if (auto editor = qobject_cast<BaseTextEditor *>(Core::EditorManager::currentEditor()))
addLibraryImpl(editor->document()->filePath().toString(), editor);
}
void QmakeProjectManagerPluginPrivate::addLibraryContextMenu()
{
QString projectPath;
Node *node = ProjectTree::currentNode();
if (ContainerNode *cn = node->asContainerNode())
projectPath = cn->project()->projectFilePath().toString();
else if (dynamic_cast<QmakeProFileNode *>(node))
projectPath = node->filePath().toString();
addLibraryImpl(projectPath, nullptr);
}
void QmakeProjectManagerPluginPrivate::addLibraryImpl(const QString &fileName, BaseTextEditor *editor)
{
if (fileName.isEmpty())
return;
Internal::AddLibraryWizard wizard(fileName, Core::ICore::dialogParent());
if (wizard.exec() != QDialog::Accepted)
return;
if (!editor)
editor = qobject_cast<BaseTextEditor *>(Core::EditorManager::openEditor(fileName,
Constants::PROFILE_EDITOR_ID, Core::EditorManager::DoNotMakeVisible));
if (!editor)
return;
const int endOfDoc = editor->position(EndOfDocPosition);
editor->setCursorPosition(endOfDoc);
QString snippet = wizard.snippet();
// add extra \n in case the last line is not empty
int line, column;
editor->convertPosition(endOfDoc, &line, &column);
const int positionInBlock = column - 1;
if (!editor->textAt(endOfDoc - positionInBlock, positionInBlock).simplified().isEmpty())
snippet = QLatin1Char('\n') + snippet;
editor->insert(snippet);
}
void QmakeProjectManagerPluginPrivate::runQMake()
{
runQMakeImpl(SessionManager::startupProject(), nullptr);
}
void QmakeProjectManagerPluginPrivate::runQMakeContextMenu()
{
runQMakeImpl(ProjectTree::currentProject(), ProjectTree::currentNode());
}
void QmakeProjectManagerPluginPrivate::runQMakeImpl(Project *p, Node *node)
{
if (!ProjectExplorerPlugin::saveModifiedFiles())
return;
auto *qmakeProject = qobject_cast<QmakeProject *>(p);
QTC_ASSERT(qmakeProject, return);
if (!qmakeProject->activeTarget() || !qmakeProject->activeTarget()->activeBuildConfiguration())
return;
auto *bc = static_cast<QmakeBuildConfiguration *>(qmakeProject->activeTarget()->activeBuildConfiguration());
QMakeStep *qs = bc->qmakeStep();
if (!qs)
return;
//found qmakeStep, now use it
qs->setForced(true);
if (node && node != qmakeProject->rootProjectNode())
if (auto *profile = dynamic_cast<QmakeProFileNode *>(node))
bc->setSubNodeBuild(profile);
BuildManager::appendStep(qs, tr("QMake"));
bc->setSubNodeBuild(nullptr);
}
void QmakeProjectManagerPluginPrivate::buildSubDirContextMenu()
{
handleSubDirContextMenu(BUILD, false);
}
void QmakeProjectManagerPluginPrivate::cleanSubDirContextMenu()
{
handleSubDirContextMenu(CLEAN, false);
}
void QmakeProjectManagerPluginPrivate::rebuildSubDirContextMenu()
{
handleSubDirContextMenu(REBUILD, false);
}
void QmakeProjectManagerPluginPrivate::buildFileContextMenu()
{
handleSubDirContextMenu(BUILD, true);
}
void QmakeProjectManagerPluginPrivate::buildFile()
{
if (Core::IDocument *currentDocument= Core::EditorManager::currentDocument()) {
const Utils::FilePath file = currentDocument->filePath();
Node *n = ProjectTree::nodeForFile(file);
FileNode *node = n ? n->asFileNode() : nullptr;
Project *project = SessionManager::projectForFile(file);
if (project && node)
handleSubDirContextMenu(BUILD, true, project, node->parentProjectNode(), node);
}
}
void QmakeProjectManagerPlugin::buildProduct(Project *project, Node *proFileNode)
{
QmakeProjectManagerPluginPrivate::handleSubDirContextMenu(
QmakeProjectManagerPluginPrivate::BUILD, false, project, proFileNode, nullptr);
}
void QmakeProjectManagerPluginPrivate::handleSubDirContextMenu(Action action, bool isFileBuild)
{
Node *node = ProjectTree::currentNode();
QmakeProFileNode *subProjectNode = buildableFileProFile(node);
FileNode *fileNode = node ? node->asFileNode() : nullptr;
bool buildFilePossible = subProjectNode && fileNode && fileNode->fileType() == FileType::Source;
FileNode *buildableFileNode = buildFilePossible ? fileNode : nullptr;
handleSubDirContextMenu(action,
isFileBuild,
ProjectTree::currentProject(),
buildableFileProFile(ProjectTree::currentNode()),
buildableFileNode);
}
void QmakeProjectManagerPluginPrivate::handleSubDirContextMenu(Action action, bool isFileBuild,
Project *contextProject, Node *contextNode,
FileNode *buildableFile)
{
QTC_ASSERT(contextProject, return);
Target *target = contextProject->activeTarget();
if (!target)
return;
auto *bc = qobject_cast<QmakeBuildConfiguration *>(target->activeBuildConfiguration());
if (!bc)
return;
if (!contextNode || !buildableFile)
isFileBuild = false;
if (auto *prifile = dynamic_cast<QmakePriFileNode *>(contextNode)) {
if (QmakeProFileNode *profile = prifile->proFileNode()) {
if (profile != contextProject->rootProjectNode() || isFileBuild)
bc->setSubNodeBuild(profile->proFileNode());
}
}
if (isFileBuild)
bc->setFileNodeBuild(buildableFile);
if (ProjectExplorerPlugin::saveModifiedFiles()) {
const Core::Id buildStep = ProjectExplorer::Constants::BUILDSTEPS_BUILD;
const Core::Id cleanStep = ProjectExplorer::Constants::BUILDSTEPS_CLEAN;
if (action == BUILD) {
BuildManager::buildList(bc->buildSteps());
} else if (action == CLEAN) {
BuildManager::buildList(bc->cleanSteps());
} else if (action == REBUILD) {
QStringList names;
names << ProjectExplorerPlugin::displayNameForStepId(cleanStep)
<< ProjectExplorerPlugin::displayNameForStepId(buildStep);
BuildManager::buildLists({bc->cleanSteps(), bc->buildSteps()}, names);
}
}
bc->setSubNodeBuild(nullptr);
bc->setFileNodeBuild(nullptr);
}
void QmakeProjectManagerPluginPrivate::activeTargetChanged()
{
if (m_previousTarget)

View File

@@ -27,6 +27,11 @@
#include <extensionsystem/iplugin.h>
namespace ProjectExplorer {
class Project;
class Node;
} // ProjectExplorer
namespace QmakeProjectManager {
namespace Internal {
@@ -38,6 +43,8 @@ class QmakeProjectManagerPlugin final : public ExtensionSystem::IPlugin
public:
~QmakeProjectManagerPlugin() final;
static void buildProduct(ProjectExplorer::Project *project, ProjectExplorer::Node *proFileNode);
#ifdef WITH_TESTS
private slots:
void testQmakeOutputParsers_data();

View File

@@ -26,7 +26,6 @@
#include "qtwizard.h"
#include <qmakeprojectmanager/qmakeproject.h>
#include <qmakeprojectmanager/qmakeprojectmanager.h>
#include <qmakeprojectmanager/qmakeprojectmanagerconstants.h>
#include <coreplugin/icore.h>