Skip to content

Commit

Permalink
Sort plugins in settings dialog alphabetically
Browse files Browse the repository at this point in the history
  • Loading branch information
radioactiveman authored and jlindgren90 committed Jan 21, 2024
1 parent b3dedb8 commit d8f5366
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/libaudcore/plugin-registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ static constexpr aud::array<InputKey, const char *> input_key_names = {

static aud::array<PluginType, Index<PluginHandle *>> plugins;
static aud::array<PluginType, Index<PluginHandle *>> compatible;
static aud::array<PluginType, Index<PluginHandle *>> sorted; /* by name */
static aud::mutex mutex;
static bool modified = false;

Expand Down Expand Up @@ -209,6 +210,9 @@ void plugin_registry_cleanup()

for (auto & list : compatible)
list.clear();

for (auto & list : sorted)
list.clear();
}

static void transport_plugin_parse(PluginHandle * plugin, TextParser & parser)
Expand Down Expand Up @@ -442,8 +446,14 @@ void plugin_registry_prune()
{
plugins[type].remove_if(check_not_found);
plugins[type].sort(plugin_compare);

compatible[type].insert(plugins[type].begin(), 0, plugins[type].len());
compatible[type].remove_if(check_incompatible);

sorted[type].insert(compatible[type].begin(), 0, compatible[type].len());
sorted[type].sort([](PluginHandle * a, PluginHandle * b) {
return str_compare(aud_plugin_get_name(a), aud_plugin_get_name(b));
});
}
}

Expand Down Expand Up @@ -623,6 +633,11 @@ EXPORT const Index<PluginHandle *> & aud_plugin_list(PluginType type)
return compatible[type];
}

EXPORT const Index<PluginHandle *> & aud_plugin_list_sorted(PluginType type)
{
return sorted[type];
}

EXPORT const char * aud_plugin_get_name(PluginHandle * plugin)
{
return dgettext(plugin->domain, plugin->name);
Expand Down
1 change: 1 addition & 0 deletions src/libaudcore/plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const void * aud_plugin_get_header(PluginHandle * plugin);
PluginHandle * aud_plugin_by_header(const void * header);

const Index<PluginHandle *> & aud_plugin_list(PluginType type);
const Index<PluginHandle *> & aud_plugin_list_sorted(PluginType type);

const char * aud_plugin_get_name(PluginHandle * plugin);
bool aud_plugin_has_about(PluginHandle * plugin);
Expand Down
2 changes: 1 addition & 1 deletion src/libaudgui/plugin-view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ static void list_fill (GtkTreeView * tree, void * type)
gtk_tree_view_column_pack_start (col, rend, false);
gtk_tree_view_column_set_attributes (col, rend, "text", PVIEW_COL_NAME, nullptr);

for (PluginHandle * plugin : aud_plugin_list (aud::from_ptr<PluginType> (type)))
for (PluginHandle * plugin : aud_plugin_list_sorted (aud::from_ptr<PluginType> (type)))
add_to_list (model, plugin);
}

Expand Down
2 changes: 1 addition & 1 deletion src/libaudqt/prefs-pluginlist-model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ QModelIndex PluginListModel::index(int row, int column,
if (cat < 0 || cat >= n_categories)
return QModelIndex();

auto & list = aud_plugin_list(categories[cat].type);
auto & list = aud_plugin_list_sorted(categories[cat].type);
if (row < 0 || row >= list.len())
return QModelIndex();

Expand Down

0 comments on commit d8f5366

Please sign in to comment.