                          name: "theme",
                          object: nil)
 
+        deckUndoManager = window?.undoManager
         initKeyboardShortcuts()
     }
 

    @IBAction func clickCard(sender: NSTableView) {
        guard sender.clickedRow >= 0 else { return }
        let card = currentDeck!.sortedCards[sender.clickedRow]
        currentDeck!.removeCard(card)

        isSaved = false

        deckCardsView.reloadData()
        cardsCollectionView.reloadData()
        curveView.reload()
    }

    func addCardToDeck(card: Card) {


        if deckCard == nil || currentDeck!.isArena ||
            (deckCard!.count == 1 && card.rarity != .Legendary) {

            redoCardAdd(card)
        }
    }
    
    // MARK: - Undo/Redo
    func undoCardAdd(card: AnyObject) {
        if let c = card as? Card {
            deckUndoManager?.registerUndoWithTarget(
                self, selector: #selector(EditDeck.redoCardAdd(_:)), object: card)
            
            if deckUndoManager?.undoing == true {
                deckUndoManager?.setActionName(NSLocalizedString("Add Card", comment: ""))
            } else {
                deckUndoManager?.setActionName(NSLocalizedString("Remove Card", comment: ""))
            }
            
            currentDeck?.removeCard(c)
            curveView.reload()
            deckCardsView.reloadData()
            cardsCollectionView.reloadData()
            countCards()
            isSaved = false
        }
    }
    
    func redoCardAdd(card: AnyObject) {
        if let c = card as? Card {
            deckUndoManager?.registerUndoWithTarget(
                self, selector: #selector(EditDeck.undoCardAdd(_:)), object: card)
            
            if deckUndoManager?.undoing == true {
                deckUndoManager?.setActionName(NSLocalizedString("Remove Card", comment: ""))
            } else {
                deckUndoManager?.setActionName(NSLocalizedString("Add Card", comment: ""))
            }
            
            currentDeck?.addCard(c)
            curveView.reload()
            deckCardsView.reloadData()
            cardsCollectionView.reloadData()
