Presetting variables to Spec's TextModel.

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

Presetting variables to Spec's TextModel.

Peter Uhnak
Hi,

I'm trying to preset variables to TextModel but I'm not sure if/how can such thing be achieved.

With Workspace (in pre-GT Pharo) I could do

ws := Workspace openContents: 'a'.
b := Dictionary new.
b add: (WorkspaceVariable key: #a value: 42).
ws setBindings: b.

Unfortunately Workspace isn't Spec's ComposableModel so I can't just reuse it.
Is something similar possible with TextModel? Perhaps somehow changing model to Workspace (without actually opening the workspace) or something?

Inspector seems to do something like that but my investigation ended up in OpalCompiler which is way over my head. :(

Thanks,
Peter
Reply | Threaded
Open this post in threaded view
|

Re: Presetting variables to Spec's TextModel.

stepharo
May be this is the occasion to create a WorkspaceModel and support this
behavior.

Stef

On 4/10/14 17:09, Peter Uhnák wrote:

> Hi,
>
> I'm trying to preset variables to TextModel but I'm not sure if/how
> can such thing be achieved.
>
> With Workspace (in pre-GT Pharo) I could do
>
> ws := Workspace openContents: 'a'.
> b := Dictionary new.
> b add: (WorkspaceVariable key: #a value: 42).
> ws setBindings: b.
>
> Unfortunately Workspace isn't Spec's ComposableModel so I can't just
> reuse it.
> Is something similar possible with TextModel? Perhaps somehow changing
> model to Workspace (without actually opening the workspace) or something?
>
> Inspector seems to do something like that but my investigation ended
> up in OpalCompiler which is way over my head. :(
>
> Thanks,
> Peter


Reply | Threaded
Open this post in threaded view
|

Re: Presetting variables to Spec's TextModel.

Nicolai Hess
In reply to this post by Peter Uhnak


Am 04.10.2014 17:09 schrieb "Peter Uhnák" <[hidden email]>:
>
> Hi,
>
> I'm trying to preset variables to TextModel but I'm not sure if/how can such thing be achieved.
>
> With Workspace (in pre-GT Pharo) I could do
>
> ws := Workspace openContents: 'a'.
> b := Dictionary new.
> b add: (WorkspaceVariable key: #a value: 42).
> ws setBindings: b.
>
> Unfortunately Workspace isn't Spec's ComposableModel so I can't just reuse it.
> Is something similar possible with TextModel? Perhaps somehow changing model to Workspace (without actually opening the workspace) or something?
>
> Inspector seems to do something like that but my investigation ended up in OpalCompiler which is way over my head. :(
>
> Thanks,
> Peter

I don't know how this works for variable binding,
but you can set the doItReceiver:

(that's how the inspector works)


Reply | Threaded
Open this post in threaded view
|

Re: Presetting variables to Spec's TextModel.

Peter Uhnak
I was looking at the Inspector and I saw the doItContext/doItReceiver but it spans over several objects and I wasn't able to figure out how it actually works / how to use it. (OpalCompiler was calling various methods on the objects, so it was expecting some kind of structure).

Could you give me an example?

On Sat, Oct 4, 2014 at 9:15 PM, Nicolai Hess <[hidden email]> wrote:


Am 04.10.2014 17:09 schrieb "Peter Uhnák" <[hidden email]>:


>
> Hi,
>
> I'm trying to preset variables to TextModel but I'm not sure if/how can such thing be achieved.
>
> With Workspace (in pre-GT Pharo) I could do
>
> ws := Workspace openContents: 'a'.
> b := Dictionary new.
> b add: (WorkspaceVariable key: #a value: 42).
> ws setBindings: b.
>
> Unfortunately Workspace isn't Spec's ComposableModel so I can't just reuse it.
> Is something similar possible with TextModel? Perhaps somehow changing model to Workspace (without actually opening the workspace) or something?
>
> Inspector seems to do something like that but my investigation ended up in OpalCompiler which is way over my head. :(
>
> Thanks,
> Peter

I don't know how this works for variable binding,
but you can set the doItReceiver:

(that's how the inspector works)



Reply | Threaded
Open this post in threaded view
|

Re: Presetting variables to Spec's TextModel.

Nicolai Hess
This opens a text field where all "self ..." calls are evaluated for the morph object:

|t|
t:=TextModel new.
t title:'evaluates for a morph'.
t doItReceiver:(Morph new).
t openWithSpec


for example
self openInWorld
self color:Color red.

will show the object and change the color.
But yes, you can not set any variable binding.
The workspace handles this on its own, there is no
support for this in TextModel/TextAdapter


2014-10-04 21:20 GMT+02:00 Peter Uhnák <[hidden email]>:
I was looking at the Inspector and I saw the doItContext/doItReceiver but it spans over several objects and I wasn't able to figure out how it actually works / how to use it. (OpalCompiler was calling various methods on the objects, so it was expecting some kind of structure).

Could you give me an example?

On Sat, Oct 4, 2014 at 9:15 PM, Nicolai Hess <[hidden email]> wrote:


Am 04.10.2014 17:09 schrieb "Peter Uhnák" <[hidden email]>:


>
> Hi,
>
> I'm trying to preset variables to TextModel but I'm not sure if/how can such thing be achieved.
>
> With Workspace (in pre-GT Pharo) I could do
>
> ws := Workspace openContents: 'a'.
> b := Dictionary new.
> b add: (WorkspaceVariable key: #a value: 42).
> ws setBindings: b.
>
> Unfortunately Workspace isn't Spec's ComposableModel so I can't just reuse it.
> Is something similar possible with TextModel? Perhaps somehow changing model to Workspace (without actually opening the workspace) or something?
>
> Inspector seems to do something like that but my investigation ended up in OpalCompiler which is way over my head. :(
>
> Thanks,
> Peter

I don't know how this works for variable binding,
but you can set the doItReceiver:

(that's how the inspector works)




Reply | Threaded
Open this post in threaded view
|

Re: Presetting variables to Spec's TextModel.

webwarrior
In reply to this post by Peter Uhnak
You can set your own context using #doItContext: method.
Context object should have following methods: #bindingOf:, #method, namedTempAt:, #tempNames.
See GLMDoItContext from Glamour for example.