About the Registering File list

Ned Konz ned at bike-nomad.com
Thu Jan 31 18:05:48 UTC 2002


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.

-- 
Ned Konz
currently: Stanwood, WA
email:     ned at bike-nomad.com
homepage:  http://bike-nomad.com



More information about the Squeak-dev mailing list