FileSelectionBox.st
author claus
Thu, 16 Dec 1993 12:04:09 +0100
changeset 12 1c8e8c53e8cf
parent 7 15a9291b9bd0
child 21 9ef599238fea
permissions -rw-r--r--
*** empty log message ***

"
 COPYRIGHT (c) 1990 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.
"

ListSelectionBox subclass:#FileSelectionBox
       instanceVariableNames:'patternField'
       classVariableNames:''
       poolDictionaries:''
       category:'Views-Interactors'
!

FileSelectionBox comment:'

COPYRIGHT (c) 1990 by Claus Gittinger
              All Rights Reserved

$Header: /cvs/stx/stx/libwidg/FileSelectionBox.st,v 1.5 1993-12-16 11:02:38 claus Exp $
written Jan 90 by claus
'!

!FileSelectionBox class methodsFor:'documentation'!

documentation
"
this class implements file selection boxes. Instances show a list of
files, and perform an action block with the selected pathname as
argument when ok is clicked.

There is an optional PatternField, which shows itself when a pattern
is defined. If there is such a pattern, only files matching the pattern
will be shown in the list (and directories).
"
! !

!FileSelectionBox class methodsFor:'defaults'!

listViewType
    "return the type of listView - using a FileSelectionList here"

    ^ FileSelectionList
! !

!FileSelectionBox methodsFor:'initialization'!

initialize
    super initialize.

    labelField extent:(0.7 @ labelField height).
    labelField label:(resources string:'select a file:').
    labelField adjust:#left.

    patternField := EditField
                        origin:(0.7 @ labelField origin y)
                        corner:(1.0 @ labelField corner y)
                            in:self.
    patternField initialText:'*'.
    patternField leaveAction:[:p | self updateList].
    patternField hidden:true.

    selectionList action:[:line |
        |entry|

        entry := selectionList selectionValue.
        enterField contents:entry
    ].
    selectionList doubleClickAction:[:line |
        |entry|

        entry := selectionList selectionValue.
        enterField contents:entry.
        self okPressed
    ].

    "FileSelectionBox new show"
! !

!FileSelectionBox methodsFor:'accessing'!

directory:nameOrDirectory
    "change the directory shown in the list"

    selectionList directory:nameOrDirectory
!

pattern:aPattern
    "set the pattern - this enables the PatternField."

    patternField initialText:aPattern.
    selectionList pattern:aPattern.
    aPattern isNil ifTrue:[
        patternField hidden:true.
        realized ifTrue:[
            patternField hide.
        ]
    ] ifFalse:[
        patternField hidden:false.
        realized ifTrue:[
            patternField realize.
        ].
    ].
! !

!FileSelectionBox methodsFor:'user interaction'!

okPressed
    "redefined, since action will be evaluated with full path as argument
     (instead of enterfields contents only as inherited by EnterBox"

    |absPath|

    self hideAndEvaluate:[:string |
        okAction notNil ifTrue:[
            (string startsWith:(Filename separator)) ifTrue:[
                absPath := string
            ] ifFalse:[
                absPath := selectionList directory pathName , Filename separator asString , string
            ].
            okAction value:absPath
        ]
    ]
! !