aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2023-07-28 17:02:51 +0200
committerhjk <hjk@qt.io>2023-08-16 08:57:09 +0000
commite9c1901bad44addf1f442f337ddc2b4f5f3d4d5a (patch)
treec25559fca14fc01b9138de7741aec80df5478f83
parentcf35cf326bfa8a7f7b305102900b3bc2b1092960 (diff)
Core: Use an aspect for the Patch tool path setting
Change-Id: Ifc758fb4ac5d00a7b755ea06f3f6b98d53e7cc46 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
-rw-r--r--src/libs/utils/aspects.cpp5
-rw-r--r--src/libs/utils/aspects.h6
-rw-r--r--src/plugins/coreplugin/patchtool.cpp27
-rw-r--r--src/plugins/coreplugin/patchtool.h1
-rw-r--r--src/plugins/coreplugin/systemsettings.cpp26
-rw-r--r--src/plugins/coreplugin/systemsettings.h2
6 files changed, 29 insertions, 38 deletions
diff --git a/src/libs/utils/aspects.cpp b/src/libs/utils/aspects.cpp
index 9268d325860..5cbd8f9bdbe 100644
--- a/src/libs/utils/aspects.cpp
+++ b/src/libs/utils/aspects.cpp
@@ -159,6 +159,11 @@ void BaseAspect::setDefaultVariantValue(const QVariant &value)
QTC_CHECK(false);
}
+bool BaseAspect::isDefaultValue() const
+{
+ return defaultVariantValue() == variantValue();
+}
+
QVariant BaseAspect::defaultVariantValue() const
{
return {};
diff --git a/src/libs/utils/aspects.h b/src/libs/utils/aspects.h
index b460356851a..33e72604753 100644
--- a/src/libs/utils/aspects.h
+++ b/src/libs/utils/aspects.h
@@ -60,6 +60,7 @@ public:
virtual QVariant defaultVariantValue() const;
virtual void setDefaultVariantValue(const QVariant &value);
+ virtual bool isDefaultValue() const;
QString settingsKey() const;
void setSettingsKey(const QString &settingsKey);
@@ -278,6 +279,11 @@ public:
internalToBuffer(); // Might be more than a plain copy.
}
+ bool isDefaultValue() const override
+ {
+ return m_default == m_internal;
+ }
+
void setValue(const ValueType &value, Announcement howToAnnounce = DoEmit)
{
Changes changes;
diff --git a/src/plugins/coreplugin/patchtool.cpp b/src/plugins/coreplugin/patchtool.cpp
index 744282728a8..89144f7a27d 100644
--- a/src/plugins/coreplugin/patchtool.cpp
+++ b/src/plugins/coreplugin/patchtool.cpp
@@ -1,10 +1,12 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+#include "patchtool.h"
+
#include "coreplugintr.h"
#include "icore.h"
#include "messagemanager.h"
-#include "patchtool.h"
+#include "systemsettings.h"
#include <utils/environment.h>
#include <utils/process.h>
@@ -12,41 +14,26 @@
#include <QMessageBox>
using namespace Utils;
+using namespace Core::Internal;
namespace Core {
-const char settingsGroupC[] = "General";
-const char patchCommandKeyC[] = "PatchCommand";
-const char patchCommandDefaultC[] = "patch";
-
FilePath PatchTool::patchCommand()
{
- QSettings *s = ICore::settings();
+ FilePath command = systemSettings().patchCommand();
- s->beginGroup(settingsGroupC);
- FilePath command = FilePath::fromSettings(s->value(patchCommandKeyC, patchCommandDefaultC));
- s->endGroup();
-
- if (HostOsInfo::isWindowsHost() && command.path() == patchCommandDefaultC) {
+ if (HostOsInfo::isWindowsHost() && systemSettings().patchCommand.isDefaultValue()) {
const QSettings settings(R"(HKEY_LOCAL_MACHINE\SOFTWARE\GitForWindows)",
QSettings::NativeFormat);
const FilePath gitInstall = FilePath::fromUserInput(settings.value("InstallPath").toString());
if (gitInstall.exists())
command = command.searchInPath({gitInstall.pathAppended("usr/bin")},
- Utils::FilePath::PrependToPath);
+ FilePath::PrependToPath);
}
return command;
}
-void PatchTool::setPatchCommand(const FilePath &newCommand)
-{
- Utils::QtcSettings *s = ICore::settings();
- s->beginGroup(settingsGroupC);
- s->setValueWithDefault(patchCommandKeyC, newCommand.toSettings(), QVariant(QString(patchCommandDefaultC)));
- s->endGroup();
-}
-
bool PatchTool::confirmPatching(QWidget *parent, PatchAction patchAction, bool isModified)
{
const QString title = patchAction == PatchAction::Apply ? Tr::tr("Apply Chunk")
diff --git a/src/plugins/coreplugin/patchtool.h b/src/plugins/coreplugin/patchtool.h
index 020ab72eb6e..c509b502a2f 100644
--- a/src/plugins/coreplugin/patchtool.h
+++ b/src/plugins/coreplugin/patchtool.h
@@ -18,7 +18,6 @@ class CORE_EXPORT PatchTool
{
public:
static Utils::FilePath patchCommand();
- static void setPatchCommand(const Utils::FilePath &newCommand);
static bool confirmPatching(QWidget *parent, PatchAction patchAction, bool isModified);
diff --git a/src/plugins/coreplugin/systemsettings.cpp b/src/plugins/coreplugin/systemsettings.cpp
index 1fbede37599..a40930b980f 100644
--- a/src/plugins/coreplugin/systemsettings.cpp
+++ b/src/plugins/coreplugin/systemsettings.cpp
@@ -13,7 +13,6 @@
#include "icore.h"
#include "iversioncontrol.h"
#include "mainwindow.h"
-#include "patchtool.h"
#include "vcsmanager.h"
#include <utils/algorithm.h>
@@ -27,15 +26,12 @@
#include <utils/terminalcommand.h>
#include <utils/unixutils.h>
-#include <QCheckBox>
#include <QComboBox>
-#include <QCoreApplication>
#include <QGuiApplication>
#include <QLineEdit>
#include <QMessageBox>
#include <QPushButton>
#include <QSettings>
-#include <QSpinBox>
#include <QToolButton>
using namespace Utils;
@@ -70,6 +66,13 @@ SystemSettings::SystemSettings()
{
setAutoApply(false);
+ patchCommand.setSettingsKey("General/PatchCommand");
+ patchCommand.setDefaultValue("patch");
+ patchCommand.setExpectedKind(PathChooser::ExistingCommand);
+ patchCommand.setHistoryCompleter("General.PatchCommand.History");
+ patchCommand.setLabelText(Tr::tr("Patch command:"));
+ patchCommand.setToolTip(Tr::tr("Command used for reverting diff chunks."));
+
autoSaveModifiedFiles.setSettingsKey("EditorManager/AutoSaveEnabled");
autoSaveModifiedFiles.setDefaultValue(true);
autoSaveModifiedFiles.setLabelText(Tr::tr("Auto-save modified files"));
@@ -163,7 +166,6 @@ public:
, m_terminalComboBox(new QComboBox)
, m_terminalOpenArgs(new QLineEdit)
, m_terminalExecuteArgs(new QLineEdit)
- , m_patchChooser(new Utils::PathChooser)
, m_environmentChangesLabel(new Utils::ElidingLabel)
, m_clearCrashReportsButton(new QPushButton(Tr::tr("Clear Local Crash Reports")))
, m_crashReportsSizeText(new QLabel)
@@ -195,7 +197,6 @@ public:
helpCrashReportingButton->setText(Tr::tr("?"));
auto resetTerminalButton = new QPushButton(Tr::tr("Reset"));
resetTerminalButton->setToolTip(Tr::tr("Reset to default.", "Terminal"));
- auto patchCommandLabel = new QLabel(Tr::tr("Patch command:"));
auto environmentButton = new QPushButton(Tr::tr("Change..."));
environmentButton->setSizePolicy(QSizePolicy::Fixed,
environmentButton->sizePolicy().verticalPolicy());
@@ -218,7 +219,7 @@ public:
resetFileBrowserButton,
helpExternalFileBrowserButton})});
}
- form.addRow({patchCommandLabel, Span(2, m_patchChooser)});
+ form.addRow({Span(3, s.patchCommand)});
if (HostOsInfo::isMacHost()) {
form.addRow({fileSystemCaseSensitivityLabel,
Span(2, Row{m_fileSystemCaseSensitivityChooser, st})});
@@ -258,13 +259,6 @@ public:
m_externalFileBrowserEdit->setText(UnixUtils::fileBrowser(ICore::settings()));
}
- const QString patchToolTip = Tr::tr("Command used for reverting diff chunks.");
- patchCommandLabel->setToolTip(patchToolTip);
- m_patchChooser->setToolTip(patchToolTip);
- m_patchChooser->setExpectedKind(PathChooser::ExistingCommand);
- m_patchChooser->setHistoryCompleter(QLatin1String("General.PatchCommand.History"));
- m_patchChooser->setFilePath(PatchTool::patchCommand());
-
#ifdef ENABLE_CRASHPAD
if (s.showCrashButton()) {
auto crashButton = new QPushButton("CRASH!!!");
@@ -374,7 +368,6 @@ private:
QComboBox *m_terminalComboBox;
QLineEdit *m_terminalOpenArgs;
QLineEdit *m_terminalExecuteArgs;
- Utils::PathChooser *m_patchChooser;
Utils::ElidingLabel *m_environmentChangesLabel;
QPushButton *m_clearCrashReportsButton;
QLabel *m_crashReportsSizeText;
@@ -398,7 +391,6 @@ void SystemSettingsWidget::apply()
UnixUtils::setFileBrowser(settings, m_externalFileBrowserEdit->text());
}
}
- PatchTool::setPatchCommand(m_patchChooser->filePath());
if (HostOsInfo::isMacHost()) {
const Qt::CaseSensitivity sensitivity = EditorManagerPrivate::readFileSystemSensitivity(
@@ -440,7 +432,7 @@ void SystemSettingsWidget::updatePath()
{
Environment env;
env.appendToPath(VcsManager::additionalToolsPath());
- m_patchChooser->setEnvironment(env);
+ systemSettings().patchCommand.setEnvironment(env);
}
void SystemSettingsWidget::updateEnvironmentChangesLabel()
diff --git a/src/plugins/coreplugin/systemsettings.h b/src/plugins/coreplugin/systemsettings.h
index 18126e29fc9..1b0415faf91 100644
--- a/src/plugins/coreplugin/systemsettings.h
+++ b/src/plugins/coreplugin/systemsettings.h
@@ -12,6 +12,8 @@ class SystemSettings final : public Utils::AspectContainer
public:
SystemSettings();
+ Utils::FilePathAspect patchCommand{this};
+
Utils::BoolAspect autoSaveModifiedFiles{this};
Utils::IntegerAspect autoSaveInterval{this};