impr: Sort View menu alphabetically

This commit is contained in:
WerWolv
2025-08-31 11:22:40 +02:00
parent 06ac7eb85f
commit fe4cb8575f

View File

@@ -551,13 +551,25 @@ namespace hex::plugin::builtin {
#endif
ContentRegistry::UserInterface::addMenuItemSubMenu({ "hex.builtin.menu.view" }, 4000, [] {
for (auto &[name, view] : ContentRegistry::Views::impl::getEntries()) {
if (view->hasViewMenuItemEntry()) {
auto &state = view->getWindowOpenState();
if (menu::menuItemEx(Lang(view->getUnlocalizedName()), view->getIcon(), Shortcut::None, state, ImHexApi::Provider::isValid() && !LayoutManager::isLayoutLocked()))
state = !state;
auto getSortedViews = [] {
std::vector<std::pair<std::string, View*>> views;
for (auto &[name, view] : ContentRegistry::Views::impl::getEntries()) {
if (view->hasViewMenuItemEntry())
views.emplace_back(name, view.get());
}
std::ranges::sort(views, [](const auto &a, const auto &b) {
return std::string_view(Lang(a.first)) < std::string_view(Lang(b.first));
});
return views;
};
for (auto &[name, view] : getSortedViews()) {
auto &state = view->getWindowOpenState();
if (menu::menuItemEx(Lang(name), view->getIcon(), Shortcut::None, state, ImHexApi::Provider::isValid() && !LayoutManager::isLayoutLocked()))
state = !state;
}
});