Skip to content

Commit 2fecde0

Browse files
authored
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.
1 parent 6db0cc5 commit 2fecde0

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ however, it has to be formatted properly to pass verification tests.
3333
- Fixed Documentation~/filter.yml GlobalNamespace rule removing all API documentation.
3434
- Fixed `Destroy may not be called from edit mode` error [ISXB-695](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-695)
3535
- Fixed possible exceptions thrown when deleting and adding Action Maps.
36+
- Fixed selection not changing when right-clicking an Action Map or Action in the Project Settings Input Action Editor.
3637
- 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)
3738
- Fixed issue where composite part dropdown manipulates binding path and leaves composite part field unchanged.
3839
- Fixed lingering highlight effect on Save Asset button after clicking.

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionMapsView.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public ActionMapsView(VisualElement root, StateContainer stateContainer)
5656

5757
m_ListView.RegisterCallback<ExecuteCommandEvent>(OnExecuteCommand);
5858
m_ListView.RegisterCallback<ValidateCommandEvent>(OnValidateCommand);
59+
m_ListView.RegisterCallback<PointerDownEvent>(OnPointerDown, TrickleDown.TrickleDown);
5960
var treeView = root.Q<TreeView>("actions-tree-view");
6061
m_ListView.AddManipulator(new DropManipulator(OnDroppedHandler, treeView));
6162
m_ListView.itemIndexChanged += OnReorder;
@@ -194,6 +195,16 @@ private void OnValidateCommand(ValidateCommandEvent evt)
194195
}
195196
}
196197

198+
private void OnPointerDown(PointerDownEvent evt)
199+
{
200+
// Allow right clicks to select an item before we bring up the matching context menu.
201+
if (evt.button == (int)MouseButton.RightMouse && evt.clickCount == 1)
202+
{
203+
var actionMap = (evt.target as VisualElement).GetFirstAncestorOfType<InputActionMapsTreeViewItem>();
204+
m_ListView.SetSelection(actionMap.parent.IndexOf(actionMap));
205+
}
206+
}
207+
197208
private readonly CollectionViewSelectionChangeFilter m_ListViewSelectionChangeFilter;
198209
private bool m_EnterRenamingMode;
199210
private readonly ListView m_ListView;

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionsTreeView.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ public ActionsTreeView(VisualElement root, StateContainer stateContainer)
5858

5959
if (item.isAction)
6060
{
61-
addBindingButton.clicked += ContextMenu.GetContextMenuForActionAddItem(treeViewItem, item.controlLayout);
61+
Action action = ContextMenu.GetContextMenuForActionAddItem(treeViewItem, item.controlLayout);
62+
addBindingButton.clicked += action;
63+
addBindingButton.userData = action; // Store to use in unbindItem
6264
addBindingButton.clickable.activators.Add(new ManipulatorActivationFilter(){button = MouseButton.RightMouse});
6365
addBindingButton.style.display = DisplayStyle.Flex;
6466
treeViewItem.EditTextFinishedCallback = newName =>
@@ -111,6 +113,12 @@ public ActionsTreeView(VisualElement root, StateContainer stateContainer)
111113
if (item.isAction || item.isComposite)
112114
treeViewItem.Reset();
113115

116+
if (item.isAction)
117+
{
118+
var button = element.Q<Button>("add-new-binding-button");
119+
button.clicked -= button.userData as Action;
120+
}
121+
114122
treeViewItem.OnDeleteItem -= treeViewItem.DeleteCallback;
115123
treeViewItem.OnDuplicateItem -= treeViewItem.DuplicateCallback;
116124
treeViewItem.EditTextFinished -= treeViewItem.EditTextFinishedCallback;
@@ -135,6 +143,7 @@ public ActionsTreeView(VisualElement root, StateContainer stateContainer)
135143

136144
m_ActionsTreeView.RegisterCallback<ExecuteCommandEvent>(OnExecuteCommand);
137145
m_ActionsTreeView.RegisterCallback<ValidateCommandEvent>(OnValidateCommand);
146+
m_ActionsTreeView.RegisterCallback<PointerDownEvent>(OnPointerDown, TrickleDown.TrickleDown);
138147
m_ActionsTreeView.RegisterCallback<DragPerformEvent>(OnDraggedItem);
139148

140149
CreateSelector(Selectors.GetActionsForSelectedActionMap, Selectors.GetActionMapCount,
@@ -423,6 +432,23 @@ private void OnValidateCommand(ValidateCommandEvent evt)
423432
}
424433
}
425434

435+
private void OnPointerDown(PointerDownEvent evt)
436+
{
437+
// Allow right clicks to select an item before we bring up the matching context menu.
438+
if (evt.button == (int)MouseButton.RightMouse && evt.clickCount == 1)
439+
{
440+
// Look upwards to the immediate child of the scroll view, so we know what Index to use
441+
var element = evt.target as VisualElement;
442+
while (element != null && element.name != "unity-tree-view__item")
443+
element = element.parent;
444+
445+
if (element == null)
446+
return;
447+
448+
m_ActionsTreeView.SetSelection(element.parent.IndexOf(element));
449+
}
450+
}
451+
426452
private string GetPreviousActionNameFromViewTree(in ActionOrBindingData data)
427453
{
428454
Debug.Assert(data.isAction);

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsTreeViewItem.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#if UNITY_EDITOR && UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
44
using System.Threading.Tasks;
55
using UnityEditor;
6-
using UnityEngine.InputSystem.Editor;
76
using UnityEngine.UIElements;
87

98
namespace UnityEngine.InputSystem.Editor

0 commit comments

Comments
 (0)