Commit ce18a9c8 authored by Nathan Sprangers's avatar Nathan Sprangers Committed by Kurt Hindenburg
Browse files

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.
parent c2aa8bc5
Pipeline #83748 passed with stage
in 3 minutes and 53 seconds
......@@ -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<int>(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<int>::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);
}
......
......@@ -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<int, QVariant> _previewedProperties;
QHash<int, QVariant> _delayedPreviewProperties;
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<ui version="5.0">
<class>EditProfileGeneralPage</class>
<widget class="QWidget" name="EditProfileGeneralPage">
<property name="geometry">
......@@ -70,16 +70,43 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="profileNameEdit">
<property name="toolTip">
<string>A descriptive name for the profile</string>
<layout class="QVBoxLayout" name="profileNameLayout">
<item>
<widget class="QLineEdit" name="profileNameEdit">
<property name="toolTip">
<string>A descriptive name for the profile</string>
</property>
<property name="placeholderText">
<string comment="@label:textbox">Profile name</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="setAsDefaultButton">
<property name="text">
<string>Default Profile</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="placeholderText">
<string comment="@label:textbox">Profile name</string>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
</widget>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>16</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0" alignment="Qt::AlignRight">
<item row="3" column="0" alignment="Qt::AlignRight">
<widget class="QLabel" name="label_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
......@@ -98,7 +125,7 @@
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QLineEdit" name="commandEdit">
<property name="toolTip">
<string>The command to execute when new terminal sessions are created using this profile</string>
......@@ -111,7 +138,7 @@
</property>
</widget>
</item>
<item row="3" column="0" alignment="Qt::AlignRight">
<item row="4" column="0" alignment="Qt::AlignRight">
<widget class="QLabel" name="label_9">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
......@@ -130,7 +157,7 @@
</property>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<widget class="QLineEdit" name="initialDirEdit">
<property name="toolTip">
<string>The initial working directory for new terminal sessions using this profile</string>
......@@ -143,7 +170,7 @@
</property>
</widget>
</item>
<item row="3" column="2">
<item row="4" column="2">
<widget class="QToolButton" name="dirSelectButton">
<property name="toolTip">
<string>Choose the initial directory</string>
......@@ -153,14 +180,14 @@
</property>
</widget>
</item>
<item row="4" column="1" colspan="2">
<item row="5" column="1" colspan="2">
<widget class="QCheckBox" name="startInSameDirButton">
<property name="text">
<string>Start in same directory as current session</string>
</property>
</widget>
</item>
<item row="5" column="0" alignment="Qt::AlignRight">
<item row="6" column="0" alignment="Qt::AlignRight">
<widget class="QLabel" name="label_4">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
......@@ -179,7 +206,7 @@
</property>
</widget>
</item>
<item row="5" column="1" colspan="2">
<item row="6" column="1" colspan="2">
<layout class="QHBoxLayout">
<property name="spacing">
<number>0</number>
......@@ -209,7 +236,7 @@
</item>
</layout>
</item>
<item row="6" column="1">
<item row="7" column="1">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -225,7 +252,7 @@
</property>
</spacer>
</item>
<item row="7" column="0" alignment="Qt::AlignRight">
<item row="8" column="0" alignment="Qt::AlignRight">
<widget class="QLabel" name="label_5">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
......@@ -241,7 +268,7 @@
</property>
</widget>
</item>
<item row="7" column="1" colspan="2">
<item row="8" column="1" colspan="2">
<layout class="QHBoxLayout">
<property name="spacing">
<number>0</number>
......@@ -300,7 +327,7 @@
</item>
</layout>
</item>
<item row="8" column="1" colspan="2">
<item row="9" column="1" colspan="2">
<widget class="QLabel" name="useCurrentWindowSizeNote">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
......@@ -319,7 +346,7 @@
</property>
</widget>
</item>
<item row="9" column="0" alignment="Qt::AlignRight">
<item row="10" column="0" alignment="Qt::AlignRight">
<widget class="QLabel" name="terminalBellLabel">
<property name="text">
<string>Terminal bell mode:</string>
......@@ -329,7 +356,7 @@
</property>
</widget>
</item>
<item row="9" column="1" colspan="1" alignment="Qt::AlignLeft">
<item row="10" column="1" colspan="1" alignment="Qt::AlignLeft">
<layout class="QHBoxLayout" name="terminalBellLayout">
<item>
<widget class="QComboBox" name="terminalBellCombo">
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment