summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKurt Hindenburg <[email protected]>2018-02-03 09:59:51 -0500
committerKurt Hindenburg <[email protected]>2018-02-03 09:59:51 -0500
commite2184aef3d7ed3f588b2981dfde652becaa1f60e (patch)
treea0dfe2bf131b712c2c12ec40d33221ad674bb774
parentc63525fcdc52b3c3d6a82364bb21e8b41bd60c4d (diff)
Select newly-created colorScheme after saving the scheme
After a new color scheme is created, select it in the list. Patch by ahmadsamir https://phabricator.kde.org/D10214
-rw-r--r--src/EditProfileDialog.cpp28
-rw-r--r--src/EditProfileDialog.h8
2 files changed, 27 insertions, 9 deletions
diff --git a/src/EditProfileDialog.cpp b/src/EditProfileDialog.cpp
index 138926f..346d85b 100644
--- a/src/EditProfileDialog.cpp
+++ b/src/EditProfileDialog.cpp
@@ -280,6 +280,12 @@ const Profile::Ptr EditProfileDialog::lookupProfile() const
return _profile;
}
+const QString EditProfileDialog::currentColorSchemeName() const
+{
+ const QString &currentColorSchemeName = lookupProfile()->colorScheme();
+ return currentColorSchemeName;
+}
+
void EditProfileDialog::preparePage(int page)
{
const Profile::Ptr profile = lookupProfile();
@@ -536,7 +542,8 @@ void EditProfileDialog::setupAppearancePage(const Profile::Ptr profile)
_ui->resetColorSchemeButton->setEnabled(false);
// setup color list
- updateColorSchemeList(true);
+ // select the colorScheme used in the current profile
+ updateColorSchemeList(currentColorSchemeName());
_ui->colorSchemeList->setMouseTracking(true);
_ui->colorSchemeList->installEventFilter(this);
@@ -636,14 +643,13 @@ void EditProfileDialog::toggleMouseWheelZoom(bool enable)
updateTempProfileProperty(Profile::MouseWheelZoomEnabled, enable);
}
-void EditProfileDialog::updateColorSchemeList(bool selectCurrentScheme)
+void EditProfileDialog::updateColorSchemeList(const QString &selectedColorSchemeName)
{
if (_ui->colorSchemeList->model() == nullptr) {
_ui->colorSchemeList->setModel(new QStandardItemModel(this));
}
- const QString &name = lookupProfile()->colorScheme();
- const ColorScheme *currentScheme = ColorSchemeManager::instance()->findColorScheme(name);
+ const ColorScheme *selectedColorScheme = ColorSchemeManager::instance()->findColorScheme(selectedColorSchemeName);
QStandardItemModel *model = qobject_cast<QStandardItemModel *>(_ui->colorSchemeList->model());
@@ -661,7 +667,9 @@ void EditProfileDialog::updateColorSchemeList(bool selectCurrentScheme)
item->setData(QVariant::fromValue(_profile->font()), Qt::UserRole + 2);
item->setFlags(item->flags());
- if (currentScheme == scheme) {
+ // if selectedColorSchemeName is not empty then select that scheme
+ // after saving the changes in the colorScheme editor
+ if (selectedColorScheme == scheme) {
selectedItem = item;
}
@@ -670,7 +678,7 @@ void EditProfileDialog::updateColorSchemeList(bool selectCurrentScheme)
model->sort(0);
- if (selectCurrentScheme && (selectedItem != nullptr)) {
+ if (selectedItem != nullptr) {
_ui->colorSchemeList->updateGeometry();
_ui->colorSchemeList->selectionModel()->setCurrentIndex(selectedItem->index(),
QItemSelectionModel::Select);
@@ -847,7 +855,8 @@ void EditProfileDialog::removeColorScheme()
void EditProfileDialog::resetColorScheme()
{
removeColorScheme();
- updateColorSchemeList(true);
+ // select the colorScheme used in the current profile
+ updateColorSchemeList(currentColorSchemeName());
}
void EditProfileDialog::showColorSchemeEditor(bool isNewScheme)
@@ -907,7 +916,10 @@ void EditProfileDialog::saveColorScheme(const ColorScheme &scheme, bool isNewSch
ColorSchemeManager::instance()->addColorScheme(newScheme);
- updateColorSchemeList(true);
+ const QString &selectedColorSchemeName = newScheme->name();
+
+ // select the edited or the new colorScheme after saving the changes
+ updateColorSchemeList(selectedColorSchemeName);
preview(Profile::ColorScheme, newScheme->name());
}
diff --git a/src/EditProfileDialog.h b/src/EditProfileDialog.h
index ed9c945..18c8568 100644
--- a/src/EditProfileDialog.h
+++ b/src/EditProfileDialog.h
@@ -207,7 +207,13 @@ private:
void setupAdvancedPage(const Profile::Ptr profile);
void setupMousePage(const Profile::Ptr info);
- void updateColorSchemeList(bool selectCurrentScheme = false);
+ // Returns the name of the colorScheme used in the current profile
+ const QString currentColorSchemeName() const;
+
+ // select @p selectedColorSchemeName after the changes are saved
+ // in the colorScheme editor
+ void updateColorSchemeList(const QString &selectedColorSchemeName = QString());
+
void updateColorSchemeButtons();
void updateKeyBindingsList(bool selectCurrentTranslator = false);
void updateKeyBindingsButtons();