(Un)doing the Impossible
Undo is always nice for users, but can be hard for developers. Luckily, this is made easier in Cocoa by NSUndoManager and its prepareWithInvocationTarget method (NSInvocation is great). With this technique, you can just store one method call for the undo reversal. But it’s common to have actions that affect files-and these aren’t as easy to undo. I ran into this in Lexicon for managing LanguageSyncs, which are like dictionary files that are available in many different languages.

In Lexicon, you can remove LanguageSyncs (with the minus button), and they are deleted. I wanted to make this action undoable like the rest of the interface. The solution is pretty simple. In the folder where LanguageSyncs are stored, I created a hidden folder (.Remove). When a LanguageSync is “deleted” I just move it there. When Lexicon is quit or launched, it checks for this folder and deletes it. This means you can undo removing a LanguageSync just like any other action-the fact that you are adding and removing files is an implementation detail and should be transparent to the user.