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

Always sort the profiles by name in 'File -> New Tab'

With the Fallback profile always sorted at the top.

(cherry picked from commit 1f480e36)
parent b297d591
......@@ -17,6 +17,8 @@
// Konsole
#include "ProfileManager.h"
#include <algorithm>
using Konsole::Profile;
using Konsole::ProfileList;
......@@ -88,7 +90,7 @@ void ProfileList::updateAction(QAction* action , Profile::Ptr profile)
action->setText(profile->name());
action->setIcon(QIcon::fromTheme(profile->icon()));
Q_EMIT actionsChanged(_group->actions());
Q_EMIT actionsChanged(actions());
}
void ProfileList::shortcutChanged(const Profile::Ptr &profile, const QKeySequence& sequence)
{
......@@ -116,7 +118,7 @@ void ProfileList::syncWidgetActions(QWidget* widget, bool sync)
widget->removeAction(currentAction);
}
widget->addActions(_group->actions());
widget->addActions(actions());
}
void ProfileList::addShortcutAction(const Profile::Ptr &profile)
......@@ -135,7 +137,7 @@ void ProfileList::addShortcutAction(const Profile::Ptr &profile)
for (QWidget *widget : qAsConst(_registeredWidgets)) {
widget->addAction(action);
}
Q_EMIT actionsChanged(_group->actions());
Q_EMIT actionsChanged(actions());
updateEmptyAction();
}
......@@ -149,7 +151,7 @@ void ProfileList::removeShortcutAction(const Profile::Ptr &profile)
for (QWidget *widget : qAsConst(_registeredWidgets)) {
widget->removeAction(action);
}
Q_EMIT actionsChanged(_group->actions());
Q_EMIT actionsChanged(actions());
}
updateEmptyAction();
}
......@@ -161,6 +163,20 @@ void ProfileList::triggered(QAction* action)
QList<QAction*> ProfileList::actions()
{
return _group->actions();
}
auto actionsList = _group->actions();
std::sort(actionsList.begin(), actionsList.end(), [](QAction *a, QAction *b) {
// Remove '&', which is added by KAcceleratorManager
const QString aName = a->text().remove(QLatin1Char('&'));
const QString bName = b->text().remove(QLatin1Char('&'));
if (aName == QLatin1String("Default")) {
return true;
} else if (bName == QLatin1String("Default")) {
return false;
}
return QString::localeAwareCompare(aName, bName) < 0;
});
return actionsList;
}
......@@ -48,9 +48,10 @@ public:
ProfileList(bool addShortcuts, QObject *parent);
/**
* Returns a list of actions representing profiles
* Returns a list of actions representing profiles, sorted by profile
* name.
*
* The user-data associated with each action is the corresponding profile
* The user-data associated with each action is the corresponding profile.
*/
QList<QAction *> actions();
......
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