def __init__(self, parent, settings):
     """ Initialize the Cursor Command Wrapper with its parent """
     self.cursor = parent.cursor
     self.textStore = parent.textStore
     self.settings = settings
     
     self.actionListManager = ActionListManager()
     self.addCommandsToParent(parent)
class TextStoreCommandWrapper:
    """ Wrapper for Text Store Commands """
    
    def __init__(self, parent, settings):
        """ Initialize the Cursor Command Wrapper with its parent """
        self.cursor = parent.cursor
        self.textStore = parent.textStore
        self.settings = settings
        
        self.actionListManager = ActionListManager()
        self.addCommandsToParent(parent)
        
    def addCommandsToParent(self, parent):
        """ Add commands to the parent """
        commands = {"addString":InsertTextAction,
                    "addLine":InsertNewlineAction,
                    "addTab":InsertTabAction,
                    "remove":RemovePreviousTextAction,
                    "delete":RemoveNextTextAction,
                    "removeTab":RemoveTabAction}
                    
        for command in commands:
            actionClass = commands[command]
            actionFunction = self.makeTextStoreActionEventFunction(actionClass)
            setattr(self, command, actionFunction)
            setattr(parent, command, getattr(self, command))
            
        parent.undo = self.undo
        parent.redo = self.redo
            
    def makeTextStoreActionEventFunction(self, actionClass):
        def performAction(event):
            action = actionClass(self.cursor, self.textStore, self.settings, event)
            if action.isDoable():
                action.do()
                self.actionListManager.addAction(action)
        return performAction
        
    def undo(self, event=None):
        """ Undo the previous action """
        self.actionListManager.undoPreviousAction()
        
    def redo(self, event=None):
        """ Redo the last undone action """
        self.actionListManager.redoPreviousAction()