Disallow removing items from SelectionCycleFillFlowContainer

This commit is contained in:
Derrick Timmermans 2021-07-07 11:43:54 +02:00
parent ddb1da5a66
commit 8b1876bc2a
No known key found for this signature in database
GPG Key ID: 8681B60806EF4A17

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using osu.Framework;
using osu.Framework.Graphics;
@ -21,8 +20,6 @@ namespace osu.Game.Graphics.Containers
private int? selectedIndex;
private readonly Dictionary<T, Action<SelectionState>> handlerMap = new Dictionary<T, Action<SelectionState>>();
public void SelectNext()
{
if (!selectedIndex.HasValue || selectedIndex == Count - 1)
@ -57,28 +54,12 @@ namespace osu.Game.Graphics.Containers
Debug.Assert(drawable != null);
// This event is used to update selection state when modified within the drawable itself.
// It is added to a dictionary so that we can unsubscribe if the drawable is removed from this container
handlerMap[drawable] = state => selectionChanged(drawable, state);
drawable.StateChanged += handlerMap[drawable];
drawable.StateChanged += state => selectionChanged(drawable, state);
}
public override bool Remove(T drawable)
{
if (!base.Remove(drawable))
return false;
=> throw new NotSupportedException($"Cannot remove drawables from {nameof(SelectionCycleFillFlowContainer<T>)}");
Debug.Assert(drawable != null);
if (handlerMap.TryGetValue(drawable, out var action))
{
drawable.StateChanged -= action;
handlerMap.Remove(drawable);
}
return true;
}
private void setSelected(int? value)
{