Exemplo n.º 1
0
    def contents_cbk(self, text):
        
        """External editor invokes that callback to inform VoiceCode
        of the buffer contents.

        **INPUTS**
                
        STR *text* -- Text to be inserted

        **OUTPUTS**
        
        *none* -- 
        """
        if self._not_cached('get_text'):               
# if we don't have the buffer contents cached, we don't know what text 
# was replaced, so we can't create a reverse diff, and all our previous
# change_history is invalid
            debug.trace('SourceBuffWithDiffs.contents_cbk',
                'not cached')

# if the text isn't cached, then the stacks should already be clear,
# but just for good measure
            self.clear_stacks()
            if self.undoing:
                # this should REALLY never happen, but if it does,
                # there is no good way to handle it
                msg = 'WARNING: SourceBuffWithDiffs.contents_cbk called\n'
                msg = msg + 'while undoing changes, with NO CACHED TEXT.\n'
                msg = msg +'.  Please report this as a bug\n'
                debug.critical_warning(msg)
            SourceBuffCached.contents_cbk(self, text)
            return
        
# otherwise, treat this as an insert callback
        start, end, change = \
               find_difference.find_difference(self.cache['get_text'], text)
        self.insert_cbk(range = (start, end), text = change)