private void TextBox_TextChanged(object sender, TextChangedEventArgs e) { var newinfo = new cTaskInfo(); var oldinfo = System.Threading.Interlocked.Exchange(ref mTaskInfo, newinfo); bool refresh = true; newinfo.mPattern = inputTextBox.Text.ToLowerInvariant(); if (oldinfo != null) { oldinfo.mTokenSource.Cancel(); if (oldinfo.mDone && newinfo.mPattern.StartsWith(oldinfo.mPattern)) { newinfo.mSuggestions = oldinfo.mSuggestions; refresh = false; } } if (refresh) { UInt64 mask = cProjectItemWithMask.sGetMask(inputTextBox.Text); if (newinfo.mSuggestions != null) { newinfo.mSuggestions.Clear(); } else { newinfo.mSuggestions = new System.Collections.Generic.List <cSuggestion>(); } foreach (var pi in mAllItems) { if ((pi.mMask & mask) == mask) { newinfo.mSuggestions.Add(new cSuggestion(0, 0, pi.mItem)); } } if (newinfo.mPattern.Length <= 1) // no point in doing more complicated fuzzing { fileNamesGrid.ItemsSource = newinfo.mSuggestions.GetRange(0, Math.Min(10, newinfo.mSuggestions.Count)); fileNamesGrid.SelectedItem = null; fileNamesGrid.SelectedIndex = 0; newinfo.mDone = true; return; } } var token = newinfo.mTokenSource.Token; System.Threading.Tasks.Task.Run(() => mGetSuggestions(newinfo, this, token), newinfo.mTokenSource.Token); }
private static void mGetSuggestions(cTaskInfo info, TestWindow w, System.Threading.CancellationToken token) { var ret = new System.Collections.Generic.List <cSuggestion>(); for (int i = 0; i < info.mSuggestions.Count; ++i) { if (token.IsCancellationRequested) { return; } var sug = info.mSuggestions[i]; if (mGetMatch(info.mPattern, sug)) { ret.Add(sug); } } ret.Sort(); info.mSuggestions = ret; info.mDone = true; w.mUpdateSuggestions(info.mPattern, ret); }