Skip to content

Commit

Permalink
Sort by enabled and name
Browse files Browse the repository at this point in the history
  • Loading branch information
Tharylia committed Sep 25, 2024
1 parent 1113d79 commit d6cf600
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 10 additions & 6 deletions Blish HUD/GameServices/ModuleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,15 @@ private void Gw2Instance_Gw2Started(object sender, EventArgs e) {
private readonly Dictionary<MenuItem, ModuleManager> _moduleMenus = new Dictionary<MenuItem, ModuleManager>();

private IOrderedEnumerable<KeyValuePair<MenuItem, ModuleManager>> GetSortedMenuItems() {
return _moduleMenus.OrderBy(c => c.Value.Manifest.Name);
return _moduleMenus.OrderByDescending(c => c.Value.Enabled).ThenBy(c => c.Value.Manifest.Name);
}

internal void SortMenuItems() {
_rootModuleSettingsMenuItem.ClearChildren();

foreach (var menuItemPair in this.GetSortedMenuItems()) {
menuItemPair.Key.Parent = _rootModuleSettingsMenuItem;
}
}

private void RegisterModuleMenuInSettings(ModuleManager moduleManager) {
Expand All @@ -338,11 +346,7 @@ private void RegisterModuleMenuInSettings(ModuleManager moduleManager) {

_moduleMenus.Add(moduleMi, moduleManager);

_rootModuleSettingsMenuItem.ClearChildren();

foreach (var menuItemPair in this.GetSortedMenuItems()) {
menuItemPair.Key.Parent = _rootModuleSettingsMenuItem;
}
this.SortMenuItems();
}

private void UnregisterModuleMenuInSettings(ModuleManager moduleManager) {
Expand Down
4 changes: 4 additions & 0 deletions Blish HUD/GameServices/Modules/ModuleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public bool TryEnable() {
this.State.Enabled = this.Enabled;
GameService.Settings.Save();

GameService.Module.SortMenuItems();

return this.Enabled;
}

Expand Down Expand Up @@ -142,6 +144,8 @@ public void Disable() {

this.State.Enabled = this.Enabled;
GameService.Settings.Save();

GameService.Module.SortMenuItems();
}

public void DeleteModule() {
Expand Down

0 comments on commit d6cf600

Please sign in to comment.