UNSOLVED Tracking Undo/Redo-History for the custom attributes



  • Hey Guys,
    I have a class, with a list as a custom attribute:

    from mojo.events import EditingTool, installTool
    
    class MyTool(EditingTool):
        def __init__(self):
            super().__init__()
            self.specialPoints = [] # My Custom Attribute
    

    This attribute will contain set of points that should be selected by a user.
    At some point this class adds selected points to this list

    def additionContextualMenuItems(self):
        return [("Create Special Point", self.createSpecialPoint)]
    
    def createSpecialPoint(self, sender):
        g = CurrentGlyph()
        for p in g.selection:
            self.specialPoints.append(p)
    
    

    Is there any way to track this action, so If the user will use Undo/Redo, the points will be deleted form the list or re-added to the list in the right order? Also this Undo/Redo should still track other actions of course.

    I think I should use didUndo(), but how?

    I was thinking of tracking changes by adding the labels, but changes in the labels are not tracked by history related events.

    Thanks in advance for the help!


  • admin

    the font.lib is also possible but then its hard to have the global undo manager focus. The current undo manager is connected to the current glyph.

    good luck!


  • admin

    store your data in the glyph.lib if you want undo powers



  • a new version of Undo looks really nice. Unfortunately, It doesn't work in my case.
    This action is not connected with a glyph or a font, so I cannot track it with prepare/performUndo.
    I will maybe try to use a font.lib dictionary, although I don't know if it can be tracked. I will keep you posted if it worked


  • admin

    you have to wrap your actions inside:

    glyph.prepareUndo("Moved By 100, 100")
    glyph.moveBy((100, 100)
    glyph.performUndo()
    

    see RGlyph.performUndo

    in the next release (RF3.2) you can use:

    with glyph.Undo("Moved By 100, 100")
        glyph.moveBy((100, 100)
    

Log in to reply