diff --git a/src/ColorSchemeManager.h b/src/ColorSchemeManager.h --- a/src/ColorSchemeManager.h +++ b/src/ColorSchemeManager.h @@ -88,6 +88,18 @@ /** Returns the global color scheme manager instance. */ static ColorSchemeManager *instance(); + /** + * Returns @c true if a colorscheme with @p name exists both under + * the user's home dir location, and a system-wide location + */ + bool canResetColorScheme(const QString &name); + + /** + * Returns @c true if a colorscheme with @p name exists under the + * user's home dir location, and hence can be deleted + */ + bool isColorSchemeDeletable(const QString &name); + private: Q_DISABLE_COPY(ColorSchemeManager) diff --git a/src/ColorSchemeManager.cpp b/src/ColorSchemeManager.cpp --- a/src/ColorSchemeManager.cpp +++ b/src/ColorSchemeManager.cpp @@ -213,3 +213,33 @@ return QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("konsole/") + name + QStringLiteral(".schema")); } + +bool ColorSchemeManager::isColorSchemeDeletable(const QString &name) +{ + const QString path = findColorSchemePath(name); + + QFileInfo fileInfo(path); + QFileInfo dirInfo = fileInfo.path(); + + if (fileInfo.exists()) { + return dirInfo.isWritable(); + } else { + return true; + } +} + +bool ColorSchemeManager::canResetColorScheme(const QString &name) +{ + const QStringList paths = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("konsole/") + name + QStringLiteral(".colorscheme")); + + // if the colorscheme exists in both a writable location under the + // user's home dir and a system-wide location, then it's possible + // to delete the colorscheme under the user's home dir so that the + // colorscheme from the system-wide location can be used instead, + // i.e. resetting the colorscheme + if (paths.count() > 1) { + return true; + } else { + return false; + } +} diff --git a/src/EditProfileDialog.h b/src/EditProfileDialog.h --- a/src/EditProfileDialog.h +++ b/src/EditProfileDialog.h @@ -132,6 +132,14 @@ void editColorScheme(); void saveColorScheme(const ColorScheme &scheme, bool isNewScheme); void removeColorScheme(); + + /** + * Deletes the selected colorscheme from the user's home dir location + * so that the original one from the system-wide location can be used + * instead + */ + void resetColorScheme(); + void colorSchemeSelected(); void previewColorScheme(const QModelIndex &index); void fontSelected(const QFont &); diff --git a/src/EditProfileDialog.cpp b/src/EditProfileDialog.cpp --- a/src/EditProfileDialog.cpp +++ b/src/EditProfileDialog.cpp @@ -533,6 +533,7 @@ _ui->editColorSchemeButton->setEnabled(false); _ui->removeColorSchemeButton->setEnabled(false); + _ui->resetColorSchemeButton->setEnabled(false); // setup color list updateColorSchemeList(true); @@ -556,6 +557,9 @@ connect(_ui->newColorSchemeButton, &QPushButton::clicked, this, &Konsole::EditProfileDialog::newColorScheme); + connect(_ui->resetColorSchemeButton, &QPushButton::clicked, this, + &Konsole::EditProfileDialog::resetColorScheme); + // setup font preview const bool antialias = profile->antiAliasFonts(); @@ -840,6 +844,12 @@ } } +void EditProfileDialog::resetColorScheme() +{ + removeColorScheme(); + updateColorSchemeList(true); +} + void EditProfileDialog::showColorSchemeEditor(bool isNewScheme) { // Finding selected ColorScheme @@ -923,7 +933,23 @@ void EditProfileDialog::updateColorSchemeButtons() { enableIfNonEmptySelection(_ui->editColorSchemeButton, _ui->colorSchemeList->selectionModel()); - enableIfNonEmptySelection(_ui->removeColorSchemeButton, _ui->colorSchemeList->selectionModel()); + + QModelIndexList selected = _ui->colorSchemeList->selectionModel()->selectedIndexes(); + + if (!selected.isEmpty()) { + const QString &name = selected.first().data(Qt::UserRole + 1).value()->name(); + + bool on = ColorSchemeManager::instance()->canResetColorScheme(name); + _ui->resetColorSchemeButton->setEnabled(on); + + bool isDeletable = ColorSchemeManager::instance()->isColorSchemeDeletable(name); + // if a colorScheme can be restored then it can't be deleted + _ui->removeColorSchemeButton->setEnabled(isDeletable && !on); + } else { + _ui->removeColorSchemeButton->setEnabled(false); + _ui->resetColorSchemeButton->setEnabled(false); + } + } void EditProfileDialog::updateKeyBindingsButtons() diff --git a/src/EditProfileDialog.ui b/src/EditProfileDialog.ui --- a/src/EditProfileDialog.ui +++ b/src/EditProfileDialog.ui @@ -481,7 +481,17 @@ - + + + + Reset the selected color scheme settings to the default values + + + Defaults + + + + Qt::Vertical