How do I save contents of Workspace into a collection?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
37 messages Options
12
Reply | Threaded
Open this post in threaded view
|

How do I save contents of Workspace into a collection?

Frank Church
Hi guys,

My images are gathering a number of Workspaces whose contents I don't want to delete.

I want to create a collection of Workspace contents along this defintion:

Description
Date
Category
Content (the actual text in the Workspace).

In the final version I would like to be able to select a workspace and simply click a button or a menu item and get a dialog where I can enter the Description, Category and Date with the Workspace contents automatically captured into a text box. Copying and pasting the contents would be okay to start with.

Filing it out would be another aspect later.

What kind of array would best suited to the task? There is quite a number of them depicted here: http://www.jmcsweeney.co.uk/computing/m206/collections_intro.php

What could be the best way to go about it?

For those who are curious I am experimenting with the original ideas of Smalltalk where a computer user would do everything in Smalltalk workspace/desktop. I am intrigued by the possibility and somehow it seems eminently doable.

--
Frank Church

=======================
http://devblog.brahmancreations.com
Reply | Threaded
Open this post in threaded view
|

Re: How do I save contents of Workspace into a collection?

Sean P. DeNigris
Administrator
Frank Church wrote
I want to create a collection of Workspace contents...What kind of array would best suited to the task?
I usually just start with an OrderedCollection until I feel the need for something more complicated. It's like an Array, but will grow dynamically.

Two things to check out that already exist in the system:
* you can save workspace contents to a file by clicking the little arrow in the top right of the workspace window and select "Save As..."
* check out ScriptManager, which is a GUI for organizing and saving workspaces. It was included in Pharo by default in 1.3 (I think) and has a repo on sqs... search the list to see how/if it can be loaded into later Pharos.

HTH,
Sean
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: How do I save contents of Workspace into a collection?

Frank Church


On 7 January 2013 13:01, Sean P. DeNigris <[hidden email]> wrote:
Frank Church wrote
> I want to create a collection of Workspace contents...What kind of array
> would best suited to the task?

I usually just start with an OrderedCollection until I feel the need for
something more complicated. It's like an Array, but will grow dynamically.

Two things to check out that already exist in the system:
* you can save workspace contents to a file by clicking the little arrow in
the top right of the workspace window and select "Save As..."
* check out ScriptManager, which is a GUI for organizing and saving
workspaces. It was included in Pharo by default in 1.3 (I think) and has a
repo on sqs... search the list to see how/if it can be loaded into later
Pharos.



I tried ScriptManager but it appears to save the files in a binary format. It wouldn't open in a text editor .

I am interested in something which persists in Smalltalk, so I can just browse them without saving to disk, 'The Smalltalk Way'. Saving to disk is an option though.

Is there a way of selecting a workspace and extracting the text it contains. Something like a small script to enumerate all open Workspaces and printing out their text contents in a Transcript?

I saw your blog article about using Smalltalk to view the contents of your mailbox and the other about parsing a feeds contents and I want to try something similar as a
start.

My thoughts are along these lines.

1. Define a class consisting of workspace and a method which returns their text content.
2. Define collection
3. List workspaces and add to collection. I am not sure if this will replicate the workspaces perhaps they should be 'pointers' to the workspaces
4. inspect/explore the results like you did in your blog.

Thanks

HTH,
Sean



--
View this message in context: http://forum.world.st/How-do-I-save-contents-of-Workspace-into-a-collection-tp4662321p4662327.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.




--
Frank Church

=======================
http://devblog.brahmancreations.com
Reply | Threaded
Open this post in threaded view
|

Re: How do I save contents of Workspace into a collection?

Frank Church


On 7 January 2013 14:15, Frank Church <[hidden email]> wrote:


On 7 January 2013 13:01, Sean P. DeNigris <[hidden email]> wrote:
Frank Church wrote
> I want to create a collection of Workspace contents...What kind of array
> would best suited to the task?

I usually just start with an OrderedCollection until I feel the need for
something more complicated. It's like an Array, but will grow dynamically.

Two things to check out that already exist in the system:
* you can save workspace contents to a file by clicking the little arrow in
the top right of the workspace window and select "Save As..."
* check out ScriptManager, which is a GUI for organizing and saving
workspaces. It was included in Pharo by default in 1.3 (I think) and has a
repo on sqs... search the list to see how/if it can be loaded into later
Pharos.



I tried ScriptManager but it appears to save the files in a binary format. It wouldn't open in a text editor .

I am interested in something which persists in Smalltalk, so I can just browse them without saving to disk, 'The Smalltalk Way'. Saving to disk is an option though.

Is there a way of selecting a workspace and extracting the text it contains. Something like a small script to enumerate all open Workspaces and printing out their text contents in a Transcript?

I saw your blog article about using Smalltalk to view the contents of your mailbox and the other about parsing a feeds contents and I want to try something similar as a
start.

My thoughts are along these lines.

1. Define a class consisting of workspace and a method which returns their text content.
2. Define collection
3. List workspaces and add to collection. I am not sure if this will replicate the workspaces perhaps they should be 'pointers' to the workspaces
4. inspect/explore the results like you did in your blog.

Thanks

HTH,
Sean
 


After further investigation this is what I found.

 When I shift click a Workspace window the item selected is usually a PluggableTextMorph or a TextMorphForEditView. When it is a PluggableTextMorph it owns a TextMorphforEditView which was not picked by the click.

Inspecting or exploring the hierarchy shows that is owned by a SystemWindow of a Model Workspace further up the hierachy.

What code do I need to first list all TextMorphforEditView(s) in the system and lookup the ownership hierarchy to determine whether the model of the SystemWindow is a Workspace or a Transcript?

 
--
Frank Church

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



--
Frank Church

=======================
http://devblog.brahmancreations.com
Reply | Threaded
Open this post in threaded view
|

Re: How do I save contents of Workspace into a collection?

Igor Stasenko
On 7 January 2013 22:12, Frank Church <[hidden email]> wrote:

>
>
> On 7 January 2013 14:15, Frank Church <[hidden email]> wrote:
>>
>>
>>
>> On 7 January 2013 13:01, Sean P. DeNigris <[hidden email]> wrote:
>>>
>>> Frank Church wrote
>>> > I want to create a collection of Workspace contents...What kind of
>>> > array
>>> > would best suited to the task?
>>>
>>> I usually just start with an OrderedCollection until I feel the need for
>>> something more complicated. It's like an Array, but will grow
>>> dynamically.
>>>
>>> Two things to check out that already exist in the system:
>>> * you can save workspace contents to a file by clicking the little arrow
>>> in
>>> the top right of the workspace window and select "Save As..."
>>> * check out ScriptManager, which is a GUI for organizing and saving
>>> workspaces. It was included in Pharo by default in 1.3 (I think) and has
>>> a
>>> repo on sqs... search the list to see how/if it can be loaded into later
>>> Pharos.
>>>
>>
>>
>> I tried ScriptManager but it appears to save the files in a binary format.
>> It wouldn't open in a text editor .
>>
>> I am interested in something which persists in Smalltalk, so I can just
>> browse them without saving to disk, 'The Smalltalk Way'. Saving to disk is
>> an option though.
>>
>> Is there a way of selecting a workspace and extracting the text it
>> contains. Something like a small script to enumerate all open Workspaces and
>> printing out their text contents in a Transcript?
>>
>> I saw your blog article about using Smalltalk to view the contents of your
>> mailbox and the other about parsing a feeds contents and I want to try
>> something similar as a
>> start.
>>
>> My thoughts are along these lines.
>>
>> 1. Define a class consisting of workspace and a method which returns their
>> text content.
>> 2. Define collection
>> 3. List workspaces and add to collection. I am not sure if this will
>> replicate the workspaces perhaps they should be 'pointers' to the workspaces
>> 4. inspect/explore the results like you did in your blog.
>>
>> Thanks
>>
>>> HTH,
>>> Sean
>>>
>
>
>
> After further investigation this is what I found.
>
>  When I shift click a Workspace window the item selected is usually a
> PluggableTextMorph or a TextMorphForEditView. When it is a
> PluggableTextMorph it owns a TextMorphforEditView which was not picked by
> the click.
>
> Inspecting or exploring the hierarchy shows that is owned by a SystemWindow
> of a Model Workspace further up the hierachy.
>
> What code do I need to first list all TextMorphforEditView(s) in the system
> and lookup the ownership hierarchy to determine whether the model of the
> SystemWindow is a Workspace or a Transcript?


just accept text in all workspaces (cmd-s) before doing it:

Workspace allInstances collect: [:ea |
 ea contents
]


>
>>>
>>> --
>>
>> Frank Church
>>
>> =======================
>> http://devblog.brahmancreations.com
>
>
>
>
> --
> Frank Church
>
> =======================
> http://devblog.brahmancreations.com



--
Best regards,
Igor Stasenko.

Reply | Threaded
Open this post in threaded view
|

Re: How do I save contents of Workspace into a collection?

Frank Church


On 7 January 2013 23:32, Igor Stasenko <[hidden email]> wrote:
Workspace allInstances collect: [:ea |
 ea contents

Following your example I used this expression 'TextMorphForEditView allInstances collect: [ :ea | ea text]'.to get the text in all the TextMorphForEditView instances without have to Cmd-S them first..

In my case I need to know if the TextMorphForEditView belongs to a Workspace. Is there a message for checking if an object is a child object of a particular class further up the hierarchy,.something along the lines of:

isTrue(TextMorphForEditViewObject childOf: Workspace)

and conversely

isTrue(WorkspaceObject parentOf: TextMorphForEditView)

?
--
Frank Church

=======================
http://devblog.brahmancreations.com
Reply | Threaded
Open this post in threaded view
|

Re: How do I save contents of Workspace into a collection?

Igor Stasenko
On 8 January 2013 02:22, Frank Church <[hidden email]> wrote:

>
>
> On 7 January 2013 23:32, Igor Stasenko <[hidden email]> wrote:
>>
>> Workspace allInstances collect: [:ea |
>>  ea contents
>
>
> Following your example I used this expression 'TextMorphForEditView
> allInstances collect: [ :ea | ea text]'.to get the text in all the
> TextMorphForEditView instances without have to Cmd-S them first..
>
> In my case I need to know if the TextMorphForEditView belongs to a
> Workspace. Is there a message for checking if an object is a child object of
> a particular class further up the hierarchy,.something along the lines of:
>
> isTrue(TextMorphForEditViewObject childOf: Workspace)
>
> and conversely
>
> isTrue(WorkspaceObject parentOf: TextMorphForEditView)
>
>

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

something like that.

> ?
> --
> Frank Church
>
> =======================
> http://devblog.brahmancreations.com



--
Best regards,
Igor Stasenko.

Reply | Threaded
Open this post in threaded view
|

Re: How do I save contents of Workspace into a collection?

Igor Stasenko
On 8 January 2013 03:52, Igor Stasenko <[hidden email]> wrote:

> On 8 January 2013 02:22, Frank Church <[hidden email]> wrote:
>>
>>
>> On 7 January 2013 23:32, Igor Stasenko <[hidden email]> wrote:
>>>
>>> Workspace allInstances collect: [:ea |
>>>  ea contents
>>
>>
>> Following your example I used this expression 'TextMorphForEditView
>> allInstances collect: [ :ea | ea text]'.to get the text in all the
>> TextMorphForEditView instances without have to Cmd-S them first..
>>
>> In my case I need to know if the TextMorphForEditView belongs to a
>> Workspace. Is there a message for checking if an object is a child object of
>> a particular class further up the hierarchy,.something along the lines of:
>>
>> isTrue(TextMorphForEditViewObject childOf: Workspace)
>>
>> and conversely
>>
>> isTrue(WorkspaceObject parentOf: TextMorphForEditView)
>>
>>
>
> TextMorphForEditView allInstances select: [:morph |
>   morph firstOwnerSuchThat: [:owner | (owner class isKindOf:
> SystemWindow) and: [
>   owner model isKindOf: Workspace ] ]
>
> something like that.
>
or this: ...
 TextMorphForEditView allInstances select: [:morph |
   morph firstOwnerSuchThat: [:owner | (owner class isKindOf:
 SystemWindow) and: [
   owner model isKindOf: Workspace ]  notNil ]


>> ?
>> --
>> Frank Church
>>
>> =======================
>> http://devblog.brahmancreations.com
>
>
>
> --
> Best regards,
> Igor Stasenko.



--
Best regards,
Igor Stasenko.

Reply | Threaded
Open this post in threaded view
|

Re: How do I save contents of Workspace into a collection?

Frank Church


On 8 January 2013 02:53, Igor Stasenko <[hidden email]> wrote:
On 8 January 2013 03:52, Igor Stasenko <[hidden email]> wrote:
> On 8 January 2013 02:22, Frank Church <[hidden email]> wrote:
>>
>>
>> On 7 January 2013 23:32, Igor Stasenko <[hidden email]> wrote:
>>>
>>> Workspace allInstances collect: [:ea |
>>>  ea contents
>>
>>
>> Following your example I used this expression 'TextMorphForEditView
>> allInstances collect: [ :ea | ea text]'.to get the text in all the
>> TextMorphForEditView instances without have to Cmd-S them first..
>>
>> In my case I need to know if the TextMorphForEditView belongs to a
>> Workspace. Is there a message for checking if an object is a child object of
>> a particular class further up the hierarchy,.something along the lines of:
>>
>> isTrue(TextMorphForEditViewObject childOf: Workspace)
>>
>> and conversely
>>
>> isTrue(WorkspaceObject parentOf: TextMorphForEditView)
>>
>>
>
> TextMorphForEditView allInstances select: [:morph |
>   morph firstOwnerSuchThat: [:owner | (owner class isKindOf:
> SystemWindow) and: [
>   owner model isKindOf: Workspace ] ]
>
> something like that.
>
or this: ...
 TextMorphForEditView allInstances select: [:morph |
   morph firstOwnerSuchThat: [:owner | (owner class isKindOf:
 SystemWindow) and: [
   owner model isKindOf: Workspace ]  notNil ]


>> ?
>> --
>> Frank Church
>>
>> =======================
>> http://devblog.brahmancreations.com
>
>
>
> --
> Best regards,
> Igor Stasenko.



--
Best regards,
Igor Stasenko.


Do you care to rack some points at Stackoverflow 14203861, less I end up having to answer my own question (rather uncool) ?

--
Frank Church

=======================
http://devblog.brahmancreations.com
Reply | Threaded
Open this post in threaded view
|

Re: How do I save contents of Workspace into a collection?

Frank Church
In reply to this post by Igor Stasenko


On 8 January 2013 02:53, Igor Stasenko <[hidden email]> wrote:
On 8 January 2013 03:52, Igor Stasenko <[hidden email]> wrote:
> On 8 January 2013 02:22, Frank Church <[hidden email]> wrote:
>>
>>
>> On 7 January 2013 23:32, Igor Stasenko <[hidden email]> wrote:
>>>
>>> Workspace allInstances collect: [:ea |
>>>  ea contents
>>
>>
>> Following your example I used this expression 'TextMorphForEditView
>> allInstances collect: [ :ea | ea text]'.to get the text in all the
>> TextMorphForEditView instances without have to Cmd-S them first..
>>
>> In my case I need to know if the TextMorphForEditView belongs to a
>> Workspace. Is there a message for checking if an object is a child object of
>> a particular class further up the hierarchy,.something along the lines of:
>>
>> isTrue(TextMorphForEditViewObject childOf: Workspace)
>>
>> and conversely
>>
>> isTrue(WorkspaceObject parentOf: TextMorphForEditView)
>>
>>
>
> TextMorphForEditView allInstances select: [:morph |
>   morph firstOwnerSuchThat: [:owner | (owner class isKindOf:
> SystemWindow) and: [
>   owner model isKindOf: Workspace ] ]
>
> something like that.
>
or this: ...
 TextMorphForEditView allInstances select: [:morph |
   morph firstOwnerSuchThat: [:owner | (owner class isKindOf:
 SystemWindow) and: [
   owner model isKindOf: Workspace ]  notNil ]


>> ?
>> --
>> Frank Church
>>
>> =======================
>> http://devblog.brahmancreations.com
>
>
>
> --
> Best regards,
> Igor Stasenko.



--
Best regards,
Igor Stasenko.


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

This code generates a syntax error. When I put the brackets where I think they should be I either get a NonBoolean receiver error or a True doesNotUndertstand value message/


--
Frank Church

=======================
http://devblog.brahmancreations.com
Reply | Threaded
Open this post in threaded view
|

Re: How do I save contents of Workspace into a collection?

Paul DeBruicker
On 01/09/2013 10:26 AM, Frank Church wrote:
> TextMorphForEditView allInstances select: [:morph |
>    morph firstOwnerSuchThat: [:owner | (owner class isKindOf:
>  SystemWindow) and: [
>    owner model isKindOf: Workspace ]  notNil ]

Does this do what you want:

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

Reply | Threaded
Open this post in threaded view
|

Re: How do I save contents of Workspace into a collection?

Frank Church

On 9 January 2013 18:32, Paul DeBruicker <[hidden email]> wrote:
TextMorphForEditView allInstances
                select: [ :morph |
                        (morph firstOwnerSuchThat: [ :owner | (owner class isKindOf:
SystemWindow) and: [ owner model isKindOf: Workspace ] ])
                                notNil ]


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

=======================
http://devblog.brahmancreations.com
Reply | Threaded
Open this post in threaded view
|

Re: How do I save contents of Workspace into a collection?

Paul DeBruicker
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.

Reply | Threaded
Open this post in threaded view
|

Re: How do I save contents of Workspace into a collection?

Frank Church


On 9 January 2013 19:30, Paul DeBruicker <[hidden email]> 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?

--
Frank Church

=======================
http://devblog.brahmancreations.com
Reply | Threaded
Open this post in threaded view
|

Re: How do I save contents of Workspace into a collection?

Stéphane Ducasse
Hi frank

select: returns the elements that satisfy the argument.
If none of them works -> #()

(10 20 30) select: [:each | each > 100]
        -> #()

what else could it be?

Stef

On Jan 9, 2013, at 9:39 PM, Frank Church wrote:

>
>
> On 9 January 2013 19:30, Paul DeBruicker <[hidden email]> 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?
>
> --
> Frank Church
>
> =======================
> http://devblog.brahmancreations.com


Reply | Threaded
Open this post in threaded view
|

Re: How do I save contents of Workspace into a collection?

Paul DeBruicker
In reply to this post by Frank Church
On 01/09/2013 12:39 PM, Frank Church wrote:

>
> On 9 January 2013 19:30, Paul DeBruicker <[hidden email]
> <mailto:[hidden email]>> 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.






Reply | Threaded
Open this post in threaded view
|

Re: How do I save contents of Workspace into a collection?

Frank Church


On 9 January 2013 21:08, Paul DeBruicker <[hidden email]> wrote:
On 01/09/2013 12:39 PM, Frank Church wrote:
>
> On 9 January 2013 19:30, Paul DeBruicker <[hidden email]
> <mailto:[hidden email]>> 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
Reply | Threaded
Open this post in threaded view
|

Re: How do I save contents of Workspace into a collection?

Paul DeBruicker
On 01/10/2013 07:32 AM, Frank Church wrote:

>
>
>
> 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.


I recommend you read through this:

http://squeak.joyful.com/LanguageNotes


1.

 workSpaces:=

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


2.

TextMorph>>getWorkspace
 |workspace|
 workspace:= self firstOwnerSuchThat: [ :owner | (owner
isKindOf: SystemWindow) and: [ owner model isKindOf: Workspace ] ].
^workspace



Heres some for you:

 Why are you so resistant to using classes and so interested in using
workspaces?  Why invent a new way of using Smalltalk when you don't have
the basics down pat?  My point is you didn't know about #select: and you
didn't know about #collect: but you do know that Workspaces are
interesting and Classes and the Browser is not.  Why not just put the
contents of whatever you've got in the Workspaces into methods in a
Classes you define and the you can call them whenever you want and
persist them with the tools that have been developed thus far rather
than inventing your own tooling while learning about Smalltalk.....


Good luck

Paul

Reply | Threaded
Open this post in threaded view
|

Re: How do I save contents of Workspace into a collection?

Paul DeBruicker
So I'm an idiot.  The answer to question 1 could be:

workSpaces:=
 TextMorphForEditView allInstances
                 select: [ :morph | (morph firstOwnerSuchThat: [ :owner
 | (owner
 isKindOf: SystemWindow) and: [ owner model isKindOf: Workspace ] ])
notNil ] thenCollect:[:each | each].
workSpaces


or:


workSpaces:=OrderedCollection new.
 TextMorphForEditView allInstances
                 do: [ :morph | (morph firstOwnerSuchThat: [ :owner
 | (owner
 isKindOf: SystemWindow) and: [ owner model isKindOf: Workspace ] ])
notNil ifTrue:[workSpaces add: morph] ].


But the answer I gave to it earlier is definitely wrong as you just end
up with a an array full of trues and falses.  Sorry for leading you down
the wrong path


Paul


On 01/10/2013 09:29 AM, Paul DeBruicker wrote:

> On 01/10/2013 07:32 AM, Frank Church wrote:
>>
>>
>>
>> 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.
>
>
> I recommend you read through this:
>
> http://squeak.joyful.com/LanguageNotes
>
>
> 1.
>
>  workSpaces:=
>
> TextMorphForEditView allInstances
>                 collect: [ :morph | (morph firstOwnerSuchThat: [ :owner
> | (owner
> isKindOf: SystemWindow) and: [ owner model isKindOf: Workspace ] ]) notNil ]
>
>
> 2.
>
> TextMorph>>getWorkspace
>  |workspace|
>  workspace:= self firstOwnerSuchThat: [ :owner | (owner
> isKindOf: SystemWindow) and: [ owner model isKindOf: Workspace ] ].
> ^workspace
>
>
>
> Heres some for you:
>
>  Why are you so resistant to using classes and so interested in using
> workspaces?  Why invent a new way of using Smalltalk when you don't have
> the basics down pat?  My point is you didn't know about #select: and you
> didn't know about #collect: but you do know that Workspaces are
> interesting and Classes and the Browser is not.  Why not just put the
> contents of whatever you've got in the Workspaces into methods in a
> Classes you define and the you can call them whenever you want and
> persist them with the tools that have been developed thus far rather
> than inventing your own tooling while learning about Smalltalk.....
>
>
> Good luck
>
> Paul
>


Reply | Threaded
Open this post in threaded view
|

Re: How do I save contents of Workspace into a collection?

Igor Stasenko
In reply to this post by Paul DeBruicker
On 10 January 2013 18:29, Paul DeBruicker <[hidden email]> wrote:

> On 01/10/2013 07:32 AM, Frank Church wrote:
>>
>>
>>
>> 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.
>
>
> I recommend you read through this:
>
> http://squeak.joyful.com/LanguageNotes
>
>
> 1.
>
>  workSpaces:=
>
> TextMorphForEditView allInstances
>                 collect: [ :morph | (morph firstOwnerSuchThat: [ :owner
> | (owner
> isKindOf: SystemWindow) and: [ owner model isKindOf: Workspace ] ]) notNil ]
>
>
> 2.
>
> TextMorph>>getWorkspace
>  |workspace|
>  workspace:= self firstOwnerSuchThat: [ :owner | (owner
> isKindOf: SystemWindow) and: [ owner model isKindOf: Workspace ] ].
> ^workspace
>
>
>
> Heres some for you:
>
>  Why are you so resistant to using classes and so interested in using
> workspaces?  Why invent a new way of using Smalltalk when you don't have
> the basics down pat?  My point is you didn't know about #select: and you
> didn't know about #collect: but you do know that Workspaces are
> interesting and Classes and the Browser is not.  Why not just put the
> contents of whatever you've got in the Workspaces into methods in a
> Classes you define and the you can call them whenever you want and
> persist them with the tools that have been developed thus far rather
> than inventing your own tooling while learning about Smalltalk.....
>
indeed.
I wonder why you (Frank) need such complicated way for doing things.
If you need a reusable piece of code, which you want to use more than 1 time,
classes is the best placeholder for them..

Even if you put things at class side, it helps a lot.. so then you can
just type:

MyUtilsClass doThis

MyUtilsClass doThat

etc

>
> Good luck
>
> Paul
>



--
Best regards,
Igor Stasenko.

12