How to execute undo for some glyphs via code?



  • Sorry, maybe it is obvious, but I couldn't find it in the documentation.
    I possible something like that? (executing Edit>Undo for some glyph ?) if yes, how to do it?

    font = CurrentFont()
    g = font['a'].execUndo()
    

    Cheers


  • admin

    why would you want to call undo separately?

    fontParts has no api for this, maybe it should...

    this is the internal way calling undo:

    f = CurrentFont()
    
    m = f.document().getUndoManagerForGlyph_(f["a"].naked())
    m.undo()
    


  • great, thanks!

    I have a tool, that has my own custom edit window which works quite differently than the default Glyph Window.
    I wanted to add undo/redo functionality to it because it is more convenient than swapping between my tool and the edit window only for this.


  • admin

    then you dont need to call undo :) but you have to add undo items while editing.

    glyph = CurrentGlyph()
    # in RF 3.2
    with glyph.undo("changed spacing"):
        glyph.leftMargin += 10
        glyph.rightMargin += 10
    

    this will 'record' the change, add an menu item.

    good luck!