#if UNITY_EDITOR && UNITY_INPUT_SYSTEM_UI_TK_ASSET_EDITOR using System.Collections.Generic; using System.Linq; using UnityEngine.InputSystem.Utilities; using UnityEngine.UIElements; namespace UnityEngine.InputSystem.Editor { /// /// A list view to display the action maps of the currently opened input actions asset. /// internal class ActionMapsView : ViewBase { public ActionMapsView(VisualElement root, StateContainer stateContainer) : base(stateContainer) { m_Root = root; m_ListView = m_Root?.Q("action-maps-list-view"); m_ListView.selectionType = UIElements.SelectionType.Single; m_ListView.selectionChanged += _ => SelectActionMap(); m_ListView.bindItem = (element, i) => { var treeViewItem = (InputActionsTreeViewItem)element; treeViewItem.label.text = (string)m_ListView.itemsSource[i]; treeViewItem.EditTextFinishedCallback = newName => ChangeActionMapName(i, newName); treeViewItem.EditTextFinished += treeViewItem.EditTextFinishedCallback; treeViewItem.DeleteCallback = _ => DeleteActionMap(i); treeViewItem.DuplicateCallback = _ => DuplicateActionMap(i); treeViewItem.OnDeleteItem += treeViewItem.DeleteCallback; treeViewItem.OnDuplicateItem += treeViewItem.DuplicateCallback; ContextMenu.GetContextMenuForActionMapItem(treeViewItem); }; m_ListView.makeItem = () => new InputActionsTreeViewItem(); m_ListView.unbindItem = (element, i) => { var treeViewElement = (InputActionsTreeViewItem)element; treeViewElement.Reset(); treeViewElement.OnDeleteItem -= treeViewElement.DeleteCallback; treeViewElement.OnDuplicateItem -= treeViewElement.DuplicateCallback; treeViewElement.EditTextFinished -= treeViewElement.EditTextFinishedCallback; }; m_ListView.itemsChosen += objects => { var item = m_ListView.GetRootElementForIndex(m_ListView.selectedIndex).Q(); item.FocusOnRenameTextField(); }; m_ListView.RegisterCallback(OnKeyDownEvent); CreateSelector(s => new ViewStateCollection(Selectors.GetActionMapNames(s)), (actionMapNames, state) => new ViewState(Selectors.GetSelectedActionMap(state), actionMapNames)); addActionMapButton.clicked += AddActionMap; } private Button addActionMapButton => m_Root?.Q