Use more FilePathAspect

Change-Id: Ib348df1460f8610607251498b07010df58d51ddf
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
hjk
2023-05-17 17:18:11 +02:00
parent 2274847bfe
commit 6f31d87444
26 changed files with 53 additions and 66 deletions

View File

@@ -22,8 +22,6 @@ GeneralSettings::GeneralSettings()
setDisplayCategory(Tr::tr("Beautifier"));
setCategoryIconPath(":/beautifier/images/settingscategory_beautifier.png");
setSettingsGroups("Beautifier", "General");
setSettings(this);
setAutoApply(false);
registerAspect(&autoFormatOnSave);
autoFormatOnSave.setSettingsKey(Utils::Constants::BEAUTIFIER_AUTO_FORMAT_ON_SAVE);
@@ -47,9 +45,9 @@ GeneralSettings::GeneralSettings()
autoFormatMime.setLabelText(Tr::tr("Restrict to MIME types:"));
autoFormatMime.setDisplayStyle(StringAspect::LineEditDisplay);
setLayouter([this](QWidget *widget) {
setLayouter([this] {
using namespace Layouting;
Column {
return Column {
Group {
title(Tr::tr("Automatic Formatting on File Save")),
autoFormatOnSave.groupChecker(),
@@ -60,7 +58,7 @@ GeneralSettings::GeneralSettings()
}
},
st
}.attachTo(widget);
};
});
}

View File

@@ -2079,8 +2079,8 @@ void CMakeBuildConfiguration::addToEnvironment(Utils::Environment &env) const
return;
auto settings = CMakeSpecificSettings::instance();
if (!settings->ninjaPath.filePath().isEmpty()) {
const Utils::FilePath ninja = settings->ninjaPath.filePath();
if (!settings->ninjaPath().isEmpty()) {
const Utils::FilePath ninja = settings->ninjaPath();
env.appendOrSetPath(ninja.isFile() ? ninja.parentDir() : ninja);
}
}

View File

@@ -52,7 +52,6 @@ public:
registerAspect(&command);
command.setSettingsKey("autoFormatCommand");
command.setDisplayStyle(StringAspect::PathChooserDisplay);
command.setDefaultValue("cmake-format");
command.setExpectedKind(PathChooser::ExistingCommand);
@@ -121,14 +120,14 @@ public:
TextEditor::Command formatCommand() const
{
TextEditor::Command cmd;
cmd.setExecutable(command.filePath());
cmd.setExecutable(command());
cmd.setProcessing(TextEditor::Command::FileProcessing);
cmd.addOption("--in-place");
cmd.addOption("%file");
return cmd;
}
StringAspect command;
FilePathAspect command;
BoolAspect autoFormatOnSave;
BoolAspect autoFormatOnlyCurrentProject;
StringAspect autoFormatMime;

View File

@@ -678,7 +678,7 @@ QVariant CMakeGeneratorKitAspect::defaultValue(const Kit *k) const
if (it != known.constEnd()) {
const bool hasNinja = [k, tool] {
auto settings = Internal::CMakeSpecificSettings::instance();
if (settings->ninjaPath.filePath().isEmpty()) {
if (settings->ninjaPath().isEmpty()) {
auto findNinja = [](const Environment &env) -> bool {
return !env.searchInPath("ninja").isEmpty();
};

View File

@@ -32,9 +32,9 @@ CMakeSpecificSettings::CMakeSpecificSettings()
setCategory(Constants::Settings::CATEGORY);
setCategoryIconPath(Constants::Icons::SETTINGS_CATEGORY);
setLayouter([this](QWidget *widget) {
setLayouter([this] {
using namespace Layouting;
Column {
return Column {
autorunCMake,
packageManagerAutoSetup,
askBeforeReConfigureInitialParams,
@@ -42,7 +42,7 @@ CMakeSpecificSettings::CMakeSpecificSettings()
showSourceSubFolders,
showAdvancedOptionsByDefault,
st
}.attachTo(widget);
};
});
// TODO: fixup of QTCREATORBUG-26289 , remove in Qt Creator 7 or so

View File

@@ -15,7 +15,7 @@ public:
static CMakeSpecificSettings *instance();
Utils::BoolAspect autorunCMake;
Utils::StringAspect ninjaPath;
Utils::FilePathAspect ninjaPath;
Utils::BoolAspect packageManagerAutoSetup;
Utils::BoolAspect askBeforeReConfigureInitialParams;
Utils::BoolAspect askBeforePresetsReload;

View File

@@ -36,7 +36,6 @@ CppcheckOptions::CppcheckOptions()
registerAspect(&binary);
binary.setSettingsKey("binary");
binary.setDisplayStyle(StringAspect::PathChooserDisplay);
binary.setExpectedKind(PathChooser::ExistingCommand);
binary.setCommandVersionArguments({"--version"});
binary.setLabelText(Tr::tr("Binary:"));

View File

@@ -17,7 +17,7 @@ public:
std::function<void(QWidget *widget)> layouter();
Utils::StringAspect binary;
Utils::FilePathAspect binary;
Utils::BoolAspect warning;
Utils::BoolAspect style;
Utils::BoolAspect performance;

View File

@@ -100,7 +100,7 @@ void CppcheckTool::updateArguments()
arguments.push_back("--template=\"{file},{line},{severity},{id},{message}\"");
m_runner->reconfigure(m_options.binary.filePath(), arguments.join(' '));
m_runner->reconfigure(m_options.binary(), arguments.join(' '));
}
QStringList CppcheckTool::additionalArguments(const CppEditor::ProjectPart &part) const

View File

@@ -103,7 +103,7 @@ std::optional<bool> DockerApi::isDockerDaemonAvailable(bool async)
FilePath DockerApi::dockerClient()
{
return FilePath::fromString(m_settings->dockerBinaryPath.value());
return m_settings->dockerBinaryPath();
}
} // Docker::Internal

View File

@@ -99,7 +99,7 @@ public:
private:
void setupShellProcess(Process *shellProcess) final
{
shellProcess->setCommand({m_settings->dockerBinaryPath.filePath(),
shellProcess->setCommand({m_settings->dockerBinaryPath(),
{"container", "start", "-i", "-a", m_containerId}});
}
@@ -498,7 +498,7 @@ CommandLine DockerDevicePrivate::withDockerExecCmd(const CommandLine &cmd,
if (!updateContainerAccess())
return {};
CommandLine dockerCmd{m_settings->dockerBinaryPath.filePath(), {"exec"}};
CommandLine dockerCmd{m_settings->dockerBinaryPath(), {"exec"}};
if (interactive)
dockerCmd.addArg("-i");
@@ -555,7 +555,7 @@ void DockerDevicePrivate::stopCurrentContainer()
}
Process proc;
proc.setCommand({m_settings->dockerBinaryPath.filePath(), {"container", "stop", m_container}});
proc.setCommand({m_settings->dockerBinaryPath(), {"container", "stop", m_container}});
m_container.clear();
@@ -660,7 +660,7 @@ bool DockerDevicePrivate::isImageAvailable() const
{
Process proc;
proc.setCommand(
{m_settings->dockerBinaryPath.filePath(),
{m_settings->dockerBinaryPath(),
{"image", "list", m_data.repoAndTag(), "--format", "{{.Repository}}:{{.Tag}}"}});
proc.runBlocking();
if (proc.result() != ProcessResult::FinishedWithSuccess)
@@ -682,7 +682,7 @@ bool DockerDevicePrivate::createContainer()
const QString display = HostOsInfo::isLinuxHost() ? QString(":0")
: QString("host.docker.internal:0");
CommandLine dockerCreate{m_settings->dockerBinaryPath.filePath(),
CommandLine dockerCreate{m_settings->dockerBinaryPath(),
{"create",
"-i",
"--rm",
@@ -1053,7 +1053,7 @@ public:
connect(m_buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
m_buttons->button(QDialogButtonBox::Ok)->setEnabled(false);
CommandLine cmd{m_settings->dockerBinaryPath.filePath(),
CommandLine cmd{m_settings->dockerBinaryPath(),
{"images", "--format", "{{.ID}}\\t{{.Repository}}\\t{{.Tag}}\\t{{.Size}}"}};
m_log->append(Tr::tr("Running \"%1\"\n").arg(cmd.toUserOutput()));

View File

@@ -8,7 +8,6 @@
#include <projectexplorer/projectexplorerconstants.h>
#include <utils/filepath.h>
#include <utils/hostosinfo.h>
#include <utils/layoutbuilder.h>
@@ -23,17 +22,16 @@ DockerSettings::DockerSettings()
setDisplayName(Tr::tr("Docker"));
setCategory(ProjectExplorer::Constants::DEVICE_SETTINGS_CATEGORY);
setLayouter([this](QWidget *widget) {
setLayouter([this] {
using namespace Layouting;
// clang-format off
Column {
return Column {
Group {
title(Tr::tr("Configuration")),
Row { dockerBinaryPath }
},
st
}.attachTo(widget);
};
// clang-format on
});
@@ -44,7 +42,6 @@ DockerSettings::DockerSettings()
additionalPaths.append("/usr/local/bin");
registerAspect(&dockerBinaryPath);
dockerBinaryPath.setDisplayStyle(StringAspect::PathChooserDisplay);
dockerBinaryPath.setExpectedKind(PathChooser::ExistingCommand);
dockerBinaryPath.setDefaultFilePath(
FilePath::fromString("docker").searchInPath(additionalPaths));

View File

@@ -12,7 +12,7 @@ class DockerSettings final : public Core::PagedSettings
public:
DockerSettings();
Utils::StringAspect dockerBinaryPath;
Utils::FilePathAspect dockerBinaryPath;
};
} // Docker::Internal

View File

@@ -232,7 +232,7 @@ FossilClient::FossilClient()
unsigned int FossilClient::synchronousBinaryVersion() const
{
if (settings().binaryPath.value().isEmpty())
if (settings().binaryPath().isEmpty())
return 0;
const CommandResult result = vcsSynchronousExec({}, QStringList{"version"});

View File

@@ -2422,7 +2422,7 @@ void GitClient::launchGitK(const FilePath &workingDirectory, const QString &file
void GitClient::launchRepositoryBrowser(const FilePath &workingDirectory) const
{
const FilePath repBrowserBinary = settings().repositoryBrowserCmd.filePath();
const FilePath repBrowserBinary = settings().repositoryBrowserCmd();
if (!repBrowserBinary.isEmpty())
Process::startDetached({repBrowserBinary, {workingDirectory.toString()}}, workingDirectory);
}

View File

@@ -2001,7 +2001,7 @@ QObject *GitPlugin::remoteCommand(const QStringList &options, const QString &wor
void GitPluginPrivate::updateRepositoryBrowserAction()
{
const bool repositoryEnabled = currentState().hasTopLevel();
const bool hasRepositoryBrowserCmd = !settings().repositoryBrowserCmd.value().isEmpty();
const bool hasRepositoryBrowserCmd = !settings().repositoryBrowserCmd().isEmpty();
m_repositoryBrowserAction->setEnabled(repositoryEnabled && hasRepositoryBrowserCmd);
}

View File

@@ -94,7 +94,6 @@ GitSettings::GitSettings()
logDiff.setToolTip(Tr::tr("Note that huge amount of commits might take some time."));
registerAspect(&repositoryBrowserCmd);
repositoryBrowserCmd.setDisplayStyle(StringAspect::PathChooserDisplay);
repositoryBrowserCmd.setSettingsKey("RepositoryBrowserCmd");
repositoryBrowserCmd.setExpectedKind(PathChooser::ExistingCommand);
repositoryBrowserCmd.setHistoryCompleter("Git.RepoCommand.History");
@@ -130,10 +129,9 @@ GitSettings::GitSettings()
timeout.setDefaultValue(Utils::HostOsInfo::isWindowsHost() ? 60 : 30);
setLayouter([this](QWidget *widget) {
setLayouter([this] {
using namespace Layouting;
Column {
return Column {
Group {
title(Tr::tr("Configuration")),
Column {
@@ -166,7 +164,7 @@ GitSettings::GitSettings()
},
st
}.attachTo(widget);
};
});
connect(&binaryPath, &StringAspect::valueChanged, this, [this] { tryResolve = true; });
connect(&path, &StringAspect::valueChanged, this, [this] { tryResolve = true; });
@@ -181,7 +179,7 @@ FilePath GitSettings::gitExecutable(bool *ok, QString *errorMessage) const
errorMessage->clear();
if (tryResolve) {
resolvedBinPath = binaryPath.filePath();
resolvedBinPath = binaryPath();
if (!resolvedBinPath.isAbsolutePath())
resolvedBinPath = resolvedBinPath.searchInPath({path.filePath()}, FilePath::PrependToPath);
tryResolve = false;

View File

@@ -30,7 +30,7 @@ public:
Utils::BoolAspect winSetHomeEnvironment;
Utils::StringAspect gitkOptions;
Utils::BoolAspect logDiff;
Utils::StringAspect repositoryBrowserCmd;
Utils::FilePathAspect repositoryBrowserCmd;
Utils::BoolAspect graphLog;
Utils::BoolAspect colorLog;
Utils::BoolAspect firstParent;

View File

@@ -148,7 +148,7 @@ private:
QPushButton *m_remove = nullptr;
QPushButton *m_add = nullptr;
QComboBox *m_defaultGitLabServer = nullptr;
Utils::StringAspect m_curl;
FilePathAspect m_curl;
};
GitLabOptionsWidget::GitLabOptionsWidget(GitLabParameters *params)
@@ -156,9 +156,8 @@ GitLabOptionsWidget::GitLabOptionsWidget(GitLabParameters *params)
{
auto defaultLabel = new QLabel(Tr::tr("Default:"), this);
m_defaultGitLabServer = new QComboBox(this);
m_curl.setDisplayStyle(Utils::StringAspect::DisplayStyle::PathChooserDisplay);
m_curl.setLabelText(Tr::tr("curl:"));
m_curl.setExpectedKind(Utils::PathChooser::ExistingCommand);
m_curl.setExpectedKind(PathChooser::ExistingCommand);
m_gitLabServerWidget = new GitLabServerWidget(GitLabServerWidget::Display, this);
@@ -208,7 +207,7 @@ GitLabOptionsWidget::GitLabOptionsWidget(GitLabParameters *params)
result.gitLabServers.append(m_defaultGitLabServer->itemData(i).value<GitLabServer>());
if (m_defaultGitLabServer->count())
result.defaultGitLabServer = m_defaultGitLabServer->currentData().value<GitLabServer>().id;
result.curl = m_curl.filePath();
result.curl = m_curl();
if (result != *m_parameters) {
m_parameters->assign(result);

View File

@@ -46,7 +46,7 @@ void HaskellManager::openGhci(const FilePath &haskellFile)
+ (isHaskell ? QStringList{haskellFile.fileName()} : QStringList());
Process p;
p.setTerminalMode(TerminalMode::Detached);
p.setCommand({settings().stackPath.filePath(), args});
p.setCommand({settings().stackPath(), args});
p.setWorkingDirectory(haskellFile.absolutePath());
p.start();
}

View File

@@ -68,7 +68,7 @@ Runnable HaskellRunConfiguration::runnable() const
r.workingDirectory = projectDirectory;
r.environment = aspect<LocalEnvironmentAspect>()->environment();
r.command = {r.environment.searchInPath(settings().stackPath()), args};
r.command = {r.environment.searchInPath(settings().stackPath().path()), args};
return r;
}

View File

@@ -6,10 +6,7 @@
#include "haskellconstants.h"
#include "haskelltr.h"
#include <coreplugin/icore.h>
#include <utils/hostosinfo.h>
#include <utils/pathchooser.h>
#include <utils/layoutbuilder.h>
using namespace Utils;
@@ -46,18 +43,18 @@ HaskellSettings::HaskellSettings()
? FilePath::fromString("/usr/local/bin/stack")
: FilePath::fromString("stack"));
setLayouter([this](QWidget *widget) {
setLayouter([this] {
using namespace Layouting;
Column {
return Column {
Group {
title(Tr::tr("General")),
Row { Tr::tr("Stack executable:"), stackPath }
},
st,
}.attachTo(widget);
};
});
readSettings(Core::ICore::settings());
readSettings();
}
} // Haskell::Internal

View File

@@ -12,7 +12,7 @@ class HaskellSettings : public Core::PagedSettings
public:
HaskellSettings();
Utils::StringAspect stackPath;
Utils::FilePathAspect stackPath;
};
HaskellSettings &settings();

View File

@@ -38,7 +38,7 @@ bool StackBuildStep::init()
if (AbstractProcessStep::init()) {
const auto projectDir = QDir(project()->projectDirectory().toString());
processParameters()->setCommandLine(
{settings().stackPath.filePath(),
{settings().stackPath(),
{"build", "--work-dir", projectDir.relativeFilePath(buildDirectory().toString())}});
processParameters()->setEnvironment(buildEnvironment());
}

View File

@@ -783,7 +783,7 @@ VcsCommand *MercurialPluginPrivate::createInitialCheckoutCommand(const QString &
QStringList args;
args << QLatin1String("clone") << extraArgs << url << localName;
auto command = VcsBaseClient::createVcsCommand(baseDirectory, m_client.processEnvironment());
command->addJob({settings().binaryPath.filePath(), args}, -1);
command->addJob({settings().binaryPath(), args}, -1);
return command;
}

View File

@@ -863,7 +863,7 @@ void SubversionPluginPrivate::vcsAnnotateHelper(const FilePath &workingDir, cons
const FilePath source = VcsBaseEditor::getSource(workingDir, file);
QTextCodec *codec = VcsBaseEditor::getCodec(source);
CommandLine args{settings().binaryPath.filePath(), {"annotate"}};
CommandLine args{settings().binaryPath(), {"annotate"}};
args << SubversionClient::AddAuthOptions();
if (settings().spaceIgnorantAnnotation.value())
args << "-x" << "-uw";
@@ -1006,7 +1006,7 @@ QString SubversionPluginPrivate::synchronousTopic(const FilePath &repository) co
bool SubversionPluginPrivate::vcsAdd(const FilePath &workingDir, const QString &rawFileName)
{
const QString file = QDir::toNativeSeparators(SubversionClient::escapeFile(rawFileName));
CommandLine args{settings().binaryPath.filePath()};
CommandLine args{settings().binaryPath()};
args << "add" << SubversionClient::AddAuthOptions() << "--parents" << file;
return runSvn(workingDir, args, RunFlags::ShowStdOut).result()
== ProcessResult::FinishedWithSuccess;
@@ -1016,7 +1016,7 @@ bool SubversionPluginPrivate::vcsDelete(const FilePath &workingDir, const QStrin
{
const QString file = QDir::toNativeSeparators(SubversionClient::escapeFile(rawFileName));
CommandLine args{settings().binaryPath.filePath()};
CommandLine args{settings().binaryPath()};
args << "delete" << SubversionClient::AddAuthOptions() << "--force" << file;
return runSvn(workingDir, args, RunFlags::ShowStdOut).result()
@@ -1025,7 +1025,7 @@ bool SubversionPluginPrivate::vcsDelete(const FilePath &workingDir, const QStrin
bool SubversionPluginPrivate::vcsMove(const FilePath &workingDir, const QString &from, const QString &to)
{
CommandLine args{settings().binaryPath.filePath(), {"move"}};
CommandLine args{settings().binaryPath(), {"move"}};
args << SubversionClient::AddAuthOptions()
<< QDir::toNativeSeparators(SubversionClient::escapeFile(from))
<< QDir::toNativeSeparators(SubversionClient::escapeFile(to));
@@ -1038,7 +1038,7 @@ bool SubversionPluginPrivate::vcsCheckout(const FilePath &directory, const QByte
QUrl tempUrl = QUrl::fromEncoded(url);
const QString username = tempUrl.userName();
const QString password = tempUrl.password();
CommandLine args{settings().binaryPath.filePath(), {"checkout"}};
CommandLine args{settings().binaryPath(), {"checkout"}};
args << Constants::NON_INTERACTIVE_OPTION;
if (!username.isEmpty()) {
@@ -1085,7 +1085,7 @@ bool SubversionPluginPrivate::managesDirectory(const FilePath &directory, FilePa
bool SubversionPluginPrivate::managesFile(const FilePath &workingDirectory, const QString &fileName) const
{
CommandLine args{settings().binaryPath.filePath()};
CommandLine args{settings().binaryPath()};
args << "status" << SubversionClient::AddAuthOptions()
<< QDir::toNativeSeparators(SubversionClient::escapeFile(fileName));
const QString output = runSvn(workingDirectory, args).cleanedStdOut();
@@ -1124,7 +1124,7 @@ bool SubversionPluginPrivate::isVcsFileOrDirectory(const FilePath &filePath) con
bool SubversionPluginPrivate::isConfigured() const
{
const FilePath binary = settings().binaryPath.filePath();
const FilePath binary = settings().binaryPath();
if (binary.isEmpty())
return false;
QFileInfo fi = binary.toFileInfo();
@@ -1187,7 +1187,7 @@ VcsCommand *SubversionPluginPrivate::createInitialCheckoutCommand(const QString
const QString &localName,
const QStringList &extraArgs)
{
CommandLine args{settings().binaryPath.filePath()};
CommandLine args{settings().binaryPath()};
args << "checkout";
args << SubversionClient::AddAuthOptions();
args << Subversion::Constants::NON_INTERACTIVE_OPTION << extraArgs << url << localName;