home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BURKS 2
/
BURKS_AUG97.ISO
/
BURKS
/
LANGUAGE
/
SMALTALK
/
TEXTBOOK
/
AP11.ST
(
.txt
)
< prev
next >
Wrap
Text File
|
1997-04-22
|
13KB
|
499 lines
'Smalltalk Textbook Appendix 11'!
FileBrowser subclass: #EngiFileChoiceModel
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Engi-Choice'!
EngiFileChoiceModel comment:
'
Engi 0.04 (8 February 1994)
Copyright (C) 1994 by Atsushi Aoki
'!
!EngiFileChoiceModel methodsFor: 'initialize-release'!
initialize
autoRead := ValueHolder with: false! !
!EngiFileChoiceModel methodsFor: 'pattern'!
pattern: aString
myPattern := aString asText.
self changed: #fileNameList.
self changed: #pattern! !
!EngiFileChoiceModel methodsFor: 'file name list'!
fileListMenu
fileName == nil ifTrue: [^PopUpMenu
labels: 'make directory...' withCRs
lines: #()
values: #(#makeDir )].
selectionState = #directory ifTrue: [^PopUpMenu
labels: 'new pattern' withCRs
lines: #()
values: #(#directoryPattern )].
^PopUpMenu
labels: 'spawn' withCRs
lines: #()
values: #(#spawnFileList )!
fileListMenuToPopUp
fileName == nil ifTrue: [^PopUpMenu
labels: 'make directory...' withCRs
lines: #()
values: #(#makeDir )].
selectionState = #directory ifTrue: [^PopUpMenu
labels: 'new pattern' withCRs
lines: #()
values: #(#directoryPattern )].
^nil!
fileName: selection
super fileName: selection.
self changed: #fileName!
makeDir
| continue newName |
continue := true.
[continue]
whileTrue:
[newName := EngiTextModel request: 'Name for new directory?' default: ''.
newName isNil ifTrue: [^nil].
newName isEmpty ifTrue: [^nil].
((self isLegalFileName: newName)
and: [newName asFilename exists not])
ifTrue: [continue := false]
ifFalse: [(DialogView confirm: 'File exists or bad file name. Try again?')
ifFalse: [^nil]]].
(Filename named: newName) makeDirectory.
list == nil ifTrue: [self list: SortedCollection new].
list add: newName.
self changed: #fileNameList! !
!EngiFileChoiceModel methodsFor: 'viewing'!
open
| patternHeight topView patternView listView |
patternHeight := TextAttributes defaultLineGrid + 8.
topView := EngiTopView
model: nil
label: 'File Choice'
minimumSize: 250 @ 180.
patternView := TextView
on: self
aspect: #pattern
change: #acceptPattern:from:
menu: #patternMenu
initialSelection: nil.
patternView controller dispatchOn: Character cr to: #alwaysAcceptKey:.
patternView controller dispatchOn: #Enter to: #alwaysAcceptKey:.
patternView := LookPreferences edgeDecorator on: patternView.
patternView noMenuBar.
patternView noVerticalScrollBar.
patternView noHorizontalScrollBar.
listView := SelectionInListView
on: self
aspect: #fileNameList
change: #fileName:
list: #fileNameList
menu: #fileListMenu
initialSelection: #fileName.
listView := LookPreferences edgeDecorator on: listView.
listView noMenuBar.
listView useVerticalScrollBar.
listView useHorizontalScrollBar.
topView add: patternView in: (topView frameFraction: (0 @ 0 corner: 1 @ 0)
offset: (0 @ 0 corner: 0 @ patternHeight)).
topView add: listView in: (topView frameFraction: (0 @ 0 corner: 1 @ 1)
offset: (0 @ patternHeight corner: 0 @ 0)).
topView open! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
EngiFileChoiceModel class
instanceVariableNames: ''!
!EngiFileChoiceModel class methodsFor: 'instance creation'!
pattern: aPattern
| choiceModel aCollection |
choiceModel := self new.
choiceModel pattern: aPattern.
aPattern = ''
ifFalse:
[aCollection := choiceModel filesMatching: aPattern.
aCollection := aCollection asSortedCollection.
choiceModel list: aCollection].
^choiceModel! !
!EngiFileChoiceModel class methodsFor: 'utilities'!
request: messageVisual
"EngiFileChoiceModel request: 'message'."
^self request: messageVisual default: String new!
request: messageVisual default: aPattern
"EngiFileChoiceModel request: 'message' default: '*'."
| visualComponent margin height width half patternHeight fileChoice topView patternView listView aBoolean |
((messageVisual respondsTo: #bounds)
and: [messageVisual respondsTo: #displayOn:at:])
ifTrue: [visualComponent := messageVisual]
ifFalse: [((messageVisual isKindOf: String)
or: [messageVisual isKindOf: Text])
ifTrue: [visualComponent := messageVisual asComposedText]
ifFalse: [visualComponent := messageVisual printString asComposedText]].
margin := 8.
height := margin + visualComponent bounds height + margin.
width := margin + visualComponent bounds width + margin.
half := visualComponent bounds width // 2 + 1.
patternHeight := TextAttributes defaultLineGrid + 8.
fileChoice := self pattern: aPattern.
topView := EngiTopView new.
topView minimumSize: width @ (height + 100 + 40).
patternView := TextView
on: fileChoice
aspect: #pattern
change: #acceptPattern:from:
menu: #patternMenu
initialSelection: nil.
patternView controller dispatchOn: Character cr to: #alwaysAcceptKey:.
patternView controller dispatchOn: #Enter to: #alwaysAcceptKey:.
patternView := LookPreferences edgeDecorator on: patternView.
patternView noMenuBar.
patternView noVerticalScrollBar.
patternView noHorizontalScrollBar.
listView := SelectionInListView
on: fileChoice
aspect: #fileNameList
change: #fileName:
list: #fileNameList
menu: #fileListMenuToPopUp
initialSelection: #fileName.
listView := LookPreferences edgeDecorator on: listView.
listView noMenuBar.
listView useVerticalScrollBar.
listView useHorizontalScrollBar.
topView add: visualComponent in: (topView frameFraction: (0.5 @ 0 corner: 0.5 @ 0)
offset: (half negated @ margin corner: half @ height)).
topView add: patternView in: (topView frameFraction: (0 @ 0 corner: 1 @ 0)
offset: (0 @ height corner: 0 @ (height + patternHeight))).
topView add: listView in: (topView frameFraction: (0 @ 0 corner: 1 @ 1)
offset: (0 @ (height + patternHeight) corner: 0 @ 0)).
aBoolean := topView popUp.
aBoolean = true
ifTrue: [^fileChoice fileName]
ifFalse: [^nil]! !
!EngiFileChoiceModel class methodsFor: 'examples'!
example1
"EngiFileChoiceModel example1."
| choiceModel |
choiceModel := EngiFileChoiceModel pattern: '*'.
choiceModel open.
choiceModel open.
^choiceModel!
example2
"EngiFileChoiceModel example2."
^EngiFileChoiceModel request: 'Please select a file.' default: '*'! !
EngiVariable subclass: #EngiMultipleChoiceModel
instanceVariableNames: 'list '
classVariableNames: ''
poolDictionaries: ''
category: 'Engi-Choice'!
EngiMultipleChoiceModel comment:
'
Engi 0.04 (8 February 1994)
Copyright (C) 1994 by Atsushi Aoki
'!
!EngiMultipleChoiceModel methodsFor: 'accessing'!
list
^list!
list: aCollection
| string |
list := OrderedCollection new.
aCollection do: [:each | ((each isKindOf: String)
or: [each isKindOf: Text])
ifTrue: [list add: each]
ifFalse: [(each isKindOf: ComposedText)
ifTrue: [list add: each asText]
ifFalse:
[string := each printString copyUpTo: Character cr.
list add: string asText]]].
self changed: #item! !
!EngiMultipleChoiceModel methodsFor: 'adaptor'!
item
^self value!
item: selection
| aSet |
aSet := Set new.
selection do: [:each | aSet add: ((each isKindOf: Number)
ifTrue: [each]
ifFalse: [self list indexOf: each])].
self value: aSet.
self changed: #itemSelection!
itemList
^self list!
itemMenu
^nil!
itemSelection
^self item!
itemView
| itemView edgeDecorator |
itemView := self defaultViewClass
on: self
printItems: false
oneItem: false
aspect: #item
change: #item:
list: #itemList
menu: #itemMenu
initialSelection: #itemSelection
useIndex: true.
edgeDecorator := LookPreferences edgeDecorator on: itemView.
edgeDecorator useVerticalScrollBar.
edgeDecorator useHorizontalScrollBar.
^edgeDecorator! !
!EngiMultipleChoiceModel methodsFor: 'viewing'!
open
| topWindow |
topWindow := EngiTopView
model: nil
label: self defaultWindowLabel
minimumSize: 250 @ 180.
topWindow add: self itemView in: (0 @ 0 corner: 1 @ 1).
topWindow open! !
!EngiMultipleChoiceModel methodsFor: 'defaults'!
defaultViewClass
^SelectionSetInListView!
defaultWindowLabel
^'Multiple Choice'! !
"-- -- -- -