/// <summary> /// KeyUp Event /// </summary> /// <param name="e">KeyEventArgs</param> protected override void OnPreviewKeyUp(KeyEventArgs e) { base.OnPreviewKeyUp(e); SetWordAtPointer(); SetLastWord(); KeyColourRun(); if ((_isAssistPredictOn == false) && (e.Key == Key.Space)) //need to know key is space so call in KeyUp { //save variable names, we for now will just add if last word has $ at the front if (_haveVariable) { if (!_variableNames.Contains(_lastWord)) { _variableNames.Add(_lastWord); } _predictKeyWord = "$"; } else { _predictKeyWord = _lastWord;//see what word we need to predict } var trigger = PredictTriggers.Where(s => s.Key == _predictKeyWord); if (trigger.Any()) { FilterAssistBoxItemsPredict((e.Key == Key.Space)); return; } } if ((_isAssistKeyWordOn == false) && ((_isAssistPredictOn == false) || _haveVariable) && !string.IsNullOrEmpty(_lastWord) && (e.Key != Key.Space)) { IEnumerable <string> match; if (_haveVariable) { match = _variableNames.Where(s => s.ToUpper().StartsWith(_lastWord.ToUpper())); } else { match = KeyWordSource.Where(s => s.ToUpper().StartsWith(_lastWord.ToUpper())); } if (match.Any()) { FilterAssistBoxItemsKeyWord((e.Key == Key.Space)); return; } } if (_isAssistKeyWordOn) { FilterAssistBoxItemsKeyWord((e.Key == Key.Space)); } else if (_isAssistPredictOn) { FilterAssistBoxItemsPredict((e.Key == Key.Space)); } }
/// <summary> /// Controller for the Predict list control /// </summary> /// <param name="haveSpace">bool</param> private void FilterAssistBoxItemsPredict(bool haveSpace) { #if DEBUG //Debug.Print("LastWord in FilterAssistBoxItemsPredict= {0}", _lastWord); #endif string srchLastWord = string.Empty; if (haveSpace) //takes care of backspacing back to a space to display options { _predictKeyWord = _lastWord; _lastWord = string.Empty; } else { srchLastWord = _lastWord; } IEnumerable <string> displayItems = PredictTriggers.Where(s => s.Key.ToUpper() == _predictKeyWord).SelectMany(s => s.Value).Where(s => s.ToUpper().StartsWith(srchLastWord) && (s.ToUpper() != _lastWord.ToUpper()) && (s.ToUpper() != _wordAtPointer)).OrderBy(s => s); List <string> sortedItems = displayItems.ToList(); sortedItems.Sort(); _assistListBox.ItemsSource = sortedItems; _assistListBox.ItemsSource = displayItems; _assistListBox.SelectedIndex = 0; if (displayItems.Count() == 0) { _assistListBox.Visibility = Visibility.Collapsed; _isAssistPredictOn = false; //OK no longer a predict so see if a keyword FilterAssistBoxItemsKeyWord(haveSpace); } else if (_assistListBox.Visibility != Visibility.Visible) { _isAssistPredictOn = true; _isAssistKeyWordOn = false; //override keyword if on ResetAssistListBoxLocation(); //set list box position _assistListBox.Visibility = Visibility.Visible; } }