Commit a59d9b8d authored by Ahmad Samir's avatar Ahmad Samir
Browse files

Update the profiles list menu when the default profile is changed

Now the 'File->New Tab' menu is updated when the default profile is
changed, i.e. the action font is made bold and the favourites icon
emblem is added to the profile icon.

A call to menu()->setDefaultAction() has been removed, as I don't see
what it serves exactly in the current code.

Reported by khindenburg in:
!351
parent 5976de12
......@@ -415,15 +415,20 @@ void MainWindow::profileListChanged(const QList<QAction *> &sessionActions)
for (QAction *sessionAction : sessionActions) {
_newTabMenuAction->menu()->addAction(sessionAction);
// NOTE: defaultProfile seems to not work here, sigh.
auto setActionFont = [sessionAction](bool isBold) {
QFont actionFont = sessionAction->font();
actionFont.setBold(isBold);
sessionAction->setFont(actionFont);
};
Profile::Ptr profile = ProfileManager::instance()->defaultProfile();
if (profile && profile->name() == sessionAction->text().remove(QLatin1Char('&'))) {
QIcon icon(KIconLoader::global()->loadIcon(profile->icon(), KIconLoader::Small, 0, KIconLoader::DefaultState, QStringList(QStringLiteral("emblem-favorite"))));
sessionAction->setIcon(icon);
_newTabMenuAction->menu()->setDefaultAction(sessionAction);
QFont actionFont = sessionAction->font();
actionFont.setBold(true);
sessionAction->setFont(actionFont);
setActionFont(true);
} else {
sessionAction->setIcon(QIcon::fromTheme(profile->icon()));
setActionFont(false);
}
}
} else {
......
......@@ -87,6 +87,8 @@ void ProfileList::updateAction(QAction* action , Profile::Ptr profile)
action->setText(profile->name());
action->setIcon(QIcon::fromTheme(profile->icon()));
Q_EMIT actionsChanged(_group->actions());
}
void ProfileList::shortcutChanged(const Profile::Ptr &profile, const QKeySequence& sequence)
{
......
......@@ -502,8 +502,16 @@ bool ProfileManager::deleteProfile(Profile::Ptr profile)
void ProfileManager::setDefaultProfile(const Profile::Ptr &profile)
{
Q_ASSERT(_profiles.contains(profile));
const auto oldDefault = _defaultProfile;
_defaultProfile = profile;
ProfileModel::instance()->setDefault(profile);
// Setting/unsetting a profile as the default is a sort of a
// "profile change", useful for updating the icon/font of the
// "default profile in e.g. 'File -> New Tab' menu.
Q_EMIT profileChanged(oldDefault);
Q_EMIT profileChanged(profile);
}
void ProfileManager::saveDefaultProfile()
......
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