Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ internal static class ContextMenu
private static readonly string add_Binding_String = "Add Binding";

#region ActionMaps
// Determine whether current clipboard contents can can pasted into the ActionMaps view
//
// can always paste an ActionMap
// need an existing map to be able to paste an Action
//
private static bool CanPasteIntoActionMaps(ActionMapsView mapView)
{
bool haveMap = mapView.GetMapCount() > 0;
var copiedType = CopyPasteHelper.GetCopiedClipboardType();
bool copyIsMap = copiedType == typeof(InputActionMap);
bool copyIsAction = copiedType == typeof(InputAction);
bool hasPastableData = (copyIsMap || (copyIsAction && haveMap));
return hasPastableData;
}

public static void GetContextMenuForActionMapItem(ActionMapsView mapView, InputActionMapsTreeViewItem treeViewItem, int index)
{
treeViewItem.OnContextualMenuPopulateEvent = (menuEvent =>
Expand All @@ -39,9 +54,15 @@ public static void GetContextMenuForActionMapItem(ActionMapsView mapView, InputA
menuEvent.menu.AppendAction(copy_String, _ => mapView.CopyItems());
menuEvent.menu.AppendAction(cut_String, _ => mapView.CutItems());

var copiedAction = CopyPasteHelper.GetCopiedClipboardType() == typeof(InputAction);
if (CopyPasteHelper.HasPastableClipboardData(typeof(InputActionMap)))
menuEvent.menu.AppendAction(paste_String, _ => mapView.PasteItems(copiedAction));
if (CanPasteIntoActionMaps(mapView))
{
bool copyIsAction = CopyPasteHelper.GetCopiedClipboardType() == typeof(InputAction);
if (CopyPasteHelper.HasPastableClipboardData(typeof(InputActionMap)))
menuEvent.menu.AppendAction(paste_String, _ => mapView.PasteItems(copyIsAction));
}

menuEvent.menu.AppendSeparator();
menuEvent.menu.AppendAction(add_Action_Map_String, _ => mapView.AddActionMap());
});
}

Expand All @@ -51,27 +72,60 @@ public static void GetContextMenuForActionMapsEmptySpace(ActionMapsView mapView,
{
_ = new ContextualMenuManipulator(menuEvent =>
{
var copiedAction = CopyPasteHelper.GetCopiedClipboardType() == typeof(InputAction);
if (CopyPasteHelper.HasPastableClipboardData(typeof(InputActionMap)))
menuEvent.menu.AppendAction(paste_String, _ => mapView.PasteItems(copiedAction));

menuEvent.menu.AppendSeparator();
if (CanPasteIntoActionMaps(mapView))
{
bool copyIsAction = CopyPasteHelper.GetCopiedClipboardType() == typeof(InputAction);
menuEvent.menu.AppendAction(paste_String, _ => mapView.PasteItems(copyIsAction));
menuEvent.menu.AppendSeparator();
}
menuEvent.menu.AppendAction(add_Action_Map_String, _ => mapView.AddActionMap());
}) { target = element };
}

#endregion

#region Actions
// Determine whether current clipboard contents can pasted into the Actions TreeView
//
// item selected => can paste either Action or Binding (depends on selected item context)
// empty view => can only paste Action
// no selection => can only paste Action
//
private static bool CanPasteIntoActions(TreeView treeView)
{
bool hasPastableData = false;
bool selected = treeView.selectedIndex != -1;
if (selected)
{
var item = treeView.GetItemDataForIndex<ActionOrBindingData>(treeView.selectedIndex);
var itemType = item.isAction ? typeof(InputAction) : typeof(InputBinding);
hasPastableData = CopyPasteHelper.HasPastableClipboardData(itemType);
}
else
{
// Cannot paste Binding when no Action is selected or into an empty view
bool copyIsBinding = CopyPasteHelper.GetCopiedClipboardType() == typeof(InputBinding);
hasPastableData = !copyIsBinding && CopyPasteHelper.HasPastableClipboardData(typeof(InputAction));
}
return hasPastableData;
}

// Add the "Paste" option to all elements in the Action area.
public static void GetContextMenuForActionListView(ActionsTreeView actionsTreeView, TreeView treeView, VisualElement target)
{
_ = new ContextualMenuManipulator(menuEvent =>
{
var item = treeView.GetItemDataForIndex<ActionOrBindingData>(treeView.selectedIndex);
var hasPastableData = CopyPasteHelper.HasPastableClipboardData(item.isAction ? typeof(InputAction) : typeof(InputBinding));
if (hasPastableData)
menuEvent.menu.AppendAction(paste_String, _ => actionsTreeView.PasteItems());
bool haveMap = actionsTreeView.GetMapCount() > 0;
if (haveMap)
{
bool hasPastableData = CanPasteIntoActions(treeView);
if (hasPastableData)
{
menuEvent.menu.AppendAction(paste_String, _ => actionsTreeView.PasteItems());
}
menuEvent.menu.AppendSeparator();
menuEvent.menu.AppendAction(add_Action_String, _ => actionsTreeView.AddAction());
}
}) { target = target };
}

Expand All @@ -81,13 +135,15 @@ public static void GetContextMenuForActionsEmptySpace(ActionsTreeView actionsTre
{
_ = new ContextualMenuManipulator(menuEvent =>
{
if (actionsTreeView.GetMapCount() > 0 && (!onlyShowIfTreeIsEmpty || treeView.GetTreeCount() == 0))
bool haveMap = actionsTreeView.GetMapCount() > 0;
if (haveMap && (!onlyShowIfTreeIsEmpty || treeView.GetTreeCount() == 0))
{
var item = treeView.GetItemDataForIndex<ActionOrBindingData>(treeView.selectedIndex);
if (CopyPasteHelper.HasPastableClipboardData(item.isAction ? typeof(InputAction) : typeof(InputBinding)))
bool hasPastableData = CanPasteIntoActions(treeView);
if (hasPastableData)
{
menuEvent.menu.AppendAction(paste_String, _ => actionsTreeView.PasteItems());

menuEvent.menu.AppendSeparator();
menuEvent.menu.AppendSeparator();
}
menuEvent.menu.AppendAction(add_Action_String, _ => actionsTreeView.AddAction());
}
}) { target = target };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,17 @@ private static void PasteBlocks(string transmission, int indexToInsert, Serializ
{
var actionName = Selectors.GetSelectedBinding(s_State)?.wrappedProperty.FindPropertyRelative("m_Action")
.stringValue;

if (s_State.selectionType == SelectionType.Action)
actionName = PropertyName(Selectors.GetSelectedAction(s_State)?.wrappedProperty);
{
SerializedProperty property = Selectors.GetSelectedAction(s_State)?.wrappedProperty;
if (property == null)
return;
actionName = PropertyName(property);
}
if (actionName == null)
return;

PasteBindingOrComposite(arrayToInsertInto, block, indexToInsert, actionName);
}
}
Expand Down