void CheckForEmailAddress() { Trace.Write("CheckingForEmailAddress"); RegularExpression regex = new RegularExpression(EmailRegex); string email = selector.Text.Trim(); if (regex.Test(email)) { Suggestion suggestion = new Suggestion(); suggestion.html = GetPicTitleDetailTemplateHtml(@"/gfx/icon40-inbox.png", "Add " + selector.Text.Trim() + " as a buddy", "When they join DontStayIn they will be added as one of your buddies. If you type a name after the email address you can use that in future to find this person."); suggestion.text = selector.Text; suggestion.value = "{'email': '" + selector.Text.Escape() + "'}"; suggestion.priority = selector.Text.Length * 100; for (int i = 0; i < selector.Suggestions.Count; i++) { if (selector.Suggestions[i].value.StartsWith("{'email': ")) { selector.Suggestions.RemoveAt(i); break; } } selector.AddSuggestion(suggestion); selector.DisplaySuggestionsInPopupMenu(); } if (oldOnSuggestionsRequested != null) oldOnSuggestionsRequested(); }
private Suggestion GetGoogleSearchSuggestion() { Suggestion googleSearchSuggestion = new Suggestion(); googleSearchSuggestion.html = Suggestion.GetPicTitleDetailTemplateHtml("/gfx/icon40-google.png", "Search DSI using Google", ""); googleSearchSuggestion.text = this.view.uiAuto.Text; googleSearchSuggestion.value = "{google}"; return googleSearchSuggestion; }
public void AddRange(Suggestion[] newSuggestions) { for (int i = 0; i < newSuggestions.Length; i++) { AddWithoutSortOrNotify(newSuggestions[i]); } Sort(); if (OnSuggestionsChanged != null) OnSuggestionsChanged(); }
public static void AddSuggestionAtTop(Suggestion[] suggestions, Suggestion suggestion) { suggestion.priority = (suggestions.Length > 0) ? (suggestions[0].priority + 1): 1; for (int i = suggestions.Length; i > 0; i--) { Suggestion temp = suggestions[i - 1]; suggestions[i - 1] = null; suggestions[i] = temp; } suggestions[0] = suggestion; }
private void AddWithoutSortOrNotify(Suggestion newSuggestion) { int i = 0; for (i = 0; i < suggestions.Length; i++) { Suggestion current = (Suggestion)suggestions[i]; if (current.value == newSuggestion.value) { if (newSuggestion.priority < current.priority) { newSuggestion.priority = current.priority; } break; } } suggestions[i] = newSuggestion; }
void CheckForEmailAddresses() { Trace.Write("CheckingForEmailAddresses"); RegularExpression regExp = new RegularExpression(@"\s|,|;| +", "g"); string text = selector.Text.Replace(regExp, " "); while (text.IndexOf(" ") > -1) { text = text.Replace(" ", " "); } text = text.Trim(); for (int i = selector.Suggestions.Count - 1; i > -1; i--) { Trace.Write(selector.Suggestions[i].value); if (selector.Suggestions[i].value.StartsWith("{'emails': ")) { selector.Suggestions.RemoveAt(i); break; } } RegularExpression regex = new RegularExpression(EmailsRegex); if (regex.Test(text)) { selector.Text = text; selector.Suggestions.Clear(); string[] emails = text.Split(" "); Suggestion suggestion = new Suggestion(); suggestion.html = GetPicTitleDetailTemplateHtml(@"/gfx/icon40-inbox.png", "Add " + emails.Length + " email addresses as buddies", "Next time you want to include these email addresses, just add all your buddies and they will be included."); suggestion.text = emails.Length + " email addresses as buddies"; suggestion.value = "{'emails': '" + text.Escape() + "', 'buddies':'true'}"; suggestion.priority = selector.Text.Length * 100; selector.AddSuggestion(suggestion); Suggestion suggestion2 = new Suggestion(); suggestion2.html = GetPicTitleDetailTemplateHtml(@"/gfx/icon40-inbox.png", "Add " + emails.Length + " email addresses, but NOT as buddies", "Next time you want to include these email addresses you'll have to copy them in again"); suggestion2.text = emails.Length + " email addresses"; suggestion2.value = "{'emails': '" + text.Escape() + "', 'buddies':'false'}"; suggestion2.priority = selector.Text.Length * 100; selector.AddSuggestion(suggestion2); selector.DisplaySuggestionsInPopupMenu(); } if (oldOnSuggestionsRequested != null) oldOnSuggestionsRequested(); }
private Suggestion[] TransformReceivedSuggestions(Suggestion[] suggestions, int maxNumberToGet) { Suggestion.AddSuggestionAtTop(suggestions, this.GetGoogleSearchSuggestion()); if (this.oldTransformReceivedSuggestions != null) suggestions = oldTransformReceivedSuggestions(suggestions, maxNumberToGet); return suggestions; }
private void AddSuggestions(Suggestion[] newSuggestions) { Trace.Write("Adding " + newSuggestions.Length + " suggestions. Suggestions length = " + Suggestions.Count); Suggestions.AddRange(newSuggestions); while (Suggestions.Count > maxNumberOfItemsToGet) { Trace.Write("Suggestions length " + Suggestions.Count + " Removing suggestion"); Suggestions.RemoveAt(Suggestions.Count - 1); } Trace.Write("Finished adding " + newSuggestions.Length + " suggestions. Suggestions length = " + Suggestions.Count); }
public void AddSuggestion(Suggestion newSuggestion) { AddSuggestions(new Suggestion[] { newSuggestion }); }
public static void AddSuggestion(Suggestion[] suggestions, Suggestion suggestion, int maxNumberOfItemsToGet) { suggestion.priority = (suggestions.Length > 0) ? suggestions[suggestions.Length - 1].priority : 1; suggestions[suggestions.Length < maxNumberOfItemsToGet ? suggestions.Length : suggestions.Length - 1] = suggestion; }
private Suggestion[] TransformReceivedSuggestions(Suggestion[] suggestions, int maxNumberOfItemsToGet) { if (view.uiVenueGetter.GetVenue() != null && view.uiCal.GetDate() != null && view.uiEventName.Value == "") { string eventString = this.view.uiEventName.Text + " @ " + view.uiVenueGetter.GetVenue().name + " on " + view.uiCal.GetDate().Format("ddd dd/MM/yyyy"); Suggestion quickAdd = new Suggestion(); quickAdd.html = Suggestion.GetPicTitleDetailTemplateHtml("@/gfx/icon40-eventcreator-add.png", "Add <b>" + eventString + "</b>", "You'll be able to add more details later if you like"); quickAdd.value = "{addMethod:quick}"; quickAdd.text = this.view.uiEventName.Text; Suggestion.AddSuggestion(suggestions, quickAdd, maxNumberOfItemsToGet); } else { Suggestion notInDbSuggestion = new Suggestion(); notInDbSuggestion.html = Suggestion.GetPicTitleDetailTemplateHtml(@"/gfx/icon40-eventcreator-noadd.png", "Can't add <b>" + this.view.uiEventName.Text + "</b>", "Fill out all the fields"); notInDbSuggestion.value = "{filloutFields}"; notInDbSuggestion.text = this.view.uiEventName.Text; Suggestion.AddSuggestion(suggestions, notInDbSuggestion, maxNumberOfItemsToGet); } if (oldTransformReceivedSuggestions != null) { suggestions = oldTransformReceivedSuggestions(suggestions, maxNumberOfItemsToGet); } return suggestions; }
private Suggestion[] TransformReceivedSuggestions(Suggestion[] suggestions, int maxNumberOfItemsToGet) { if (oldTransformReceivedSuggestions != null) suggestions = oldTransformReceivedSuggestions(suggestions, maxNumberOfItemsToGet); if (this.view.uiAuto.Text != "" && this.view.uiAuto.Value == null) { Suggestion createNewVenueSuggestion = new Suggestion(); createNewVenueSuggestion.html = Suggestion.GetPicTitleDetailTemplateHtml(@"/gfx/icon40-eventcreator-add.png", "Add <b>" + view.uiAuto.Text + "</b>", "Other people will be able to add details about the venue later"); createNewVenueSuggestion.value = "|create|" + view.uiAuto.Text + ""; createNewVenueSuggestion.text = createNewVenueSuggestion.value; Suggestion.AddSuggestion(suggestions, createNewVenueSuggestion, maxNumberOfItemsToGet); } return suggestions; }
public void Add(Suggestion newSuggestion) { AddWithoutSortOrNotify(newSuggestion); Sort(); if (OnSuggestionsChanged != null) OnSuggestionsChanged(); }