Changeset 1268

Show
Ignore:
Timestamp:
04/17/08 22:07:51 (7 months ago)
Author:
rob
Message:

Refs #408: added a single storage spot for last search

Location:
trunk/peppy
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/peppy/actions/minibuffer.py

    r1266 r1268  
    9696        self.win.SetFocus() 
    9797     
     98    def closePreHook(self): 
     99        """Hook called when minibuffer is about to be closed to allow it to 
     100        save any persistent data. 
     101        """ 
     102        pass 
     103     
    98104    def close(self): 
    99105        """ 
    100106        Destroy the minibuffer widgets. 
    101107        """ 
     108        self.closePreHook() 
    102109        self.win.Destroy() 
    103110        self.win=None 
  • trunk/peppy/plugins/find_replace.py

    r1265 r1268  
    2626    backward = "Find Backward" 
    2727     
    28     def __init__(self, parent, frame, stc, initial='', direction=1): 
     28    def __init__(self, parent, frame, stc, storage=None, direction=1): 
    2929        wx.Panel.__init__(self, parent, style=wx.NO_BORDER|wx.TAB_TRAVERSAL) 
    3030        self.frame = frame 
    3131        self.stc = stc 
     32        if isinstance(storage, dict): 
     33            self.storage = storage 
     34        else: 
     35            self.storage = {} 
    3236         
    3337        sizer = wx.BoxSizer(wx.HORIZONTAL) 
     
    4650        self.text.Bind(wx.EVT_TEXT_ENTER, self.OnEnter) 
    4751        self.text.Bind(wx.EVT_TEXT, self.OnChar) 
    48  
    49         if initial: 
    50             self.text.ChangeValue(initial) 
    5152     
    5253    def setDirection(self, dir=1): 
     
    186187        self.OnNotFound() 
    187188 
    188  
     189    def repeat(self, direction): 
     190        if not self.getSearchString(): 
     191            if 'last_search' in self.storage: 
     192                self.text.ChangeValue(self.storage['last_search']) 
     193                self.text.SetInsertionPointEnd() 
     194                return 
     195             
     196        if direction < 0: 
     197            self.setDirection(-1) 
     198            self.OnFindP(None) 
     199        else: 
     200            self.setDirection(1) 
     201            self.OnFindN(None) 
     202     
     203    def saveState(self): 
     204        last = self.getSearchString() 
     205        if last: 
     206            self.storage['last_search'] = last 
    189207 
    190208 
     
    193211    Adapter for PyPE findbar.  Maps findbar callbacks to our stuff. 
    194212    """ 
     213    search_storage = {} 
     214     
    195215    def createWindow(self): 
    196216        # Create the find bar widget. 
     
    199219        else: 
    200220            dir = 1 
    201         self.win = FindBar(self.mode.wrapper, self.mode.frame, self.mode, direction=dir) 
     221        self.win = FindBar(self.mode.wrapper, self.mode.frame, self.mode, self.search_storage, direction=dir) 
    202222     
    203223    def repeat(self, action): 
     
    205225        dprint(action) 
    206226        if action.__class__ == FindPrevText: 
    207             self.win.setDirection(-1) 
    208             self.win.OnFindP(None) 
    209         else: 
    210             self.win.setDirection(1) 
    211             self.win.OnFindN(None) 
     227            self.win.repeat(-1) 
     228        else: 
     229            self.win.repeat(1) 
    212230 
    213231    def focus(self): 
     
    215233        # to the text ctrl or combo box of the pype findbar. 
    216234        self.win.text.SetFocus() 
     235     
     236    def closePreHook(self): 
     237        self.win.saveState() 
     238        self.dprint(self.search_storage) 
    217239 
    218240