From b6a593e4f9dcfeb48c9c080a67aa88a346699fbe Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 22 Feb 2023 16:04:59 +0100 Subject: [PATCH] ProjectExplorer: Add a generic copy step Change-Id: I6b4a70e3f71776f7009c0419c8d2f41dfd1c704d Reviewed-by: Jarek Kobus --- src/plugins/projectexplorer/CMakeLists.txt | 1 + src/plugins/projectexplorer/copystep.cpp | 114 ++++++++++++++++++ src/plugins/projectexplorer/copystep.h | 22 ++++ .../projectexplorer/projectexplorer.cpp | 3 + .../projectexplorer/projectexplorer.qbs | 1 + 5 files changed, 141 insertions(+) create mode 100644 src/plugins/projectexplorer/copystep.cpp create mode 100644 src/plugins/projectexplorer/copystep.h diff --git a/src/plugins/projectexplorer/CMakeLists.txt b/src/plugins/projectexplorer/CMakeLists.txt index deacbc57c56..b14cb87a5ff 100644 --- a/src/plugins/projectexplorer/CMakeLists.txt +++ b/src/plugins/projectexplorer/CMakeLists.txt @@ -28,6 +28,7 @@ add_qtc_plugin(ProjectExplorer codestylesettingspropertiespage.cpp codestylesettingspropertiespage.h compileoutputwindow.cpp compileoutputwindow.h configtaskhandler.cpp configtaskhandler.h + copystep.cpp copystep.h copytaskhandler.cpp copytaskhandler.h currentprojectfilter.cpp currentprojectfilter.h currentprojectfind.cpp currentprojectfind.h diff --git a/src/plugins/projectexplorer/copystep.cpp b/src/plugins/projectexplorer/copystep.cpp new file mode 100644 index 00000000000..b07c28b3cfd --- /dev/null +++ b/src/plugins/projectexplorer/copystep.cpp @@ -0,0 +1,114 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include "copystep.h" + +#include "projectexplorertr.h" + +#include + +using namespace Utils; + +namespace ProjectExplorer::Internal { + +const char SOURCE_KEY[] = "ProjectExplorer.CopyStep.Source"; +const char TARGET_KEY[] = "ProjectExplorer.CopyStep.Target"; + +class CopyStepBase : public BuildStep +{ +public: + CopyStepBase(BuildStepList *bsl, Id id) + : BuildStep(bsl, id) + { + m_sourceAspect = addAspect(); + m_sourceAspect->setSettingsKey(SOURCE_KEY); + m_sourceAspect->setDisplayStyle(StringAspect::PathChooserDisplay); + m_sourceAspect->setLabelText(Tr::tr("Source:")); + + m_targetAspect = addAspect(); + m_targetAspect->setSettingsKey(TARGET_KEY); + m_targetAspect->setDisplayStyle(StringAspect::PathChooserDisplay); + m_targetAspect->setLabelText(Tr::tr("Target:")); + + addMacroExpander(); + } + +protected: + bool init() final + { + m_source = m_sourceAspect->filePath(); + m_target = m_targetAspect->filePath(); + return m_source.exists(); + } + + void doRun() final + { + // FIXME: asyncCopy does not handle directories yet. + QTC_ASSERT(m_source.isFile(), emit finished(false)); + m_source.asyncCopy(m_target, [this](const expected_str &cont) { + if (!cont) { + addOutput(cont.error(), OutputFormat::ErrorMessage); + addOutput(Tr::tr("Copying failed"), OutputFormat::ErrorMessage); + emit finished(false); + } else { + addOutput(Tr::tr("Copying finished"), OutputFormat::NormalMessage); + emit finished(true); + } + }); + } + + StringAspect *m_sourceAspect; + StringAspect *m_targetAspect; + +private: + FilePath m_source; + FilePath m_target; +}; + +class CopyFileStep final : public CopyStepBase +{ +public: + CopyFileStep(BuildStepList *bsl, Id id) + : CopyStepBase(bsl, id) + { + m_sourceAspect->setExpectedKind(PathChooser::File); + m_targetAspect->setExpectedKind(PathChooser::SaveFile); + + setSummaryUpdater([] { + return QString("" + Tr::tr("Copy file") + ""); + }); + } +}; + +class CopyDirectoryStep final : public CopyStepBase +{ +public: + CopyDirectoryStep(BuildStepList *bsl, Id id) + : CopyStepBase(bsl, id) + { + m_sourceAspect->setExpectedKind(PathChooser::Directory); + m_targetAspect->setExpectedKind(PathChooser::Directory); + + setSummaryUpdater([] { + return QString("" + Tr::tr("Copy directory recursively") + ""); + }); + } +}; + +// Factories + +CopyFileStepFactory::CopyFileStepFactory() +{ + registerStep("ProjectExplorer.CopyFileStep"); + //: Default CopyStep display name + setDisplayName(Tr::tr("Copy file")); +} + +CopyDirectoryStepFactory::CopyDirectoryStepFactory() +{ + registerStep("ProjectExplorer.CopyDirectoryStep"); + //: Default CopyStep display name + setDisplayName(Tr::tr("Copy directory recursively")); +} + +} // ProjectExplorer::Internal diff --git a/src/plugins/projectexplorer/copystep.h b/src/plugins/projectexplorer/copystep.h new file mode 100644 index 00000000000..07940f3a89a --- /dev/null +++ b/src/plugins/projectexplorer/copystep.h @@ -0,0 +1,22 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#pragma once + +#include "buildstep.h" + +namespace ProjectExplorer::Internal { + +class CopyFileStepFactory final : public BuildStepFactory +{ +public: + CopyFileStepFactory(); +}; + +class CopyDirectoryStepFactory final : public BuildStepFactory +{ +public: + CopyDirectoryStepFactory(); +}; + +} // ProjectExplorer::Internal diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 3834593a63e..25aae3385c2 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -8,6 +8,7 @@ #include "buildsystem.h" #include "compileoutputwindow.h" #include "configtaskhandler.h" +#include "copystep.h" #include "customexecutablerunconfiguration.h" #include "customparserssettingspage.h" #include "customwizard/customwizard.h" @@ -680,6 +681,8 @@ public: RunRunConfigurationLocatorFilter m_runConfigurationLocatorFilter; SwitchToRunConfigurationLocatorFilter m_switchRunConfigurationLocatorFilter; + CopyFileStepFactory m_copyFileStepFactory; + CopyDirectoryStepFactory m_copyDirectoryFactory; ProcessStepFactory m_processStepFactory; AllProjectsFind m_allProjectsFind; diff --git a/src/plugins/projectexplorer/projectexplorer.qbs b/src/plugins/projectexplorer/projectexplorer.qbs index 27be767db9c..e7d3d76b794 100644 --- a/src/plugins/projectexplorer/projectexplorer.qbs +++ b/src/plugins/projectexplorer/projectexplorer.qbs @@ -45,6 +45,7 @@ Project { "codestylesettingspropertiespage.cpp", "codestylesettingspropertiespage.h", "compileoutputwindow.cpp", "compileoutputwindow.h", "configtaskhandler.cpp", "configtaskhandler.h", + "copystep.cpp", "copystep.h", "copytaskhandler.cpp", "copytaskhandler.h", "currentprojectfilter.cpp", "currentprojectfilter.h", "currentprojectfind.cpp", "currentprojectfind.h",