mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Merge branch 'v2_develop' of tig:tig/Terminal.Gui into v2_develop
This commit is contained in:
@@ -11,9 +11,11 @@ namespace Terminal.Gui;
|
||||
/// </summary>
|
||||
public sealed class Colors : INotifyCollectionChanged, IDictionary<string, ColorScheme?>
|
||||
{
|
||||
private static readonly object _lock = new object ();
|
||||
|
||||
static Colors ()
|
||||
{
|
||||
ColorSchemes = new (5, StringComparer.InvariantCultureIgnoreCase);
|
||||
ColorSchemes = new Dictionary<string, ColorScheme?> (5, StringComparer.InvariantCultureIgnoreCase);
|
||||
Reset ();
|
||||
}
|
||||
|
||||
@@ -66,111 +68,195 @@ public sealed class Colors : INotifyCollectionChanged, IDictionary<string, Color
|
||||
[UsedImplicitly]
|
||||
public static Dictionary<string, ColorScheme?> ColorSchemes { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IEnumerator<KeyValuePair<string, ColorScheme?>> GetEnumerator () { return ColorSchemes.GetEnumerator (); }
|
||||
|
||||
/// <inheritdoc/>
|
||||
IEnumerator IEnumerable.GetEnumerator () { return GetEnumerator (); }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Add (KeyValuePair<string, ColorScheme?> item)
|
||||
{
|
||||
ColorSchemes.Add (item.Key, item.Value);
|
||||
CollectionChanged?.Invoke (this, new (NotifyCollectionChangedAction.Add, item));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Clear ()
|
||||
{
|
||||
ColorSchemes.Clear ();
|
||||
CollectionChanged?.Invoke (this, new (NotifyCollectionChangedAction.Reset));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Contains (KeyValuePair<string, ColorScheme?> item) { return ColorSchemes.Contains (item); }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void CopyTo (KeyValuePair<string, ColorScheme?> [] array, int arrayIndex) { ((ICollection)ColorSchemes).CopyTo (array, arrayIndex); }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Remove (KeyValuePair<string, ColorScheme?> item)
|
||||
{
|
||||
if (ColorSchemes.Remove (item.Key))
|
||||
{
|
||||
CollectionChanged?.Invoke (this, new (NotifyCollectionChangedAction.Remove, item));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public int Count => ColorSchemes.Count;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool IsReadOnly => false;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Add (string key, ColorScheme? value) { Add (new (key, value)); }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool ContainsKey (string key) { return ColorSchemes.ContainsKey (key); }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Remove (string key)
|
||||
{
|
||||
if (ColorSchemes.Remove (key))
|
||||
{
|
||||
CollectionChanged?.Invoke (this, new (NotifyCollectionChangedAction.Remove, key));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool TryGetValue (string key, out ColorScheme? value) { return ColorSchemes.TryGetValue (key, out value); }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ColorScheme? this [string key]
|
||||
{
|
||||
get => ColorSchemes [key];
|
||||
set
|
||||
{
|
||||
if (ColorSchemes.TryAdd (key, value))
|
||||
{
|
||||
CollectionChanged?.Invoke (this, new (NotifyCollectionChangedAction.Add, new KeyValuePair<string, ColorScheme?> (key, value)));
|
||||
}
|
||||
else
|
||||
{
|
||||
ColorScheme? oldValue = ColorSchemes [key];
|
||||
ColorSchemes [key] = value;
|
||||
CollectionChanged?.Invoke (this, new (NotifyCollectionChangedAction.Replace, value, oldValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ICollection<string> Keys => ColorSchemes.Keys;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ICollection<ColorScheme?> Values => ColorSchemes.Values;
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <summary>
|
||||
/// Raised when the collection changes.
|
||||
/// </summary>
|
||||
public event NotifyCollectionChangedEventHandler? CollectionChanged;
|
||||
|
||||
/// <summary>Resets the <see cref="ColorSchemes"/> dictionary to the default values.</summary>
|
||||
/// <inheritdoc />
|
||||
public ColorScheme? this [string key]
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return ColorSchemes [key];
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (ColorSchemes.ContainsKey (key))
|
||||
{
|
||||
ColorScheme? oldValue = ColorSchemes [key];
|
||||
ColorSchemes [key] = value;
|
||||
CollectionChanged?.Invoke (this, new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Replace, value, oldValue));
|
||||
}
|
||||
else
|
||||
{
|
||||
ColorSchemes.Add (key, value);
|
||||
CollectionChanged?.Invoke (this, new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Add, new KeyValuePair<string, ColorScheme?> (key, value)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return ColorSchemes.Count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsReadOnly => false;
|
||||
|
||||
/// <inheritdoc />
|
||||
public ICollection<string> Keys
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return new List<string> (ColorSchemes.Keys);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ICollection<ColorScheme?> Values
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return new List<ColorScheme?> (ColorSchemes.Values);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Add (KeyValuePair<string, ColorScheme?> item)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
ColorSchemes.Add (item.Key, item.Value);
|
||||
CollectionChanged?.Invoke (this, new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Add, item));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Add (string key, ColorScheme? value)
|
||||
{
|
||||
Add (new KeyValuePair<string, ColorScheme?> (key, value));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Clear ()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
ColorSchemes.Clear ();
|
||||
CollectionChanged?.Invoke (this, new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Reset));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Contains (KeyValuePair<string, ColorScheme?> item)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return ColorSchemes.Contains (item);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool ContainsKey (string key)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return ColorSchemes.ContainsKey (key);
|
||||
}
|
||||
}
|
||||
|
||||
public void CopyTo (KeyValuePair<string, ColorScheme?> [] array, int arrayIndex)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
((ICollection)ColorSchemes).CopyTo (array, arrayIndex);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator<KeyValuePair<string, ColorScheme?>> GetEnumerator ()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return new List<KeyValuePair<string, ColorScheme?>> (ColorSchemes).GetEnumerator ();
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator ()
|
||||
{
|
||||
return GetEnumerator ();
|
||||
}
|
||||
|
||||
public bool Remove (KeyValuePair<string, ColorScheme?> item)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (ColorSchemes.Remove (item.Key))
|
||||
{
|
||||
CollectionChanged?.Invoke (this, new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Remove, item));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Remove (string key)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (ColorSchemes.Remove (key))
|
||||
{
|
||||
CollectionChanged?.Invoke (this, new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Remove, key));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool TryGetValue (string key, out ColorScheme? value)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return ColorSchemes.TryGetValue (key, out value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Resets the <see cref="ColorSchemes"/> dictionary to its default values.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static Dictionary<string, ColorScheme?> Reset ()
|
||||
{
|
||||
ColorSchemes.Clear ();
|
||||
ColorSchemes.Add ("TopLevel", new ());
|
||||
ColorSchemes.Add ("Base", new ());
|
||||
ColorSchemes.Add ("Dialog", new ());
|
||||
ColorSchemes.Add ("Menu", new ());
|
||||
ColorSchemes.Add ("Error", new ());
|
||||
|
||||
return ColorSchemes;
|
||||
lock (_lock)
|
||||
{
|
||||
ColorSchemes.Clear ();
|
||||
ColorSchemes.Add ("TopLevel", new ColorScheme ());
|
||||
ColorSchemes.Add ("Base", new ColorScheme ());
|
||||
ColorSchemes.Add ("Dialog", new ColorScheme ());
|
||||
ColorSchemes.Add ("Menu", new ColorScheme ());
|
||||
ColorSchemes.Add ("Error", new ColorScheme ());
|
||||
return ColorSchemes;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user