Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort module menu items #985

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions Blish HUD/GameServices/ModuleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,27 @@ private void Gw2Instance_Gw2Started(object sender, EventArgs e) {

private MenuItem _rootModuleSettingsMenuItem;
private readonly Dictionary<MenuItem, ModuleManager> _moduleMenus = new Dictionary<MenuItem, ModuleManager>();

private IOrderedEnumerable<KeyValuePair<MenuItem, ModuleManager>> GetSortedMenuItems() {
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) {
var moduleMi = new ModuleMenuItem(moduleManager) {
BasicTooltipText = moduleManager.Manifest.Description,
Parent = _rootModuleSettingsMenuItem
BasicTooltipText = moduleManager.Manifest.Description
};

_moduleMenus.Add(moduleMi, moduleManager);

this.SortMenuItems();
}

private void UnregisterModuleMenuInSettings(ModuleManager moduleManager) {
Expand All @@ -342,7 +355,7 @@ private void UnregisterModuleMenuInSettings(ModuleManager moduleManager) {
_moduleMenus.Remove(moduleMenuPair.Key);

MenuItem toSelect = moduleMenuPair.Key.Selected
? _moduleMenus.FirstOrDefault().Key ?? _rootModuleSettingsMenuItem
? this.GetSortedMenuItems().FirstOrDefault().Key ?? _rootModuleSettingsMenuItem
: null;

moduleMenuPair.Key.Parent = null;
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
Loading