From ce18a9c8dd8a20491ed2e383e99ef54a76b04dd1 Mon Sep 17 00:00:00 2001 From: Nathan Sprangers Date: Wed, 29 Sep 2021 01:46:59 -0400 Subject: [PATCH] Add a "set as default" option to the edit profile dialog Add a checkbox to the Edit Profile dialog to set/unset the profile as the default profile. Responds to the Apply and Ok buttons like other dialog settings. Unchecking (and clicking Apply/Ok) sets the fallback profile as the default. --- src/widgets/EditProfileDialog.cpp | 32 ++++++++++++- src/widgets/EditProfileDialog.h | 4 +- src/widgets/EditProfileGeneralPage.ui | 69 +++++++++++++++++++-------- 3 files changed, 81 insertions(+), 24 deletions(-) diff --git a/src/widgets/EditProfileDialog.cpp b/src/widgets/EditProfileDialog.cpp index 1a9bb842..5a30770c 100644 --- a/src/widgets/EditProfileDialog.cpp +++ b/src/widgets/EditProfileDialog.cpp @@ -229,13 +229,15 @@ void EditProfileDialog::save() ProfileManager::instance()->addProfile(_profile); } - if (_tempProfile->isEmpty()) { + bool defaultChanged = _isDefault != _generalUi->setAsDefaultButton->isChecked(); + + if (_tempProfile->isEmpty() && !defaultChanged) { if (isNewProfile) { // New profile, we need to save it to disk, even if no settings // were changed and _tempProfile is empty ProfileManager::instance()->changeProfile(_profile, _profile->setProperties()); } - + // no changes since last save return; } @@ -249,6 +251,16 @@ void EditProfileDialog::save() _previewedProperties.remove(iter.key()); } + // Update the default profile if needed + if (defaultChanged) { + Q_ASSERT(_profile != ProfileManager::instance()->fallbackProfile()); + + bool defaultChecked = _generalUi->setAsDefaultButton->isChecked(); + Profile::Ptr newDefault = defaultChecked ? _profile : ProfileManager::instance()->fallbackProfile(); + ProfileManager::instance()->setDefaultProfile(newDefault); + _isDefault = defaultChecked; + } + createTempProfile(); _buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false); @@ -464,6 +476,16 @@ void EditProfileDialog::setupGeneralPage(const Profile::Ptr &profile) _generalUi->terminalBellCombo->setModel(bellModeModel); _generalUi->terminalBellCombo->setCurrentIndex(profile->property(Profile::BellMode)); + _isDefault = profile == ProfileManager::instance()->defaultProfile(); + _generalUi->setAsDefaultButton->setChecked(_isDefault); + QString appName = QCoreApplication::applicationName(); + if (appName == QStringLiteral("konsole")) { + _generalUi->setAsDefaultButton->setText(i18n("Default profile")); + } else { + appName[0] = appName[0].toUpper(); + _generalUi->setAsDefaultButton->setText(i18n("Default profile for new terminal sessions in %1", appName)); + } + // signals and slots connect(_generalUi->dirSelectButton, &QToolButton::clicked, this, &Konsole::EditProfileDialog::selectInitialDir); connect(_generalUi->iconSelectButton, &QPushButton::clicked, this, &Konsole::EditProfileDialog::selectIcon); @@ -479,6 +501,8 @@ void EditProfileDialog::setupGeneralPage(const Profile::Ptr &profile) connect(_generalUi->terminalBellCombo, QOverload::of(&QComboBox::currentIndexChanged), this, [this](const int index) { updateTempProfileProperty(Profile::BellMode, index); }); + + connect(_generalUi->setAsDefaultButton, &QAbstractButton::toggled, this, &Konsole::EditProfileDialog::updateButtonApply); } void EditProfileDialog::showEnvironmentEditor() @@ -1363,6 +1387,10 @@ void EditProfileDialog::updateButtonApply() } } + if (_generalUi->setAsDefaultButton->isChecked() != _isDefault) { + userModified = true; + } + _buttonBox->button(QDialogButtonBox::Apply)->setEnabled(userModified); } diff --git a/src/widgets/EditProfileDialog.h b/src/widgets/EditProfileDialog.h index 3368347b..8ed10549 100644 --- a/src/widgets/EditProfileDialog.h +++ b/src/widgets/EditProfileDialog.h @@ -287,7 +287,7 @@ private: void createTempProfile(); // Enable or disable apply button, used only within - // updateTempProfileProperty(). + // updateTempProfileProperty() or when toggling the default profile. void updateButtonApply(); static QString groupProfileNames(const ProfileGroup::Ptr &group, int maxLength = -1); @@ -337,6 +337,8 @@ private: Profile::Ptr _tempProfile; Profile::Ptr _profile; + bool _isDefault; + QHash _previewedProperties; QHash _delayedPreviewProperties; diff --git a/src/widgets/EditProfileGeneralPage.ui b/src/widgets/EditProfileGeneralPage.ui index b649531c..85ede363 100644 --- a/src/widgets/EditProfileGeneralPage.ui +++ b/src/widgets/EditProfileGeneralPage.ui @@ -1,5 +1,5 @@ - + EditProfileGeneralPage @@ -70,16 +70,43 @@ - - - A descriptive name for the profile + + + + + A descriptive name for the profile + + + Profile name + + + + + + + Default Profile + + + + + + + + + Qt::Vertical - - Profile name + + QSizePolicy::Fixed - + + + 20 + 16 + + + - + @@ -98,7 +125,7 @@ - + The command to execute when new terminal sessions are created using this profile @@ -111,7 +138,7 @@ - + @@ -130,7 +157,7 @@ - + The initial working directory for new terminal sessions using this profile @@ -143,7 +170,7 @@ - + Choose the initial directory @@ -153,14 +180,14 @@ - + Start in same directory as current session - + @@ -179,7 +206,7 @@ - + 0 @@ -209,7 +236,7 @@ - + Qt::Vertical @@ -225,7 +252,7 @@ - + @@ -241,7 +268,7 @@ - + 0 @@ -300,7 +327,7 @@ - + @@ -319,7 +346,7 @@ - + Terminal bell mode: @@ -329,7 +356,7 @@ - +