forked from qt-creator/qt-creator
ProjectExplorer: Add a generic copy step
Change-Id: I6b4a70e3f71776f7009c0419c8d2f41dfd1c704d Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -28,6 +28,7 @@ add_qtc_plugin(ProjectExplorer
|
|||||||
codestylesettingspropertiespage.cpp codestylesettingspropertiespage.h
|
codestylesettingspropertiespage.cpp codestylesettingspropertiespage.h
|
||||||
compileoutputwindow.cpp compileoutputwindow.h
|
compileoutputwindow.cpp compileoutputwindow.h
|
||||||
configtaskhandler.cpp configtaskhandler.h
|
configtaskhandler.cpp configtaskhandler.h
|
||||||
|
copystep.cpp copystep.h
|
||||||
copytaskhandler.cpp copytaskhandler.h
|
copytaskhandler.cpp copytaskhandler.h
|
||||||
currentprojectfilter.cpp currentprojectfilter.h
|
currentprojectfilter.cpp currentprojectfilter.h
|
||||||
currentprojectfind.cpp currentprojectfind.h
|
currentprojectfind.cpp currentprojectfind.h
|
||||||
|
114
src/plugins/projectexplorer/copystep.cpp
Normal file
114
src/plugins/projectexplorer/copystep.cpp
Normal file
@@ -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 <utils/aspects.h>
|
||||||
|
|
||||||
|
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<StringAspect>();
|
||||||
|
m_sourceAspect->setSettingsKey(SOURCE_KEY);
|
||||||
|
m_sourceAspect->setDisplayStyle(StringAspect::PathChooserDisplay);
|
||||||
|
m_sourceAspect->setLabelText(Tr::tr("Source:"));
|
||||||
|
|
||||||
|
m_targetAspect = addAspect<StringAspect>();
|
||||||
|
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<void> &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("<b>" + Tr::tr("Copy file") + "</b>");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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("<b>" + Tr::tr("Copy directory recursively") + "</b>");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Factories
|
||||||
|
|
||||||
|
CopyFileStepFactory::CopyFileStepFactory()
|
||||||
|
{
|
||||||
|
registerStep<CopyFileStep>("ProjectExplorer.CopyFileStep");
|
||||||
|
//: Default CopyStep display name
|
||||||
|
setDisplayName(Tr::tr("Copy file"));
|
||||||
|
}
|
||||||
|
|
||||||
|
CopyDirectoryStepFactory::CopyDirectoryStepFactory()
|
||||||
|
{
|
||||||
|
registerStep<CopyDirectoryStep>("ProjectExplorer.CopyDirectoryStep");
|
||||||
|
//: Default CopyStep display name
|
||||||
|
setDisplayName(Tr::tr("Copy directory recursively"));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // ProjectExplorer::Internal
|
22
src/plugins/projectexplorer/copystep.h
Normal file
22
src/plugins/projectexplorer/copystep.h
Normal file
@@ -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
|
@@ -8,6 +8,7 @@
|
|||||||
#include "buildsystem.h"
|
#include "buildsystem.h"
|
||||||
#include "compileoutputwindow.h"
|
#include "compileoutputwindow.h"
|
||||||
#include "configtaskhandler.h"
|
#include "configtaskhandler.h"
|
||||||
|
#include "copystep.h"
|
||||||
#include "customexecutablerunconfiguration.h"
|
#include "customexecutablerunconfiguration.h"
|
||||||
#include "customparserssettingspage.h"
|
#include "customparserssettingspage.h"
|
||||||
#include "customwizard/customwizard.h"
|
#include "customwizard/customwizard.h"
|
||||||
@@ -680,6 +681,8 @@ public:
|
|||||||
RunRunConfigurationLocatorFilter m_runConfigurationLocatorFilter;
|
RunRunConfigurationLocatorFilter m_runConfigurationLocatorFilter;
|
||||||
SwitchToRunConfigurationLocatorFilter m_switchRunConfigurationLocatorFilter;
|
SwitchToRunConfigurationLocatorFilter m_switchRunConfigurationLocatorFilter;
|
||||||
|
|
||||||
|
CopyFileStepFactory m_copyFileStepFactory;
|
||||||
|
CopyDirectoryStepFactory m_copyDirectoryFactory;
|
||||||
ProcessStepFactory m_processStepFactory;
|
ProcessStepFactory m_processStepFactory;
|
||||||
|
|
||||||
AllProjectsFind m_allProjectsFind;
|
AllProjectsFind m_allProjectsFind;
|
||||||
|
@@ -45,6 +45,7 @@ Project {
|
|||||||
"codestylesettingspropertiespage.cpp", "codestylesettingspropertiespage.h",
|
"codestylesettingspropertiespage.cpp", "codestylesettingspropertiespage.h",
|
||||||
"compileoutputwindow.cpp", "compileoutputwindow.h",
|
"compileoutputwindow.cpp", "compileoutputwindow.h",
|
||||||
"configtaskhandler.cpp", "configtaskhandler.h",
|
"configtaskhandler.cpp", "configtaskhandler.h",
|
||||||
|
"copystep.cpp", "copystep.h",
|
||||||
"copytaskhandler.cpp", "copytaskhandler.h",
|
"copytaskhandler.cpp", "copytaskhandler.h",
|
||||||
"currentprojectfilter.cpp", "currentprojectfilter.h",
|
"currentprojectfilter.cpp", "currentprojectfilter.h",
|
||||||
"currentprojectfind.cpp", "currentprojectfind.h",
|
"currentprojectfind.cpp", "currentprojectfind.h",
|
||||||
|
Reference in New Issue
Block a user