Kyma Forum
  Tips & Techniques
  Smalltalk collections

Post New Topic  Post A Reply
profile | register | preferences | faq | search

next newest topic | next oldest topic
Author Topic:   Smalltalk collections
mk23
Member
posted 26 October 2008 17:12         Edit/Delete Message   Reply w/Quote
Hello all,
I am currently playing around with the tool editor, trying to wrap my head round more smalltalk. I have managed to fill an ordered collection with a list of file names. Now I would like to display these as a vertical list in the tools GUI, with a number of parameters aligned horizontally next to each file name.

The thing I'm stuck with currently is how best to step through each name in the ordered collection. I checked the manual but from the description of the Do and the While loops I can't really seem to get either working. Anyone have any suggestions?

And while I'm at it, does anyone have any suggestions about how to list the file names in the tools GUI? The number of files will be different each time the tool is run on a different folder, so I need a dynamic way of listing them...

Thanks in advance for any assistance

David mK

IP: Logged

SSC
Administrator
posted 27 October 2008 16:34         Edit/Delete Message   Reply w/Quote

toolwithlistoffilenames.pci.zip

 
One approach might be to create a Tool variable of type String. Then onEntry to the state where you want to display the filenames, you could do something like this:

code:

"Ask user to select a filename in folder"

| oneFile collectionOfNames writeStream |

oneFile := (SamplesFile
fromOldFilename: (HostDriverInterface
getFileWithPrompt: 'Select a sample'
fileTypes: HostDriverInterface sampleFileTypes
ifCancel: [^ self])) filename nameString.

collectionOfNames := oneFile asString fileNamesOfSameTypeInSameFolder.

writeStream := String new writeStream.

collectionOfNames do: [ :fn | writeStream nextPutAll: fn.
writeStream cr].

Filenames := writeStream contents.


This opens a file dialog, lets you select one file in a folder, then creates a collection of all files of the same type in that folder. In the next step, it creates a writeStream and writes all the filenames to that stream with CRs separating each filename. Then it assigns the contents of that writeStream to the variable (which automatically displays the filenames in the Tool).

IP: Logged

cristian_vogel
Member
posted 29 October 2008 03:37         Edit/Delete Message   Reply w/Quote
its always good to see SmallTalk problems and solutions - good for learning

Keep on with the tool , look forward to seeing it!

... what does

[ ^ self ]

mean?

[This message has been edited by cristian_vogel (edited 29 October 2008).]

IP: Logged

mk23
Member
posted 05 November 2008 14:59         Edit/Delete Message   Reply w/Quote
SSC: thanks for the code fragment, I am slowly unraveling it :-) I'm still playing with it, will have more questions soon!

quote:
Originally posted by cristian_vogel:
its always good to see SmallTalk problems and solutions - good for learning

indeed, this code snippet has kick started my Smalltalk studies again....

quote:

... what does

[ ^ self ]

mean?
[/b]



I was wondering this as well. After a fair bit of googling on Smalltalk this week I came across a good description on this page: http://www.inf.ufsc.br/poo/smalltalk/ibm/tutorial/chap3.html
read the section "Returning a Value".

Clarifies it well in my opinion.

Best

David


[This message has been edited by mk23 (edited 05 November 2008).]

IP: Logged

All times are CT (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply

Contact Us | Symbolic Sound Home

This forum is provided solely for the support and edification of the customers of Symbolic Sound Corporation.


Ultimate Bulletin Board 5.45c