FilenameEditField.st
author claus
Mon, 10 Oct 1994 04:13:51 +0100
changeset 24 6704fad5eb7d
parent 16 7a977f95170b
child 25 e07adf47d209
permissions -rw-r--r--
*** empty log message ***

"
 COPYRIGHT (c) 1994 by Claus Gittinger
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

EditField subclass:#FilenameEditField 
       instanceVariableNames:''
       classVariableNames:   ''
       poolDictionaries:''
       category:'Views-Text'
!

FilenameEditField comment:'
COPYRIGHT (c) 1994 by Claus Gittinger
              All Rights Reserved

$Header: /cvs/stx/stx/libwidg2/FilenameEditField.st,v 1.4 1994-10-10 03:13:10 claus Exp $
'!

!FilenameEditField class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1994 by Claus Gittinger
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

version
"
$Header: /cvs/stx/stx/libwidg2/FilenameEditField.st,v 1.4 1994-10-10 03:13:10 claus Exp $
"
!

documentation
"
    like a normal editField, but does filename-completion on the last word of
    the contents, when TAB is pressed.
"
! !

!FilenameEditField methodsFor:'events'!

keyPress:key x:x y:y
    "handle tab for filename completion"

    |s f matchSet name words|

    enabled ifTrue:[
        key == #Tab ifTrue:[
            s := self contents.
            "
             find the last word ...
            "
            words := s asCollectionOfWords.
            f := words last asFilename.
            matchSet := f filenameCompletion.
            matchSet size ~~ 1 ifTrue:[
                "
                 more than one possible completion -
                "
                self changed:#directory with:f directoryName.
                device beep
            ].
            "
             even with more than one possible completion,
             f's name is now common prefix
            "
            name := f asString.
            matchSet size == 1 ifTrue:[
                "
                 exactly one possible completion -
                "
                f isDirectory ifTrue:[
                    (name endsWith:(Filename separator)) ifFalse:[
                        name := (f construct:'') asString
                    ].
                ].
            ].
            "
             construct new contents, by taking
             last words completion
            "
            s := ''.
            1 to:(words size - 1) do:[:idx |
                s := s , (words at:idx) , ' '
            ].
            s := s , name.
            self contents:s.
            self cursorToEndOfLine.
            ^ self
        ].
    ].
    ^ super keyPress:key x:x y:y.
! !