New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX: Allow Copy/Paste between windows (ISX-1823). #1844
base: develop
Are you sure you want to change the base?
Conversation
94d27e7
to
8944d39
Compare
…gher up the hierarchy. (ISX-1823)
8944d39
to
4d21dbf
Compare
@@ -288,13 +292,14 @@ private static void PasteAction(SerializedProperty arrayProperty, string jsonToI | |||
private static int PasteBindingOrComposite(SerializedProperty arrayProperty, string json, int index, string actionName, bool createCompositeParts = true) | |||
{ | |||
var pastePartOfComposite = IsPartOfComposite(json); | |||
if (index > 0) | |||
if (index > 0 && arrayProperty.arraySize > 0 && index - 1 < arrayProperty.arraySize) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am confused about an index that must be greater than zero and at least two elements from the end of the anway? Would recommend adding an inline comment if this is correct but some kind of special case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This somewhat doubled up from merging develop - should be clearer now :)
Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs
Show resolved
Hide resolved
As a side-note, when #1834 lands there will exist an interesting scenario for this functionality when the same asset is open simultaneously in two windows, both in Project Settings and in a free-floating Input Action Editor. |
Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CopyPasteHelper.cs
Show resolved
Hide resolved
@@ -159,6 +169,49 @@ public class ViewState | |||
public IEnumerable<InputControlScheme> controlSchemes; | |||
public int selectedControlSchemeIndex; | |||
} | |||
|
|||
void OnExecuteCommand(ExecuteCommandEvent evt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels like double work - do we handle events twice here? (additional to handling them in the InputActionsTreeView / InputActionMapsView)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you mean, could both be called with one action - I don't believe this is possible since we StopPropagation.
If you mean there's code overlap - I think I've now reduced the code in this section to the point where reducing it further would just mean adding an extra string comparison and function call to jump to the maps/actions views' OnExecuteCommand calls, but let me know what you think 🙂
On a somewhat related note to that - do we need the HasPastableClipboardData calls in OnExecuteCommand in ActionsTreeView/ActionMapsView? Won't that be checked anyway in one of the functions that PasteItems calls? It feels like that's logically where it should happen, if it doesn't already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it? Even with using the events on TrickleDown? If the second event is used OnBubbleUp this means we could catch the event beforehand.
I thought about a delegation concept when I said "do we handle events twice", a event handler somewhere that delegates to the list/treeView. It was more a rough idea, if the trickledown/bubbleup does not work out.
About your second comment: I think there is a safety check, and if we could indeed skip the one in the list/treeviews.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'm not sure what the problem you want to solve is - do you believe there's a way the event would be acted upon twice? If so, how? (I'm definitely new to the events system!) If it's just that you'd prefer the actual Paste command is only in one place, fair enough, but an intermediary handler to decide which View to send the command to would surely be more complex than what's here in the editor View?
Apologies if I'm entirely misunderstanding!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah - were you suggesting removing the Paste event handlers for the Action Maps/Actions, and having a single handler for the entire window? And then events from anywhere lower in the hierarchy can bubble up to the root?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that was what I was thinking of as one solution. The other way would be to catch the events at actionMap/actionTreeView on trickleDown, and stop the event propagation and then only if nothing was registered there we catch the rest of the events on bubble up on the root element to handle them from there.
For your reference: https://docs.unity3d.com/2021.2/Documentation/Manual/UIE-Events-Handling.html
This describes the event phases pretty well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Rita - Have pushed a couple changes, looks much better now I think!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think like that the logic to paste actions into action maps (and add them as last element) is broken because it is impossible to determine from outside of the actionMapView in wich list the paste was performed. Added @Pauliusd01
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finished for now. Two bugs not yet fixed are:
- BUG: trying to paste an action into empty map throws error:
--ArgumentException: '0' cannot be greater than -1. - BUG: trying to paste a modifier into empty map throws errror
--NullReferenceException: Object reference not set to an instance of an object
Once they are fixed it looks good.
Thanks @stefanunity - I believe these should both be fixed now, can you confirm? |
Unity_2024-02-22_14-11-34.mp4Cutting and pasting into an empty asset somehow "resurrects" all of the previously deleted actions. (I do deselect ProjectWideActions to confirm the auto save but that does not seem to help) |
Both are fixed now. |
The bug called out @Pauliusd01 doesn't really make any sense to me but should be fixed. Where is this coming from if not the copy buffer? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updating status - waiting for fixes
Description
Fix for ISX-1823.
Changes made
This was previously not working because the Paste command would only apply to the relevant Action Maps/Actions List/Tree, so if neither of those were focused, nothing would happen. We now also listen for Paste at the top level of the element hierarchy and send paste commands from there.
Notes
Issues:
• Undoing adding an Action Map/Action leaves the list unselected. Pasting at that point fails because the state thinks there's still a valid item selected. Mentioned here, and should be added as a separate bug.
• Currently won't work if the window is tabbed to - user has to click somewhere in the window. Think I'll need to ask UITK team about this.
Checklist
Before review:
Changed
,Fixed
,Added
sections.([case %number%](https://issuetracker.unity3d.com/issues/...))
.Area_CanDoX
,Area_CanDoX_EvenIfYIsTheCase
,Area_WhenIDoX_AndYHappens_ThisIsTheResult
.During merge:
NEW: ___
.FIX: ___
.DOCS: ___
.CHANGE: ___
.RELEASE: 1.1.0-preview.3
.