Commit fed1a9d2 authored by Nathan Sprangers's avatar Nathan Sprangers
Browse files

Fix missing new-tab menu when only one profile exists

Sub-menu will always be displayed in "File>New Tab" and "New Tab" button,
even if there is only one profile to display (the built-in default).

This fixes not being able to create a new tab from "File>New Tab" menu and
long-pressing on the new tab toolbar button.

BUG: 436264
parent 8ee53cc5
......@@ -426,47 +426,24 @@ void MainWindow::setProfileList(ProfileList *list)
void MainWindow::profileListChanged(const QList<QAction *> &sessionActions)
{
// If only 1 profile is to be shown in the menu, only display
// it if it is the non-default profile.
if (sessionActions.size() > 2) {
// Update the 'New Tab' KActionMenu
if (_newTabMenuAction->menu() != nullptr) {
_newTabMenuAction->menu()->clear();
} else {
_newTabMenuAction->setMenu(new QMenu());
}
for (QAction *sessionAction : sessionActions) {
_newTabMenuAction->menu()->addAction(sessionAction);
auto setActionFontBold = [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 = KIconUtils::addOverlay(QIcon::fromTheme(profile->icon()), QIcon::fromTheme(QStringLiteral("emblem-favorite")), Qt::BottomRightCorner);
sessionAction->setIcon(icon);
setActionFontBold(true);
} else {
setActionFontBold(false);
}
}
} else {
if (_newTabMenuAction->menu() != nullptr) {
_newTabMenuAction->menu()->clear();
} else {
_newTabMenuAction->setMenu(new QMenu());
}
Profile::Ptr profile = ProfileManager::instance()->defaultProfile();
// Update the 'New Tab' KActionMenu
_newTabMenuAction->menu()->clear();
for (QAction *sessionAction : sessionActions) {
_newTabMenuAction->menu()->addAction(sessionAction);
// NOTE: Compare names w/o any '&'
if (sessionActions.size() == 2
&& sessionActions[1]->text().remove(QLatin1Char('&')) != profile->name()) {
_newTabMenuAction->menu()->addAction(sessionActions[1]);
auto setActionFontBold = [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 = KIconUtils::addOverlay(QIcon::fromTheme(profile->icon()), QIcon::fromTheme(QStringLiteral("emblem-favorite")), Qt::BottomRightCorner);
sessionAction->setIcon(icon);
setActionFontBold(true);
} else {
_newTabMenuAction->menu()->deleteLater();
setActionFontBold(false);
}
}
}
......
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