mirror of
https://github.com/haven1433/HexManiacAdvance.git
synced 2026-05-18 19:16:46 -05:00
41 lines
1.4 KiB
C#
41 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
|
|
namespace HavenSoft.HexManiac.Core.ViewModels {
|
|
public class AutoCompleteSelectionItem : IEquatable<AutoCompleteSelectionItem>, INotifyPropertyChanged {
|
|
public string CompletionText { get; }
|
|
public bool IsSelected { get; }
|
|
|
|
#pragma warning disable 0067 // it's ok if events are never used after implementing an interface
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
#pragma warning restore 0067
|
|
|
|
public AutoCompleteSelectionItem(string text, bool selection) => (CompletionText, IsSelected) = (text, selection);
|
|
|
|
public static int SelectedIndex(IReadOnlyList<AutoCompleteSelectionItem> options) {
|
|
for (int i = 0; i < options.Count; i++) {
|
|
if (options[i].IsSelected) return i;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
public static IReadOnlyList<AutoCompleteSelectionItem> Generate(IEnumerable<string> options, int selectionIndex) {
|
|
var list = new List<AutoCompleteSelectionItem>();
|
|
|
|
int i = 0;
|
|
foreach (var option in options) {
|
|
list.Add(new AutoCompleteSelectionItem(option, i == selectionIndex));
|
|
i++;
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
public bool Equals(AutoCompleteSelectionItem other) {
|
|
if (other == null) return false;
|
|
return IsSelected == other.IsSelected && CompletionText == other.CompletionText;
|
|
}
|
|
}
|
|
}
|