Hi
I'm fixing some of the problems with the file list. Now I have a question. Right now a reader registers in the following way:
B3DScene class >>initialize
FileList registerFileReader: self
B3DScene class>>fileReaderServicesForSuffix: suffix
^(suffix = '3ds') | (suffix = '*') ifTrue: [ {SimpleServiceEntry provider: self label: 'Open 3DS file' selector: #open3DSFile:}] ifFalse: [#()]
So the file list only knows the classes and not the services which have been register.
The first question is then how to get some specific services
A possible answer would be to call
col := OrderedCollection new. FileList allReader do: [:each | res := each fileReaderServicesForSuffix: '*'. res isEmpty ifFalse: [col add: each ]]. col
The problem is that every reader developers has to not forget to put the (suffix = '*') in the fileReaderServicesForSuffix method
A possible solution would be to have a method such as
B3DScene class>>registeredServices
^ {SimpleServiceEntry provider: self label: 'Open 3DS file' selector: #open3DSFile:}
B3DScene class>>fileReaderServicesForSuffix: suffix
^(suffix = '3ds') | (suffix = '*') ifTrue: [ self registeredServices] ifFalse: [#()]
The second question is should we register classes or services. With classes, when I'm looking for the services that fileIn for example I have to look for all the classes get their services select the right one. With services I would just goes over the services.
Any ideas pros and cons.
Stef
On Thursday 31 January 2002 03:31 am, Stephane Ducasse wrote:
So the file list only knows the classes and not the services which have been register.
I'm in favor of letting the reader classes decide:
* whether they're going to handle a specific file or not (not just by suffix!)
* what services they want to provide for a specific file
I'd suggest registering classes using file suffixes (as an optimization for readers that care about suffixes), and then before popping up a menu, passing the name of the selected file(s) to the registered reader classes.
If you include '*' as a file suffix that can be registered, it would allow readers to decide on a file-by-file basis.
This is important for some files that may not have predictable file suffixes (I'm thinking here of ZIP files, which may have suffixes like .zip .ZIP .exe .EXE .pr .PR, etc...) and would benefit from being looked at (for magic numbers, etc.).
That is, I'd have something like this (probably pseudo-code):
ArchiveViewer class >>initialize FileList registerReader: self forSuffixes: #( * ).
ArchiveViewer class>>servicesForFile: aFileName services := OrderedCollection new. (aFileName isZipFile) ifTrue: [ services add: (SimpleServiceEntry provider: self label: 'view zip' selector: #viewZip:) ]. services add: (SimpleServiceEntry provider: self label: 'add to zip' selector: #addFileToNewZip:) . ^services
and before popping up a menu, the FileList would call all the reader classes that had expressed an interest in the given file suffix (plus all those who'd registered '*'). The results would be added to the menu.
squeak-dev@lists.squeakfoundation.org