Bug 565767 - Cannot undo a copy resource action
Summary: Cannot undo a copy resource action
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: IDE (show other bugs)
Version: 4.17   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-08-02 20:17 EDT by Andrew Obuchowicz CLA
Modified: 2020-08-12 17:27 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Obuchowicz CLA 2020-08-02 20:17:47 EDT
When using the Project Explorer, a file copy cannot be undone. It seems that the Resource Operation is being executed without an IOperationHistory (which would provide the undo functionality). 

Providing undo here doesn't seem like it'd be too difficult of a task.

Comparing MoveProjectAction's performMove to CopyFilesAndFoldersOperation's performCopy, it seems that MoveProjectAction is executing the operation like so:

PlatformUI.getWorkbench().getOperationSupport()	.getOperationHistory().execute(op1, monitor,					WorkspaceUndoUtil.getUIInfoAdapter(shellProvider.getShell()));  

And CopyFilesAndFoldersOperation is executing the operation by doing:

op.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(messageShell));

Not only would this fix benefit the IDE from a UX standpoint, but it'd also benefit RCP application's who reuse the copy action from Platform.

If this is desired, I can provide a Gerrit :)
Comment 1 Eclipse Genie CLA 2020-08-02 20:31:02 EDT
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.ui/+/167150
Comment 2 Andrew Obuchowicz CLA 2020-08-02 20:35:24 EDT
Ahh I guess I ignored the big comment:
"If we are copying files and folders, do not execute the operation in the undo history, since the creation of a new file is not added to undo history and modification of a file is not added to the same undo history and therefore a redo cannot be properly done. Just execute it directly so it won't be added to the undo history."

Maybe there's still a way to either fix the underlying issue ("creation of a new file is not added to undo history and modification of a file is not added to the same undo history"). Or still provide API for those who want to provide undo/redo in their RCP applications

In my quick testing.. I didn't seem to find any issues with undo/redo for copying files and folders, so that might be promising.
Comment 3 Andrew Obuchowicz CLA 2020-08-07 15:31:00 EDT
Does anyone have an opinion or comment regarding this topic?

Ideally, I'd like to allow undo/redo of copy resources in the IDE. 
However, I could settle for adding new API to perform a copy resource action that is undoable.
Comment 4 Lars Vogel CLA 2020-08-09 06:43:28 EDT
(In reply to Andrew Obuchowicz from comment #3)
> Does anyone have an opinion or comment regarding this topic?

No opinion, patch looks OK to me, just ensure that undo / redo works and remove the comment if it does.
Comment 5 Andrew Obuchowicz CLA 2020-08-12 17:19:04 EDT
So it seems undo/redo was disabled for copy resource actions in Bug 460698.

The issue of that bug was that a user could modify a file after having copied it, then undo the copy action from the project explorer and loose all local changes to the copy.

This issue still exists, and is sadly a blocker ): 

Perhaps there's some way to attach a document listener that will remove the undo operation from the stack if the document was modified?

Or perhaps the undo/redo implementation of CopyResourcesOperation needs to be improved to account for this case.
Comment 6 Andrew Obuchowicz CLA 2020-08-12 17:27:40 EDT
In CopyResourcesOperation.computeUndoableStatus, we might be able to check if the target resources modification timestamp has changed which would indicate the user modified the copied resource and the undo shouldn't be allowed.