FilenameWidgetWithHistory.st
author Claus Gittinger <cg@exept.de>
Wed, 12 Nov 2008 14:11:36 +0100
changeset 3593 f11c5a41d4a9
parent 3590 c3c778e11564
child 3594 8bdad6d9c51a
permissions -rw-r--r--
*** empty log message ***

"
 COPYRIGHT (c) 2007 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.
"
"{ Package: 'stx:libwidg2' }"

SimpleView subclass:#FilenameWidgetWithHistory
	instanceVariableNames:'fileNameEntryField browseButton history directoriesOnly filesOnly
		dialogTitle'
	classVariableNames:''
	poolDictionaries:''
	category:'Views-Interactors'
!

!FilenameWidgetWithHistory class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2007 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
"
    A Filename InputField with history-list and a browse-button, which opens a file dialog.

    [author:]
        Claus Gittinger

    [see also:]
        ComboBoxView
        FilenameEditField
        FilenameComboBoxView
"
!

examples
"
                                                                        [exBegin]
     |top b|

     top := StandardSystemView new.
     top extent:(300 @ 200).

     b := FilenameWidgetWithHistory in:top.
     b origin:(0.0 @ 0.0) corner:(1.0 @ 0.0).
     b bottomInset:(b preferredExtent y negated).

     top open.
                                                                        [exEnd]
"
! !

!FilenameWidgetWithHistory methodsFor:'accessing'!

dialogTitle:something
    "set the dialogs title"

    dialogTitle := something.
!

directoriesOnly:aBoolean
    "if true, directories are selectable only.
     If both filesOnly and directoriesOnly are false, which is the default, 
     anything is selectable."

    directoriesOnly := aBoolean.
    directoriesOnly ifTrue:[
        filesOnly := false.
    ].
    fileNameEntryField notNil ifTrue:[
        fileNameEntryField directoriesOnly:aBoolean
    ].
!

filesOnly:aBoolean
    "if true, files are selectable only.
     If both filesOnly and directoriesOnly are false, which is the default, 
     anything is selectable."

    filesOnly := aBoolean.
    filesOnly ifTrue:[
        directoriesOnly := false.
    ].
    fileNameEntryField notNil ifTrue:[
        fileNameEntryField filesOnly:aBoolean
    ].
!

historyList
    history isNil ifTrue:[
        history := nil asValue
    ].
    ^ history
!

historyList:aList
    "set the history - useful when two or more such fields shall share a common history"

    history := aList
!

model
    ^ fileNameEntryField model
!

model:aFilenameHolder
    fileNameEntryField model:aFilenameHolder.
! !

!FilenameWidgetWithHistory methodsFor:'accessing-channels'!

enableChannel:aValueHolder
    fileNameEntryField enableChannel:aValueHolder.
    browseButton enableChannel:aValueHolder.
! !

!FilenameWidgetWithHistory methodsFor:'accessing-editField attributes'!

acceptIfUnchanged:aBoolean
    fileNameEntryField acceptIfUnchanged:aBoolean
!

acceptOnLeave:aBoolean
    fileNameEntryField acceptOnLeave:aBoolean
!

acceptOnLostFocus:aBoolean
    fileNameEntryField acceptOnLostFocus:aBoolean
!

acceptOnPointerLeave:aBoolean
    fileNameEntryField acceptOnPointerLeave:aBoolean
!

acceptOnReturn:aBoolean
    fileNameEntryField acceptOnReturn:aBoolean
!

acceptOnTab:aBoolean
    fileNameEntryField acceptOnTab:aBoolean
!

contents:aString
    fileNameEntryField contents:aString
!

immediateAccept:aBoolean
    fileNameEntryField immediateAccept:aBoolean
!

maxChars:aBoolean
    fileNameEntryField maxChars:aBoolean
!

readOnly:aBoolean
    fileNameEntryField readOnly:aBoolean
! !

!FilenameWidgetWithHistory methodsFor:'initialization'!

initialize
    super initialize.

    directoriesOnly := filesOnly := false.

    fileNameEntryField := FilenameComboBoxView in:self.
    fileNameEntryField layout:(LayoutFrame
                                  leftFraction:0 offset:0 
                                  rightFraction:1 offset:-22 
                                  topFraction:0 offset:0 
                                  bottomFraction:1 offset:0).
    fileNameEntryField listHolder:(self historyList).

    browseButton := Button in:self.
    browseButton label:'...'.
    browseButton action:[ self browseForFileOrDirectory ].
    browseButton layout:(LayoutFrame
                                  leftFraction:1 offset:-22 
                                  rightFraction:1 offset:-2 
                                  topFraction:0 offset:0 
                                  bottomFraction:1 offset:0).
! !

!FilenameWidgetWithHistory methodsFor:'queries'!

preferredExtent
    "/ If I have an explicit preferredExtent..
    explicitExtent notNil ifTrue:[
        ^ explicitExtent
    ].

    "/ If I have a cached preferredExtent value..
    preferredExtent notNil ifTrue:[
        ^ preferredExtent
    ].

    preferredExtent := (fileNameEntryField preferredWidth + browseButton preferredWidth)
                       @
                       (fileNameEntryField preferredHeight "max: browseButton preferredExtent y").
    ^ preferredExtent
! !

!FilenameWidgetWithHistory methodsFor:'user actions'!

browseForDestinationDirectory
    <resource: #obsolete>
    self obsoleteMethodWarning.
    self browseForFileOrDirectory
!

browseForFileOrDirectory
    |dir|

    Dialog aboutToOpenBoxNotificationSignal handle:[:ex |
        |dialog|

        dialog := ex parameter.
        dialog perform:#browseVisibleHolder with:true ifNotUnderstood:[].
        ex proceed.
    ] do:[
        |title|

        title := dialogTitle notNil 
                    ifTrue:[ dialogTitle ]
                    ifFalse:[ 
                        directoriesOnly 
                            ifTrue:[ resources string:'Select Directory' ]
                            ifFalse:[ 
                                filesOnly
                                    ifTrue:[ resources string:'Select File' ]
                                    ifFalse:[ resources string:'Select Path' ]]].

        dir := Dialog 
                requestFileName:title
                default:(self model value ? '.' asFilename pathName).
    ].
    dir isEmptyOrNil ifTrue:[ ^ self ].

    self model value:dir.

    "Modified: / 02-10-2006 / 14:45:54 / cg"
! !

!FilenameWidgetWithHistory class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libwidg2/FilenameWidgetWithHistory.st,v 1.11 2008-11-12 13:11:36 cg Exp $'
! !