Reloads actions on actions changed.
This commit is contained in:
@@ -6,6 +6,8 @@ namespace Cryville.Crtr.Browsing.Actions {
|
||||
public class ActionManager {
|
||||
readonly Dictionary<Type, List<IResourceAction>> _actions = new Dictionary<Type, List<IResourceAction>>();
|
||||
|
||||
public event Action Changed;
|
||||
|
||||
class ActionPriorityComparer : IComparer<IResourceAction> {
|
||||
public static readonly ActionPriorityComparer Instance = new ActionPriorityComparer();
|
||||
public int Compare(IResourceAction x, IResourceAction y) {
|
||||
@@ -21,6 +23,7 @@ namespace Cryville.Crtr.Browsing.Actions {
|
||||
int index = actions.BinarySearch(action, ActionPriorityComparer.Instance);
|
||||
if (index < 0) index = ~index;
|
||||
actions.Insert(index, action);
|
||||
Changed?.Invoke();
|
||||
}
|
||||
public void Register(IResourceAction action) {
|
||||
Register(typeof(object), action);
|
||||
@@ -33,6 +36,7 @@ namespace Cryville.Crtr.Browsing.Actions {
|
||||
List<IResourceAction> actions;
|
||||
if (!_actions.TryGetValue(type, out actions)) return;
|
||||
actions.Remove(action);
|
||||
Changed?.Invoke();
|
||||
}
|
||||
public void Unregister(IResourceAction action) {
|
||||
Unregister(typeof(object), action);
|
||||
|
Reference in New Issue
Block a user