Skip to content

Commit

Permalink
Implement searching of the game list. Fixes #39.
Browse files Browse the repository at this point in the history
  • Loading branch information
gibbed committed May 27, 2018
1 parent 16c552e commit 0958770
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions SAM.Picker/GamePicker.Designer.cs

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

49 changes: 49 additions & 0 deletions SAM.Picker/GamePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,55 @@ private void OnGameListViewRetrieveVirtualItem(object sender, RetrieveVirtualIte
};
}

private void OnGameListViewSearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e)
{
if (e.Direction != SearchDirectionHint.Down || e.IsTextSearch == false)
{
return;
}

var count = this._FilteredGames.Count;
if (count < 2)
{
return;
}

var text = e.Text.ToLowerInvariant();
int startIndex = e.StartIndex;

Predicate<GameInfo> predicate;
/*if (e.IsPrefixSearch == true)*/
{
predicate = gi => gi.Name != null && gi.Name.ToLowerInvariant().StartsWith(e.Text);
}
/*else
{
predicate = gi => gi.Name != null && gi.Name.ToLowerInvariant() == e.Text;
}*/

int index;
if (e.StartIndex >= count)
{
// starting from the last item in the list
index = this._FilteredGames.FindIndex(0, startIndex - 1, predicate);
}
else if (startIndex <= 0)
{
// starting from the first item in the list
index = this._FilteredGames.FindIndex(0, count, predicate);
}
else
{
index = this._FilteredGames.FindIndex(startIndex, count - startIndex, predicate);
if (index < 0)
{
index = this._FilteredGames.FindIndex(0, startIndex - 1, predicate);
}
}

e.Index = index < 0 ? -1 : index;
}

private void DoDownloadLogo(object sender, DoWorkEventArgs e)
{
var info = (GameInfo)e.Argument;
Expand Down

0 comments on commit 0958770

Please sign in to comment.