[4.1] undo/redo in media manager#30511
Conversation
|
I have tested this item ✅ successfully on 4b2b742 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/30511. |
|
Didn't do a code review, @dgrammatiko any feedback? |
|
The code seems fine. Although when I added the
EDIT The current implementation actually stores the plugin state so that's ok (the second point) |
Co-authored-by: Quy <quy@fluxbb.org>
|
I have added a length limit option. |
|
@dgrammatiko As for the first point, I believe I have already solved this by changing the events on which the history points are stored. They are only sent once a change has been made and not multiple times during the change how it was implemented before. For the last point I have added an option in the settings to limit the history length. To restore the plugins state, I'm still trying to figure out a solution. I do store the plugins state, but since the changed image is rendered and stored every time the plugin changes, I would need to somehow go over each plugin and apply the changes to the original image again. So for example, if my first change is cropping the image, and then I switch to resize and change the size, I'm applying this to the already cropped image. If I go back to the crop plugin, I would need to apply the crop to the original image to allow the user to extend the crop area, but then I would also need to apply resize (and all other changes made in other plugins) to the original image as well. Any thougths? |
|
@vlaucht I think there is a fundamental piece missing here, you need to register the plugin execution function with their payload in order to replay them. A thought experiment, that will probably work in this context is like: // Create an API point that all plugins run in order to execute a command
// Execute Plugin Command
Joomla.MediaManager.execCommand = (command, payload) => {
new Promise(command({ ...payload }))
.then(resolve => storeToHistory)
.catch(rollbackLastHistoryEntry);
};
// The history store also needs to change a little bit like
// I think what you have right now is an array of {file: 'string', data: 'string'}
which should become
{
file: 'string',
data: 'string',
command: 'string',
payload: {}
}
// Maybe also you need to store the plugin name and the tab index
// So you could safely switch to the right context (execCommand will need to switch plugins iirc)The combination of these changes should allow you to replay safely any plugin command. Of course, quite some checks need to be implemented but I think this approach is viable |
|
Right now it stores the following: So do you mean I need to implement an exec function and then run it for each plugin in order to restore the images state? |
I think it's safe to assume that there might be some intermediate functions in the chain of execution. Eg an input has an |
That's the reason for a promise based solution. I had a comment
Not all commands will be always executable and that is expected (also in photoshop you don't get to redo everything), thus the catch part, you can throw am alert, something like |
|
I've allowed myself to fix the conflicts here because they were caused by the recent merge of my PR #30373 . |
|
@vlaucht there are now some styling issues, can you have a look on them? Then I would do another round of tests. If all is ok, would be nice to get that in. If there are then still some tasks open, we can do them in a followup pr or open an issue. |
|
When you make a change without the patch applied, clicking the reset button returns you back to the first history point (original loading of the image you're editing). When you make a change with the patch applied, clicking the reset button does nothing now.
Aside from that, very nice addition to the Media Manager. |
|
I have tested this item 🔴 unsuccessfully on 7034307 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/30511. |
Save is a destructing actions or plain English: reset only works from the last loaded image (when you hit save the saved image is your new starting point). That was the initial implementation AFAIR so there is nothing broken here |
|
I have tested this item 🔴 unsuccessfully on 7034307 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/30511. |
This comment was marked as abuse.
This comment was marked as abuse.
|
This pull request has automatically rebased to 4.2-dev. |
|
Good idea, thanks for proposing the feature. Closing this PR because of inactivity for a longer time. |
|


Pull Request for Issue # .
Summary of Changes
Added Undo/Redo functionality for MediaManager Plugins.

All changes will be saved in a history, and can then be undone or redone with the buttons in the menu.
This could also be used to preserve the state of the plugin. As of now, if a change has been made and then the plugin is switched, the changes will be applied in a destructive way, and returning back to the plugin does not allow to return to the original state (For example: crop an image, switch to resize, go back to cropping and you will find, that it is not possible to extend the cropped area back to the images original size). The history stores the plugin state as well, and this could be used in a later PR to restore the state of the plugin.
Testing Instructions
Edit an image in the MediaManager and click undo or redo in the menu to revert or redo the changes.