Commit bc41efd8 authored by Ahmad Samir's avatar Ahmad Samir Committed by Kurt Hindenburg
Browse files

Fix crash in ProfileSettings; clone selected profile settings to new profile

- If there is no selection only enable the "New" button, this fixes a
  crash if you select a profile, then Ctrl+Click to unselect it, the set
  as default button would still be enabled and clicking it caused a crash

- If a profile is selected, clone its properties, otherwise the fallback
  profile properties will be used, this more expected
parent 27cedc46
......@@ -90,13 +90,20 @@ void ProfileSettings::populateTable()
connect(profilesList->selectionModel(), &QItemSelectionModel::selectionChanged, this, &Konsole::ProfileSettings::tableSelectionChanged);
}
void ProfileSettings::tableSelectionChanged(const QItemSelection&)
void ProfileSettings::tableSelectionChanged(const QItemSelection &selected)
{
newProfileButton->setEnabled(true);
if (selected.isEmpty()) {
editProfileButton->setEnabled(false);
deleteProfileButton->setEnabled(false);
setAsDefaultButton->setEnabled(false);
return;
}
const auto profile = currentProfile();
const bool isNotDefault = profile != ProfileManager::instance()->defaultProfile();
newProfileButton->setEnabled(true);
// See comment about isProfileWritable(profile) in editSelected()
editProfileButton->setEnabled(isProfileWritable(profile));
......@@ -126,14 +133,14 @@ void ProfileSettings::setSelectedAsDefault()
void ProfileSettings::createProfile()
{
// setup a temporary profile which is a clone of the selected profile
// or the default if no profile is selected
Profile::Ptr sourceProfile = currentProfile() ? currentProfile() : ProfileManager::instance()->defaultProfile();
auto newProfile = Profile::Ptr(new Profile(ProfileManager::instance()->fallbackProfile()));
Q_ASSERT(sourceProfile);
// If a profile is selected, clone its properties, otherwise the
// the fallback profile properties will be used
if (currentProfile()) {
newProfile->clone(currentProfile(), true);
}
auto newProfile = Profile::Ptr(new Profile(ProfileManager::instance()->fallbackProfile()));
newProfile->clone(sourceProfile, true);
const QString uniqueName = ProfileManager::instance()->generateUniqueName();
newProfile->setProperty(Profile::Name, uniqueName);
newProfile->setProperty(Profile::UntranslatedName, uniqueName);
......@@ -189,7 +196,7 @@ Profile::Ptr ProfileSettings::currentProfile() const
{
QItemSelectionModel* selection = profilesList->selectionModel();
if ((selection == nullptr) || selection->selectedRows().count() != 1) {
if ((selection == nullptr) || !selection->hasSelection()) {
return Profile::Ptr();
}
......
Markdown is supported
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