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

Search by supports relationship and other search improvements #3939

Merged
merged 6 commits into from
Dec 11, 2023
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
5 changes: 3 additions & 2 deletions Core/Games/IGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public interface IGame
string[] BuildIDFiles { get; }

// How to get metadata
Uri DefaultRepositoryURL { get; }
Uri RepositoryListURL { get; }
Uri DefaultRepositoryURL { get; }
Uri RepositoryListURL { get; }
Uri MetadataBugtrackerURL { get; }
}
}
2 changes: 2 additions & 0 deletions Core/Games/KerbalSpaceProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ public GameVersion DetectVersion(DirectoryInfo where)

public Uri RepositoryListURL => new Uri("https://raw.githubusercontent.com/KSP-CKAN/CKAN-meta/master/repositories.json");

public Uri MetadataBugtrackerURL => new Uri("https://github.com/KSP-CKAN/NetKAN/issues/new/choose");

private string Missions(GameInstance inst)
=> CKANPathUtils.NormalizePath(Path.Combine(inst.GameDir(), "Missions"));

Expand Down
2 changes: 2 additions & 0 deletions Core/Games/KerbalSpaceProgram2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ private GameVersion VersionFromFile(string path)

public Uri RepositoryListURL => new Uri("https://raw.githubusercontent.com/KSP-CKAN/KSP2-CKAN-meta/main/repositories.json");

public Uri MetadataBugtrackerURL => new Uri("https://github.com/KSP-CKAN/KSP2-NetKAN/issues/new/choose");

// Key: Allowed value of install_to
// Value: Relative path
// (PrimaryModDirectoryRelative is allowed implicitly)
Expand Down
98 changes: 28 additions & 70 deletions GUI/Controls/EditModSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,29 @@ public bool ShowLabel
}
}

public void CloseSearch(Point screenCoords)
{
// Treat the entire main window as an uncheck button, and let
// the actual checkbox handle unchecking itself
var bounds = new Rectangle(ExpandButton.PointToScreen(new Point(0, 0)),
ExpandButton.Size);
if (!bounds.Contains(screenCoords))
{
ExpandButton.Checked = false;
}
}

public void ParentMoved()
{
FormGeometryChanged();
}

protected override void OnResize(EventArgs e)
{
base.OnResize(e);
FormGeometryChanged();
}

private bool suppressSearch = false;
private ModSearch currentSearch = null;

Expand Down Expand Up @@ -174,25 +197,15 @@ private void ExpandButton_CheckedChanged(object sender, EventArgs e)

private void DoLayout(bool expanded)
{
FormGeometryChanged(null, null);
FormGeometryChanged();
SearchDetails.Visible = expanded;
if (SearchDetails.Visible)
{
SearchDetails.FilterByNameTextBox.Focus();
if (Main.Instance != null)
{
Main.Instance.Move += FormGeometryChanged;
Resize += FormGeometryChanged;
}
}
else if (Main.Instance != null)
{
Main.Instance.Move -= FormGeometryChanged;
Resize -= FormGeometryChanged;
SearchDetails.SetFocus();
}
}

private void FormGeometryChanged(object sender, EventArgs e)
private void FormGeometryChanged()
{
SearchDetails.Location = PointToScreen(new Point(
FilterCombinedTextBox.Left,
Expand All @@ -207,73 +220,18 @@ private void FormGeometryChanged(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;
SearchDetails.PopulateSearch(currentSearch);
suppressSearch = false;
}

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

private void SearchDetails_ApplySearch(object sender, EventArgs e)
{
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.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToList(),
SearchDetails.FilterByDescriptionTextBox.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
);
currentSearch = SearchDetails.CurrentSearch();
suppressSearch = true;
FilterCombinedTextBox.Text = currentSearch?.Combined ?? "";
suppressSearch = false;
Expand Down
Loading
Loading