AppMan: Update Aspects of all deploy steps

Remove all custom Aspects we don't need anymore.

Change-Id: I201a500e9a2c31b8787bc2b093dc671cdab917a8
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Dominik Holland
2024-01-15 17:18:47 +01:00
parent 15d0402694
commit 09c549d12f
6 changed files with 123 additions and 284 deletions

View File

@@ -18,6 +18,7 @@
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/runconfiguration.h> #include <projectexplorer/runconfiguration.h>
#include <projectexplorer/runconfigurationaspects.h>
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
using namespace ProjectExplorer; using namespace ProjectExplorer;
@@ -37,42 +38,33 @@ public:
{ {
setDisplayName(Tr::tr("Create Application Manager package")); setDisplayName(Tr::tr("Create Application Manager package"));
executable.setSettingsKey(SETTINGSPREFIX "Executable"); packager.setSettingsKey(SETTINGSPREFIX "Executable");
executable.setHistoryCompleter(SETTINGSPREFIX "Executable.History");
executable.setExpectedKind(PathChooser::ExistingCommand);
executable.setLabelText(Tr::tr("Executable:"));
executable.setPromptDialogFilter(getToolNameByDevice(Constants::APPMAN_PACKAGER));
arguments.setSettingsKey(SETTINGSPREFIX "Arguments"); arguments.setSettingsKey(SETTINGSPREFIX "Arguments");
arguments.setHistoryCompleter(SETTINGSPREFIX "Arguments.History");
arguments.setDisplayStyle(StringAspect::LineEditDisplay);
arguments.setLabelText(Tr::tr("Arguments:"));
sourceDirectory.setSettingsKey(SETTINGSPREFIX "SourceDirectory"); sourceDirectory.setSettingsKey(SETTINGSPREFIX "SourceDirectory");
sourceDirectory.setHistoryCompleter(SETTINGSPREFIX "SourceDirectory.History");
sourceDirectory.setExpectedKind(PathChooser::Directory);
sourceDirectory.setLabelText(Tr::tr("Source directory:")); sourceDirectory.setLabelText(Tr::tr("Source directory:"));
sourceDirectory.setExpectedKind(Utils::PathChooser::ExistingDirectory);
buildDirectory.setSettingsKey(SETTINGSPREFIX "BuildDirectory"); packageFile.setSettingsKey(SETTINGSPREFIX "FileName");
buildDirectory.setHistoryCompleter(SETTINGSPREFIX "BuildDirectory.History"); packageFile.setLabelText(Tr::tr("Package file:"));
buildDirectory.setExpectedKind(PathChooser::Directory); packageFile.setExpectedKind(Utils::PathChooser::SaveFile);
buildDirectory.setLabelText(Tr::tr("Build directory:"));
packageFileName.setSettingsKey(SETTINGSPREFIX "FileName");
packageFileName.setHistoryCompleter(SETTINGSPREFIX "FileName.History");
packageFileName.setDisplayStyle(StringAspect::LineEditDisplay);
packageFileName.setLabelText(Tr::tr("Package file name:"));
const auto updateAspects = [this] { const auto updateAspects = [this] {
const auto targetInformation = TargetInformation(target()); const auto targetInformation = TargetInformation(target());
executable.setPlaceHolderPath(getToolFilePath(Constants::APPMAN_PACKAGER, target()->kit(), nullptr)); packager.setValue(FilePath::fromString(getToolFilePath(Constants::APPMAN_PACKAGER,
arguments.setPlaceHolderText(ArgumentsDefault); target()->kit(),
sourceDirectory.setPlaceHolderPath(targetInformation.packageSourcesDirectory.absolutePath()); targetInformation.device)));
buildDirectory.setPlaceHolderPath(targetInformation.buildDirectory.absolutePath()); packager.setDefaultValue(packager.value());
packageFileName.setPlaceHolderText(targetInformation.packageFile.fileName()); arguments.setArguments(ArgumentsDefault);
arguments.setResetter([] { return QLatin1String(ArgumentsDefault); });
setEnabled(!targetInformation.isBuiltin); packageFile.setValue(targetInformation.packageFile.absoluteFilePath());
packageFile.setDefaultValue(packageFile.value());
sourceDirectory.setValue(targetInformation.packageSourcesDirectory.absolutePath());
sourceDirectory.setDefaultValue(sourceDirectory.value());
}; };
connect(target(), &Target::activeRunConfigurationChanged, this, updateAspects); connect(target(), &Target::activeRunConfigurationChanged, this, updateAspects);
@@ -88,31 +80,31 @@ public:
if (!AbstractProcessStep::init()) if (!AbstractProcessStep::init())
return false; return false;
const auto targetInformation = TargetInformation(target()); const FilePath packagerPath = packager().isEmpty() ?
if (!targetInformation.isValid()) FilePath::fromString(packager.defaultValue()) :
return false; packager();
const QString packagerArguments = arguments();
const FilePath sourceDirectoryPath = sourceDirectory().isEmpty() ?
FilePath::fromString(sourceDirectory.defaultValue()) :
sourceDirectory();
const FilePath packageFilePath = packageFile().isEmpty() ?
FilePath::fromString(packageFile.defaultValue()) :
packageFile();
const FilePath packager = executable.valueOrDefault(getToolFilePath(Constants::APPMAN_PACKAGER, target()->kit(), nullptr));
const QString packagerArguments = arguments.valueOrDefault(ArgumentsDefault);
const FilePath packageSourcesDirectory = sourceDirectory.valueOrDefault(targetInformation.packageSourcesDirectory.absolutePath());
const FilePath packageDirectory = buildDirectory.valueOrDefault(targetInformation.buildDirectory.absolutePath());
const QString packageFile = packageFileName.valueOrDefault(targetInformation.packageFile.fileName());
CommandLine cmd(packager); CommandLine cmd(packagerPath);
cmd.addArgs(packagerArguments, CommandLine::Raw); cmd.addArgs(packagerArguments, CommandLine::Raw);
cmd.addArgs({packageFile, packageSourcesDirectory.path()}); cmd.addArgs({packageFilePath.nativePath(), sourceDirectoryPath.nativePath()});
processParameters()->setWorkingDirectory(packageDirectory);
processParameters()->setCommandLine(cmd); processParameters()->setCommandLine(cmd);
return true; return true;
} }
private: private:
AppManagerFilePathAspect executable{this}; AppManagerPackagerAspect packager{this};
AppManagerStringAspect arguments{this}; ProjectExplorer::ArgumentsAspect arguments{this};
AppManagerFilePathAspect sourceDirectory{this}; FilePathAspect sourceDirectory{this};
AppManagerFilePathAspect buildDirectory{this}; FilePathAspect packageFile{this};
AppManagerStringAspect packageFileName{this};
}; };
// Factory // Factory

View File

@@ -39,21 +39,19 @@ public:
setDisplayName(Tr::tr("Deploy Application Manager package")); setDisplayName(Tr::tr("Deploy Application Manager package"));
packageFilePath.setSettingsKey(SETTINGSPREFIX "FilePath"); packageFilePath.setSettingsKey(SETTINGSPREFIX "FilePath");
packageFilePath.setHistoryCompleter(SETTINGSPREFIX "FilePath.History"); packageFilePath.setLabelText(Tr::tr("Package file:"));
packageFilePath.setExpectedKind(PathChooser::File);
packageFilePath.setLabelText(Tr::tr("Package file path:"));
targetDirectory.setSettingsKey(SETTINGSPREFIX "TargetDirectory"); targetDirectory.setSettingsKey(SETTINGSPREFIX "TargetDirectory");
targetDirectory.setHistoryCompleter(SETTINGSPREFIX "TargetDirectory.History");
targetDirectory.setExpectedKind(PathChooser::Directory);
targetDirectory.setLabelText(Tr::tr("Target directory:")); targetDirectory.setLabelText(Tr::tr("Target directory:"));
targetDirectory.setButtonsVisible(false);
const auto updateAspects = [this] { const auto updateAspects = [this] {
const TargetInformation targetInformation(target()); const TargetInformation targetInformation(target());
packageFilePath.setPlaceHolderPath(targetInformation.packageFile.absoluteFilePath()); packageFilePath.setValue(targetInformation.packageFile.absoluteFilePath());
targetDirectory.setPlaceHolderPath(targetInformation.runDirectory.absolutePath()); packageFilePath.setDefaultValue(packageFilePath.value());
targetDirectory.setValue(targetInformation.runDirectory.absolutePath());
targetDirectory.setDefaultValue(targetDirectory.value());
setEnabled(!targetInformation.isBuiltin); setEnabled(!targetInformation.isBuiltin);
}; };
@@ -77,10 +75,12 @@ private:
{ {
const auto onSetup = [this](FileStreamer &streamer) { const auto onSetup = [this](FileStreamer &streamer) {
const TargetInformation targetInformation(target()); const TargetInformation targetInformation(target());
const FilePath source = packageFilePath.valueOrDefault( const FilePath source = packageFilePath().isEmpty() ?
targetInformation.packageFile.absoluteFilePath()); FilePath::fromString(packageFilePath.defaultValue()) :
const FilePath targetDir = targetDirectory.valueOrDefault( packageFilePath();
targetInformation.runDirectory.absolutePath()); const FilePath targetDir = targetDirectory().isEmpty() ?
FilePath::fromString(targetDirectory.defaultValue()) :
targetDirectory();
const FilePath target = targetInformation.device->filePath(targetDir.path()) const FilePath target = targetInformation.device->filePath(targetDir.path())
.pathAppended(source.fileName()); .pathAppended(source.fileName());
streamer.setSource(source); streamer.setSource(source);
@@ -96,8 +96,8 @@ private:
return FileStreamerTask(onSetup, onDone); return FileStreamerTask(onSetup, onDone);
} }
AppManagerFilePathAspect packageFilePath{this}; FilePathAspect packageFilePath{this};
AppManagerFilePathAspect targetDirectory{this}; FilePathAspect targetDirectory{this};
}; };
// Factory // Factory

View File

@@ -16,6 +16,7 @@
#include <projectexplorer/deployconfiguration.h> #include <projectexplorer/deployconfiguration.h>
#include <projectexplorer/processparameters.h> #include <projectexplorer/processparameters.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/runconfigurationaspects.h>
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
#include <projectexplorer/kitaspects.h> #include <projectexplorer/kitaspects.h>
@@ -30,8 +31,6 @@ const char ArgumentsDefault[] = "install-package -a";
class AppManagerInstallPackageStep final : public AbstractProcessStep class AppManagerInstallPackageStep final : public AbstractProcessStep
{ {
Q_DECLARE_TR_FUNCTIONS(AppManager::Internal::AppManagerInstallPackageStep)
public: public:
AppManagerInstallPackageStep(BuildStepList *bsl, Id id); AppManagerInstallPackageStep(BuildStepList *bsl, Id id);
@@ -39,10 +38,9 @@ protected:
bool init() final; bool init() final;
private: private:
AppManagerFilePathAspect executable{this}; AppManagerControllerAspect controller{this};
AppManagerStringAspect arguments{this}; ProjectExplorer::ArgumentsAspect arguments{this};
AppManagerStringAspect packageFileName{this}; FilePathAspect packageFile{this};
AppManagerFilePathAspect packageDirectory{this};
}; };
AppManagerInstallPackageStep::AppManagerInstallPackageStep(BuildStepList *bsl, Id id) AppManagerInstallPackageStep::AppManagerInstallPackageStep(BuildStepList *bsl, Id id)
@@ -50,39 +48,22 @@ AppManagerInstallPackageStep::AppManagerInstallPackageStep(BuildStepList *bsl, I
{ {
setDisplayName(Tr::tr("Install Application Manager package")); setDisplayName(Tr::tr("Install Application Manager package"));
executable.setSettingsKey(SETTINGSPREFIX "Executable");
executable.setHistoryCompleter(SETTINGSPREFIX "Executable.History");
executable.setLabelText(Tr::tr("Executable:"));
arguments.setSettingsKey(SETTINGSPREFIX "Arguments"); arguments.setSettingsKey(SETTINGSPREFIX "Arguments");
arguments.setHistoryCompleter(SETTINGSPREFIX "Arguments.History");
arguments.setDisplayStyle(StringAspect::LineEditDisplay);
arguments.setLabelText(Tr::tr("Arguments:"));
packageFileName.setSettingsKey(SETTINGSPREFIX "FileName"); packageFile.setSettingsKey(SETTINGSPREFIX "FileName");
packageFileName.setHistoryCompleter(SETTINGSPREFIX "FileName.History"); packageFile.setLabelText(Tr::tr("Package file:"));
packageFileName.setDisplayStyle(StringAspect::LineEditDisplay);
packageFileName.setLabelText(Tr::tr("File name:"));
packageDirectory.setSettingsKey(SETTINGSPREFIX "Directory");
packageDirectory.setHistoryCompleter(SETTINGSPREFIX "Directory.History");
packageDirectory.setExpectedKind(PathChooser::Directory);
packageDirectory.setLabelText(Tr::tr("Directory:"));
const auto updateAspects = [this] { const auto updateAspects = [this] {
const TargetInformation targetInformation(target()); const TargetInformation targetInformation(target());
executable.setPromptDialogFilter(getToolNameByDevice(Constants::APPMAN_CONTROLLER, targetInformation.device)); controller.setValue(FilePath::fromString(getToolFilePath(Constants::APPMAN_CONTROLLER,
executable.setButtonsVisible(!targetInformation.remote); target()->kit(),
executable.setExpectedKind(targetInformation.remote ? PathChooser::Command : PathChooser::ExistingCommand); targetInformation.device)));
executable.setPlaceHolderPath(getToolFilePath(Constants::APPMAN_CONTROLLER, target()->kit(), targetInformation.device)); controller.setDefaultValue(controller.value());
arguments.setPlaceHolderText(ArgumentsDefault); arguments.setArguments(ArgumentsDefault);
packageFileName.setPlaceHolderText(targetInformation.packageFile.fileName()); arguments.setResetter([] { return QLatin1String(ArgumentsDefault); });
auto device = DeviceKitAspect::device(target()->kit());
bool remote = device && device->type() != ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE; packageFile.setValue(targetInformation.packageFile.absoluteFilePath());
QDir packageDirectoryPath = remote ? QDir(Constants::REMOTE_DEFAULT_TMP_PATH) : targetInformation.packageFile.absolutePath();
packageDirectory.setPlaceHolderPath(packageDirectoryPath.absolutePath());
packageDirectory.setButtonsVisible(!targetInformation.remote);
setEnabled(!targetInformation.isBuiltin); setEnabled(!targetInformation.isBuiltin);
}; };
@@ -100,22 +81,17 @@ bool AppManagerInstallPackageStep::init()
if (!AbstractProcessStep::init()) if (!AbstractProcessStep::init())
return false; return false;
const TargetInformation targetInformation(target()); const FilePath controllerPath = controller().isEmpty() ?
if (!targetInformation.isValid()) FilePath::fromString(controller.defaultValue()) :
return false; controller();
const QString controllerArguments = arguments();
const FilePath packageFilePath = packageFile().isEmpty() ?
FilePath::fromString(packageFile.defaultValue()) :
packageFile();
const FilePath controller = executable.valueOrDefault(getToolFilePath(Constants::APPMAN_CONTROLLER, target()->kit(), targetInformation.device)); CommandLine cmd(controllerPath);
const QString controllerArguments = arguments.valueOrDefault(ArgumentsDefault);
const QString packageFile = packageFileName.valueOrDefault(targetInformation.packageFile.fileName());
auto device = DeviceKitAspect::device(target()->kit());
bool remote = device && device->type() != ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE;
QDir packageDirectoryPath = remote ? QDir(Constants::REMOTE_DEFAULT_TMP_PATH) : targetInformation.packageFile.absolutePath();
const FilePath packageDir = packageDirectory.valueOrDefault(packageDirectoryPath.absolutePath());
CommandLine cmd(targetInformation.device->filePath(controller.path()));
cmd.addArgs(controllerArguments, CommandLine::Raw); cmd.addArgs(controllerArguments, CommandLine::Raw);
cmd.addArg(packageFile); cmd.addArg(packageFilePath.nativePath());
processParameters()->setWorkingDirectory(packageDir);
processParameters()->setCommandLine(cmd); processParameters()->setCommandLine(cmd);
return true; return true;

View File

@@ -20,6 +20,7 @@
#include <projectexplorer/processparameters.h> #include <projectexplorer/processparameters.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
#include <projectexplorer/runconfigurationaspects.h>
#include <utils/process.h> #include <utils/process.h>
@@ -35,8 +36,6 @@ const char ArgumentsDefault[] = "install-package -a";
class AppManagerRemoteInstallPackageStep final : public RemoteLinux::AbstractRemoteLinuxDeployStep class AppManagerRemoteInstallPackageStep final : public RemoteLinux::AbstractRemoteLinuxDeployStep
{ {
Q_DECLARE_TR_FUNCTIONS(AppManager::Internal::AppManagerInstallPackageStep)
public: public:
AppManagerRemoteInstallPackageStep(BuildStepList *bsl, Id id); AppManagerRemoteInstallPackageStep(BuildStepList *bsl, Id id);
@@ -44,10 +43,9 @@ private:
GroupItem deployRecipe() final; GroupItem deployRecipe() final;
private: private:
AppManagerFilePathAspect executable{this}; AppManagerControllerAspect controller{this};
AppManagerStringAspect arguments{this}; ProjectExplorer::ArgumentsAspect arguments{this};
AppManagerStringAspect packageFileName{this}; FilePathAspect packageFile{this};
AppManagerFilePathAspect packageDirectory{this};
}; };
AppManagerRemoteInstallPackageStep::AppManagerRemoteInstallPackageStep(BuildStepList *bsl, Id id) AppManagerRemoteInstallPackageStep::AppManagerRemoteInstallPackageStep(BuildStepList *bsl, Id id)
@@ -55,41 +53,25 @@ AppManagerRemoteInstallPackageStep::AppManagerRemoteInstallPackageStep(BuildStep
{ {
setDisplayName(tr("Remote Install Application Manager package")); setDisplayName(tr("Remote Install Application Manager package"));
executable.setSettingsKey(SETTINGSPREFIX "Executable");
executable.setHistoryCompleter(SETTINGSPREFIX "Executable.History");
executable.setLabelText(tr("Executable:"));
arguments.setSettingsKey(SETTINGSPREFIX "Arguments"); arguments.setSettingsKey(SETTINGSPREFIX "Arguments");
arguments.setHistoryCompleter(SETTINGSPREFIX "Arguments.History");
arguments.setDisplayStyle(StringAspect::LineEditDisplay);
arguments.setLabelText(tr("Arguments:"));
packageFileName.setSettingsKey(SETTINGSPREFIX "FileName"); packageFile.setSettingsKey(SETTINGSPREFIX "FileName");
packageFileName.setHistoryCompleter(SETTINGSPREFIX "FileName.History"); packageFile.setLabelText(Tr::tr("Package file:"));
packageFileName.setDisplayStyle(StringAspect::LineEditDisplay);
packageFileName.setLabelText(tr("File name:"));
packageDirectory.setSettingsKey(SETTINGSPREFIX "Directory");
packageDirectory.setHistoryCompleter(SETTINGSPREFIX "Directory.History");
packageDirectory.setExpectedKind(PathChooser::Directory);
packageDirectory.setLabelText(tr("Directory:"));
setInternalInitializer([this] { return isDeploymentPossible(); }); setInternalInitializer([this] { return isDeploymentPossible(); });
const auto updateAspects = [this] { const auto updateAspects = [this] {
const TargetInformation targetInformation(target()); const TargetInformation targetInformation(target());
executable.setPromptDialogFilter(getToolNameByDevice(Constants::APPMAN_CONTROLLER, targetInformation.device)); controller.setValue(FilePath::fromString(getToolFilePath(Constants::APPMAN_CONTROLLER,
executable.setButtonsVisible(!targetInformation.remote); target()->kit(),
executable.setExpectedKind(targetInformation.remote ? PathChooser::Command : PathChooser::ExistingCommand); targetInformation.device)));
executable.setPlaceHolderPath(getToolFilePath(Constants::APPMAN_CONTROLLER, target()->kit(), targetInformation.device)); controller.setDefaultValue(controller.value());
arguments.setPlaceHolderText(ArgumentsDefault); arguments.setArguments(ArgumentsDefault);
packageFileName.setPlaceHolderText(targetInformation.packageFile.fileName()); arguments.setResetter([](){ return QLatin1String(ArgumentsDefault); });
auto device = DeviceKitAspect::device(target()->kit());
bool remote = device && device->type() != ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE; packageFile.setValue(targetInformation.packageFile.absoluteFilePath());
QDir packageDirectoryPath = remote ? QDir(Constants::REMOTE_DEFAULT_TMP_PATH) : targetInformation.packageFile.absolutePath(); packageFile.setDefaultValue(packageFile.value());
packageDirectory.setPlaceHolderPath(packageDirectoryPath.absolutePath());
packageDirectory.setButtonsVisible(!targetInformation.remote);
setEnabled(!targetInformation.isBuiltin); setEnabled(!targetInformation.isBuiltin);
}; };
@@ -106,18 +88,18 @@ GroupItem AppManagerRemoteInstallPackageStep::deployRecipe()
{ {
const TargetInformation targetInformation(target()); const TargetInformation targetInformation(target());
const FilePath controller = executable.valueOrDefault(getToolFilePath(Constants::APPMAN_CONTROLLER, target()->kit(), targetInformation.device)); const FilePath controllerPath = controller().isEmpty() ?
const QString controllerArguments = arguments.valueOrDefault(ArgumentsDefault); FilePath::fromString(controller.defaultValue()) :
const QString packageFile = packageFileName.valueOrDefault(targetInformation.packageFile.fileName()); controller();
auto device = DeviceKitAspect::device(target()->kit()); const QString controllerArguments = arguments();
bool remote = device && device->type() != ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE; const FilePath packageFilePath = packageFile().isEmpty() ?
QDir packageDirectoryPath = remote ? QDir(Constants::REMOTE_DEFAULT_TMP_PATH) : targetInformation.packageFile.absolutePath(); FilePath::fromString(packageFile.defaultValue()) :
const FilePath packageDir = packageDirectory.valueOrDefault(packageDirectoryPath.absolutePath()); packageFile();
const auto setupHandler = [=](Process &process) { const auto setupHandler = [=](Process &process) {
CommandLine remoteCmd(controller); CommandLine remoteCmd(controllerPath);
remoteCmd.addArgs(controllerArguments, CommandLine::Raw); remoteCmd.addArgs(controllerArguments, CommandLine::Raw);
remoteCmd.addArg(packageDir.toString() + '/' + packageFile); remoteCmd.addArg(packageFilePath.nativePath());
CommandLine cmd(deviceConfiguration()->filePath("/bin/sh")); CommandLine cmd(deviceConfiguration()->filePath("/bin/sh"));
cmd.addArg("-c"); cmd.addArg("-c");

View File

@@ -22,7 +22,7 @@ AppManagerIdAspect::AppManagerIdAspect(Utils::AspectContainer *container)
{ {
setSettingsKey("ApplicationManagerPlugin.ApplicationId"); setSettingsKey("ApplicationManagerPlugin.ApplicationId");
setDisplayStyle(StringAspect::LineEditDisplay); setDisplayStyle(StringAspect::LineEditDisplay);
setLabelText(Tr::tr("Application Id:")); setLabelText(Tr::tr("Application id:"));
// setReadOnly(true); // setReadOnly(true);
} }
@@ -31,7 +31,18 @@ AppManagerInstanceIdAspect::AppManagerInstanceIdAspect(Utils::AspectContainer *c
{ {
setSettingsKey("ApplicationManagerPlugin.InstanceId"); setSettingsKey("ApplicationManagerPlugin.InstanceId");
setDisplayStyle(StringAspect::LineEditDisplay); setDisplayStyle(StringAspect::LineEditDisplay);
setLabelText(Tr::tr("AppMan Instance Id:")); setLabelText(Tr::tr("AppMan instance id:"));
makeCheckable(Utils::CheckBoxPlacement::Right, Tr::tr("Default Instance"),
"ApplicationManagerPlugin.InstanceIdDefault");
setChecked(true);
addDataExtractor(this, &AppManagerInstanceIdAspect::operator(), &Data::value);
}
QString AppManagerInstanceIdAspect::operator()() const
{
return !isChecked() ? value() : QString();
} }
AppManagerDocumentUrlAspect::AppManagerDocumentUrlAspect(Utils::AspectContainer *container) AppManagerDocumentUrlAspect::AppManagerDocumentUrlAspect(Utils::AspectContainer *container)
@@ -39,130 +50,25 @@ AppManagerDocumentUrlAspect::AppManagerDocumentUrlAspect(Utils::AspectContainer
{ {
setSettingsKey("ApplicationManagerPlugin.DocumentUrl"); setSettingsKey("ApplicationManagerPlugin.DocumentUrl");
setDisplayStyle(StringAspect::LineEditDisplay); setDisplayStyle(StringAspect::LineEditDisplay);
setLabelText(Tr::tr("Document Url:")); setLabelText(Tr::tr("Document url:"));
} }
AppManagerControllerAspect::AppManagerControllerAspect(Utils::AspectContainer *container) AppManagerControllerAspect::AppManagerControllerAspect(Utils::AspectContainer *container)
: FilePathAspect(container) : FilePathAspect(container)
{ {
setSettingsKey("ApplicationManagerPlugin.AppControllerPath"); setSettingsKey("ApplicationManagerPlugin.AppControllerPath");
setExpectedKind(Utils::PathChooser::ExistingCommand);
setLabelText(Tr::tr("Controller:")); setLabelText(Tr::tr("Controller:"));
setPlaceHolderText(Tr::tr("-"));
} }
AppManagerStringAspect::AppManagerStringAspect(AspectContainer *container) AppManagerPackagerAspect::AppManagerPackagerAspect(Utils::AspectContainer *container)
: StringAspect(container)
{
}
QString AppManagerStringAspect::valueOrDefault(const QString &defaultValue) const
{
return value().isEmpty() ? defaultValue : value();
}
// FilePath
AppManagerFilePathAspect::AppManagerFilePathAspect(AspectContainer *container)
: FilePathAspect(container) : FilePathAspect(container)
{ {
setSettingsKey("ApplicationManagerPlugin.AppPackagerPath");
setExpectedKind(Utils::PathChooser::ExistingCommand);
setLabelText(Tr::tr("Packager:"));
} }
void AppManagerFilePathAspect::setButtonsVisible(bool visible)
{
if (m_buttonsVisibile != visible) {
m_buttonsVisibile = visible;
updateWidgets();
}
}
void AppManagerFilePathAspect::setPlaceHolderPath(const QString &value)
{
if (m_placeHolderPath != value) {
m_placeHolderPath = value;
updateWidgets();
}
}
void AppManagerFilePathAspect::setPromptDialogFilter(const QString &value)
{
if (m_promptDialogFilter != value) {
m_promptDialogFilter = value;
updateWidgets();
}
}
void AppManagerFilePathAspect::addToLayout(Layouting::LayoutItem &parent)
{
FilePathAspect::addToLayout(parent);
updateWidgets();
}
FilePath AppManagerFilePathAspect::valueOrDefault(const FilePath &defaultValue) const
{
return operator()().isEmpty() ? defaultValue : operator()();
}
FilePath AppManagerFilePathAspect::valueOrDefault(const QString &defaultValue) const
{
return operator()().isEmpty() ? FilePath::fromUserInput(defaultValue) : operator()();
}
static bool callValidationFunction(const FancyLineEdit::ValidationFunction &f, FancyLineEdit *lineEdit, QString *errorMessage)
{
if (f.index() == 0) {
QString oldText = lineEdit->text();
auto future = std::get<0>(f)(oldText);
future.waitForFinished();
auto res = future.result();
if (res) {
if (oldText != *res && lineEdit->text() == *res)
lineEdit->setText(*res);
return true;
}
if (errorMessage)
*errorMessage = res.error();
return false;
}
return std::get<1>(f)(lineEdit, errorMessage);
}
bool AppManagerFilePathAspect::validatePathWithPlaceHolder(FancyLineEdit *lineEdit, QString *errorMessage) const
{
if (!lineEdit)
return false;
if (auto pathChooser = qobject_cast<PathChooser*>(lineEdit->parent())) {
if (lineEdit->text().isEmpty() && !lineEdit->placeholderText().isEmpty()) {
FancyLineEdit temporaryLineEdit;
temporaryLineEdit.setText(lineEdit->placeholderText());
PathChooser temporaryPathChooser;
temporaryPathChooser.setExpectedKind(pathChooser->expectedKind());
return callValidationFunction(temporaryPathChooser.defaultValidationFunction(), &temporaryLineEdit, errorMessage);
}
return callValidationFunction(pathChooser->defaultValidationFunction(), lineEdit, errorMessage);
}
return callValidationFunction(lineEdit->defaultValidationFunction(), lineEdit, errorMessage);
}
void AppManagerFilePathAspect::updateWidgets()
{
const auto pathChooser = this->pathChooser();
if (!pathChooser)
return;
for (auto button : pathChooser->findChildren<QPushButton*>())
button->setVisible(m_buttonsVisibile);
for (auto fancyLineEdit : pathChooser->findChildren<FancyLineEdit*>())
fancyLineEdit->setPlaceholderText(m_placeHolderPath);
QFileInfo initialBrowsePath(m_placeHolderPath);
while (!initialBrowsePath.path().isEmpty() && !initialBrowsePath.isDir())
initialBrowsePath.setFile(initialBrowsePath.path());
if (initialBrowsePath.isDir())
pathChooser->setInitialBrowsePathBackup(FilePath::fromString(initialBrowsePath.absoluteFilePath()));
pathChooser->setPromptDialogFilter(m_promptDialogFilter);
pathChooser->setValidationFunction(
[&](FancyLineEdit *edit, QString *error) { return validatePathWithPlaceHolder(edit, error); });
}
} // namespace Internal } // namespace Internal
} // namespace AppManager } // namespace AppManager

View File

@@ -28,7 +28,11 @@ class AppManagerInstanceIdAspect final : public Utils::StringAspect
public: public:
AppManagerInstanceIdAspect(Utils::AspectContainer *container = nullptr); AppManagerInstanceIdAspect(Utils::AspectContainer *container = nullptr);
~AppManagerInstanceIdAspect() final = default; QString operator()() const;
struct Data : StringAspect::Data { QString value; };
~AppManagerInstanceIdAspect() override = default;
}; };
class AppManagerDocumentUrlAspect final : public Utils::StringAspect class AppManagerDocumentUrlAspect final : public Utils::StringAspect
@@ -51,35 +55,14 @@ public:
~AppManagerControllerAspect() final = default; ~AppManagerControllerAspect() final = default;
}; };
class AppManagerStringAspect : public Utils::StringAspect class AppManagerPackagerAspect final : public Utils::FilePathAspect
{ {
Q_OBJECT
public: public:
AppManagerStringAspect(Utils::AspectContainer *container); AppManagerPackagerAspect(Utils::AspectContainer *container = nullptr);
QString valueOrDefault(const QString &defaultValue) const; ~AppManagerPackagerAspect() final = default;
};
class AppManagerFilePathAspect : public Utils::FilePathAspect
{
public:
AppManagerFilePathAspect(Utils::AspectContainer *container);
void setButtonsVisible(bool visible);
void setPlaceHolderPath(const QString &value);
void setPromptDialogFilter(const QString &value);
void addToLayout(Layouting::LayoutItem &parent) override;
Utils::FilePath valueOrDefault(const Utils::FilePath &defaultValue) const;
Utils::FilePath valueOrDefault(const QString &defaultValue) const;
private:
bool validatePathWithPlaceHolder(Utils::FancyLineEdit *lineEdit, QString *errorMessage) const;
void updateWidgets();
QString m_placeHolderPath;
QString m_promptDialogFilter;
bool m_buttonsVisibile = true;
}; };
} // AppManager::Internal } // AppManager::Internal