FileSelectionBrowser.st
author tz
Fri, 30 Jan 1998 15:04:16 +0100
changeset 534 25e349c437d2
parent 515 1b64e990e495
child 585 19dddcff0f5f
permissions -rw-r--r--
info clock removed

"
 COPYRIGHT (c) 1997 by eXept Software AG
              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.
"



SelectionBrowser subclass:#FileSelectionBrowser
	instanceVariableNames:'selectedFileFilter directoryView listOfFileFilters directory'
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-Advanced-Tools'
!

!FileSelectionBrowser class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1997 by eXept Software AG
              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.
"


!

documentation
"
    documentation to be added.

    [author:]
        Thomas Zwick
"
!

history
    "Created: / 10.1.1998 / 11:00:06 / tz"
! !

!FileSelectionBrowser class methodsFor:'instance creation'!

request: aTitle fileFilters: fileFilters

    "self request: 'Select A File' fileFilters: #('.*')"

    ^self new
        title: aTitle;
        listOfFileFilters: fileFilters;
        open
!

request: aTitle fileName: aFileName inDirectory: dir withFileFilters: fileFilters

    "self 
        request: 'Select Your Profile File' 
        fileName: '.profile' 
        inDirectory: Filename homeDirectory 
        withFileFilters: #('.*')"

    ^self new
        title: aTitle;
        fileName: aFileName;
        directory: dir;
        listOfFileFilters: fileFilters;
        open
!

request: aTitle pathName: aPath fileFilters: fileFilters

    "self request: 'Select A File' pathName: '' fileFilters: #('.*')"

    ^self new
        title: aTitle;
        fileName: aPath;
        directory: aPath;
        listOfFileFilters: fileFilters;
        open
!

requestFileName

    "self requestFileName"

    ^self new title: 'Select A File'; open

! !

!FileSelectionBrowser class methodsFor:'accessing'!

loadImageFileNameFilters
    ^self saveImageFileNameFilters addAll: #('*.jpeg' '*.jpg'); yourself

!

projectFileNameFilters
    ^Array withAll: #('*.st' '*.*o'  '*.s' '*.c' 'Make*' '*.project')

!

saveImageFileNameFilters
    ^Array withAll: #('*.xpm' '*.xbm' '*.gif' '*.tif' '*.tiff' '*.bmp')

! !

!FileSelectionBrowser class methodsFor:'interface specs'!

windowSpec
    "this window spec was automatically generated by the ST/X UIPainter"

    "do not manually edit this - the painter/builder may not be able to
     handle the specification if its corrupted."

    "
     UIPainter new openOnClass:FileSelectionBrowser andSelector:#windowSpec
     FileSelectionBrowser new openInterface:#windowSpec
    "
    "FileSelectionBrowser open"

    <resource: #canvas>

    ^
     
       #(#FullSpec
          #'window:' 
           #(#WindowSpec
              #'name:' 'File Selection Browser'
              #'layout:' #(#LayoutFrame 207 0 351 0 606 0 650 0)
              #'label:' 'File Selection Browser'
              #'min:' #(#Point 10 10)
              #'max:' #(#Point 1152 900)
              #'bounds:' #(#Rectangle 207 351 607 651)
              #'usePreferredExtent:' false
          )
          #'component:' 
           #(#SpecCollection
              #'collection:' 
               #(
                 #(#VariableHorizontalPanelSpec
                    #'name:' 'panel'
                    #'layout:' #(#LayoutFrame 0 0.0 0 0.0 0 1.0 -40 1.0)
                    #'component:' 
                     #(#SpecCollection
                        #'collection:' 
                         #(
                           #(#ViewSpec
                              #'name:' 'view1'
                              #'component:' 
                               #(#SpecCollection
                                  #'collection:' 
                                   #(
                                     #(#FileSelectionTreeSpec
                                        #'name:' 'directoryTreeView'
                                        #'layout:' #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
                                        #'model:' #selectionOfDirectory
                                        #'hasHorizontalScrollBar:' true
                                        #'hasVerticalScrollBar:' true
                                        #'miniScrollerHorizontal:' true
                                        #'showRoot:' false
                                        #'showDirectoryIndicator:' true
                                        #'valueChangeSelector:' #readDirectory
                                        #'hierarchicalList:' #rootOfDirectory
                                        #'itemClass:' 'Directory'
                                    )
                                  )
                              )
                          )
                           #(#ViewSpec
                              #'name:' 'view2'
                              #'component:' 
                               #(#SpecCollection
                                  #'collection:' 
                                   #(
                                     #(#InputFieldSpec
                                        #'name:' 'EditField'
                                        #'layout:' #(#LayoutFrame 1 0.0 -22 1 0 1.0 0 1)
                                        #'model:' #valueOfFileName
                                        #'acceptOnReturn:' false
                                        #'acceptOnTab:' false
                                    )
                                     #(#SubCanvasSpec
                                        #'name:' 'subCanvas1'
                                        #'layout:' #(#LayoutFrame 1 0.0 0 0.0 0 1.0 -22 1.0)
                                        #'clientHolder:' #directoryView
                                    )
                                  )
                              )
                          )
                        )
                    )
                    #'handles:' #(#Any 0.5 1.0)
                )
                 #(#UISubSpecification
                    #'name:' 'SubSpecification'
                    #'layout:' #(#LayoutFrame 2 0.0 -32 1 -2 1.0 -8 1.0)
                    #'majorKey:' #ToolApplicationModel
                    #'minorKey:' #windowSpecForCommitWithoutChannels
                )
              )
          )
      )
! !

!FileSelectionBrowser methodsFor:'accessing'!

directory: aDirectory

    directory := (aDirectory ? Filename homeDirectory) asFilename asAbsoluteFilename name
!

directoryView

    ^directoryView ? (directoryView := DirectoryView new)
!

fileName: aFileName

    self valueOfFileName value: (aFileName ? '') asFilename baseName.
    directory := directory ? ((aFileName ? '') asFilename directoryName).

!

listOfFileFilters: anArray

    listOfFileFilters := anArray
! !

!FileSelectionBrowser methodsFor:'accessing - views'!

directoryTreeView

    ^builder componentAt: #directoryTreeView

! !

!FileSelectionBrowser methodsFor:'aspects'!

rootOfDirectory

    |holder|
    (holder := builder bindingAt:#rootOfDirectory) isNil ifTrue:[
        builder aspectAt:#rootOfDirectory put: (holder :=  Filename rootDirectory name asValue).
    ].
    ^ holder

!

selectionOfDirectory

    |holder|
    (holder := builder bindingAt:#selectionOfDirectory) isNil ifTrue:[
        builder aspectAt:#selectionOfDirectory put: (holder := ValueHolder new)
    ].
    ^ holder

!

valueOfFileName

    |holder|
    (holder := builder bindingAt:#valueOfFileName) isNil ifTrue:[
        builder aspectAt:#valueOfFileName put:(holder :=  ValueHolder new).
    ].
    ^ holder
! !

!FileSelectionBrowser methodsFor:'callbacks'!

fileDoubleClicked: aFileName

    self valueOfFileName value: aFileName.
    accept value: true.
    self close
!

readDirectory
    "Diesen Mist musste ich machen, weil ztk es nicht fertig bringt,
    seine Models upzudaten, bevor er die Callbacks aufruft!!!!!!"

    |dir|
    directoryView listOfFiles removeAll.
    directoryView directory: 
        (dir := (self directoryTreeView model list at:
        self directoryTreeView model selection) contents name);   
        readDirectory.
    directory isNil ifTrue: [self class lastSelection: dir]
! !

!FileSelectionBrowser methodsFor:'startup / release'!

closeCancel

    directoryView release.
    super closeCancel
!

closeRequest

    directoryView release.
    super closeRequest

!

open

    super open.
    accept value ifTrue:[
        ^ (self selectionOfDirectory value ? '') asFilename 
                constructString:(self valueOfFileName value ? '')
    ].
    ^ nil

    "Modified: / 28.1.1998 / 15:21:40 / stefan"
!

postBuildWith:aBuilder

    directoryView listOfFileFilters: listOfFileFilters ? #('*').
    directoryView fileSelectAction: [:aFileName |self valueOfFileName value: aFileName asFilename baseName].
    directoryView fileDoubleClickAction: [:aFileName |self fileDoubleClicked: aFileName asFilename baseName].
    directoryView fileFilterSelectAction: [:fileFilter|
    self valueOfFileName value: (
        ((self valueOfFileName value ? 'unknown') readStream upTo: $.), '.',
        (fileFilter copy reverse readStream upTo: $.) reverse)].
    self directoryTreeView selectPathname: directory ? self class lastSelection.

    ^super postBuildWith:aBuilder
! !

!FileSelectionBrowser class methodsFor:'documentation'!

version
    ^ '$Header$'
! !