From 2fecde04ebffa10652d36c928ae2df8c20f00985 Mon Sep 17 00:00:00 2001 From: Graham Huws <102745393+graham-huws@users.noreply.github.com> Date: Thu, 15 Feb 2024 11:39:07 +0000 Subject: [PATCH] FIX: Select appropriate action/action map when right clicking (ISX-1743). (#1806) * Intercept right click to select appropriate items before context menus appear. * Undo callback changes. * Formatting fix. * Update changelog, remove unneeded brackets. * Store the Action generated for context menus so it can be correctly removed later. * Add null check for element hunting. * Formatting fix. --- Packages/com.unity.inputsystem/CHANGELOG.md | 1 + .../UITKAssetEditor/Views/ActionMapsView.cs | 11 ++++++++ .../UITKAssetEditor/Views/ActionsTreeView.cs | 28 ++++++++++++++++++- .../Views/InputActionsTreeViewItem.cs | 1 - 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 1437473c32..bc6b9c45d5 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -33,6 +33,7 @@ however, it has to be formatted properly to pass verification tests. - Fixed Documentation~/filter.yml GlobalNamespace rule removing all API documentation. - Fixed `Destroy may not be called from edit mode` error [ISXB-695](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-695) - Fixed possible exceptions thrown when deleting and adding Action Maps. +- Fixed selection not changing when right-clicking an Action Map or Action in the Project Settings Input Action Editor. - Fixed potential race condition on access to GCHandle in DefferedResolutionOfBindings and halved number of calls to GCHandle resolution [ISXB-726](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-726) - Fixed issue where composite part dropdown manipulates binding path and leaves composite part field unchanged. - Fixed lingering highlight effect on Save Asset button after clicking. diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionMapsView.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionMapsView.cs index 2ede37ecf4..c40971dcd4 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionMapsView.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionMapsView.cs @@ -56,6 +56,7 @@ public ActionMapsView(VisualElement root, StateContainer stateContainer) m_ListView.RegisterCallback(OnExecuteCommand); m_ListView.RegisterCallback(OnValidateCommand); + m_ListView.RegisterCallback(OnPointerDown, TrickleDown.TrickleDown); var treeView = root.Q("actions-tree-view"); m_ListView.AddManipulator(new DropManipulator(OnDroppedHandler, treeView)); m_ListView.itemIndexChanged += OnReorder; @@ -194,6 +195,16 @@ private void OnValidateCommand(ValidateCommandEvent evt) } } + private void OnPointerDown(PointerDownEvent evt) + { + // Allow right clicks to select an item before we bring up the matching context menu. + if (evt.button == (int)MouseButton.RightMouse && evt.clickCount == 1) + { + var actionMap = (evt.target as VisualElement).GetFirstAncestorOfType(); + m_ListView.SetSelection(actionMap.parent.IndexOf(actionMap)); + } + } + private readonly CollectionViewSelectionChangeFilter m_ListViewSelectionChangeFilter; private bool m_EnterRenamingMode; private readonly ListView m_ListView; diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionsTreeView.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionsTreeView.cs index f445487dc6..493b66a0b3 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionsTreeView.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionsTreeView.cs @@ -58,7 +58,9 @@ public ActionsTreeView(VisualElement root, StateContainer stateContainer) if (item.isAction) { - addBindingButton.clicked += ContextMenu.GetContextMenuForActionAddItem(treeViewItem, item.controlLayout); + Action action = ContextMenu.GetContextMenuForActionAddItem(treeViewItem, item.controlLayout); + addBindingButton.clicked += action; + addBindingButton.userData = action; // Store to use in unbindItem addBindingButton.clickable.activators.Add(new ManipulatorActivationFilter(){button = MouseButton.RightMouse}); addBindingButton.style.display = DisplayStyle.Flex; treeViewItem.EditTextFinishedCallback = newName => @@ -111,6 +113,12 @@ public ActionsTreeView(VisualElement root, StateContainer stateContainer) if (item.isAction || item.isComposite) treeViewItem.Reset(); + if (item.isAction) + { + var button = element.Q