/// <summary> /// Find entities matching the entered text /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void btnGo_Click(object sender, RoutedEventArgs e) { if (tokens == null || tokens.Count == 0) { return; } if (txtFindID.Text.Trim().Length == 0) { if (matchEnumerator != null) { matchEnumerator.Dispose(); matchEnumerator = null; } return; } txtFindID.Text = txtFindID.Text.Trim(); // If this is the first time, get all matches if (matchEnumerator == null) { matchEnumerator = tokens.Find(t => (!String.IsNullOrEmpty(t.TokenName) && t.TokenName.IndexOf(txtFindID.Text, StringComparison.CurrentCultureIgnoreCase) != -1) || (!String.IsNullOrEmpty(t.TokenValue) && t.TokenValue.IndexOf(txtFindID.Text, StringComparison.CurrentCultureIgnoreCase) != -1)).GetEnumerator(); } // Move to the next match if (matchEnumerator.MoveNext()) { matchEnumerator.Current.IsSelected = true; lbTokens.ScrollIntoView(matchEnumerator.Current); } else { if (matchEnumerator != null) { matchEnumerator.Dispose(); matchEnumerator = null; } MessageBox.Show("No more matches found", "Token Editor", MessageBoxButton.OK, MessageBoxImage.Information); } }
//===================================================================== /// <summary> /// Load a token file for editing /// </summary> /// <param name="tokenFile">The token file to load</param> /// <param name="selectedToken">The token ID to select by default or null if no selection</param> public void LoadTokenFile(string tokenFile, string selectedToken) { if (tokenFile == null) { throw new ArgumentNullException("tokenFile", "A token filename must be specified"); } tokens = new TokenCollection(tokenFile); tokens.Load(); tokens.ListChanged += new ListChangedEventHandler(tokens_ListChanged); if (tokens.Count != 0) { if (selectedToken == null) { tokens[0].IsSelected = true; } else { var match = tokens.Find(t => t.TokenName == selectedToken).FirstOrDefault(); if (match != null) { match.IsSelected = true; } else { tokens[0].IsSelected = true; } } } lbTokens.ItemsSource = tokens; this.tokens_ListChanged(this, new ListChangedEventArgs(ListChangedType.Reset, -1)); }
//===================================================================== /// <summary> /// Load a token file for editing /// </summary> /// <param name="tokenFile">The token file to load</param> /// <param name="selectedToken">The token ID to select by default or null if no selection</param> public void LoadTokenFile(string tokenFile, string selectedToken) { if(tokenFile == null) throw new ArgumentNullException("tokenFile", "A token filename must be specified"); tokens = new TokenCollection(tokenFile); tokens.Load(); tokens.ListChanged += new ListChangedEventHandler(tokens_ListChanged); if(tokens.Count != 0) if(selectedToken == null) tokens[0].IsSelected = true; else { var match = tokens.Find(t => t.TokenName == selectedToken).FirstOrDefault(); if(match != null) match.IsSelected = true; else tokens[0].IsSelected = true; } lbTokens.ItemsSource = tokens; this.tokens_ListChanged(this, new ListChangedEventArgs(ListChangedType.Reset, -1)); }