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

Clean up some more "favourite profile"-related code

- Since the favourite profile feature was removed in commit 28ba920c,
there is no need to sort profiles by menu index, this simlifies the code
some more.

- Remove Profile::menuIndexAsInt() method, now it's not used anywhere

- This also fixes an issue with sorting the the Default/fallback profile,
since commit ce31d0e2 it would be always sorted at the top of the
list (to signify that it's a special, read-only profile...etc), sorting
by menu index breaks that behaviour:
 - create a new profile by editing the Defualt/fallback profile, and give
   the new profile a name (Defualt is reserved of course)
 - open the profile manager dialog, you'll find the Default/fallback
   profile not at the top of the list, until you restart Konsole

This issue was reported by Kurt in
!351 (comment 197432)

(cherry picked from commit 646408dd)
parent 0d1d757d
......@@ -331,16 +331,6 @@ void Profile::registerProperty(const PropertyInfo& info)
}
}
int Profile::menuIndexAsInt() const
{
bool ok;
int index = menuIndex().toInt(&ok, 10);
if (ok) {
return index;
}
return 0;
}
const QStringList Profile::propertiesInfoList() const
{
QStringList info;
......
......@@ -731,8 +731,6 @@ public:
return QKeySequence::fromString(property<QString>(Profile::PeekPrimaryKeySequence));
}
int menuIndexAsInt() const;
/** Return a list of all properties names and their type
* (for use with -p option).
*/
......
......@@ -32,38 +32,11 @@
using namespace Konsole;
static bool profileIndexLessThan(const Profile::Ptr& p1, const Profile::Ptr& p2)
{
return p1->menuIndexAsInt() < p2->menuIndexAsInt();
}
static bool profileNameLessThan(const Profile::Ptr& p1, const Profile::Ptr& p2)
{
// Always put the Default/fallback profile at the top
if (p1->isFallback()) {
return true;
} else if (p2->isFallback()) {
return false;
}
return QString::localeAwareCompare(p1->name(), p2->name()) < 0;
}
static bool stringLessThan(const QString& p1, const QString& p2)
{
return QString::localeAwareCompare(p1, p2) < 0;
}
static void sortByIndexProfileList(QList<Profile::Ptr>& list)
{
std::stable_sort(list.begin(), list.end(), profileIndexLessThan);
}
static void sortByNameProfileList(QList<Profile::Ptr>& list)
{
std::stable_sort(list.begin(), list.end(), profileNameLessThan);
}
ProfileManager::ProfileManager()
: _profiles(QSet<Profile::Ptr>())
, _defaultProfile(nullptr)
......@@ -247,41 +220,17 @@ void ProfileManager::loadAllProfiles()
void ProfileManager::sortProfiles(QList<Profile::Ptr>& list)
{
QList<Profile::Ptr> lackingIndices;
QList<Profile::Ptr> havingIndices;
for (const auto & i : list) {
if (i->menuIndexAsInt() == 0) {
lackingIndices.append(i);
} else {
havingIndices.append(i);
// Sort alphabetically
std::stable_sort(list.begin(), list.end(), [](const Profile::Ptr &p1, const Profile::Ptr &p2) {
// Always put the Default/fallback profile at the top
if (p1->isFallback()) {
return true;
} else if (p2->isFallback()) {
return false;
}
}
// sort by index
sortByIndexProfileList(havingIndices);
// sort alphabetically those w/o an index
sortByNameProfileList(lackingIndices);
// Put those with indices in sequential order w/o any gaps
int i = 0;
for (i = 0; i < havingIndices.size(); ++i) {
Profile::Ptr tempProfile = havingIndices.at(i);
tempProfile->setProperty(Profile::MenuIndex, QString::number(i + 1));
havingIndices.replace(i, tempProfile);
}
// Put those w/o indices in sequential order
for (int j = 0; j < lackingIndices.size(); ++j) {
Profile::Ptr tempProfile = lackingIndices.at(j);
tempProfile->setProperty(Profile::MenuIndex, QString::number(j + 1 + i));
lackingIndices.replace(j, tempProfile);
}
// combine the 2 list: first those who had indices
list.clear();
list.append(havingIndices);
list.append(lackingIndices);
return QString::localeAwareCompare(p1->name(), p2->name()) < 0;
});
}
void ProfileManager::saveSettings()
......@@ -302,7 +251,7 @@ QList<Profile::Ptr> ProfileManager::allProfiles()
loadAllProfiles();
auto loadedProfiles = _profiles.values();
sortByNameProfileList(loadedProfiles);
sortProfiles(loadedProfiles);
return loadedProfiles;
}
......
......@@ -156,10 +156,9 @@ public:
Profile::Ptr fallbackProfile() const;
/**
* Sorts the profile list by menuindex; those without an menuindex, sort by name.
* The menuindex list is first and then the non-menuindex list.
* Sorts @p list of profiles alphabetically.
*
* @param list The profile list to sort
* @param list The profiles list to sort
*/
void sortProfiles(QList<Profile::Ptr> &list);
......
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