diff --git a/src/plugins/qmakeprojectmanager/CMakeLists.txt b/src/plugins/qmakeprojectmanager/CMakeLists.txt index 835913cac3a..b87a17a66a6 100644 --- a/src/plugins/qmakeprojectmanager/CMakeLists.txt +++ b/src/plugins/qmakeprojectmanager/CMakeLists.txt @@ -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 diff --git a/src/plugins/qmakeprojectmanager/profileeditor.cpp b/src/plugins/qmakeprojectmanager/profileeditor.cpp index 3d14ff3d500..e7757e0359a 100644 --- a/src/plugins/qmakeprojectmanager/profileeditor.cpp +++ b/src/plugins/qmakeprojectmanager/profileeditor.cpp @@ -30,8 +30,6 @@ #include "profilehoverhandler.h" #include "qmakenodes.h" #include "qmakeproject.h" -#include "qmakeprojectmanager.h" -#include "qmakeprojectmanagerconstants.h" #include "qmakeprojectmanagerconstants.h" #include diff --git a/src/plugins/qmakeprojectmanager/qmakenodes.cpp b/src/plugins/qmakeprojectmanager/qmakenodes.cpp index 59f22e4faa8..a16603f2eca 100644 --- a/src/plugins/qmakeprojectmanager/qmakenodes.cpp +++ b/src/plugins/qmakeprojectmanager/qmakenodes.cpp @@ -26,7 +26,7 @@ #include "qmakenodes.h" #include "qmakeproject.h" -#include "qmakeprojectmanager.h" +#include "qmakeprojectmanagerplugin.h" #include #include @@ -339,7 +339,7 @@ bool QmakeProFileNode::validParse() const void QmakeProFileNode::build() { - QmakeManager::buildProduct(getProject(), this); + QmakeProjectManagerPlugin::buildProduct(getProject(), this); } QStringList QmakeProFileNode::targetApplications() const diff --git a/src/plugins/qmakeprojectmanager/qmakeproject.cpp b/src/plugins/qmakeprojectmanager/qmakeproject.cpp index d28b390d54d..a807adf1d69 100644 --- a/src/plugins/qmakeprojectmanager/qmakeproject.cpp +++ b/src/plugins/qmakeprojectmanager/qmakeproject.cpp @@ -25,7 +25,6 @@ #include "qmakeproject.h" -#include "qmakeprojectmanager.h" #include "qmakeprojectimporter.h" #include "qmakebuildinfo.h" #include "qmakestep.h" diff --git a/src/plugins/qmakeprojectmanager/qmakeproject.h b/src/plugins/qmakeprojectmanager/qmakeproject.h index b70bfbfdee9..4abc5309c5b 100644 --- a/src/plugins/qmakeprojectmanager/qmakeproject.h +++ b/src/plugins/qmakeprojectmanager/qmakeproject.h @@ -26,12 +26,12 @@ #pragma once #include "qmakeprojectmanager_global.h" -#include "qmakeprojectmanager.h" #include "qmakenodes.h" #include "qmakeparsernodes.h" #include #include +#include #include #include diff --git a/src/plugins/qmakeprojectmanager/qmakeprojectmanager.cpp b/src/plugins/qmakeprojectmanager/qmakeprojectmanager.cpp deleted file mode 100644 index ba7b44b7d64..00000000000 --- a/src/plugins/qmakeprojectmanager/qmakeprojectmanager.cpp +++ /dev/null @@ -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 -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -using namespace ProjectExplorer; -using namespace TextEditor; - -namespace QmakeProjectManager { - -static QmakeProFileNode *buildableFileProFile(Node *node) -{ - if (node) { - auto subPriFileNode = dynamic_cast(node); - if (!subPriFileNode) - subPriFileNode = dynamic_cast(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(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(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(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(p); - QTC_ASSERT(qmakeProject, return); - - if (!qmakeProject->activeTarget() || !qmakeProject->activeTarget()->activeBuildConfiguration()) - return; - - auto *bc = static_cast(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(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(target->activeBuildConfiguration()); - if (!bc) - return; - - if (!contextNode || !buildableFile) - isFileBuild = false; - - if (auto *prifile = dynamic_cast(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 diff --git a/src/plugins/qmakeprojectmanager/qmakeprojectmanager.h b/src/plugins/qmakeprojectmanager/qmakeprojectmanager.h deleted file mode 100644 index 722ab075773..00000000000 --- a/src/plugins/qmakeprojectmanager/qmakeprojectmanager.h +++ /dev/null @@ -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 - -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 diff --git a/src/plugins/qmakeprojectmanager/qmakeprojectmanager.pro b/src/plugins/qmakeprojectmanager/qmakeprojectmanager.pro index ee5e931c9ad..cc4f27ae78a 100644 --- a/src/plugins/qmakeprojectmanager/qmakeprojectmanager.pro +++ b/src/plugins/qmakeprojectmanager/qmakeprojectmanager.pro @@ -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 \ diff --git a/src/plugins/qmakeprojectmanager/qmakeprojectmanager.qbs b/src/plugins/qmakeprojectmanager/qmakeprojectmanager.qbs index 7b23de4e178..4955ca43a17 100644 --- a/src/plugins/qmakeprojectmanager/qmakeprojectmanager.qbs +++ b/src/plugins/qmakeprojectmanager/qmakeprojectmanager.qbs @@ -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", diff --git a/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp b/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp index 21978b33c24..a2ed0c1b956 100644 --- a/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp +++ b/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp @@ -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 #include +#include #include #include #include #include #include +#include +#include #include #include @@ -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 @@ -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(node); + if (!subPriFileNode) + subPriFileNode = dynamic_cast(node->parentProjectNode()); + if (subPriFileNode) + return subPriFileNode->proFileNode(); + } + return nullptr; +} + +void QmakeProjectManagerPluginPrivate::addLibrary() +{ + if (auto editor = qobject_cast(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(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(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(p); + QTC_ASSERT(qmakeProject, return); + + if (!qmakeProject->activeTarget() || !qmakeProject->activeTarget()->activeBuildConfiguration()) + return; + + auto *bc = static_cast(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(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(target->activeBuildConfiguration()); + if (!bc) + return; + + if (!contextNode || !buildableFile) + isFileBuild = false; + + if (auto *prifile = dynamic_cast(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) diff --git a/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.h b/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.h index 5b3176b9b72..1d11bb45cb5 100644 --- a/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.h +++ b/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.h @@ -27,6 +27,11 @@ #include +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(); diff --git a/src/plugins/qmakeprojectmanager/wizards/qtwizard.cpp b/src/plugins/qmakeprojectmanager/wizards/qtwizard.cpp index 38074cb0c61..f9d66de3ed6 100644 --- a/src/plugins/qmakeprojectmanager/wizards/qtwizard.cpp +++ b/src/plugins/qmakeprojectmanager/wizards/qtwizard.cpp @@ -26,7 +26,6 @@ #include "qtwizard.h" #include -#include #include #include