brendand / mbtablegrid

An NSControl subclass which provides a spreadsheet-style table grid
9 stars 3 forks source link

Add undo/redo support #44

Closed brendand closed 9 years ago

brendand commented 9 years ago

If you fill up or down, you can easily lose data. Especially if you meant to simply select the rows but you accidentally initiated the fill command. So we need to be able to keep track of all the previous values and call tableGrid:setObjectValue:forColumn:row if the user uses the Undo command. The same goes for adding or deleting rows.

Dejal commented 9 years ago

Done basic undo/redo support.

It now supports Undo and Redo for all situations that edit cells (e.g. entering values, toggling checkboxes, etc), in addition to filling.

Not perfect; the selected cell isn't changed when undoing, like Numbers does. And if rows are added during a fill, they aren't removed when undoing the fill. I could see if I can make those enhancements if you wish.

brendand commented 9 years ago

Yes, removing any added rows would be helpful. And also re-adding any rows if you redo. The biggest issue to be handled was for filling because that can cause data loss if you accidentally fill down when you just meant to drag/select a bunch of cells. Great stuff!

Dejal commented 9 years ago

Done; it will now remove any added rows when undoing the fill, and re-add them when redoing. It also adjusts the selection to match undoing/redoing the fill, like in Numbers.

brendand commented 9 years ago

:+1: