Reloads actions on actions changed.
This commit is contained in:
@@ -6,6 +6,8 @@ namespace Cryville.Crtr.Browsing.Actions {
|
|||||||
public class ActionManager {
|
public class ActionManager {
|
||||||
readonly Dictionary<Type, List<IResourceAction>> _actions = new Dictionary<Type, List<IResourceAction>>();
|
readonly Dictionary<Type, List<IResourceAction>> _actions = new Dictionary<Type, List<IResourceAction>>();
|
||||||
|
|
||||||
|
public event Action Changed;
|
||||||
|
|
||||||
class ActionPriorityComparer : IComparer<IResourceAction> {
|
class ActionPriorityComparer : IComparer<IResourceAction> {
|
||||||
public static readonly ActionPriorityComparer Instance = new ActionPriorityComparer();
|
public static readonly ActionPriorityComparer Instance = new ActionPriorityComparer();
|
||||||
public int Compare(IResourceAction x, IResourceAction y) {
|
public int Compare(IResourceAction x, IResourceAction y) {
|
||||||
@@ -21,6 +23,7 @@ namespace Cryville.Crtr.Browsing.Actions {
|
|||||||
int index = actions.BinarySearch(action, ActionPriorityComparer.Instance);
|
int index = actions.BinarySearch(action, ActionPriorityComparer.Instance);
|
||||||
if (index < 0) index = ~index;
|
if (index < 0) index = ~index;
|
||||||
actions.Insert(index, action);
|
actions.Insert(index, action);
|
||||||
|
Changed?.Invoke();
|
||||||
}
|
}
|
||||||
public void Register(IResourceAction action) {
|
public void Register(IResourceAction action) {
|
||||||
Register(typeof(object), action);
|
Register(typeof(object), action);
|
||||||
@@ -33,6 +36,7 @@ namespace Cryville.Crtr.Browsing.Actions {
|
|||||||
List<IResourceAction> actions;
|
List<IResourceAction> actions;
|
||||||
if (!_actions.TryGetValue(type, out actions)) return;
|
if (!_actions.TryGetValue(type, out actions)) return;
|
||||||
actions.Remove(action);
|
actions.Remove(action);
|
||||||
|
Changed?.Invoke();
|
||||||
}
|
}
|
||||||
public void Unregister(IResourceAction action) {
|
public void Unregister(IResourceAction action) {
|
||||||
Unregister(typeof(object), action);
|
Unregister(typeof(object), action);
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
UnregisterManager();
|
UnregisterManager();
|
||||||
}
|
}
|
||||||
void UnregisterManager() {
|
void UnregisterManager() {
|
||||||
Master.Actions.Unregister(_importAction);
|
if (_importAction != null) Master.Actions.Unregister(_importAction);
|
||||||
_manager.ItemChanged -= OnItemChanged;
|
_manager.ItemChanged -= OnItemChanged;
|
||||||
_manager.DirectoryChanged -= OnDirectoryChanged;
|
_manager.DirectoryChanged -= OnDirectoryChanged;
|
||||||
}
|
}
|
||||||
@@ -111,9 +111,19 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
_selectedItems.Add(id);
|
_selectedItems.Add(id);
|
||||||
var res = _manager[id];
|
var res = _manager[id];
|
||||||
m_detailPanel.Load(res);
|
m_detailPanel.Load(res);
|
||||||
m_actionBar.Load(this, Master.Actions.GetActions(res.GetType()).Except(_importActionArray));
|
if (_selectedItems.Count == 1) {
|
||||||
|
LoadActions(res);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
internal override void OnActionsChanged() {
|
||||||
|
if (_selectedItems.Count == 1) {
|
||||||
|
LoadActions(_manager[_selectedItems.Single()]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void LoadActions(IResourceMeta res) {
|
||||||
|
m_actionBar.Load(this, Master.Actions.GetActions(res.GetType()).Except(_importActionArray));
|
||||||
|
}
|
||||||
|
|
||||||
public void OnPathClicked(int index) {
|
public void OnPathClicked(int index) {
|
||||||
_manager.ReturnToDirectory(index);
|
_manager.ReturnToDirectory(index);
|
||||||
|
|||||||
@@ -15,5 +15,6 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
public abstract void OnItemClicked(int index);
|
public abstract void OnItemClicked(int index);
|
||||||
|
|
||||||
public abstract void InvokeAction(IResourceAction action);
|
public abstract void InvokeAction(IResourceAction action);
|
||||||
|
internal abstract void OnActionsChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
base.Awake();
|
base.Awake();
|
||||||
|
|
||||||
Actions = new ActionManager();
|
Actions = new ActionManager();
|
||||||
|
Actions.Changed += OnActionsChanged;
|
||||||
Actions.Register(new PlayChartAction());
|
Actions.Register(new PlayChartAction());
|
||||||
|
|
||||||
OnTabClicked(AddPathedBrowserTab("Local", new LegacyResourceManager(Settings.Default.GameDataPath)));
|
OnTabClicked(AddPathedBrowserTab("Local", new LegacyResourceManager(Settings.Default.GameDataPath)));
|
||||||
@@ -64,6 +65,12 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnActionsChanged() {
|
||||||
|
foreach (var tab in _tabs) {
|
||||||
|
tab.Value.OnActionsChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool Back() {
|
public bool Back() {
|
||||||
return true; // TODO
|
return true; // TODO
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,5 +9,6 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
}
|
}
|
||||||
public override void OnItemClicked(int index) { }
|
public override void OnItemClicked(int index) { }
|
||||||
public override void InvokeAction(IResourceAction action) { }
|
public override void InvokeAction(IResourceAction action) { }
|
||||||
|
internal override void OnActionsChanged() { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user