On 9 January 2013 21:08, Paul DeBruicker <pdebruic@gmail.com> wrote:
On 01/09/2013 12:39 PM, Frank Church wrote:
>
> On 9 January 2013 19:30, Paul DeBruicker <pdebruic@gmail.com
> <mailto:pdebruic@gmail.com>> wrote:
>
> � � On 01/09/2013 11:18 AM, Frank Church wrote:
> � � >
> � � > When I print it returns an empty array #(), but I expect to get subset
> � � > of TextMorphForEditView allInstances.
> � � >
> � � > What is the likely purpose of the notNil?
> � � >
> � � > --
> � � > Frank Church
>
>
> � � The #firstOwnerSuchThat: method either returns the morph that meets the
> � � criteria specified in the block sent to it (in this instance that the
> � � owner is a SystemWindow and its model is a Workspace) or nil. �The
> � � #select: block needs the code inside it to return a boolean, so the
> � � #notNil converts the response from the #firstOwnerSuchThat: method into
> � � a boolean rather than leaving it as either nil or the morph.
>
>
> � � If you right click on a method and choose Implementors you can see how
> � � each class that implements the method defines it. �You can also right
> � � click the method and choose Senders to see examples of how the method is
> � � used.
>
>
> Is there some reason why the expression is �returning an empty collection?
>
> Isn't the select: meant to return the whole list?


No the #select: returns only those elements for which the select block
returns true. �The reason why you're getting an empty collection is
because the select block for every element returns false. �The criteria
in the #firstOwnerSuchThat: block needs to be adjusted to be more
permissive. �Or the starting collection is wrong.

In this instance its an issue of the criteria in the
#firstOwnerSuchThat: block being wrong.

This one you want is this:

TextMorphForEditView allInstances
� � � � � � � � select: [ :morph | (morph firstOwnerSuchThat: [ :owner | (owner
isKindOf: SystemWindow) and: [ owner model isKindOf: Workspace ] ]) notNil ]

(I changed 'owner class isKindOf: SystemWindow' to 'owner isKindOf:
SystemWindow')


I'm on linux and you can shift-click (it may be option-click or
commanc-click on other platforms I have no idea) the title bar of a
Workspace and click 'explore' to see that workspace's instance
variables. �In the bottom pane of the explorer window you can test your
select block's criteria to ensure it works for your desired objects.




Another way to find a workspace is first close all windows then open a
workspace and run

Smalltalk garbageCollect


then �highlight the following, right click it, and choose 'explore'


TextMorphForEditView allInstances

The only thing in the array in the explorer window is the morph for the
workspace. �You can then start looking through the owners by clicking
the triangle next to the #owner instance variable until you find one
who's model is 'a Workspace'. That's the workspace object.







Thanks for the last answer which lists all the workspaces.

My initial desire was to label my Workspaces and then copy the contents of those which match some label and organize them into a kind of collection. Similar to ScriptManager.

So essentially I want to list all Workspaces whose titles or contents match a substring, parse the contents further for some criteria and put those matching into a list for review. Then from there put the right ones into a permanent persisted collection.

My intention is to do something like.

| workSpaces textMorphs |
workSpaces := OrderedCollection new.
textMorphs := TextMorphForEditView allInstances
� � � � � � � � select: [ :morph | (morph firstOwnerSuchThat: [ :owner | (owner
isKindOf: SystemWindow) and: [ owner model isKindOf: Workspace ] ]) notNil ]

I want to capture all the matching Workspaces into the workSpaces variable, by some method such as 'workSpaces[i] := textMorphs[i] getWorkspace' and get the labelString of the Workspace, but it seems that firstOwnerSuchThat returns a nil or notNil, rather than the actual Workspace and it also seems redundant to get the list of Workspaces into the workSpaces through iterating over the textMorphs variable as the owner variable in the loop captures them at some point.

So this question breaks down into 2 parts.

1. How can copy add the owner if it turns out to be a Workspace to the workSpaces variable inside the loop (what is syntax)

2. How would I write a method such as : workSpace := textMorph getWorkspace, with or without using firstOwnerSuchThat, ie a general method of parsing the inheritance/ownership chain.




--
Frank Church

=======================
http://devblog.brahmancreations.com