From ead7afde3dcf8c1ca6d76adbebbd6dfb59a5d2ca Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 24 Jan 2024 12:31:10 +0100 Subject: [PATCH] Utils: Introduce FilePathAspect::setDefaultPathValue(FilePath) ... as a convenience function for .setDefaultValue(filePath.toUserOutput()); The case that someone already has FilePaths should not look (much) uglier on the user side than the QString "raw" case. Direct overloading setDefaultValue(FilePath) causes resolution conflicts, which are solvable, but I'd rather keep it explicit now. Change-Id: I03d71e4f99005a1d1f76ebf23080bebe46a9351d Reviewed-by: Marcus Tillmanns --- src/libs/utils/aspects.cpp | 5 +++++ src/libs/utils/aspects.h | 1 + src/plugins/copilot/copilotsettings.cpp | 4 ++-- src/plugins/screenrecorder/screenrecordersettings.cpp | 4 ++-- src/plugins/vcpkg/vcpkgsettings.cpp | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/libs/utils/aspects.cpp b/src/libs/utils/aspects.cpp index 9fde2da787b..ba09fe46653 100644 --- a/src/libs/utils/aspects.cpp +++ b/src/libs/utils/aspects.cpp @@ -1442,6 +1442,11 @@ void FilePathAspect::setDefaultValue(const QString &filePath) TypedAspect::setDefaultValue(filePath); } +void FilePathAspect::setDefaultPathValue(const FilePath &filePath) +{ + TypedAspect::setDefaultValue(filePath.toUserOutput()); +} + /*! Adds a check box with a \a checkerLabel according to \a checkBoxPlacement to the line edit. diff --git a/src/libs/utils/aspects.h b/src/libs/utils/aspects.h index 727861d2bc7..fc787ef4ecf 100644 --- a/src/libs/utils/aspects.h +++ b/src/libs/utils/aspects.h @@ -666,6 +666,7 @@ public: void setValue(const FilePath &filePath, Announcement howToAnnounce = DoEmit); void setValue(const QString &filePath, Announcement howToAnnounce = DoEmit); void setDefaultValue(const QString &filePath); + void setDefaultPathValue(const FilePath &filePath); void setPromptDialogFilter(const QString &filter); void setPromptDialogTitle(const QString &title); diff --git a/src/plugins/copilot/copilotsettings.cpp b/src/plugins/copilot/copilotsettings.cpp index c75f7124235..9ddfa4edfbb 100644 --- a/src/plugins/copilot/copilotsettings.cpp +++ b/src/plugins/copilot/copilotsettings.cpp @@ -68,7 +68,7 @@ CopilotSettings::CopilotSettings() const FilePath distFromVim = findOrDefault(searchDirs, &FilePath::exists); nodeJsPath.setExpectedKind(PathChooser::ExistingCommand); - nodeJsPath.setDefaultValue(nodeFromPath.toUserOutput()); + nodeJsPath.setDefaultPathValue(nodeFromPath); nodeJsPath.setSettingsKey("Copilot.NodeJsPath"); nodeJsPath.setLabelText(Tr::tr("Node.js path:")); nodeJsPath.setHistoryCompleter("Copilot.NodePath.History"); @@ -79,7 +79,7 @@ CopilotSettings::CopilotSettings() .arg("https://nodejs.org/en/download/")); distPath.setExpectedKind(PathChooser::File); - distPath.setDefaultValue(distFromVim.toUserOutput()); + distPath.setDefaultPathValue(distFromVim); distPath.setSettingsKey("Copilot.DistPath"); distPath.setLabelText(Tr::tr("Path to agent.js:")); distPath.setHistoryCompleter("Copilot.DistPath.History"); diff --git a/src/plugins/screenrecorder/screenrecordersettings.cpp b/src/plugins/screenrecorder/screenrecordersettings.cpp index 4647d9fb9e5..35ba138faad 100644 --- a/src/plugins/screenrecorder/screenrecordersettings.cpp +++ b/src/plugins/screenrecorder/screenrecordersettings.cpp @@ -57,7 +57,7 @@ ScreenRecorderSettings::ScreenRecorderSettings() const FilePath ffmpegDefault = Environment::systemEnvironment().searchInPath(Constants::FFMPEG_COMMAND, FileUtils::usefulExtraSearchPaths()); - ffmpegTool.setDefaultValue(ffmpegDefault.toUserOutput()); + ffmpegTool.setDefaultPathValue(ffmpegDefault); ffmpegTool.setLabelText(Tr::tr("ffmpeg tool:")); ffprobeTool.setSettingsKey("FFprobeTool"); @@ -66,7 +66,7 @@ ScreenRecorderSettings::ScreenRecorderSettings() const FilePath ffprobeDefault = Environment::systemEnvironment().searchInPath(Constants::FFPROBE_COMMAND, FileUtils::usefulExtraSearchPaths()); - ffprobeTool.setDefaultValue(ffprobeDefault.toUserOutput()); + ffprobeTool.setDefaultPathValue(ffprobeDefault); ffprobeTool.setLabelText(Tr::tr("ffprobe tool:")); captureCursor.setSettingsKey("CaptureCursor"); diff --git a/src/plugins/vcpkg/vcpkgsettings.cpp b/src/plugins/vcpkg/vcpkgsettings.cpp index 4ea4496519d..160f57ef6ed 100644 --- a/src/plugins/vcpkg/vcpkgsettings.cpp +++ b/src/plugins/vcpkg/vcpkgsettings.cpp @@ -40,7 +40,7 @@ VcpkgSettings::VcpkgSettings() if (!defaultPath.isDir()) defaultPath = FilePath::fromUserInput(qtcEnvironmentVariable(Constants::ENVVAR_VCPKG_ROOT)); if (defaultPath.isDir()) - vcpkgRoot.setDefaultValue(defaultPath.toUserOutput()); + vcpkgRoot.setDefaultPathValue(defaultPath); connect(this, &AspectContainer::applied, this, &VcpkgSettings::setVcpkgRootEnvironmentVariable);