private void reloadTokens() { MatchCollection matches = Regex.Matches(box.Text, "<[^>]+>"); currentTokens = new Dictionary<string, SearchToken>(); foreach (Match match in matches) { String[] token = match.Value.Split(new char[] { ':' }, 2); string key = token[0].TrimStart('<'); string value = token[1].TrimEnd('>'); SearchToken searchToken = new SearchToken(); searchToken.Text = match.Value; searchToken.Start = match.Index; searchToken.End = match.Index + match.Length; searchToken.Closed = true; currentTokens.Add(key, searchToken); } }
private SearchToken currentToken() { int cursor = box.SelectionStart; int end = box.Text.Length; SearchToken token = new SearchToken(); MatchCollection matches = Regex.Matches(box.Text, "<[^>]+>"); int start = 0; foreach (Match match in matches) { if (cursor >= match.Index && cursor <= match.Index + match.Length) { token.Closed = true; token.Text = match.Value; token.Start = match.Index; token.End = match.Index + match.Length; //Console.WriteLine(token.ToString()); return token; } if (match.Index + match.Length < cursor) { start = match.Index + match.Length; } if (match.Index > cursor && match.Index < end) { end = match.Index; } } token.Closed = false; token.Start = start; token.End = end; token.Text = box.Text.Substring(start, end - start).TrimStart(' '); //Console.WriteLine(token.ToString()); return token; }
private void insertTokenToBox(string key, string value, SearchToken token) { skipTypeahead = true; var aStringBuilder = new StringBuilder(box.Text); if (token == null) { token = new SearchToken(); token.Start = box.Text.Length - 1; token.End = token.Start; } if (currentTokens.ContainsKey(key)) { //duplicate key not allowed, replace the old one aStringBuilder.Remove(token.Start, token.Length); token = currentTokens[key]; } aStringBuilder.Remove(token.Start, token.Length); string startingSpace = ""; string endingSpace = " "; if (token.Start != 0) { startingSpace = " "; } aStringBuilder.Insert(token.Start, startingSpace + "<" + key + ":" + value + ">"+endingSpace); box.Text = aStringBuilder.ToString(); box.SelectionStart = box.Text.Length; reStyle(); }
private IEnumerable<JObject> applyCurrentFilter(IEnumerable<JObject> searchResult) { MatchCollection matches = Regex.Matches(box.Text, "<[^>]+>"); currentTokens = new Dictionary<string, SearchToken>(); foreach (Match match in matches) { String[] token = match.Value.Split(new char[] { ':' }, 2); string key = token[0].TrimStart('<'); string value = token[1].TrimEnd('>'); SearchToken searchToken=new SearchToken(); searchToken.Text=match.Value; searchToken.Start = match.Index; searchToken.End = match.Index + match.Length; searchToken.Closed=true; currentTokens.Add(key, searchToken); if (isTokenKey(key)) { if (key == "title") { searchResult = searchResult.Where(af => ((string)af["top_id"]).Equals(selectedAffiliate.TopID)); } else { searchResult = searchResult.Where(af => ((string)af[key]).Equals(value)); } } } return searchResult; }