mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 12:57:35 +00:00
Settings: Make sure settings are listed in alphabetical order
DirectoryIterator, and so `Desktop::AppFile::for_each()`, doesn't guarantee anything about the order, so we manually sort afterwards. Which means using a manual version of NonnullRefPtrVector, since that doesn't support `quick_sort()`.
This commit is contained in:
parent
705b7fc407
commit
377a984905
1 changed files with 11 additions and 8 deletions
|
@ -4,6 +4,7 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/QuickSort.h>
|
||||||
#include <LibCore/Process.h>
|
#include <LibCore/Process.h>
|
||||||
#include <LibDesktop/AppFile.h>
|
#include <LibDesktop/AppFile.h>
|
||||||
#include <LibGUI/Application.h>
|
#include <LibGUI/Application.h>
|
||||||
|
@ -27,6 +28,7 @@ public:
|
||||||
return;
|
return;
|
||||||
m_apps.append(app_file);
|
m_apps.append(app_file);
|
||||||
});
|
});
|
||||||
|
quick_sort(m_apps, [](auto& a, auto& b) { return a->name() < b->name(); });
|
||||||
}
|
}
|
||||||
virtual int row_count(GUI::ModelIndex const&) const override { return m_apps.size(); }
|
virtual int row_count(GUI::ModelIndex const&) const override { return m_apps.size(); }
|
||||||
virtual int column_count(GUI::ModelIndex const&) const override { return 1; }
|
virtual int column_count(GUI::ModelIndex const&) const override { return 1; }
|
||||||
|
@ -42,25 +44,26 @@ public:
|
||||||
{
|
{
|
||||||
auto& app = m_apps[index.row()];
|
auto& app = m_apps[index.row()];
|
||||||
if (role == GUI::ModelRole::Icon) {
|
if (role == GUI::ModelRole::Icon) {
|
||||||
return app.icon();
|
return app->icon();
|
||||||
}
|
}
|
||||||
if (role == GUI::ModelRole::Display) {
|
if (role == GUI::ModelRole::Display) {
|
||||||
String name;
|
String name;
|
||||||
if (app.name().ends_with(" Settings"sv)) {
|
if (app->name().ends_with(" Settings"sv)) {
|
||||||
name = app.name().substring(0, app.name().length() - " Settings"sv.length());
|
name = app->name().substring(0, app->name().length() - " Settings"sv.length());
|
||||||
} else {
|
} else {
|
||||||
name = app.name();
|
name = app->name();
|
||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
if (role == GUI::ModelRole::Custom) {
|
if (role == GUI::ModelRole::Custom) {
|
||||||
return app.executable();
|
return app->executable();
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NonnullRefPtrVector<Desktop::AppFile> m_apps;
|
// NonnullRefPtrVector doesn't allow us to quick_sort() it, because its operator[] returns T&.
|
||||||
|
Vector<NonnullRefPtr<Desktop::AppFile>> m_apps;
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
|
@ -118,8 +121,8 @@ int main(int argc, char** argv)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& app = *(Desktop::AppFile*)index.internal_data();
|
auto& app = *(NonnullRefPtr<Desktop::AppFile>*)index.internal_data();
|
||||||
statusbar.set_text(app.description());
|
statusbar.set_text(app->description());
|
||||||
};
|
};
|
||||||
|
|
||||||
window->set_icon(app_icon.bitmap_for_size(16));
|
window->set_icon(app_icon.bitmap_for_size(16));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue