FileSelectionBox.st
changeset 1671 5afdf222b738
parent 1670 8d24855a9f0b
child 1672 4ad88fcbc3ac
equal deleted inserted replaced
1670:8d24855a9f0b 1671:5afdf222b738
   306     ^ (selectionList directory pathName asFilename construct:string) asString
   306     ^ (selectionList directory pathName asFilename construct:string) asString
   307 
   307 
   308     "Modified: / 9.9.1998 / 21:23:16 / cg"
   308     "Modified: / 9.9.1998 / 21:23:16 / cg"
   309 !
   309 !
   310 
   310 
   311 directory
   311 ied: / 9.9.1998 / 21:23:16 / cg"
   312     "return the directory which is currently shown"
   312 !
   313 
   313 
   314     ^ selectionList directory
   314 ^ selectionList directory
   315 !
   315 !
   316 
   316 
   317 directory:directoryName
   317 tionList directory:directoryName
   318     "change the directory shown in the list."
   318 !
   319 
   319 
   320     selectionList directory:directoryName
   320 ed: / 12.8.1998 / 09:54:01 / cg"
   321 !
   321 !
   322 
   322 
   323 fileName
   323 selectionList matchBlock:aBlock 
   324     "if some filename has been entered, return it (without the directory path)
       
   325      otherwise, return nil"
       
   326 
       
   327     |string|
       
   328 
       
   329     string := super contents.
       
   330     string isNil ifTrue:[^ nil].
       
   331     ^ self pathName asFilename baseName
       
   332 
       
   333     "Modified: / 12.8.1998 / 09:54:01 / cg"
       
   334 !
       
   335 
       
   336 matchBlock:aBlock
       
   337     "set the matchBlock (in the selectionList). Only files
       
   338      for which the block returns true are shown.
       
   339      The matching is actually done in the fileSelectionList."
       
   340 
       
   341     selectionList matchBlock:aBlock 
       
   342 !
       
   343 
       
   344 openOn:aPath
       
   345     "open the box showing files in aPath.
       
   346      This is only a shortcut message - no new functionality."
       
   347 
       
   348     self directory:aPath.
       
   349     self showAtPointer
       
   350 !
   324 !
   351 
   325 
   352 pathName
   326 pathName
   353     "same as contents - return the full pathname of the selected file,
   327     "same as contents - return the full pathname of the selected file,
   354      or the pathname of the directory if nothing has been entered"
   328      or the pathname of the directory if nothing has been entered"
   355 
   329 
   356     ^ self contents
   330     ^ self contents
   357 !
   331 !
   358 
   332 
   359 pattern:aPattern
   333 entered"
   360     "set the pattern - this also enables the PatternField
   334 
   361      (if the pattern is non-nil) or hides it (if nil)."
   335     ^ self contents
   362 
       
   363     |focusSequence|
       
   364 
       
   365     patternField initialText:aPattern.
       
   366     selectionList pattern:aPattern.
       
   367     aPattern isNil ifTrue:[
       
   368         patternField beInvisible.
       
   369         self makeUntabable:patternField.
       
   370         focusSequence := (Array 
       
   371                              with:enterField 
       
   372                              with:selectionList 
       
   373                              with:okButton 
       
   374                              with:abortButton)
       
   375     ] ifFalse:[
       
   376         patternField beVisible.
       
   377         self makeTabable:patternField before:enterField.
       
   378         focusSequence := (Array 
       
   379                              with:patternField 
       
   380                              with:enterField 
       
   381                              with:selectionList 
       
   382                              with:okButton 
       
   383                              with:abortButton)
       
   384     ].
       
   385 
       
   386     windowGroup notNil ifTrue:[
       
   387         windowGroup focusSequence:focusSequence
       
   388     ].
       
   389 
       
   390     "Modified: 18.10.1997 / 03:02:05 / cg"
       
   391 !
   336 !
   392 
   337 
   393 selectingDirectory:aBoolean
   338 selectingDirectory:aBoolean
   394     "setup the box for directory selection (hides regular files).
   339     "setup the box for directory selection (hides regular files).
   395      Use this, to ask the user for a directories name"
   340      Use this, to ask the user for a directories name"
   429     ]
   374     ]
   430 ! !
   375 ! !
   431 
   376 
   432 !FileSelectionBox methodsFor:'initialization'!
   377 !FileSelectionBox methodsFor:'initialization'!
   433 
   378 
   434 createEnterField
   379 ionBox methodsFor:'initialization'!
   435     "if the (optional) class FilenameEditField is present, use
   380 
   436      it, since it provides filename completion. Otherwise, we have
   381 fied: 18.4.1996 / 20:02:24 / cg"
   437      to live with the dumb (default) field ...
   382 !
   438     "
   383 
   439     FilenameEditField notNil ifTrue:[
   384 ied: 18.10.1997 / 02:47:49 / cg"
   440         ^ FilenameEditField new.
       
   441     ].
       
   442     ^ super createEnterField
       
   443 
       
   444     "Modified: 18.4.1996 / 20:02:24 / cg"
       
   445 !
       
   446 
       
   447 initialize
       
   448     |corner|
       
   449 
       
   450     super initialize.
       
   451     selectingDirectory := false.
       
   452 
       
   453     label := resources string:'File dialog'.
       
   454 
       
   455     labelField extent:(0.7 @ labelField height).
       
   456     labelField label:(resources string:'select a file:').
       
   457     labelField adjust:#left.
       
   458 
       
   459     patternField := EditField in:self.
       
   460     self is3D ifTrue:[
       
   461         corner := (1.0 @ (labelField origin y+patternField heightIncludingBorder)).
       
   462     ] ifFalse:[
       
   463         corner := [(width - ViewSpacing - (patternField borderWidth * 2)) @ (labelField origin y+patternField height"IncludingBorder")].
       
   464     ].
       
   465     patternField origin:(0.7 @ labelField origin y) corner:corner.
       
   466     patternField rightInset:ViewSpacing.
       
   467     patternField initialText:'*'.
       
   468     patternField leaveAction:[:reason | self patternChanged]. 
       
   469     patternField crAction:[self patternChanged].
       
   470     patternField hiddenOnRealize:true. "delay showing, until a pattern is defined"
       
   471 "/ no, since its invisible
       
   472 "/    self makeTabable:patternField before:enterField.
       
   473 
       
   474     enterField addDependent:self.
       
   475 
       
   476     "
       
   477      FileSelectionBox open
       
   478      FileSelectionBox new show
       
   479     "
       
   480 
       
   481     "Modified: 18.10.1997 / 02:47:49 / cg"
       
   482 !
       
   483 
       
   484 postRealize
       
   485     "if some default is present in the enterField,
       
   486      scroll to make this one visible"
       
   487 
       
   488     |contents|
       
   489 
       
   490     super postRealize.
       
   491     (contents := enterField contents) notNil ifTrue:[
       
   492         contents notEmpty ifTrue:[
       
   493             selectionList makeVisible:contents
       
   494         ]
       
   495     ]
       
   496 
       
   497     "Created: 24.7.1997 / 18:19:14 / cg"
       
   498 ! !
   385 ! !
   499 
   386 
   500 !FileSelectionBox methodsFor:'private'!
   387 !FileSelectionBox methodsFor:'private'!
   501 
   388 
   502 updateList
   389 eSelectionBox methodsFor:'private'! !
   503     selectionList updateList
       
   504 ! !
       
   505 
   390 
   506 !FileSelectionBox methodsFor:'queries'!
   391 !FileSelectionBox methodsFor:'queries'!
   507 
   392 
   508 preferredExtent
   393 eSelectionBox methodsFor:'queries'! !
   509     "return my preferred extent - thats the minimum size 
       
   510      to make everything visible"
       
   511 
       
   512     |wWanted hWanted mm|
       
   513 
       
   514     "/ If I have an explicit preferredExtent ..
       
   515 
       
   516     preferredExtent notNil ifTrue:[
       
   517         ^ preferredExtent
       
   518     ].
       
   519 
       
   520     mm := ViewSpacing.
       
   521 
       
   522     wWanted := mm + 
       
   523                labelField preferredExtent x + 
       
   524                (mm * 2) + 
       
   525                patternField preferredExtent x + 
       
   526                mm.
       
   527     (wWanted < width) ifTrue:[
       
   528         wWanted := width
       
   529     ].
       
   530     hWanted := mm + labelField height +
       
   531                mm + enterField height +
       
   532                mm + selectionList height +
       
   533                mm + buttonPanel preferredExtent y +
       
   534                mm.
       
   535 
       
   536     (hWanted < height) ifTrue:[
       
   537         hWanted := height
       
   538     ].
       
   539     ^ (wWanted @ hWanted)
       
   540 
       
   541     "Modified: 19.7.1996 / 20:44:04 / cg"
       
   542 ! !
       
   543 
   394 
   544 !FileSelectionBox methodsFor:'user actions'!
   395 !FileSelectionBox methodsFor:'user actions'!
   545 
   396 
   546 directoryChanged
   397 ctionBox methodsFor:'user actions'!
   547     selectingDirectory ifTrue:[
   398 
   548         selectionList changeDirectory.
   399 fied: 25.5.1996 / 12:27:05 / cg"
   549         enterField contents:(selectionList directory pathName).
   400 !
   550         selectionList setSelection:nil.
   401 
   551     ].
   402 ied: / 7.8.1998 / 17:19:26 / cg"
   552 
       
   553     "Created: 18.4.1996 / 18:38:21 / cg"
       
   554     "Modified: 25.5.1996 / 12:27:05 / cg"
       
   555 !
       
   556 
       
   557 directorySelected
       
   558     "a directory was selected - show the new path in the inputField,
       
   559      if we are in directory mode"
       
   560 
       
   561     selectingDirectory ifTrue:[
       
   562         |newDir|
       
   563 
       
   564         newDir := (selectionList directory)
       
   565                       construct:selectionList selectionValue.
       
   566         enterField contents:newDir pathName.
       
   567     ].
       
   568 
       
   569     "Created: / 18.4.1996 / 18:46:15 / cg"
       
   570     "Modified: / 7.8.1998 / 17:19:26 / cg"
       
   571 !
       
   572 
       
   573 doubleClick
       
   574     |entry|
       
   575 
       
   576     entry := selectionList selectionValue.
       
   577     entry notNil ifTrue:[
       
   578         ((selectionList directory asFilename construct:entry) isDirectory) ifFalse:[
       
   579             selectingDirectory ifFalse:[
       
   580                 enterField contents:entry.
       
   581                 self okPressed
       
   582             ]
       
   583         ]
       
   584     ].
       
   585 
       
   586     "Modified: 19.10.1997 / 00:17:37 / cg"
       
   587 !
   403 !
   588 
   404 
   589 okPressed
   405 okPressed
   590     "called for both on ok-press and on return-key"
   406     "called for both on ok-press and on return-key"
   591 
   407 
   614         ].
   430         ].
   615     ].
   431     ].
   616 
   432 
   617     super okPressed
   433     super okPressed
   618 
   434 
       
   435 <<<<<<< FSelBox.st
       
   436     "Modified: / 9.9.1998 / 21:42:33 / cg"
       
   437 !
       
   438 
       
   439 ].
       
   440     ].
       
   441 
       
   442     super okPressed
       
   443 
   619     "Modified: / 9.9.1998 / 21:21:14 / cg"
   444     "Modified: / 9.9.1998 / 21:21:14 / cg"
   620 !
   445 =======
   621 
   446     "Modified: / 9.9.1998 / 21:21:14 / cg"
   622 patternChanged
   447 >>>>>>> 1.52
   623     selectionList pattern:patternField contents. 
   448 !
       
   449 
       
   450 :patternField contents. 
   624     self updateList
   451     self updateList
   625 
   452 
   626     "Created: 4.6.1996 / 20:30:23 / cg"
   453     "Created: 4.6.1996 / 20:30:23 / cg"
   627 !
       
   628 
       
   629 selectionChanged
       
   630     |entry|
       
   631 
       
   632     entry := selectionList selectionValue.
       
   633     (selectionList directory asFilename construct:entry) type == #directory ifFalse:[
       
   634         selectingDirectory ifTrue:[
       
   635             enterField contents:(selectionList directory pathName).
       
   636             selectionList setSelection:nil.
       
   637             ^ self
       
   638         ]
       
   639     ].
       
   640     enterField contents:entry
       
   641 
       
   642     "Modified: 21.9.1997 / 12:07:55 / cg"
       
   643 ! !
   454 ! !
   644 
   455 
   645 !FileSelectionBox class methodsFor:'documentation'!
   456 !FileSelectionBox class methodsFor:'documentation'!
   646 
   457 
   647 version
   458 version
   648     ^ '$Header: /cvs/stx/stx/libwidg/FileSelectionBox.st,v 1.52 1998-09-09 20:10:13 cg Exp $'
   459     ^ '$Header: /cvs/stx/stx/libwidg/FileSelectionBox.st,v 1.53 1998-09-09 20:27:16 cg Exp $'
   649 ! !
   460 ! !