Skip to content

Commit

Permalink
Merge #4270 Optimize label searches and handle spaces in names
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Dec 3, 2024
2 parents 670f5dc + 6aa6d21 commit c70b5cd
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 73 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ All notable changes to this project will be documented in this file.
- [Core] Exclude DLLs being upgraded to full modules (#4250 by: HebaruSan)
- [Core] Ignore manually installed duplicates of installed modules (#4257 by: HebaruSan)
- [Core] Exclude dependencies in the changeset from supported by list (#4261 by: HebaruSan)
- [GUI] Optimize label searches and handle spaces in names (#4270 by: HebaruSan)

### Internal

Expand Down
4 changes: 2 additions & 2 deletions GUI/Controls/EditModSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ private void ImmediateHandler(object? sender, EventArgs? e)
}
break;
}
if (Main.Instance?.CurrentInstance != null)
if (Main.Instance?.CurrentInstance is GameInstance inst)
{
// Sync the search boxes immediately
currentSearch = ModSearch.Parse(FilterCombinedTextBox.Text);
currentSearch = ModSearch.Parse(inst, FilterCombinedTextBox.Text);
}
SearchToEditor();
}
Expand Down
1 change: 1 addition & 0 deletions GUI/Controls/EditModSearchDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void SetFocus()

public ModSearch CurrentSearch()
=> new ModSearch(
Main.Instance!.CurrentInstance!,
FilterByNameTextBox.Text,
FilterByAuthorTextBox.Text.Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries).ToList(),
FilterByDescriptionTextBox.Text,
Expand Down
70 changes: 36 additions & 34 deletions GUI/Controls/ManageMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,18 @@ private void FilterLabelsToolButton_DropDown_Opening(object? sender, CancelEvent
if (currentInstance != null)
{
FilterLabelsToolButton.DropDownItems.Clear();
foreach (ModuleLabel mlbl in ModuleLabelList.ModuleLabels.LabelsFor(currentInstance.Name))
{
FilterLabelsToolButton.DropDownItems.Add(new ToolStripMenuItem(
$"{mlbl.Name} ({mlbl.ModuleCount(currentInstance.game)})",
null, customFilterButton_Click)
{
Tag = mlbl,
ToolTipText = Properties.Resources.FilterLinkToolTip,
});
}
FilterLabelsToolButton.DropDownItems.AddRange(
ModuleLabelList.ModuleLabels
.LabelsFor(currentInstance.Name)
.Select(mlbl => new ToolStripMenuItem(
$"{mlbl.Name} ({mlbl.ModuleCount(currentInstance.game)})",
null, customFilterButton_Click)
{
Tag = mlbl,
BackColor = mlbl.Color ?? Color.Transparent,
ToolTipText = Properties.Resources.FilterLinkToolTip,
})
.ToArray());
}
}

Expand Down Expand Up @@ -389,73 +391,73 @@ private void tagFilterButton_Click(object? sender, EventArgs? e)
{
var clicked = sender as ToolStripMenuItem;
var merge = ModifierKeys.HasAnyFlag(Keys.Control, Keys.Shift);
Filter(ModList.FilterToSavedSearch(GUIModFilter.Tag, clicked?.Tag as ModuleTag, null), merge);
Filter(ModList.FilterToSavedSearch(currentInstance!, GUIModFilter.Tag, clicked?.Tag as ModuleTag, null), merge);
}

private void customFilterButton_Click(object? sender, EventArgs? e)
{
var clicked = sender as ToolStripMenuItem;
var merge = ModifierKeys.HasAnyFlag(Keys.Control, Keys.Shift);
Filter(ModList.FilterToSavedSearch(GUIModFilter.CustomLabel, null, clicked?.Tag as ModuleLabel), merge);
Filter(ModList.FilterToSavedSearch(currentInstance!, GUIModFilter.CustomLabel, null, clicked?.Tag as ModuleLabel), merge);
}

private void FilterCompatibleButton_Click(object? sender, EventArgs? e)
{
var merge = ModifierKeys.HasAnyFlag(Keys.Control, Keys.Shift);
Filter(ModList.FilterToSavedSearch(GUIModFilter.Compatible), merge);
Filter(ModList.FilterToSavedSearch(currentInstance!, GUIModFilter.Compatible), merge);
}

private void FilterInstalledButton_Click(object? sender, EventArgs? e)
{
var merge = ModifierKeys.HasAnyFlag(Keys.Control, Keys.Shift);
Filter(ModList.FilterToSavedSearch(GUIModFilter.Installed), merge);
Filter(ModList.FilterToSavedSearch(currentInstance!, GUIModFilter.Installed), merge);
}

private void FilterInstalledUpdateButton_Click(object? sender, EventArgs? e)
{
var merge = ModifierKeys.HasAnyFlag(Keys.Control, Keys.Shift);
Filter(ModList.FilterToSavedSearch(GUIModFilter.InstalledUpdateAvailable), merge);
Filter(ModList.FilterToSavedSearch(currentInstance!, GUIModFilter.InstalledUpdateAvailable), merge);
}

private void FilterReplaceableButton_Click(object? sender, EventArgs? e)
{
var merge = ModifierKeys.HasAnyFlag(Keys.Control, Keys.Shift);
Filter(ModList.FilterToSavedSearch(GUIModFilter.Replaceable), merge);
Filter(ModList.FilterToSavedSearch(currentInstance!, GUIModFilter.Replaceable), merge);
}

private void FilterCachedButton_Click(object? sender, EventArgs? e)
{
var merge = ModifierKeys.HasAnyFlag(Keys.Control, Keys.Shift);
Filter(ModList.FilterToSavedSearch(GUIModFilter.Cached), merge);
Filter(ModList.FilterToSavedSearch(currentInstance!, GUIModFilter.Cached), merge);
}

private void FilterUncachedButton_Click(object? sender, EventArgs? e)
{
var merge = ModifierKeys.HasAnyFlag(Keys.Control, Keys.Shift);
Filter(ModList.FilterToSavedSearch(GUIModFilter.Uncached), merge);
Filter(ModList.FilterToSavedSearch(currentInstance!, GUIModFilter.Uncached), merge);
}

private void FilterNewButton_Click(object? sender, EventArgs? e)
{
var merge = ModifierKeys.HasAnyFlag(Keys.Control, Keys.Shift);
Filter(ModList.FilterToSavedSearch(GUIModFilter.NewInRepository), merge);
Filter(ModList.FilterToSavedSearch(currentInstance!, GUIModFilter.NewInRepository), merge);
}

private void FilterNotInstalledButton_Click(object? sender, EventArgs? e)
{
var merge = ModifierKeys.HasAnyFlag(Keys.Control, Keys.Shift);
Filter(ModList.FilterToSavedSearch(GUIModFilter.NotInstalled), merge);
Filter(ModList.FilterToSavedSearch(currentInstance!, GUIModFilter.NotInstalled), merge);
}

private void FilterIncompatibleButton_Click(object? sender, EventArgs? e)
{
var merge = ModifierKeys.HasAnyFlag(Keys.Control, Keys.Shift);
Filter(ModList.FilterToSavedSearch(GUIModFilter.Incompatible), merge);
Filter(ModList.FilterToSavedSearch(currentInstance!, GUIModFilter.Incompatible), merge);
}

private void FilterAllButton_Click(object? sender, EventArgs? e)
{
Filter(ModList.FilterToSavedSearch(GUIModFilter.All), false);
Filter(ModList.FilterToSavedSearch(currentInstance!, GUIModFilter.All), false);
}

/// <summary>
Expand All @@ -468,7 +470,7 @@ public void Filter(SavedSearch search, bool merge)
if (currentInstance != null)
{
var searches = search.Values
.Select(s => ModSearch.Parse(s))
.Select(s => ModSearch.Parse(currentInstance!, s))
.OfType<ModSearch>()
.ToList();

Expand Down Expand Up @@ -1501,25 +1503,25 @@ private bool _UpdateModsList(Dictionary<string, bool>? old_modules = null)
Util.Invoke(menuStrip2, () =>
{
FilterCompatibleButton.Text = string.Format(Properties.Resources.MainModListCompatible,
mainModList.CountModsByFilter(GUIModFilter.Compatible));
mainModList.CountModsByFilter(currentInstance, GUIModFilter.Compatible));
FilterInstalledButton.Text = string.Format(Properties.Resources.MainModListInstalled,
mainModList.CountModsByFilter(GUIModFilter.Installed));
mainModList.CountModsByFilter(currentInstance, GUIModFilter.Installed));
FilterInstalledUpdateButton.Text = string.Format(Properties.Resources.MainModListUpgradeable,
mainModList.CountModsByFilter(GUIModFilter.InstalledUpdateAvailable));
mainModList.CountModsByFilter(currentInstance, GUIModFilter.InstalledUpdateAvailable));
FilterReplaceableButton.Text = string.Format(Properties.Resources.MainModListReplaceable,
mainModList.CountModsByFilter(GUIModFilter.Replaceable));
mainModList.CountModsByFilter(currentInstance, GUIModFilter.Replaceable));
FilterCachedButton.Text = string.Format(Properties.Resources.MainModListCached,
mainModList.CountModsByFilter(GUIModFilter.Cached));
mainModList.CountModsByFilter(currentInstance, GUIModFilter.Cached));
FilterUncachedButton.Text = string.Format(Properties.Resources.MainModListUncached,
mainModList.CountModsByFilter(GUIModFilter.Uncached));
mainModList.CountModsByFilter(currentInstance, GUIModFilter.Uncached));
FilterNewButton.Text = string.Format(Properties.Resources.MainModListNewlyCompatible,
mainModList.CountModsByFilter(GUIModFilter.NewInRepository));
mainModList.CountModsByFilter(currentInstance, GUIModFilter.NewInRepository));
FilterNotInstalledButton.Text = string.Format(Properties.Resources.MainModListNotInstalled,
mainModList.CountModsByFilter(GUIModFilter.NotInstalled));
mainModList.CountModsByFilter(currentInstance, GUIModFilter.NotInstalled));
FilterIncompatibleButton.Text = string.Format(Properties.Resources.MainModListIncompatible,
mainModList.CountModsByFilter(GUIModFilter.Incompatible));
mainModList.CountModsByFilter(currentInstance, GUIModFilter.Incompatible));
FilterAllButton.Text = string.Format(Properties.Resources.MainModListAll,
mainModList.CountModsByFilter(GUIModFilter.All));
mainModList.CountModsByFilter(currentInstance, GUIModFilter.All));

UpdateAllToolButton.Enabled = has_unheld_updates;
});
Expand Down Expand Up @@ -1851,7 +1853,7 @@ private void hiddenTagsLabelsLinkList_TagClicked(ModuleTag tag, bool merge)

private void hiddenTagsLabelsLinkList_LabelClicked(ModuleLabel label, bool merge)
{
Filter(ModList.FilterToSavedSearch(GUIModFilter.CustomLabel, null, label),
Filter(ModList.FilterToSavedSearch(currentInstance!, GUIModFilter.CustomLabel, null, label),
merge);
}

Expand Down
6 changes: 4 additions & 2 deletions GUI/Controls/ModInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,14 @@ private void UpdateTagsAndLabels(CkanModule mod)


private void tagsLabelsLinkList_TagClicked(ModuleTag tag, bool merge)
=> OnChangeFilter?.Invoke(ModList.FilterToSavedSearch(GUIModFilter.Tag,
=> OnChangeFilter?.Invoke(ModList.FilterToSavedSearch(Main.Instance!.CurrentInstance!,
GUIModFilter.Tag,
tag, null),
merge);

private void tagsLabelsLinkList_LabelClicked(ModuleLabel label, bool merge)
=> OnChangeFilter?.Invoke(ModList.FilterToSavedSearch(GUIModFilter.CustomLabel,
=> OnChangeFilter?.Invoke(ModList.FilterToSavedSearch(Main.Instance!.CurrentInstance!,
GUIModFilter.CustomLabel,
null, label),
merge);

Expand Down
3 changes: 2 additions & 1 deletion GUI/Controls/ModInfoTabs/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ private void OnAuthorClick(object? sender, LinkLabelLinkClickedEventArgs? e)
new SavedSearch()
{
Name = string.Format(Properties.Resources.AuthorSearchName, author),
Values = Enumerable.Repeat(ModSearch.FromAuthors(Enumerable.Repeat(author, 1)).Combined, 1)
Values = Enumerable.Repeat(ModSearch.FromAuthors(Main.Instance!.CurrentInstance!,
Enumerable.Repeat(author, 1)).Combined, 1)
.OfType<string>()
.ToList(),
},
Expand Down
3 changes: 2 additions & 1 deletion GUI/Main/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ private void SetupDefaultSearch()
// Fall back to old setting
ManageMods.Filter(
ModList.FilterToSavedSearch(
CurrentInstance,
(GUIModFilter)configuration.ActiveFilter,
configuration.TagFilter == null
? null
Expand All @@ -678,7 +679,7 @@ private void SetupDefaultSearch()
}
else
{
var searches = def.Select(s => ModSearch.Parse(s))
var searches = def.Select(s => ModSearch.Parse(CurrentInstance, s))
.OfType<ModSearch>()
.ToList();
ManageMods.SetSearches(searches);
Expand Down
23 changes: 13 additions & 10 deletions GUI/Main/MainTrayIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,20 @@ private void UpdateTrayState()

private void UpdateTrayInfo()
{
var count = ManageMods.mainModList.CountModsByFilter(GUIModFilter.InstalledUpdateAvailable);

if (count == 0)
{
updatesToolStripMenuItem.Enabled = false;
updatesToolStripMenuItem.Text = Properties.Resources.MainTrayNoUpdates;
}
else
if (CurrentInstance != null)
{
updatesToolStripMenuItem.Enabled = true;
updatesToolStripMenuItem.Text = string.Format(Properties.Resources.MainTrayUpdatesAvailable, count);
var count = ManageMods.mainModList.CountModsByFilter(CurrentInstance,
GUIModFilter.InstalledUpdateAvailable);
if (count == 0)
{
updatesToolStripMenuItem.Enabled = false;
updatesToolStripMenuItem.Text = Properties.Resources.MainTrayNoUpdates;
}
else
{
updatesToolStripMenuItem.Enabled = true;
updatesToolStripMenuItem.Text = string.Format(Properties.Resources.MainTrayUpdatesAvailable, count);
}
}
toolStripSeparator4.Visible = true;
updatesToolStripMenuItem.Visible = true;
Expand Down
9 changes: 5 additions & 4 deletions GUI/Model/ModList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,14 @@ private static string FilterName(GUIModFilter filter,
return "";
}

public static SavedSearch FilterToSavedSearch(GUIModFilter filter,
public static SavedSearch FilterToSavedSearch(GameInstance instance,
GUIModFilter filter,
ModuleTag? tag = null,
ModuleLabel? label = null)
=> new SavedSearch()
{
Name = FilterName(filter, tag, label),
Values = new List<string>() { new ModSearch(filter, tag, label).Combined ?? "" },
Values = new List<string>() { new ModSearch(instance, filter, tag, label).Combined ?? "" },
};

private static RelationshipResolverOptions conflictOptions(StabilityToleranceConfig stabilityTolerance)
Expand Down Expand Up @@ -277,8 +278,8 @@ private bool HiddenByTagsOrLabels(GUIMod m, string instanceName, IGame game, Reg
public int CountModsBySearches(List<ModSearch> searches)
=> Modules.Count(mod => searches?.Any(s => s?.Matches(mod) ?? true) ?? true);

public int CountModsByFilter(GUIModFilter filter)
=> CountModsBySearches(new List<ModSearch>() { new ModSearch(filter, null, null) });
public int CountModsByFilter(GameInstance inst, GUIModFilter filter)
=> CountModsBySearches(new List<ModSearch>() { new ModSearch(inst, filter, null, null) });

/// <summary>
/// Constructs the mod list suitable for display to the user.
Expand Down
Loading

0 comments on commit c70b5cd

Please sign in to comment.