Exemple #1
0
		public void AddItem(KeyValuePair pair)
		{

			DivElement div = (DivElement)Document.CreateElement("DIV");
			Dictionary divAsArray = (Dictionary)(object)div;
			divAsArray["value"] = pair.Value;
			if (pair.Key.IndexOf("<") > -1)
				div.InnerHTML = pair.Key;
			else
				div.InnerHTML = "<div class=\"DefaultPopupMenuItem\">" + pair.Key + "</div>";
			container.AppendChild(div);
			DomEvent.AddHandler(div, "click", ItemClickHandler);
			DomEvent.AddHandler(div, "mouseover", ItemMouseEnterHandler);
			
		}
		void HandleKeyDown(DomEvent e)
		{
			if (e.KeyCode == (int)Key.Up) { if (popupMenu != null) popupMenu.IndexOfCurrentlyHighlightedItem -= 1; }
			else if (e.KeyCode == (int)Key.Down) { if (popupMenu != null) { popupMenu.IndexOfCurrentlyHighlightedItem += 1; } }
			
			else if (e.KeyCode == (int)Key.Esc)
			{
				if (this.popupMenu.CurrentlyHighlightedItem != null)
				{
					Clear();
					e.PreventDefault();
				}
				else
				{
					Cancel();
				}
			} 
			else if ((e.KeyCode == (int)Key.Tab && !e.ShiftKey) || e.KeyCode == (int)Key.Enter)
			{
				if (mode == HtmlAutoCompleteMode.Suggest)
				{
					if (SuggestionIsHighlighted)
					{
						e.PreventDefault();
						ItemSelected(this.popupMenu.CurrentlyHighlightedItem);
						popupMenu.Clear();
						return;
					}
					else
					{
						if (ValidSelectionHasBeenMade)
						{
							KeyValuePair pair = new KeyValuePair();
							pair.Key = this.input.Value;
							pair.Value = this.input.Value;
							ItemSelected(pair);
							return;
						}
					}
				}
				else if (mode == HtmlAutoCompleteMode.Complete)
				{
					if (SuggestionIsHighlighted && !ValidSelectionHasBeenMade)
					{
						if (e.KeyCode == (int)Key.Enter) e.PreventDefault();
						ItemSelected(this.popupMenu.CurrentlyHighlightedItem);

						return;
					}
				}
			}
			else if (e.KeyCode == (int)Key.Backspace && mode == HtmlAutoCompleteMode.Complete)
			{
				Suggestions.Clear();
				if (this.ValidSelectionHasBeenMade)
				{
					this.hiddenInput.Value = ""; this.input.Value = ""; 
				}
				else
				{
					this.hiddenInput.Value = ""; RequestSuggestions(); ; 
				}
			}
			else if (e.KeyCode == (int)Key.Del && mode == HtmlAutoCompleteMode.Complete) { this.hiddenInput.Value = ""; RequestSuggestions(); ; }
		}
		public void DisplaySuggestionsInPopupMenu()
		{
			Trace.Write("DisplaySuggestionsInPopupMenu"); 
			popupMenu.Clear();
			for (int i = 0; i < Suggestions.Count; i++)
			{
				Suggestion suggestion = (Suggestion)Suggestions[i];
				KeyValuePair pair = new KeyValuePair();
				pair.Key = suggestion.html;
				KeyValuePair value = new KeyValuePair();
				value.Key = suggestion.text;
				value.Value = mode == HtmlAutoCompleteMode.Complete ? suggestion.value : suggestion.text;
				pair.Value = value;
				popupMenu.AddItem(pair);
			}
			HighlightFirstSuggestion();
			
			
			popupMenu.Show(anchor, minWidth, maxWidth, popupTopOffset, popupLeftOffset, rightAlign);
		}