示例#1
0
    def restore_state(self, cookie):
        """
        restores the buffer to its state at the time when
        the cookie was returned by store_current_state.  Both the
        contents and the selection will be restored.  However, other
        data, such as the search history, may not.  The restore
        operation can fail, which will be indicated by a return value of
        0, so the caller should always check the return value.
        
        **INPUTS**

        *SourceBuffState cookie* -- see above.

        **OUTPUTS**

        *BOOL* -- true if restore was successful

        """
        debug.trace('SB_ServiceFullState.restore_state', 'cookie=%s' % cookie)
        debug.trace('SB_ServiceFullState.restore_state',
                    'buffer %s' % self.buff.name())
        if not self.valid_cookie(cookie):
            return 0
        if debug.trace_is_active('SB_ServiceFullState.restore_state'):
            contents = cookie.contents()
            first_lines = re.match(r'.*\n.*\n', contents).group()
            last_lines = re.search(r'\n.*\n.*\n?$', contents).group()

        self.buff.set_text(cookie.contents())

        self.buff.set_selection(cookie.get_selection(),
                                cursor_at=cookie.cursor_at())
        self.buff.print_buff_if_necessary()
        self.buff.last_search = cookie.last_search()
        return 1
示例#2
0
    def store_current_state(self):
        """stores the current state of the buffer, including both the
        contents and the current selection, for subsequent restoration.
        Store_current_state returns a "cookie" which can be passed to
        restore_state or compare_with_current.  The type and attributes
        of the cookie will depend on the specific subclass of
        SourceBuff.  In the most straightforward implementation, it 
        may include a copy of the entire contents of the
        buffer and the selection.  In other cases, particularly when the
        editor or SourceBuff provides an internal undo stack, it may simply be a
        reference to a point in this stack.
        
        Important Notes:
        
        You should only pass the cookie to methods of
        the SAME SourceBuff object from which it came.  Generally,
        cookies can not be pickled and retrieved.

        The type of cookie will vary with the concrete subclass 
        of SourceBuff.  The corresponding class object is 
        returned by _state_cookie_class.  However, external callers
        should not depend on the type, attributes, or methods 
        of the cookie.

        **INPUTS**

        *none*

        **OUTPUTS**

        *SourceBuffState* -- state cookie (see above)
        """
        selection = self.buff.get_selection()
        pos = self.buff.cur_pos()
        if pos == selection[0]:
            cursor_at = 0
        else:
            cursor_at = 1
        debug.trace('SB_ServiceFullState.store_current_state',
                    'buffer %s' % self.buff.name())
        #        debug.trace('SB_ServiceFullState.store_current_state',
        #            '%s: contents = \n%s\n' % (self.buff.name(), self.buff.contents()))
        if debug.trace_is_active('SB_ServiceFullState.store_current_state'):
            contents = self.buff.contents()
            first_lines = re.match(r'.*\n.*\n', contents).group()
            last_lines = re.search(r'\n.*\n.*\n?$', contents).group()
        cookie = SourceBuffState.SourceBuffState(
            buff_name=self.buff.name(),
            contents=self.buff.contents(),
            selection=selection,
            cursor_at=cursor_at,
            last_search=self.buff.last_search)
        return cookie
示例#3
0
    def store_current_state(self):
        """stores the current state of the buffer, including both the
        contents and the current selection, for subsequent restoration.
        Store_current_state returns a "cookie" which can be passed to
        restore_state or compare_with_current.  The type and attributes
        of the cookie will depend on the specific subclass of
        SourceBuff.  In the most straightforward implementation, it 
        may include a copy of the entire contents of the
        buffer and the selection.  In other cases, particularly when the
        editor or SourceBuff provides an internal undo stack, it may simply be a
        reference to a point in this stack.
        
        Important Notes:
        
        You should only pass the cookie to methods of
        the SAME SourceBuff object from which it came.  Generally,
        cookies can not be pickled and retrieved.

        The type of cookie will vary with the concrete subclass 
        of SourceBuff.  The corresponding class object is 
        returned by _state_cookie_class.  However, external callers
        should not depend on the type, attributes, or methods 
        of the cookie.

        **INPUTS**

        *none*

        **OUTPUTS**

        *SourceBuffState* -- state cookie (see above)
        """
        selection = self.buff.get_selection()
        pos = self.buff.cur_pos()
        if pos == selection[0]:
            cursor_at = 0
        else:
            cursor_at = 1
        debug.trace('SB_ServiceFullState.store_current_state',
            'buffer %s' % self.buff.name())
#        debug.trace('SB_ServiceFullState.store_current_state',
#            '%s: contents = \n%s\n' % (self.buff.name(), self.buff.contents()))
        if debug.trace_is_active('SB_ServiceFullState.store_current_state'):
            contents = self.buff.contents()
            first_lines = re.match(r'.*\n.*\n', contents).group()
            last_lines = re.search(r'\n.*\n.*\n?$', contents).group()
        cookie = SourceBuffState.SourceBuffState(buff_name = self.buff.name(), 
            contents = self.buff.contents(), 
            selection = selection, cursor_at = cursor_at,
            last_search = self.buff.last_search)
        return cookie
示例#4
0
    def restore_state(self, cookie):
        """
        restores the buffer to its state at the time when
        the cookie was returned by store_current_state.  Both the
        contents and the selection will be restored.  However, other
        data, such as the search history, may not.  The restore
        operation can fail, which will be indicated by a return value of
        0, so the caller should always check the return value.
        
        **INPUTS**

        *SourceBuffState cookie* -- see above.

        **OUTPUTS**

        *BOOL* -- true if restore was successful

        """
        debug.trace('SB_ServiceFullState.restore_state', 'cookie=%s' % cookie)
        debug.trace('SB_ServiceFullState.restore_state',
            'buffer %s' % self.buff.name())
        if not self.valid_cookie(cookie):
            return 0
        if debug.trace_is_active('SB_ServiceFullState.restore_state'):
            contents = cookie.contents()
            first_lines = re.match(r'.*\n.*\n', contents).group()
            last_lines = re.search(r'\n.*\n.*\n?$', contents).group()
                    
        self.buff.set_text(cookie.contents())
        
        
        self.buff.set_selection(cookie.get_selection(), cursor_at =
            cookie.cursor_at())
        self.buff.print_buff_if_necessary()
        self.buff.last_search = cookie.last_search()
        return 1