Core: Move SystemSettings page closer to current setup

Also align items a bit and use BaseAspect::setEnabler() where
appropriate.

Change-Id: I7497e3ce82f3685582a84b1bf383e65892d76f96
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2023-07-26 18:29:20 +02:00
parent bc1ef0f158
commit 7f908d737b
7 changed files with 182 additions and 338 deletions

View File

@@ -8,6 +8,7 @@
#include "coreplugintr.h"
#include "editormanager/editormanager_p.h"
#include "dialogs/restartdialog.h"
#include "dialogs/ioptionspage.h"
#include "fileutils.h"
#include "icore.h"
#include "iversioncontrol.h"
@@ -40,13 +41,9 @@
using namespace Utils;
using namespace Layouting;
namespace Core {
namespace Internal {
namespace Core::Internal {
#ifdef ENABLE_CRASHPAD
const char crashReportingEnabledKey[] = "CrashReportingEnabled";
const char showCrashButtonKey[] = "ShowCrashButton";
// TODO: move to somewhere in Utils
static QString formatSize(qint64 size)
{
@@ -63,55 +60,128 @@ static QString formatSize(qint64 size)
}
#endif // ENABLE_CRASHPAD
SystemSettings &systemSettings()
{
static SystemSettings theSettings;
return theSettings;
}
SystemSettings::SystemSettings()
{
setAutoApply(false);
autoSaveModifiedFiles.setSettingsKey("EditorManager/AutoSaveEnabled");
autoSaveModifiedFiles.setDefaultValue(true);
autoSaveModifiedFiles.setLabelText(Tr::tr("Auto-save modified files"));
autoSaveModifiedFiles.setLabelPlacement(
BoolAspect::LabelPlacement::AtCheckBoxWithoutDummyLabel);
autoSaveModifiedFiles.setToolTip(
Tr::tr("Automatically creates temporary copies of modified files. "
"If %1 is restarted after a crash or power failure, it asks whether to "
"recover the auto-saved content.")
.arg(QGuiApplication::applicationDisplayName()));
autoSaveInterval.setSettingsKey("EditorManager/AutoSaveInterval");
autoSaveInterval.setSuffix(Tr::tr("min"));
autoSaveInterval.setRange(1, 1000000);
autoSaveInterval.setDefaultValue(5);
autoSaveInterval.setEnabler(&autoSaveModifiedFiles);
autoSaveInterval.setLabelText(Tr::tr("Interval:"));
autoSaveAfterRefactoring.setSettingsKey("EditorManager/AutoSaveAfterRefactoring");
autoSaveAfterRefactoring.setDefaultValue(true);
autoSaveAfterRefactoring.setLabelPlacement(
BoolAspect::LabelPlacement::AtCheckBoxWithoutDummyLabel);
autoSaveAfterRefactoring.setLabelText(Tr::tr("Auto-save files after refactoring"));
autoSaveAfterRefactoring.setToolTip(
Tr::tr("Automatically saves all open files affected by a refactoring operation,\n"
"provided they were unmodified before the refactoring."));
autoSuspendEnabled.setSettingsKey("EditorManager/AutoSuspendEnabled");
autoSuspendEnabled.setDefaultValue(true);
autoSuspendEnabled.setLabelText(Tr::tr("Auto-suspend unmodified files"));
autoSuspendEnabled.setLabelPlacement(
BoolAspect::LabelPlacement::AtCheckBoxWithoutDummyLabel);
autoSuspendEnabled.setToolTip(
Tr::tr("Automatically free resources of old documents that are not visible and not "
"modified. They stay visible in the list of open documents."));
autoSuspendMinDocumentCount.setSettingsKey("EditorManager/AutoSuspendMinDocuments");
autoSuspendMinDocumentCount.setRange(1, 500);
autoSuspendMinDocumentCount.setDefaultValue(30);
autoSuspendMinDocumentCount.setEnabler(&autoSuspendEnabled);
autoSuspendMinDocumentCount.setLabelText(Tr::tr("Files to keep open:"));
autoSuspendMinDocumentCount.setToolTip(
Tr::tr("Minimum number of open documents that should be kept in memory. Increasing this "
"number will lead to greater resource usage when not manually closing documents."));
warnBeforeOpeningBigFiles.setSettingsKey("EditorManager/WarnBeforeOpeningBigTextFiles");
warnBeforeOpeningBigFiles.setDefaultValue(true);
warnBeforeOpeningBigFiles.setLabelPlacement(
BoolAspect::LabelPlacement::AtCheckBoxWithoutDummyLabel);
warnBeforeOpeningBigFiles.setLabelText(Tr::tr("Warn before opening text files greater than"));
bigFileSizeLimitInMB.setSettingsKey("EditorManager/BigTextFileSizeLimitInMB");
bigFileSizeLimitInMB.setSuffix(Tr::tr("MB"));
bigFileSizeLimitInMB.setRange(1, 500);
bigFileSizeLimitInMB.setDefaultValue(5);
bigFileSizeLimitInMB.setEnabler(&warnBeforeOpeningBigFiles);
maxRecentFiles.setSettingsKey("EditorManager/MaxRecentFiles");
maxRecentFiles.setRange(1, 99);
maxRecentFiles.setDefaultValue(8);
reloadSetting.setSettingsKey("EditorManager/ReloadBehavior");
reloadSetting.setDisplayStyle(SelectionAspect::DisplayStyle::ComboBox);
reloadSetting.addOption(Tr::tr("Always Ask"));
reloadSetting.addOption(Tr::tr("Reload All Unchanged Editors"));
reloadSetting.addOption(Tr::tr("Ignore Modifications"));
reloadSetting.setDefaultValue(IDocument::AlwaysAsk);
reloadSetting.setLabelText(Tr::tr("When files are externally modified:"));
askBeforeExit.setSettingsKey("AskBeforeExit");
askBeforeExit.setLabelText(Tr::tr("Ask for confirmation before exiting"));
askBeforeExit.setLabelPlacement(BoolAspect::LabelPlacement::AtCheckBoxWithoutDummyLabel);
#ifdef ENABLE_CRASHPAD
enableCrashReporting.setSettingsKey("CrashReportingEnabled");
enableCrashReporting.setLabelText(tr("Enable crash reporting"));
enableCrashReporting.setToolTip(
Tr::tr("Allow crashes to be automatically reported. Collected reports are "
"used for the sole purpose of fixing bugs."));
showCrashButton.setSettingsKey("ShowCrashButton");
#endif
const auto updateAutoSave = [] { EditorManagerPrivate::updateAutoSave(); };
connect(&autoSaveModifiedFiles, &BaseAspect::changed, this, updateAutoSave);
connect(&autoSaveInterval, &BaseAspect::changed, this, updateAutoSave);
readSettings();
}
class SystemSettingsWidget : public IOptionsPageWidget
{
public:
SystemSettingsWidget()
: m_fileSystemCaseSensitivityChooser(new QComboBox)
, m_autoSuspendMinDocumentCount(new QSpinBox)
, m_externalFileBrowserEdit(new QLineEdit)
, m_autoSuspendCheckBox(new QCheckBox(Tr::tr("Auto-suspend unmodified files")))
, m_maxRecentFilesSpinBox(new QSpinBox)
, m_enableCrashReportingCheckBox(new QCheckBox(Tr::tr("Enable crash reporting")))
, m_warnBeforeOpeningBigFiles(
new QCheckBox(Tr::tr("Warn before opening text files greater than")))
, m_bigFilesLimitSpinBox(new QSpinBox)
, m_terminalComboBox(new QComboBox)
, m_terminalOpenArgs(new QLineEdit)
, m_terminalExecuteArgs(new QLineEdit)
, m_patchChooser(new Utils::PathChooser)
, m_environmentChangesLabel(new Utils::ElidingLabel)
, m_askBeforeExitCheckBox(new QCheckBox(Tr::tr("Ask for confirmation before exiting")))
, m_reloadBehavior(new QComboBox)
, m_autoSaveCheckBox(new QCheckBox(Tr::tr("Auto-save modified files")))
, m_clearCrashReportsButton(new QPushButton(Tr::tr("Clear Local Crash Reports")))
, m_crashReportsSizeText(new QLabel)
, m_autoSaveInterval(new QSpinBox)
, m_autoSaveRefactoringCheckBox(new QCheckBox(Tr::tr("Auto-save files after refactoring")))
{
m_autoSuspendCheckBox->setToolTip(
Tr::tr("Automatically free resources of old documents that are not visible and not "
"modified. They stay visible in the list of open documents."));
m_autoSuspendMinDocumentCount->setMinimum(1);
m_autoSuspendMinDocumentCount->setMaximum(500);
m_autoSuspendMinDocumentCount->setValue(30);
m_enableCrashReportingCheckBox->setToolTip(
Tr::tr("Allow crashes to be automatically reported. Collected reports are "
"used for the sole purpose of fixing bugs."));
m_bigFilesLimitSpinBox->setSuffix(Tr::tr("MB"));
m_bigFilesLimitSpinBox->setMinimum(1);
m_bigFilesLimitSpinBox->setMaximum(500);
m_bigFilesLimitSpinBox->setValue(5);
SystemSettings &s = systemSettings();
m_terminalExecuteArgs->setToolTip(
Tr::tr("Command line arguments used for \"Run in terminal\"."));
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
sizePolicy.setHorizontalStretch(5);
m_environmentChangesLabel->setSizePolicy(sizePolicy);
m_reloadBehavior->addItem(Tr::tr("Always Ask"));
m_reloadBehavior->addItem(Tr::tr("Reload All Unchanged Editors"));
m_reloadBehavior->addItem(Tr::tr("Ignore Modifications"));
m_autoSaveInterval->setSuffix(Tr::tr("min"));
QSizePolicy termSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
termSizePolicy.setHorizontalStretch(3);
m_terminalComboBox->setSizePolicy(termSizePolicy);
@@ -119,15 +189,10 @@ public:
m_terminalComboBox->setEditable(true);
m_terminalOpenArgs->setToolTip(
Tr::tr("Command line arguments used for \"%1\".").arg(FileUtils::msgTerminalHereAction()));
m_autoSaveInterval->setMinimum(1);
auto fileSystemCaseSensitivityLabel = new QLabel(Tr::tr("File system case sensitivity:"));
fileSystemCaseSensitivityLabel->setToolTip(
Tr::tr("Influences how file names are matched to decide if they are the same."));
auto autoSuspendLabel = new QLabel(Tr::tr("Files to keep open:"));
autoSuspendLabel->setToolTip(
Tr::tr("Minimum number of open documents that should be kept in memory. Increasing this "
"number will lead to greater resource usage when not manually closing documents."));
auto resetFileBrowserButton = new QPushButton(Tr::tr("Reset"));
resetFileBrowserButton->setToolTip(Tr::tr("Reset to default."));
auto helpExternalFileBrowserButton = new QToolButton;
@@ -164,21 +229,16 @@ public:
form.addRow({fileSystemCaseSensitivityLabel,
Span(2, Row{m_fileSystemCaseSensitivityChooser, st})});
}
form.addRow(
{Tr::tr("When files are externally modified:"), Span(2, Row{m_reloadBehavior, st})});
form.addRow(
{m_autoSaveCheckBox, Span(2, Row{Tr::tr("Interval:"), m_autoSaveInterval, st})});
form.addRow({Span(3, m_autoSaveRefactoringCheckBox)});
form.addRow({m_autoSuspendCheckBox,
Span(2, Row{autoSuspendLabel, m_autoSuspendMinDocumentCount, st})});
form.addRow({Span(3, Row{m_warnBeforeOpeningBigFiles, m_bigFilesLimitSpinBox, st})});
form.addRow({Span(3,
Row{Tr::tr("Maximum number of entries in \"Recent Files\":"),
m_maxRecentFilesSpinBox,
st})});
form.addRow({m_askBeforeExitCheckBox});
form.addRow({s.reloadSetting, st});
form.addRow({s.autoSaveModifiedFiles, Span(2, Row{s.autoSaveInterval, st})});
form.addRow({Span(3, s.autoSaveAfterRefactoring)});
form.addRow({s.autoSuspendEnabled, Span(2, Row{s.autoSuspendMinDocumentCount, st})});
form.addRow({s.warnBeforeOpeningBigFiles, Span(2, Row{s.bigFileSizeLimitInMB, st})});
form.addRow({Tr::tr("Maximum number of entries in \"Recent Files\":"),
Span(2, Row{s.maxRecentFiles, st})});
form.addRow({s.askBeforeExit});
#ifdef ENABLE_CRASHPAD
form.addRow({Span(3, Row{m_enableCrashReportingCheckBox, helpCrashReportingButton, st})});
form.addRow({Span(3, Row{s.enableCrashReporting, helpCrashReportingButton, st})});
form.addRow({Span(3, Row{m_clearCrashReportsButton, m_crashReportsSizeText, st})});
#endif
@@ -189,7 +249,6 @@ public:
}
}.attachTo(this);
m_reloadBehavior->setCurrentIndex(EditorManager::reloadSetting());
if (HostOsInfo::isAnyUnixHost()) {
const QVector<TerminalCommand> availableTerminals
= TerminalCommand::availableTerminalEmulators();
@@ -211,28 +270,9 @@ public:
m_patchChooser->setExpectedKind(PathChooser::ExistingCommand);
m_patchChooser->setHistoryCompleter(QLatin1String("General.PatchCommand.History"));
m_patchChooser->setFilePath(PatchTool::patchCommand());
m_autoSaveCheckBox->setChecked(EditorManagerPrivate::autoSaveEnabled());
m_autoSaveCheckBox->setToolTip(Tr::tr("Automatically creates temporary copies of "
"modified files. If %1 is restarted after "
"a crash or power failure, it asks whether to "
"recover the auto-saved content.")
.arg(QGuiApplication::applicationDisplayName()));
m_autoSaveRefactoringCheckBox->setChecked(EditorManager::autoSaveAfterRefactoring());
m_autoSaveRefactoringCheckBox->setToolTip(
Tr::tr("Automatically saves all open files "
"affected by a refactoring operation,\nprovided they were unmodified before the "
"refactoring."));
m_autoSaveInterval->setValue(EditorManagerPrivate::autoSaveInterval());
m_autoSuspendCheckBox->setChecked(EditorManagerPrivate::autoSuspendEnabled());
m_autoSuspendMinDocumentCount->setValue(EditorManagerPrivate::autoSuspendMinDocumentCount());
m_warnBeforeOpeningBigFiles->setChecked(
EditorManagerPrivate::warnBeforeOpeningBigFilesEnabled());
m_bigFilesLimitSpinBox->setValue(EditorManagerPrivate::bigFileSizeLimit());
m_maxRecentFilesSpinBox->setMinimum(1);
m_maxRecentFilesSpinBox->setMaximum(99);
m_maxRecentFilesSpinBox->setValue(EditorManagerPrivate::maxRecentFiles());
#ifdef ENABLE_CRASHPAD
if (ICore::settings()->value(showCrashButtonKey).toBool()) {
if (s.showCrashButton()) {
auto crashButton = new QPushButton("CRASH!!!");
crashButton->show();
connect(crashButton, &QPushButton::clicked, [] {
@@ -241,12 +281,10 @@ public:
});
}
m_enableCrashReportingCheckBox->setChecked(
ICore::settings()->value(crashReportingEnabledKey).toBool());
connect(helpCrashReportingButton, &QAbstractButton::clicked, this, [this] {
showHelpDialog(Tr::tr("Crash Reporting"), CorePlugin::msgCrashpadInformation());
});
connect(m_enableCrashReportingCheckBox, &QCheckBox::stateChanged, this, [this] {
connect(&s.enableCrashReporting, &BaseAspect::changed, this, [this] {
const QString restartText = Tr::tr("The change will take effect after restart.");
Core::RestartDialog restartDialog(Core::ICore::dialogParent(), restartText);
restartDialog.exec();
@@ -263,10 +301,6 @@ public:
});
#endif
m_askBeforeExitCheckBox->setChecked(
static_cast<Core::Internal::MainWindow *>(ICore::mainWindow())
->askConfirmationBeforeExit());
if (HostOsInfo::isAnyUnixHost()) {
connect(resetTerminalButton,
&QAbstractButton::clicked,
@@ -342,33 +376,24 @@ private:
void showHelpDialog(const QString &title, const QString &helpText);
QComboBox *m_fileSystemCaseSensitivityChooser;
QSpinBox *m_autoSuspendMinDocumentCount;
QLineEdit *m_externalFileBrowserEdit;
QCheckBox *m_autoSuspendCheckBox;
QSpinBox *m_maxRecentFilesSpinBox;
QCheckBox *m_enableCrashReportingCheckBox;
QCheckBox *m_warnBeforeOpeningBigFiles;
QSpinBox *m_bigFilesLimitSpinBox;
QComboBox *m_terminalComboBox;
QLineEdit *m_terminalOpenArgs;
QLineEdit *m_terminalExecuteArgs;
Utils::PathChooser *m_patchChooser;
Utils::ElidingLabel *m_environmentChangesLabel;
QCheckBox *m_askBeforeExitCheckBox;
QComboBox *m_reloadBehavior;
QCheckBox *m_autoSaveCheckBox;
QPushButton *m_clearCrashReportsButton;
QLabel *m_crashReportsSizeText;
QSpinBox *m_autoSaveInterval;
QCheckBox *m_autoSaveRefactoringCheckBox;
QPointer<QMessageBox> m_dialog;
EnvironmentItems m_environmentChanges;
};
void SystemSettingsWidget::apply()
{
systemSettings().apply();
systemSettings().writeSettings();
QtcSettings *settings = ICore::settings();
EditorManager::setReloadSetting(IDocument::ReloadSetting(m_reloadBehavior->currentIndex()));
if (HostOsInfo::isAnyUnixHost()) {
TerminalCommand::setTerminalEmulator({
FilePath::fromUserInput(m_terminalComboBox->lineEdit()->text()),
@@ -380,22 +405,6 @@ void SystemSettingsWidget::apply()
}
}
PatchTool::setPatchCommand(m_patchChooser->filePath());
EditorManagerPrivate::setAutoSaveEnabled(m_autoSaveCheckBox->isChecked());
EditorManagerPrivate::setAutoSaveInterval(m_autoSaveInterval->value());
EditorManagerPrivate::setAutoSaveAfterRefactoring(m_autoSaveRefactoringCheckBox->isChecked());
EditorManagerPrivate::setAutoSuspendEnabled(m_autoSuspendCheckBox->isChecked());
EditorManagerPrivate::setAutoSuspendMinDocumentCount(m_autoSuspendMinDocumentCount->value());
EditorManagerPrivate::setWarnBeforeOpeningBigFilesEnabled(
m_warnBeforeOpeningBigFiles->isChecked());
EditorManagerPrivate::setBigFileSizeLimit(m_bigFilesLimitSpinBox->value());
EditorManagerPrivate::setMaxRecentFiles(m_maxRecentFilesSpinBox->value());
#ifdef ENABLE_CRASHPAD
ICore::settings()->setValue(crashReportingEnabledKey,
m_enableCrashReportingCheckBox->isChecked());
#endif
static_cast<Core::Internal::MainWindow *>(ICore::mainWindow())
->setAskConfirmationBeforeExit(m_askBeforeExitCheckBox->isChecked());
if (HostOsInfo::isMacHost()) {
const Qt::CaseSensitivity sensitivity = EditorManagerPrivate::readFileSystemSensitivity(
@@ -487,13 +496,20 @@ void SystemSettingsWidget::showHelpForFileBrowser()
showHelpDialog(Tr::tr("Variables"), UnixUtils::fileBrowserHelpText());
}
SystemSettings::SystemSettings()
{
setId(Constants::SETTINGS_ID_SYSTEM);
setDisplayName(Tr::tr("System"));
setCategory(Constants::SETTINGS_CATEGORY_CORE);
setWidgetCreator([] { return new SystemSettingsWidget; });
}
// SystemSettingsPage
} // namespace Internal
} // namespace Core
class SystemSettingsPage final : public IOptionsPage
{
public:
SystemSettingsPage()
{
setId(Constants::SETTINGS_ID_SYSTEM);
setDisplayName(Tr::tr("System"));
setCategory(Constants::SETTINGS_CATEGORY_CORE);
setWidgetCreator([] { return new SystemSettingsWidget; });
}
};
const SystemSettingsPage settingsPage;
} // Core::Internal