GNOME Bugzilla – Bug 139989
copy-visible should not be undoable
Last modified: 2004-04-15 08:08:50 UTC
The copy-visible script produces an entry in the undo history, and there is no reason for this, because it leaves the image unchanged.
Probably a trivial change. Should be considered for 2.0.2 if it's really trivial.
This does not look like a trivial change, unfortunately. When you invoke Edit->Copy Visible, the script copy-visible.scm duplicates the visible layers, merges them (gimp-image-merge-visible-layers), copies the result and then deletes that temporary layer. It is necessary to push an undo group in order to be able to perform all these operations. The image is in the same state before and after the invocation of the script, but an undo group is pushed on the stack so the image is marked as being modified (dirty). I did not find an easy workaround: replacing gimp-image-undo-group-{start,end} by gimp-image-undo-{freeze,thaw} or gimp-image-undo-{disable,enable} do not help: the dirty flag is always set on the image and using undo-{disable,enable} only makes the problem worse by showing an empty undo history but still a dirty image. The only solution that I can think about right now would be to make gimp_image_undo() and gimp_image_redo() available through the PDB. This would be useful anyway for a future macro recorder. And then the script could call gimp-image-undo after calling gimp-image-undo-group-end. This is a hack, but I cannot find a better solution. Also, this would probably be the only way to ensure that the image is exactly in the same state as it was before even if the script is not perfect (e.g., if a layer mask, channel or path was active before the script was invoked). If the solution requires some additions to the PDB, do we keep the milestone to 2.0.2 or bump it to 2.2? These are additions, not changes, but I am not sure about what is best here.
I think it's worth noting the relation between bug #116145 and this one.
Trivial workaround: Duplicate the image before messing with the layers. It even might make the script a lot easier.
Yes, we should duplicate the image or if that's not feasible, close this report as WONTFIX.
Created attachment 26650 [details] New version of copy-visible.scm This new version of the script is shorter and copies the image first. Please test.
The attached script just crashed here. ERROR wta(non-symbol) to setvar (see errobj) It worked with a single layer. Crashed with 2 layers.
Strange... Could you describe the steps to reproduce this problem? I tried the script with 1, 2, 3 and many layers and it worked for me (with or without hidden layers, with or without an active selection, etc.)
Oh, shoot! Sorry, I see now that I had attached the wrong version of the script to this bug report. Of course, it worked for me and it could not work for you...
Created attachment 26655 [details] Correct version of copy-visible.scm (hopefully) Let's see if it works better this time...
Just worked fine. :-) There we go....
If there are no objections, I will commit this later today. By the way, I was not sure about what to do with the copyright and the date. I re-wrote most of the code, but I kept the same API as before so I left the original authors there.
I think it is more than fair that you add your name in there. Or add a comment that reads "Heavily rewritten by Raphaël Quinet"
Well, I had already mentioned in a comment that I had rewritten most of the code from scratch (mentioning these significant changes would be required by the GPL anyway). In fact, I only kept the API for registering, but the code itself is new. I was wondering about whether I should keep the original authors in the call to script-fu-register since the code is new, but in the end I left everybody there. 2004-04-14 Raphaël Quinet <quinet@gamers.org> * plug-ins/script-fu/scripts/copy-visible.scm: New version of the script that works on a temporary copy of the image instead of copying the visible layers. Fixes bug #139989. Main advantages of the new code: it fixes this bug and it is smaller and easier to understand. Disadvantage: without copy-on-write, it wastes memory if the original image has many hidden layers. Should I merge this to the new gimp-2-0 branch?
Yes, please commit to gimp-2-0 as well.