using System; using System.ComponentModel; using System.Collections.ObjectModel; using System.Collections.Generic; using System.Runtime.CompilerServices; namespace FooEditEngine { /// /// 補完候補を表すインターフェイス /// public interface ICompleteItem : INotifyPropertyChanged { /// /// 補完対象の単語を表す /// string word { get; } } /// /// 補完候補 /// public class CompleteWord : ICompleteItem { private string _word; /// /// コンストラクター /// public CompleteWord(string w) { this._word = w; this.PropertyChanged += new PropertyChangedEventHandler((s,e)=>{}); } /// /// 補完候補となる単語を表す /// public string word { get { return this._word; } set { this._word = value; this.OnPropertyChanged(); } } /// /// プロパティが変更されたことを通知する /// public void OnPropertyChanged([CallerMemberName] string name = "") { if (this.PropertyChanged != null) this.PropertyChanged(this, new PropertyChangedEventArgs(name)); } /// /// プロパティが変更されたことを通知する /// public event PropertyChangedEventHandler PropertyChanged; } /// /// 補完候補リスト /// /// ICompleteItemを継承したクラス public sealed class CompleteCollection : ObservableCollection where T : ICompleteItem { internal const string ShowMember = "word"; /// /// 補完対象の単語を表す /// public CompleteCollection() { this.LongestItem = default(T); } /// /// 最も長い単語を表す /// public T LongestItem { get; private set; } /// /// 補完候補を追加する /// /// public void AddRange(IEnumerable collection) { foreach (T s in collection) this.Add(s); } /// /// 補完候補を追加する /// /// public new void Add(T s) { if (this.LongestItem == null) this.LongestItem = s; if (s.word.Length > this.LongestItem.word.Length) this.LongestItem = s; base.Add(s); } /// /// 補完候補を挿入する /// /// /// public new void Insert(int index, T s) { if (this.LongestItem == null) this.LongestItem = s; if (s.word.Length > this.LongestItem.word.Length) this.LongestItem = s; base.Insert(index, s); } /// /// 補完候補をすべて削除する /// public new void Clear() { this.LongestItem = default(T); base.Clear(); } } }