ProjectExplorer: Use direct aspect registration in ProcessStep

Task-number: QTCREATORBUG-29168
Change-Id: If83acc092689a935cf81c8133d6a07d802a07177
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2023-06-29 18:05:07 +02:00
parent f3654b8fd2
commit 345c946255
2 changed files with 53 additions and 60 deletions

View File

@@ -11,13 +11,11 @@
#include "projectexplorertr.h" #include "projectexplorertr.h"
#include <utils/aspects.h> #include <utils/aspects.h>
#include <utils/fileutils.h>
#include <utils/outputformatter.h> #include <utils/outputformatter.h>
using namespace Utils; using namespace Utils;
namespace ProjectExplorer { namespace ProjectExplorer::Internal {
namespace Internal {
const char PROCESS_COMMAND_KEY[] = "ProjectExplorer.ProcessStep.Command"; const char PROCESS_COMMAND_KEY[] = "ProjectExplorer.ProcessStep.Command";
const char PROCESS_WORKINGDIRECTORY_KEY[] = "ProjectExplorer.ProcessStep.WorkingDirectory"; const char PROCESS_WORKINGDIRECTORY_KEY[] = "ProjectExplorer.ProcessStep.WorkingDirectory";
@@ -26,40 +24,32 @@ const char PROCESS_ARGUMENTS_KEY[] = "ProjectExplorer.ProcessStep.Arguments";
class ProcessStep final : public AbstractProcessStep class ProcessStep final : public AbstractProcessStep
{ {
public: public:
ProcessStep(BuildStepList *bsl, Id id); ProcessStep(BuildStepList *bsl, Id id)
void setupOutputFormatter(OutputFormatter *formatter) final;
};
ProcessStep::ProcessStep(BuildStepList *bsl, Id id)
: AbstractProcessStep(bsl, id) : AbstractProcessStep(bsl, id)
{ {
auto command = addAspect<FilePathAspect>(); command.setSettingsKey(PROCESS_COMMAND_KEY);
command->setSettingsKey(PROCESS_COMMAND_KEY); command.setLabelText(Tr::tr("Command:"));
command->setLabelText(Tr::tr("Command:")); command.setExpectedKind(PathChooser::Command);
command->setExpectedKind(PathChooser::Command); command.setHistoryCompleter("PE.ProcessStepCommand.History");
command->setHistoryCompleter("PE.ProcessStepCommand.History");
auto arguments = addAspect<StringAspect>(); arguments.setSettingsKey(PROCESS_ARGUMENTS_KEY);
arguments->setSettingsKey(PROCESS_ARGUMENTS_KEY); arguments.setDisplayStyle(StringAspect::LineEditDisplay);
arguments->setDisplayStyle(StringAspect::LineEditDisplay); arguments.setLabelText(Tr::tr("Arguments:"));
arguments->setLabelText(Tr::tr("Arguments:"));
auto workingDirectory = addAspect<FilePathAspect>(); workingDirectory.setSettingsKey(PROCESS_WORKINGDIRECTORY_KEY);
workingDirectory->setSettingsKey(PROCESS_WORKINGDIRECTORY_KEY); workingDirectory.setValue(Constants::DEFAULT_WORKING_DIR);
workingDirectory->setValue(Constants::DEFAULT_WORKING_DIR); workingDirectory.setLabelText(Tr::tr("Working directory:"));
workingDirectory->setLabelText(Tr::tr("Working directory:")); workingDirectory.setExpectedKind(PathChooser::Directory);
workingDirectory->setExpectedKind(PathChooser::Directory);
setWorkingDirectoryProvider([this, workingDirectory] { setWorkingDirectoryProvider([this] {
const FilePath workingDir = workingDirectory->filePath(); const FilePath workingDir = workingDirectory();
if (workingDir.isEmpty()) if (workingDir.isEmpty())
return FilePath::fromString(fallbackWorkingDirectory()); return FilePath::fromString(fallbackWorkingDirectory());
return workingDir; return workingDir;
}); });
setCommandLineProvider([command, arguments] { setCommandLineProvider([this] {
return CommandLine{command->filePath(), arguments->value(), CommandLine::Raw}; return CommandLine{command(), arguments(), CommandLine::Raw};
}); });
setSummaryUpdater([this] { setSummaryUpdater([this] {
@@ -74,12 +64,18 @@ ProcessStep::ProcessStep(BuildStepList *bsl, Id id)
addMacroExpander(); addMacroExpander();
} }
void ProcessStep::setupOutputFormatter(OutputFormatter *formatter) private:
void setupOutputFormatter(OutputFormatter *formatter) final
{ {
formatter->addLineParsers(kit()->createOutputParsers()); formatter->addLineParsers(kit()->createOutputParsers());
AbstractProcessStep::setupOutputFormatter(formatter); AbstractProcessStep::setupOutputFormatter(formatter);
} }
FilePathAspect command{this};
StringAspect arguments{this};
FilePathAspect workingDirectory{this};
};
// ProcessStepFactory // ProcessStepFactory
ProcessStepFactory::ProcessStepFactory() ProcessStepFactory::ProcessStepFactory()
@@ -89,5 +85,4 @@ ProcessStepFactory::ProcessStepFactory()
setDisplayName(Tr::tr("Custom Process Step")); setDisplayName(Tr::tr("Custom Process Step"));
} }
} // Internal } // ProjectExplorer::Internal
} // ProjectExplorer

View File

@@ -5,8 +5,7 @@
#include "buildstep.h" #include "buildstep.h"
namespace ProjectExplorer { namespace ProjectExplorer::Internal {
namespace Internal {
class ProcessStepFactory final : public BuildStepFactory class ProcessStepFactory final : public BuildStepFactory
{ {
@@ -14,5 +13,4 @@ public:
ProcessStepFactory(); ProcessStepFactory();
}; };
} // namespace Internal } // ProjectExplorer::Internal
} // namespace ProjectExplorer