namespace UIWidgets
{
using System;
using System.Collections;
using System.Collections.Generic;
///
/// Dialog actions.
/// Key - button name.
/// Value - action on click.
///
[Obsolete("No more used. Replaced with DialogButton[].")]
public class DialogActions : IList
{
readonly List buttons = new List();
///
/// Gets the number of elements contained in the dictionary.
///
/// The count.
public int Count
{
get
{
return buttons.Count;
}
}
///
/// Gets a value indicating whether this instance is read only.
///
/// true if this instance is read only; otherwise, false.
public bool IsReadOnly
{
get
{
return false;
}
}
///
/// Gets or sets the element with the specified key.
///
/// The element with the specified key.
/// The key of the element to get or set.
[Obsolete("Should not be used.")]
public Func this[string key]
{
get
{
return GetButton(key).ActionBool;
}
set
{
GetButton(key).ActionBool = value;
}
}
DialogButton GetButton(string key)
{
for (int i = 0; i < buttons.Count; i++)
{
if (buttons[i].Label == key)
{
return buttons[i];
}
}
return null;
}
///
/// Gets an ICollection{string} containing the keys of the dictionary.
///
/// The keys.
public List Keys
{
get
{
var result = new List();
foreach (var button in buttons)
{
result.Add(button.Label);
}
return result;
}
}
///
/// Gets an ICollection{Func{bool}} containing the values in the dictionary.
///
/// The values.
[Obsolete("Should not be used.")]
public List> Values
{
get
{
var result = new List>();
foreach (var button in buttons)
{
result.Add(button.ActionBool);
}
return result;
}
}
///
/// Gets or sets the element at the specified index.
///
/// The element at the specified index.
/// The zero-based index of the element to get or set.
public DialogButton this[int index]
{
get
{
return buttons[index];
}
set
{
buttons[index] = value;
}
}
///
/// Add the specified item.
///
/// Item.
public void Add(KeyValuePair> item)
{
Add(item.Key, item.Value, 0);
}
///
/// Add the specified key and value.
///
/// Key.
/// Value.
public void Add(string key, Func value)
{
Add(key, value, 0);
}
///
/// Add the specified key and value.
///
/// Key.
/// Value.
/// Index of the button.
public void Add(string key, Func value, int buttonIndex)
{
if (key == null)
{
throw new ArgumentNullException("key", "Key is null.");
}
if (ContainsKey(key))
{
throw new ArgumentException(string.Format("An element with the same key ({0}) already exists.", key), "key");
}
#pragma warning disable 0618
buttons.Add(new DialogButton(key, value, buttonIndex));
#pragma warning restore 0618
}
///
/// Removes all items.
///
public void Clear()
{
buttons.Clear();
}
///
/// Determines whether contains a specific value.
///
/// Item.
/// true if contains a specific value; otherwise false.
[Obsolete("Should not be used.")]
public bool Contains(KeyValuePair> item)
{
return ContainsKey(item.Key);
}
///
/// Determines whether the IDictionary{TKey, TValue} contains an element with the specified key.
///
/// Key.
/// true, if key is exists, false otherwise.
public bool ContainsKey(string key)
{
if (key == null)
{
throw new ArgumentNullException("key", "Key is null.");
}
for (int i = 0; i < buttons.Count; i++)
{
if (buttons[i].Label == key)
{
return true;
}
}
return false;
}
///
/// Copies the elements of the KeyValuePair{string, Func{bool}} to an Array, starting at a particular Array index.
///
/// Array.
/// Array index.
[Obsolete("Should not be used.")]
public void CopyTo(KeyValuePair>[] array, int arrayIndex)
{
for (int i = 0; i < buttons.Count; i++)
{
array[arrayIndex + i] = new KeyValuePair>(buttons[i].Label, buttons[i].ActionBool);
}
}
///
/// Returns an enumerator that iterates through the collection.
///
/// Returns an enumerator that iterates through a collection.
public List.Enumerator GetEnumerator()
{
return buttons.GetEnumerator();
}
///
/// Returns an enumerator that iterates through the DialogActions{T}.
///
/// A DialogActions{T}.Enumerator for the DialogActions{T}.
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0601:Value type to reference type conversion causing boxing allocation", Justification = "Required.")]
IEnumerator IEnumerable.GetEnumerator()
{
return buttons.GetEnumerator();
}
///
/// Returns an enumerator that iterates through the collection.
///
/// Returns an enumerator that iterates through a collection.
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0601:Value type to reference type conversion causing boxing allocation", Justification = "Required.")]
IEnumerator IEnumerable.GetEnumerator()
{
return buttons.GetEnumerator();
}
///
/// Removes the first occurrence of a specific object from the dictionary.
///
/// Item.
/// true if item exists and item was removed; false otherwise.
[Obsolete("Should not be used.")]
public bool Remove(KeyValuePair> item)
{
return Remove(item.Key);
}
///
/// Removes the element with the specified key from the dictionary.
///
/// Key.
/// true if key exists and item was removed; false otherwise.
public bool Remove(string key)
{
if (key == null)
{
throw new ArgumentNullException("key", "Key is null.");
}
for (int i = 0; i < buttons.Count; i++)
{
if (buttons[i].Label == key)
{
buttons.RemoveAt(i);
return true;
}
}
return false;
}
///
/// Gets the value associated with the specified key.
///
/// true, if key was found, false otherwise.
/// Key.
/// Value.
[Obsolete("Should not be used.")]
public bool TryGetValue(string key, out Func value)
{
if (key == null)
{
throw new ArgumentNullException("key", "Key is null.");
}
for (int i = 0; i < buttons.Count; i++)
{
if (buttons[i].Label == key)
{
value = buttons[i].ActionBool;
return true;
}
}
value = default(Func);
return false;
}
///
/// Searches for the specified object and returns the zero-based index of the first occurrence within the entire DialogActions{T}.
///
/// The zero-based index of the first occurrence of item within the entire DialogActions{T}, if found; otherwise, –1.
/// The object to locate in the DialogActions{T}. The value can be null for reference types.
public int IndexOf(DialogButton item)
{
return buttons.IndexOf(item);
}
///
/// Inserts an element into the DialogActions{T} at the specified index.
///
/// The zero-based index at which item should be inserted.
/// The object to insert. The value can be null for reference types.
public void Insert(int index, DialogButton item)
{
buttons.Insert(index, item);
}
///
/// Removes the element at the specified index of the DialogActions{T}.
///
/// The zero-based index of the element to remove.
public void RemoveAt(int index)
{
buttons.RemoveAt(index);
}
///
/// Adds an object to the end of the DialogActions{T}.
///
/// The object to be added to the end of the DialogActions{T}. The value can be null for reference types.
public void Add(DialogButton item)
{
buttons.Add(item);
}
///
/// Determines whether an element is in the DialogActions{T}.
///
/// true if item is found in the DialogActions{T}; otherwise, false.
/// The object to locate in the DialogActions{T}. The value can be null for reference types.
public bool Contains(DialogButton item)
{
return buttons.Contains(item);
}
///
/// Copies the entire DialogActions{T} to a compatible one-dimensional array, starting at the specified index of the target array.
///
/// The one-dimensional Array that is the destination of the elements copied from DialogActions{T}. The Array must have zero-based indexing.
/// The zero-based index in array at which copying begins.
public void CopyTo(DialogButton[] array, int arrayIndex)
{
buttons.CopyTo(array, arrayIndex);
}
///
/// Removes the first occurrence of a specific object from the DialogActions{T}.
///
/// The object to remove from the DialogActions{T}. The value can be null for reference types.
/// true if item is successfully removed; otherwise, false. This method also returns false if item was not found in the DialogActions{T}.
public bool Remove(DialogButton item)
{
return buttons.Remove(item);
}
}
}