Example #1
0
    def redo(self):
        ''' Redoes the last undo operation. Use can_redo to check whether a call
        to this function will have any effect.
        '''

        if not self._redos: return None
        action = self._redos.pop()
        if isinstance(action, Insert):
            self._undos.append(action)
            UnformattedDocument.insert_text(self, action.start, action.text)
            return action.end
        elif isinstance(action, Delete):
            self._undos.append(action)
            UnformattedDocument.delete_text(self, action.start, action.end)
            return action.start
        return None
Example #2
0
    def insert_text(self, start, text, attributes=None):
        '''Insert text into the document.

        :Parameters:
            `start` : int
                Character insertion point within document.
            `text` : str
                Text to insert.
            `attributes` : dict
                Optional dictionary giving named style attributes of the
                inserted text.

        '''
        if self._undoable_action:
            action = Insert(start,text) 
            if self._undos:
                last = self._undos[-1]
                if not last.merge(action):
                    self._undos.append(action)
            else:
                self._undos.append(action)
            #print self._undos
        UnformattedDocument.insert_text(self, start, text, attributes)