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

Multiple search boxes with OR logic in GUI #3323

Merged
merged 7 commits into from
Apr 24, 2021
Merged
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
9 changes: 9 additions & 0 deletions GUI/CKAN-GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@
<Compile Include="Controls\ModInfo.Designer.cs">
<DependentUpon>ModInfo.cs</DependentUpon>
</Compile>
<Compile Include="Controls\EditModSearches.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Controls\EditModSearches.Designer.cs">
<DependentUpon>EditModSearches.cs</DependentUpon>
</Compile>
<Compile Include="Controls\EditModSearch.cs">
<SubType>UserControl</SubType>
</Compile>
Expand Down Expand Up @@ -226,6 +232,9 @@
<Compile Include="Controls\TransparentTextBox.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\TriStateToggle.cs">
<SubType>Component</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="Model\GUIConfiguration.cs" />
Expand Down
23 changes: 19 additions & 4 deletions GUI/Controls/EditModSearch.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

110 changes: 87 additions & 23 deletions GUI/Controls/EditModSearch.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Timer = System.Windows.Forms.Timer;
Expand All @@ -21,7 +22,7 @@ public EditModSearch()
{
InitializeComponent();

this.ToolTip.SetToolTip(ExpandButton, Properties.Resources.EditModSearchTooltipExpandButton);
ToolTip.SetToolTip(ExpandButton, Properties.Resources.EditModSearchTooltipExpandButton);

// TextBox resizes unpredictably at runtime, so we need special logic
// to line up the button with it
Expand All @@ -48,13 +49,33 @@ public void ExpandCollapse()
/// <summary>
/// Event fired when a search needs to be executed.
/// </summary>
public event Action<ModSearch> ApplySearch;
public event Action<EditModSearch, ModSearch> ApplySearch;

/// <summary>
/// Event fired when user wants to switch focus away from this control.
/// </summary>
public event Action SurrenderFocus;

public ModSearch Search
{
get => currentSearch;
set
{
currentSearch = value;
SearchToEditor();
FilterCombinedTextBox.Text = currentSearch?.Combined ?? "";
}
}

public bool ShowLabel
{
set
{
FilterCombinedLabel.Visible = value;
FilterOrLabel.Visible = !value;
}
}

private static readonly ILog log = LogManager.GetLogger(typeof(EditModSearch));
private Timer filterTimer;
private bool suppressSearch = false;
Expand Down Expand Up @@ -105,17 +126,10 @@ private void FilterCombinedTextBox_TextChanged(object sender, EventArgs e)

try
{
currentSearch = ModSearch.Parse(FilterCombinedTextBox.Text);
suppressSearch = true;
SearchDetails.FilterByNameTextBox.Text = currentSearch?.Name ?? "";
SearchDetails.FilterByAuthorTextBox.Text = currentSearch?.Author ?? "";
SearchDetails.FilterByDescriptionTextBox.Text = currentSearch?.Description ?? "";
SearchDetails.FilterByLanguageTextBox.Text = currentSearch?.Localization ?? "";
SearchDetails.FilterByDependsTextBox.Text = currentSearch?.DependsOn ?? "";
SearchDetails.FilterByRecommendsTextBox.Text = currentSearch?.Recommends ?? "";
SearchDetails.FilterByConflictsTextBox.Text = currentSearch?.ConflictsWith ?? "";
SearchDetails.FilterBySuggestsTextBox.Text = currentSearch?.Suggests ?? "";
suppressSearch = false;
currentSearch = ModSearch.Parse(FilterCombinedTextBox.Text,
Main.Instance.ManageMods.mainModList.ModuleLabels.LabelsFor(Main.Instance.CurrentInstance.Name).ToList()
);
SearchToEditor();
TriggerSearchOrTimer();
}
catch (Kraken k)
Expand All @@ -124,20 +138,73 @@ private void FilterCombinedTextBox_TextChanged(object sender, EventArgs e)
}
}

private void SearchToEditor()
{
suppressSearch = true;
SearchDetails.FilterByNameTextBox.Text = currentSearch?.Name
?? "";
SearchDetails.FilterByAuthorTextBox.Text = currentSearch?.Authors.Aggregate("", combinePieces)
?? "";
SearchDetails.FilterByDescriptionTextBox.Text = currentSearch?.Description
?? "";
SearchDetails.FilterByLanguageTextBox.Text = currentSearch?.Localizations.Aggregate("", combinePieces)
?? "";
SearchDetails.FilterByDependsTextBox.Text = currentSearch?.DependsOn.Aggregate("", combinePieces)
?? "";
SearchDetails.FilterByRecommendsTextBox.Text = currentSearch?.Recommends.Aggregate("", combinePieces)
?? "";
SearchDetails.FilterByConflictsTextBox.Text = currentSearch?.ConflictsWith.Aggregate("", combinePieces)
?? "";
SearchDetails.FilterBySuggestsTextBox.Text = currentSearch?.Suggests.Aggregate("", combinePieces)
?? "";
SearchDetails.FilterByTagsTextBox.Text = currentSearch?.TagNames.Aggregate("", combinePieces)
?? "";
SearchDetails.FilterByLabelsTextBox.Text = currentSearch?.Labels
.Select(lb => lb.Name)
.Aggregate("", combinePieces)
?? "";

SearchDetails.CompatibleToggle.Value = currentSearch?.Compatible;
SearchDetails.InstalledToggle.Value = currentSearch?.Installed;
SearchDetails.CachedToggle.Value = currentSearch?.Cached;
SearchDetails.NewlyCompatibleToggle.Value = currentSearch?.NewlyCompatible;
SearchDetails.UpgradeableToggle.Value = currentSearch?.Upgradeable;
SearchDetails.ReplaceableToggle.Value = currentSearch?.Replaceable;
suppressSearch = false;
}

private static string combinePieces(string joined, string piece)
{
return string.IsNullOrEmpty(joined) ? piece : $"{joined} {piece}";
}

private void SearchDetails_ApplySearch(bool immediately)
{
if (suppressSearch)
return;

var knownLabels = Main.Instance.ManageMods.mainModList.ModuleLabels.LabelsFor(Main.Instance.CurrentInstance.Name).ToList();

currentSearch = new ModSearch(
SearchDetails.FilterByNameTextBox.Text,
SearchDetails.FilterByAuthorTextBox.Text,
SearchDetails.FilterByAuthorTextBox.Text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToList(),
SearchDetails.FilterByDescriptionTextBox.Text,
SearchDetails.FilterByLanguageTextBox.Text,
SearchDetails.FilterByDependsTextBox.Text,
SearchDetails.FilterByRecommendsTextBox.Text,
SearchDetails.FilterBySuggestsTextBox.Text,
SearchDetails.FilterByConflictsTextBox.Text
SearchDetails.FilterByLanguageTextBox.Text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToList(),
SearchDetails.FilterByDependsTextBox.Text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToList(),
SearchDetails.FilterByRecommendsTextBox.Text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToList(),
SearchDetails.FilterBySuggestsTextBox.Text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToList(),
SearchDetails.FilterByConflictsTextBox.Text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToList(),
SearchDetails.FilterByTagsTextBox.Text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToList(),
SearchDetails.FilterByLabelsTextBox.Text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries)
.Select(ln => knownLabels.FirstOrDefault(lb => lb.Name == ln))
.Where(lb => lb != null)
.ToList(),
SearchDetails.CompatibleToggle.Value,
SearchDetails.InstalledToggle.Value,
SearchDetails.CachedToggle.Value,
SearchDetails.NewlyCompatibleToggle.Value,
SearchDetails.UpgradeableToggle.Value,
SearchDetails.ReplaceableToggle.Value
);
suppressSearch = true;
FilterCombinedTextBox.Text = currentSearch?.Combined ?? "";
Expand Down Expand Up @@ -242,10 +309,7 @@ private void OnFilterUpdateTimer(object source, EventArgs e)

private void TriggerSearch()
{
if (ApplySearch != null)
{
ApplySearch(currentSearch);
}
ApplySearch?.Invoke(this, currentSearch);
}

}
Expand Down
1 change: 1 addition & 0 deletions GUI/Controls/EditModSearch.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,5 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="FilterCombinedLabel.Text" xml:space="preserve"><value>Search:</value></data>
<data name="FilterOrLabel.Text" xml:space="preserve"><value>Or:</value></data>
</root>
Loading