Changeset 150

Show
Ignore:
Timestamp:
03/08/08 01:01:27 (10 months ago)
Author:
tal
Message:
Better behavior when the user is deleting text.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • packages/defconAppKit/trunk/Lib/defconAppKit/views/glyphNameComboBox.py

    r147 r150  
    11from AppKit import * 
    22import vanilla 
     3 
    34 
    45class GlyphNameComboBox(vanilla.EditText): 
     
    89        self._font = font 
    910        self._finalCallback = callback 
     11        self._currentText = "" 
    1012 
    1113    def _breakCycles(self): 
     
    1517 
    1618    def _textInputCallback(self, sender): 
    17         input, match = self._searchForMatch(self.get()) 
     19        input = sender.get() 
     20        deleting = False 
     21        if len(input) <= len(self._currentText): 
     22            if self._currentText.startswith(input): 
     23                deleting = True 
     24        self._currentText = input 
     25        input, match = self._searchForMatch(input, deleting=deleting) 
    1826        if match is None: 
    1927            return 
     
    2533            window = textField.window() 
    2634            fieldEditor = window.fieldEditor_forObject_(True, textField) 
    27             fieldEditor.setSelectedRange_((selectionStart, selectionLength)) 
     35            if not deleting: 
     36                fieldEditor.setSelectedRange_((selectionStart, selectionLength)) 
    2837        if self._finalCallback is not None: 
    2938            self._finalCallback(self) 
    3039 
    31     def _searchForMatch(self, text): 
     40    def _searchForMatch(self, text, deleting=False): 
    3241        # no text 
    3342        if not text: 
     
    4756        if match is None: 
    4857            glyphNames = list(sorted(glyphNames)) 
    49             for glyphName in glyphNames: 
    50                 if glyphName.startswith(text): 
    51                     match = glyphName 
    52                     break 
     58            if not deleting: 
     59                for glyphName in glyphNames: 
     60                    if glyphName.startswith(text): 
     61                        match = glyphName 
     62                        break 
     63            else: 
     64                for glyphName in glyphNames: 
     65                    if text.startswith(glyphName): 
     66                        match = glyphName 
     67                    elif match is not None: 
     68                        break 
    5369        return text, match 
    5470 
    55